Lines 41-47
Link Here
|
41 |
* Version 2 license, then the option applies only if the new code is |
41 |
* Version 2 license, then the option applies only if the new code is |
42 |
* made subject to such option by the copyright holder. |
42 |
* made subject to such option by the copyright holder. |
43 |
*/ |
43 |
*/ |
44 |
package org.netbeans.core; |
44 |
package org.netbeans; |
45 |
|
45 |
|
46 |
import java.awt.KeyboardFocusManager; |
46 |
import java.awt.KeyboardFocusManager; |
47 |
import java.awt.Window; |
47 |
import java.awt.Window; |
Lines 61-67
Link Here
|
61 |
import javax.swing.SwingUtilities; |
61 |
import javax.swing.SwingUtilities; |
62 |
import org.netbeans.junit.NbTestCase; |
62 |
import org.netbeans.junit.NbTestCase; |
63 |
import org.openide.util.Utilities; |
63 |
import org.openide.util.Utilities; |
64 |
import org.openide.windows.TopComponent; |
|
|
65 |
|
64 |
|
66 |
/** Basic tests on NbClipboard |
65 |
/** Basic tests on NbClipboard |
67 |
* |
66 |
* |
Lines 111-136
Link Here
|
111 |
class Safe implements Runnable { |
110 |
class Safe implements Runnable { |
112 |
WeakReference<Object> ref; |
111 |
WeakReference<Object> ref; |
113 |
Window w; |
112 |
Window w; |
114 |
TopComponent tc; |
|
|
115 |
|
116 |
|
113 |
|
117 |
public void beforeAWT() throws InterruptedException { |
114 |
public void beforeAWT() throws InterruptedException { |
118 |
NbClipboard ec = new NbClipboard(); |
115 |
NbClipboard ec = new NbClipboard(); |
119 |
|
116 |
|
120 |
tc = new TopComponent(); |
117 |
w = new JFrame("Original frame"); |
121 |
tc.open(); |
118 |
w.pack(); |
122 |
|
119 |
w.setVisible(true); |
123 |
for(;;) { |
120 |
w.toFront(); |
124 |
w = SwingUtilities.getWindowAncestor(tc); |
121 |
w.requestFocus(); |
125 |
if (w != null && w.isVisible()) { |
122 |
w.requestFocusInWindow(); |
126 |
break; |
123 |
|
127 |
} |
124 |
w.setVisible(false); |
128 |
Thread.sleep(100); |
|
|
129 |
} |
130 |
|
131 |
tc.close(); |
132 |
w.dispose(); |
125 |
w.dispose(); |
133 |
|
126 |
|
134 |
// opening new frame shall clear all the AWT references to previous frame |
127 |
// opening new frame shall clear all the AWT references to previous frame |
135 |
JFrame f = new JFrame("Focus stealer"); |
128 |
JFrame f = new JFrame("Focus stealer"); |
136 |
f.setVisible(true); |
129 |
f.setVisible(true); |
Lines 145-151
Link Here
|
145 |
|
138 |
|
146 |
ref = new WeakReference<Object>(w); |
139 |
ref = new WeakReference<Object>(w); |
147 |
w = null; |
140 |
w = null; |
148 |
tc = null; |
|
|
149 |
} |
141 |
} |
150 |
} |
142 |
} |
151 |
|
143 |
|
Lines 155-161
Link Here
|
155 |
SwingUtilities.invokeAndWait(safe); |
147 |
SwingUtilities.invokeAndWait(safe); |
156 |
|
148 |
|
157 |
try { |
149 |
try { |
158 |
assertGC("Top component can disappear", safe.ref); |
150 |
assertGC("Original frame can disappear", safe.ref); |
159 |
} catch (junit.framework.AssertionFailedError ex) { |
151 |
} catch (junit.framework.AssertionFailedError ex) { |
160 |
if (ex.getMessage().indexOf("NbClipboard") >= 0) { |
152 |
if (ex.getMessage().indexOf("NbClipboard") >= 0) { |
161 |
throw ex; |
153 |
throw ex; |