Lines 15-27
Link Here
|
15 |
|
15 |
|
16 |
import java.awt.Dialog; |
16 |
import java.awt.Dialog; |
17 |
import java.awt.EventQueue; |
17 |
import java.awt.EventQueue; |
|
|
18 |
import java.lang.ref.Reference; |
19 |
import java.lang.ref.WeakReference; |
20 |
import java.lang.reflect.InvocationTargetException; |
18 |
import javax.swing.JButton; |
21 |
import javax.swing.JButton; |
|
|
22 |
import javax.swing.JLabel; |
19 |
import javax.swing.JOptionPane; |
23 |
import javax.swing.JOptionPane; |
20 |
import javax.swing.SwingUtilities; |
24 |
import javax.swing.SwingUtilities; |
21 |
import org.netbeans.junit.NbTestCase; |
25 |
import org.netbeans.junit.NbTestCase; |
22 |
import org.openide.DialogDescriptor; |
26 |
import org.openide.DialogDescriptor; |
23 |
import org.openide.DialogDisplayer; |
27 |
import org.openide.DialogDisplayer; |
24 |
import org.openide.NotifyDescriptor; |
28 |
import org.openide.NotifyDescriptor; |
|
|
29 |
import org.openide.util.RequestProcessor; |
25 |
|
30 |
|
26 |
/** |
31 |
/** |
27 |
* |
32 |
* |
Lines 36-41
Link Here
|
36 |
private JButton openChild; |
41 |
private JButton openChild; |
37 |
private JButton closeChild; |
42 |
private JButton closeChild; |
38 |
private Dialog child; |
43 |
private Dialog child; |
|
|
44 |
private Dialog testDialog; |
45 |
private Dialog swingDialog; |
39 |
|
46 |
|
40 |
public DialogDisplayerImplTest (String testName) { |
47 |
public DialogDisplayerImplTest (String testName) { |
41 |
super (testName); |
48 |
super (testName); |
Lines 209-214
Link Here
|
209 |
|
216 |
|
210 |
assertFalse ("Leaf is dead", owner.isVisible ()); |
217 |
assertFalse ("Leaf is dead", owner.isVisible ()); |
211 |
assertFalse ("Child is dead too", child.isVisible ()); |
218 |
assertFalse ("Child is dead too", child.isVisible ()); |
|
|
219 |
} |
220 |
|
221 |
/** Tests issue 55273: Dialogs created by DialogDisplayer are not disposed after close |
222 |
* |
223 |
* @throws java.lang.Exception |
224 |
*/ |
225 |
public void testDialogDisposed () throws Exception { |
226 |
final DialogDescriptor dd = new DialogDescriptor (pane, "Hello", false, new Object[] {closeOwner}, null, 0, null, null); |
227 |
//final DialogDescriptor dd = new DialogDescriptor (new JLabel ("Hello"), "Hello", false, null); |
228 |
testDialog = DialogDisplayer.getDefault().createDialog(dd); |
229 |
Reference ref = new WeakReference (testDialog); |
230 |
SwingUtilities.invokeAndWait (new Runnable () { |
231 |
public void run () { |
232 |
testDialog.setVisible (true); |
233 |
} |
234 |
}); |
235 |
assertNotNull ("Test dialog lives.", ref.get ()); |
236 |
SwingUtilities.invokeAndWait (new Runnable () { |
237 |
public void run () { |
238 |
closeOwner.doClick (); |
239 |
} |
240 |
}); |
241 |
while (testDialog.isVisible ()); |
242 |
assertNotNull ("Test dialog still lives.", ref.get ()); |
243 |
testDialog.dispose(); |
244 |
testDialog = null; |
245 |
RequestProcessor.getDefault ().post (new Runnable () { |
246 |
public void run () { |
247 |
} |
248 |
}, 1000).waitFinished (); |
249 |
assertGC ("Test dialog allocs no resources.", ref); |
250 |
assertNull ("Test dialog must be dead.", ref.get ()); |
251 |
} |
252 |
|
253 |
public void testSwingDialogDisposed () throws Exception { |
254 |
swingDialog = new Dialog ((Dialog)null, "Hello"); |
255 |
Reference ref = new WeakReference (swingDialog); |
256 |
SwingUtilities.invokeAndWait (new Runnable () { |
257 |
public void run () { |
258 |
swingDialog.setVisible (true); |
259 |
} |
260 |
}); |
261 |
assertNotNull ("Test dialog lives.", ref.get ()); |
262 |
SwingUtilities.invokeAndWait (new Runnable () { |
263 |
public void run () { |
264 |
swingDialog.setVisible (false); |
265 |
} |
266 |
}); |
267 |
while (swingDialog.isVisible ()); |
268 |
assertNotNull ("Test dialog still lives.", ref.get ()); |
269 |
swingDialog = null; |
270 |
RequestProcessor.getDefault ().post (new Runnable () { |
271 |
public void run () { |
272 |
} |
273 |
}, 1000).waitFinished (); |
274 |
assertGC ("Test dialog allocs no resources.", ref); |
275 |
assertNull ("Test dialog must be dead.", ref.get ()); |
212 |
} |
276 |
} |
213 |
|
277 |
|
214 |
private void postInAwtAndWaitOutsideAwt (final Runnable run) throws Exception { |
278 |
private void postInAwtAndWaitOutsideAwt (final Runnable run) throws Exception { |