author | anthony |
Thu, 14 Oct 2010 18:59:15 +0400 | |
changeset 6827 | ee4403d28487 |
parent 5506 | 202f599c92aa |
child 7154 | 4e8371f358ac |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1995, 2009, 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 |
package java.awt; |
|
26 |
||
27 |
import java.awt.dnd.DropTarget; |
|
28 |
||
29 |
import java.awt.event.*; |
|
30 |
||
31 |
import java.awt.peer.ContainerPeer; |
|
32 |
import java.awt.peer.ComponentPeer; |
|
33 |
import java.awt.peer.LightweightPeer; |
|
34 |
||
35 |
import java.beans.PropertyChangeListener; |
|
36 |
||
37 |
import java.io.IOException; |
|
38 |
import java.io.ObjectInputStream; |
|
39 |
import java.io.ObjectOutputStream; |
|
40 |
import java.io.ObjectStreamField; |
|
41 |
import java.io.PrintStream; |
|
42 |
import java.io.PrintWriter; |
|
43 |
||
44 |
import java.util.Arrays; |
|
45 |
import java.util.EventListener; |
|
46 |
import java.util.HashSet; |
|
47 |
import java.util.Set; |
|
48 |
||
49 |
import javax.accessibility.*; |
|
50 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
51 |
import sun.util.logging.PlatformLogger; |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
52 |
|
2 | 53 |
import sun.awt.AppContext; |
54 |
import sun.awt.CausedFocusEvent; |
|
55 |
import sun.awt.PeerEvent; |
|
56 |
import sun.awt.SunToolkit; |
|
57 |
||
58 |
import sun.awt.dnd.SunDropTargetEvent; |
|
59 |
||
60 |
import sun.java2d.pipe.Region; |
|
61 |
||
62 |
/** |
|
63 |
* A generic Abstract Window Toolkit(AWT) container object is a component |
|
64 |
* that can contain other AWT components. |
|
65 |
* <p> |
|
66 |
* Components added to a container are tracked in a list. The order |
|
67 |
* of the list will define the components' front-to-back stacking order |
|
68 |
* within the container. If no index is specified when adding a |
|
69 |
* component to a container, it will be added to the end of the list |
|
70 |
* (and hence to the bottom of the stacking order). |
|
71 |
* <p> |
|
72 |
* <b>Note</b>: For details on the focus subsystem, see |
|
73 |
* <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html"> |
|
74 |
* How to Use the Focus Subsystem</a>, |
|
75 |
* a section in <em>The Java Tutorial</em>, and the |
|
76 |
* <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a> |
|
77 |
* for more information. |
|
78 |
* |
|
79 |
* @author Arthur van Hoff |
|
80 |
* @author Sami Shaio |
|
81 |
* @see #add(java.awt.Component, int) |
|
82 |
* @see #getComponent(int) |
|
83 |
* @see LayoutManager |
|
84 |
* @since JDK1.0 |
|
85 |
*/ |
|
86 |
public class Container extends Component { |
|
87 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
88 |
private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Container"); |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
89 |
private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Container"); |
2 | 90 |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
91 |
private static final Component[] EMPTY_ARRAY = new Component[0]; |
2 | 92 |
|
93 |
/** |
|
94 |
* The components in this container. |
|
95 |
* @see #add |
|
96 |
* @see #getComponents |
|
97 |
*/ |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
98 |
private java.util.List<Component> component = new java.util.ArrayList<Component>(); |
2 | 99 |
|
100 |
/** |
|
101 |
* Layout manager for this container. |
|
102 |
* @see #doLayout |
|
103 |
* @see #setLayout |
|
104 |
* @see #getLayout |
|
105 |
*/ |
|
106 |
LayoutManager layoutMgr; |
|
107 |
||
108 |
/** |
|
109 |
* Event router for lightweight components. If this container |
|
110 |
* is native, this dispatcher takes care of forwarding and |
|
111 |
* retargeting the events to lightweight components contained |
|
112 |
* (if any). |
|
113 |
*/ |
|
114 |
private LightweightDispatcher dispatcher; |
|
115 |
||
116 |
/** |
|
117 |
* The focus traversal policy that will manage keyboard traversal of this |
|
118 |
* Container's children, if this Container is a focus cycle root. If the |
|
119 |
* value is null, this Container inherits its policy from its focus-cycle- |
|
120 |
* root ancestor. If all such ancestors of this Container have null |
|
121 |
* policies, then the current KeyboardFocusManager's default policy is |
|
122 |
* used. If the value is non-null, this policy will be inherited by all |
|
123 |
* focus-cycle-root children that have no keyboard-traversal policy of |
|
124 |
* their own (as will, recursively, their focus-cycle-root children). |
|
125 |
* <p> |
|
126 |
* If this Container is not a focus cycle root, the value will be |
|
127 |
* remembered, but will not be used or inherited by this or any other |
|
128 |
* Containers until this Container is made a focus cycle root. |
|
129 |
* |
|
130 |
* @see #setFocusTraversalPolicy |
|
131 |
* @see #getFocusTraversalPolicy |
|
132 |
* @since 1.4 |
|
133 |
*/ |
|
134 |
private transient FocusTraversalPolicy focusTraversalPolicy; |
|
135 |
||
136 |
/** |
|
137 |
* Indicates whether this Component is the root of a focus traversal cycle. |
|
138 |
* Once focus enters a traversal cycle, typically it cannot leave it via |
|
139 |
* focus traversal unless one of the up- or down-cycle keys is pressed. |
|
140 |
* Normal traversal is limited to this Container, and all of this |
|
141 |
* Container's descendants that are not descendants of inferior focus cycle |
|
142 |
* roots. |
|
143 |
* |
|
144 |
* @see #setFocusCycleRoot |
|
145 |
* @see #isFocusCycleRoot |
|
146 |
* @since 1.4 |
|
147 |
*/ |
|
148 |
private boolean focusCycleRoot = false; |
|
149 |
||
150 |
||
151 |
/** |
|
152 |
* Stores the value of focusTraversalPolicyProvider property. |
|
153 |
* @since 1.5 |
|
154 |
* @see #setFocusTraversalPolicyProvider |
|
155 |
*/ |
|
156 |
private boolean focusTraversalPolicyProvider; |
|
157 |
||
158 |
// keeps track of the threads that are printing this component |
|
159 |
private transient Set printingThreads; |
|
160 |
// True if there is at least one thread that's printing this component |
|
161 |
private transient boolean printing = false; |
|
162 |
||
163 |
transient ContainerListener containerListener; |
|
164 |
||
165 |
/* HierarchyListener and HierarchyBoundsListener support */ |
|
166 |
transient int listeningChildren; |
|
167 |
transient int listeningBoundsChildren; |
|
168 |
transient int descendantsCount; |
|
169 |
||
2451 | 170 |
/* Non-opaque window support -- see Window.setLayersOpaque */ |
171 |
transient Color preserveBackgroundColor = null; |
|
172 |
||
2 | 173 |
/** |
174 |
* JDK 1.1 serialVersionUID |
|
175 |
*/ |
|
176 |
private static final long serialVersionUID = 4613797578919906343L; |
|
177 |
||
178 |
/** |
|
179 |
* A constant which toggles one of the controllable behaviors |
|
180 |
* of <code>getMouseEventTarget</code>. It is used to specify whether |
|
181 |
* the method can return the Container on which it is originally called |
|
182 |
* in case if none of its children are the current mouse event targets. |
|
183 |
* |
|
184 |
* @see #getMouseEventTarget(int, int, boolean, boolean, boolean) |
|
185 |
*/ |
|
186 |
static final boolean INCLUDE_SELF = true; |
|
187 |
||
188 |
/** |
|
189 |
* A constant which toggles one of the controllable behaviors |
|
190 |
* of <code>getMouseEventTarget</code>. It is used to specify whether |
|
191 |
* the method should search only lightweight components. |
|
192 |
* |
|
193 |
* @see #getMouseEventTarget(int, int, boolean, boolean, boolean) |
|
194 |
*/ |
|
195 |
static final boolean SEARCH_HEAVYWEIGHTS = true; |
|
196 |
||
197 |
/* |
|
198 |
* Number of HW or LW components in this container (including |
|
199 |
* all descendant containers). |
|
200 |
*/ |
|
201 |
private transient int numOfHWComponents = 0; |
|
202 |
private transient int numOfLWComponents = 0; |
|
203 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
204 |
private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Container"); |
2 | 205 |
|
206 |
/** |
|
207 |
* @serialField ncomponents int |
|
208 |
* The number of components in this container. |
|
209 |
* This value can be null. |
|
210 |
* @serialField component Component[] |
|
211 |
* The components in this container. |
|
212 |
* @serialField layoutMgr LayoutManager |
|
213 |
* Layout manager for this container. |
|
214 |
* @serialField dispatcher LightweightDispatcher |
|
215 |
* Event router for lightweight components. If this container |
|
216 |
* is native, this dispatcher takes care of forwarding and |
|
217 |
* retargeting the events to lightweight components contained |
|
218 |
* (if any). |
|
219 |
* @serialField maxSize Dimension |
|
220 |
* Maximum size of this Container. |
|
221 |
* @serialField focusCycleRoot boolean |
|
222 |
* Indicates whether this Component is the root of a focus traversal cycle. |
|
223 |
* Once focus enters a traversal cycle, typically it cannot leave it via |
|
224 |
* focus traversal unless one of the up- or down-cycle keys is pressed. |
|
225 |
* Normal traversal is limited to this Container, and all of this |
|
226 |
* Container's descendants that are not descendants of inferior focus cycle |
|
227 |
* roots. |
|
228 |
* @serialField containerSerializedDataVersion int |
|
229 |
* Container Serial Data Version. |
|
230 |
* @serialField focusTraversalPolicyProvider boolean |
|
231 |
* Stores the value of focusTraversalPolicyProvider property. |
|
232 |
*/ |
|
233 |
private static final ObjectStreamField[] serialPersistentFields = { |
|
234 |
new ObjectStreamField("ncomponents", Integer.TYPE), |
|
235 |
new ObjectStreamField("component", Component[].class), |
|
236 |
new ObjectStreamField("layoutMgr", LayoutManager.class), |
|
237 |
new ObjectStreamField("dispatcher", LightweightDispatcher.class), |
|
238 |
new ObjectStreamField("maxSize", Dimension.class), |
|
239 |
new ObjectStreamField("focusCycleRoot", Boolean.TYPE), |
|
240 |
new ObjectStreamField("containerSerializedDataVersion", Integer.TYPE), |
|
241 |
new ObjectStreamField("focusTraversalPolicyProvider", Boolean.TYPE), |
|
242 |
}; |
|
243 |
||
244 |
static { |
|
245 |
/* ensure that the necessary native libraries are loaded */ |
|
246 |
Toolkit.loadLibraries(); |
|
247 |
if (!GraphicsEnvironment.isHeadless()) { |
|
248 |
initIDs(); |
|
249 |
} |
|
250 |
} |
|
251 |
||
252 |
/** |
|
253 |
* Initialize JNI field and method IDs for fields that may be |
|
254 |
called from C. |
|
255 |
*/ |
|
256 |
private static native void initIDs(); |
|
257 |
||
258 |
/** |
|
259 |
* Constructs a new Container. Containers can be extended directly, |
|
260 |
* but are lightweight in this case and must be contained by a parent |
|
261 |
* somewhere higher up in the component tree that is native. |
|
262 |
* (such as Frame for example). |
|
263 |
*/ |
|
264 |
public Container() { |
|
265 |
} |
|
266 |
||
267 |
void initializeFocusTraversalKeys() { |
|
268 |
focusTraversalKeys = new Set[4]; |
|
269 |
} |
|
270 |
||
271 |
/** |
|
272 |
* Gets the number of components in this panel. |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
273 |
* <p> |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
274 |
* Note: This method should be called under AWT tree lock. |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
275 |
* |
2 | 276 |
* @return the number of components in this panel. |
277 |
* @see #getComponent |
|
278 |
* @since JDK1.1 |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
279 |
* @see Component#getTreeLock() |
2 | 280 |
*/ |
281 |
public int getComponentCount() { |
|
282 |
return countComponents(); |
|
283 |
} |
|
284 |
||
285 |
/** |
|
286 |
* @deprecated As of JDK version 1.1, |
|
287 |
* replaced by getComponentCount(). |
|
288 |
*/ |
|
289 |
@Deprecated |
|
290 |
public int countComponents() { |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
291 |
// This method is not synchronized under AWT tree lock. |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
292 |
// Instead, the calling code is responsible for the |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
293 |
// synchronization. See 6784816 for details. |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
294 |
return component.size(); |
2 | 295 |
} |
296 |
||
297 |
/** |
|
298 |
* Gets the nth component in this container. |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
299 |
* <p> |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
300 |
* Note: This method should be called under AWT tree lock. |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
301 |
* |
2 | 302 |
* @param n the index of the component to get. |
303 |
* @return the n<sup>th</sup> component in this container. |
|
304 |
* @exception ArrayIndexOutOfBoundsException |
|
305 |
* if the n<sup>th</sup> value does not exist. |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
306 |
* @see Component#getTreeLock() |
2 | 307 |
*/ |
308 |
public Component getComponent(int n) { |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
309 |
// This method is not synchronized under AWT tree lock. |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
310 |
// Instead, the calling code is responsible for the |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
311 |
// synchronization. See 6784816 for details. |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
312 |
try { |
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
313 |
return component.get(n); |
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
314 |
} catch (IndexOutOfBoundsException z) { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
315 |
throw new ArrayIndexOutOfBoundsException("No such child: " + n); |
2 | 316 |
} |
317 |
} |
|
318 |
||
319 |
/** |
|
320 |
* Gets all the components in this container. |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
321 |
* <p> |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
322 |
* Note: This method should be called under AWT tree lock. |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
323 |
* |
2 | 324 |
* @return an array of all the components in this container. |
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
325 |
* @see Component#getTreeLock() |
2 | 326 |
*/ |
327 |
public Component[] getComponents() { |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
328 |
// This method is not synchronized under AWT tree lock. |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
329 |
// Instead, the calling code is responsible for the |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
330 |
// synchronization. See 6784816 for details. |
2 | 331 |
return getComponents_NoClientCode(); |
332 |
} |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
333 |
|
2 | 334 |
// NOTE: This method may be called by privileged threads. |
335 |
// This functionality is implemented in a package-private method |
|
336 |
// to insure that it cannot be overridden by client subclasses. |
|
337 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
338 |
final Component[] getComponents_NoClientCode() { |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
339 |
return component.toArray(EMPTY_ARRAY); |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
340 |
} |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
341 |
|
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
342 |
/* |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
343 |
* Wrapper for getComponents() method with a proper synchronization. |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
344 |
*/ |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
345 |
Component[] getComponentsSync() { |
2 | 346 |
synchronized (getTreeLock()) { |
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
347 |
return getComponents(); |
2 | 348 |
} |
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
349 |
} |
2 | 350 |
|
351 |
/** |
|
352 |
* Determines the insets of this container, which indicate the size |
|
353 |
* of the container's border. |
|
354 |
* <p> |
|
355 |
* A <code>Frame</code> object, for example, has a top inset that |
|
356 |
* corresponds to the height of the frame's title bar. |
|
357 |
* @return the insets of this container. |
|
358 |
* @see Insets |
|
359 |
* @see LayoutManager |
|
360 |
* @since JDK1.1 |
|
361 |
*/ |
|
362 |
public Insets getInsets() { |
|
363 |
return insets(); |
|
364 |
} |
|
365 |
||
366 |
/** |
|
367 |
* @deprecated As of JDK version 1.1, |
|
368 |
* replaced by <code>getInsets()</code>. |
|
369 |
*/ |
|
370 |
@Deprecated |
|
371 |
public Insets insets() { |
|
372 |
ComponentPeer peer = this.peer; |
|
373 |
if (peer instanceof ContainerPeer) { |
|
374 |
ContainerPeer cpeer = (ContainerPeer)peer; |
|
1964 | 375 |
return (Insets)cpeer.getInsets().clone(); |
2 | 376 |
} |
377 |
return new Insets(0, 0, 0, 0); |
|
378 |
} |
|
379 |
||
380 |
/** |
|
381 |
* Appends the specified component to the end of this container. |
|
382 |
* This is a convenience method for {@link #addImpl}. |
|
383 |
* <p> |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
384 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
385 |
* invalidates the component hierarchy. If the container has already been |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
386 |
* displayed, the hierarchy must be validated thereafter in order to |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
387 |
* display the added component. |
2 | 388 |
* |
389 |
* @param comp the component to be added |
|
390 |
* @exception NullPointerException if {@code comp} is {@code null} |
|
391 |
* @see #addImpl |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
392 |
* @see #invalidate |
2 | 393 |
* @see #validate |
394 |
* @see javax.swing.JComponent#revalidate() |
|
395 |
* @return the component argument |
|
396 |
*/ |
|
397 |
public Component add(Component comp) { |
|
398 |
addImpl(comp, null, -1); |
|
399 |
return comp; |
|
400 |
} |
|
401 |
||
402 |
/** |
|
403 |
* Adds the specified component to this container. |
|
404 |
* This is a convenience method for {@link #addImpl}. |
|
405 |
* <p> |
|
406 |
* This method is obsolete as of 1.1. Please use the |
|
407 |
* method <code>add(Component, Object)</code> instead. |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
408 |
* <p> |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
409 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
410 |
* invalidates the component hierarchy. If the container has already been |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
411 |
* displayed, the hierarchy must be validated thereafter in order to |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
412 |
* display the added component. |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
413 |
* |
2 | 414 |
* @exception NullPointerException if {@code comp} is {@code null} |
415 |
* @see #add(Component, Object) |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
416 |
* @see #invalidate |
2 | 417 |
*/ |
418 |
public Component add(String name, Component comp) { |
|
419 |
addImpl(comp, name, -1); |
|
420 |
return comp; |
|
421 |
} |
|
422 |
||
423 |
/** |
|
424 |
* Adds the specified component to this container at the given |
|
425 |
* position. |
|
426 |
* This is a convenience method for {@link #addImpl}. |
|
427 |
* <p> |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
428 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
429 |
* invalidates the component hierarchy. If the container has already been |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
430 |
* displayed, the hierarchy must be validated thereafter in order to |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
431 |
* display the added component. |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
432 |
* |
2 | 433 |
* |
434 |
* @param comp the component to be added |
|
435 |
* @param index the position at which to insert the component, |
|
436 |
* or <code>-1</code> to append the component to the end |
|
437 |
* @exception NullPointerException if {@code comp} is {@code null} |
|
438 |
* @exception IllegalArgumentException if {@code index} is invalid (see |
|
439 |
* {@link #addImpl} for details) |
|
440 |
* @return the component <code>comp</code> |
|
441 |
* @see #addImpl |
|
442 |
* @see #remove |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
443 |
* @see #invalidate |
2 | 444 |
* @see #validate |
445 |
* @see javax.swing.JComponent#revalidate() |
|
446 |
*/ |
|
447 |
public Component add(Component comp, int index) { |
|
448 |
addImpl(comp, null, index); |
|
449 |
return comp; |
|
450 |
} |
|
451 |
||
452 |
/** |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
453 |
* Checks that the component |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
454 |
* isn't supposed to be added into itself. |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
455 |
*/ |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
456 |
private void checkAddToSelf(Component comp){ |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
457 |
if (comp instanceof Container) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
458 |
for (Container cn = this; cn != null; cn=cn.parent) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
459 |
if (cn == comp) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
460 |
throw new IllegalArgumentException("adding container's parent to itself"); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
461 |
} |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
462 |
} |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
463 |
} |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
464 |
} |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
465 |
|
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
466 |
/** |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
467 |
* Checks that the component is not a Window instance. |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
468 |
*/ |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
469 |
private void checkNotAWindow(Component comp){ |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
470 |
if (comp instanceof Window) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
471 |
throw new IllegalArgumentException("adding a window to a container"); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
472 |
} |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
473 |
} |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
474 |
|
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
475 |
/** |
2 | 476 |
* Checks that the component comp can be added to this container |
477 |
* Checks : index in bounds of container's size, |
|
478 |
* comp is not one of this container's parents, |
|
479 |
* and comp is not a window. |
|
480 |
* Comp and container must be on the same GraphicsDevice. |
|
481 |
* if comp is container, all sub-components must be on |
|
482 |
* same GraphicsDevice. |
|
483 |
* |
|
484 |
* @since 1.5 |
|
485 |
*/ |
|
486 |
private void checkAdding(Component comp, int index) { |
|
487 |
checkTreeLock(); |
|
488 |
||
489 |
GraphicsConfiguration thisGC = getGraphicsConfiguration(); |
|
490 |
||
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
491 |
if (index > component.size() || index < 0) { |
2 | 492 |
throw new IllegalArgumentException("illegal component position"); |
493 |
} |
|
494 |
if (comp.parent == this) { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
495 |
if (index == component.size()) { |
2 | 496 |
throw new IllegalArgumentException("illegal component position " + |
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
497 |
index + " should be less then " + component.size()); |
2 | 498 |
} |
499 |
} |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
500 |
checkAddToSelf(comp); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
501 |
checkNotAWindow(comp); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
502 |
|
2 | 503 |
Window thisTopLevel = getContainingWindow(); |
504 |
Window compTopLevel = comp.getContainingWindow(); |
|
505 |
if (thisTopLevel != compTopLevel) { |
|
506 |
throw new IllegalArgumentException("component and container should be in the same top-level window"); |
|
507 |
} |
|
508 |
if (thisGC != null) { |
|
509 |
comp.checkGD(thisGC.getDevice().getIDstring()); |
|
510 |
} |
|
511 |
} |
|
512 |
||
513 |
/** |
|
514 |
* Removes component comp from this container without making unneccessary changes |
|
515 |
* and generating unneccessary events. This function intended to perform optimized |
|
516 |
* remove, for example, if newParent and current parent are the same it just changes |
|
517 |
* index without calling removeNotify. |
|
518 |
* Note: Should be called while holding treeLock |
|
519 |
* Returns whether removeNotify was invoked |
|
520 |
* @since: 1.5 |
|
521 |
*/ |
|
522 |
private boolean removeDelicately(Component comp, Container newParent, int newIndex) { |
|
523 |
checkTreeLock(); |
|
524 |
||
525 |
int index = getComponentZOrder(comp); |
|
526 |
boolean needRemoveNotify = isRemoveNotifyNeeded(comp, this, newParent); |
|
527 |
if (needRemoveNotify) { |
|
528 |
comp.removeNotify(); |
|
529 |
} |
|
530 |
if (newParent != this) { |
|
531 |
if (layoutMgr != null) { |
|
532 |
layoutMgr.removeLayoutComponent(comp); |
|
533 |
} |
|
534 |
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, |
|
535 |
-comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
536 |
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, |
|
537 |
-comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)); |
|
538 |
adjustDescendants(-(comp.countHierarchyMembers())); |
|
539 |
||
540 |
comp.parent = null; |
|
2461 | 541 |
if (needRemoveNotify) { |
542 |
comp.setGraphicsConfiguration(null); |
|
543 |
} |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
544 |
component.remove(index); |
2 | 545 |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
546 |
invalidateIfValid(); |
2 | 547 |
} else { |
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
548 |
// We should remove component and then |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
549 |
// add it by the newIndex without newIndex decrement if even we shift components to the left |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
550 |
// after remove. Consult the rules below: |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
551 |
// 2->4: 012345 -> 013425, 2->5: 012345 -> 013452 |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
552 |
// 4->2: 012345 -> 014235 |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
553 |
component.remove(index); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
554 |
component.add(newIndex, comp); |
2 | 555 |
} |
556 |
if (comp.parent == null) { // was actually removed |
|
557 |
if (containerListener != null || |
|
558 |
(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 || |
|
559 |
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) { |
|
560 |
ContainerEvent e = new ContainerEvent(this, |
|
561 |
ContainerEvent.COMPONENT_REMOVED, |
|
562 |
comp); |
|
563 |
dispatchEvent(e); |
|
564 |
||
565 |
} |
|
566 |
comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp, |
|
567 |
this, HierarchyEvent.PARENT_CHANGED, |
|
568 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
569 |
if (peer != null && layoutMgr == null && isVisible()) { |
|
570 |
updateCursorImmediately(); |
|
571 |
} |
|
572 |
} |
|
573 |
return needRemoveNotify; |
|
574 |
} |
|
575 |
||
576 |
/** |
|
577 |
* Checks whether this container can contain component which is focus owner. |
|
578 |
* Verifies that container is enable and showing, and if it is focus cycle root |
|
579 |
* its FTP allows component to be focus owner |
|
580 |
* @since 1.5 |
|
581 |
*/ |
|
582 |
boolean canContainFocusOwner(Component focusOwnerCandidate) { |
|
583 |
if (!(isEnabled() && isDisplayable() |
|
584 |
&& isVisible() && isFocusable())) |
|
585 |
{ |
|
586 |
return false; |
|
587 |
} |
|
588 |
if (isFocusCycleRoot()) { |
|
589 |
FocusTraversalPolicy policy = getFocusTraversalPolicy(); |
|
590 |
if (policy instanceof DefaultFocusTraversalPolicy) { |
|
591 |
if (!((DefaultFocusTraversalPolicy)policy).accept(focusOwnerCandidate)) { |
|
592 |
return false; |
|
593 |
} |
|
594 |
} |
|
595 |
} |
|
596 |
synchronized(getTreeLock()) { |
|
597 |
if (parent != null) { |
|
598 |
return parent.canContainFocusOwner(focusOwnerCandidate); |
|
599 |
} |
|
600 |
} |
|
601 |
return true; |
|
602 |
} |
|
603 |
||
604 |
/** |
|
605 |
* Checks whether or not this container has heavyweight children. |
|
606 |
* Note: Should be called while holding tree lock |
|
607 |
* @return true if there is at least one heavyweight children in a container, false otherwise |
|
608 |
* @since 1.5 |
|
609 |
*/ |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
610 |
final boolean hasHeavyweightDescendants() { |
2 | 611 |
checkTreeLock(); |
612 |
return numOfHWComponents > 0; |
|
613 |
} |
|
614 |
||
615 |
/** |
|
616 |
* Checks whether or not this container has lightweight children. |
|
617 |
* Note: Should be called while holding tree lock |
|
618 |
* @return true if there is at least one lightweight children in a container, false otherwise |
|
619 |
* @since 1.7 |
|
620 |
*/ |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
621 |
final boolean hasLightweightDescendants() { |
2 | 622 |
checkTreeLock(); |
623 |
return numOfLWComponents > 0; |
|
624 |
} |
|
625 |
||
626 |
/** |
|
627 |
* Returns closest heavyweight component to this container. If this container is heavyweight |
|
628 |
* returns this. |
|
629 |
* @since 1.5 |
|
630 |
*/ |
|
631 |
Container getHeavyweightContainer() { |
|
632 |
checkTreeLock(); |
|
633 |
if (peer != null && !(peer instanceof LightweightPeer)) { |
|
634 |
return this; |
|
635 |
} else { |
|
636 |
return getNativeContainer(); |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
/** |
|
641 |
* Detects whether or not remove from current parent and adding to new parent requires call of |
|
642 |
* removeNotify on the component. Since removeNotify destroys native window this might (not) |
|
643 |
* be required. For example, if new container and old containers are the same we don't need to |
|
644 |
* destroy native window. |
|
645 |
* @since: 1.5 |
|
646 |
*/ |
|
647 |
private static boolean isRemoveNotifyNeeded(Component comp, Container oldContainer, Container newContainer) { |
|
648 |
if (oldContainer == null) { // Component didn't have parent - no removeNotify |
|
649 |
return false; |
|
650 |
} |
|
651 |
if (comp.peer == null) { // Component didn't have peer - no removeNotify |
|
652 |
return false; |
|
653 |
} |
|
654 |
if (newContainer.peer == null) { |
|
655 |
// Component has peer but new Container doesn't - call removeNotify |
|
656 |
return true; |
|
657 |
} |
|
658 |
||
659 |
// If component is lightweight non-Container or lightweight Container with all but heavyweight |
|
660 |
// children there is no need to call remove notify |
|
661 |
if (comp.isLightweight()) { |
|
662 |
boolean isContainer = comp instanceof Container; |
|
663 |
||
664 |
if (!isContainer || (isContainer && !((Container)comp).hasHeavyweightDescendants())) { |
|
665 |
return false; |
|
666 |
} |
|
667 |
} |
|
668 |
||
669 |
// If this point is reached, then the comp is either a HW or a LW container with HW descendants. |
|
670 |
||
671 |
// All three components have peers, check for peer change |
|
672 |
Container newNativeContainer = oldContainer.getHeavyweightContainer(); |
|
673 |
Container oldNativeContainer = newContainer.getHeavyweightContainer(); |
|
674 |
if (newNativeContainer != oldNativeContainer) { |
|
675 |
// Native containers change - check whether or not current platform supports |
|
676 |
// changing of widget hierarchy on native level without recreation. |
|
677 |
// The current implementation forbids reparenting of LW containers with HW descendants |
|
678 |
// into another native container w/o destroying the peers. Actually such an operation |
|
679 |
// is quite rare. If we ever need to save the peers, we'll have to slightly change the |
|
680 |
// addDelicately() method in order to handle such LW containers recursively, reparenting |
|
681 |
// each HW descendant independently. |
|
682 |
return !comp.peer.isReparentSupported(); |
|
683 |
} else { |
|
2462
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2461
diff
changeset
|
684 |
return false; |
2 | 685 |
} |
686 |
} |
|
687 |
||
688 |
/** |
|
689 |
* Moves the specified component to the specified z-order index in |
|
690 |
* the container. The z-order determines the order that components |
|
691 |
* are painted; the component with the highest z-order paints first |
|
692 |
* and the component with the lowest z-order paints last. |
|
693 |
* Where components overlap, the component with the lower |
|
694 |
* z-order paints over the component with the higher z-order. |
|
695 |
* <p> |
|
696 |
* If the component is a child of some other container, it is |
|
697 |
* removed from that container before being added to this container. |
|
698 |
* The important difference between this method and |
|
699 |
* <code>java.awt.Container.add(Component, int)</code> is that this method |
|
700 |
* doesn't call <code>removeNotify</code> on the component while |
|
701 |
* removing it from its previous container unless necessary and when |
|
702 |
* allowed by the underlying native windowing system. This way, if the |
|
703 |
* component has the keyboard focus, it maintains the focus when |
|
704 |
* moved to the new position. |
|
705 |
* <p> |
|
706 |
* This property is guaranteed to apply only to lightweight |
|
707 |
* non-<code>Container</code> components. |
|
708 |
* <p> |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
709 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
710 |
* invalidates the component hierarchy. |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
711 |
* <p> |
2 | 712 |
* <b>Note</b>: Not all platforms support changing the z-order of |
713 |
* heavyweight components from one container into another without |
|
714 |
* the call to <code>removeNotify</code>. There is no way to detect |
|
715 |
* whether a platform supports this, so developers shouldn't make |
|
716 |
* any assumptions. |
|
717 |
* |
|
718 |
* @param comp the component to be moved |
|
719 |
* @param index the position in the container's list to |
|
720 |
* insert the component, where <code>getComponentCount()</code> |
|
721 |
* appends to the end |
|
722 |
* @exception NullPointerException if <code>comp</code> is |
|
723 |
* <code>null</code> |
|
724 |
* @exception IllegalArgumentException if <code>comp</code> is one of the |
|
725 |
* container's parents |
|
726 |
* @exception IllegalArgumentException if <code>index</code> is not in |
|
727 |
* the range <code>[0, getComponentCount()]</code> for moving |
|
728 |
* between containers, or not in the range |
|
729 |
* <code>[0, getComponentCount()-1]</code> for moving inside |
|
730 |
* a container |
|
731 |
* @exception IllegalArgumentException if adding a container to itself |
|
732 |
* @exception IllegalArgumentException if adding a <code>Window</code> |
|
733 |
* to a container |
|
734 |
* @see #getComponentZOrder(java.awt.Component) |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
735 |
* @see #invalidate |
2 | 736 |
* @since 1.5 |
737 |
*/ |
|
738 |
public void setComponentZOrder(Component comp, int index) { |
|
739 |
synchronized (getTreeLock()) { |
|
740 |
// Store parent because remove will clear it |
|
741 |
Container curParent = comp.parent; |
|
742 |
int oldZindex = getComponentZOrder(comp); |
|
743 |
||
744 |
if (curParent == this && index == oldZindex) { |
|
745 |
return; |
|
746 |
} |
|
747 |
checkAdding(comp, index); |
|
748 |
||
749 |
boolean peerRecreated = (curParent != null) ? |
|
750 |
curParent.removeDelicately(comp, this, index) : false; |
|
751 |
||
752 |
addDelicately(comp, curParent, index); |
|
753 |
||
754 |
// If the oldZindex == -1, the component gets inserted, |
|
755 |
// rather than it changes its z-order. |
|
756 |
if (!peerRecreated && oldZindex != -1) { |
|
757 |
// The new 'index' cannot be == -1. |
|
758 |
// It gets checked at the checkAdding() method. |
|
759 |
// Therefore both oldZIndex and index denote |
|
760 |
// some existing positions at this point and |
|
761 |
// this is actually a Z-order changing. |
|
762 |
comp.mixOnZOrderChanging(oldZindex, index); |
|
763 |
} |
|
764 |
} |
|
765 |
} |
|
766 |
||
767 |
/** |
|
768 |
* Traverses the tree of components and reparents children heavyweight component |
|
769 |
* to new heavyweight parent. |
|
770 |
* @since 1.5 |
|
771 |
*/ |
|
772 |
private void reparentTraverse(ContainerPeer parentPeer, Container child) { |
|
773 |
checkTreeLock(); |
|
774 |
||
775 |
for (int i = 0; i < child.getComponentCount(); i++) { |
|
776 |
Component comp = child.getComponent(i); |
|
777 |
if (comp.isLightweight()) { |
|
778 |
// If components is lightweight check if it is container |
|
779 |
// If it is container it might contain heavyweight children we need to reparent |
|
780 |
if (comp instanceof Container) { |
|
781 |
reparentTraverse(parentPeer, (Container)comp); |
|
782 |
} |
|
783 |
} else { |
|
784 |
// Q: Need to update NativeInLightFixer? |
|
785 |
comp.getPeer().reparent(parentPeer); |
|
786 |
} |
|
787 |
} |
|
788 |
} |
|
789 |
||
790 |
/** |
|
791 |
* Reparents child component peer to this container peer. |
|
792 |
* Container must be heavyweight. |
|
793 |
* @since 1.5 |
|
794 |
*/ |
|
795 |
private void reparentChild(Component comp) { |
|
796 |
checkTreeLock(); |
|
797 |
if (comp == null) { |
|
798 |
return; |
|
799 |
} |
|
800 |
if (comp.isLightweight()) { |
|
801 |
// If component is lightweight container we need to reparent all its explicit heavyweight children |
|
802 |
if (comp instanceof Container) { |
|
803 |
// Traverse component's tree till depth-first until encountering heavyweight component |
|
804 |
reparentTraverse((ContainerPeer)getPeer(), (Container)comp); |
|
805 |
} |
|
806 |
} else { |
|
807 |
comp.getPeer().reparent((ContainerPeer)getPeer()); |
|
808 |
} |
|
809 |
} |
|
810 |
||
811 |
/** |
|
812 |
* Adds component to this container. Tries to minimize side effects of this adding - |
|
813 |
* doesn't call remove notify if it is not required. |
|
814 |
* @since 1.5 |
|
815 |
*/ |
|
816 |
private void addDelicately(Component comp, Container curParent, int index) { |
|
817 |
checkTreeLock(); |
|
818 |
||
819 |
// Check if moving between containers |
|
820 |
if (curParent != this) { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
821 |
//index == -1 means add to the end. |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
822 |
if (index == -1) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
823 |
component.add(comp); |
2 | 824 |
} else { |
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
825 |
component.add(index, comp); |
2 | 826 |
} |
827 |
comp.parent = this; |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
828 |
comp.setGraphicsConfiguration(getGraphicsConfiguration()); |
2 | 829 |
|
830 |
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, |
|
831 |
comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
832 |
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, |
|
833 |
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)); |
|
834 |
adjustDescendants(comp.countHierarchyMembers()); |
|
835 |
} else { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
836 |
if (index < component.size()) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
837 |
component.set(index, comp); |
2 | 838 |
} |
839 |
} |
|
840 |
||
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
841 |
invalidateIfValid(); |
2 | 842 |
if (peer != null) { |
843 |
if (comp.peer == null) { // Remove notify was called or it didn't have peer - create new one |
|
844 |
comp.addNotify(); |
|
845 |
} else { // Both container and child have peers, it means child peer should be reparented. |
|
846 |
// In both cases we need to reparent native widgets. |
|
847 |
Container newNativeContainer = getHeavyweightContainer(); |
|
848 |
Container oldNativeContainer = curParent.getHeavyweightContainer(); |
|
849 |
if (oldNativeContainer != newNativeContainer) { |
|
850 |
// Native container changed - need to reparent native widgets |
|
851 |
newNativeContainer.reparentChild(comp); |
|
852 |
} |
|
2647
ea80a312972e
6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents:
2644
diff
changeset
|
853 |
comp.updateZOrder(); |
2462
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2461
diff
changeset
|
854 |
|
2 | 855 |
if (!comp.isLightweight() && isLightweight()) { |
856 |
// If component is heavyweight and one of the containers is lightweight |
|
130 | 857 |
// the location of the component should be fixed. |
858 |
comp.relocateComponent(); |
|
2 | 859 |
} |
860 |
} |
|
861 |
} |
|
862 |
if (curParent != this) { |
|
863 |
/* Notify the layout manager of the added component. */ |
|
864 |
if (layoutMgr != null) { |
|
865 |
if (layoutMgr instanceof LayoutManager2) { |
|
866 |
((LayoutManager2)layoutMgr).addLayoutComponent(comp, null); |
|
867 |
} else { |
|
868 |
layoutMgr.addLayoutComponent(null, comp); |
|
869 |
} |
|
870 |
} |
|
871 |
if (containerListener != null || |
|
872 |
(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 || |
|
873 |
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) { |
|
874 |
ContainerEvent e = new ContainerEvent(this, |
|
875 |
ContainerEvent.COMPONENT_ADDED, |
|
876 |
comp); |
|
877 |
dispatchEvent(e); |
|
878 |
} |
|
879 |
comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp, |
|
880 |
this, HierarchyEvent.PARENT_CHANGED, |
|
881 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
882 |
||
883 |
// If component is focus owner or parent container of focus owner check that after reparenting |
|
884 |
// focus owner moved out if new container prohibit this kind of focus owner. |
|
1171
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
441
diff
changeset
|
885 |
if (comp.isFocusOwner() && !comp.canBeFocusOwnerRecursively()) { |
2 | 886 |
comp.transferFocus(); |
887 |
} else if (comp instanceof Container) { |
|
888 |
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); |
|
1171
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
441
diff
changeset
|
889 |
if (focusOwner != null && isParentOf(focusOwner) && !focusOwner.canBeFocusOwnerRecursively()) { |
2 | 890 |
focusOwner.transferFocus(); |
891 |
} |
|
892 |
} |
|
893 |
} else { |
|
894 |
comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp, |
|
895 |
this, HierarchyEvent.HIERARCHY_CHANGED, |
|
896 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
897 |
} |
|
898 |
||
899 |
if (peer != null && layoutMgr == null && isVisible()) { |
|
900 |
updateCursorImmediately(); |
|
901 |
} |
|
902 |
} |
|
903 |
||
904 |
/** |
|
905 |
* Returns the z-order index of the component inside the container. |
|
906 |
* The higher a component is in the z-order hierarchy, the lower |
|
907 |
* its index. The component with the lowest z-order index is |
|
908 |
* painted last, above all other child components. |
|
909 |
* |
|
910 |
* @param comp the component being queried |
|
911 |
* @return the z-order index of the component; otherwise |
|
912 |
* returns -1 if the component is <code>null</code> |
|
913 |
* or doesn't belong to the container |
|
914 |
* @see #setComponentZOrder(java.awt.Component, int) |
|
915 |
* @since 1.5 |
|
916 |
*/ |
|
917 |
public int getComponentZOrder(Component comp) { |
|
918 |
if (comp == null) { |
|
919 |
return -1; |
|
920 |
} |
|
921 |
synchronized(getTreeLock()) { |
|
922 |
// Quick check - container should be immediate parent of the component |
|
923 |
if (comp.parent != this) { |
|
924 |
return -1; |
|
925 |
} |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
926 |
return component.indexOf(comp); |
2 | 927 |
} |
928 |
} |
|
929 |
||
930 |
/** |
|
931 |
* Adds the specified component to the end of this container. |
|
932 |
* Also notifies the layout manager to add the component to |
|
933 |
* this container's layout using the specified constraints object. |
|
934 |
* This is a convenience method for {@link #addImpl}. |
|
935 |
* <p> |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
936 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
937 |
* invalidates the component hierarchy. If the container has already been |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
938 |
* displayed, the hierarchy must be validated thereafter in order to |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
939 |
* display the added component. |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
940 |
* |
2 | 941 |
* |
942 |
* @param comp the component to be added |
|
943 |
* @param constraints an object expressing |
|
944 |
* layout contraints for this component |
|
945 |
* @exception NullPointerException if {@code comp} is {@code null} |
|
946 |
* @see #addImpl |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
947 |
* @see #invalidate |
2 | 948 |
* @see #validate |
949 |
* @see javax.swing.JComponent#revalidate() |
|
950 |
* @see LayoutManager |
|
951 |
* @since JDK1.1 |
|
952 |
*/ |
|
953 |
public void add(Component comp, Object constraints) { |
|
954 |
addImpl(comp, constraints, -1); |
|
955 |
} |
|
956 |
||
957 |
/** |
|
958 |
* Adds the specified component to this container with the specified |
|
959 |
* constraints at the specified index. Also notifies the layout |
|
960 |
* manager to add the component to the this container's layout using |
|
961 |
* the specified constraints object. |
|
962 |
* This is a convenience method for {@link #addImpl}. |
|
963 |
* <p> |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
964 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
965 |
* invalidates the component hierarchy. If the container has already been |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
966 |
* displayed, the hierarchy must be validated thereafter in order to |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
967 |
* display the added component. |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
968 |
* |
2 | 969 |
* |
970 |
* @param comp the component to be added |
|
971 |
* @param constraints an object expressing layout contraints for this |
|
972 |
* @param index the position in the container's list at which to insert |
|
973 |
* the component; <code>-1</code> means insert at the end |
|
974 |
* component |
|
975 |
* @exception NullPointerException if {@code comp} is {@code null} |
|
976 |
* @exception IllegalArgumentException if {@code index} is invalid (see |
|
977 |
* {@link #addImpl} for details) |
|
978 |
* @see #addImpl |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
979 |
* @see #invalidate |
2 | 980 |
* @see #validate |
981 |
* @see javax.swing.JComponent#revalidate() |
|
982 |
* @see #remove |
|
983 |
* @see LayoutManager |
|
984 |
*/ |
|
985 |
public void add(Component comp, Object constraints, int index) { |
|
986 |
addImpl(comp, constraints, index); |
|
987 |
} |
|
988 |
||
989 |
/** |
|
990 |
* Adds the specified component to this container at the specified |
|
991 |
* index. This method also notifies the layout manager to add |
|
992 |
* the component to this container's layout using the specified |
|
993 |
* constraints object via the <code>addLayoutComponent</code> |
|
994 |
* method. |
|
995 |
* <p> |
|
996 |
* The constraints are |
|
997 |
* defined by the particular layout manager being used. For |
|
998 |
* example, the <code>BorderLayout</code> class defines five |
|
999 |
* constraints: <code>BorderLayout.NORTH</code>, |
|
1000 |
* <code>BorderLayout.SOUTH</code>, <code>BorderLayout.EAST</code>, |
|
1001 |
* <code>BorderLayout.WEST</code>, and <code>BorderLayout.CENTER</code>. |
|
1002 |
* <p> |
|
1003 |
* The <code>GridBagLayout</code> class requires a |
|
1004 |
* <code>GridBagConstraints</code> object. Failure to pass |
|
1005 |
* the correct type of constraints object results in an |
|
1006 |
* <code>IllegalArgumentException</code>. |
|
1007 |
* <p> |
|
1008 |
* If the current layout manager implements {@code LayoutManager2}, then |
|
1009 |
* {@link LayoutManager2#addLayoutComponent(Component,Object)} is invoked on |
|
1010 |
* it. If the current layout manager does not implement |
|
1011 |
* {@code LayoutManager2}, and constraints is a {@code String}, then |
|
1012 |
* {@link LayoutManager#addLayoutComponent(String,Component)} is invoked on it. |
|
1013 |
* <p> |
|
1014 |
* If the component is not an ancestor of this container and has a non-null |
|
1015 |
* parent, it is removed from its current parent before it is added to this |
|
1016 |
* container. |
|
1017 |
* <p> |
|
1018 |
* This is the method to override if a program needs to track |
|
1019 |
* every add request to a container as all other add methods defer |
|
1020 |
* to this one. An overriding method should |
|
1021 |
* usually include a call to the superclass's version of the method: |
|
1022 |
* <p> |
|
1023 |
* <blockquote> |
|
1024 |
* <code>super.addImpl(comp, constraints, index)</code> |
|
1025 |
* </blockquote> |
|
1026 |
* <p> |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1027 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1028 |
* invalidates the component hierarchy. If the container has already been |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1029 |
* displayed, the hierarchy must be validated thereafter in order to |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1030 |
* display the added component. |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1031 |
* |
2 | 1032 |
* @param comp the component to be added |
1033 |
* @param constraints an object expressing layout constraints |
|
1034 |
* for this component |
|
1035 |
* @param index the position in the container's list at which to |
|
1036 |
* insert the component, where <code>-1</code> |
|
1037 |
* means append to the end |
|
1038 |
* @exception IllegalArgumentException if {@code index} is invalid; |
|
1039 |
* if {@code comp} is a child of this container, the valid |
|
1040 |
* range is {@code [-1, getComponentCount()-1]}; if component is |
|
1041 |
* not a child of this container, the valid range is |
|
1042 |
* {@code [-1, getComponentCount()]} |
|
1043 |
* |
|
1044 |
* @exception IllegalArgumentException if {@code comp} is an ancestor of |
|
1045 |
* this container |
|
1046 |
* @exception IllegalArgumentException if adding a window to a container |
|
1047 |
* @exception NullPointerException if {@code comp} is {@code null} |
|
1048 |
* @see #add(Component) |
|
1049 |
* @see #add(Component, int) |
|
1050 |
* @see #add(Component, java.lang.Object) |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1051 |
* @see #invalidate |
2 | 1052 |
* @see LayoutManager |
1053 |
* @see LayoutManager2 |
|
1054 |
* @since JDK1.1 |
|
1055 |
*/ |
|
1056 |
protected void addImpl(Component comp, Object constraints, int index) { |
|
1057 |
synchronized (getTreeLock()) { |
|
1058 |
/* Check for correct arguments: index in bounds, |
|
1059 |
* comp cannot be one of this container's parents, |
|
1060 |
* and comp cannot be a window. |
|
1061 |
* comp and container must be on the same GraphicsDevice. |
|
1062 |
* if comp is container, all sub-components must be on |
|
1063 |
* same GraphicsDevice. |
|
1064 |
*/ |
|
1065 |
GraphicsConfiguration thisGC = this.getGraphicsConfiguration(); |
|
1066 |
||
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1067 |
if (index > component.size() || (index < 0 && index != -1)) { |
2 | 1068 |
throw new IllegalArgumentException( |
1069 |
"illegal component position"); |
|
1070 |
} |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1071 |
checkAddToSelf(comp); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1072 |
checkNotAWindow(comp); |
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
1073 |
if (thisGC != null) { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
1074 |
comp.checkGD(thisGC.getDevice().getIDstring()); |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
1075 |
} |
2 | 1076 |
|
1077 |
/* Reparent the component and tidy up the tree's state. */ |
|
1078 |
if (comp.parent != null) { |
|
1079 |
comp.parent.remove(comp); |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1080 |
if (index > component.size()) { |
2 | 1081 |
throw new IllegalArgumentException("illegal component position"); |
1082 |
} |
|
1083 |
} |
|
1084 |
||
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1085 |
//index == -1 means add to the end. |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1086 |
if (index == -1) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1087 |
component.add(comp); |
2 | 1088 |
} else { |
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1089 |
component.add(index, comp); |
2 | 1090 |
} |
1091 |
comp.parent = this; |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1092 |
comp.setGraphicsConfiguration(thisGC); |
2 | 1093 |
|
1094 |
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, |
|
1095 |
comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
1096 |
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, |
|
1097 |
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)); |
|
1098 |
adjustDescendants(comp.countHierarchyMembers()); |
|
1099 |
||
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
1100 |
invalidateIfValid(); |
2 | 1101 |
if (peer != null) { |
1102 |
comp.addNotify(); |
|
1103 |
} |
|
1104 |
||
1105 |
/* Notify the layout manager of the added component. */ |
|
1106 |
if (layoutMgr != null) { |
|
1107 |
if (layoutMgr instanceof LayoutManager2) { |
|
1108 |
((LayoutManager2)layoutMgr).addLayoutComponent(comp, constraints); |
|
1109 |
} else if (constraints instanceof String) { |
|
1110 |
layoutMgr.addLayoutComponent((String)constraints, comp); |
|
1111 |
} |
|
1112 |
} |
|
1113 |
if (containerListener != null || |
|
1114 |
(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 || |
|
1115 |
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) { |
|
1116 |
ContainerEvent e = new ContainerEvent(this, |
|
1117 |
ContainerEvent.COMPONENT_ADDED, |
|
1118 |
comp); |
|
1119 |
dispatchEvent(e); |
|
1120 |
} |
|
1121 |
||
1122 |
comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp, |
|
1123 |
this, HierarchyEvent.PARENT_CHANGED, |
|
1124 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
1125 |
if (peer != null && layoutMgr == null && isVisible()) { |
|
1126 |
updateCursorImmediately(); |
|
1127 |
} |
|
1128 |
} |
|
1129 |
} |
|
1130 |
||
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1131 |
@Override |
2805
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1132 |
boolean updateGraphicsData(GraphicsConfiguration gc) { |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1133 |
checkTreeLock(); |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1134 |
|
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1135 |
boolean ret = super.updateGraphicsData(gc); |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1136 |
|
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1137 |
for (Component comp : component) { |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1138 |
if (comp != null) { |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1139 |
ret |= comp.updateGraphicsData(gc); |
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1140 |
} |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1141 |
} |
2805
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1142 |
return ret; |
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1143 |
} |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1144 |
|
2 | 1145 |
/** |
1146 |
* Checks that all Components that this Container contains are on |
|
1147 |
* the same GraphicsDevice as this Container. If not, throws an |
|
1148 |
* IllegalArgumentException. |
|
1149 |
*/ |
|
1150 |
void checkGD(String stringID) { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1151 |
for (Component comp : component) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1152 |
if (comp != null) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1153 |
comp.checkGD(stringID); |
2 | 1154 |
} |
1155 |
} |
|
1156 |
} |
|
1157 |
||
1158 |
/** |
|
1159 |
* Removes the component, specified by <code>index</code>, |
|
1160 |
* from this container. |
|
1161 |
* This method also notifies the layout manager to remove the |
|
1162 |
* component from this container's layout via the |
|
1163 |
* <code>removeLayoutComponent</code> method. |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1164 |
* <p> |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1165 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1166 |
* invalidates the component hierarchy. If the container has already been |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1167 |
* displayed, the hierarchy must be validated thereafter in order to |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1168 |
* reflect the changes. |
2 | 1169 |
* |
1170 |
* |
|
1171 |
* @param index the index of the component to be removed |
|
1172 |
* @throws ArrayIndexOutOfBoundsException if {@code index} is not in |
|
1173 |
* range {@code [0, getComponentCount()-1]} |
|
1174 |
* @see #add |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1175 |
* @see #invalidate |
2 | 1176 |
* @see #validate |
1177 |
* @see #getComponentCount |
|
1178 |
* @since JDK1.1 |
|
1179 |
*/ |
|
1180 |
public void remove(int index) { |
|
1181 |
synchronized (getTreeLock()) { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1182 |
if (index < 0 || index >= component.size()) { |
2 | 1183 |
throw new ArrayIndexOutOfBoundsException(index); |
1184 |
} |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1185 |
Component comp = component.get(index); |
2 | 1186 |
if (peer != null) { |
1187 |
comp.removeNotify(); |
|
1188 |
} |
|
1189 |
if (layoutMgr != null) { |
|
1190 |
layoutMgr.removeLayoutComponent(comp); |
|
1191 |
} |
|
1192 |
||
1193 |
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, |
|
1194 |
-comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
1195 |
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, |
|
1196 |
-comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)); |
|
1197 |
adjustDescendants(-(comp.countHierarchyMembers())); |
|
1198 |
||
1199 |
comp.parent = null; |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1200 |
component.remove(index); |
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1201 |
comp.setGraphicsConfiguration(null); |
2 | 1202 |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
1203 |
invalidateIfValid(); |
2 | 1204 |
if (containerListener != null || |
1205 |
(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 || |
|
1206 |
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) { |
|
1207 |
ContainerEvent e = new ContainerEvent(this, |
|
1208 |
ContainerEvent.COMPONENT_REMOVED, |
|
1209 |
comp); |
|
1210 |
dispatchEvent(e); |
|
1211 |
} |
|
1212 |
||
1213 |
comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp, |
|
1214 |
this, HierarchyEvent.PARENT_CHANGED, |
|
1215 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
1216 |
if (peer != null && layoutMgr == null && isVisible()) { |
|
1217 |
updateCursorImmediately(); |
|
1218 |
} |
|
1219 |
} |
|
1220 |
} |
|
1221 |
||
1222 |
/** |
|
1223 |
* Removes the specified component from this container. |
|
1224 |
* This method also notifies the layout manager to remove the |
|
1225 |
* component from this container's layout via the |
|
1226 |
* <code>removeLayoutComponent</code> method. |
|
1227 |
* <p> |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1228 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1229 |
* invalidates the component hierarchy. If the container has already been |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1230 |
* displayed, the hierarchy must be validated thereafter in order to |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1231 |
* reflect the changes. |
2 | 1232 |
* |
1233 |
* @param comp the component to be removed |
|
1234 |
* @see #add |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1235 |
* @see #invalidate |
2 | 1236 |
* @see #validate |
1237 |
* @see #remove(int) |
|
1238 |
*/ |
|
1239 |
public void remove(Component comp) { |
|
1240 |
synchronized (getTreeLock()) { |
|
1241 |
if (comp.parent == this) { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1242 |
int index = component.indexOf(comp); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1243 |
if (index >= 0) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1244 |
remove(index); |
2 | 1245 |
} |
1246 |
} |
|
1247 |
} |
|
1248 |
} |
|
1249 |
||
1250 |
/** |
|
1251 |
* Removes all the components from this container. |
|
1252 |
* This method also notifies the layout manager to remove the |
|
1253 |
* components from this container's layout via the |
|
1254 |
* <code>removeLayoutComponent</code> method. |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1255 |
* <p> |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1256 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1257 |
* invalidates the component hierarchy. If the container has already been |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1258 |
* displayed, the hierarchy must be validated thereafter in order to |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1259 |
* reflect the changes. |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1260 |
* |
2 | 1261 |
* @see #add |
1262 |
* @see #remove |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1263 |
* @see #invalidate |
2 | 1264 |
*/ |
1265 |
public void removeAll() { |
|
1266 |
synchronized (getTreeLock()) { |
|
1267 |
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, |
|
1268 |
-listeningChildren); |
|
1269 |
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, |
|
1270 |
-listeningBoundsChildren); |
|
1271 |
adjustDescendants(-descendantsCount); |
|
1272 |
||
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1273 |
while (!component.isEmpty()) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1274 |
Component comp = component.remove(component.size()-1); |
2 | 1275 |
|
1276 |
if (peer != null) { |
|
1277 |
comp.removeNotify(); |
|
1278 |
} |
|
1279 |
if (layoutMgr != null) { |
|
1280 |
layoutMgr.removeLayoutComponent(comp); |
|
1281 |
} |
|
1282 |
comp.parent = null; |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1283 |
comp.setGraphicsConfiguration(null); |
2 | 1284 |
if (containerListener != null || |
1285 |
(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 || |
|
1286 |
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) { |
|
1287 |
ContainerEvent e = new ContainerEvent(this, |
|
1288 |
ContainerEvent.COMPONENT_REMOVED, |
|
1289 |
comp); |
|
1290 |
dispatchEvent(e); |
|
1291 |
} |
|
1292 |
||
1293 |
comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, |
|
1294 |
comp, this, |
|
1295 |
HierarchyEvent.PARENT_CHANGED, |
|
1296 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
1297 |
} |
|
1298 |
if (peer != null && layoutMgr == null && isVisible()) { |
|
1299 |
updateCursorImmediately(); |
|
1300 |
} |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
1301 |
invalidateIfValid(); |
2 | 1302 |
} |
1303 |
} |
|
1304 |
||
1305 |
// Should only be called while holding tree lock |
|
1306 |
int numListening(long mask) { |
|
1307 |
int superListening = super.numListening(mask); |
|
1308 |
||
1309 |
if (mask == AWTEvent.HIERARCHY_EVENT_MASK) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1310 |
if (eventLog.isLoggable(PlatformLogger.FINE)) { |
2 | 1311 |
// Verify listeningChildren is correct |
1312 |
int sum = 0; |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1313 |
for (Component comp : component) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1314 |
sum += comp.numListening(mask); |
2 | 1315 |
} |
1316 |
if (listeningChildren != sum) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1317 |
eventLog.fine("Assertion (listeningChildren == sum) failed"); |
2 | 1318 |
} |
1319 |
} |
|
1320 |
return listeningChildren + superListening; |
|
1321 |
} else if (mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1322 |
if (eventLog.isLoggable(PlatformLogger.FINE)) { |
2 | 1323 |
// Verify listeningBoundsChildren is correct |
1324 |
int sum = 0; |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1325 |
for (Component comp : component) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1326 |
sum += comp.numListening(mask); |
2 | 1327 |
} |
1328 |
if (listeningBoundsChildren != sum) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1329 |
eventLog.fine("Assertion (listeningBoundsChildren == sum) failed"); |
2 | 1330 |
} |
1331 |
} |
|
1332 |
return listeningBoundsChildren + superListening; |
|
1333 |
} else { |
|
1334 |
// assert false; |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1335 |
if (eventLog.isLoggable(PlatformLogger.FINE)) { |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1336 |
eventLog.fine("This code must never be reached"); |
2 | 1337 |
} |
1338 |
return superListening; |
|
1339 |
} |
|
1340 |
} |
|
1341 |
||
1342 |
// Should only be called while holding tree lock |
|
1343 |
void adjustListeningChildren(long mask, int num) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1344 |
if (eventLog.isLoggable(PlatformLogger.FINE)) { |
2 | 1345 |
boolean toAssert = (mask == AWTEvent.HIERARCHY_EVENT_MASK || |
1346 |
mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK || |
|
1347 |
mask == (AWTEvent.HIERARCHY_EVENT_MASK | |
|
1348 |
AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)); |
|
1349 |
if (!toAssert) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1350 |
eventLog.fine("Assertion failed"); |
2 | 1351 |
} |
1352 |
} |
|
1353 |
||
1354 |
if (num == 0) |
|
1355 |
return; |
|
1356 |
||
1357 |
if ((mask & AWTEvent.HIERARCHY_EVENT_MASK) != 0) { |
|
1358 |
listeningChildren += num; |
|
1359 |
} |
|
1360 |
if ((mask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0) { |
|
1361 |
listeningBoundsChildren += num; |
|
1362 |
} |
|
1363 |
||
1364 |
adjustListeningChildrenOnParent(mask, num); |
|
1365 |
} |
|
1366 |
||
1367 |
// Should only be called while holding tree lock |
|
1368 |
void adjustDescendants(int num) { |
|
1369 |
if (num == 0) |
|
1370 |
return; |
|
1371 |
||
1372 |
descendantsCount += num; |
|
1373 |
adjustDecendantsOnParent(num); |
|
1374 |
} |
|
1375 |
||
1376 |
// Should only be called while holding tree lock |
|
1377 |
void adjustDecendantsOnParent(int num) { |
|
1378 |
if (parent != null) { |
|
1379 |
parent.adjustDescendants(num); |
|
1380 |
} |
|
1381 |
} |
|
1382 |
||
1383 |
// Should only be called while holding tree lock |
|
1384 |
int countHierarchyMembers() { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1385 |
if (log.isLoggable(PlatformLogger.FINE)) { |
2 | 1386 |
// Verify descendantsCount is correct |
1387 |
int sum = 0; |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1388 |
for (Component comp : component) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1389 |
sum += comp.countHierarchyMembers(); |
2 | 1390 |
} |
1391 |
if (descendantsCount != sum) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1392 |
log.fine("Assertion (descendantsCount == sum) failed"); |
2 | 1393 |
} |
1394 |
} |
|
1395 |
return descendantsCount + 1; |
|
1396 |
} |
|
1397 |
||
1398 |
private int getListenersCount(int id, boolean enabledOnToolkit) { |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
1399 |
checkTreeLock(); |
2 | 1400 |
if (enabledOnToolkit) { |
1401 |
return descendantsCount; |
|
1402 |
} |
|
1403 |
switch (id) { |
|
1404 |
case HierarchyEvent.HIERARCHY_CHANGED: |
|
1405 |
return listeningChildren; |
|
1406 |
case HierarchyEvent.ANCESTOR_MOVED: |
|
1407 |
case HierarchyEvent.ANCESTOR_RESIZED: |
|
1408 |
return listeningBoundsChildren; |
|
1409 |
default: |
|
1410 |
return 0; |
|
1411 |
} |
|
1412 |
} |
|
1413 |
||
1414 |
final int createHierarchyEvents(int id, Component changed, |
|
1415 |
Container changedParent, long changeFlags, boolean enabledOnToolkit) |
|
1416 |
{ |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
1417 |
checkTreeLock(); |
2 | 1418 |
int listeners = getListenersCount(id, enabledOnToolkit); |
1419 |
||
1420 |
for (int count = listeners, i = 0; count > 0; i++) { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1421 |
count -= component.get(i).createHierarchyEvents(id, changed, |
2 | 1422 |
changedParent, changeFlags, enabledOnToolkit); |
1423 |
} |
|
1424 |
return listeners + |
|
1425 |
super.createHierarchyEvents(id, changed, changedParent, |
|
1426 |
changeFlags, enabledOnToolkit); |
|
1427 |
} |
|
1428 |
||
1429 |
final void createChildHierarchyEvents(int id, long changeFlags, |
|
1430 |
boolean enabledOnToolkit) |
|
1431 |
{ |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
1432 |
checkTreeLock(); |
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1433 |
if (component.isEmpty()) { |
2 | 1434 |
return; |
1435 |
} |
|
1436 |
int listeners = getListenersCount(id, enabledOnToolkit); |
|
1437 |
||
1438 |
for (int count = listeners, i = 0; count > 0; i++) { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1439 |
count -= component.get(i).createHierarchyEvents(id, this, parent, |
2 | 1440 |
changeFlags, enabledOnToolkit); |
1441 |
} |
|
1442 |
} |
|
1443 |
||
1444 |
/** |
|
1445 |
* Gets the layout manager for this container. |
|
1446 |
* @see #doLayout |
|
1447 |
* @see #setLayout |
|
1448 |
*/ |
|
1449 |
public LayoutManager getLayout() { |
|
1450 |
return layoutMgr; |
|
1451 |
} |
|
1452 |
||
1453 |
/** |
|
1454 |
* Sets the layout manager for this container. |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1455 |
* <p> |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1456 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1457 |
* invalidates the component hierarchy. |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1458 |
* |
2 | 1459 |
* @param mgr the specified layout manager |
1460 |
* @see #doLayout |
|
1461 |
* @see #getLayout |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1462 |
* @see #invalidate |
2 | 1463 |
*/ |
1464 |
public void setLayout(LayoutManager mgr) { |
|
1465 |
layoutMgr = mgr; |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
1466 |
invalidateIfValid(); |
2 | 1467 |
} |
1468 |
||
1469 |
/** |
|
1470 |
* Causes this container to lay out its components. Most programs |
|
1471 |
* should not call this method directly, but should invoke |
|
1472 |
* the <code>validate</code> method instead. |
|
1473 |
* @see LayoutManager#layoutContainer |
|
1474 |
* @see #setLayout |
|
1475 |
* @see #validate |
|
1476 |
* @since JDK1.1 |
|
1477 |
*/ |
|
1478 |
public void doLayout() { |
|
1479 |
layout(); |
|
1480 |
} |
|
1481 |
||
1482 |
/** |
|
1483 |
* @deprecated As of JDK version 1.1, |
|
1484 |
* replaced by <code>doLayout()</code>. |
|
1485 |
*/ |
|
1486 |
@Deprecated |
|
1487 |
public void layout() { |
|
1488 |
LayoutManager layoutMgr = this.layoutMgr; |
|
1489 |
if (layoutMgr != null) { |
|
1490 |
layoutMgr.layoutContainer(this); |
|
1491 |
} |
|
1492 |
} |
|
1493 |
||
1494 |
/** |
|
4261 | 1495 |
* Indicates if this container is a <i>validate root</i>. |
1496 |
* <p> |
|
1497 |
* Layout-related changes, such as bounds of the validate root descendants, |
|
1498 |
* do not affect the layout of the validate root parent. This peculiarity |
|
1499 |
* enables the {@code invalidate()} method to stop invalidating the |
|
1500 |
* component hierarchy when the method encounters a validate root. |
|
1501 |
* <p> |
|
1502 |
* If a component hierarchy contains validate roots, the {@code validate()} |
|
1503 |
* method must be invoked on the validate root of a previously invalidated |
|
1504 |
* component, rather than on the top-level container (such as a {@code |
|
1505 |
* Frame} object) to restore the validity of the hierarchy later. |
|
1506 |
* <p> |
|
1507 |
* The {@code Window} class and the {@code Applet} class are the validate |
|
1508 |
* roots in AWT. Swing introduces more validate roots. |
|
2 | 1509 |
* |
4261 | 1510 |
* @return whether this container is a validate root |
1511 |
* @see #invalidate |
|
1512 |
* @see java.awt.Component#invalidate |
|
1513 |
* @see javax.swing.JComponent#isValidateRoot |
|
1514 |
* @see javax.swing.JComponent#revalidate |
|
1515 |
* @since 1.7 |
|
1516 |
*/ |
|
1517 |
public boolean isValidateRoot() { |
|
1518 |
return false; |
|
1519 |
} |
|
1520 |
||
1521 |
/** |
|
1522 |
* Invalidates the parent of the container unless the container |
|
1523 |
* is a validate root. |
|
1524 |
*/ |
|
1525 |
@Override |
|
1526 |
void invalidateParent() { |
|
1527 |
if (!isValidateRoot()) { |
|
1528 |
super.invalidateParent(); |
|
1529 |
} |
|
1530 |
} |
|
1531 |
||
1532 |
/** |
|
1533 |
* Invalidates the container. |
|
1534 |
* <p> |
|
1535 |
* If the {@code LayoutManager} installed on this container is an instance |
|
1536 |
* of the {@code LayoutManager2} interface, then |
|
1537 |
* the {@link LayoutManager2#invalidateLayout(Container)} method is invoked |
|
1538 |
* on it supplying this {@code Container} as the argument. |
|
1539 |
* <p> |
|
1540 |
* Afterwards this method marks this container invalid, and invalidates its |
|
1541 |
* ancestors. See the {@link Component#invalidate} method for more details. |
|
2 | 1542 |
* |
1543 |
* @see #validate |
|
1544 |
* @see #layout |
|
4261 | 1545 |
* @see LayoutManager2 |
2 | 1546 |
*/ |
4261 | 1547 |
@Override |
2 | 1548 |
public void invalidate() { |
1549 |
LayoutManager layoutMgr = this.layoutMgr; |
|
1550 |
if (layoutMgr instanceof LayoutManager2) { |
|
1551 |
LayoutManager2 lm = (LayoutManager2) layoutMgr; |
|
1552 |
lm.invalidateLayout(this); |
|
1553 |
} |
|
1554 |
super.invalidate(); |
|
1555 |
} |
|
1556 |
||
1557 |
/** |
|
1558 |
* Validates this container and all of its subcomponents. |
|
1559 |
* <p> |
|
4261 | 1560 |
* Validating a container means laying out its subcomponents. |
1561 |
* Layout-related changes, such as setting the bounds of a component, or |
|
1562 |
* adding a component to the container, invalidate the container |
|
1563 |
* automatically. Note that the ancestors of the container may be |
|
1564 |
* invalidated also (see {@link Component#invalidate} for details.) |
|
1565 |
* Therefore, to restore the validity of the hierarchy, the {@code |
|
1566 |
* validate()} method should be invoked on a validate root of an |
|
1567 |
* invalidated component, or on the top-most container if the hierarchy |
|
1568 |
* does not contain validate roots. |
|
1569 |
* <p> |
|
1570 |
* Validating the container may be a quite time-consuming operation. For |
|
1571 |
* performance reasons a developer may postpone the validation of the |
|
1572 |
* hierarchy till a set of layout-related operations completes, e.g. after |
|
1573 |
* adding all the children to the container. |
|
1574 |
* <p> |
|
1575 |
* If this {@code Container} is not valid, this method invokes |
|
2 | 1576 |
* the {@code validateTree} method and marks this {@code Container} |
1577 |
* as valid. Otherwise, no action is performed. |
|
1578 |
* |
|
1579 |
* @see #add(java.awt.Component) |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1580 |
* @see #invalidate |
4261 | 1581 |
* @see Container#isValidateRoot |
2 | 1582 |
* @see javax.swing.JComponent#revalidate() |
1583 |
* @see #validateTree |
|
1584 |
*/ |
|
1585 |
public void validate() { |
|
4263
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1586 |
boolean updateCur = false; |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1587 |
synchronized (getTreeLock()) { |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1588 |
if ((!isValid() || descendUnconditionallyWhenValidating) |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1589 |
&& peer != null) |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1590 |
{ |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1591 |
ContainerPeer p = null; |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1592 |
if (peer instanceof ContainerPeer) { |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1593 |
p = (ContainerPeer) peer; |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1594 |
} |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1595 |
if (p != null) { |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1596 |
p.beginValidate(); |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1597 |
} |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1598 |
validateTree(); |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1599 |
if (p != null) { |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1600 |
p.endValidate(); |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1601 |
// Avoid updating cursor if this is an internal call. |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1602 |
// See validateUnconditionally() for details. |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1603 |
if (!descendUnconditionallyWhenValidating) { |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1604 |
updateCur = isVisible(); |
2 | 1605 |
} |
1606 |
} |
|
1607 |
} |
|
4263
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1608 |
} |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1609 |
if (updateCur) { |
db2d1f69a60e
6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents:
4261
diff
changeset
|
1610 |
updateCursorImmediately(); |
2 | 1611 |
} |
1612 |
} |
|
1613 |
||
1614 |
/** |
|
4261 | 1615 |
* Indicates whether valid containers should also traverse their |
1616 |
* children and call the validateTree() method on them. |
|
1617 |
* |
|
1618 |
* Synchronization: TreeLock. |
|
1619 |
* |
|
1620 |
* The field is allowed to be static as long as the TreeLock itself is |
|
1621 |
* static. |
|
1622 |
* |
|
1623 |
* @see #validateUnconditionally() |
|
1624 |
*/ |
|
1625 |
private static boolean descendUnconditionallyWhenValidating = false; |
|
1626 |
||
1627 |
/** |
|
1628 |
* Unconditionally validate the component hierarchy. |
|
1629 |
*/ |
|
1630 |
final void validateUnconditionally() { |
|
1631 |
boolean updateCur = false; |
|
1632 |
synchronized (getTreeLock()) { |
|
1633 |
descendUnconditionallyWhenValidating = true; |
|
1634 |
||
1635 |
validate(); |
|
1636 |
if (peer instanceof ContainerPeer) { |
|
1637 |
updateCur = isVisible(); |
|
1638 |
} |
|
1639 |
||
1640 |
descendUnconditionallyWhenValidating = false; |
|
1641 |
} |
|
1642 |
if (updateCur) { |
|
1643 |
updateCursorImmediately(); |
|
1644 |
} |
|
1645 |
} |
|
1646 |
||
1647 |
/** |
|
2 | 1648 |
* Recursively descends the container tree and recomputes the |
1649 |
* layout for any subtrees marked as needing it (those marked as |
|
1650 |
* invalid). Synchronization should be provided by the method |
|
1651 |
* that calls this one: <code>validate</code>. |
|
1652 |
* |
|
1653 |
* @see #doLayout |
|
1654 |
* @see #validate |
|
1655 |
*/ |
|
1656 |
protected void validateTree() { |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
1657 |
checkTreeLock(); |
4261 | 1658 |
if (!isValid() || descendUnconditionallyWhenValidating) { |
2 | 1659 |
if (peer instanceof ContainerPeer) { |
1660 |
((ContainerPeer)peer).beginLayout(); |
|
1661 |
} |
|
4261 | 1662 |
if (!isValid()) { |
1663 |
doLayout(); |
|
1664 |
} |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1665 |
for (int i = 0; i < component.size(); i++) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1666 |
Component comp = component.get(i); |
2 | 1667 |
if ( (comp instanceof Container) |
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1668 |
&& !(comp instanceof Window) |
4261 | 1669 |
&& (!comp.isValid() || |
1670 |
descendUnconditionallyWhenValidating)) |
|
1671 |
{ |
|
2 | 1672 |
((Container)comp).validateTree(); |
1673 |
} else { |
|
1674 |
comp.validate(); |
|
1675 |
} |
|
1676 |
} |
|
1677 |
if (peer instanceof ContainerPeer) { |
|
1678 |
((ContainerPeer)peer).endLayout(); |
|
1679 |
} |
|
1680 |
} |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
1681 |
super.validate(); |
2 | 1682 |
} |
1683 |
||
1684 |
/** |
|
1685 |
* Recursively descends the container tree and invalidates all |
|
1686 |
* contained components. |
|
1687 |
*/ |
|
1688 |
void invalidateTree() { |
|
1689 |
synchronized (getTreeLock()) { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1690 |
for (int i = 0; i < component.size(); i++) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
1691 |
Component comp = component.get(i); |
2 | 1692 |
if (comp instanceof Container) { |
1693 |
((Container)comp).invalidateTree(); |
|
1694 |
} |
|
1695 |
else { |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
1696 |
comp.invalidateIfValid(); |
2 | 1697 |
} |
1698 |
} |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
1699 |
invalidateIfValid(); |
2 | 1700 |
} |
1701 |
} |
|
1702 |
||
1703 |
/** |
|
1704 |
* Sets the font of this container. |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1705 |
* <p> |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1706 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1707 |
* invalidates the component hierarchy. |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1708 |
* |
2 | 1709 |
* @param f The font to become this container's font. |
1710 |
* @see Component#getFont |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
1711 |
* @see #invalidate |
2 | 1712 |
* @since JDK1.0 |
1713 |
*/ |
|
1714 |
public void setFont(Font f) { |
|
1715 |
boolean shouldinvalidate = false; |
|
1716 |
||
1717 |
Font oldfont = getFont(); |
|
1718 |
super.setFont(f); |
|
1719 |
Font newfont = getFont(); |
|
1720 |
if (newfont != oldfont && (oldfont == null || |
|
1721 |
!oldfont.equals(newfont))) { |
|
1722 |
invalidateTree(); |
|
1723 |
} |
|
1724 |
} |
|
1725 |
||
1726 |
/** |
|
1727 |
* Returns the preferred size of this container. If the preferred size has |
|
1728 |
* not been set explicitly by {@link Component#setPreferredSize(Dimension)} |
|
1729 |
* and this {@code Container} has a {@code non-null} {@link LayoutManager}, |
|
1730 |
* then {@link LayoutManager#preferredLayoutSize(Container)} |
|
1731 |
* is used to calculate the preferred size. |
|
1732 |
* |
|
1733 |
* <p>Note: some implementations may cache the value returned from the |
|
1734 |
* {@code LayoutManager}. Implementations that cache need not invoke |
|
1735 |
* {@code preferredLayoutSize} on the {@code LayoutManager} every time |
|
1736 |
* this method is invoked, rather the {@code LayoutManager} will only |
|
1737 |
* be queried after the {@code Container} becomes invalid. |
|
1738 |
* |
|
1739 |
* @return an instance of <code>Dimension</code> that represents |
|
1740 |
* the preferred size of this container. |
|
1741 |
* @see #getMinimumSize |
|
1742 |
* @see #getMaximumSize |
|
1743 |
* @see #getLayout |
|
1744 |
* @see LayoutManager#preferredLayoutSize(Container) |
|
1745 |
* @see Component#getPreferredSize |
|
1746 |
*/ |
|
1747 |
public Dimension getPreferredSize() { |
|
1748 |
return preferredSize(); |
|
1749 |
} |
|
1750 |
||
1751 |
/** |
|
1752 |
* @deprecated As of JDK version 1.1, |
|
1753 |
* replaced by <code>getPreferredSize()</code>. |
|
1754 |
*/ |
|
1755 |
@Deprecated |
|
1756 |
public Dimension preferredSize() { |
|
1757 |
/* Avoid grabbing the lock if a reasonable cached size value |
|
1758 |
* is available. |
|
1759 |
*/ |
|
1760 |
Dimension dim = prefSize; |
|
1761 |
if (dim == null || !(isPreferredSizeSet() || isValid())) { |
|
1762 |
synchronized (getTreeLock()) { |
|
1763 |
prefSize = (layoutMgr != null) ? |
|
1764 |
layoutMgr.preferredLayoutSize(this) : |
|
1765 |
super.preferredSize(); |
|
1766 |
dim = prefSize; |
|
1767 |
} |
|
1768 |
} |
|
1769 |
if (dim != null){ |
|
1770 |
return new Dimension(dim); |
|
1771 |
} |
|
1772 |
else{ |
|
1773 |
return dim; |
|
1774 |
} |
|
1775 |
} |
|
1776 |
||
1777 |
/** |
|
1778 |
* Returns the minimum size of this container. If the minimum size has |
|
1779 |
* not been set explicitly by {@link Component#setMinimumSize(Dimension)} |
|
1780 |
* and this {@code Container} has a {@code non-null} {@link LayoutManager}, |
|
1781 |
* then {@link LayoutManager#minimumLayoutSize(Container)} |
|
1782 |
* is used to calculate the minimum size. |
|
1783 |
* |
|
1784 |
* <p>Note: some implementations may cache the value returned from the |
|
1785 |
* {@code LayoutManager}. Implementations that cache need not invoke |
|
1786 |
* {@code minimumLayoutSize} on the {@code LayoutManager} every time |
|
1787 |
* this method is invoked, rather the {@code LayoutManager} will only |
|
1788 |
* be queried after the {@code Container} becomes invalid. |
|
1789 |
* |
|
1790 |
* @return an instance of <code>Dimension</code> that represents |
|
1791 |
* the minimum size of this container. |
|
1792 |
* @see #getPreferredSize |
|
1793 |
* @see #getMaximumSize |
|
1794 |
* @see #getLayout |
|
1795 |
* @see LayoutManager#minimumLayoutSize(Container) |
|
1796 |
* @see Component#getMinimumSize |
|
1797 |
* @since JDK1.1 |
|
1798 |
*/ |
|
1799 |
public Dimension getMinimumSize() { |
|
1800 |
return minimumSize(); |
|
1801 |
} |
|
1802 |
||
1803 |
/** |
|
1804 |
* @deprecated As of JDK version 1.1, |
|
1805 |
* replaced by <code>getMinimumSize()</code>. |
|
1806 |
*/ |
|
1807 |
@Deprecated |
|
1808 |
public Dimension minimumSize() { |
|
1809 |
/* Avoid grabbing the lock if a reasonable cached size value |
|
1810 |
* is available. |
|
1811 |
*/ |
|
1812 |
Dimension dim = minSize; |
|
1813 |
if (dim == null || !(isMinimumSizeSet() || isValid())) { |
|
1814 |
synchronized (getTreeLock()) { |
|
1815 |
minSize = (layoutMgr != null) ? |
|
1816 |
layoutMgr.minimumLayoutSize(this) : |
|
1817 |
super.minimumSize(); |
|
1818 |
dim = minSize; |
|
1819 |
} |
|
1820 |
} |
|
1821 |
if (dim != null){ |
|
1822 |
return new Dimension(dim); |
|
1823 |
} |
|
1824 |
else{ |
|
1825 |
return dim; |
|
1826 |
} |
|
1827 |
} |
|
1828 |
||
1829 |
/** |
|
1830 |
* Returns the maximum size of this container. If the maximum size has |
|
1831 |
* not been set explicitly by {@link Component#setMaximumSize(Dimension)} |
|
1832 |
* and the {@link LayoutManager} installed on this {@code Container} |
|
1833 |
* is an instance of {@link LayoutManager2}, then |
|
1834 |
* {@link LayoutManager2#maximumLayoutSize(Container)} |
|
1835 |
* is used to calculate the maximum size. |
|
1836 |
* |
|
1837 |
* <p>Note: some implementations may cache the value returned from the |
|
1838 |
* {@code LayoutManager2}. Implementations that cache need not invoke |
|
1839 |
* {@code maximumLayoutSize} on the {@code LayoutManager2} every time |
|
1840 |
* this method is invoked, rather the {@code LayoutManager2} will only |
|
1841 |
* be queried after the {@code Container} becomes invalid. |
|
1842 |
* |
|
1843 |
* @return an instance of <code>Dimension</code> that represents |
|
1844 |
* the maximum size of this container. |
|
1845 |
* @see #getPreferredSize |
|
1846 |
* @see #getMinimumSize |
|
1847 |
* @see #getLayout |
|
1848 |
* @see LayoutManager2#maximumLayoutSize(Container) |
|
1849 |
* @see Component#getMaximumSize |
|
1850 |
*/ |
|
1851 |
public Dimension getMaximumSize() { |
|
1852 |
/* Avoid grabbing the lock if a reasonable cached size value |
|
1853 |
* is available. |
|
1854 |
*/ |
|
1855 |
Dimension dim = maxSize; |
|
1856 |
if (dim == null || !(isMaximumSizeSet() || isValid())) { |
|
1857 |
synchronized (getTreeLock()) { |
|
1858 |
if (layoutMgr instanceof LayoutManager2) { |
|
1859 |
LayoutManager2 lm = (LayoutManager2) layoutMgr; |
|
1860 |
maxSize = lm.maximumLayoutSize(this); |
|
1861 |
} else { |
|
1862 |
maxSize = super.getMaximumSize(); |
|
1863 |
} |
|
1864 |
dim = maxSize; |
|
1865 |
} |
|
1866 |
} |
|
1867 |
if (dim != null){ |
|
1868 |
return new Dimension(dim); |
|
1869 |
} |
|
1870 |
else{ |
|
1871 |
return dim; |
|
1872 |
} |
|
1873 |
} |
|
1874 |
||
1875 |
/** |
|
1876 |
* Returns the alignment along the x axis. This specifies how |
|
1877 |
* the component would like to be aligned relative to other |
|
1878 |
* components. The value should be a number between 0 and 1 |
|
1879 |
* where 0 represents alignment along the origin, 1 is aligned |
|
1880 |
* the furthest away from the origin, 0.5 is centered, etc. |
|
1881 |
*/ |
|
1882 |
public float getAlignmentX() { |
|
1883 |
float xAlign; |
|
1884 |
if (layoutMgr instanceof LayoutManager2) { |
|
1885 |
synchronized (getTreeLock()) { |
|
1886 |
LayoutManager2 lm = (LayoutManager2) layoutMgr; |
|
1887 |
xAlign = lm.getLayoutAlignmentX(this); |
|
1888 |
} |
|
1889 |
} else { |
|
1890 |
xAlign = super.getAlignmentX(); |
|
1891 |
} |
|
1892 |
return xAlign; |
|
1893 |
} |
|
1894 |
||
1895 |
/** |
|
1896 |
* Returns the alignment along the y axis. This specifies how |
|
1897 |
* the component would like to be aligned relative to other |
|
1898 |
* components. The value should be a number between 0 and 1 |
|
1899 |
* where 0 represents alignment along the origin, 1 is aligned |
|
1900 |
* the furthest away from the origin, 0.5 is centered, etc. |
|
1901 |
*/ |
|
1902 |
public float getAlignmentY() { |
|
1903 |
float yAlign; |
|
1904 |
if (layoutMgr instanceof LayoutManager2) { |
|
1905 |
synchronized (getTreeLock()) { |
|
1906 |
LayoutManager2 lm = (LayoutManager2) layoutMgr; |
|
1907 |
yAlign = lm.getLayoutAlignmentY(this); |
|
1908 |
} |
|
1909 |
} else { |
|
1910 |
yAlign = super.getAlignmentY(); |
|
1911 |
} |
|
1912 |
return yAlign; |
|
1913 |
} |
|
1914 |
||
1915 |
/** |
|
1916 |
* Paints the container. This forwards the paint to any lightweight |
|
1917 |
* components that are children of this container. If this method is |
|
1918 |
* reimplemented, super.paint(g) should be called so that lightweight |
|
1919 |
* components are properly rendered. If a child component is entirely |
|
1920 |
* clipped by the current clipping setting in g, paint() will not be |
|
1921 |
* forwarded to that child. |
|
1922 |
* |
|
1923 |
* @param g the specified Graphics window |
|
1924 |
* @see Component#update(Graphics) |
|
1925 |
*/ |
|
1926 |
public void paint(Graphics g) { |
|
1927 |
if (isShowing()) { |
|
1928 |
synchronized (this) { |
|
1929 |
if (printing) { |
|
1930 |
if (printingThreads.contains(Thread.currentThread())) { |
|
1931 |
return; |
|
1932 |
} |
|
1933 |
} |
|
1934 |
} |
|
1935 |
||
1936 |
// The container is showing on screen and |
|
1937 |
// this paint() is not called from print(). |
|
1938 |
// Paint self and forward the paint to lightweight subcomponents. |
|
1939 |
||
1940 |
// super.paint(); -- Don't bother, since it's a NOP. |
|
1941 |
||
1942 |
GraphicsCallback.PaintCallback.getInstance(). |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
1943 |
runComponents(getComponentsSync(), g, GraphicsCallback.LIGHTWEIGHTS); |
2 | 1944 |
} |
1945 |
} |
|
1946 |
||
1947 |
/** |
|
1948 |
* Updates the container. This forwards the update to any lightweight |
|
1949 |
* components that are children of this container. If this method is |
|
1950 |
* reimplemented, super.update(g) should be called so that lightweight |
|
1951 |
* components are properly rendered. If a child component is entirely |
|
1952 |
* clipped by the current clipping setting in g, update() will not be |
|
1953 |
* forwarded to that child. |
|
1954 |
* |
|
1955 |
* @param g the specified Graphics window |
|
1956 |
* @see Component#update(Graphics) |
|
1957 |
*/ |
|
1958 |
public void update(Graphics g) { |
|
1959 |
if (isShowing()) { |
|
1960 |
if (! (peer instanceof LightweightPeer)) { |
|
1961 |
g.clearRect(0, 0, width, height); |
|
1962 |
} |
|
1963 |
paint(g); |
|
1964 |
} |
|
1965 |
} |
|
1966 |
||
1967 |
/** |
|
1968 |
* Prints the container. This forwards the print to any lightweight |
|
1969 |
* components that are children of this container. If this method is |
|
1970 |
* reimplemented, super.print(g) should be called so that lightweight |
|
1971 |
* components are properly rendered. If a child component is entirely |
|
1972 |
* clipped by the current clipping setting in g, print() will not be |
|
1973 |
* forwarded to that child. |
|
1974 |
* |
|
1975 |
* @param g the specified Graphics window |
|
1976 |
* @see Component#update(Graphics) |
|
1977 |
*/ |
|
1978 |
public void print(Graphics g) { |
|
1979 |
if (isShowing()) { |
|
1980 |
Thread t = Thread.currentThread(); |
|
1981 |
try { |
|
1982 |
synchronized (this) { |
|
1983 |
if (printingThreads == null) { |
|
1984 |
printingThreads = new HashSet(); |
|
1985 |
} |
|
1986 |
printingThreads.add(t); |
|
1987 |
printing = true; |
|
1988 |
} |
|
1989 |
super.print(g); // By default, Component.print() calls paint() |
|
1990 |
} finally { |
|
1991 |
synchronized (this) { |
|
1992 |
printingThreads.remove(t); |
|
1993 |
printing = !printingThreads.isEmpty(); |
|
1994 |
} |
|
1995 |
} |
|
1996 |
||
1997 |
GraphicsCallback.PrintCallback.getInstance(). |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
1998 |
runComponents(getComponentsSync(), g, GraphicsCallback.LIGHTWEIGHTS); |
2 | 1999 |
} |
2000 |
} |
|
2001 |
||
2002 |
/** |
|
2003 |
* Paints each of the components in this container. |
|
2004 |
* @param g the graphics context. |
|
2005 |
* @see Component#paint |
|
2006 |
* @see Component#paintAll |
|
2007 |
*/ |
|
2008 |
public void paintComponents(Graphics g) { |
|
2009 |
if (isShowing()) { |
|
2010 |
GraphicsCallback.PaintAllCallback.getInstance(). |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2011 |
runComponents(getComponentsSync(), g, GraphicsCallback.TWO_PASSES); |
2 | 2012 |
} |
2013 |
} |
|
2014 |
||
2015 |
/** |
|
2016 |
* Simulates the peer callbacks into java.awt for printing of |
|
2017 |
* lightweight Containers. |
|
2018 |
* @param g the graphics context to use for printing. |
|
2019 |
* @see Component#printAll |
|
2020 |
* @see #printComponents |
|
2021 |
*/ |
|
2022 |
void lightweightPaint(Graphics g) { |
|
2023 |
super.lightweightPaint(g); |
|
2024 |
paintHeavyweightComponents(g); |
|
2025 |
} |
|
2026 |
||
2027 |
/** |
|
2028 |
* Prints all the heavyweight subcomponents. |
|
2029 |
*/ |
|
2030 |
void paintHeavyweightComponents(Graphics g) { |
|
2031 |
if (isShowing()) { |
|
2032 |
GraphicsCallback.PaintHeavyweightComponentsCallback.getInstance(). |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2033 |
runComponents(getComponentsSync(), g, |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2034 |
GraphicsCallback.LIGHTWEIGHTS | GraphicsCallback.HEAVYWEIGHTS); |
2 | 2035 |
} |
2036 |
} |
|
2037 |
||
2038 |
/** |
|
2039 |
* Prints each of the components in this container. |
|
2040 |
* @param g the graphics context. |
|
2041 |
* @see Component#print |
|
2042 |
* @see Component#printAll |
|
2043 |
*/ |
|
2044 |
public void printComponents(Graphics g) { |
|
2045 |
if (isShowing()) { |
|
2046 |
GraphicsCallback.PrintAllCallback.getInstance(). |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2047 |
runComponents(getComponentsSync(), g, GraphicsCallback.TWO_PASSES); |
2 | 2048 |
} |
2049 |
} |
|
2050 |
||
2051 |
/** |
|
2052 |
* Simulates the peer callbacks into java.awt for printing of |
|
2053 |
* lightweight Containers. |
|
2054 |
* @param g the graphics context to use for printing. |
|
2055 |
* @see Component#printAll |
|
2056 |
* @see #printComponents |
|
2057 |
*/ |
|
2058 |
void lightweightPrint(Graphics g) { |
|
2059 |
super.lightweightPrint(g); |
|
2060 |
printHeavyweightComponents(g); |
|
2061 |
} |
|
2062 |
||
2063 |
/** |
|
2064 |
* Prints all the heavyweight subcomponents. |
|
2065 |
*/ |
|
2066 |
void printHeavyweightComponents(Graphics g) { |
|
2067 |
if (isShowing()) { |
|
2068 |
GraphicsCallback.PrintHeavyweightComponentsCallback.getInstance(). |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2069 |
runComponents(getComponentsSync(), g, |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2070 |
GraphicsCallback.LIGHTWEIGHTS | GraphicsCallback.HEAVYWEIGHTS); |
2 | 2071 |
} |
2072 |
} |
|
2073 |
||
2074 |
/** |
|
2075 |
* Adds the specified container listener to receive container events |
|
2076 |
* from this container. |
|
2077 |
* If l is null, no exception is thrown and no action is performed. |
|
2078 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
2079 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
2080 |
* |
|
2081 |
* @param l the container listener |
|
2082 |
* |
|
2083 |
* @see #removeContainerListener |
|
2084 |
* @see #getContainerListeners |
|
2085 |
*/ |
|
2086 |
public synchronized void addContainerListener(ContainerListener l) { |
|
2087 |
if (l == null) { |
|
2088 |
return; |
|
2089 |
} |
|
2090 |
containerListener = AWTEventMulticaster.add(containerListener, l); |
|
2091 |
newEventsOnly = true; |
|
2092 |
} |
|
2093 |
||
2094 |
/** |
|
2095 |
* Removes the specified container listener so it no longer receives |
|
2096 |
* container events from this container. |
|
2097 |
* If l is null, no exception is thrown and no action is performed. |
|
2098 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
2099 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
2100 |
* |
|
2101 |
* @param l the container listener |
|
2102 |
* |
|
2103 |
* @see #addContainerListener |
|
2104 |
* @see #getContainerListeners |
|
2105 |
*/ |
|
2106 |
public synchronized void removeContainerListener(ContainerListener l) { |
|
2107 |
if (l == null) { |
|
2108 |
return; |
|
2109 |
} |
|
2110 |
containerListener = AWTEventMulticaster.remove(containerListener, l); |
|
2111 |
} |
|
2112 |
||
2113 |
/** |
|
2114 |
* Returns an array of all the container listeners |
|
2115 |
* registered on this container. |
|
2116 |
* |
|
2117 |
* @return all of this container's <code>ContainerListener</code>s |
|
2118 |
* or an empty array if no container |
|
2119 |
* listeners are currently registered |
|
2120 |
* |
|
2121 |
* @see #addContainerListener |
|
2122 |
* @see #removeContainerListener |
|
2123 |
* @since 1.4 |
|
2124 |
*/ |
|
2125 |
public synchronized ContainerListener[] getContainerListeners() { |
|
2126 |
return (ContainerListener[]) (getListeners(ContainerListener.class)); |
|
2127 |
} |
|
2128 |
||
2129 |
/** |
|
2130 |
* Returns an array of all the objects currently registered |
|
2131 |
* as <code><em>Foo</em>Listener</code>s |
|
2132 |
* upon this <code>Container</code>. |
|
2133 |
* <code><em>Foo</em>Listener</code>s are registered using the |
|
2134 |
* <code>add<em>Foo</em>Listener</code> method. |
|
2135 |
* |
|
2136 |
* <p> |
|
2137 |
* You can specify the <code>listenerType</code> argument |
|
2138 |
* with a class literal, such as |
|
2139 |
* <code><em>Foo</em>Listener.class</code>. |
|
2140 |
* For example, you can query a |
|
2141 |
* <code>Container</code> <code>c</code> |
|
2142 |
* for its container listeners with the following code: |
|
2143 |
* |
|
2144 |
* <pre>ContainerListener[] cls = (ContainerListener[])(c.getListeners(ContainerListener.class));</pre> |
|
2145 |
* |
|
2146 |
* If no such listeners exist, this method returns an empty array. |
|
2147 |
* |
|
2148 |
* @param listenerType the type of listeners requested; this parameter |
|
2149 |
* should specify an interface that descends from |
|
2150 |
* <code>java.util.EventListener</code> |
|
2151 |
* @return an array of all objects registered as |
|
2152 |
* <code><em>Foo</em>Listener</code>s on this container, |
|
2153 |
* or an empty array if no such listeners have been added |
|
2154 |
* @exception ClassCastException if <code>listenerType</code> |
|
2155 |
* doesn't specify a class or interface that implements |
|
2156 |
* <code>java.util.EventListener</code> |
|
2157 |
* |
|
2158 |
* @see #getContainerListeners |
|
2159 |
* |
|
2160 |
* @since 1.3 |
|
2161 |
*/ |
|
2162 |
public <T extends EventListener> T[] getListeners(Class<T> listenerType) { |
|
2163 |
EventListener l = null; |
|
2164 |
if (listenerType == ContainerListener.class) { |
|
2165 |
l = containerListener; |
|
2166 |
} else { |
|
2167 |
return super.getListeners(listenerType); |
|
2168 |
} |
|
2169 |
return AWTEventMulticaster.getListeners(l, listenerType); |
|
2170 |
} |
|
2171 |
||
2172 |
// REMIND: remove when filtering is done at lower level |
|
2173 |
boolean eventEnabled(AWTEvent e) { |
|
2174 |
int id = e.getID(); |
|
2175 |
||
2176 |
if (id == ContainerEvent.COMPONENT_ADDED || |
|
2177 |
id == ContainerEvent.COMPONENT_REMOVED) { |
|
2178 |
if ((eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 || |
|
2179 |
containerListener != null) { |
|
2180 |
return true; |
|
2181 |
} |
|
2182 |
return false; |
|
2183 |
} |
|
2184 |
return super.eventEnabled(e); |
|
2185 |
} |
|
2186 |
||
2187 |
/** |
|
2188 |
* Processes events on this container. If the event is a |
|
2189 |
* <code>ContainerEvent</code>, it invokes the |
|
2190 |
* <code>processContainerEvent</code> method, else it invokes |
|
2191 |
* its superclass's <code>processEvent</code>. |
|
2192 |
* <p>Note that if the event parameter is <code>null</code> |
|
2193 |
* the behavior is unspecified and may result in an |
|
2194 |
* exception. |
|
2195 |
* |
|
2196 |
* @param e the event |
|
2197 |
*/ |
|
2198 |
protected void processEvent(AWTEvent e) { |
|
2199 |
if (e instanceof ContainerEvent) { |
|
2200 |
processContainerEvent((ContainerEvent)e); |
|
2201 |
return; |
|
2202 |
} |
|
2203 |
super.processEvent(e); |
|
2204 |
} |
|
2205 |
||
2206 |
/** |
|
2207 |
* Processes container events occurring on this container by |
|
2208 |
* dispatching them to any registered ContainerListener objects. |
|
2209 |
* NOTE: This method will not be called unless container events |
|
2210 |
* are enabled for this component; this happens when one of the |
|
2211 |
* following occurs: |
|
2212 |
* <ul> |
|
2213 |
* <li>A ContainerListener object is registered via |
|
2214 |
* <code>addContainerListener</code> |
|
2215 |
* <li>Container events are enabled via <code>enableEvents</code> |
|
2216 |
* </ul> |
|
2217 |
* <p>Note that if the event parameter is <code>null</code> |
|
2218 |
* the behavior is unspecified and may result in an |
|
2219 |
* exception. |
|
2220 |
* |
|
2221 |
* @param e the container event |
|
2222 |
* @see Component#enableEvents |
|
2223 |
*/ |
|
2224 |
protected void processContainerEvent(ContainerEvent e) { |
|
2225 |
ContainerListener listener = containerListener; |
|
2226 |
if (listener != null) { |
|
2227 |
switch(e.getID()) { |
|
2228 |
case ContainerEvent.COMPONENT_ADDED: |
|
2229 |
listener.componentAdded(e); |
|
2230 |
break; |
|
2231 |
case ContainerEvent.COMPONENT_REMOVED: |
|
2232 |
listener.componentRemoved(e); |
|
2233 |
break; |
|
2234 |
} |
|
2235 |
} |
|
2236 |
} |
|
2237 |
||
2238 |
/* |
|
2239 |
* Dispatches an event to this component or one of its sub components. |
|
2240 |
* Create ANCESTOR_RESIZED and ANCESTOR_MOVED events in response to |
|
2241 |
* COMPONENT_RESIZED and COMPONENT_MOVED events. We have to do this |
|
2242 |
* here instead of in processComponentEvent because ComponentEvents |
|
2243 |
* may not be enabled for this Container. |
|
2244 |
* @param e the event |
|
2245 |
*/ |
|
2246 |
void dispatchEventImpl(AWTEvent e) { |
|
2247 |
if ((dispatcher != null) && dispatcher.dispatchEvent(e)) { |
|
2248 |
// event was sent to a lightweight component. The |
|
2249 |
// native-produced event sent to the native container |
|
2250 |
// must be properly disposed of by the peer, so it |
|
2251 |
// gets forwarded. If the native host has been removed |
|
2252 |
// as a result of the sending the lightweight event, |
|
2253 |
// the peer reference will be null. |
|
2254 |
e.consume(); |
|
2255 |
if (peer != null) { |
|
2256 |
peer.handleEvent(e); |
|
2257 |
} |
|
2258 |
return; |
|
2259 |
} |
|
2260 |
||
2261 |
super.dispatchEventImpl(e); |
|
2262 |
||
2263 |
synchronized (getTreeLock()) { |
|
2264 |
switch (e.getID()) { |
|
2265 |
case ComponentEvent.COMPONENT_RESIZED: |
|
2266 |
createChildHierarchyEvents(HierarchyEvent.ANCESTOR_RESIZED, 0, |
|
2267 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)); |
|
2268 |
break; |
|
2269 |
case ComponentEvent.COMPONENT_MOVED: |
|
2270 |
createChildHierarchyEvents(HierarchyEvent.ANCESTOR_MOVED, 0, |
|
2271 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)); |
|
2272 |
break; |
|
2273 |
default: |
|
2274 |
break; |
|
2275 |
} |
|
2276 |
} |
|
2277 |
} |
|
2278 |
||
2279 |
/* |
|
2280 |
* Dispatches an event to this component, without trying to forward |
|
2281 |
* it to any subcomponents |
|
2282 |
* @param e the event |
|
2283 |
*/ |
|
2284 |
void dispatchEventToSelf(AWTEvent e) { |
|
2285 |
super.dispatchEventImpl(e); |
|
2286 |
} |
|
2287 |
||
2288 |
/** |
|
2289 |
* Fetchs the top-most (deepest) lightweight component that is interested |
|
2290 |
* in receiving mouse events. |
|
2291 |
*/ |
|
2292 |
Component getMouseEventTarget(int x, int y, boolean includeSelf) { |
|
2293 |
return getMouseEventTarget(x, y, includeSelf, |
|
2294 |
MouseEventTargetFilter.FILTER, |
|
2295 |
!SEARCH_HEAVYWEIGHTS); |
|
2296 |
} |
|
2297 |
||
2298 |
/** |
|
2299 |
* Fetches the top-most (deepest) component to receive SunDropTargetEvents. |
|
2300 |
*/ |
|
2301 |
Component getDropTargetEventTarget(int x, int y, boolean includeSelf) { |
|
2302 |
return getMouseEventTarget(x, y, includeSelf, |
|
2303 |
DropTargetEventTargetFilter.FILTER, |
|
2304 |
SEARCH_HEAVYWEIGHTS); |
|
2305 |
} |
|
2306 |
||
2307 |
/** |
|
2308 |
* A private version of getMouseEventTarget which has two additional |
|
2309 |
* controllable behaviors. This method searches for the top-most |
|
2310 |
* descendant of this container that contains the given coordinates |
|
2311 |
* and is accepted by the given filter. The search will be constrained to |
|
2312 |
* lightweight descendants if the last argument is <code>false</code>. |
|
2313 |
* |
|
2314 |
* @param filter EventTargetFilter instance to determine whether the |
|
2315 |
* given component is a valid target for this event. |
|
2316 |
* @param searchHeavyweights if <code>false</code>, the method |
|
2317 |
* will bypass heavyweight components during the search. |
|
2318 |
*/ |
|
2319 |
private Component getMouseEventTarget(int x, int y, boolean includeSelf, |
|
2320 |
EventTargetFilter filter, |
|
2321 |
boolean searchHeavyweights) { |
|
2322 |
Component comp = null; |
|
2323 |
if (searchHeavyweights) { |
|
2324 |
comp = getMouseEventTargetImpl(x, y, includeSelf, filter, |
|
2325 |
SEARCH_HEAVYWEIGHTS, |
|
2326 |
searchHeavyweights); |
|
2327 |
} |
|
2328 |
||
2329 |
if (comp == null || comp == this) { |
|
2330 |
comp = getMouseEventTargetImpl(x, y, includeSelf, filter, |
|
2331 |
!SEARCH_HEAVYWEIGHTS, |
|
2332 |
searchHeavyweights); |
|
2333 |
} |
|
2334 |
||
2335 |
return comp; |
|
2336 |
} |
|
2337 |
||
2338 |
/** |
|
2339 |
* A private version of getMouseEventTarget which has three additional |
|
2340 |
* controllable behaviors. This method searches for the top-most |
|
2341 |
* descendant of this container that contains the given coordinates |
|
2342 |
* and is accepted by the given filter. The search will be constrained to |
|
2343 |
* descendants of only lightweight children or only heavyweight children |
|
2344 |
* of this container depending on searchHeavyweightChildren. The search will |
|
2345 |
* be constrained to only lightweight descendants of the searched children |
|
2346 |
* of this container if searchHeavyweightDescendants is <code>false</code>. |
|
2347 |
* |
|
2348 |
* @param filter EventTargetFilter instance to determine whether the |
|
2349 |
* selected component is a valid target for this event. |
|
2350 |
* @param searchHeavyweightChildren if <code>true</code>, the method |
|
2351 |
* will bypass immediate lightweight children during the search. |
|
2352 |
* If <code>false</code>, the methods will bypass immediate |
|
2353 |
* heavyweight children during the search. |
|
2354 |
* @param searchHeavyweightDescendants if <code>false</code>, the method |
|
2355 |
* will bypass heavyweight descendants which are not immediate |
|
2356 |
* children during the search. If <code>true</code>, the method |
|
2357 |
* will traverse both lightweight and heavyweight descendants during |
|
2358 |
* the search. |
|
2359 |
*/ |
|
2360 |
private Component getMouseEventTargetImpl(int x, int y, boolean includeSelf, |
|
2361 |
EventTargetFilter filter, |
|
2362 |
boolean searchHeavyweightChildren, |
|
2363 |
boolean searchHeavyweightDescendants) { |
|
125
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2364 |
synchronized (getTreeLock()) { |
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2365 |
|
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2366 |
for (int i = 0; i < component.size(); i++) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2367 |
Component comp = component.get(i); |
125
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2368 |
if (comp != null && comp.visible && |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2369 |
((!searchHeavyweightChildren && |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2370 |
comp.peer instanceof LightweightPeer) || |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2371 |
(searchHeavyweightChildren && |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2372 |
!(comp.peer instanceof LightweightPeer))) && |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2373 |
comp.contains(x - comp.x, y - comp.y)) { |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2374 |
|
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2375 |
// found a component that intersects the point, see if there |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2376 |
// is a deeper possibility. |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2377 |
if (comp instanceof Container) { |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2378 |
Container child = (Container) comp; |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2379 |
Component deeper = child.getMouseEventTarget( |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2380 |
x - child.x, |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2381 |
y - child.y, |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2382 |
includeSelf, |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2383 |
filter, |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2384 |
searchHeavyweightDescendants); |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2385 |
if (deeper != null) { |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2386 |
return deeper; |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2387 |
} |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2388 |
} else { |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2389 |
if (filter.accept(comp)) { |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2390 |
// there isn't a deeper target, but this component |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2391 |
// is a target |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2392 |
return comp; |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2393 |
} |
2 | 2394 |
} |
2395 |
} |
|
2396 |
} |
|
125
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2397 |
|
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2398 |
boolean isPeerOK; |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2399 |
boolean isMouseOverMe; |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2400 |
|
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2401 |
isPeerOK = (peer instanceof LightweightPeer) || includeSelf; |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2402 |
isMouseOverMe = contains(x,y); |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2403 |
|
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2404 |
// didn't find a child target, return this component if it's |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2405 |
// a possible target |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2406 |
if (isMouseOverMe && isPeerOK && filter.accept(this)) { |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2407 |
return this; |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2408 |
} |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2409 |
// no possible target |
079ae88eaea9
6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents:
121
diff
changeset
|
2410 |
return null; |
2 | 2411 |
} |
2412 |
} |
|
2413 |
||
2414 |
static interface EventTargetFilter { |
|
2415 |
boolean accept(final Component comp); |
|
2416 |
} |
|
2417 |
||
2418 |
static class MouseEventTargetFilter implements EventTargetFilter { |
|
2419 |
static final EventTargetFilter FILTER = new MouseEventTargetFilter(); |
|
2420 |
||
2421 |
private MouseEventTargetFilter() {} |
|
2422 |
||
2423 |
public boolean accept(final Component comp) { |
|
2424 |
return (comp.eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 |
|
2425 |
|| (comp.eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 |
|
2426 |
|| (comp.eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 |
|
2427 |
|| comp.mouseListener != null |
|
2428 |
|| comp.mouseMotionListener != null |
|
2429 |
|| comp.mouseWheelListener != null; |
|
2430 |
} |
|
2431 |
} |
|
2432 |
||
2433 |
static class DropTargetEventTargetFilter implements EventTargetFilter { |
|
2434 |
static final EventTargetFilter FILTER = new DropTargetEventTargetFilter(); |
|
2435 |
||
2436 |
private DropTargetEventTargetFilter() {} |
|
2437 |
||
2438 |
public boolean accept(final Component comp) { |
|
2439 |
DropTarget dt = comp.getDropTarget(); |
|
2440 |
return dt != null && dt.isActive(); |
|
2441 |
} |
|
2442 |
} |
|
2443 |
||
2444 |
/** |
|
2445 |
* This is called by lightweight components that want the containing |
|
2446 |
* windowed parent to enable some kind of events on their behalf. |
|
2447 |
* This is needed for events that are normally only dispatched to |
|
2448 |
* windows to be accepted so that they can be forwarded downward to |
|
2449 |
* the lightweight component that has enabled them. |
|
2450 |
*/ |
|
2451 |
void proxyEnableEvents(long events) { |
|
2452 |
if (peer instanceof LightweightPeer) { |
|
2453 |
// this container is lightweight.... continue sending it |
|
2454 |
// upward. |
|
2455 |
if (parent != null) { |
|
2456 |
parent.proxyEnableEvents(events); |
|
2457 |
} |
|
2458 |
} else { |
|
2459 |
// This is a native container, so it needs to host |
|
2460 |
// one of it's children. If this function is called before |
|
2461 |
// a peer has been created we don't yet have a dispatcher |
|
2462 |
// because it has not yet been determined if this instance |
|
2463 |
// is lightweight. |
|
2464 |
if (dispatcher != null) { |
|
2465 |
dispatcher.enableEvents(events); |
|
2466 |
} |
|
2467 |
} |
|
2468 |
} |
|
2469 |
||
2470 |
/** |
|
2471 |
* @deprecated As of JDK version 1.1, |
|
2472 |
* replaced by <code>dispatchEvent(AWTEvent e)</code> |
|
2473 |
*/ |
|
2474 |
@Deprecated |
|
2475 |
public void deliverEvent(Event e) { |
|
2476 |
Component comp = getComponentAt(e.x, e.y); |
|
2477 |
if ((comp != null) && (comp != this)) { |
|
2478 |
e.translate(-comp.x, -comp.y); |
|
2479 |
comp.deliverEvent(e); |
|
2480 |
} else { |
|
2481 |
postEvent(e); |
|
2482 |
} |
|
2483 |
} |
|
2484 |
||
2485 |
/** |
|
2486 |
* Locates the component that contains the x,y position. The |
|
2487 |
* top-most child component is returned in the case where there |
|
2488 |
* is overlap in the components. This is determined by finding |
|
2489 |
* the component closest to the index 0 that claims to contain |
|
2490 |
* the given point via Component.contains(), except that Components |
|
2491 |
* which have native peers take precedence over those which do not |
|
2492 |
* (i.e., lightweight Components). |
|
2493 |
* |
|
2494 |
* @param x the <i>x</i> coordinate |
|
2495 |
* @param y the <i>y</i> coordinate |
|
2496 |
* @return null if the component does not contain the position. |
|
2497 |
* If there is no child component at the requested point and the |
|
2498 |
* point is within the bounds of the container the container itself |
|
2499 |
* is returned; otherwise the top-most child is returned. |
|
2500 |
* @see Component#contains |
|
2501 |
* @since JDK1.1 |
|
2502 |
*/ |
|
2503 |
public Component getComponentAt(int x, int y) { |
|
2504 |
return locate(x, y); |
|
2505 |
} |
|
2506 |
||
2507 |
/** |
|
2508 |
* @deprecated As of JDK version 1.1, |
|
2509 |
* replaced by <code>getComponentAt(int, int)</code>. |
|
2510 |
*/ |
|
2511 |
@Deprecated |
|
2512 |
public Component locate(int x, int y) { |
|
2513 |
if (!contains(x, y)) { |
|
2514 |
return null; |
|
2515 |
} |
|
2516 |
synchronized (getTreeLock()) { |
|
2517 |
// Two passes: see comment in sun.awt.SunGraphicsCallback |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2518 |
for (int i = 0; i < component.size(); i++) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2519 |
Component comp = component.get(i); |
2 | 2520 |
if (comp != null && |
2521 |
!(comp.peer instanceof LightweightPeer)) { |
|
2522 |
if (comp.contains(x - comp.x, y - comp.y)) { |
|
2523 |
return comp; |
|
2524 |
} |
|
2525 |
} |
|
2526 |
} |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2527 |
for (int i = 0; i < component.size(); i++) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2528 |
Component comp = component.get(i); |
2 | 2529 |
if (comp != null && |
2530 |
comp.peer instanceof LightweightPeer) { |
|
2531 |
if (comp.contains(x - comp.x, y - comp.y)) { |
|
2532 |
return comp; |
|
2533 |
} |
|
2534 |
} |
|
2535 |
} |
|
2536 |
} |
|
2537 |
return this; |
|
2538 |
} |
|
2539 |
||
2540 |
/** |
|
2541 |
* Gets the component that contains the specified point. |
|
2542 |
* @param p the point. |
|
2543 |
* @return returns the component that contains the point, |
|
2544 |
* or <code>null</code> if the component does |
|
2545 |
* not contain the point. |
|
2546 |
* @see Component#contains |
|
2547 |
* @since JDK1.1 |
|
2548 |
*/ |
|
2549 |
public Component getComponentAt(Point p) { |
|
2550 |
return getComponentAt(p.x, p.y); |
|
2551 |
} |
|
2552 |
||
2553 |
/** |
|
2554 |
* Returns the position of the mouse pointer in this <code>Container</code>'s |
|
2555 |
* coordinate space if the <code>Container</code> is under the mouse pointer, |
|
2556 |
* otherwise returns <code>null</code>. |
|
2557 |
* This method is similar to {@link Component#getMousePosition()} with the exception |
|
2558 |
* that it can take the <code>Container</code>'s children into account. |
|
2559 |
* If <code>allowChildren</code> is <code>false</code>, this method will return |
|
2560 |
* a non-null value only if the mouse pointer is above the <code>Container</code> |
|
2561 |
* directly, not above the part obscured by children. |
|
2562 |
* If <code>allowChildren</code> is <code>true</code>, this method returns |
|
2563 |
* a non-null value if the mouse pointer is above <code>Container</code> or any |
|
2564 |
* of its descendants. |
|
2565 |
* |
|
2566 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true |
|
2567 |
* @param allowChildren true if children should be taken into account |
|
2568 |
* @see Component#getMousePosition |
|
2569 |
* @return mouse coordinates relative to this <code>Component</code>, or null |
|
2570 |
* @since 1.5 |
|
2571 |
*/ |
|
2572 |
public Point getMousePosition(boolean allowChildren) throws HeadlessException { |
|
2573 |
if (GraphicsEnvironment.isHeadless()) { |
|
2574 |
throw new HeadlessException(); |
|
2575 |
} |
|
2576 |
PointerInfo pi = (PointerInfo)java.security.AccessController.doPrivileged( |
|
2577 |
new java.security.PrivilegedAction() { |
|
2578 |
public Object run() { |
|
2579 |
return MouseInfo.getPointerInfo(); |
|
2580 |
} |
|
2581 |
} |
|
2582 |
); |
|
2583 |
synchronized (getTreeLock()) { |
|
2584 |
Component inTheSameWindow = findUnderMouseInWindow(pi); |
|
2585 |
if (isSameOrAncestorOf(inTheSameWindow, allowChildren)) { |
|
2586 |
return pointRelativeToComponent(pi.getLocation()); |
|
2587 |
} |
|
2588 |
return null; |
|
2589 |
} |
|
2590 |
} |
|
2591 |
||
2592 |
boolean isSameOrAncestorOf(Component comp, boolean allowChildren) { |
|
2593 |
return this == comp || (allowChildren && isParentOf(comp)); |
|
2594 |
} |
|
2595 |
||
2596 |
/** |
|
2597 |
* Locates the visible child component that contains the specified |
|
2598 |
* position. The top-most child component is returned in the case |
|
2599 |
* where there is overlap in the components. If the containing child |
|
2600 |
* component is a Container, this method will continue searching for |
|
2601 |
* the deepest nested child component. Components which are not |
|
2602 |
* visible are ignored during the search.<p> |
|
2603 |
* |
|
2604 |
* The findComponentAt method is different from getComponentAt in |
|
2605 |
* that getComponentAt only searches the Container's immediate |
|
2606 |
* children; if the containing component is a Container, |
|
2607 |
* findComponentAt will search that child to find a nested component. |
|
2608 |
* |
|
2609 |
* @param x the <i>x</i> coordinate |
|
2610 |
* @param y the <i>y</i> coordinate |
|
2611 |
* @return null if the component does not contain the position. |
|
2612 |
* If there is no child component at the requested point and the |
|
2613 |
* point is within the bounds of the container the container itself |
|
2614 |
* is returned. |
|
2615 |
* @see Component#contains |
|
2616 |
* @see #getComponentAt |
|
2617 |
* @since 1.2 |
|
2618 |
*/ |
|
2619 |
public Component findComponentAt(int x, int y) { |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2620 |
return findComponentAt(x, y, true); |
2 | 2621 |
} |
2622 |
||
2623 |
/** |
|
2624 |
* Private version of findComponentAt which has a controllable |
|
2625 |
* behavior. Setting 'ignoreEnabled' to 'false' bypasses disabled |
|
2626 |
* Components during the search. This behavior is used by the |
|
2627 |
* lightweight cursor support in sun.awt.GlobalCursorManager. |
|
2628 |
* The cursor code calls this function directly via native code. |
|
2629 |
* |
|
2630 |
* The addition of this feature is temporary, pending the |
|
2631 |
* adoption of new, public API which exports this feature. |
|
2632 |
*/ |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2633 |
final Component findComponentAt(int x, int y, boolean ignoreEnabled) { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2634 |
synchronized (getTreeLock()) { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2635 |
if (isRecursivelyVisible()){ |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2636 |
return findComponentAtImpl(x, y, ignoreEnabled); |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2637 |
} |
2 | 2638 |
} |
2639 |
return null; |
|
2640 |
} |
|
2641 |
||
2642 |
final Component findComponentAtImpl(int x, int y, boolean ignoreEnabled){ |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2643 |
checkTreeLock(); |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2644 |
|
2 | 2645 |
if (!(contains(x, y) && visible && (ignoreEnabled || enabled))) { |
2646 |
return null; |
|
2647 |
} |
|
2648 |
||
2649 |
// Two passes: see comment in sun.awt.SunGraphicsCallback |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2650 |
for (int i = 0; i < component.size(); i++) { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2651 |
Component comp = component.get(i); |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2652 |
if (comp != null && |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2653 |
!(comp.peer instanceof LightweightPeer)) { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2654 |
if (comp instanceof Container) { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2655 |
comp = ((Container)comp).findComponentAtImpl(x - comp.x, |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2656 |
y - comp.y, |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2657 |
ignoreEnabled); |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2658 |
} else { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2659 |
comp = comp.locate(x - comp.x, y - comp.y); |
2 | 2660 |
} |
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2661 |
if (comp != null && comp.visible && |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2662 |
(ignoreEnabled || comp.enabled)) |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2663 |
{ |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2664 |
return comp; |
2 | 2665 |
} |
2666 |
} |
|
2667 |
} |
|
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2668 |
for (int i = 0; i < component.size(); i++) { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2669 |
Component comp = component.get(i); |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2670 |
if (comp != null && |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2671 |
comp.peer instanceof LightweightPeer) { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2672 |
if (comp instanceof Container) { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2673 |
comp = ((Container)comp).findComponentAtImpl(x - comp.x, |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2674 |
y - comp.y, |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2675 |
ignoreEnabled); |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2676 |
} else { |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2677 |
comp = comp.locate(x - comp.x, y - comp.y); |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2678 |
} |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2679 |
if (comp != null && comp.visible && |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2680 |
(ignoreEnabled || comp.enabled)) |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2681 |
{ |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2682 |
return comp; |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2683 |
} |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2684 |
} |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2685 |
} |
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
2686 |
|
2 | 2687 |
return this; |
2688 |
} |
|
2689 |
||
2690 |
/** |
|
2691 |
* Locates the visible child component that contains the specified |
|
2692 |
* point. The top-most child component is returned in the case |
|
2693 |
* where there is overlap in the components. If the containing child |
|
2694 |
* component is a Container, this method will continue searching for |
|
2695 |
* the deepest nested child component. Components which are not |
|
2696 |
* visible are ignored during the search.<p> |
|
2697 |
* |
|
2698 |
* The findComponentAt method is different from getComponentAt in |
|
2699 |
* that getComponentAt only searches the Container's immediate |
|
2700 |
* children; if the containing component is a Container, |
|
2701 |
* findComponentAt will search that child to find a nested component. |
|
2702 |
* |
|
2703 |
* @param p the point. |
|
2704 |
* @return null if the component does not contain the position. |
|
2705 |
* If there is no child component at the requested point and the |
|
2706 |
* point is within the bounds of the container the container itself |
|
2707 |
* is returned. |
|
2708 |
* @see Component#contains |
|
2709 |
* @see #getComponentAt |
|
2710 |
* @since 1.2 |
|
2711 |
*/ |
|
2712 |
public Component findComponentAt(Point p) { |
|
2713 |
return findComponentAt(p.x, p.y); |
|
2714 |
} |
|
2715 |
||
2716 |
/** |
|
2717 |
* Makes this Container displayable by connecting it to |
|
2718 |
* a native screen resource. Making a container displayable will |
|
2719 |
* cause all of its children to be made displayable. |
|
2720 |
* This method is called internally by the toolkit and should |
|
2721 |
* not be called directly by programs. |
|
2722 |
* @see Component#isDisplayable |
|
2723 |
* @see #removeNotify |
|
2724 |
*/ |
|
2725 |
public void addNotify() { |
|
2726 |
synchronized (getTreeLock()) { |
|
2727 |
// addNotify() on the children may cause proxy event enabling |
|
2728 |
// on this instance, so we first call super.addNotify() and |
|
2729 |
// possibly create an lightweight event dispatcher before calling |
|
2730 |
// addNotify() on the children which may be lightweight. |
|
2731 |
super.addNotify(); |
|
2732 |
if (! (peer instanceof LightweightPeer)) { |
|
2733 |
dispatcher = new LightweightDispatcher(this); |
|
2734 |
} |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2735 |
|
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2736 |
// We shouldn't use iterator because of the Swing menu |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2737 |
// implementation specifics: |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2738 |
// the menu is being assigned as a child to JLayeredPane |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2739 |
// instead of particular component so always affect |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2740 |
// collection of component if menu is becoming shown or hidden. |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2741 |
for (int i = 0; i < component.size(); i++) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2742 |
component.get(i).addNotify(); |
2 | 2743 |
} |
2744 |
} |
|
2745 |
} |
|
2746 |
||
2747 |
/** |
|
2748 |
* Makes this Container undisplayable by removing its connection |
|
2749 |
* to its native screen resource. Making a container undisplayable |
|
2750 |
* will cause all of its children to be made undisplayable. |
|
2751 |
* This method is called by the toolkit internally and should |
|
2752 |
* not be called directly by programs. |
|
2753 |
* @see Component#isDisplayable |
|
2754 |
* @see #addNotify |
|
2755 |
*/ |
|
2756 |
public void removeNotify() { |
|
2757 |
synchronized (getTreeLock()) { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2758 |
// We shouldn't use iterator because of the Swing menu |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2759 |
// implementation specifics: |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2760 |
// the menu is being assigned as a child to JLayeredPane |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2761 |
// instead of particular component so always affect |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2762 |
// collection of component if menu is becoming shown or hidden. |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2763 |
for (int i = component.size()-1 ; i >= 0 ; i--) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2764 |
Component comp = component.get(i); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2765 |
if (comp != null) { |
441 | 2766 |
// Fix for 6607170. |
2767 |
// We want to suppress focus change on disposal |
|
2768 |
// of the focused component. But because of focus |
|
2769 |
// is asynchronous, we should suppress focus change |
|
2770 |
// on every component in case it receives native focus |
|
2771 |
// in the process of disposal. |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2772 |
comp.setAutoFocusTransferOnDisposal(false); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2773 |
comp.removeNotify(); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2774 |
comp.setAutoFocusTransferOnDisposal(true); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2775 |
} |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2776 |
} |
441 | 2777 |
// If some of the children had focus before disposal then it still has. |
2778 |
// Auto-transfer focus to the next (or previous) component if auto-transfer |
|
2779 |
// is enabled. |
|
2780 |
if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabledFor(this)) { |
|
2781 |
if (!transferFocus(false)) { |
|
2782 |
transferFocusBackward(true); |
|
2783 |
} |
|
2 | 2784 |
} |
2785 |
if ( dispatcher != null ) { |
|
2786 |
dispatcher.dispose(); |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2787 |
dispatcher = null; |
2 | 2788 |
} |
2789 |
super.removeNotify(); |
|
2790 |
} |
|
2791 |
} |
|
2792 |
||
2793 |
/** |
|
2794 |
* Checks if the component is contained in the component hierarchy of |
|
2795 |
* this container. |
|
2796 |
* @param c the component |
|
2797 |
* @return <code>true</code> if it is an ancestor; |
|
2798 |
* <code>false</code> otherwise. |
|
2799 |
* @since JDK1.1 |
|
2800 |
*/ |
|
2801 |
public boolean isAncestorOf(Component c) { |
|
2802 |
Container p; |
|
2803 |
if (c == null || ((p = c.getParent()) == null)) { |
|
2804 |
return false; |
|
2805 |
} |
|
2806 |
while (p != null) { |
|
2807 |
if (p == this) { |
|
2808 |
return true; |
|
2809 |
} |
|
2810 |
p = p.getParent(); |
|
2811 |
} |
|
2812 |
return false; |
|
2813 |
} |
|
2814 |
||
2815 |
/* |
|
2816 |
* The following code was added to support modal JInternalFrames |
|
2817 |
* Unfortunately this code has to be added here so that we can get access to |
|
2818 |
* some private AWT classes like SequencedEvent. |
|
2819 |
* |
|
2820 |
* The native container of the LW component has this field set |
|
2821 |
* to tell it that it should block Mouse events for all LW |
|
2822 |
* children except for the modal component. |
|
2823 |
* |
|
2824 |
* In the case of nested Modal components, we store the previous |
|
2825 |
* modal component in the new modal components value of modalComp; |
|
2826 |
*/ |
|
2827 |
||
2828 |
transient Component modalComp; |
|
2829 |
transient AppContext modalAppContext; |
|
2830 |
||
2831 |
private void startLWModal() { |
|
2832 |
// Store the app context on which this component is being shown. |
|
2833 |
// Event dispatch thread of this app context will be sleeping until |
|
2834 |
// we wake it by any event from hideAndDisposeHandler(). |
|
2835 |
modalAppContext = AppContext.getAppContext(); |
|
2836 |
||
2837 |
// keep the KeyEvents from being dispatched |
|
2838 |
// until the focus has been transfered |
|
2839 |
long time = Toolkit.getEventQueue().getMostRecentEventTime(); |
|
2840 |
Component predictedFocusOwner = (Component.isInstanceOf(this, "javax.swing.JInternalFrame")) ? ((javax.swing.JInternalFrame)(this)).getMostRecentFocusOwner() : null; |
|
2841 |
if (predictedFocusOwner != null) { |
|
2842 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
2843 |
enqueueKeyEvents(time, predictedFocusOwner); |
|
2844 |
} |
|
2845 |
// We have two mechanisms for blocking: 1. If we're on the |
|
2846 |
// EventDispatchThread, start a new event pump. 2. If we're |
|
2847 |
// on any other thread, call wait() on the treelock. |
|
2848 |
final Container nativeContainer; |
|
2849 |
synchronized (getTreeLock()) { |
|
2850 |
nativeContainer = getHeavyweightContainer(); |
|
2851 |
if (nativeContainer.modalComp != null) { |
|
2852 |
this.modalComp = nativeContainer.modalComp; |
|
2853 |
nativeContainer.modalComp = this; |
|
2854 |
return; |
|
2855 |
} |
|
2856 |
else { |
|
2857 |
nativeContainer.modalComp = this; |
|
2858 |
} |
|
2859 |
} |
|
2860 |
||
2861 |
Runnable pumpEventsForHierarchy = new Runnable() { |
|
2862 |
public void run() { |
|
2863 |
EventDispatchThread dispatchThread = |
|
2864 |
(EventDispatchThread)Thread.currentThread(); |
|
2865 |
dispatchThread.pumpEventsForHierarchy( |
|
2866 |
new Conditional() { |
|
2867 |
public boolean evaluate() { |
|
2868 |
return ((windowClosingException == null) && (nativeContainer.modalComp != null)) ; |
|
2869 |
} |
|
2870 |
}, Container.this); |
|
2871 |
} |
|
2872 |
}; |
|
2873 |
||
2874 |
if (EventQueue.isDispatchThread()) { |
|
2875 |
SequencedEvent currentSequencedEvent = |
|
2876 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
2877 |
getCurrentSequencedEvent(); |
|
2878 |
if (currentSequencedEvent != null) { |
|
2879 |
currentSequencedEvent.dispose(); |
|
2880 |
} |
|
2881 |
||
2882 |
pumpEventsForHierarchy.run(); |
|
2883 |
} else { |
|
2884 |
synchronized (getTreeLock()) { |
|
2885 |
Toolkit.getEventQueue(). |
|
2886 |
postEvent(new PeerEvent(this, |
|
2887 |
pumpEventsForHierarchy, |
|
2888 |
PeerEvent.PRIORITY_EVENT)); |
|
2889 |
while ((windowClosingException == null) && |
|
2890 |
(nativeContainer.modalComp != null)) |
|
2891 |
{ |
|
2892 |
try { |
|
2893 |
getTreeLock().wait(); |
|
2894 |
} catch (InterruptedException e) { |
|
2895 |
break; |
|
2896 |
} |
|
2897 |
} |
|
2898 |
} |
|
2899 |
} |
|
2900 |
if (windowClosingException != null) { |
|
2901 |
windowClosingException.fillInStackTrace(); |
|
2902 |
throw windowClosingException; |
|
2903 |
} |
|
2904 |
if (predictedFocusOwner != null) { |
|
2905 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
2906 |
dequeueKeyEvents(time, predictedFocusOwner); |
|
2907 |
} |
|
2908 |
} |
|
2909 |
||
2910 |
private void stopLWModal() { |
|
2911 |
synchronized (getTreeLock()) { |
|
2912 |
if (modalAppContext != null) { |
|
2913 |
Container nativeContainer = getHeavyweightContainer(); |
|
2914 |
if(nativeContainer != null) { |
|
2915 |
if (this.modalComp != null) { |
|
2916 |
nativeContainer.modalComp = this.modalComp; |
|
2917 |
this.modalComp = null; |
|
2918 |
return; |
|
2919 |
} |
|
2920 |
else { |
|
2921 |
nativeContainer.modalComp = null; |
|
2922 |
} |
|
2923 |
} |
|
2924 |
// Wake up event dispatch thread on which the dialog was |
|
2925 |
// initially shown |
|
2926 |
SunToolkit.postEvent(modalAppContext, |
|
2927 |
new PeerEvent(this, |
|
2928 |
new WakingRunnable(), |
|
2929 |
PeerEvent.PRIORITY_EVENT)); |
|
2930 |
} |
|
2931 |
EventQueue.invokeLater(new WakingRunnable()); |
|
2932 |
getTreeLock().notifyAll(); |
|
2933 |
} |
|
2934 |
} |
|
2935 |
||
2936 |
final static class WakingRunnable implements Runnable { |
|
2937 |
public void run() { |
|
2938 |
} |
|
2939 |
} |
|
2940 |
||
2941 |
/* End of JOptionPane support code */ |
|
2942 |
||
2943 |
/** |
|
2944 |
* Returns a string representing the state of this <code>Container</code>. |
|
2945 |
* This method is intended to be used only for debugging purposes, and the |
|
2946 |
* content and format of the returned string may vary between |
|
2947 |
* implementations. The returned string may be empty but may not be |
|
2948 |
* <code>null</code>. |
|
2949 |
* |
|
2950 |
* @return the parameter string of this container |
|
2951 |
*/ |
|
2952 |
protected String paramString() { |
|
2953 |
String str = super.paramString(); |
|
2954 |
LayoutManager layoutMgr = this.layoutMgr; |
|
2955 |
if (layoutMgr != null) { |
|
2956 |
str += ",layout=" + layoutMgr.getClass().getName(); |
|
2957 |
} |
|
2958 |
return str; |
|
2959 |
} |
|
2960 |
||
2961 |
/** |
|
2962 |
* Prints a listing of this container to the specified output |
|
2963 |
* stream. The listing starts at the specified indentation. |
|
2964 |
* <p> |
|
2965 |
* The immediate children of the container are printed with |
|
2966 |
* an indentation of <code>indent+1</code>. The children |
|
2967 |
* of those children are printed at <code>indent+2</code> |
|
2968 |
* and so on. |
|
2969 |
* |
|
2970 |
* @param out a print stream |
|
2971 |
* @param indent the number of spaces to indent |
|
2972 |
* @see Component#list(java.io.PrintStream, int) |
|
2973 |
* @since JDK1.0 |
|
2974 |
*/ |
|
2975 |
public void list(PrintStream out, int indent) { |
|
2976 |
super.list(out, indent); |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2977 |
synchronized(getTreeLock()) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2978 |
for (int i = 0; i < component.size(); i++) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2979 |
Component comp = component.get(i); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2980 |
if (comp != null) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2981 |
comp.list(out, indent+1); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2982 |
} |
2 | 2983 |
} |
2984 |
} |
|
2985 |
} |
|
2986 |
||
2987 |
/** |
|
2988 |
* Prints out a list, starting at the specified indentation, |
|
2989 |
* to the specified print writer. |
|
2990 |
* <p> |
|
2991 |
* The immediate children of the container are printed with |
|
2992 |
* an indentation of <code>indent+1</code>. The children |
|
2993 |
* of those children are printed at <code>indent+2</code> |
|
2994 |
* and so on. |
|
2995 |
* |
|
2996 |
* @param out a print writer |
|
2997 |
* @param indent the number of spaces to indent |
|
2998 |
* @see Component#list(java.io.PrintWriter, int) |
|
2999 |
* @since JDK1.1 |
|
3000 |
*/ |
|
3001 |
public void list(PrintWriter out, int indent) { |
|
3002 |
super.list(out, indent); |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3003 |
synchronized(getTreeLock()) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3004 |
for (int i = 0; i < component.size(); i++) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3005 |
Component comp = component.get(i); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3006 |
if (comp != null) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3007 |
comp.list(out, indent+1); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3008 |
} |
2 | 3009 |
} |
3010 |
} |
|
3011 |
} |
|
3012 |
||
3013 |
/** |
|
3014 |
* Sets the focus traversal keys for a given traversal operation for this |
|
3015 |
* Container. |
|
3016 |
* <p> |
|
3017 |
* The default values for a Container's focus traversal keys are |
|
3018 |
* implementation-dependent. Sun recommends that all implementations for a |
|
3019 |
* particular native platform use the same default values. The |
|
3020 |
* recommendations for Windows and Unix are listed below. These |
|
3021 |
* recommendations are used in the Sun AWT implementations. |
|
3022 |
* |
|
3023 |
* <table border=1 summary="Recommended default values for a Container's focus traversal keys"> |
|
3024 |
* <tr> |
|
3025 |
* <th>Identifier</th> |
|
3026 |
* <th>Meaning</th> |
|
3027 |
* <th>Default</th> |
|
3028 |
* </tr> |
|
3029 |
* <tr> |
|
3030 |
* <td>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</td> |
|
3031 |
* <td>Normal forward keyboard traversal</td> |
|
3032 |
* <td>TAB on KEY_PRESSED, CTRL-TAB on KEY_PRESSED</td> |
|
3033 |
* </tr> |
|
3034 |
* <tr> |
|
3035 |
* <td>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</td> |
|
3036 |
* <td>Normal reverse keyboard traversal</td> |
|
3037 |
* <td>SHIFT-TAB on KEY_PRESSED, CTRL-SHIFT-TAB on KEY_PRESSED</td> |
|
3038 |
* </tr> |
|
3039 |
* <tr> |
|
3040 |
* <td>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</td> |
|
3041 |
* <td>Go up one focus traversal cycle</td> |
|
3042 |
* <td>none</td> |
|
3043 |
* </tr> |
|
3044 |
* <tr> |
|
3045 |
* <td>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS<td> |
|
3046 |
* <td>Go down one focus traversal cycle</td> |
|
3047 |
* <td>none</td> |
|
3048 |
* </tr> |
|
3049 |
* </table> |
|
3050 |
* |
|
3051 |
* To disable a traversal key, use an empty Set; Collections.EMPTY_SET is |
|
3052 |
* recommended. |
|
3053 |
* <p> |
|
3054 |
* Using the AWTKeyStroke API, client code can specify on which of two |
|
3055 |
* specific KeyEvents, KEY_PRESSED or KEY_RELEASED, the focus traversal |
|
3056 |
* operation will occur. Regardless of which KeyEvent is specified, |
|
3057 |
* however, all KeyEvents related to the focus traversal key, including the |
|
3058 |
* associated KEY_TYPED event, will be consumed, and will not be dispatched |
|
3059 |
* to any Container. It is a runtime error to specify a KEY_TYPED event as |
|
3060 |
* mapping to a focus traversal operation, or to map the same event to |
|
3061 |
* multiple default focus traversal operations. |
|
3062 |
* <p> |
|
3063 |
* If a value of null is specified for the Set, this Container inherits the |
|
3064 |
* Set from its parent. If all ancestors of this Container have null |
|
3065 |
* specified for the Set, then the current KeyboardFocusManager's default |
|
3066 |
* Set is used. |
|
3067 |
* |
|
3068 |
* @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
3069 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, |
|
3070 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or |
|
3071 |
* KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS |
|
3072 |
* @param keystrokes the Set of AWTKeyStroke for the specified operation |
|
3073 |
* @see #getFocusTraversalKeys |
|
3074 |
* @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS |
|
3075 |
* @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS |
|
3076 |
* @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS |
|
3077 |
* @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS |
|
3078 |
* @throws IllegalArgumentException if id is not one of |
|
3079 |
* KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
3080 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, |
|
3081 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or |
|
3082 |
* KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, or if keystrokes |
|
3083 |
* contains null, or if any Object in keystrokes is not an |
|
3084 |
* AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, |
|
3085 |
* or if any keystroke already maps to another focus traversal |
|
3086 |
* operation for this Container |
|
3087 |
* @since 1.4 |
|
3088 |
* @beaninfo |
|
3089 |
* bound: true |
|
3090 |
*/ |
|
3091 |
public void setFocusTraversalKeys(int id, |
|
3092 |
Set<? extends AWTKeyStroke> keystrokes) |
|
3093 |
{ |
|
3094 |
if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) { |
|
3095 |
throw new IllegalArgumentException("invalid focus traversal key identifier"); |
|
3096 |
} |
|
3097 |
||
3098 |
// Don't call super.setFocusTraversalKey. The Component parameter check |
|
3099 |
// does not allow DOWN_CYCLE_TRAVERSAL_KEYS, but we do. |
|
3100 |
setFocusTraversalKeys_NoIDCheck(id, keystrokes); |
|
3101 |
} |
|
3102 |
||
3103 |
/** |
|
3104 |
* Returns the Set of focus traversal keys for a given traversal operation |
|
3105 |
* for this Container. (See |
|
3106 |
* <code>setFocusTraversalKeys</code> for a full description of each key.) |
|
3107 |
* <p> |
|
3108 |
* If a Set of traversal keys has not been explicitly defined for this |
|
3109 |
* Container, then this Container's parent's Set is returned. If no Set |
|
3110 |
* has been explicitly defined for any of this Container's ancestors, then |
|
3111 |
* the current KeyboardFocusManager's default Set is returned. |
|
3112 |
* |
|
3113 |
* @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
3114 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, |
|
3115 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or |
|
3116 |
* KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS |
|
3117 |
* @return the Set of AWTKeyStrokes for the specified operation. The Set |
|
3118 |
* will be unmodifiable, and may be empty. null will never be |
|
3119 |
* returned. |
|
3120 |
* @see #setFocusTraversalKeys |
|
3121 |
* @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS |
|
3122 |
* @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS |
|
3123 |
* @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS |
|
3124 |
* @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS |
|
3125 |
* @throws IllegalArgumentException if id is not one of |
|
3126 |
* KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
3127 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, |
|
3128 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or |
|
3129 |
* KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS |
|
3130 |
* @since 1.4 |
|
3131 |
*/ |
|
3132 |
public Set<AWTKeyStroke> getFocusTraversalKeys(int id) { |
|
3133 |
if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) { |
|
3134 |
throw new IllegalArgumentException("invalid focus traversal key identifier"); |
|
3135 |
} |
|
3136 |
||
3137 |
// Don't call super.getFocusTraversalKey. The Component parameter check |
|
3138 |
// does not allow DOWN_CYCLE_TRAVERSAL_KEY, but we do. |
|
3139 |
return getFocusTraversalKeys_NoIDCheck(id); |
|
3140 |
} |
|
3141 |
||
3142 |
/** |
|
3143 |
* Returns whether the Set of focus traversal keys for the given focus |
|
3144 |
* traversal operation has been explicitly defined for this Container. If |
|
3145 |
* this method returns <code>false</code>, this Container is inheriting the |
|
3146 |
* Set from an ancestor, or from the current KeyboardFocusManager. |
|
3147 |
* |
|
3148 |
* @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
3149 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, |
|
3150 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or |
|
3151 |
* KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS |
|
3152 |
* @return <code>true</code> if the the Set of focus traversal keys for the |
|
3153 |
* given focus traversal operation has been explicitly defined for |
|
3154 |
* this Component; <code>false</code> otherwise. |
|
3155 |
* @throws IllegalArgumentException if id is not one of |
|
3156 |
* KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
3157 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, |
|
3158 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or |
|
3159 |
* KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS |
|
3160 |
* @since 1.4 |
|
3161 |
*/ |
|
3162 |
public boolean areFocusTraversalKeysSet(int id) { |
|
3163 |
if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) { |
|
3164 |
throw new IllegalArgumentException("invalid focus traversal key identifier"); |
|
3165 |
} |
|
3166 |
||
3167 |
return (focusTraversalKeys != null && focusTraversalKeys[id] != null); |
|
3168 |
} |
|
3169 |
||
3170 |
/** |
|
3171 |
* Returns whether the specified Container is the focus cycle root of this |
|
3172 |
* Container's focus traversal cycle. Each focus traversal cycle has only |
|
3173 |
* a single focus cycle root and each Container which is not a focus cycle |
|
3174 |
* root belongs to only a single focus traversal cycle. Containers which |
|
3175 |
* are focus cycle roots belong to two cycles: one rooted at the Container |
|
3176 |
* itself, and one rooted at the Container's nearest focus-cycle-root |
|
3177 |
* ancestor. This method will return <code>true</code> for both such |
|
3178 |
* Containers in this case. |
|
3179 |
* |
|
3180 |
* @param container the Container to be tested |
|
3181 |
* @return <code>true</code> if the specified Container is a focus-cycle- |
|
3182 |
* root of this Container; <code>false</code> otherwise |
|
3183 |
* @see #isFocusCycleRoot() |
|
3184 |
* @since 1.4 |
|
3185 |
*/ |
|
3186 |
public boolean isFocusCycleRoot(Container container) { |
|
3187 |
if (isFocusCycleRoot() && container == this) { |
|
3188 |
return true; |
|
3189 |
} else { |
|
3190 |
return super.isFocusCycleRoot(container); |
|
3191 |
} |
|
3192 |
} |
|
3193 |
||
3194 |
private Container findTraversalRoot() { |
|
3195 |
// I potentially have two roots, myself and my root parent |
|
3196 |
// If I am the current root, then use me |
|
3197 |
// If none of my parents are roots, then use me |
|
3198 |
// If my root parent is the current root, then use my root parent |
|
3199 |
// If neither I nor my root parent is the current root, then |
|
3200 |
// use my root parent (a guess) |
|
3201 |
||
3202 |
Container currentFocusCycleRoot = KeyboardFocusManager. |
|
3203 |
getCurrentKeyboardFocusManager().getCurrentFocusCycleRoot(); |
|
3204 |
Container root; |
|
3205 |
||
3206 |
if (currentFocusCycleRoot == this) { |
|
3207 |
root = this; |
|
3208 |
} else { |
|
3209 |
root = getFocusCycleRootAncestor(); |
|
3210 |
if (root == null) { |
|
3211 |
root = this; |
|
3212 |
} |
|
3213 |
} |
|
3214 |
||
3215 |
if (root != currentFocusCycleRoot) { |
|
3216 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
3217 |
setGlobalCurrentFocusCycleRoot(root); |
|
3218 |
} |
|
3219 |
return root; |
|
3220 |
} |
|
3221 |
||
3222 |
final boolean containsFocus() { |
|
3223 |
final Component focusOwner = KeyboardFocusManager. |
|
3224 |
getCurrentKeyboardFocusManager().getFocusOwner(); |
|
3225 |
return isParentOf(focusOwner); |
|
3226 |
} |
|
3227 |
||
3228 |
/** |
|
3229 |
* Check if this component is the child of this container or its children. |
|
3230 |
* Note: this function acquires treeLock |
|
3231 |
* Note: this function traverses children tree only in one Window. |
|
3232 |
* @param comp a component in test, must not be null |
|
3233 |
*/ |
|
3234 |
private boolean isParentOf(Component comp) { |
|
3235 |
synchronized(getTreeLock()) { |
|
3236 |
while (comp != null && comp != this && !(comp instanceof Window)) { |
|
3237 |
comp = comp.getParent(); |
|
3238 |
} |
|
3239 |
return (comp == this); |
|
3240 |
} |
|
3241 |
} |
|
3242 |
||
3243 |
void clearMostRecentFocusOwnerOnHide() { |
|
3244 |
boolean reset = false; |
|
3245 |
Window window = null; |
|
3246 |
||
3247 |
synchronized (getTreeLock()) { |
|
3248 |
window = getContainingWindow(); |
|
3249 |
if (window != null) { |
|
3250 |
Component comp = KeyboardFocusManager.getMostRecentFocusOwner(window); |
|
3251 |
reset = ((comp == this) || isParentOf(comp)); |
|
3252 |
// This synchronized should always be the second in a pair |
|
3253 |
// (tree lock, KeyboardFocusManager.class) |
|
3254 |
synchronized(KeyboardFocusManager.class) { |
|
3255 |
Component storedComp = window.getTemporaryLostComponent(); |
|
3256 |
if (isParentOf(storedComp) || storedComp == this) { |
|
3257 |
window.setTemporaryLostComponent(null); |
|
3258 |
} |
|
3259 |
} |
|
3260 |
} |
|
3261 |
} |
|
3262 |
||
3263 |
if (reset) { |
|
3264 |
KeyboardFocusManager.setMostRecentFocusOwner(window, null); |
|
3265 |
} |
|
3266 |
} |
|
3267 |
||
3268 |
void clearCurrentFocusCycleRootOnHide() { |
|
3269 |
KeyboardFocusManager kfm = |
|
3270 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(); |
|
3271 |
Container cont = kfm.getCurrentFocusCycleRoot(); |
|
3272 |
||
3273 |
if (cont == this || isParentOf(cont)) { |
|
3274 |
kfm.setGlobalCurrentFocusCycleRoot(null); |
|
3275 |
} |
|
3276 |
} |
|
3277 |
||
3278 |
final Container getTraversalRoot() { |
|
3279 |
if (isFocusCycleRoot()) { |
|
3280 |
return findTraversalRoot(); |
|
3281 |
} |
|
3282 |
||
3283 |
return super.getTraversalRoot(); |
|
3284 |
} |
|
3285 |
||
3286 |
/** |
|
3287 |
* Sets the focus traversal policy that will manage keyboard traversal of |
|
3288 |
* this Container's children, if this Container is a focus cycle root. If |
|
3289 |
* the argument is null, this Container inherits its policy from its focus- |
|
3290 |
* cycle-root ancestor. If the argument is non-null, this policy will be |
|
3291 |
* inherited by all focus-cycle-root children that have no keyboard- |
|
3292 |
* traversal policy of their own (as will, recursively, their focus-cycle- |
|
3293 |
* root children). |
|
3294 |
* <p> |
|
3295 |
* If this Container is not a focus cycle root, the policy will be |
|
3296 |
* remembered, but will not be used or inherited by this or any other |
|
3297 |
* Containers until this Container is made a focus cycle root. |
|
3298 |
* |
|
3299 |
* @param policy the new focus traversal policy for this Container |
|
3300 |
* @see #getFocusTraversalPolicy |
|
3301 |
* @see #setFocusCycleRoot |
|
3302 |
* @see #isFocusCycleRoot |
|
3303 |
* @since 1.4 |
|
3304 |
* @beaninfo |
|
3305 |
* bound: true |
|
3306 |
*/ |
|
3307 |
public void setFocusTraversalPolicy(FocusTraversalPolicy policy) { |
|
3308 |
FocusTraversalPolicy oldPolicy; |
|
3309 |
synchronized (this) { |
|
3310 |
oldPolicy = this.focusTraversalPolicy; |
|
3311 |
this.focusTraversalPolicy = policy; |
|
3312 |
} |
|
3313 |
firePropertyChange("focusTraversalPolicy", oldPolicy, policy); |
|
3314 |
} |
|
3315 |
||
3316 |
/** |
|
3317 |
* Returns the focus traversal policy that will manage keyboard traversal |
|
3318 |
* of this Container's children, or null if this Container is not a focus |
|
3319 |
* cycle root. If no traversal policy has been explicitly set for this |
|
3320 |
* Container, then this Container's focus-cycle-root ancestor's policy is |
|
3321 |
* returned. |
|
3322 |
* |
|
3323 |
* @return this Container's focus traversal policy, or null if this |
|
3324 |
* Container is not a focus cycle root. |
|
3325 |
* @see #setFocusTraversalPolicy |
|
3326 |
* @see #setFocusCycleRoot |
|
3327 |
* @see #isFocusCycleRoot |
|
3328 |
* @since 1.4 |
|
3329 |
*/ |
|
3330 |
public FocusTraversalPolicy getFocusTraversalPolicy() { |
|
3331 |
if (!isFocusTraversalPolicyProvider() && !isFocusCycleRoot()) { |
|
3332 |
return null; |
|
3333 |
} |
|
3334 |
||
3335 |
FocusTraversalPolicy policy = this.focusTraversalPolicy; |
|
3336 |
if (policy != null) { |
|
3337 |
return policy; |
|
3338 |
} |
|
3339 |
||
3340 |
Container rootAncestor = getFocusCycleRootAncestor(); |
|
3341 |
if (rootAncestor != null) { |
|
3342 |
return rootAncestor.getFocusTraversalPolicy(); |
|
3343 |
} else { |
|
3344 |
return KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
3345 |
getDefaultFocusTraversalPolicy(); |
|
3346 |
} |
|
3347 |
} |
|
3348 |
||
3349 |
/** |
|
3350 |
* Returns whether the focus traversal policy has been explicitly set for |
|
3351 |
* this Container. If this method returns <code>false</code>, this |
|
3352 |
* Container will inherit its focus traversal policy from an ancestor. |
|
3353 |
* |
|
3354 |
* @return <code>true</code> if the focus traversal policy has been |
|
3355 |
* explicitly set for this Container; <code>false</code> otherwise. |
|
3356 |
* @since 1.4 |
|
3357 |
*/ |
|
3358 |
public boolean isFocusTraversalPolicySet() { |
|
3359 |
return (focusTraversalPolicy != null); |
|
3360 |
} |
|
3361 |
||
3362 |
/** |
|
3363 |
* Sets whether this Container is the root of a focus traversal cycle. Once |
|
3364 |
* focus enters a traversal cycle, typically it cannot leave it via focus |
|
3365 |
* traversal unless one of the up- or down-cycle keys is pressed. Normal |
|
3366 |
* traversal is limited to this Container, and all of this Container's |
|
3367 |
* descendants that are not descendants of inferior focus cycle roots. Note |
|
3368 |
* that a FocusTraversalPolicy may bend these restrictions, however. For |
|
3369 |
* example, ContainerOrderFocusTraversalPolicy supports implicit down-cycle |
|
3370 |
* traversal. |
|
3371 |
* <p> |
|
3372 |
* The alternative way to specify the traversal order of this Container's |
|
3373 |
* children is to make this Container a |
|
3374 |
* <a href="doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus traversal policy provider</a>. |
|
3375 |
* |
|
3376 |
* @param focusCycleRoot indicates whether this Container is the root of a |
|
3377 |
* focus traversal cycle |
|
3378 |
* @see #isFocusCycleRoot() |
|
3379 |
* @see #setFocusTraversalPolicy |
|
3380 |
* @see #getFocusTraversalPolicy |
|
3381 |
* @see ContainerOrderFocusTraversalPolicy |
|
3382 |
* @see #setFocusTraversalPolicyProvider |
|
3383 |
* @since 1.4 |
|
3384 |
* @beaninfo |
|
3385 |
* bound: true |
|
3386 |
*/ |
|
3387 |
public void setFocusCycleRoot(boolean focusCycleRoot) { |
|
3388 |
boolean oldFocusCycleRoot; |
|
3389 |
synchronized (this) { |
|
3390 |
oldFocusCycleRoot = this.focusCycleRoot; |
|
3391 |
this.focusCycleRoot = focusCycleRoot; |
|
3392 |
} |
|
3393 |
firePropertyChange("focusCycleRoot", oldFocusCycleRoot, |
|
3394 |
focusCycleRoot); |
|
3395 |
} |
|
3396 |
||
3397 |
/** |
|
3398 |
* Returns whether this Container is the root of a focus traversal cycle. |
|
3399 |
* Once focus enters a traversal cycle, typically it cannot leave it via |
|
3400 |
* focus traversal unless one of the up- or down-cycle keys is pressed. |
|
3401 |
* Normal traversal is limited to this Container, and all of this |
|
3402 |
* Container's descendants that are not descendants of inferior focus |
|
3403 |
* cycle roots. Note that a FocusTraversalPolicy may bend these |
|
3404 |
* restrictions, however. For example, ContainerOrderFocusTraversalPolicy |
|
3405 |
* supports implicit down-cycle traversal. |
|
3406 |
* |
|
3407 |
* @return whether this Container is the root of a focus traversal cycle |
|
3408 |
* @see #setFocusCycleRoot |
|
3409 |
* @see #setFocusTraversalPolicy |
|
3410 |
* @see #getFocusTraversalPolicy |
|
3411 |
* @see ContainerOrderFocusTraversalPolicy |
|
3412 |
* @since 1.4 |
|
3413 |
*/ |
|
3414 |
public boolean isFocusCycleRoot() { |
|
3415 |
return focusCycleRoot; |
|
3416 |
} |
|
3417 |
||
3418 |
/** |
|
3419 |
* Sets whether this container will be used to provide focus |
|
3420 |
* traversal policy. Container with this property as |
|
3421 |
* <code>true</code> will be used to acquire focus traversal policy |
|
3422 |
* instead of closest focus cycle root ancestor. |
|
3423 |
* @param provider indicates whether this container will be used to |
|
3424 |
* provide focus traversal policy |
|
3425 |
* @see #setFocusTraversalPolicy |
|
3426 |
* @see #getFocusTraversalPolicy |
|
3427 |
* @see #isFocusTraversalPolicyProvider |
|
3428 |
* @since 1.5 |
|
3429 |
* @beaninfo |
|
3430 |
* bound: true |
|
3431 |
*/ |
|
3432 |
public final void setFocusTraversalPolicyProvider(boolean provider) { |
|
3433 |
boolean oldProvider; |
|
3434 |
synchronized(this) { |
|
3435 |
oldProvider = focusTraversalPolicyProvider; |
|
3436 |
focusTraversalPolicyProvider = provider; |
|
3437 |
} |
|
3438 |
firePropertyChange("focusTraversalPolicyProvider", oldProvider, provider); |
|
3439 |
} |
|
3440 |
||
3441 |
/** |
|
3442 |
* Returns whether this container provides focus traversal |
|
3443 |
* policy. If this property is set to <code>true</code> then when |
|
3444 |
* keyboard focus manager searches container hierarchy for focus |
|
3445 |
* traversal policy and encounters this container before any other |
|
3446 |
* container with this property as true or focus cycle roots then |
|
3447 |
* its focus traversal policy will be used instead of focus cycle |
|
3448 |
* root's policy. |
|
3449 |
* @see #setFocusTraversalPolicy |
|
3450 |
* @see #getFocusTraversalPolicy |
|
3451 |
* @see #setFocusCycleRoot |
|
3452 |
* @see #setFocusTraversalPolicyProvider |
|
3453 |
* @return <code>true</code> if this container provides focus traversal |
|
3454 |
* policy, <code>false</code> otherwise |
|
3455 |
* @since 1.5 |
|
3456 |
* @beaninfo |
|
3457 |
* bound: true |
|
3458 |
*/ |
|
3459 |
public final boolean isFocusTraversalPolicyProvider() { |
|
3460 |
return focusTraversalPolicyProvider; |
|
3461 |
} |
|
3462 |
||
3463 |
/** |
|
3464 |
* Transfers the focus down one focus traversal cycle. If this Container is |
|
3465 |
* a focus cycle root, then the focus owner is set to this Container's |
|
3466 |
* default Component to focus, and the current focus cycle root is set to |
|
3467 |
* this Container. If this Container is not a focus cycle root, then no |
|
3468 |
* focus traversal operation occurs. |
|
3469 |
* |
|
3470 |
* @see Component#requestFocus() |
|
3471 |
* @see #isFocusCycleRoot |
|
3472 |
* @see #setFocusCycleRoot |
|
3473 |
* @since 1.4 |
|
3474 |
*/ |
|
3475 |
public void transferFocusDownCycle() { |
|
3476 |
if (isFocusCycleRoot()) { |
|
3477 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
3478 |
setGlobalCurrentFocusCycleRoot(this); |
|
3479 |
Component toFocus = getFocusTraversalPolicy(). |
|
3480 |
getDefaultComponent(this); |
|
3481 |
if (toFocus != null) { |
|
3482 |
toFocus.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_DOWN); |
|
3483 |
} |
|
3484 |
} |
|
3485 |
} |
|
3486 |
||
3487 |
void preProcessKeyEvent(KeyEvent e) { |
|
3488 |
Container parent = this.parent; |
|
3489 |
if (parent != null) { |
|
3490 |
parent.preProcessKeyEvent(e); |
|
3491 |
} |
|
3492 |
} |
|
3493 |
||
3494 |
void postProcessKeyEvent(KeyEvent e) { |
|
3495 |
Container parent = this.parent; |
|
3496 |
if (parent != null) { |
|
3497 |
parent.postProcessKeyEvent(e); |
|
3498 |
} |
|
3499 |
} |
|
3500 |
||
3501 |
boolean postsOldMouseEvents() { |
|
3502 |
return true; |
|
3503 |
} |
|
3504 |
||
3505 |
/** |
|
3506 |
* Sets the <code>ComponentOrientation</code> property of this container |
|
3507 |
* and all components contained within it. |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
3508 |
* <p> |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
3509 |
* This method changes layout-related information, and therefore, |
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
3510 |
* invalidates the component hierarchy. |
2 | 3511 |
* |
3512 |
* @param o the new component orientation of this container and |
|
3513 |
* the components contained within it. |
|
3514 |
* @exception NullPointerException if <code>orientation</code> is null. |
|
3515 |
* @see Component#setComponentOrientation |
|
3516 |
* @see Component#getComponentOrientation |
|
3966
0ce65d9e45e2
6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents:
2805
diff
changeset
|
3517 |
* @see #invalidate |
2 | 3518 |
* @since 1.4 |
3519 |
*/ |
|
3520 |
public void applyComponentOrientation(ComponentOrientation o) { |
|
3521 |
super.applyComponentOrientation(o); |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3522 |
synchronized (getTreeLock()) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3523 |
for (int i = 0; i < component.size(); i++) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3524 |
Component comp = component.get(i); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3525 |
comp.applyComponentOrientation(o); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3526 |
} |
2 | 3527 |
} |
3528 |
} |
|
3529 |
||
3530 |
/** |
|
3531 |
* Adds a PropertyChangeListener to the listener list. The listener is |
|
3532 |
* registered for all bound properties of this class, including the |
|
3533 |
* following: |
|
3534 |
* <ul> |
|
3535 |
* <li>this Container's font ("font")</li> |
|
3536 |
* <li>this Container's background color ("background")</li> |
|
3537 |
* <li>this Container's foreground color ("foreground")</li> |
|
3538 |
* <li>this Container's focusability ("focusable")</li> |
|
3539 |
* <li>this Container's focus traversal keys enabled state |
|
3540 |
* ("focusTraversalKeysEnabled")</li> |
|
3541 |
* <li>this Container's Set of FORWARD_TRAVERSAL_KEYS |
|
3542 |
* ("forwardFocusTraversalKeys")</li> |
|
3543 |
* <li>this Container's Set of BACKWARD_TRAVERSAL_KEYS |
|
3544 |
* ("backwardFocusTraversalKeys")</li> |
|
3545 |
* <li>this Container's Set of UP_CYCLE_TRAVERSAL_KEYS |
|
3546 |
* ("upCycleFocusTraversalKeys")</li> |
|
3547 |
* <li>this Container's Set of DOWN_CYCLE_TRAVERSAL_KEYS |
|
3548 |
* ("downCycleFocusTraversalKeys")</li> |
|
3549 |
* <li>this Container's focus traversal policy ("focusTraversalPolicy") |
|
3550 |
* </li> |
|
3551 |
* <li>this Container's focus-cycle-root state ("focusCycleRoot")</li> |
|
3552 |
* </ul> |
|
3553 |
* Note that if this Container is inheriting a bound property, then no |
|
3554 |
* event will be fired in response to a change in the inherited property. |
|
3555 |
* <p> |
|
3556 |
* If listener is null, no exception is thrown and no action is performed. |
|
3557 |
* |
|
3558 |
* @param listener the PropertyChangeListener to be added |
|
3559 |
* |
|
3560 |
* @see Component#removePropertyChangeListener |
|
3561 |
* @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener) |
|
3562 |
*/ |
|
3563 |
public void addPropertyChangeListener(PropertyChangeListener listener) { |
|
3564 |
super.addPropertyChangeListener(listener); |
|
3565 |
} |
|
3566 |
||
3567 |
/** |
|
3568 |
* Adds a PropertyChangeListener to the listener list for a specific |
|
3569 |
* property. The specified property may be user-defined, or one of the |
|
3570 |
* following defaults: |
|
3571 |
* <ul> |
|
3572 |
* <li>this Container's font ("font")</li> |
|
3573 |
* <li>this Container's background color ("background")</li> |
|
3574 |
* <li>this Container's foreground color ("foreground")</li> |
|
3575 |
* <li>this Container's focusability ("focusable")</li> |
|
3576 |
* <li>this Container's focus traversal keys enabled state |
|
3577 |
* ("focusTraversalKeysEnabled")</li> |
|
3578 |
* <li>this Container's Set of FORWARD_TRAVERSAL_KEYS |
|
3579 |
* ("forwardFocusTraversalKeys")</li> |
|
3580 |
* <li>this Container's Set of BACKWARD_TRAVERSAL_KEYS |
|
3581 |
* ("backwardFocusTraversalKeys")</li> |
|
3582 |
* <li>this Container's Set of UP_CYCLE_TRAVERSAL_KEYS |
|
3583 |
* ("upCycleFocusTraversalKeys")</li> |
|
3584 |
* <li>this Container's Set of DOWN_CYCLE_TRAVERSAL_KEYS |
|
3585 |
* ("downCycleFocusTraversalKeys")</li> |
|
3586 |
* <li>this Container's focus traversal policy ("focusTraversalPolicy") |
|
3587 |
* </li> |
|
3588 |
* <li>this Container's focus-cycle-root state ("focusCycleRoot")</li> |
|
3589 |
* <li>this Container's focus-traversal-policy-provider state("focusTraversalPolicyProvider")</li> |
|
3590 |
* <li>this Container's focus-traversal-policy-provider state("focusTraversalPolicyProvider")</li> |
|
3591 |
* </ul> |
|
3592 |
* Note that if this Container is inheriting a bound property, then no |
|
3593 |
* event will be fired in response to a change in the inherited property. |
|
3594 |
* <p> |
|
3595 |
* If listener is null, no exception is thrown and no action is performed. |
|
3596 |
* |
|
3597 |
* @param propertyName one of the property names listed above |
|
3598 |
* @param listener the PropertyChangeListener to be added |
|
3599 |
* |
|
3600 |
* @see #addPropertyChangeListener(java.beans.PropertyChangeListener) |
|
3601 |
* @see Component#removePropertyChangeListener |
|
3602 |
*/ |
|
3603 |
public void addPropertyChangeListener(String propertyName, |
|
3604 |
PropertyChangeListener listener) { |
|
3605 |
super.addPropertyChangeListener(propertyName, listener); |
|
3606 |
} |
|
3607 |
||
3608 |
// Serialization support. A Container is responsible for restoring the |
|
3609 |
// parent fields of its component children. |
|
3610 |
||
3611 |
/** |
|
3612 |
* Container Serial Data Version. |
|
3613 |
*/ |
|
3614 |
private int containerSerializedDataVersion = 1; |
|
3615 |
||
3616 |
/** |
|
3617 |
* Serializes this <code>Container</code> to the specified |
|
3618 |
* <code>ObjectOutputStream</code>. |
|
3619 |
* <ul> |
|
3620 |
* <li>Writes default serializable fields to the stream.</li> |
|
3621 |
* <li>Writes a list of serializable ContainerListener(s) as optional |
|
3622 |
* data. The non-serializable ContainerListner(s) are detected and |
|
3623 |
* no attempt is made to serialize them.</li> |
|
3624 |
* <li>Write this Container's FocusTraversalPolicy if and only if it |
|
3625 |
* is Serializable; otherwise, <code>null</code> is written.</li> |
|
3626 |
* </ul> |
|
3627 |
* |
|
3628 |
* @param s the <code>ObjectOutputStream</code> to write |
|
3629 |
* @serialData <code>null</code> terminated sequence of 0 or more pairs; |
|
3630 |
* the pair consists of a <code>String</code> and <code>Object</code>; |
|
3631 |
* the <code>String</code> indicates the type of object and |
|
3632 |
* is one of the following: |
|
3633 |
* <code>containerListenerK</code> indicating an |
|
3634 |
* <code>ContainerListener</code> object; |
|
3635 |
* the <code>Container</code>'s <code>FocusTraversalPolicy</code>, |
|
3636 |
* or <code>null</code> |
|
3637 |
* |
|
3638 |
* @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener) |
|
3639 |
* @see Container#containerListenerK |
|
3640 |
* @see #readObject(ObjectInputStream) |
|
3641 |
*/ |
|
3642 |
private void writeObject(ObjectOutputStream s) throws IOException { |
|
3643 |
ObjectOutputStream.PutField f = s.putFields(); |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3644 |
f.put("ncomponents", component.size()); |
2463
c90a9d542c79
6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents:
2462
diff
changeset
|
3645 |
f.put("component", getComponentsSync()); |
2 | 3646 |
f.put("layoutMgr", layoutMgr); |
3647 |
f.put("dispatcher", dispatcher); |
|
3648 |
f.put("maxSize", maxSize); |
|
3649 |
f.put("focusCycleRoot", focusCycleRoot); |
|
3650 |
f.put("containerSerializedDataVersion", containerSerializedDataVersion); |
|
3651 |
f.put("focusTraversalPolicyProvider", focusTraversalPolicyProvider); |
|
3652 |
s.writeFields(); |
|
3653 |
||
3654 |
AWTEventMulticaster.save(s, containerListenerK, containerListener); |
|
3655 |
s.writeObject(null); |
|
3656 |
||
3657 |
if (focusTraversalPolicy instanceof java.io.Serializable) { |
|
3658 |
s.writeObject(focusTraversalPolicy); |
|
3659 |
} else { |
|
3660 |
s.writeObject(null); |
|
3661 |
} |
|
3662 |
} |
|
3663 |
||
3664 |
/** |
|
3665 |
* Deserializes this <code>Container</code> from the specified |
|
3666 |
* <code>ObjectInputStream</code>. |
|
3667 |
* <ul> |
|
3668 |
* <li>Reads default serializable fields from the stream.</li> |
|
3669 |
* <li>Reads a list of serializable ContainerListener(s) as optional |
|
3670 |
* data. If the list is null, no Listeners are installed.</li> |
|
3671 |
* <li>Reads this Container's FocusTraversalPolicy, which may be null, |
|
3672 |
* as optional data.</li> |
|
3673 |
* </ul> |
|
3674 |
* |
|
3675 |
* @param s the <code>ObjectInputStream</code> to read |
|
3676 |
* @serial |
|
3677 |
* @see #addContainerListener |
|
3678 |
* @see #writeObject(ObjectOutputStream) |
|
3679 |
*/ |
|
3680 |
private void readObject(ObjectInputStream s) |
|
3681 |
throws ClassNotFoundException, IOException |
|
3682 |
{ |
|
3683 |
ObjectInputStream.GetField f = s.readFields(); |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3684 |
Component [] tmpComponent = (Component[])f.get("component", EMPTY_ARRAY); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3685 |
int ncomponents = (Integer) f.get("ncomponents", 0); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3686 |
component = new java.util.ArrayList<Component>(ncomponents); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3687 |
for (int i = 0; i < ncomponents; ++i) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3688 |
component.add(tmpComponent[i]); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3689 |
} |
2 | 3690 |
layoutMgr = (LayoutManager)f.get("layoutMgr", null); |
3691 |
dispatcher = (LightweightDispatcher)f.get("dispatcher", null); |
|
3692 |
// Old stream. Doesn't contain maxSize among Component's fields. |
|
3693 |
if (maxSize == null) { |
|
3694 |
maxSize = (Dimension)f.get("maxSize", null); |
|
3695 |
} |
|
3696 |
focusCycleRoot = f.get("focusCycleRoot", false); |
|
3697 |
containerSerializedDataVersion = f.get("containerSerializedDataVersion", 1); |
|
3698 |
focusTraversalPolicyProvider = f.get("focusTraversalPolicyProvider", false); |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3699 |
java.util.List<Component> component = this.component; |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3700 |
for(Component comp : component) { |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3701 |
comp.parent = this; |
2 | 3702 |
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, |
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3703 |
comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK)); |
2 | 3704 |
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, |
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3705 |
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)); |
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
3706 |
adjustDescendants(comp.countHierarchyMembers()); |
2 | 3707 |
} |
3708 |
||
3709 |
Object keyOrNull; |
|
3710 |
while(null != (keyOrNull = s.readObject())) { |
|
3711 |
String key = ((String)keyOrNull).intern(); |
|
3712 |
||
3713 |
if (containerListenerK == key) { |
|
3714 |
addContainerListener((ContainerListener)(s.readObject())); |
|
3715 |
} else { |
|
3716 |
// skip value for unrecognized key |
|
3717 |
s.readObject(); |
|
3718 |
} |
|
3719 |
} |
|
3720 |
||
3721 |
try { |
|
3722 |
Object policy = s.readObject(); |
|
3723 |
if (policy instanceof FocusTraversalPolicy) { |
|
3724 |
focusTraversalPolicy = (FocusTraversalPolicy)policy; |
|
3725 |
} |
|
3726 |
} catch (java.io.OptionalDataException e) { |
|
3727 |
// JDK 1.1/1.2/1.3 instances will not have this optional data. |
|
3728 |
// e.eof will be true to indicate that there is no more data |
|
3729 |
// available for this object. If e.eof is not true, throw the |
|
3730 |
// exception as it might have been caused by reasons unrelated to |
|
3731 |
// focusTraversalPolicy. |
|
3732 |
||
3733 |
if (!e.eof) { |
|
3734 |
throw e; |
|
3735 |
} |
|
3736 |
} |
|
3737 |
} |
|
3738 |
||
3739 |
/* |
|
3740 |
* --- Accessibility Support --- |
|
3741 |
*/ |
|
3742 |
||
3743 |
/** |
|
3744 |
* Inner class of Container used to provide default support for |
|
3745 |
* accessibility. This class is not meant to be used directly by |
|
3746 |
* application developers, but is instead meant only to be |
|
3747 |
* subclassed by container developers. |
|
3748 |
* <p> |
|
3749 |
* The class used to obtain the accessible role for this object, |
|
3750 |
* as well as implementing many of the methods in the |
|
3751 |
* AccessibleContainer interface. |
|
3752 |
* @since 1.3 |
|
3753 |
*/ |
|
3754 |
protected class AccessibleAWTContainer extends AccessibleAWTComponent { |
|
3755 |
||
3756 |
/** |
|
3757 |
* JDK1.3 serialVersionUID |
|
3758 |
*/ |
|
3759 |
private static final long serialVersionUID = 5081320404842566097L; |
|
3760 |
||
3761 |
/** |
|
3762 |
* Returns the number of accessible children in the object. If all |
|
3763 |
* of the children of this object implement <code>Accessible</code>, |
|
3764 |
* then this method should return the number of children of this object. |
|
3765 |
* |
|
3766 |
* @return the number of accessible children in the object |
|
3767 |
*/ |
|
3768 |
public int getAccessibleChildrenCount() { |
|
3769 |
return Container.this.getAccessibleChildrenCount(); |
|
3770 |
} |
|
3771 |
||
3772 |
/** |
|
3773 |
* Returns the nth <code>Accessible</code> child of the object. |
|
3774 |
* |
|
3775 |
* @param i zero-based index of child |
|
3776 |
* @return the nth <code>Accessible</code> child of the object |
|
3777 |
*/ |
|
3778 |
public Accessible getAccessibleChild(int i) { |
|
3779 |
return Container.this.getAccessibleChild(i); |
|
3780 |
} |
|
3781 |
||
3782 |
/** |
|
3783 |
* Returns the <code>Accessible</code> child, if one exists, |
|
3784 |
* contained at the local coordinate <code>Point</code>. |
|
3785 |
* |
|
3786 |
* @param p the point defining the top-left corner of the |
|
3787 |
* <code>Accessible</code>, given in the coordinate space |
|
3788 |
* of the object's parent |
|
3789 |
* @return the <code>Accessible</code>, if it exists, |
|
3790 |
* at the specified location; else <code>null</code> |
|
3791 |
*/ |
|
3792 |
public Accessible getAccessibleAt(Point p) { |
|
3793 |
return Container.this.getAccessibleAt(p); |
|
3794 |
} |
|
3795 |
||
3796 |
protected ContainerListener accessibleContainerHandler = null; |
|
3797 |
||
3798 |
/** |
|
3799 |
* Fire <code>PropertyChange</code> listener, if one is registered, |
|
3800 |
* when children are added or removed. |
|
3801 |
* @since 1.3 |
|
3802 |
*/ |
|
3803 |
protected class AccessibleContainerHandler |
|
3804 |
implements ContainerListener { |
|
3805 |
public void componentAdded(ContainerEvent e) { |
|
3806 |
Component c = e.getChild(); |
|
3807 |
if (c != null && c instanceof Accessible) { |
|
3808 |
AccessibleAWTContainer.this.firePropertyChange( |
|
3809 |
AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, |
|
3810 |
null, ((Accessible) c).getAccessibleContext()); |
|
3811 |
} |
|
3812 |
} |
|
3813 |
public void componentRemoved(ContainerEvent e) { |
|
3814 |
Component c = e.getChild(); |
|
3815 |
if (c != null && c instanceof Accessible) { |
|
3816 |
AccessibleAWTContainer.this.firePropertyChange( |
|
3817 |
AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, |
|
3818 |
((Accessible) c).getAccessibleContext(), null); |
|
3819 |
} |
|
3820 |
} |
|
3821 |
} |
|
3822 |
||
3823 |
/** |
|
3824 |
* Adds a PropertyChangeListener to the listener list. |
|
3825 |
* |
|
3826 |
* @param listener the PropertyChangeListener to be added |
|
3827 |
*/ |
|
3828 |
public void addPropertyChangeListener(PropertyChangeListener listener) { |
|
3829 |
if (accessibleContainerHandler == null) { |
|
3830 |
accessibleContainerHandler = new AccessibleContainerHandler(); |
|
3831 |
Container.this.addContainerListener(accessibleContainerHandler); |
|
3832 |
} |
|
3833 |
super.addPropertyChangeListener(listener); |
|
3834 |
} |
|
3835 |
||
3836 |
} // inner class AccessibleAWTContainer |
|
3837 |
||
3838 |
/** |
|
3839 |
* Returns the <code>Accessible</code> child contained at the local |
|
3840 |
* coordinate <code>Point</code>, if one exists. Otherwise |
|
3841 |
* returns <code>null</code>. |
|
3842 |
* |
|
3843 |
* @param p the point defining the top-left corner of the |
|
3844 |
* <code>Accessible</code>, given in the coordinate space |
|
3845 |
* of the object's parent |
|
3846 |
* @return the <code>Accessible</code> at the specified location, |
|
3847 |
* if it exists; otherwise <code>null</code> |
|
3848 |
*/ |
|
3849 |
Accessible getAccessibleAt(Point p) { |
|
3850 |
synchronized (getTreeLock()) { |
|
3851 |
if (this instanceof Accessible) { |
|
3852 |
Accessible a = (Accessible)this; |
|
3853 |
AccessibleContext ac = a.getAccessibleContext(); |
|
3854 |
if (ac != null) { |
|
3855 |
AccessibleComponent acmp; |
|
3856 |
Point location; |
|
3857 |
int nchildren = ac.getAccessibleChildrenCount(); |
|
3858 |
for (int i=0; i < nchildren; i++) { |
|
3859 |
a = ac.getAccessibleChild(i); |
|
3860 |
if ((a != null)) { |
|
3861 |
ac = a.getAccessibleContext(); |
|
3862 |
if (ac != null) { |
|
3863 |
acmp = ac.getAccessibleComponent(); |
|
3864 |
if ((acmp != null) && (acmp.isShowing())) { |
|
3865 |
location = acmp.getLocation(); |
|
3866 |
Point np = new Point(p.x-location.x, |
|
3867 |
p.y-location.y); |
|
3868 |
if (acmp.contains(np)){ |
|
3869 |
return a; |
|
3870 |
} |
|
3871 |
} |
|
3872 |
} |
|
3873 |
} |
|
3874 |
} |
|
3875 |
} |
|
3876 |
return (Accessible)this; |
|
3877 |
} else { |
|
3878 |
Component ret = this; |
|
3879 |
if (!this.contains(p.x,p.y)) { |
|
3880 |
ret = null; |
|
3881 |
} else { |
|
3882 |
int ncomponents = this.getComponentCount(); |
|
3883 |
for (int i=0; i < ncomponents; i++) { |
|
3884 |
Component comp = this.getComponent(i); |
|
3885 |
if ((comp != null) && comp.isShowing()) { |
|
3886 |
Point location = comp.getLocation(); |
|
3887 |
if (comp.contains(p.x-location.x,p.y-location.y)) { |
|
3888 |
ret = comp; |
|
3889 |
} |
|
3890 |
} |
|
3891 |
} |
|
3892 |
} |
|
3893 |
if (ret instanceof Accessible) { |
|
3894 |
return (Accessible) ret; |
|
3895 |
} |
|
3896 |
} |
|
3897 |
return null; |
|
3898 |
} |
|
3899 |
} |
|
3900 |
||
3901 |
/** |
|
3902 |
* Returns the number of accessible children in the object. If all |
|
3903 |
* of the children of this object implement <code>Accessible</code>, |
|
3904 |
* then this method should return the number of children of this object. |
|
3905 |
* |
|
3906 |
* @return the number of accessible children in the object |
|
3907 |
*/ |
|
3908 |
int getAccessibleChildrenCount() { |
|
3909 |
synchronized (getTreeLock()) { |
|
3910 |
int count = 0; |
|
3911 |
Component[] children = this.getComponents(); |
|
3912 |
for (int i = 0; i < children.length; i++) { |
|
3913 |
if (children[i] instanceof Accessible) { |
|
3914 |
count++; |
|
3915 |
} |
|
3916 |
} |
|
3917 |
return count; |
|
3918 |
} |
|
3919 |
} |
|
3920 |
||
3921 |
/** |
|
3922 |
* Returns the nth <code>Accessible</code> child of the object. |
|
3923 |
* |
|
3924 |
* @param i zero-based index of child |
|
3925 |
* @return the nth <code>Accessible</code> child of the object |
|
3926 |
*/ |
|
3927 |
Accessible getAccessibleChild(int i) { |
|
3928 |
synchronized (getTreeLock()) { |
|
3929 |
Component[] children = this.getComponents(); |
|
3930 |
int count = 0; |
|
3931 |
for (int j = 0; j < children.length; j++) { |
|
3932 |
if (children[j] instanceof Accessible) { |
|
3933 |
if (count == i) { |
|
3934 |
return (Accessible) children[j]; |
|
3935 |
} else { |
|
3936 |
count++; |
|
3937 |
} |
|
3938 |
} |
|
3939 |
} |
|
3940 |
return null; |
|
3941 |
} |
|
3942 |
} |
|
3943 |
||
3944 |
// ************************** MIXING CODE ******************************* |
|
3945 |
||
3946 |
final void increaseComponentCount(Component c) { |
|
3947 |
synchronized (getTreeLock()) { |
|
3948 |
if (!c.isDisplayable()) { |
|
3949 |
throw new IllegalStateException( |
|
3950 |
"Peer does not exist while invoking the increaseComponentCount() method" |
|
3951 |
); |
|
3952 |
} |
|
3953 |
||
3954 |
int addHW = 0; |
|
3955 |
int addLW = 0; |
|
3956 |
||
3957 |
if (c instanceof Container) { |
|
3958 |
addLW = ((Container)c).numOfLWComponents; |
|
3959 |
addHW = ((Container)c).numOfHWComponents; |
|
3960 |
} |
|
3961 |
if (c.isLightweight()) { |
|
3962 |
addLW++; |
|
3963 |
} else { |
|
3964 |
addHW++; |
|
3965 |
} |
|
3966 |
||
3967 |
for (Container cont = this; cont != null; cont = cont.getContainer()) { |
|
3968 |
cont.numOfLWComponents += addLW; |
|
3969 |
cont.numOfHWComponents += addHW; |
|
3970 |
} |
|
3971 |
} |
|
3972 |
} |
|
3973 |
||
3974 |
final void decreaseComponentCount(Component c) { |
|
3975 |
synchronized (getTreeLock()) { |
|
3976 |
if (!c.isDisplayable()) { |
|
3977 |
throw new IllegalStateException( |
|
3978 |
"Peer does not exist while invoking the decreaseComponentCount() method" |
|
3979 |
); |
|
3980 |
} |
|
3981 |
||
3982 |
int subHW = 0; |
|
3983 |
int subLW = 0; |
|
3984 |
||
3985 |
if (c instanceof Container) { |
|
3986 |
subLW = ((Container)c).numOfLWComponents; |
|
3987 |
subHW = ((Container)c).numOfHWComponents; |
|
3988 |
} |
|
3989 |
if (c.isLightweight()) { |
|
3990 |
subLW++; |
|
3991 |
} else { |
|
3992 |
subHW++; |
|
3993 |
} |
|
3994 |
||
3995 |
for (Container cont = this; cont != null; cont = cont.getContainer()) { |
|
3996 |
cont.numOfLWComponents -= subLW; |
|
3997 |
cont.numOfHWComponents -= subHW; |
|
3998 |
} |
|
3999 |
} |
|
4000 |
} |
|
4001 |
||
4002 |
private int getTopmostComponentIndex() { |
|
4003 |
checkTreeLock(); |
|
4004 |
if (getComponentCount() > 0) { |
|
4005 |
return 0; |
|
4006 |
} |
|
4007 |
return -1; |
|
4008 |
} |
|
4009 |
||
4010 |
private int getBottommostComponentIndex() { |
|
4011 |
checkTreeLock(); |
|
4012 |
if (getComponentCount() > 0) { |
|
4013 |
return getComponentCount() - 1; |
|
4014 |
} |
|
4015 |
return -1; |
|
4016 |
} |
|
4017 |
||
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4018 |
/* |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4019 |
* This method is overriden to handle opaque children in non-opaque |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4020 |
* containers. |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4021 |
*/ |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4022 |
@Override |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4023 |
final Region getOpaqueShape() { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4024 |
checkTreeLock(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4025 |
if (isLightweight() && isNonOpaqueForMixing() |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4026 |
&& hasLightweightDescendants()) |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4027 |
{ |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4028 |
Region s = Region.EMPTY_REGION; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4029 |
for (int index = 0; index < getComponentCount(); index++) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4030 |
Component c = getComponent(index); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4031 |
if (c.isLightweight() && c.isShowing()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4032 |
s = s.getUnion(c.getOpaqueShape()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4033 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4034 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4035 |
return s.getIntersection(getNormalShape()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4036 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4037 |
return super.getOpaqueShape(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4038 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4039 |
|
2 | 4040 |
final void recursiveSubtractAndApplyShape(Region shape) { |
4041 |
recursiveSubtractAndApplyShape(shape, getTopmostComponentIndex(), getBottommostComponentIndex()); |
|
4042 |
} |
|
4043 |
||
4044 |
final void recursiveSubtractAndApplyShape(Region shape, int fromZorder) { |
|
4045 |
recursiveSubtractAndApplyShape(shape, fromZorder, getBottommostComponentIndex()); |
|
4046 |
} |
|
4047 |
||
4048 |
final void recursiveSubtractAndApplyShape(Region shape, int fromZorder, int toZorder) { |
|
4049 |
checkTreeLock(); |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4050 |
if (mixingLog.isLoggable(PlatformLogger.FINE)) { |
2 | 4051 |
mixingLog.fine("this = " + this + |
4052 |
"; shape=" + shape + "; fromZ=" + fromZorder + "; toZ=" + toZorder); |
|
4053 |
} |
|
4054 |
if (fromZorder == -1) { |
|
4055 |
return; |
|
4056 |
} |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4057 |
if (shape.isEmpty()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4058 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4059 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4060 |
// An invalid container with not-null layout should be ignored |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4061 |
// by the mixing code, the container will be validated later |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4062 |
// and the mixing code will be executed later. |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4063 |
if (getLayout() != null && !isValid()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4064 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4065 |
} |
2 | 4066 |
for (int index = fromZorder; index <= toZorder; index++) { |
4067 |
Component comp = getComponent(index); |
|
4068 |
if (!comp.isLightweight()) { |
|
4069 |
comp.subtractAndApplyShape(shape); |
|
4070 |
} else if (comp instanceof Container && |
|
4071 |
((Container)comp).hasHeavyweightDescendants() && comp.isShowing()) { |
|
4072 |
((Container)comp).recursiveSubtractAndApplyShape(shape); |
|
4073 |
} |
|
4074 |
} |
|
4075 |
} |
|
4076 |
||
4077 |
final void recursiveApplyCurrentShape() { |
|
4078 |
recursiveApplyCurrentShape(getTopmostComponentIndex(), getBottommostComponentIndex()); |
|
4079 |
} |
|
4080 |
||
4081 |
final void recursiveApplyCurrentShape(int fromZorder) { |
|
4082 |
recursiveApplyCurrentShape(fromZorder, getBottommostComponentIndex()); |
|
4083 |
} |
|
4084 |
||
4085 |
final void recursiveApplyCurrentShape(int fromZorder, int toZorder) { |
|
4086 |
checkTreeLock(); |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4087 |
if (mixingLog.isLoggable(PlatformLogger.FINE)) { |
2 | 4088 |
mixingLog.fine("this = " + this + |
4089 |
"; fromZ=" + fromZorder + "; toZ=" + toZorder); |
|
4090 |
} |
|
4091 |
if (fromZorder == -1) { |
|
4092 |
return; |
|
4093 |
} |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4094 |
// An invalid container with not-null layout should be ignored |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4095 |
// by the mixing code, the container will be validated later |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4096 |
// and the mixing code will be executed later. |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4097 |
if (getLayout() != null && !isValid()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4098 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4099 |
} |
2 | 4100 |
for (int index = fromZorder; index <= toZorder; index++) { |
4101 |
Component comp = getComponent(index); |
|
4102 |
if (!comp.isLightweight()) { |
|
4103 |
comp.applyCurrentShape(); |
|
2644
63360b4ca6c4
6829858: JInternalFrame is not redrawing heavyweight children properly
anthony
parents:
2463
diff
changeset
|
4104 |
} |
63360b4ca6c4
6829858: JInternalFrame is not redrawing heavyweight children properly
anthony
parents:
2463
diff
changeset
|
4105 |
if (comp instanceof Container && |
2 | 4106 |
((Container)comp).hasHeavyweightDescendants()) { |
4107 |
((Container)comp).recursiveApplyCurrentShape(); |
|
4108 |
} |
|
4109 |
} |
|
4110 |
} |
|
4111 |
||
130 | 4112 |
private void recursiveShowHeavyweightChildren() { |
4113 |
if (!hasHeavyweightDescendants() || !isVisible()) { |
|
4114 |
return; |
|
4115 |
} |
|
4116 |
for (int index = 0; index < getComponentCount(); index++) { |
|
4117 |
Component comp = getComponent(index); |
|
4118 |
if (comp.isLightweight()) { |
|
4119 |
if (comp instanceof Container) { |
|
4120 |
((Container)comp).recursiveShowHeavyweightChildren(); |
|
4121 |
} |
|
4122 |
} else { |
|
4123 |
if (comp.isVisible()) { |
|
4124 |
ComponentPeer peer = comp.getPeer(); |
|
4125 |
if (peer != null) { |
|
1964 | 4126 |
peer.setVisible(true); |
130 | 4127 |
} |
4128 |
} |
|
4129 |
} |
|
4130 |
} |
|
4131 |
} |
|
4132 |
||
4133 |
private void recursiveHideHeavyweightChildren() { |
|
4134 |
if (!hasHeavyweightDescendants()) { |
|
4135 |
return; |
|
4136 |
} |
|
4137 |
for (int index = 0; index < getComponentCount(); index++) { |
|
4138 |
Component comp = getComponent(index); |
|
4139 |
if (comp.isLightweight()) { |
|
4140 |
if (comp instanceof Container) { |
|
4141 |
((Container)comp).recursiveHideHeavyweightChildren(); |
|
4142 |
} |
|
4143 |
} else { |
|
4144 |
if (comp.isVisible()) { |
|
4145 |
ComponentPeer peer = comp.getPeer(); |
|
4146 |
if (peer != null) { |
|
1964 | 4147 |
peer.setVisible(false); |
130 | 4148 |
} |
4149 |
} |
|
4150 |
} |
|
4151 |
} |
|
4152 |
} |
|
4153 |
||
4154 |
private void recursiveRelocateHeavyweightChildren(Point origin) { |
|
4155 |
for (int index = 0; index < getComponentCount(); index++) { |
|
4156 |
Component comp = getComponent(index); |
|
4157 |
if (comp.isLightweight()) { |
|
4158 |
if (comp instanceof Container && |
|
4159 |
((Container)comp).hasHeavyweightDescendants()) |
|
4160 |
{ |
|
4161 |
final Point newOrigin = new Point(origin); |
|
4162 |
newOrigin.translate(comp.getX(), comp.getY()); |
|
4163 |
((Container)comp).recursiveRelocateHeavyweightChildren(newOrigin); |
|
4164 |
} |
|
4165 |
} else { |
|
4166 |
ComponentPeer peer = comp.getPeer(); |
|
4167 |
if (peer != null) { |
|
4168 |
peer.setBounds(origin.x + comp.getX(), origin.y + comp.getY(), |
|
4169 |
comp.getWidth(), comp.getHeight(), |
|
4170 |
ComponentPeer.SET_LOCATION); |
|
4171 |
} |
|
4172 |
} |
|
4173 |
} |
|
4174 |
} |
|
4175 |
||
4257
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4176 |
/** |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4177 |
* Checks if the container and its direct lightweight containers are |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4178 |
* visible. |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4179 |
* |
130 | 4180 |
* Consider the heavyweight container hides or shows the HW descendants |
4181 |
* automatically. Therefore we care of LW containers' visibility only. |
|
4257
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4182 |
* |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4183 |
* This method MUST be invoked under the TreeLock. |
130 | 4184 |
*/ |
4257
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4185 |
final boolean isRecursivelyVisibleUpToHeavyweightContainer() { |
130 | 4186 |
if (!isLightweight()) { |
4187 |
return true; |
|
4188 |
} |
|
4257
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4189 |
|
6827
ee4403d28487
6979568: Test failure: test\closed\java\awt\Component\VisibleHwInLwContTest\VisibleHwInLwContTest.html
anthony
parents:
5506
diff
changeset
|
4190 |
for (Container cont = this; |
4257
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4191 |
cont != null && cont.isLightweight(); |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4192 |
cont = cont.getContainer()) |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4193 |
{ |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4194 |
if (!cont.isVisible()) { |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4195 |
return false; |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4196 |
} |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4197 |
} |
c447aed67cec
6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents:
3971
diff
changeset
|
4198 |
return true; |
130 | 4199 |
} |
4200 |
||
4201 |
@Override |
|
2 | 4202 |
void mixOnShowing() { |
4203 |
synchronized (getTreeLock()) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4204 |
if (mixingLog.isLoggable(PlatformLogger.FINE)) { |
2 | 4205 |
mixingLog.fine("this = " + this); |
4206 |
} |
|
4207 |
||
4208 |
boolean isLightweight = isLightweight(); |
|
4209 |
||
130 | 4210 |
if (isLightweight && isRecursivelyVisibleUpToHeavyweightContainer()) { |
4211 |
recursiveShowHeavyweightChildren(); |
|
4212 |
} |
|
4213 |
||
3971
067e6580a577
6862611: Reg testcase closed/java/awt/Component/NativeInLightShow/NativeInLightShow.html fails
anthony
parents:
3966
diff
changeset
|
4214 |
if (!isMixingNeeded()) { |
067e6580a577
6862611: Reg testcase closed/java/awt/Component/NativeInLightShow/NativeInLightShow.html fails
anthony
parents:
3966
diff
changeset
|
4215 |
return; |
067e6580a577
6862611: Reg testcase closed/java/awt/Component/NativeInLightShow/NativeInLightShow.html fails
anthony
parents:
3966
diff
changeset
|
4216 |
} |
067e6580a577
6862611: Reg testcase closed/java/awt/Component/NativeInLightShow/NativeInLightShow.html fails
anthony
parents:
3966
diff
changeset
|
4217 |
|
2 | 4218 |
if (!isLightweight || (isLightweight && hasHeavyweightDescendants())) { |
4219 |
recursiveApplyCurrentShape(); |
|
4220 |
} |
|
4221 |
||
4222 |
super.mixOnShowing(); |
|
4223 |
} |
|
4224 |
} |
|
4225 |
||
130 | 4226 |
@Override |
4227 |
void mixOnHiding(boolean isLightweight) { |
|
4228 |
synchronized (getTreeLock()) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4229 |
if (mixingLog.isLoggable(PlatformLogger.FINE)) { |
130 | 4230 |
mixingLog.fine("this = " + this + |
4231 |
"; isLightweight=" + isLightweight); |
|
4232 |
} |
|
4233 |
if (isLightweight) { |
|
4234 |
recursiveHideHeavyweightChildren(); |
|
4235 |
} |
|
4236 |
super.mixOnHiding(isLightweight); |
|
4237 |
} |
|
4238 |
} |
|
4239 |
||
4240 |
@Override |
|
4241 |
void mixOnReshaping() { |
|
4242 |
synchronized (getTreeLock()) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4243 |
if (mixingLog.isLoggable(PlatformLogger.FINE)) { |
130 | 4244 |
mixingLog.fine("this = " + this); |
4245 |
} |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4246 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4247 |
boolean isMixingNeeded = isMixingNeeded(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4248 |
|
130 | 4249 |
if (isLightweight() && hasHeavyweightDescendants()) { |
4250 |
final Point origin = new Point(getX(), getY()); |
|
4251 |
for (Container cont = getContainer(); |
|
4252 |
cont != null && cont.isLightweight(); |
|
4253 |
cont = cont.getContainer()) |
|
4254 |
{ |
|
4255 |
origin.translate(cont.getX(), cont.getY()); |
|
4256 |
} |
|
4257 |
||
4258 |
recursiveRelocateHeavyweightChildren(origin); |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4259 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4260 |
if (!isMixingNeeded) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4261 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4262 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4263 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4264 |
recursiveApplyCurrentShape(); |
130 | 4265 |
} |
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4266 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4267 |
if (!isMixingNeeded) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4268 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4269 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4270 |
|
130 | 4271 |
super.mixOnReshaping(); |
4272 |
} |
|
4273 |
} |
|
4274 |
||
4275 |
@Override |
|
2 | 4276 |
void mixOnZOrderChanging(int oldZorder, int newZorder) { |
4277 |
synchronized (getTreeLock()) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4278 |
if (mixingLog.isLoggable(PlatformLogger.FINE)) { |
2 | 4279 |
mixingLog.fine("this = " + this + |
4280 |
"; oldZ=" + oldZorder + "; newZ=" + newZorder); |
|
4281 |
} |
|
4282 |
||
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4283 |
if (!isMixingNeeded()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4284 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4285 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4286 |
|
2 | 4287 |
boolean becameHigher = newZorder < oldZorder; |
4288 |
||
4289 |
if (becameHigher && isLightweight() && hasHeavyweightDescendants()) { |
|
4290 |
recursiveApplyCurrentShape(); |
|
4291 |
} |
|
4292 |
super.mixOnZOrderChanging(oldZorder, newZorder); |
|
4293 |
} |
|
4294 |
} |
|
4295 |
||
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4296 |
@Override |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4297 |
void mixOnValidating() { |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4298 |
synchronized (getTreeLock()) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4299 |
if (mixingLog.isLoggable(PlatformLogger.FINE)) { |
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4300 |
mixingLog.fine("this = " + this); |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4301 |
} |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4302 |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4303 |
if (!isMixingNeeded()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4304 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4305 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4306 |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4307 |
if (hasHeavyweightDescendants()) { |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4308 |
recursiveApplyCurrentShape(); |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4309 |
} |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4310 |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4311 |
if (isLightweight() && isNonOpaqueForMixing()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4312 |
subtractAndApplyShapeBelowMe(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4313 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
4314 |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4315 |
super.mixOnValidating(); |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4316 |
} |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4317 |
} |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1172
diff
changeset
|
4318 |
|
2 | 4319 |
// ****************** END OF MIXING CODE ******************************** |
4320 |
} |
|
4321 |
||
4322 |
||
4323 |
/** |
|
4324 |
* Class to manage the dispatching of MouseEvents to the lightweight descendants |
|
4325 |
* and SunDropTargetEvents to both lightweight and heavyweight descendants |
|
4326 |
* contained by a native container. |
|
4327 |
* |
|
4328 |
* NOTE: the class name is not appropriate anymore, but we cannot change it |
|
4329 |
* because we must keep serialization compatibility. |
|
4330 |
* |
|
4331 |
* @author Timothy Prinzing |
|
4332 |
*/ |
|
4333 |
class LightweightDispatcher implements java.io.Serializable, AWTEventListener { |
|
4334 |
||
4335 |
/* |
|
4336 |
* JDK 1.1 serialVersionUID |
|
4337 |
*/ |
|
4338 |
private static final long serialVersionUID = 5184291520170872969L; |
|
4339 |
/* |
|
4340 |
* Our own mouse event for when we're dragged over from another hw |
|
4341 |
* container |
|
4342 |
*/ |
|
4343 |
private static final int LWD_MOUSE_DRAGGED_OVER = 1500; |
|
4344 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4345 |
private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.LightweightDispatcher"); |
2 | 4346 |
|
4347 |
LightweightDispatcher(Container nativeContainer) { |
|
4348 |
this.nativeContainer = nativeContainer; |
|
4349 |
mouseEventTarget = null; |
|
4350 |
eventMask = 0; |
|
4351 |
} |
|
4352 |
||
4353 |
/* |
|
4354 |
* Clean up any resources allocated when dispatcher was created; |
|
4355 |
* should be called from Container.removeNotify |
|
4356 |
*/ |
|
4357 |
void dispose() { |
|
4358 |
//System.out.println("Disposing lw dispatcher"); |
|
4359 |
stopListeningForOtherDrags(); |
|
4360 |
mouseEventTarget = null; |
|
4361 |
} |
|
4362 |
||
4363 |
/** |
|
4364 |
* Enables events to subcomponents. |
|
4365 |
*/ |
|
4366 |
void enableEvents(long events) { |
|
4367 |
eventMask |= events; |
|
4368 |
} |
|
4369 |
||
4370 |
/** |
|
4371 |
* Dispatches an event to a sub-component if necessary, and |
|
4372 |
* returns whether or not the event was forwarded to a |
|
4373 |
* sub-component. |
|
4374 |
* |
|
4375 |
* @param e the event |
|
4376 |
*/ |
|
4377 |
boolean dispatchEvent(AWTEvent e) { |
|
4378 |
boolean ret = false; |
|
4379 |
||
4380 |
/* |
|
4381 |
* Fix for BugTraq Id 4389284. |
|
4382 |
* Dispatch SunDropTargetEvents regardless of eventMask value. |
|
4383 |
* Do not update cursor on dispatching SunDropTargetEvents. |
|
4384 |
*/ |
|
4385 |
if (e instanceof SunDropTargetEvent) { |
|
4386 |
||
4387 |
SunDropTargetEvent sdde = (SunDropTargetEvent) e; |
|
4388 |
ret = processDropTargetEvent(sdde); |
|
4389 |
||
4390 |
} else { |
|
4391 |
if (e instanceof MouseEvent && (eventMask & MOUSE_MASK) != 0) { |
|
4392 |
MouseEvent me = (MouseEvent) e; |
|
4393 |
ret = processMouseEvent(me); |
|
4394 |
} |
|
4395 |
||
4396 |
if (e.getID() == MouseEvent.MOUSE_MOVED) { |
|
4397 |
nativeContainer.updateCursorImmediately(); |
|
4398 |
} |
|
4399 |
} |
|
4400 |
||
4401 |
return ret; |
|
4402 |
} |
|
4403 |
||
4404 |
/* This method effectively returns whether or not a mouse button was down |
|
4405 |
* just BEFORE the event happened. A better method name might be |
|
4406 |
* wasAMouseButtonDownBeforeThisEvent(). |
|
4407 |
*/ |
|
4408 |
private boolean isMouseGrab(MouseEvent e) { |
|
4409 |
int modifiers = e.getModifiersEx(); |
|
4410 |
||
4411 |
if(e.getID() == MouseEvent.MOUSE_PRESSED |
|
4412 |
|| e.getID() == MouseEvent.MOUSE_RELEASED) |
|
4413 |
{ |
|
4414 |
switch (e.getButton()) { |
|
4415 |
case MouseEvent.BUTTON1: |
|
4416 |
modifiers ^= InputEvent.BUTTON1_DOWN_MASK; |
|
4417 |
break; |
|
4418 |
case MouseEvent.BUTTON2: |
|
4419 |
modifiers ^= InputEvent.BUTTON2_DOWN_MASK; |
|
4420 |
break; |
|
4421 |
case MouseEvent.BUTTON3: |
|
4422 |
modifiers ^= InputEvent.BUTTON3_DOWN_MASK; |
|
4423 |
break; |
|
4424 |
} |
|
4425 |
} |
|
4426 |
/* modifiers now as just before event */ |
|
4427 |
return ((modifiers & (InputEvent.BUTTON1_DOWN_MASK |
|
4428 |
| InputEvent.BUTTON2_DOWN_MASK |
|
4429 |
| InputEvent.BUTTON3_DOWN_MASK)) != 0); |
|
4430 |
} |
|
4431 |
||
4432 |
/** |
|
4433 |
* This method attempts to distribute a mouse event to a lightweight |
|
4434 |
* component. It tries to avoid doing any unnecessary probes down |
|
4435 |
* into the component tree to minimize the overhead of determining |
|
4436 |
* where to route the event, since mouse movement events tend to |
|
4437 |
* come in large and frequent amounts. |
|
4438 |
*/ |
|
4439 |
private boolean processMouseEvent(MouseEvent e) { |
|
4440 |
int id = e.getID(); |
|
4441 |
Component mouseOver = // sensitive to mouse events |
|
4442 |
nativeContainer.getMouseEventTarget(e.getX(), e.getY(), |
|
4443 |
Container.INCLUDE_SELF); |
|
4444 |
||
4445 |
trackMouseEnterExit(mouseOver, e); |
|
4446 |
||
4447 |
// 4508327 : MOUSE_CLICKED should only go to the recipient of |
|
4448 |
// the accompanying MOUSE_PRESSED, so don't reset mouseEventTarget on a |
|
4449 |
// MOUSE_CLICKED. |
|
4450 |
if (!isMouseGrab(e) && id != MouseEvent.MOUSE_CLICKED) { |
|
4451 |
mouseEventTarget = (mouseOver != nativeContainer) ? mouseOver: null; |
|
4452 |
} |
|
4453 |
||
4454 |
if (mouseEventTarget != null) { |
|
4455 |
switch (id) { |
|
4456 |
case MouseEvent.MOUSE_ENTERED: |
|
4457 |
case MouseEvent.MOUSE_EXITED: |
|
4458 |
break; |
|
4459 |
case MouseEvent.MOUSE_PRESSED: |
|
4460 |
retargetMouseEvent(mouseEventTarget, id, e); |
|
4461 |
break; |
|
4462 |
case MouseEvent.MOUSE_RELEASED: |
|
4463 |
retargetMouseEvent(mouseEventTarget, id, e); |
|
4464 |
break; |
|
4465 |
case MouseEvent.MOUSE_CLICKED: |
|
4466 |
// 4508327: MOUSE_CLICKED should never be dispatched to a Component |
|
4467 |
// other than that which received the MOUSE_PRESSED event. If the |
|
4468 |
// mouse is now over a different Component, don't dispatch the event. |
|
4469 |
// The previous fix for a similar problem was associated with bug |
|
4470 |
// 4155217. |
|
4471 |
if (mouseOver == mouseEventTarget) { |
|
4472 |
retargetMouseEvent(mouseOver, id, e); |
|
4473 |
} |
|
4474 |
break; |
|
4475 |
case MouseEvent.MOUSE_MOVED: |
|
4476 |
retargetMouseEvent(mouseEventTarget, id, e); |
|
4477 |
break; |
|
4478 |
case MouseEvent.MOUSE_DRAGGED: |
|
4479 |
if (isMouseGrab(e)) { |
|
4480 |
retargetMouseEvent(mouseEventTarget, id, e); |
|
4481 |
} |
|
4482 |
break; |
|
4483 |
case MouseEvent.MOUSE_WHEEL: |
|
4484 |
// This may send it somewhere that doesn't have MouseWheelEvents |
|
4485 |
// enabled. In this case, Component.dispatchEventImpl() will |
|
4486 |
// retarget the event to a parent that DOES have the events enabled. |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4487 |
if (eventLog.isLoggable(PlatformLogger.FINEST) && (mouseOver != null)) { |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4488 |
eventLog.finest("retargeting mouse wheel to " + |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4489 |
mouseOver.getName() + ", " + |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
4490 |
mouseOver.getClass()); |
2 | 4491 |
} |
4492 |
retargetMouseEvent(mouseOver, id, e); |
|
4493 |
break; |
|
4494 |
} |
|
5277
03170721df2e
6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents:
4263
diff
changeset
|
4495 |
//Consuming of wheel events is implemented in "retargetMouseEvent". |
03170721df2e
6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents:
4263
diff
changeset
|
4496 |
if (id != MouseEvent.MOUSE_WHEEL) { |
03170721df2e
6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents:
4263
diff
changeset
|
4497 |
e.consume(); |
03170721df2e
6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents:
4263
diff
changeset
|
4498 |
} |
2 | 4499 |
} |
4500 |
return e.isConsumed(); |
|
4501 |
} |
|
4502 |
||
4503 |
private boolean processDropTargetEvent(SunDropTargetEvent e) { |
|
4504 |
int id = e.getID(); |
|
4505 |
int x = e.getX(); |
|
4506 |
int y = e.getY(); |
|
4507 |
||
4508 |
/* |
|
4509 |
* Fix for BugTraq ID 4395290. |
|
4510 |
* It is possible that SunDropTargetEvent's Point is outside of the |
|
4511 |
* native container bounds. In this case we truncate coordinates. |
|
4512 |
*/ |
|
4513 |
if (!nativeContainer.contains(x, y)) { |
|
4514 |
final Dimension d = nativeContainer.getSize(); |
|
4515 |
if (d.width <= x) { |
|
4516 |
x = d.width - 1; |
|
4517 |
} else if (x < 0) { |
|
4518 |
x = 0; |
|
4519 |
} |
|
4520 |
if (d.height <= y) { |
|
4521 |
y = d.height - 1; |
|
4522 |
} else if (y < 0) { |
|
4523 |
y = 0; |
|
4524 |
} |
|
4525 |
} |
|
4526 |
Component mouseOver = // not necessarily sensitive to mouse events |
|
4527 |
nativeContainer.getDropTargetEventTarget(x, y, |
|
4528 |
Container.INCLUDE_SELF); |
|
4529 |
trackMouseEnterExit(mouseOver, e); |
|
4530 |
||
4531 |
if (mouseOver != nativeContainer && mouseOver != null) { |
|
4532 |
switch (id) { |
|
4533 |
case SunDropTargetEvent.MOUSE_ENTERED: |
|
4534 |
case SunDropTargetEvent.MOUSE_EXITED: |
|
4535 |
break; |
|
4536 |
default: |
|
4537 |
retargetMouseEvent(mouseOver, id, e); |
|
4538 |
e.consume(); |
|
4539 |
break; |
|
4540 |
} |
|
4541 |
} |
|
4542 |
return e.isConsumed(); |
|
4543 |
} |
|
4544 |
||
4545 |
/* |
|
4546 |
* Generates enter/exit events as mouse moves over lw components |
|
4547 |
* @param targetOver Target mouse is over (including native container) |
|
4548 |
* @param e Mouse event in native container |
|
4549 |
*/ |
|
4550 |
private void trackMouseEnterExit(Component targetOver, MouseEvent e) { |
|
4551 |
Component targetEnter = null; |
|
4552 |
int id = e.getID(); |
|
4553 |
||
4554 |
if (e instanceof SunDropTargetEvent && |
|
4555 |
id == MouseEvent.MOUSE_ENTERED && |
|
4556 |
isMouseInNativeContainer == true) { |
|
4557 |
// This can happen if a lightweight component which initiated the |
|
4558 |
// drag has an associated drop target. MOUSE_ENTERED comes when the |
|
4559 |
// mouse is in the native container already. To propagate this event |
|
4560 |
// properly we should null out targetLastEntered. |
|
4561 |
targetLastEntered = null; |
|
4562 |
} else if ( id != MouseEvent.MOUSE_EXITED && |
|
4563 |
id != MouseEvent.MOUSE_DRAGGED && |
|
4564 |
id != LWD_MOUSE_DRAGGED_OVER && |
|
4565 |
isMouseInNativeContainer == false ) { |
|
4566 |
// any event but an exit or drag means we're in the native container |
|
4567 |
isMouseInNativeContainer = true; |
|
4568 |
startListeningForOtherDrags(); |
|
4569 |
} else if ( id == MouseEvent.MOUSE_EXITED ) { |
|
4570 |
isMouseInNativeContainer = false; |
|
4571 |
stopListeningForOtherDrags(); |
|
4572 |
} |
|
4573 |
||
4574 |
if (isMouseInNativeContainer) { |
|
4575 |
targetEnter = targetOver; |
|
4576 |
} |
|
4577 |
||
4578 |
if (targetLastEntered == targetEnter) { |
|
4579 |
return; |
|
4580 |
} |
|
4581 |
||
4582 |
if (targetLastEntered != null) { |
|
4583 |
retargetMouseEvent(targetLastEntered, MouseEvent.MOUSE_EXITED, e); |
|
4584 |
} |
|
4585 |
if (id == MouseEvent.MOUSE_EXITED) { |
|
4586 |
// consume native exit event if we generate one |
|
4587 |
e.consume(); |
|
4588 |
} |
|
4589 |
||
4590 |
if (targetEnter != null) { |
|
4591 |
retargetMouseEvent(targetEnter, MouseEvent.MOUSE_ENTERED, e); |
|
4592 |
} |
|
4593 |
if (id == MouseEvent.MOUSE_ENTERED) { |
|
4594 |
// consume native enter event if we generate one |
|
4595 |
e.consume(); |
|
4596 |
} |
|
4597 |
||
4598 |
targetLastEntered = targetEnter; |
|
4599 |
} |
|
4600 |
||
4601 |
/* |
|
4602 |
* Listens to global mouse drag events so even drags originating |
|
4603 |
* from other heavyweight containers will generate enter/exit |
|
4604 |
* events in this container |
|
4605 |
*/ |
|
4606 |
private void startListeningForOtherDrags() { |
|
4607 |
//System.out.println("Adding AWTEventListener"); |
|
4608 |
java.security.AccessController.doPrivileged( |
|
4609 |
new java.security.PrivilegedAction() { |
|
4610 |
public Object run() { |
|
4611 |
nativeContainer.getToolkit().addAWTEventListener( |
|
4612 |
LightweightDispatcher.this, |
|
4613 |
AWTEvent.MOUSE_EVENT_MASK | |
|
4614 |
AWTEvent.MOUSE_MOTION_EVENT_MASK); |
|
4615 |
return null; |
|
4616 |
} |
|
4617 |
} |
|
4618 |
); |
|
4619 |
} |
|
4620 |
||
4621 |
private void stopListeningForOtherDrags() { |
|
4622 |
//System.out.println("Removing AWTEventListener"); |
|
4623 |
java.security.AccessController.doPrivileged( |
|
4624 |
new java.security.PrivilegedAction() { |
|
4625 |
public Object run() { |
|
4626 |
nativeContainer.getToolkit().removeAWTEventListener(LightweightDispatcher.this); |
|
4627 |
return null; |
|
4628 |
} |
|
4629 |
} |
|
4630 |
); |
|
4631 |
} |
|
4632 |
||
4633 |
/* |
|
4634 |
* (Implementation of AWTEventListener) |
|
4635 |
* Listen for drag events posted in other hw components so we can |
|
4636 |
* track enter/exit regardless of where a drag originated |
|
4637 |
*/ |
|
4638 |
public void eventDispatched(AWTEvent e) { |
|
4639 |
boolean isForeignDrag = (e instanceof MouseEvent) && |
|
4640 |
!(e instanceof SunDropTargetEvent) && |
|
4641 |
(e.id == MouseEvent.MOUSE_DRAGGED) && |
|
4642 |
(e.getSource() != nativeContainer); |
|
4643 |
||
4644 |
if (!isForeignDrag) { |
|
4645 |
// only interested in drags from other hw components |
|
4646 |
return; |
|
4647 |
} |
|
4648 |
||
4649 |
MouseEvent srcEvent = (MouseEvent)e; |
|
4650 |
MouseEvent me; |
|
4651 |
||
4652 |
synchronized (nativeContainer.getTreeLock()) { |
|
4653 |
Component srcComponent = srcEvent.getComponent(); |
|
4654 |
||
4655 |
// component may have disappeared since drag event posted |
|
4656 |
// (i.e. Swing hierarchical menus) |
|
4657 |
if ( !srcComponent.isShowing() ) { |
|
4658 |
return; |
|
4659 |
} |
|
4660 |
||
4661 |
// see 5083555 |
|
4662 |
// check if srcComponent is in any modal blocked window |
|
4663 |
Component c = nativeContainer; |
|
4664 |
while ((c != null) && !(c instanceof Window)) { |
|
4665 |
c = c.getParent_NoClientCode(); |
|
4666 |
} |
|
4667 |
if ((c == null) || ((Window)c).isModalBlocked()) { |
|
4668 |
return; |
|
4669 |
} |
|
4670 |
||
4671 |
// |
|
4672 |
// create an internal 'dragged-over' event indicating |
|
4673 |
// we are being dragged over from another hw component |
|
4674 |
// |
|
4675 |
me = new MouseEvent(nativeContainer, |
|
4676 |
LWD_MOUSE_DRAGGED_OVER, |
|
4677 |
srcEvent.getWhen(), |
|
4678 |
srcEvent.getModifiersEx() | srcEvent.getModifiers(), |
|
4679 |
srcEvent.getX(), |
|
4680 |
srcEvent.getY(), |
|
4681 |
srcEvent.getXOnScreen(), |
|
4682 |
srcEvent.getYOnScreen(), |
|
4683 |
srcEvent.getClickCount(), |
|
4684 |
srcEvent.isPopupTrigger(), |
|
4685 |
srcEvent.getButton()); |
|
4686 |
((AWTEvent)srcEvent).copyPrivateDataInto(me); |
|
4687 |
// translate coordinates to this native container |
|
4688 |
final Point ptSrcOrigin = srcComponent.getLocationOnScreen(); |
|
4689 |
||
4690 |
if (AppContext.getAppContext() != nativeContainer.appContext) { |
|
4691 |
final MouseEvent mouseEvent = me; |
|
4692 |
Runnable r = new Runnable() { |
|
4693 |
public void run() { |
|
4694 |
if (!nativeContainer.isShowing() ) { |
|
4695 |
return; |
|
4696 |
} |
|
4697 |
||
4698 |
Point ptDstOrigin = nativeContainer.getLocationOnScreen(); |
|
4699 |
mouseEvent.translatePoint(ptSrcOrigin.x - ptDstOrigin.x, |
|
4700 |
ptSrcOrigin.y - ptDstOrigin.y ); |
|
4701 |
Component targetOver = |
|
4702 |
nativeContainer.getMouseEventTarget(mouseEvent.getX(), |
|
4703 |
mouseEvent.getY(), |
|
4704 |
Container.INCLUDE_SELF); |
|
4705 |
trackMouseEnterExit(targetOver, mouseEvent); |
|
4706 |
} |
|
4707 |
}; |
|
4708 |
SunToolkit.executeOnEventHandlerThread(nativeContainer, r); |
|
4709 |
return; |
|
4710 |
} else { |
|
4711 |
if (!nativeContainer.isShowing() ) { |
|
4712 |
return; |
|
4713 |
} |
|
4714 |
||
4715 |
Point ptDstOrigin = nativeContainer.getLocationOnScreen(); |
|
4716 |
me.translatePoint( ptSrcOrigin.x - ptDstOrigin.x, ptSrcOrigin.y - ptDstOrigin.y ); |
|
4717 |
} |
|
4718 |
} |
|
4719 |
//System.out.println("Track event: " + me); |
|
4720 |
// feed the 'dragged-over' event directly to the enter/exit |
|
4721 |
// code (not a real event so don't pass it to dispatchEvent) |
|
4722 |
Component targetOver = |
|
4723 |
nativeContainer.getMouseEventTarget(me.getX(), me.getY(), |
|
4724 |
Container.INCLUDE_SELF); |
|
4725 |
trackMouseEnterExit(targetOver, me); |
|
4726 |
} |
|
4727 |
||
4728 |
/** |
|
4729 |
* Sends a mouse event to the current mouse event recipient using |
|
4730 |
* the given event (sent to the windowed host) as a srcEvent. If |
|
4731 |
* the mouse event target is still in the component tree, the |
|
4732 |
* coordinates of the event are translated to those of the target. |
|
4733 |
* If the target has been removed, we don't bother to send the |
|
4734 |
* message. |
|
4735 |
*/ |
|
4736 |
void retargetMouseEvent(Component target, int id, MouseEvent e) { |
|
4737 |
if (target == null) { |
|
4738 |
return; // mouse is over another hw component or target is disabled |
|
4739 |
} |
|
4740 |
||
4741 |
int x = e.getX(), y = e.getY(); |
|
4742 |
Component component; |
|
4743 |
||
4744 |
for(component = target; |
|
4745 |
component != null && component != nativeContainer; |
|
4746 |
component = component.getParent()) { |
|
4747 |
x -= component.x; |
|
4748 |
y -= component.y; |
|
4749 |
} |
|
4750 |
MouseEvent retargeted; |
|
4751 |
if (component != null) { |
|
4752 |
if (e instanceof SunDropTargetEvent) { |
|
4753 |
retargeted = new SunDropTargetEvent(target, |
|
4754 |
id, |
|
4755 |
x, |
|
4756 |
y, |
|
4757 |
((SunDropTargetEvent)e).getDispatcher()); |
|
4758 |
} else if (id == MouseEvent.MOUSE_WHEEL) { |
|
4759 |
retargeted = new MouseWheelEvent(target, |
|
4760 |
id, |
|
4761 |
e.getWhen(), |
|
4762 |
e.getModifiersEx() | e.getModifiers(), |
|
4763 |
x, |
|
4764 |
y, |
|
4765 |
e.getXOnScreen(), |
|
4766 |
e.getYOnScreen(), |
|
4767 |
e.getClickCount(), |
|
4768 |
e.isPopupTrigger(), |
|
4769 |
((MouseWheelEvent)e).getScrollType(), |
|
4770 |
((MouseWheelEvent)e).getScrollAmount(), |
|
121 | 4771 |
((MouseWheelEvent)e).getWheelRotation(), |
4772 |
((MouseWheelEvent)e).getPreciseWheelRotation()); |
|
2 | 4773 |
} |
4774 |
else { |
|
4775 |
retargeted = new MouseEvent(target, |
|
4776 |
id, |
|
4777 |
e.getWhen(), |
|
4778 |
e.getModifiersEx() | e.getModifiers(), |
|
4779 |
x, |
|
4780 |
y, |
|
4781 |
e.getXOnScreen(), |
|
4782 |
e.getYOnScreen(), |
|
4783 |
e.getClickCount(), |
|
4784 |
e.isPopupTrigger(), |
|
4785 |
e.getButton()); |
|
4786 |
} |
|
4787 |
||
4788 |
((AWTEvent)e).copyPrivateDataInto(retargeted); |
|
4789 |
||
4790 |
if (target == nativeContainer) { |
|
4791 |
// avoid recursively calling LightweightDispatcher... |
|
4792 |
((Container)target).dispatchEventToSelf(retargeted); |
|
4793 |
} else { |
|
4794 |
assert AppContext.getAppContext() == target.appContext; |
|
4795 |
||
4796 |
if (nativeContainer.modalComp != null) { |
|
4797 |
if (((Container)nativeContainer.modalComp).isAncestorOf(target)) { |
|
4798 |
target.dispatchEvent(retargeted); |
|
4799 |
} else { |
|
4800 |
e.consume(); |
|
4801 |
} |
|
4802 |
} else { |
|
4803 |
target.dispatchEvent(retargeted); |
|
4804 |
} |
|
4805 |
} |
|
5277
03170721df2e
6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents:
4263
diff
changeset
|
4806 |
if (id == MouseEvent.MOUSE_WHEEL && retargeted.isConsumed()) { |
03170721df2e
6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents:
4263
diff
changeset
|
4807 |
//An exception for wheel bubbling to the native system. |
03170721df2e
6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents:
4263
diff
changeset
|
4808 |
//In "processMouseEvent" total event consuming for wheel events is skipped. |
03170721df2e
6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents:
4263
diff
changeset
|
4809 |
//Protection from bubbling of Java-accepted wheel events. |
03170721df2e
6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents:
4263
diff
changeset
|
4810 |
e.consume(); |
03170721df2e
6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents:
4263
diff
changeset
|
4811 |
} |
2 | 4812 |
} |
4813 |
} |
|
4814 |
||
4815 |
// --- member variables ------------------------------- |
|
4816 |
||
4817 |
/** |
|
4818 |
* The windowed container that might be hosting events for |
|
4819 |
* subcomponents. |
|
4820 |
*/ |
|
4821 |
private Container nativeContainer; |
|
4822 |
||
4823 |
/** |
|
4824 |
* This variable is not used, but kept for serialization compatibility |
|
4825 |
*/ |
|
4826 |
private Component focus; |
|
4827 |
||
4828 |
/** |
|
4829 |
* The current subcomponent being hosted by this windowed |
|
4830 |
* component that has events being forwarded to it. If this |
|
4831 |
* is null, there are currently no events being forwarded to |
|
4832 |
* a subcomponent. |
|
4833 |
*/ |
|
4834 |
private transient Component mouseEventTarget; |
|
4835 |
||
4836 |
/** |
|
4837 |
* The last component entered |
|
4838 |
*/ |
|
4839 |
private transient Component targetLastEntered; |
|
4840 |
||
4841 |
/** |
|
4842 |
* Is the mouse over the native container |
|
4843 |
*/ |
|
4844 |
private transient boolean isMouseInNativeContainer = false; |
|
4845 |
||
4846 |
/** |
|
4847 |
* This variable is not used, but kept for serialization compatibility |
|
4848 |
*/ |
|
4849 |
private Cursor nativeCursor; |
|
4850 |
||
4851 |
/** |
|
4852 |
* The event mask for contained lightweight components. Lightweight |
|
4853 |
* components need a windowed container to host window-related |
|
4854 |
* events. This separate mask indicates events that have been |
|
4855 |
* requested by contained lightweight components without effecting |
|
4856 |
* the mask of the windowed component itself. |
|
4857 |
*/ |
|
4858 |
private long eventMask; |
|
4859 |
||
4860 |
/** |
|
4861 |
* The kind of events routed to lightweight components from windowed |
|
4862 |
* hosts. |
|
4863 |
*/ |
|
4864 |
private static final long PROXY_EVENT_MASK = |
|
4865 |
AWTEvent.FOCUS_EVENT_MASK | |
|
4866 |
AWTEvent.KEY_EVENT_MASK | |
|
4867 |
AWTEvent.MOUSE_EVENT_MASK | |
|
4868 |
AWTEvent.MOUSE_MOTION_EVENT_MASK | |
|
4869 |
AWTEvent.MOUSE_WHEEL_EVENT_MASK; |
|
4870 |
||
4871 |
private static final long MOUSE_MASK = |
|
4872 |
AWTEvent.MOUSE_EVENT_MASK | |
|
4873 |
AWTEvent.MOUSE_MOTION_EVENT_MASK | |
|
4874 |
AWTEvent.MOUSE_WHEEL_EVENT_MASK; |
|
4875 |
} |