author | erikj |
Thu, 07 Jun 2012 18:05:09 -0700 | |
changeset 12813 | c10ab96dcf41 |
parent 11264 | 54f2f4c6bd30 |
child 13604 | 31089af1a447 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.awt; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.event.*; |
|
30 |
import java.awt.image.*; |
|
31 |
import java.awt.peer.*; |
|
32 |
import java.security.AccessController; |
|
33 |
import java.security.PrivilegedAction; |
|
34 |
import java.lang.reflect.Constructor; |
|
35 |
import java.lang.reflect.InvocationTargetException; |
|
36 |
import java.lang.reflect.Modifier; |
|
37 |
import java.lang.reflect.Field; |
|
38 |
import java.beans.PropertyChangeListener; |
|
39 |
import java.beans.PropertyChangeEvent; |
|
40 |
import java.util.Set; |
|
41 |
import java.awt.AWTKeyStroke; |
|
42 |
import java.applet.Applet; |
|
12813
c10ab96dcf41
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents:
11264
diff
changeset
|
43 |
import javax.tools.annotation.GenerateNativeHeader; |
2 | 44 |
import sun.applet.AppletPanel; |
45 |
||
46 |
/** |
|
47 |
* A generic container used for embedding Java components, usually applets. |
|
48 |
* An EmbeddedFrame has two related uses: |
|
49 |
* |
|
50 |
* . Within a Java-based application, an EmbeddedFrame serves as a sort of |
|
51 |
* firewall, preventing the contained components or applets from using |
|
52 |
* getParent() to find parent components, such as menubars. |
|
53 |
* |
|
54 |
* . Within a C-based application, an EmbeddedFrame contains a window handle |
|
55 |
* which was created by the application, which serves as the top-level |
|
56 |
* Java window. EmbeddedFrames created for this purpose are passed-in a |
|
57 |
* handle of an existing window created by the application. The window |
|
58 |
* handle should be of the appropriate native type for a specific |
|
59 |
* platform, as stored in the pData field of the ComponentPeer. |
|
60 |
* |
|
61 |
* @author Thomas Ball |
|
62 |
*/ |
|
12813
c10ab96dcf41
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents:
11264
diff
changeset
|
63 |
/* No native methods here, but the constants are needed in the supporting JNI code */ |
c10ab96dcf41
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents:
11264
diff
changeset
|
64 |
@GenerateNativeHeader |
2 | 65 |
public abstract class EmbeddedFrame extends Frame |
66 |
implements KeyEventDispatcher, PropertyChangeListener { |
|
67 |
||
68 |
private boolean isCursorAllowed = true; |
|
69 |
private static Field fieldPeer; |
|
70 |
private static Field currentCycleRoot; |
|
71 |
private boolean supportsXEmbed = false; |
|
72 |
private KeyboardFocusManager appletKFM; |
|
73 |
// JDK 1.1 compatibility |
|
74 |
private static final long serialVersionUID = 2967042741780317130L; |
|
75 |
||
6634
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
76 |
/* |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
77 |
* The constants define focus traversal directions. |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
78 |
* Use them in {@code traverseIn}, {@code traverseOut} methods. |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
79 |
*/ |
2 | 80 |
protected static final boolean FORWARD = true; |
81 |
protected static final boolean BACKWARD = false; |
|
82 |
||
83 |
public boolean supportsXEmbed() { |
|
84 |
return supportsXEmbed && SunToolkit.needsXEmbed(); |
|
85 |
} |
|
86 |
||
87 |
protected EmbeddedFrame(boolean supportsXEmbed) { |
|
88 |
this((long)0, supportsXEmbed); |
|
89 |
} |
|
90 |
||
91 |
||
92 |
protected EmbeddedFrame() { |
|
93 |
this((long)0); |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* @deprecated This constructor will be removed in 1.5 |
|
98 |
*/ |
|
99 |
@Deprecated |
|
100 |
protected EmbeddedFrame(int handle) { |
|
101 |
this((long)handle); |
|
102 |
} |
|
103 |
||
104 |
protected EmbeddedFrame(long handle) { |
|
105 |
this(handle, false); |
|
106 |
} |
|
107 |
||
108 |
protected EmbeddedFrame(long handle, boolean supportsXEmbed) { |
|
109 |
this.supportsXEmbed = supportsXEmbed; |
|
110 |
registerListeners(); |
|
111 |
} |
|
112 |
||
113 |
/** |
|
114 |
* Block introspection of a parent window by this child. |
|
115 |
*/ |
|
116 |
public Container getParent() { |
|
117 |
return null; |
|
118 |
} |
|
119 |
||
120 |
/** |
|
121 |
* Needed to track which KeyboardFocusManager is current. We want to avoid memory |
|
122 |
* leaks, so when KFM stops being current, we remove ourselves as listeners. |
|
123 |
*/ |
|
124 |
public void propertyChange(PropertyChangeEvent evt) { |
|
125 |
// We don't handle any other properties. Skip it. |
|
126 |
if (!evt.getPropertyName().equals("managingFocus")) { |
|
127 |
return; |
|
128 |
} |
|
129 |
||
130 |
// We only do it if it stops being current. Technically, we should |
|
131 |
// never get an event about KFM starting being current. |
|
132 |
if (evt.getNewValue() == Boolean.TRUE) { |
|
133 |
return; |
|
134 |
} |
|
135 |
||
136 |
// should be the same as appletKFM |
|
137 |
removeTraversingOutListeners((KeyboardFocusManager)evt.getSource()); |
|
138 |
||
139 |
appletKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager(); |
|
140 |
if (isVisible()) { |
|
141 |
addTraversingOutListeners(appletKFM); |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
/** |
|
146 |
* Register us as KeyEventDispatcher and property "managingFocus" listeners. |
|
147 |
*/ |
|
148 |
private void addTraversingOutListeners(KeyboardFocusManager kfm) { |
|
149 |
kfm.addKeyEventDispatcher(this); |
|
150 |
kfm.addPropertyChangeListener("managingFocus", this); |
|
151 |
} |
|
152 |
||
153 |
/** |
|
154 |
* Deregister us as KeyEventDispatcher and property "managingFocus" listeners. |
|
155 |
*/ |
|
156 |
private void removeTraversingOutListeners(KeyboardFocusManager kfm) { |
|
157 |
kfm.removeKeyEventDispatcher(this); |
|
158 |
kfm.removePropertyChangeListener("managingFocus", this); |
|
159 |
} |
|
160 |
||
161 |
/** |
|
162 |
* Because there may be many AppContexts, and we can't be sure where this |
|
163 |
* EmbeddedFrame is first created or shown, we can't automatically determine |
|
164 |
* the correct KeyboardFocusManager to attach to as KeyEventDispatcher. |
|
165 |
* Those who want to use the functionality of traversing out of the EmbeddedFrame |
|
166 |
* must call this method on the Applet's AppContext. After that, all the changes |
|
167 |
* can be handled automatically, including possible replacement of |
|
168 |
* KeyboardFocusManager. |
|
169 |
*/ |
|
170 |
public void registerListeners() { |
|
171 |
if (appletKFM != null) { |
|
172 |
removeTraversingOutListeners(appletKFM); |
|
173 |
} |
|
174 |
appletKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager(); |
|
175 |
if (isVisible()) { |
|
176 |
addTraversingOutListeners(appletKFM); |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Needed to avoid memory leak: we register this EmbeddedFrame as a listener with |
|
182 |
* KeyboardFocusManager of applet's AppContext. We don't want the KFM to keep |
|
183 |
* reference to our EmbeddedFrame forever if the Frame is no longer in use, so we |
|
184 |
* add listeners in show() and remove them in hide(). |
|
185 |
*/ |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
186 |
@SuppressWarnings("deprecation") |
2 | 187 |
public void show() { |
188 |
if (appletKFM != null) { |
|
189 |
addTraversingOutListeners(appletKFM); |
|
190 |
} |
|
191 |
super.show(); |
|
192 |
} |
|
193 |
||
194 |
/** |
|
195 |
* Needed to avoid memory leak: we register this EmbeddedFrame as a listener with |
|
196 |
* KeyboardFocusManager of applet's AppContext. We don't want the KFM to keep |
|
197 |
* reference to our EmbeddedFrame forever if the Frame is no longer in use, so we |
|
198 |
* add listeners in show() and remove them in hide(). |
|
199 |
*/ |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
200 |
@SuppressWarnings("deprecation") |
2 | 201 |
public void hide() { |
202 |
if (appletKFM != null) { |
|
203 |
removeTraversingOutListeners(appletKFM); |
|
204 |
} |
|
205 |
super.hide(); |
|
206 |
} |
|
207 |
||
208 |
/** |
|
209 |
* Need this method to detect when the focus may have chance to leave the |
|
210 |
* focus cycle root which is EmbeddedFrame. Mostly, the code here is copied |
|
211 |
* from DefaultKeyboardFocusManager.processKeyEvent with some minor |
|
212 |
* modifications. |
|
213 |
*/ |
|
214 |
public boolean dispatchKeyEvent(KeyEvent e) { |
|
215 |
||
216 |
// We can't guarantee that this is called on the same AppContext as EmbeddedFrame |
|
217 |
// belongs to. That's why we can't use public methods to find current focus cycle |
|
218 |
// root. Instead, we access KFM's private field directly. |
|
219 |
if (currentCycleRoot == null) { |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
220 |
currentCycleRoot = AccessController.doPrivileged(new PrivilegedAction<Field>() { |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
221 |
public Field run() { |
2 | 222 |
try { |
223 |
Field unaccessibleRoot = KeyboardFocusManager.class. |
|
224 |
getDeclaredField("currentFocusCycleRoot"); |
|
225 |
if (unaccessibleRoot != null) { |
|
226 |
unaccessibleRoot.setAccessible(true); |
|
227 |
} |
|
228 |
return unaccessibleRoot; |
|
229 |
} catch (NoSuchFieldException e1) { |
|
230 |
assert false; |
|
231 |
} catch (SecurityException e2) { |
|
232 |
assert false; |
|
233 |
} |
|
234 |
return null; |
|
235 |
} |
|
236 |
}); |
|
237 |
} |
|
238 |
||
239 |
Container currentRoot = null; |
|
240 |
if (currentCycleRoot != null) { |
|
241 |
try { |
|
242 |
// The field is static, so we can pass null to Field.get() as the argument. |
|
243 |
currentRoot = (Container)currentCycleRoot.get(null); |
|
244 |
} catch (IllegalAccessException e3) { |
|
245 |
// This is impossible: currentCycleRoot would be null if setAccessible failed. |
|
246 |
assert false; |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
// if we are not in EmbeddedFrame's cycle, we should not try to leave. |
|
251 |
if (this != currentRoot) { |
|
252 |
return false; |
|
253 |
} |
|
254 |
||
255 |
// KEY_TYPED events cannot be focus traversal keys |
|
256 |
if (e.getID() == KeyEvent.KEY_TYPED) { |
|
257 |
return false; |
|
258 |
} |
|
259 |
||
260 |
if (!getFocusTraversalKeysEnabled() || e.isConsumed()) { |
|
261 |
return false; |
|
262 |
} |
|
263 |
||
264 |
AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e); |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
265 |
Set<AWTKeyStroke> toTest; |
2 | 266 |
Component currentFocused = e.getComponent(); |
267 |
||
268 |
toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); |
|
1179
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
269 |
if (toTest.contains(stroke)) { |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
270 |
// 6581899: performance improvement for SortingFocusTraversalPolicy |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
271 |
Component last = getFocusTraversalPolicy().getLastComponent(this); |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
272 |
if (currentFocused == last || last == null) { |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
273 |
if (traverseOut(FORWARD)) { |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
274 |
e.consume(); |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
275 |
return true; |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
276 |
} |
2 | 277 |
} |
278 |
} |
|
279 |
||
280 |
toTest = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); |
|
1179
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
281 |
if (toTest.contains(stroke)) { |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
282 |
// 6581899: performance improvement for SortingFocusTraversalPolicy |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
283 |
Component first = getFocusTraversalPolicy().getFirstComponent(this); |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
284 |
if (currentFocused == first || first == null) { |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
285 |
if (traverseOut(BACKWARD)) { |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
286 |
e.consume(); |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
287 |
return true; |
b0d106998757
6581899: JTextField & JTextArea - Poor performance with JRE 1.5.0_08
dcherepanov
parents:
2
diff
changeset
|
288 |
} |
2 | 289 |
} |
290 |
} |
|
291 |
return false; |
|
292 |
} |
|
293 |
||
294 |
/** |
|
6634
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
295 |
* This method is called by the embedder when we should receive focus as element |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
296 |
* of the traversal chain. The method requests focus on: |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
297 |
* 1. the first Component of this EmbeddedFrame if user moves focus forward |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
298 |
* in the focus traversal cycle. |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
299 |
* 2. the last Component of this EmbeddedFrame if user moves focus backward |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
300 |
* in the focus traversal cycle. |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
301 |
* |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
302 |
* The direction parameter specifies which of the two mentioned cases is |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
303 |
* happening. Use FORWARD and BACKWARD constants defined in the EmbeddedFrame class |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
304 |
* to avoid confusing boolean values. |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
305 |
* |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
306 |
* A concrete implementation of this method is defined in the platform-dependent |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
307 |
* subclasses. |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
308 |
* |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
309 |
* @param direction FORWARD or BACKWARD |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
310 |
* @return true, if the EmbeddedFrame wants to get focus, false otherwise. |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
311 |
*/ |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
312 |
public boolean traverseIn(boolean direction) { |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
313 |
Component comp = null; |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
314 |
|
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
315 |
if (direction == FORWARD) { |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
316 |
comp = getFocusTraversalPolicy().getFirstComponent(this); |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
317 |
} else { |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
318 |
comp = getFocusTraversalPolicy().getLastComponent(this); |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
319 |
} |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
320 |
if (comp != null) { |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
321 |
// comp.requestFocus(); - Leads to a hung. |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
322 |
|
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
323 |
AWTAccessor.getKeyboardFocusManagerAccessor().setMostRecentFocusOwner(this, comp); |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
324 |
synthesizeWindowActivation(true); |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
325 |
} |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
326 |
return (null != comp); |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
327 |
} |
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
328 |
|
439221465ac5
6505819: Provide traverseIn method for sun.awt.EmbeddedFrame
ant
parents:
5506
diff
changeset
|
329 |
/** |
2 | 330 |
* This method is called from dispatchKeyEvent in the following two cases: |
331 |
* 1. The focus is on the first Component of this EmbeddedFrame and we are |
|
332 |
* about to transfer the focus backward. |
|
333 |
* 2. The focus in on the last Component of this EmbeddedFrame and we are |
|
334 |
* about to transfer the focus forward. |
|
335 |
* This is needed to give the opportuity for keyboard focus to leave the |
|
336 |
* EmbeddedFrame. Override this method, initiate focus transfer in it and |
|
337 |
* return true if you want the focus to leave EmbeddedFrame's cycle. |
|
338 |
* The direction parameter specifies which of the two mentioned cases is |
|
339 |
* happening. Use FORWARD and BACKWARD constants defined in EmbeddedFrame |
|
340 |
* to avoid confusing boolean values. |
|
341 |
* |
|
342 |
* @param direction FORWARD or BACKWARD |
|
343 |
* @return true, if EmbeddedFrame wants the focus to leave it, |
|
344 |
* false otherwise. |
|
345 |
*/ |
|
346 |
protected boolean traverseOut(boolean direction) { |
|
347 |
return false; |
|
348 |
} |
|
349 |
||
350 |
/** |
|
351 |
* Block modifying any frame attributes, since they aren't applicable |
|
352 |
* for EmbeddedFrames. |
|
353 |
*/ |
|
354 |
public void setTitle(String title) {} |
|
355 |
public void setIconImage(Image image) {} |
|
356 |
public void setIconImages(java.util.List<? extends Image> icons) {} |
|
357 |
public void setMenuBar(MenuBar mb) {} |
|
358 |
public void setResizable(boolean resizable) {} |
|
359 |
public void remove(MenuComponent m) {} |
|
360 |
||
361 |
public boolean isResizable() { |
|
362 |
return true; |
|
363 |
} |
|
364 |
||
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
365 |
@SuppressWarnings("deprecation") |
2 | 366 |
public void addNotify() { |
367 |
synchronized (getTreeLock()) { |
|
368 |
if (getPeer() == null) { |
|
369 |
setPeer(new NullEmbeddedFramePeer()); |
|
370 |
} |
|
371 |
super.addNotify(); |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
// These three functions consitute RFE 4100710. Do not remove. |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
376 |
@SuppressWarnings("deprecation") |
2 | 377 |
public void setCursorAllowed(boolean isCursorAllowed) { |
378 |
this.isCursorAllowed = isCursorAllowed; |
|
379 |
getPeer().updateCursorImmediately(); |
|
380 |
} |
|
381 |
public boolean isCursorAllowed() { |
|
382 |
return isCursorAllowed; |
|
383 |
} |
|
384 |
public Cursor getCursor() { |
|
385 |
return (isCursorAllowed) |
|
386 |
? super.getCursor() |
|
387 |
: Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); |
|
388 |
} |
|
389 |
||
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
390 |
@SuppressWarnings("deprecation") |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
391 |
protected void setPeer(final ComponentPeer p){ |
2 | 392 |
if (fieldPeer == null) { |
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
393 |
fieldPeer = AccessController.doPrivileged(new PrivilegedAction<Field>() { |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
394 |
public Field run() { |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
395 |
try { |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
396 |
Field lnkPeer = Component.class.getDeclaredField("peer"); |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
397 |
if (lnkPeer != null) { |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
398 |
lnkPeer.setAccessible(true); |
2 | 399 |
} |
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
400 |
return lnkPeer; |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
401 |
} catch (NoSuchFieldException e) { |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
402 |
assert false; |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
403 |
} catch (SecurityException e) { |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
404 |
assert false; |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
405 |
} |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
406 |
return null; |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
407 |
}//run |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
408 |
}); |
2 | 409 |
} |
410 |
try{ |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
411 |
if (fieldPeer != null){ |
2 | 412 |
fieldPeer.set(EmbeddedFrame.this, p); |
413 |
} |
|
414 |
} catch (IllegalAccessException e) { |
|
415 |
assert false; |
|
416 |
} |
|
417 |
}; //setPeer method ends |
|
418 |
||
419 |
/** |
|
420 |
* Synthesize native message to activate or deactivate EmbeddedFrame window |
|
421 |
* depending on the value of parameter <code>b</code>. |
|
422 |
* Peers should override this method if they are to implement |
|
423 |
* this functionality. |
|
424 |
* @param doActivate if <code>true</code>, activates the window; |
|
425 |
* otherwise, deactivates the window |
|
426 |
*/ |
|
427 |
public void synthesizeWindowActivation(boolean doActivate) {} |
|
428 |
||
429 |
/** |
|
430 |
* Moves this embedded frame to a new location. The top-left corner of |
|
431 |
* the new location is specified by the <code>x</code> and <code>y</code> |
|
432 |
* parameters relative to the native parent component. |
|
433 |
* <p> |
|
434 |
* setLocation() and setBounds() for EmbeddedFrame really don't move it |
|
435 |
* within the native parent. These methods always put embedded frame to |
|
436 |
* (0, 0) for backward compatibility. To allow moving embedded frame |
|
437 |
* setLocationPrivate() and setBoundsPrivate() were introduced, and they |
|
438 |
* work just the same way as setLocation() and setBounds() for usual, |
|
439 |
* non-embedded components. |
|
440 |
* </p> |
|
441 |
* <p> |
|
442 |
* Using usual get/setLocation() and get/setBounds() together with new |
|
443 |
* get/setLocationPrivate() and get/setBoundsPrivate() is not recommended. |
|
444 |
* For example, calling getBoundsPrivate() after setLocation() works fine, |
|
445 |
* but getBounds() after setBoundsPrivate() may return unpredictable value. |
|
446 |
* </p> |
|
447 |
* @param x the new <i>x</i>-coordinate relative to the parent component |
|
448 |
* @param y the new <i>y</i>-coordinate relative to the parent component |
|
449 |
* @see java.awt.Component#setLocation |
|
450 |
* @see #getLocationPrivate |
|
451 |
* @see #setBoundsPrivate |
|
452 |
* @see #getBoundsPrivate |
|
453 |
* @since 1.5 |
|
454 |
*/ |
|
455 |
protected void setLocationPrivate(int x, int y) { |
|
456 |
Dimension size = getSize(); |
|
457 |
setBoundsPrivate(x, y, size.width, size.height); |
|
458 |
} |
|
459 |
||
460 |
/** |
|
461 |
* Gets the location of this embedded frame as a point specifying the |
|
462 |
* top-left corner relative to parent component. |
|
463 |
* <p> |
|
464 |
* setLocation() and setBounds() for EmbeddedFrame really don't move it |
|
465 |
* within the native parent. These methods always put embedded frame to |
|
466 |
* (0, 0) for backward compatibility. To allow getting location and size |
|
467 |
* of embedded frame getLocationPrivate() and getBoundsPrivate() were |
|
468 |
* introduced, and they work just the same way as getLocation() and getBounds() |
|
469 |
* for ususal, non-embedded components. |
|
470 |
* </p> |
|
471 |
* <p> |
|
472 |
* Using usual get/setLocation() and get/setBounds() together with new |
|
473 |
* get/setLocationPrivate() and get/setBoundsPrivate() is not recommended. |
|
474 |
* For example, calling getBoundsPrivate() after setLocation() works fine, |
|
475 |
* but getBounds() after setBoundsPrivate() may return unpredictable value. |
|
476 |
* </p> |
|
477 |
* @return a point indicating this embedded frame's top-left corner |
|
478 |
* @see java.awt.Component#getLocation |
|
479 |
* @see #setLocationPrivate |
|
480 |
* @see #setBoundsPrivate |
|
481 |
* @see #getBoundsPrivate |
|
482 |
* @since 1.6 |
|
483 |
*/ |
|
484 |
protected Point getLocationPrivate() { |
|
485 |
Rectangle bounds = getBoundsPrivate(); |
|
486 |
return new Point(bounds.x, bounds.y); |
|
487 |
} |
|
488 |
||
489 |
/** |
|
490 |
* Moves and resizes this embedded frame. The new location of the top-left |
|
491 |
* corner is specified by <code>x</code> and <code>y</code> parameters |
|
492 |
* relative to the native parent component. The new size is specified by |
|
493 |
* <code>width</code> and <code>height</code>. |
|
494 |
* <p> |
|
495 |
* setLocation() and setBounds() for EmbeddedFrame really don't move it |
|
496 |
* within the native parent. These methods always put embedded frame to |
|
497 |
* (0, 0) for backward compatibility. To allow moving embedded frames |
|
498 |
* setLocationPrivate() and setBoundsPrivate() were introduced, and they |
|
499 |
* work just the same way as setLocation() and setBounds() for usual, |
|
500 |
* non-embedded components. |
|
501 |
* </p> |
|
502 |
* <p> |
|
503 |
* Using usual get/setLocation() and get/setBounds() together with new |
|
504 |
* get/setLocationPrivate() and get/setBoundsPrivate() is not recommended. |
|
505 |
* For example, calling getBoundsPrivate() after setLocation() works fine, |
|
506 |
* but getBounds() after setBoundsPrivate() may return unpredictable value. |
|
507 |
* </p> |
|
508 |
* @param x the new <i>x</i>-coordinate relative to the parent component |
|
509 |
* @param y the new <i>y</i>-coordinate relative to the parent component |
|
510 |
* @param width the new <code>width</code> of this embedded frame |
|
511 |
* @param height the new <code>height</code> of this embedded frame |
|
512 |
* @see java.awt.Component#setBounds |
|
513 |
* @see #setLocationPrivate |
|
514 |
* @see #getLocationPrivate |
|
515 |
* @see #getBoundsPrivate |
|
516 |
* @since 1.5 |
|
517 |
*/ |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
518 |
@SuppressWarnings("deprecation") |
2 | 519 |
protected void setBoundsPrivate(int x, int y, int width, int height) { |
520 |
final FramePeer peer = (FramePeer)getPeer(); |
|
521 |
if (peer != null) { |
|
522 |
peer.setBoundsPrivate(x, y, width, height); |
|
523 |
} |
|
524 |
} |
|
525 |
||
526 |
/** |
|
527 |
* Gets the bounds of this embedded frame as a rectangle specifying the |
|
528 |
* width, height and location relative to the native parent component. |
|
529 |
* <p> |
|
530 |
* setLocation() and setBounds() for EmbeddedFrame really don't move it |
|
531 |
* within the native parent. These methods always put embedded frame to |
|
532 |
* (0, 0) for backward compatibility. To allow getting location and size |
|
533 |
* of embedded frames getLocationPrivate() and getBoundsPrivate() were |
|
534 |
* introduced, and they work just the same way as getLocation() and getBounds() |
|
535 |
* for ususal, non-embedded components. |
|
536 |
* </p> |
|
537 |
* <p> |
|
538 |
* Using usual get/setLocation() and get/setBounds() together with new |
|
539 |
* get/setLocationPrivate() and get/setBoundsPrivate() is not recommended. |
|
540 |
* For example, calling getBoundsPrivate() after setLocation() works fine, |
|
541 |
* but getBounds() after setBoundsPrivate() may return unpredictable value. |
|
542 |
* </p> |
|
543 |
* @return a rectangle indicating this embedded frame's bounds |
|
544 |
* @see java.awt.Component#getBounds |
|
545 |
* @see #setLocationPrivate |
|
546 |
* @see #getLocationPrivate |
|
547 |
* @see #setBoundsPrivate |
|
548 |
* @since 1.6 |
|
549 |
*/ |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
7668
diff
changeset
|
550 |
@SuppressWarnings("deprecation") |
2 | 551 |
protected Rectangle getBoundsPrivate() { |
552 |
final FramePeer peer = (FramePeer)getPeer(); |
|
553 |
if (peer != null) { |
|
554 |
return peer.getBoundsPrivate(); |
|
555 |
} |
|
556 |
else { |
|
557 |
return getBounds(); |
|
558 |
} |
|
559 |
} |
|
560 |
||
561 |
public void toFront() {} |
|
562 |
public void toBack() {} |
|
563 |
||
564 |
public abstract void registerAccelerator(AWTKeyStroke stroke); |
|
565 |
public abstract void unregisterAccelerator(AWTKeyStroke stroke); |
|
566 |
||
567 |
/** |
|
568 |
* Checks if the component is in an EmbeddedFrame. If so, |
|
569 |
* returns the applet found in the hierarchy or null if |
|
570 |
* not found. |
|
571 |
* @return the parent applet or {@ null} |
|
572 |
* @since 1.6 |
|
573 |
*/ |
|
574 |
public static Applet getAppletIfAncestorOf(Component comp) { |
|
575 |
Container parent = comp.getParent(); |
|
576 |
Applet applet = null; |
|
577 |
while (parent != null && !(parent instanceof EmbeddedFrame)) { |
|
578 |
if (parent instanceof Applet) { |
|
579 |
applet = (Applet)parent; |
|
580 |
} |
|
581 |
parent = parent.getParent(); |
|
582 |
} |
|
583 |
return parent == null ? null : applet; |
|
584 |
} |
|
585 |
||
586 |
/** |
|
587 |
* This method should be overriden in subclasses. It is |
|
588 |
* called when window this frame is within should be blocked |
|
589 |
* by some modal dialog. |
|
590 |
*/ |
|
591 |
public void notifyModalBlocked(Dialog blocker, boolean blocked) { |
|
592 |
} |
|
593 |
||
594 |
private static class NullEmbeddedFramePeer |
|
595 |
extends NullComponentPeer implements FramePeer { |
|
596 |
public void setTitle(String title) {} |
|
597 |
public void setIconImage(Image im) {} |
|
598 |
public void updateIconImages() {} |
|
599 |
public void setMenuBar(MenuBar mb) {} |
|
600 |
public void setResizable(boolean resizeable) {} |
|
601 |
public void setState(int state) {} |
|
602 |
public int getState() { return Frame.NORMAL; } |
|
603 |
public void setMaximizedBounds(Rectangle b) {} |
|
604 |
public void toFront() {} |
|
605 |
public void toBack() {} |
|
606 |
public void updateFocusableWindowState() {} |
|
607 |
public void updateAlwaysOnTop() {} |
|
608 |
public void setAlwaysOnTop(boolean alwaysOnTop) {} |
|
609 |
public Component getGlobalHeavyweightFocusOwner() { return null; } |
|
610 |
public void setBoundsPrivate(int x, int y, int width, int height) { |
|
611 |
setBounds(x, y, width, height, SET_BOUNDS); |
|
612 |
} |
|
613 |
public Rectangle getBoundsPrivate() { |
|
614 |
return getBounds(); |
|
615 |
} |
|
616 |
public void setModalBlocked(Dialog blocker, boolean blocked) {} |
|
617 |
||
618 |
/** |
|
619 |
* @see java.awt.peer.ContainerPeer#restack |
|
620 |
*/ |
|
621 |
public void restack() { |
|
622 |
throw new UnsupportedOperationException(); |
|
623 |
} |
|
624 |
||
625 |
/** |
|
626 |
* @see java.awt.peer.ContainerPeer#isRestackSupported |
|
627 |
*/ |
|
628 |
public boolean isRestackSupported() { |
|
629 |
return false; |
|
630 |
} |
|
631 |
public boolean requestWindowFocus() { |
|
632 |
return false; |
|
633 |
} |
|
634 |
public void updateMinimumSize() { |
|
635 |
} |
|
2451 | 636 |
|
637 |
public void setOpacity(float opacity) { |
|
638 |
} |
|
2648 | 639 |
|
2451 | 640 |
public void setOpaque(boolean isOpaque) { |
641 |
} |
|
2648 | 642 |
|
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2648
diff
changeset
|
643 |
public void updateWindow() { |
2451 | 644 |
} |
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2648
diff
changeset
|
645 |
|
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
2451
diff
changeset
|
646 |
public void repositionSecurityWarning() { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
2451
diff
changeset
|
647 |
} |
2451 | 648 |
} |
2 | 649 |
} // class EmbeddedFrame |