author | anthony |
Fri, 28 Aug 2009 19:34:00 +0400 | |
changeset 3729 | 80d0cf73598d |
parent 3727 | 43b25dfd1129 |
child 3966 | 0ce65d9e45e2 |
child 3932 | c9cd7ff79037 |
child 4209 | e2e5a973b879 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2451 | 2 |
* Copyright 1995-2009 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
package java.awt; |
|
26 |
||
27 |
import java.io.PrintStream; |
|
28 |
import java.io.PrintWriter; |
|
29 |
import java.util.Vector; |
|
30 |
import java.util.Locale; |
|
31 |
import java.util.EventListener; |
|
32 |
import java.util.Iterator; |
|
33 |
import java.util.HashSet; |
|
34 |
import java.util.Map; |
|
35 |
import java.util.Set; |
|
36 |
import java.util.Collections; |
|
37 |
import java.awt.peer.ComponentPeer; |
|
38 |
import java.awt.peer.ContainerPeer; |
|
39 |
import java.awt.peer.LightweightPeer; |
|
40 |
import java.awt.image.BufferStrategy; |
|
41 |
import java.awt.image.ImageObserver; |
|
42 |
import java.awt.image.ImageProducer; |
|
43 |
import java.awt.image.ColorModel; |
|
44 |
import java.awt.image.VolatileImage; |
|
45 |
import java.awt.event.*; |
|
46 |
import java.io.Serializable; |
|
47 |
import java.io.ObjectOutputStream; |
|
48 |
import java.io.ObjectInputStream; |
|
49 |
import java.io.IOException; |
|
50 |
import java.beans.PropertyChangeListener; |
|
51 |
import java.beans.PropertyChangeSupport; |
|
466
6acd5ec503a8
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents:
130
diff
changeset
|
52 |
import java.beans.Transient; |
2 | 53 |
import java.awt.event.InputMethodListener; |
54 |
import java.awt.event.InputMethodEvent; |
|
55 |
import java.awt.im.InputContext; |
|
56 |
import java.awt.im.InputMethodRequests; |
|
57 |
import java.awt.dnd.DropTarget; |
|
58 |
import java.lang.reflect.InvocationTargetException; |
|
59 |
import java.lang.reflect.Method; |
|
60 |
import java.security.AccessController; |
|
61 |
import java.security.PrivilegedAction; |
|
62 |
import javax.accessibility.*; |
|
63 |
import java.util.logging.*; |
|
64 |
import java.applet.Applet; |
|
65 |
||
66 |
import sun.security.action.GetPropertyAction; |
|
67 |
import sun.awt.AppContext; |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
68 |
import sun.awt.AWTAccessor; |
2 | 69 |
import sun.awt.ConstrainableGraphics; |
70 |
import sun.awt.SubRegionShowable; |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
71 |
import sun.awt.SunToolkit; |
2 | 72 |
import sun.awt.WindowClosingListener; |
73 |
import sun.awt.CausedFocusEvent; |
|
74 |
import sun.awt.EmbeddedFrame; |
|
75 |
import sun.awt.dnd.SunDropTargetEvent; |
|
76 |
import sun.awt.im.CompositionArea; |
|
77 |
import sun.java2d.SunGraphics2D; |
|
78 |
import sun.java2d.pipe.Region; |
|
887 | 79 |
import sun.awt.image.VSyncedBSManager; |
80 |
import sun.java2d.pipe.hw.ExtendedBufferCapabilities; |
|
81 |
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*; |
|
2 | 82 |
import sun.awt.RequestFocusController; |
887 | 83 |
import sun.java2d.SunGraphicsEnvironment; |
2 | 84 |
|
85 |
/** |
|
86 |
* A <em>component</em> is an object having a graphical representation |
|
87 |
* that can be displayed on the screen and that can interact with the |
|
88 |
* user. Examples of components are the buttons, checkboxes, and scrollbars |
|
89 |
* of a typical graphical user interface. <p> |
|
90 |
* The <code>Component</code> class is the abstract superclass of |
|
91 |
* the nonmenu-related Abstract Window Toolkit components. Class |
|
92 |
* <code>Component</code> can also be extended directly to create a |
|
93 |
* lightweight component. A lightweight component is a component that is |
|
94 |
* not associated with a native opaque window. |
|
95 |
* <p> |
|
96 |
* <h3>Serialization</h3> |
|
97 |
* It is important to note that only AWT listeners which conform |
|
98 |
* to the <code>Serializable</code> protocol will be saved when |
|
99 |
* the object is stored. If an AWT object has listeners that |
|
100 |
* aren't marked serializable, they will be dropped at |
|
101 |
* <code>writeObject</code> time. Developers will need, as always, |
|
102 |
* to consider the implications of making an object serializable. |
|
103 |
* One situation to watch out for is this: |
|
104 |
* <pre> |
|
105 |
* import java.awt.*; |
|
106 |
* import java.awt.event.*; |
|
107 |
* import java.io.Serializable; |
|
108 |
* |
|
109 |
* class MyApp implements ActionListener, Serializable |
|
110 |
* { |
|
111 |
* BigObjectThatShouldNotBeSerializedWithAButton bigOne; |
|
112 |
* Button aButton = new Button(); |
|
113 |
* |
|
114 |
* MyApp() |
|
115 |
* { |
|
116 |
* // Oops, now aButton has a listener with a reference |
|
117 |
* // to bigOne! |
|
118 |
* aButton.addActionListener(this); |
|
119 |
* } |
|
120 |
* |
|
121 |
* public void actionPerformed(ActionEvent e) |
|
122 |
* { |
|
123 |
* System.out.println("Hello There"); |
|
124 |
* } |
|
125 |
* } |
|
126 |
* </pre> |
|
127 |
* In this example, serializing <code>aButton</code> by itself |
|
128 |
* will cause <code>MyApp</code> and everything it refers to |
|
129 |
* to be serialized as well. The problem is that the listener |
|
130 |
* is serializable by coincidence, not by design. To separate |
|
131 |
* the decisions about <code>MyApp</code> and the |
|
132 |
* <code>ActionListener</code> being serializable one can use a |
|
133 |
* nested class, as in the following example: |
|
134 |
* <pre> |
|
135 |
* import java.awt.*; |
|
136 |
* import java.awt.event.*; |
|
137 |
* import java.io.Serializable; |
|
138 |
* |
|
139 |
* class MyApp java.io.Serializable |
|
140 |
* { |
|
141 |
* BigObjectThatShouldNotBeSerializedWithAButton bigOne; |
|
142 |
* Button aButton = new Button(); |
|
143 |
* |
|
144 |
* static class MyActionListener implements ActionListener |
|
145 |
* { |
|
146 |
* public void actionPerformed(ActionEvent e) |
|
147 |
* { |
|
148 |
* System.out.println("Hello There"); |
|
149 |
* } |
|
150 |
* } |
|
151 |
* |
|
152 |
* MyApp() |
|
153 |
* { |
|
154 |
* aButton.addActionListener(new MyActionListener()); |
|
155 |
* } |
|
156 |
* } |
|
157 |
* </pre> |
|
158 |
* <p> |
|
159 |
* <b>Note</b>: For more information on the paint mechanisms utilitized |
|
160 |
* by AWT and Swing, including information on how to write the most |
|
161 |
* efficient painting code, see |
|
162 |
* <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. |
|
163 |
* <p> |
|
164 |
* For details on the focus subsystem, see |
|
165 |
* <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html"> |
|
166 |
* How to Use the Focus Subsystem</a>, |
|
167 |
* a section in <em>The Java Tutorial</em>, and the |
|
168 |
* <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a> |
|
169 |
* for more information. |
|
170 |
* |
|
171 |
* @author Arthur van Hoff |
|
172 |
* @author Sami Shaio |
|
173 |
*/ |
|
174 |
public abstract class Component implements ImageObserver, MenuContainer, |
|
175 |
Serializable |
|
176 |
{ |
|
177 |
||
178 |
private static final Logger log = Logger.getLogger("java.awt.Component"); |
|
179 |
private static final Logger eventLog = Logger.getLogger("java.awt.event.Component"); |
|
180 |
private static final Logger focusLog = Logger.getLogger("java.awt.focus.Component"); |
|
181 |
private static final Logger mixingLog = Logger.getLogger("java.awt.mixing.Component"); |
|
182 |
||
183 |
/** |
|
184 |
* The peer of the component. The peer implements the component's |
|
185 |
* behavior. The peer is set when the <code>Component</code> is |
|
186 |
* added to a container that also is a peer. |
|
187 |
* @see #addNotify |
|
188 |
* @see #removeNotify |
|
189 |
*/ |
|
190 |
transient ComponentPeer peer; |
|
191 |
||
192 |
/** |
|
193 |
* The parent of the object. It may be <code>null</code> |
|
194 |
* for top-level components. |
|
195 |
* @see #getParent |
|
196 |
*/ |
|
197 |
transient Container parent; |
|
198 |
||
199 |
/** |
|
200 |
* The <code>AppContext</code> of the component. Applets/Plugin may |
|
201 |
* change the AppContext. |
|
202 |
*/ |
|
203 |
transient AppContext appContext; |
|
204 |
||
205 |
/** |
|
206 |
* The x position of the component in the parent's coordinate system. |
|
207 |
* |
|
208 |
* @serial |
|
209 |
* @see #getLocation |
|
210 |
*/ |
|
211 |
int x; |
|
212 |
||
213 |
/** |
|
214 |
* The y position of the component in the parent's coordinate system. |
|
215 |
* |
|
216 |
* @serial |
|
217 |
* @see #getLocation |
|
218 |
*/ |
|
219 |
int y; |
|
220 |
||
221 |
/** |
|
222 |
* The width of the component. |
|
223 |
* |
|
224 |
* @serial |
|
225 |
* @see #getSize |
|
226 |
*/ |
|
227 |
int width; |
|
228 |
||
229 |
/** |
|
230 |
* The height of the component. |
|
231 |
* |
|
232 |
* @serial |
|
233 |
* @see #getSize |
|
234 |
*/ |
|
235 |
int height; |
|
236 |
||
237 |
/** |
|
238 |
* The foreground color for this component. |
|
239 |
* <code>foreground</code> can be <code>null</code>. |
|
240 |
* |
|
241 |
* @serial |
|
242 |
* @see #getForeground |
|
243 |
* @see #setForeground |
|
244 |
*/ |
|
245 |
Color foreground; |
|
246 |
||
247 |
/** |
|
248 |
* The background color for this component. |
|
249 |
* <code>background</code> can be <code>null</code>. |
|
250 |
* |
|
251 |
* @serial |
|
252 |
* @see #getBackground |
|
253 |
* @see #setBackground |
|
254 |
*/ |
|
255 |
Color background; |
|
256 |
||
257 |
/** |
|
258 |
* The font used by this component. |
|
259 |
* The <code>font</code> can be <code>null</code>. |
|
260 |
* |
|
261 |
* @serial |
|
262 |
* @see #getFont |
|
263 |
* @see #setFont |
|
264 |
*/ |
|
265 |
Font font; |
|
266 |
||
267 |
/** |
|
268 |
* The font which the peer is currently using. |
|
269 |
* (<code>null</code> if no peer exists.) |
|
270 |
*/ |
|
271 |
Font peerFont; |
|
272 |
||
273 |
/** |
|
274 |
* The cursor displayed when pointer is over this component. |
|
275 |
* This value can be <code>null</code>. |
|
276 |
* |
|
277 |
* @serial |
|
278 |
* @see #getCursor |
|
279 |
* @see #setCursor |
|
280 |
*/ |
|
281 |
Cursor cursor; |
|
282 |
||
283 |
/** |
|
284 |
* The locale for the component. |
|
285 |
* |
|
286 |
* @serial |
|
287 |
* @see #getLocale |
|
288 |
* @see #setLocale |
|
289 |
*/ |
|
290 |
Locale locale; |
|
291 |
||
292 |
/** |
|
293 |
* A reference to a <code>GraphicsConfiguration</code> object |
|
294 |
* used to describe the characteristics of a graphics |
|
295 |
* destination. |
|
296 |
* This value can be <code>null</code>. |
|
297 |
* |
|
298 |
* @since 1.3 |
|
299 |
* @serial |
|
300 |
* @see GraphicsConfiguration |
|
301 |
* @see #getGraphicsConfiguration |
|
302 |
*/ |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
303 |
private transient GraphicsConfiguration graphicsConfig = null; |
2 | 304 |
|
305 |
/** |
|
306 |
* A reference to a <code>BufferStrategy</code> object |
|
307 |
* used to manipulate the buffers on this component. |
|
308 |
* |
|
309 |
* @since 1.4 |
|
310 |
* @see java.awt.image.BufferStrategy |
|
311 |
* @see #getBufferStrategy() |
|
312 |
*/ |
|
313 |
transient BufferStrategy bufferStrategy = null; |
|
314 |
||
315 |
/** |
|
316 |
* True when the object should ignore all repaint events. |
|
317 |
* |
|
318 |
* @since 1.4 |
|
319 |
* @serial |
|
320 |
* @see #setIgnoreRepaint |
|
321 |
* @see #getIgnoreRepaint |
|
322 |
*/ |
|
323 |
boolean ignoreRepaint = false; |
|
324 |
||
325 |
/** |
|
326 |
* True when the object is visible. An object that is not |
|
327 |
* visible is not drawn on the screen. |
|
328 |
* |
|
329 |
* @serial |
|
330 |
* @see #isVisible |
|
331 |
* @see #setVisible |
|
332 |
*/ |
|
333 |
boolean visible = true; |
|
334 |
||
335 |
/** |
|
336 |
* True when the object is enabled. An object that is not |
|
337 |
* enabled does not interact with the user. |
|
338 |
* |
|
339 |
* @serial |
|
340 |
* @see #isEnabled |
|
341 |
* @see #setEnabled |
|
342 |
*/ |
|
343 |
boolean enabled = true; |
|
344 |
||
345 |
/** |
|
346 |
* True when the object is valid. An invalid object needs to |
|
347 |
* be layed out. This flag is set to false when the object |
|
348 |
* size is changed. |
|
349 |
* |
|
350 |
* @serial |
|
351 |
* @see #isValid |
|
352 |
* @see #validate |
|
353 |
* @see #invalidate |
|
354 |
*/ |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
355 |
private volatile boolean valid = false; |
2 | 356 |
|
357 |
/** |
|
358 |
* The <code>DropTarget</code> associated with this component. |
|
359 |
* |
|
360 |
* @since 1.2 |
|
361 |
* @serial |
|
362 |
* @see #setDropTarget |
|
363 |
* @see #getDropTarget |
|
364 |
*/ |
|
365 |
DropTarget dropTarget; |
|
366 |
||
367 |
/** |
|
368 |
* @serial |
|
369 |
* @see #add |
|
370 |
*/ |
|
371 |
Vector popups; |
|
372 |
||
373 |
/** |
|
374 |
* A component's name. |
|
375 |
* This field can be <code>null</code>. |
|
376 |
* |
|
377 |
* @serial |
|
378 |
* @see #getName |
|
379 |
* @see #setName(String) |
|
380 |
*/ |
|
381 |
private String name; |
|
382 |
||
383 |
/** |
|
384 |
* A bool to determine whether the name has |
|
385 |
* been set explicitly. <code>nameExplicitlySet</code> will |
|
386 |
* be false if the name has not been set and |
|
387 |
* true if it has. |
|
388 |
* |
|
389 |
* @serial |
|
390 |
* @see #getName |
|
391 |
* @see #setName(String) |
|
392 |
*/ |
|
393 |
private boolean nameExplicitlySet = false; |
|
394 |
||
395 |
/** |
|
396 |
* Indicates whether this Component can be focused. |
|
397 |
* |
|
398 |
* @serial |
|
399 |
* @see #setFocusable |
|
400 |
* @see #isFocusable |
|
401 |
* @since 1.4 |
|
402 |
*/ |
|
403 |
private boolean focusable = true; |
|
404 |
||
405 |
private static final int FOCUS_TRAVERSABLE_UNKNOWN = 0; |
|
406 |
private static final int FOCUS_TRAVERSABLE_DEFAULT = 1; |
|
407 |
private static final int FOCUS_TRAVERSABLE_SET = 2; |
|
408 |
||
409 |
/** |
|
410 |
* Tracks whether this Component is relying on default focus travesability. |
|
411 |
* |
|
412 |
* @serial |
|
413 |
* @since 1.4 |
|
414 |
*/ |
|
415 |
private int isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN; |
|
416 |
||
417 |
/** |
|
418 |
* The focus traversal keys. These keys will generate focus traversal |
|
419 |
* behavior for Components for which focus traversal keys are enabled. If a |
|
420 |
* value of null is specified for a traversal key, this Component inherits |
|
421 |
* that traversal key from its parent. If all ancestors of this Component |
|
422 |
* have null specified for that traversal key, then the current |
|
423 |
* KeyboardFocusManager's default traversal key is used. |
|
424 |
* |
|
425 |
* @serial |
|
426 |
* @see #setFocusTraversalKeys |
|
427 |
* @see #getFocusTraversalKeys |
|
428 |
* @since 1.4 |
|
429 |
*/ |
|
430 |
Set[] focusTraversalKeys; |
|
431 |
||
432 |
private static final String[] focusTraversalKeyPropertyNames = { |
|
433 |
"forwardFocusTraversalKeys", |
|
434 |
"backwardFocusTraversalKeys", |
|
435 |
"upCycleFocusTraversalKeys", |
|
436 |
"downCycleFocusTraversalKeys" |
|
437 |
}; |
|
438 |
||
439 |
/** |
|
440 |
* Indicates whether focus traversal keys are enabled for this Component. |
|
441 |
* Components for which focus traversal keys are disabled receive key |
|
442 |
* events for focus traversal keys. Components for which focus traversal |
|
443 |
* keys are enabled do not see these events; instead, the events are |
|
444 |
* automatically converted to traversal operations. |
|
445 |
* |
|
446 |
* @serial |
|
447 |
* @see #setFocusTraversalKeysEnabled |
|
448 |
* @see #getFocusTraversalKeysEnabled |
|
449 |
* @since 1.4 |
|
450 |
*/ |
|
451 |
private boolean focusTraversalKeysEnabled = true; |
|
452 |
||
453 |
/** |
|
454 |
* The locking object for AWT component-tree and layout operations. |
|
455 |
* |
|
456 |
* @see #getTreeLock |
|
457 |
*/ |
|
458 |
static final Object LOCK = new AWTTreeLock(); |
|
459 |
static class AWTTreeLock {} |
|
460 |
||
461 |
/** |
|
462 |
* Minimum size. |
|
463 |
* (This field perhaps should have been transient). |
|
464 |
* |
|
465 |
* @serial |
|
466 |
*/ |
|
467 |
Dimension minSize; |
|
468 |
||
469 |
/** |
|
470 |
* Whether or not setMinimumSize has been invoked with a non-null value. |
|
471 |
*/ |
|
472 |
boolean minSizeSet; |
|
473 |
||
474 |
/** |
|
475 |
* Preferred size. |
|
476 |
* (This field perhaps should have been transient). |
|
477 |
* |
|
478 |
* @serial |
|
479 |
*/ |
|
480 |
Dimension prefSize; |
|
481 |
||
482 |
/** |
|
483 |
* Whether or not setPreferredSize has been invoked with a non-null value. |
|
484 |
*/ |
|
485 |
boolean prefSizeSet; |
|
486 |
||
487 |
/** |
|
488 |
* Maximum size |
|
489 |
* |
|
490 |
* @serial |
|
491 |
*/ |
|
492 |
Dimension maxSize; |
|
493 |
||
494 |
/** |
|
495 |
* Whether or not setMaximumSize has been invoked with a non-null value. |
|
496 |
*/ |
|
497 |
boolean maxSizeSet; |
|
498 |
||
499 |
/** |
|
500 |
* The orientation for this component. |
|
501 |
* @see #getComponentOrientation |
|
502 |
* @see #setComponentOrientation |
|
503 |
*/ |
|
504 |
transient ComponentOrientation componentOrientation |
|
505 |
= ComponentOrientation.UNKNOWN; |
|
506 |
||
507 |
/** |
|
508 |
* <code>newEventsOnly</code> will be true if the event is |
|
509 |
* one of the event types enabled for the component. |
|
510 |
* It will then allow for normal processing to |
|
511 |
* continue. If it is false the event is passed |
|
512 |
* to the component's parent and up the ancestor |
|
513 |
* tree until the event has been consumed. |
|
514 |
* |
|
515 |
* @serial |
|
516 |
* @see #dispatchEvent |
|
517 |
*/ |
|
518 |
boolean newEventsOnly = false; |
|
519 |
transient ComponentListener componentListener; |
|
520 |
transient FocusListener focusListener; |
|
521 |
transient HierarchyListener hierarchyListener; |
|
522 |
transient HierarchyBoundsListener hierarchyBoundsListener; |
|
523 |
transient KeyListener keyListener; |
|
524 |
transient MouseListener mouseListener; |
|
525 |
transient MouseMotionListener mouseMotionListener; |
|
526 |
transient MouseWheelListener mouseWheelListener; |
|
527 |
transient InputMethodListener inputMethodListener; |
|
528 |
||
529 |
transient RuntimeException windowClosingException = null; |
|
530 |
||
531 |
/** Internal, constants for serialization */ |
|
532 |
final static String actionListenerK = "actionL"; |
|
533 |
final static String adjustmentListenerK = "adjustmentL"; |
|
534 |
final static String componentListenerK = "componentL"; |
|
535 |
final static String containerListenerK = "containerL"; |
|
536 |
final static String focusListenerK = "focusL"; |
|
537 |
final static String itemListenerK = "itemL"; |
|
538 |
final static String keyListenerK = "keyL"; |
|
539 |
final static String mouseListenerK = "mouseL"; |
|
540 |
final static String mouseMotionListenerK = "mouseMotionL"; |
|
541 |
final static String mouseWheelListenerK = "mouseWheelL"; |
|
542 |
final static String textListenerK = "textL"; |
|
543 |
final static String ownedWindowK = "ownedL"; |
|
544 |
final static String windowListenerK = "windowL"; |
|
545 |
final static String inputMethodListenerK = "inputMethodL"; |
|
546 |
final static String hierarchyListenerK = "hierarchyL"; |
|
547 |
final static String hierarchyBoundsListenerK = "hierarchyBoundsL"; |
|
548 |
final static String windowStateListenerK = "windowStateL"; |
|
549 |
final static String windowFocusListenerK = "windowFocusL"; |
|
550 |
||
551 |
/** |
|
552 |
* The <code>eventMask</code> is ONLY set by subclasses via |
|
553 |
* <code>enableEvents</code>. |
|
554 |
* The mask should NOT be set when listeners are registered |
|
555 |
* so that we can distinguish the difference between when |
|
556 |
* listeners request events and subclasses request them. |
|
557 |
* One bit is used to indicate whether input methods are |
|
558 |
* enabled; this bit is set by <code>enableInputMethods</code> and is |
|
559 |
* on by default. |
|
560 |
* |
|
561 |
* @serial |
|
562 |
* @see #enableInputMethods |
|
563 |
* @see AWTEvent |
|
564 |
*/ |
|
565 |
long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK; |
|
566 |
||
567 |
/** |
|
568 |
* Static properties for incremental drawing. |
|
569 |
* @see #imageUpdate |
|
570 |
*/ |
|
571 |
static boolean isInc; |
|
572 |
static int incRate; |
|
573 |
static { |
|
574 |
/* ensure that the necessary native libraries are loaded */ |
|
575 |
Toolkit.loadLibraries(); |
|
576 |
/* initialize JNI field and method ids */ |
|
577 |
if (!GraphicsEnvironment.isHeadless()) { |
|
578 |
initIDs(); |
|
579 |
} |
|
580 |
||
581 |
String s = (String) java.security.AccessController.doPrivileged( |
|
582 |
new GetPropertyAction("awt.image.incrementaldraw")); |
|
583 |
isInc = (s == null || s.equals("true")); |
|
584 |
||
585 |
s = (String) java.security.AccessController.doPrivileged( |
|
586 |
new GetPropertyAction("awt.image.redrawrate")); |
|
587 |
incRate = (s != null) ? Integer.parseInt(s) : 100; |
|
588 |
} |
|
589 |
||
590 |
/** |
|
591 |
* Ease-of-use constant for <code>getAlignmentY()</code>. |
|
592 |
* Specifies an alignment to the top of the component. |
|
593 |
* @see #getAlignmentY |
|
594 |
*/ |
|
595 |
public static final float TOP_ALIGNMENT = 0.0f; |
|
596 |
||
597 |
/** |
|
598 |
* Ease-of-use constant for <code>getAlignmentY</code> and |
|
599 |
* <code>getAlignmentX</code>. Specifies an alignment to |
|
600 |
* the center of the component |
|
601 |
* @see #getAlignmentX |
|
602 |
* @see #getAlignmentY |
|
603 |
*/ |
|
604 |
public static final float CENTER_ALIGNMENT = 0.5f; |
|
605 |
||
606 |
/** |
|
607 |
* Ease-of-use constant for <code>getAlignmentY</code>. |
|
608 |
* Specifies an alignment to the bottom of the component. |
|
609 |
* @see #getAlignmentY |
|
610 |
*/ |
|
611 |
public static final float BOTTOM_ALIGNMENT = 1.0f; |
|
612 |
||
613 |
/** |
|
614 |
* Ease-of-use constant for <code>getAlignmentX</code>. |
|
615 |
* Specifies an alignment to the left side of the component. |
|
616 |
* @see #getAlignmentX |
|
617 |
*/ |
|
618 |
public static final float LEFT_ALIGNMENT = 0.0f; |
|
619 |
||
620 |
/** |
|
621 |
* Ease-of-use constant for <code>getAlignmentX</code>. |
|
622 |
* Specifies an alignment to the right side of the component. |
|
623 |
* @see #getAlignmentX |
|
624 |
*/ |
|
625 |
public static final float RIGHT_ALIGNMENT = 1.0f; |
|
626 |
||
627 |
/* |
|
628 |
* JDK 1.1 serialVersionUID |
|
629 |
*/ |
|
630 |
private static final long serialVersionUID = -7644114512714619750L; |
|
631 |
||
632 |
/** |
|
633 |
* If any <code>PropertyChangeListeners</code> have been registered, |
|
634 |
* the <code>changeSupport</code> field describes them. |
|
635 |
* |
|
636 |
* @serial |
|
637 |
* @since 1.2 |
|
638 |
* @see #addPropertyChangeListener |
|
639 |
* @see #removePropertyChangeListener |
|
640 |
* @see #firePropertyChange |
|
641 |
*/ |
|
642 |
private PropertyChangeSupport changeSupport; |
|
643 |
||
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
644 |
/* |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
645 |
* In some cases using "this" as an object to synchronize by |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
646 |
* can lead to a deadlock if client code also uses synchronization |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
647 |
* by a component object. For every such situation revealed we should |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
648 |
* consider possibility of replacing "this" with the package private |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
649 |
* objectLock object introduced below. So far there're 2 issues known: |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
650 |
* - CR 6708322 (the getName/setName methods); |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
651 |
* - CR 6608764 (the PropertyChangeListener machinery). |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
652 |
* |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
653 |
* Note: this field is considered final, though readObject() prohibits |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
654 |
* initializing final fields. |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
655 |
*/ |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
656 |
private transient Object objectLock = new Object(); |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
657 |
Object getObjectLock() { |
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
658 |
return objectLock; |
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
659 |
} |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
660 |
|
2 | 661 |
boolean isPacked = false; |
662 |
||
663 |
/** |
|
664 |
* Pseudoparameter for direct Geometry API (setLocation, setBounds setSize |
|
665 |
* to signal setBounds what's changing. Should be used under TreeLock. |
|
666 |
* This is only needed due to the inability to change the cross-calling |
|
667 |
* order of public and deprecated methods. |
|
668 |
*/ |
|
669 |
private int boundsOp = ComponentPeer.DEFAULT_OPERATION; |
|
670 |
||
671 |
/** |
|
672 |
* Enumeration of the common ways the baseline of a component can |
|
673 |
* change as the size changes. The baseline resize behavior is |
|
674 |
* primarily for layout managers that need to know how the |
|
675 |
* position of the baseline changes as the component size changes. |
|
676 |
* In general the baseline resize behavior will be valid for sizes |
|
677 |
* greater than or equal to the minimum size (the actual minimum |
|
678 |
* size; not a developer specified minimum size). For sizes |
|
679 |
* smaller than the minimum size the baseline may change in a way |
|
680 |
* other than the baseline resize behavior indicates. Similarly, |
|
681 |
* as the size approaches <code>Integer.MAX_VALUE</code> and/or |
|
682 |
* <code>Short.MAX_VALUE</code> the baseline may change in a way |
|
683 |
* other than the baseline resize behavior indicates. |
|
684 |
* |
|
685 |
* @see #getBaselineResizeBehavior |
|
686 |
* @see #getBaseline(int,int) |
|
687 |
* @since 1.6 |
|
688 |
*/ |
|
689 |
public enum BaselineResizeBehavior { |
|
690 |
/** |
|
691 |
* Indicates the baseline remains fixed relative to the |
|
692 |
* y-origin. That is, <code>getBaseline</code> returns |
|
693 |
* the same value regardless of the height or width. For example, a |
|
694 |
* <code>JLabel</code> containing non-empty text with a |
|
695 |
* vertical alignment of <code>TOP</code> should have a |
|
696 |
* baseline type of <code>CONSTANT_ASCENT</code>. |
|
697 |
*/ |
|
698 |
CONSTANT_ASCENT, |
|
699 |
||
700 |
/** |
|
701 |
* Indicates the baseline remains fixed relative to the height |
|
702 |
* and does not change as the width is varied. That is, for |
|
703 |
* any height H the difference between H and |
|
704 |
* <code>getBaseline(w, H)</code> is the same. For example, a |
|
705 |
* <code>JLabel</code> containing non-empty text with a |
|
706 |
* vertical alignment of <code>BOTTOM</code> should have a |
|
707 |
* baseline type of <code>CONSTANT_DESCENT</code>. |
|
708 |
*/ |
|
709 |
CONSTANT_DESCENT, |
|
710 |
||
711 |
/** |
|
712 |
* Indicates the baseline remains a fixed distance from |
|
713 |
* the center of the component. That is, for any height H the |
|
714 |
* difference between <code>getBaseline(w, H)</code> and |
|
715 |
* <code>H / 2</code> is the same (plus or minus one depending upon |
|
716 |
* rounding error). |
|
717 |
* <p> |
|
718 |
* Because of possible rounding errors it is recommended |
|
719 |
* you ask for the baseline with two consecutive heights and use |
|
720 |
* the return value to determine if you need to pad calculations |
|
721 |
* by 1. The following shows how to calculate the baseline for |
|
722 |
* any height: |
|
723 |
* <pre> |
|
724 |
* Dimension preferredSize = component.getPreferredSize(); |
|
725 |
* int baseline = getBaseline(preferredSize.width, |
|
726 |
* preferredSize.height); |
|
727 |
* int nextBaseline = getBaseline(preferredSize.width, |
|
728 |
* preferredSize.height + 1); |
|
729 |
* // Amount to add to height when calculating where baseline |
|
730 |
* // lands for a particular height: |
|
731 |
* int padding = 0; |
|
732 |
* // Where the baseline is relative to the mid point |
|
733 |
* int baselineOffset = baseline - height / 2; |
|
734 |
* if (preferredSize.height % 2 == 0 && |
|
735 |
* baseline != nextBaseline) { |
|
736 |
* padding = 1; |
|
737 |
* } |
|
738 |
* else if (preferredSize.height % 2 == 1 && |
|
739 |
* baseline == nextBaseline) { |
|
740 |
* baselineOffset--; |
|
741 |
* padding = 1; |
|
742 |
* } |
|
743 |
* // The following calculates where the baseline lands for |
|
744 |
* // the height z: |
|
745 |
* int calculatedBaseline = (z + padding) / 2 + baselineOffset; |
|
746 |
* </pre> |
|
747 |
*/ |
|
748 |
CENTER_OFFSET, |
|
749 |
||
750 |
/** |
|
751 |
* Indicates the baseline resize behavior can not be expressed using |
|
752 |
* any of the other constants. This may also indicate the baseline |
|
753 |
* varies with the width of the component. This is also returned |
|
754 |
* by components that do not have a baseline. |
|
755 |
*/ |
|
756 |
OTHER |
|
757 |
} |
|
758 |
||
759 |
/* |
|
760 |
* The shape set with the applyCompoundShape() method. It uncludes the result |
|
761 |
* of the HW/LW mixing related shape computation. It may also include |
|
762 |
* the user-specified shape of the component. |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
763 |
* The 'null' value means the component has normal shape (or has no shape at all) |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
764 |
* and applyCompoundShape() will skip the following shape identical to normal. |
2 | 765 |
*/ |
766 |
private transient Region compoundShape = null; |
|
767 |
||
768 |
/* |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
769 |
* Represents the shape of this lightweight component to be cut out from |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
770 |
* heavyweight components should they intersect. Possible values: |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
771 |
* 1. null - consider the shape rectangular |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
772 |
* 2. EMPTY_REGION - nothing gets cut out (children still get cut out) |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
773 |
* 3. non-empty - this shape gets cut out. |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
774 |
*/ |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
775 |
private transient Region mixingCutoutRegion = null; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
776 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
777 |
/* |
2 | 778 |
* Indicates whether addNotify() is complete |
779 |
* (i.e. the peer is created). |
|
780 |
*/ |
|
781 |
private transient boolean isAddNotifyComplete = false; |
|
782 |
||
783 |
/** |
|
784 |
* Should only be used in subclass getBounds to check that part of bounds |
|
785 |
* is actualy changing |
|
786 |
*/ |
|
787 |
int getBoundsOp() { |
|
788 |
assert Thread.holdsLock(getTreeLock()); |
|
789 |
return boundsOp; |
|
790 |
} |
|
791 |
||
792 |
void setBoundsOp(int op) { |
|
793 |
assert Thread.holdsLock(getTreeLock()); |
|
794 |
if (op == ComponentPeer.RESET_OPERATION) { |
|
795 |
boundsOp = ComponentPeer.DEFAULT_OPERATION; |
|
796 |
} else |
|
797 |
if (boundsOp == ComponentPeer.DEFAULT_OPERATION) { |
|
798 |
boundsOp = op; |
|
799 |
} |
|
800 |
} |
|
801 |
||
2451 | 802 |
// Whether this Component has had the background erase flag |
803 |
// specified via SunToolkit.disableBackgroundErase(). This is |
|
804 |
// needed in order to make this function work on X11 platforms, |
|
805 |
// where currently there is no chance to interpose on the creation |
|
806 |
// of the peer and therefore the call to XSetBackground. |
|
807 |
transient boolean backgroundEraseDisabled; |
|
808 |
||
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
809 |
static { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
810 |
AWTAccessor.setComponentAccessor(new AWTAccessor.ComponentAccessor() { |
2451 | 811 |
public void setBackgroundEraseDisabled(Component comp, boolean disabled) { |
812 |
comp.backgroundEraseDisabled = disabled; |
|
813 |
} |
|
814 |
public boolean getBackgroundEraseDisabled(Component comp) { |
|
815 |
return comp.backgroundEraseDisabled; |
|
816 |
} |
|
817 |
public Rectangle getBounds(Component comp) { |
|
818 |
return new Rectangle(comp.x, comp.y, comp.width, comp.height); |
|
819 |
} |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
820 |
public void setMixingCutoutShape(Component comp, Shape shape) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
821 |
Region region = shape == null ? null : |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
822 |
Region.getInstance(shape, null); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
823 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
824 |
synchronized (comp.getTreeLock()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
825 |
boolean needShowing = false; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
826 |
boolean needHiding = false; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
827 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
828 |
if (!comp.isNonOpaqueForMixing()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
829 |
needHiding = true; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
830 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
831 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
832 |
comp.mixingCutoutRegion = region; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
833 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
834 |
if (!comp.isNonOpaqueForMixing()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
835 |
needShowing = true; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
836 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
837 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
838 |
if (comp.isMixingNeeded()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
839 |
if (needHiding) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
840 |
comp.mixOnHiding(comp.isLightweight()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
841 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
842 |
if (needShowing) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
843 |
comp.mixOnShowing(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
844 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
845 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
846 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
847 |
} |
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
848 |
|
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
849 |
public void setGraphicsConfiguration(Component comp, |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
850 |
GraphicsConfiguration gc) |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
851 |
{ |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
852 |
comp.setGraphicsConfiguration(gc); |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
853 |
} |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
854 |
public boolean requestFocus(Component comp, CausedFocusEvent.Cause cause) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
855 |
return comp.requestFocus(cause); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
856 |
} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
857 |
public boolean canBeFocusOwner(Component comp) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
858 |
return comp.canBeFocusOwner(); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
859 |
} |
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
2464
diff
changeset
|
860 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
2464
diff
changeset
|
861 |
public boolean isVisible_NoClientCode(Component comp) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
2464
diff
changeset
|
862 |
return comp.isVisible_NoClientCode(); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
2464
diff
changeset
|
863 |
} |
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
864 |
public void setRequestFocusController |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
865 |
(RequestFocusController requestController) |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
866 |
{ |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
867 |
Component.setRequestFocusController(requestController); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
868 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
869 |
public AppContext getAppContext(Component comp) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
870 |
return comp.appContext; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
871 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
872 |
public void setAppContext(Component comp, AppContext appContext) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
873 |
comp.appContext = appContext; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2805
diff
changeset
|
874 |
} |
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
875 |
}); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
876 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
877 |
|
2 | 878 |
/** |
879 |
* Constructs a new component. Class <code>Component</code> can be |
|
880 |
* extended directly to create a lightweight component that does not |
|
881 |
* utilize an opaque native window. A lightweight component must be |
|
882 |
* hosted by a native container somewhere higher up in the component |
|
883 |
* tree (for example, by a <code>Frame</code> object). |
|
884 |
*/ |
|
885 |
protected Component() { |
|
886 |
appContext = AppContext.getAppContext(); |
|
887 |
} |
|
888 |
||
889 |
void initializeFocusTraversalKeys() { |
|
890 |
focusTraversalKeys = new Set[3]; |
|
891 |
} |
|
892 |
||
893 |
/** |
|
894 |
* Constructs a name for this component. Called by <code>getName</code> |
|
895 |
* when the name is <code>null</code>. |
|
896 |
*/ |
|
897 |
String constructComponentName() { |
|
898 |
return null; // For strict compliance with prior platform versions, a Component |
|
899 |
// that doesn't set its name should return null from |
|
900 |
// getName() |
|
901 |
} |
|
902 |
||
903 |
/** |
|
904 |
* Gets the name of the component. |
|
905 |
* @return this component's name |
|
906 |
* @see #setName |
|
907 |
* @since JDK1.1 |
|
908 |
*/ |
|
909 |
public String getName() { |
|
910 |
if (name == null && !nameExplicitlySet) { |
|
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
911 |
synchronized(getObjectLock()) { |
2 | 912 |
if (name == null && !nameExplicitlySet) |
913 |
name = constructComponentName(); |
|
914 |
} |
|
915 |
} |
|
916 |
return name; |
|
917 |
} |
|
918 |
||
919 |
/** |
|
920 |
* Sets the name of the component to the specified string. |
|
921 |
* @param name the string that is to be this |
|
922 |
* component's name |
|
923 |
* @see #getName |
|
924 |
* @since JDK1.1 |
|
925 |
*/ |
|
926 |
public void setName(String name) { |
|
927 |
String oldName; |
|
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
928 |
synchronized(getObjectLock()) { |
2 | 929 |
oldName = this.name; |
930 |
this.name = name; |
|
931 |
nameExplicitlySet = true; |
|
932 |
} |
|
933 |
firePropertyChange("name", oldName, name); |
|
934 |
} |
|
935 |
||
936 |
/** |
|
937 |
* Gets the parent of this component. |
|
938 |
* @return the parent container of this component |
|
939 |
* @since JDK1.0 |
|
940 |
*/ |
|
941 |
public Container getParent() { |
|
942 |
return getParent_NoClientCode(); |
|
943 |
} |
|
944 |
||
945 |
// NOTE: This method may be called by privileged threads. |
|
946 |
// This functionality is implemented in a package-private method |
|
947 |
// to insure that it cannot be overridden by client subclasses. |
|
948 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
949 |
final Container getParent_NoClientCode() { |
|
950 |
return parent; |
|
951 |
} |
|
952 |
||
953 |
// This method is overriden in the Window class to return null, |
|
954 |
// because the parent field of the Window object contains |
|
955 |
// the owner of the window, not its parent. |
|
956 |
Container getContainer() { |
|
957 |
return getParent(); |
|
958 |
} |
|
959 |
||
960 |
/** |
|
961 |
* @deprecated As of JDK version 1.1, |
|
962 |
* programs should not directly manipulate peers; |
|
963 |
* replaced by <code>boolean isDisplayable()</code>. |
|
964 |
*/ |
|
965 |
@Deprecated |
|
966 |
public ComponentPeer getPeer() { |
|
967 |
return peer; |
|
968 |
} |
|
969 |
||
970 |
/** |
|
971 |
* Associate a <code>DropTarget</code> with this component. |
|
972 |
* The <code>Component</code> will receive drops only if it |
|
973 |
* is enabled. |
|
974 |
* |
|
975 |
* @see #isEnabled |
|
976 |
* @param dt The DropTarget |
|
977 |
*/ |
|
978 |
||
979 |
public synchronized void setDropTarget(DropTarget dt) { |
|
980 |
if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt))) |
|
981 |
return; |
|
982 |
||
983 |
DropTarget old; |
|
984 |
||
985 |
if ((old = dropTarget) != null) { |
|
986 |
if (peer != null) dropTarget.removeNotify(peer); |
|
987 |
||
988 |
DropTarget t = dropTarget; |
|
989 |
||
990 |
dropTarget = null; |
|
991 |
||
992 |
try { |
|
993 |
t.setComponent(null); |
|
994 |
} catch (IllegalArgumentException iae) { |
|
995 |
// ignore it. |
|
996 |
} |
|
997 |
} |
|
998 |
||
999 |
// if we have a new one, and we have a peer, add it! |
|
1000 |
||
1001 |
if ((dropTarget = dt) != null) { |
|
1002 |
try { |
|
1003 |
dropTarget.setComponent(this); |
|
1004 |
if (peer != null) dropTarget.addNotify(peer); |
|
1005 |
} catch (IllegalArgumentException iae) { |
|
1006 |
if (old != null) { |
|
1007 |
try { |
|
1008 |
old.setComponent(this); |
|
1009 |
if (peer != null) dropTarget.addNotify(peer); |
|
1010 |
} catch (IllegalArgumentException iae1) { |
|
1011 |
// ignore it! |
|
1012 |
} |
|
1013 |
} |
|
1014 |
} |
|
1015 |
} |
|
1016 |
} |
|
1017 |
||
1018 |
/** |
|
1019 |
* Gets the <code>DropTarget</code> associated with this |
|
1020 |
* <code>Component</code>. |
|
1021 |
*/ |
|
1022 |
||
1023 |
public synchronized DropTarget getDropTarget() { return dropTarget; } |
|
1024 |
||
1025 |
/** |
|
1026 |
* Gets the <code>GraphicsConfiguration</code> associated with this |
|
1027 |
* <code>Component</code>. |
|
1028 |
* If the <code>Component</code> has not been assigned a specific |
|
1029 |
* <code>GraphicsConfiguration</code>, |
|
1030 |
* the <code>GraphicsConfiguration</code> of the |
|
1031 |
* <code>Component</code> object's top-level container is |
|
1032 |
* returned. |
|
1033 |
* If the <code>Component</code> has been created, but not yet added |
|
1034 |
* to a <code>Container</code>, this method returns <code>null</code>. |
|
1035 |
* |
|
1036 |
* @return the <code>GraphicsConfiguration</code> used by this |
|
1037 |
* <code>Component</code> or <code>null</code> |
|
1038 |
* @since 1.3 |
|
1039 |
*/ |
|
1040 |
public GraphicsConfiguration getGraphicsConfiguration() { |
|
1041 |
synchronized(getTreeLock()) { |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1042 |
return getGraphicsConfiguration_NoClientCode(); |
2 | 1043 |
} |
1044 |
} |
|
1045 |
||
1046 |
final GraphicsConfiguration getGraphicsConfiguration_NoClientCode() { |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1047 |
return graphicsConfig; |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1048 |
} |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1049 |
|
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
1050 |
void setGraphicsConfiguration(GraphicsConfiguration gc) { |
2 | 1051 |
synchronized(getTreeLock()) { |
2805
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1052 |
if (updateGraphicsData(gc)) { |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1053 |
removeNotify(); |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1054 |
addNotify(); |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1055 |
} |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1056 |
} |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1057 |
} |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1058 |
|
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1059 |
boolean updateGraphicsData(GraphicsConfiguration gc) { |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1060 |
checkTreeLock(); |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1061 |
|
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1062 |
graphicsConfig = gc; |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1063 |
|
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1064 |
ComponentPeer peer = getPeer(); |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1065 |
if (peer != null) { |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1066 |
return peer.updateGraphicsData(gc); |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1067 |
} |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2647
diff
changeset
|
1068 |
return false; |
2 | 1069 |
} |
1070 |
||
1071 |
/** |
|
1072 |
* Checks that this component's <code>GraphicsDevice</code> |
|
1073 |
* <code>idString</code> matches the string argument. |
|
1074 |
*/ |
|
1075 |
void checkGD(String stringID) { |
|
1076 |
if (graphicsConfig != null) { |
|
1077 |
if (!graphicsConfig.getDevice().getIDstring().equals(stringID)) { |
|
1078 |
throw new IllegalArgumentException( |
|
1079 |
"adding a container to a container on a different GraphicsDevice"); |
|
1080 |
} |
|
1081 |
} |
|
1082 |
} |
|
1083 |
||
1084 |
/** |
|
1085 |
* Gets this component's locking object (the object that owns the thread |
|
435
30ae000d9354
6615015: Typo in javadoc for Component.getTreeLock()
dcherepanov
parents:
432
diff
changeset
|
1086 |
* synchronization monitor) for AWT component-tree and layout |
2 | 1087 |
* operations. |
1088 |
* @return this component's locking object |
|
1089 |
*/ |
|
1090 |
public final Object getTreeLock() { |
|
1091 |
return LOCK; |
|
1092 |
} |
|
1093 |
||
1094 |
final void checkTreeLock() { |
|
1095 |
if (!Thread.holdsLock(getTreeLock())) { |
|
1096 |
throw new IllegalStateException("This function should be called while holding treeLock"); |
|
1097 |
} |
|
1098 |
} |
|
1099 |
||
1100 |
/** |
|
1101 |
* Gets the toolkit of this component. Note that |
|
1102 |
* the frame that contains a component controls which |
|
1103 |
* toolkit is used by that component. Therefore if the component |
|
1104 |
* is moved from one frame to another, the toolkit it uses may change. |
|
1105 |
* @return the toolkit of this component |
|
1106 |
* @since JDK1.0 |
|
1107 |
*/ |
|
1108 |
public Toolkit getToolkit() { |
|
1109 |
return getToolkitImpl(); |
|
1110 |
} |
|
1111 |
||
1112 |
/* |
|
1113 |
* This is called by the native code, so client code can't |
|
1114 |
* be called on the toolkit thread. |
|
1115 |
*/ |
|
1116 |
final Toolkit getToolkitImpl() { |
|
1117 |
ComponentPeer peer = this.peer; |
|
1118 |
if ((peer != null) && ! (peer instanceof LightweightPeer)){ |
|
1119 |
return peer.getToolkit(); |
|
1120 |
} |
|
1121 |
Container parent = this.parent; |
|
1122 |
if (parent != null) { |
|
1123 |
return parent.getToolkitImpl(); |
|
1124 |
} |
|
1125 |
return Toolkit.getDefaultToolkit(); |
|
1126 |
} |
|
1127 |
||
1128 |
/** |
|
1129 |
* Determines whether this component is valid. A component is valid |
|
1130 |
* when it is correctly sized and positioned within its parent |
|
1131 |
* container and all its children are also valid. |
|
1132 |
* In order to account for peers' size requirements, components are invalidated |
|
1133 |
* before they are first shown on the screen. By the time the parent container |
|
1134 |
* is fully realized, all its components will be valid. |
|
1135 |
* @return <code>true</code> if the component is valid, <code>false</code> |
|
1136 |
* otherwise |
|
1137 |
* @see #validate |
|
1138 |
* @see #invalidate |
|
1139 |
* @since JDK1.0 |
|
1140 |
*/ |
|
1141 |
public boolean isValid() { |
|
1142 |
return (peer != null) && valid; |
|
1143 |
} |
|
1144 |
||
1145 |
/** |
|
1146 |
* Determines whether this component is displayable. A component is |
|
1147 |
* displayable when it is connected to a native screen resource. |
|
1148 |
* <p> |
|
1149 |
* A component is made displayable either when it is added to |
|
1150 |
* a displayable containment hierarchy or when its containment |
|
1151 |
* hierarchy is made displayable. |
|
1152 |
* A containment hierarchy is made displayable when its ancestor |
|
1153 |
* window is either packed or made visible. |
|
1154 |
* <p> |
|
1155 |
* A component is made undisplayable either when it is removed from |
|
1156 |
* a displayable containment hierarchy or when its containment hierarchy |
|
1157 |
* is made undisplayable. A containment hierarchy is made |
|
1158 |
* undisplayable when its ancestor window is disposed. |
|
1159 |
* |
|
1160 |
* @return <code>true</code> if the component is displayable, |
|
1161 |
* <code>false</code> otherwise |
|
1162 |
* @see Container#add(Component) |
|
1163 |
* @see Window#pack |
|
1164 |
* @see Window#show |
|
1165 |
* @see Container#remove(Component) |
|
1166 |
* @see Window#dispose |
|
1167 |
* @since 1.2 |
|
1168 |
*/ |
|
1169 |
public boolean isDisplayable() { |
|
1170 |
return getPeer() != null; |
|
1171 |
} |
|
1172 |
||
1173 |
/** |
|
1174 |
* Determines whether this component should be visible when its |
|
1175 |
* parent is visible. Components are |
|
1176 |
* initially visible, with the exception of top level components such |
|
1177 |
* as <code>Frame</code> objects. |
|
1178 |
* @return <code>true</code> if the component is visible, |
|
1179 |
* <code>false</code> otherwise |
|
1180 |
* @see #setVisible |
|
1181 |
* @since JDK1.0 |
|
1182 |
*/ |
|
466
6acd5ec503a8
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents:
130
diff
changeset
|
1183 |
@Transient |
2 | 1184 |
public boolean isVisible() { |
1185 |
return isVisible_NoClientCode(); |
|
1186 |
} |
|
1187 |
final boolean isVisible_NoClientCode() { |
|
1188 |
return visible; |
|
1189 |
} |
|
1190 |
||
1191 |
/** |
|
1192 |
* Determines whether this component will be displayed on the screen. |
|
1193 |
* @return <code>true</code> if the component and all of its ancestors |
|
1194 |
* until a toplevel window or null parent are visible, |
|
1195 |
* <code>false</code> otherwise |
|
1196 |
*/ |
|
1197 |
boolean isRecursivelyVisible() { |
|
1198 |
return visible && (parent == null || parent.isRecursivelyVisible()); |
|
1199 |
} |
|
1200 |
||
1201 |
/** |
|
1202 |
* Translates absolute coordinates into coordinates in the coordinate |
|
1203 |
* space of this component. |
|
1204 |
*/ |
|
1205 |
Point pointRelativeToComponent(Point absolute) { |
|
1206 |
Point compCoords = getLocationOnScreen(); |
|
1207 |
return new Point(absolute.x - compCoords.x, |
|
1208 |
absolute.y - compCoords.y); |
|
1209 |
} |
|
1210 |
||
1211 |
/** |
|
1212 |
* Assuming that mouse location is stored in PointerInfo passed |
|
1213 |
* to this method, it finds a Component that is in the same |
|
1214 |
* Window as this Component and is located under the mouse pointer. |
|
1215 |
* If no such Component exists, null is returned. |
|
1216 |
* NOTE: this method should be called under the protection of |
|
1217 |
* tree lock, as it is done in Component.getMousePosition() and |
|
1218 |
* Container.getMousePosition(boolean). |
|
1219 |
*/ |
|
1220 |
Component findUnderMouseInWindow(PointerInfo pi) { |
|
1221 |
if (!isShowing()) { |
|
1222 |
return null; |
|
1223 |
} |
|
1224 |
Window win = getContainingWindow(); |
|
1225 |
if (!Toolkit.getDefaultToolkit().getMouseInfoPeer().isWindowUnderMouse(win)) { |
|
1226 |
return null; |
|
1227 |
} |
|
1228 |
final boolean INCLUDE_DISABLED = true; |
|
1229 |
Point relativeToWindow = win.pointRelativeToComponent(pi.getLocation()); |
|
1230 |
Component inTheSameWindow = win.findComponentAt(relativeToWindow.x, |
|
1231 |
relativeToWindow.y, |
|
1232 |
INCLUDE_DISABLED); |
|
1233 |
return inTheSameWindow; |
|
1234 |
} |
|
1235 |
||
1236 |
/** |
|
1237 |
* Returns the position of the mouse pointer in this <code>Component</code>'s |
|
1238 |
* coordinate space if the <code>Component</code> is directly under the mouse |
|
1239 |
* pointer, otherwise returns <code>null</code>. |
|
1240 |
* If the <code>Component</code> is not showing on the screen, this method |
|
1241 |
* returns <code>null</code> even if the mouse pointer is above the area |
|
1242 |
* where the <code>Component</code> would be displayed. |
|
1243 |
* If the <code>Component</code> is partially or fully obscured by other |
|
1244 |
* <code>Component</code>s or native windows, this method returns a non-null |
|
1245 |
* value only if the mouse pointer is located above the unobscured part of the |
|
1246 |
* <code>Component</code>. |
|
1247 |
* <p> |
|
1248 |
* For <code>Container</code>s it returns a non-null value if the mouse is |
|
1249 |
* above the <code>Container</code> itself or above any of its descendants. |
|
1250 |
* Use {@link Container#getMousePosition(boolean)} if you need to exclude children. |
|
1251 |
* <p> |
|
1252 |
* Sometimes the exact mouse coordinates are not important, and the only thing |
|
1253 |
* that matters is whether a specific <code>Component</code> is under the mouse |
|
1254 |
* pointer. If the return value of this method is <code>null</code>, mouse |
|
1255 |
* pointer is not directly above the <code>Component</code>. |
|
1256 |
* |
|
1257 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true |
|
1258 |
* @see #isShowing |
|
1259 |
* @see Container#getMousePosition |
|
1260 |
* @return mouse coordinates relative to this <code>Component</code>, or null |
|
1261 |
* @since 1.5 |
|
1262 |
*/ |
|
1263 |
public Point getMousePosition() throws HeadlessException { |
|
1264 |
if (GraphicsEnvironment.isHeadless()) { |
|
1265 |
throw new HeadlessException(); |
|
1266 |
} |
|
1267 |
||
1268 |
PointerInfo pi = (PointerInfo)java.security.AccessController.doPrivileged( |
|
1269 |
new java.security.PrivilegedAction() { |
|
1270 |
public Object run() { |
|
1271 |
return MouseInfo.getPointerInfo(); |
|
1272 |
} |
|
1273 |
} |
|
1274 |
); |
|
1275 |
||
1276 |
synchronized (getTreeLock()) { |
|
1277 |
Component inTheSameWindow = findUnderMouseInWindow(pi); |
|
1278 |
if (!isSameOrAncestorOf(inTheSameWindow, true)) { |
|
1279 |
return null; |
|
1280 |
} |
|
1281 |
return pointRelativeToComponent(pi.getLocation()); |
|
1282 |
} |
|
1283 |
} |
|
1284 |
||
1285 |
/** |
|
1286 |
* Overridden in Container. Must be called under TreeLock. |
|
1287 |
*/ |
|
1288 |
boolean isSameOrAncestorOf(Component comp, boolean allowChildren) { |
|
1289 |
return comp == this; |
|
1290 |
} |
|
1291 |
||
1292 |
/** |
|
1293 |
* Determines whether this component is showing on screen. This means |
|
1294 |
* that the component must be visible, and it must be in a container |
|
1295 |
* that is visible and showing. |
|
1296 |
* <p> |
|
1297 |
* <strong>Note:</strong> sometimes there is no way to detect whether the |
|
1298 |
* {@code Component} is actually visible to the user. This can happen when: |
|
1299 |
* <ul> |
|
1300 |
* <li>the component has been added to a visible {@code ScrollPane} but |
|
1301 |
* the {@code Component} is not currently in the scroll pane's view port. |
|
1302 |
* <li>the {@code Component} is obscured by another {@code Component} or |
|
1303 |
* {@code Container}. |
|
1304 |
* </ul> |
|
1305 |
* @return <code>true</code> if the component is showing, |
|
1306 |
* <code>false</code> otherwise |
|
1307 |
* @see #setVisible |
|
1308 |
* @since JDK1.0 |
|
1309 |
*/ |
|
1310 |
public boolean isShowing() { |
|
1311 |
if (visible && (peer != null)) { |
|
1312 |
Container parent = this.parent; |
|
1313 |
return (parent == null) || parent.isShowing(); |
|
1314 |
} |
|
1315 |
return false; |
|
1316 |
} |
|
1317 |
||
1318 |
/** |
|
1319 |
* Determines whether this component is enabled. An enabled component |
|
1320 |
* can respond to user input and generate events. Components are |
|
1321 |
* enabled initially by default. A component may be enabled or disabled by |
|
1322 |
* calling its <code>setEnabled</code> method. |
|
1323 |
* @return <code>true</code> if the component is enabled, |
|
1324 |
* <code>false</code> otherwise |
|
1325 |
* @see #setEnabled |
|
1326 |
* @since JDK1.0 |
|
1327 |
*/ |
|
1328 |
public boolean isEnabled() { |
|
1329 |
return isEnabledImpl(); |
|
1330 |
} |
|
1331 |
||
1332 |
/* |
|
1333 |
* This is called by the native code, so client code can't |
|
1334 |
* be called on the toolkit thread. |
|
1335 |
*/ |
|
1336 |
final boolean isEnabledImpl() { |
|
1337 |
return enabled; |
|
1338 |
} |
|
1339 |
||
1340 |
/** |
|
1341 |
* Enables or disables this component, depending on the value of the |
|
1342 |
* parameter <code>b</code>. An enabled component can respond to user |
|
1343 |
* input and generate events. Components are enabled initially by default. |
|
1344 |
* |
|
1345 |
* <p>Note: Disabling a lightweight component does not prevent it from |
|
1346 |
* receiving MouseEvents. |
|
1347 |
* <p>Note: Disabling a heavyweight container prevents all components |
|
1348 |
* in this container from receiving any input events. But disabling a |
|
1349 |
* lightweight container affects only this container. |
|
1350 |
* |
|
1351 |
* @param b If <code>true</code>, this component is |
|
1352 |
* enabled; otherwise this component is disabled |
|
1353 |
* @see #isEnabled |
|
1354 |
* @see #isLightweight |
|
1355 |
* @since JDK1.1 |
|
1356 |
*/ |
|
1357 |
public void setEnabled(boolean b) { |
|
1358 |
enable(b); |
|
1359 |
} |
|
1360 |
||
1361 |
/** |
|
1362 |
* @deprecated As of JDK version 1.1, |
|
1363 |
* replaced by <code>setEnabled(boolean)</code>. |
|
1364 |
*/ |
|
1365 |
@Deprecated |
|
1366 |
public void enable() { |
|
1367 |
if (!enabled) { |
|
1368 |
synchronized (getTreeLock()) { |
|
1369 |
enabled = true; |
|
1370 |
ComponentPeer peer = this.peer; |
|
1371 |
if (peer != null) { |
|
1964 | 1372 |
peer.setEnabled(true); |
2 | 1373 |
if (visible) { |
1374 |
updateCursorImmediately(); |
|
1375 |
} |
|
1376 |
} |
|
1377 |
} |
|
1378 |
if (accessibleContext != null) { |
|
1379 |
accessibleContext.firePropertyChange( |
|
1380 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
1381 |
null, AccessibleState.ENABLED); |
|
1382 |
} |
|
1383 |
} |
|
1384 |
} |
|
1385 |
||
1386 |
/** |
|
1387 |
* @deprecated As of JDK version 1.1, |
|
1388 |
* replaced by <code>setEnabled(boolean)</code>. |
|
1389 |
*/ |
|
1390 |
@Deprecated |
|
1391 |
public void enable(boolean b) { |
|
1392 |
if (b) { |
|
1393 |
enable(); |
|
1394 |
} else { |
|
1395 |
disable(); |
|
1396 |
} |
|
1397 |
} |
|
1398 |
||
1399 |
/** |
|
1400 |
* @deprecated As of JDK version 1.1, |
|
1401 |
* replaced by <code>setEnabled(boolean)</code>. |
|
1402 |
*/ |
|
1403 |
@Deprecated |
|
1404 |
public void disable() { |
|
1405 |
if (enabled) { |
|
1406 |
KeyboardFocusManager.clearMostRecentFocusOwner(this); |
|
1407 |
synchronized (getTreeLock()) { |
|
1408 |
enabled = false; |
|
441 | 1409 |
// A disabled lw container is allowed to contain a focus owner. |
1410 |
if ((isFocusOwner() || (containsFocus() && !isLightweight())) && |
|
1411 |
KeyboardFocusManager.isAutoFocusTransferEnabled()) |
|
1412 |
{ |
|
2 | 1413 |
// Don't clear the global focus owner. If transferFocus |
1414 |
// fails, we want the focus to stay on the disabled |
|
1415 |
// Component so that keyboard traversal, et. al. still |
|
1416 |
// makes sense to the user. |
|
441 | 1417 |
transferFocus(false); |
2 | 1418 |
} |
1419 |
ComponentPeer peer = this.peer; |
|
1420 |
if (peer != null) { |
|
1964 | 1421 |
peer.setEnabled(false); |
2 | 1422 |
if (visible) { |
1423 |
updateCursorImmediately(); |
|
1424 |
} |
|
1425 |
} |
|
1426 |
} |
|
1427 |
if (accessibleContext != null) { |
|
1428 |
accessibleContext.firePropertyChange( |
|
1429 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
1430 |
null, AccessibleState.ENABLED); |
|
1431 |
} |
|
1432 |
} |
|
1433 |
} |
|
1434 |
||
1435 |
/** |
|
1436 |
* Returns true if this component is painted to an offscreen image |
|
1437 |
* ("buffer") that's copied to the screen later. Component |
|
1438 |
* subclasses that support double buffering should override this |
|
1439 |
* method to return true if double buffering is enabled. |
|
1440 |
* |
|
1441 |
* @return false by default |
|
1442 |
*/ |
|
1443 |
public boolean isDoubleBuffered() { |
|
1444 |
return false; |
|
1445 |
} |
|
1446 |
||
1447 |
/** |
|
1448 |
* Enables or disables input method support for this component. If input |
|
1449 |
* method support is enabled and the component also processes key events, |
|
1450 |
* incoming events are offered to |
|
1451 |
* the current input method and will only be processed by the component or |
|
1452 |
* dispatched to its listeners if the input method does not consume them. |
|
1453 |
* By default, input method support is enabled. |
|
1454 |
* |
|
1455 |
* @param enable true to enable, false to disable |
|
1456 |
* @see #processKeyEvent |
|
1457 |
* @since 1.2 |
|
1458 |
*/ |
|
1459 |
public void enableInputMethods(boolean enable) { |
|
1460 |
if (enable) { |
|
1461 |
if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) |
|
1462 |
return; |
|
1463 |
||
1464 |
// If this component already has focus, then activate the |
|
1465 |
// input method by dispatching a synthesized focus gained |
|
1466 |
// event. |
|
1467 |
if (isFocusOwner()) { |
|
1468 |
InputContext inputContext = getInputContext(); |
|
1469 |
if (inputContext != null) { |
|
1470 |
FocusEvent focusGainedEvent = |
|
1471 |
new FocusEvent(this, FocusEvent.FOCUS_GAINED); |
|
1472 |
inputContext.dispatchEvent(focusGainedEvent); |
|
1473 |
} |
|
1474 |
} |
|
1475 |
||
1476 |
eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK; |
|
1477 |
} else { |
|
1478 |
if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) { |
|
1479 |
InputContext inputContext = getInputContext(); |
|
1480 |
if (inputContext != null) { |
|
1481 |
inputContext.endComposition(); |
|
1482 |
inputContext.removeNotify(this); |
|
1483 |
} |
|
1484 |
} |
|
1485 |
eventMask &= ~AWTEvent.INPUT_METHODS_ENABLED_MASK; |
|
1486 |
} |
|
1487 |
} |
|
1488 |
||
1489 |
/** |
|
1490 |
* Shows or hides this component depending on the value of parameter |
|
1491 |
* <code>b</code>. |
|
1492 |
* @param b if <code>true</code>, shows this component; |
|
1493 |
* otherwise, hides this component |
|
1494 |
* @see #isVisible |
|
1495 |
* @since JDK1.1 |
|
1496 |
*/ |
|
1497 |
public void setVisible(boolean b) { |
|
1498 |
show(b); |
|
1499 |
} |
|
1500 |
||
1501 |
/** |
|
1502 |
* @deprecated As of JDK version 1.1, |
|
1503 |
* replaced by <code>setVisible(boolean)</code>. |
|
1504 |
*/ |
|
1505 |
@Deprecated |
|
1506 |
public void show() { |
|
1507 |
if (!visible) { |
|
1508 |
synchronized (getTreeLock()) { |
|
1509 |
visible = true; |
|
1510 |
mixOnShowing(); |
|
1511 |
ComponentPeer peer = this.peer; |
|
1512 |
if (peer != null) { |
|
1964 | 1513 |
peer.setVisible(true); |
2 | 1514 |
createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, |
1515 |
this, parent, |
|
1516 |
HierarchyEvent.SHOWING_CHANGED, |
|
1517 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
1518 |
if (peer instanceof LightweightPeer) { |
|
1519 |
repaint(); |
|
1520 |
} |
|
1521 |
updateCursorImmediately(); |
|
1522 |
} |
|
1523 |
||
1524 |
if (componentListener != null || |
|
1525 |
(eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 || |
|
1526 |
Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) { |
|
1527 |
ComponentEvent e = new ComponentEvent(this, |
|
1528 |
ComponentEvent.COMPONENT_SHOWN); |
|
1529 |
Toolkit.getEventQueue().postEvent(e); |
|
1530 |
} |
|
1531 |
} |
|
1532 |
Container parent = this.parent; |
|
1533 |
if (parent != null) { |
|
1534 |
parent.invalidate(); |
|
1535 |
} |
|
1536 |
} |
|
1537 |
} |
|
1538 |
||
1539 |
/** |
|
1540 |
* @deprecated As of JDK version 1.1, |
|
1541 |
* replaced by <code>setVisible(boolean)</code>. |
|
1542 |
*/ |
|
1543 |
@Deprecated |
|
1544 |
public void show(boolean b) { |
|
1545 |
if (b) { |
|
1546 |
show(); |
|
1547 |
} else { |
|
1548 |
hide(); |
|
1549 |
} |
|
1550 |
} |
|
1551 |
||
1552 |
boolean containsFocus() { |
|
1553 |
return isFocusOwner(); |
|
1554 |
} |
|
1555 |
||
1556 |
void clearMostRecentFocusOwnerOnHide() { |
|
1557 |
KeyboardFocusManager.clearMostRecentFocusOwner(this); |
|
1558 |
} |
|
1559 |
||
1560 |
void clearCurrentFocusCycleRootOnHide() { |
|
1561 |
/* do nothing */ |
|
1562 |
} |
|
1563 |
||
1564 |
/** |
|
1565 |
* @deprecated As of JDK version 1.1, |
|
1566 |
* replaced by <code>setVisible(boolean)</code>. |
|
1567 |
*/ |
|
1568 |
@Deprecated |
|
1569 |
public void hide() { |
|
1570 |
isPacked = false; |
|
1571 |
||
1572 |
if (visible) { |
|
1573 |
clearCurrentFocusCycleRootOnHide(); |
|
1574 |
clearMostRecentFocusOwnerOnHide(); |
|
1575 |
synchronized (getTreeLock()) { |
|
1576 |
visible = false; |
|
1577 |
mixOnHiding(isLightweight()); |
|
441 | 1578 |
if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabled()) { |
1579 |
transferFocus(true); |
|
2 | 1580 |
} |
1581 |
ComponentPeer peer = this.peer; |
|
1582 |
if (peer != null) { |
|
1964 | 1583 |
peer.setVisible(false); |
2 | 1584 |
createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, |
1585 |
this, parent, |
|
1586 |
HierarchyEvent.SHOWING_CHANGED, |
|
1587 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
1588 |
if (peer instanceof LightweightPeer) { |
|
1589 |
repaint(); |
|
1590 |
} |
|
1591 |
updateCursorImmediately(); |
|
1592 |
} |
|
1593 |
if (componentListener != null || |
|
1594 |
(eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 || |
|
1595 |
Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) { |
|
1596 |
ComponentEvent e = new ComponentEvent(this, |
|
1597 |
ComponentEvent.COMPONENT_HIDDEN); |
|
1598 |
Toolkit.getEventQueue().postEvent(e); |
|
1599 |
} |
|
1600 |
} |
|
1601 |
Container parent = this.parent; |
|
1602 |
if (parent != null) { |
|
1603 |
parent.invalidate(); |
|
1604 |
} |
|
1605 |
} |
|
1606 |
} |
|
1607 |
||
1608 |
/** |
|
1609 |
* Gets the foreground color of this component. |
|
1610 |
* @return this component's foreground color; if this component does |
|
1611 |
* not have a foreground color, the foreground color of its parent |
|
1612 |
* is returned |
|
1613 |
* @see #setForeground |
|
1614 |
* @since JDK1.0 |
|
1615 |
* @beaninfo |
|
1616 |
* bound: true |
|
1617 |
*/ |
|
466
6acd5ec503a8
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents:
130
diff
changeset
|
1618 |
@Transient |
2 | 1619 |
public Color getForeground() { |
1620 |
Color foreground = this.foreground; |
|
1621 |
if (foreground != null) { |
|
1622 |
return foreground; |
|
1623 |
} |
|
1624 |
Container parent = this.parent; |
|
1625 |
return (parent != null) ? parent.getForeground() : null; |
|
1626 |
} |
|
1627 |
||
1628 |
/** |
|
1629 |
* Sets the foreground color of this component. |
|
1630 |
* @param c the color to become this component's |
|
1631 |
* foreground color; if this parameter is <code>null</code> |
|
1632 |
* then this component will inherit |
|
1633 |
* the foreground color of its parent |
|
1634 |
* @see #getForeground |
|
1635 |
* @since JDK1.0 |
|
1636 |
*/ |
|
1637 |
public void setForeground(Color c) { |
|
1638 |
Color oldColor = foreground; |
|
1639 |
ComponentPeer peer = this.peer; |
|
1640 |
foreground = c; |
|
1641 |
if (peer != null) { |
|
1642 |
c = getForeground(); |
|
1643 |
if (c != null) { |
|
1644 |
peer.setForeground(c); |
|
1645 |
} |
|
1646 |
} |
|
1647 |
// This is a bound property, so report the change to |
|
1648 |
// any registered listeners. (Cheap if there are none.) |
|
1649 |
firePropertyChange("foreground", oldColor, c); |
|
1650 |
} |
|
1651 |
||
1652 |
/** |
|
1653 |
* Returns whether the foreground color has been explicitly set for this |
|
1654 |
* Component. If this method returns <code>false</code>, this Component is |
|
1655 |
* inheriting its foreground color from an ancestor. |
|
1656 |
* |
|
1657 |
* @return <code>true</code> if the foreground color has been explicitly |
|
1658 |
* set for this Component; <code>false</code> otherwise. |
|
1659 |
* @since 1.4 |
|
1660 |
*/ |
|
1661 |
public boolean isForegroundSet() { |
|
1662 |
return (foreground != null); |
|
1663 |
} |
|
1664 |
||
1665 |
/** |
|
1666 |
* Gets the background color of this component. |
|
1667 |
* @return this component's background color; if this component does |
|
1668 |
* not have a background color, |
|
1669 |
* the background color of its parent is returned |
|
1670 |
* @see #setBackground |
|
1671 |
* @since JDK1.0 |
|
1672 |
*/ |
|
466
6acd5ec503a8
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents:
130
diff
changeset
|
1673 |
@Transient |
2 | 1674 |
public Color getBackground() { |
1675 |
Color background = this.background; |
|
1676 |
if (background != null) { |
|
1677 |
return background; |
|
1678 |
} |
|
1679 |
Container parent = this.parent; |
|
1680 |
return (parent != null) ? parent.getBackground() : null; |
|
1681 |
} |
|
1682 |
||
1683 |
/** |
|
1684 |
* Sets the background color of this component. |
|
1685 |
* <p> |
|
1686 |
* The background color affects each component differently and the |
|
1687 |
* parts of the component that are affected by the background color |
|
1688 |
* may differ between operating systems. |
|
1689 |
* |
|
1690 |
* @param c the color to become this component's color; |
|
1691 |
* if this parameter is <code>null</code>, then this |
|
1692 |
* component will inherit the background color of its parent |
|
1693 |
* @see #getBackground |
|
1694 |
* @since JDK1.0 |
|
1695 |
* @beaninfo |
|
1696 |
* bound: true |
|
1697 |
*/ |
|
1698 |
public void setBackground(Color c) { |
|
1699 |
Color oldColor = background; |
|
1700 |
ComponentPeer peer = this.peer; |
|
1701 |
background = c; |
|
1702 |
if (peer != null) { |
|
1703 |
c = getBackground(); |
|
1704 |
if (c != null) { |
|
1705 |
peer.setBackground(c); |
|
1706 |
} |
|
1707 |
} |
|
1708 |
// This is a bound property, so report the change to |
|
1709 |
// any registered listeners. (Cheap if there are none.) |
|
1710 |
firePropertyChange("background", oldColor, c); |
|
1711 |
} |
|
1712 |
||
1713 |
/** |
|
1714 |
* Returns whether the background color has been explicitly set for this |
|
1715 |
* Component. If this method returns <code>false</code>, this Component is |
|
1716 |
* inheriting its background color from an ancestor. |
|
1717 |
* |
|
1718 |
* @return <code>true</code> if the background color has been explicitly |
|
1719 |
* set for this Component; <code>false</code> otherwise. |
|
1720 |
* @since 1.4 |
|
1721 |
*/ |
|
1722 |
public boolean isBackgroundSet() { |
|
1723 |
return (background != null); |
|
1724 |
} |
|
1725 |
||
1726 |
/** |
|
1727 |
* Gets the font of this component. |
|
1728 |
* @return this component's font; if a font has not been set |
|
1729 |
* for this component, the font of its parent is returned |
|
1730 |
* @see #setFont |
|
1731 |
* @since JDK1.0 |
|
1732 |
*/ |
|
466
6acd5ec503a8
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents:
130
diff
changeset
|
1733 |
@Transient |
2 | 1734 |
public Font getFont() { |
1735 |
return getFont_NoClientCode(); |
|
1736 |
} |
|
1737 |
||
1738 |
// NOTE: This method may be called by privileged threads. |
|
1739 |
// This functionality is implemented in a package-private method |
|
1740 |
// to insure that it cannot be overridden by client subclasses. |
|
1741 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
1742 |
final Font getFont_NoClientCode() { |
|
1743 |
Font font = this.font; |
|
1744 |
if (font != null) { |
|
1745 |
return font; |
|
1746 |
} |
|
1747 |
Container parent = this.parent; |
|
1748 |
return (parent != null) ? parent.getFont_NoClientCode() : null; |
|
1749 |
} |
|
1750 |
||
1751 |
/** |
|
1752 |
* Sets the font of this component. |
|
1753 |
* @param f the font to become this component's font; |
|
1754 |
* if this parameter is <code>null</code> then this |
|
1755 |
* component will inherit the font of its parent |
|
1756 |
* @see #getFont |
|
1757 |
* @since JDK1.0 |
|
1758 |
* @beaninfo |
|
1759 |
* bound: true |
|
1760 |
*/ |
|
1761 |
public void setFont(Font f) { |
|
1762 |
Font oldFont, newFont; |
|
1763 |
synchronized(getTreeLock()) { |
|
1764 |
synchronized (this) { |
|
1765 |
oldFont = font; |
|
1766 |
newFont = font = f; |
|
1767 |
} |
|
1768 |
ComponentPeer peer = this.peer; |
|
1769 |
if (peer != null) { |
|
1770 |
f = getFont(); |
|
1771 |
if (f != null) { |
|
1772 |
peer.setFont(f); |
|
1773 |
peerFont = f; |
|
1774 |
} |
|
1775 |
} |
|
1776 |
} |
|
1777 |
// This is a bound property, so report the change to |
|
1778 |
// any registered listeners. (Cheap if there are none.) |
|
1779 |
firePropertyChange("font", oldFont, newFont); |
|
1780 |
||
1781 |
// This could change the preferred size of the Component. |
|
1782 |
// Fix for 6213660. Should compare old and new fonts and do not |
|
1783 |
// call invalidate() if they are equal. |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
1784 |
if (f != oldFont && (oldFont == null || |
2 | 1785 |
!oldFont.equals(f))) { |
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
1786 |
invalidateIfValid(); |
2 | 1787 |
} |
1788 |
} |
|
1789 |
||
1790 |
/** |
|
1791 |
* Returns whether the font has been explicitly set for this Component. If |
|
1792 |
* this method returns <code>false</code>, this Component is inheriting its |
|
1793 |
* font from an ancestor. |
|
1794 |
* |
|
1795 |
* @return <code>true</code> if the font has been explicitly set for this |
|
1796 |
* Component; <code>false</code> otherwise. |
|
1797 |
* @since 1.4 |
|
1798 |
*/ |
|
1799 |
public boolean isFontSet() { |
|
1800 |
return (font != null); |
|
1801 |
} |
|
1802 |
||
1803 |
/** |
|
1804 |
* Gets the locale of this component. |
|
1805 |
* @return this component's locale; if this component does not |
|
1806 |
* have a locale, the locale of its parent is returned |
|
1807 |
* @see #setLocale |
|
1808 |
* @exception IllegalComponentStateException if the <code>Component</code> |
|
1809 |
* does not have its own locale and has not yet been added to |
|
1810 |
* a containment hierarchy such that the locale can be determined |
|
1811 |
* from the containing parent |
|
1812 |
* @since JDK1.1 |
|
1813 |
*/ |
|
1814 |
public Locale getLocale() { |
|
1815 |
Locale locale = this.locale; |
|
1816 |
if (locale != null) { |
|
1817 |
return locale; |
|
1818 |
} |
|
1819 |
Container parent = this.parent; |
|
1820 |
||
1821 |
if (parent == null) { |
|
1822 |
throw new IllegalComponentStateException("This component must have a parent in order to determine its locale"); |
|
1823 |
} else { |
|
1824 |
return parent.getLocale(); |
|
1825 |
} |
|
1826 |
} |
|
1827 |
||
1828 |
/** |
|
1829 |
* Sets the locale of this component. This is a bound property. |
|
1830 |
* @param l the locale to become this component's locale |
|
1831 |
* @see #getLocale |
|
1832 |
* @since JDK1.1 |
|
1833 |
*/ |
|
1834 |
public void setLocale(Locale l) { |
|
1835 |
Locale oldValue = locale; |
|
1836 |
locale = l; |
|
1837 |
||
1838 |
// This is a bound property, so report the change to |
|
1839 |
// any registered listeners. (Cheap if there are none.) |
|
1840 |
firePropertyChange("locale", oldValue, l); |
|
1841 |
||
1842 |
// This could change the preferred size of the Component. |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
1843 |
invalidateIfValid(); |
2 | 1844 |
} |
1845 |
||
1846 |
/** |
|
1847 |
* Gets the instance of <code>ColorModel</code> used to display |
|
1848 |
* the component on the output device. |
|
1849 |
* @return the color model used by this component |
|
1850 |
* @see java.awt.image.ColorModel |
|
1851 |
* @see java.awt.peer.ComponentPeer#getColorModel() |
|
1852 |
* @see Toolkit#getColorModel() |
|
1853 |
* @since JDK1.0 |
|
1854 |
*/ |
|
1855 |
public ColorModel getColorModel() { |
|
1856 |
ComponentPeer peer = this.peer; |
|
1857 |
if ((peer != null) && ! (peer instanceof LightweightPeer)) { |
|
1858 |
return peer.getColorModel(); |
|
1859 |
} else if (GraphicsEnvironment.isHeadless()) { |
|
1860 |
return ColorModel.getRGBdefault(); |
|
1861 |
} // else |
|
1862 |
return getToolkit().getColorModel(); |
|
1863 |
} |
|
1864 |
||
1865 |
/** |
|
1866 |
* Gets the location of this component in the form of a |
|
1867 |
* point specifying the component's top-left corner. |
|
1868 |
* The location will be relative to the parent's coordinate space. |
|
1869 |
* <p> |
|
1870 |
* Due to the asynchronous nature of native event handling, this |
|
1871 |
* method can return outdated values (for instance, after several calls |
|
1872 |
* of <code>setLocation()</code> in rapid succession). For this |
|
1873 |
* reason, the recommended method of obtaining a component's position is |
|
1874 |
* within <code>java.awt.event.ComponentListener.componentMoved()</code>, |
|
1875 |
* which is called after the operating system has finished moving the |
|
1876 |
* component. |
|
1877 |
* </p> |
|
1878 |
* @return an instance of <code>Point</code> representing |
|
1879 |
* the top-left corner of the component's bounds in |
|
1880 |
* the coordinate space of the component's parent |
|
1881 |
* @see #setLocation |
|
1882 |
* @see #getLocationOnScreen |
|
1883 |
* @since JDK1.1 |
|
1884 |
*/ |
|
1885 |
public Point getLocation() { |
|
1886 |
return location(); |
|
1887 |
} |
|
1888 |
||
1889 |
/** |
|
1890 |
* Gets the location of this component in the form of a point |
|
1891 |
* specifying the component's top-left corner in the screen's |
|
1892 |
* coordinate space. |
|
1893 |
* @return an instance of <code>Point</code> representing |
|
1894 |
* the top-left corner of the component's bounds in the |
|
1895 |
* coordinate space of the screen |
|
1896 |
* @throws <code>IllegalComponentStateException</code> if the |
|
1897 |
* component is not showing on the screen |
|
1898 |
* @see #setLocation |
|
1899 |
* @see #getLocation |
|
1900 |
*/ |
|
1901 |
public Point getLocationOnScreen() { |
|
1902 |
synchronized (getTreeLock()) { |
|
1903 |
return getLocationOnScreen_NoTreeLock(); |
|
1904 |
} |
|
1905 |
} |
|
1906 |
||
1907 |
/* |
|
1908 |
* a package private version of getLocationOnScreen |
|
1909 |
* used by GlobalCursormanager to update cursor |
|
1910 |
*/ |
|
1911 |
final Point getLocationOnScreen_NoTreeLock() { |
|
1912 |
||
1913 |
if (peer != null && isShowing()) { |
|
1914 |
if (peer instanceof LightweightPeer) { |
|
1915 |
// lightweight component location needs to be translated |
|
1916 |
// relative to a native component. |
|
1917 |
Container host = getNativeContainer(); |
|
1918 |
Point pt = host.peer.getLocationOnScreen(); |
|
1919 |
for(Component c = this; c != host; c = c.getParent()) { |
|
1920 |
pt.x += c.x; |
|
1921 |
pt.y += c.y; |
|
1922 |
} |
|
1923 |
return pt; |
|
1924 |
} else { |
|
1925 |
Point pt = peer.getLocationOnScreen(); |
|
1926 |
return pt; |
|
1927 |
} |
|
1928 |
} else { |
|
1929 |
throw new IllegalComponentStateException("component must be showing on the screen to determine its location"); |
|
1930 |
} |
|
1931 |
} |
|
1932 |
||
1933 |
||
1934 |
/** |
|
1935 |
* @deprecated As of JDK version 1.1, |
|
1936 |
* replaced by <code>getLocation()</code>. |
|
1937 |
*/ |
|
1938 |
@Deprecated |
|
1939 |
public Point location() { |
|
1940 |
return location_NoClientCode(); |
|
1941 |
} |
|
1942 |
||
1943 |
private Point location_NoClientCode() { |
|
1944 |
return new Point(x, y); |
|
1945 |
} |
|
1946 |
||
1947 |
/** |
|
1948 |
* Moves this component to a new location. The top-left corner of |
|
1949 |
* the new location is specified by the <code>x</code> and <code>y</code> |
|
1950 |
* parameters in the coordinate space of this component's parent. |
|
1951 |
* @param x the <i>x</i>-coordinate of the new location's |
|
1952 |
* top-left corner in the parent's coordinate space |
|
1953 |
* @param y the <i>y</i>-coordinate of the new location's |
|
1954 |
* top-left corner in the parent's coordinate space |
|
1955 |
* @see #getLocation |
|
1956 |
* @see #setBounds |
|
1957 |
* @since JDK1.1 |
|
1958 |
*/ |
|
1959 |
public void setLocation(int x, int y) { |
|
1960 |
move(x, y); |
|
1961 |
} |
|
1962 |
||
1963 |
/** |
|
1964 |
* @deprecated As of JDK version 1.1, |
|
1965 |
* replaced by <code>setLocation(int, int)</code>. |
|
1966 |
*/ |
|
1967 |
@Deprecated |
|
1968 |
public void move(int x, int y) { |
|
1969 |
synchronized(getTreeLock()) { |
|
1970 |
setBoundsOp(ComponentPeer.SET_LOCATION); |
|
1971 |
setBounds(x, y, width, height); |
|
1972 |
} |
|
1973 |
} |
|
1974 |
||
1975 |
/** |
|
1976 |
* Moves this component to a new location. The top-left corner of |
|
1977 |
* the new location is specified by point <code>p</code>. Point |
|
1978 |
* <code>p</code> is given in the parent's coordinate space. |
|
1979 |
* @param p the point defining the top-left corner |
|
1980 |
* of the new location, given in the coordinate space of this |
|
1981 |
* component's parent |
|
1982 |
* @see #getLocation |
|
1983 |
* @see #setBounds |
|
1984 |
* @since JDK1.1 |
|
1985 |
*/ |
|
1986 |
public void setLocation(Point p) { |
|
1987 |
setLocation(p.x, p.y); |
|
1988 |
} |
|
1989 |
||
1990 |
/** |
|
1991 |
* Returns the size of this component in the form of a |
|
1992 |
* <code>Dimension</code> object. The <code>height</code> |
|
1993 |
* field of the <code>Dimension</code> object contains |
|
1994 |
* this component's height, and the <code>width</code> |
|
1995 |
* field of the <code>Dimension</code> object contains |
|
1996 |
* this component's width. |
|
1997 |
* @return a <code>Dimension</code> object that indicates the |
|
1998 |
* size of this component |
|
1999 |
* @see #setSize |
|
2000 |
* @since JDK1.1 |
|
2001 |
*/ |
|
2002 |
public Dimension getSize() { |
|
2003 |
return size(); |
|
2004 |
} |
|
2005 |
||
2006 |
/** |
|
2007 |
* @deprecated As of JDK version 1.1, |
|
2008 |
* replaced by <code>getSize()</code>. |
|
2009 |
*/ |
|
2010 |
@Deprecated |
|
2011 |
public Dimension size() { |
|
2012 |
return new Dimension(width, height); |
|
2013 |
} |
|
2014 |
||
2015 |
/** |
|
2016 |
* Resizes this component so that it has width <code>width</code> |
|
2017 |
* and height <code>height</code>. |
|
2018 |
* @param width the new width of this component in pixels |
|
2019 |
* @param height the new height of this component in pixels |
|
2020 |
* @see #getSize |
|
2021 |
* @see #setBounds |
|
2022 |
* @since JDK1.1 |
|
2023 |
*/ |
|
2024 |
public void setSize(int width, int height) { |
|
2025 |
resize(width, height); |
|
2026 |
} |
|
2027 |
||
2028 |
/** |
|
2029 |
* @deprecated As of JDK version 1.1, |
|
2030 |
* replaced by <code>setSize(int, int)</code>. |
|
2031 |
*/ |
|
2032 |
@Deprecated |
|
2033 |
public void resize(int width, int height) { |
|
2034 |
synchronized(getTreeLock()) { |
|
2035 |
setBoundsOp(ComponentPeer.SET_SIZE); |
|
2036 |
setBounds(x, y, width, height); |
|
2037 |
} |
|
2038 |
} |
|
2039 |
||
2040 |
/** |
|
2041 |
* Resizes this component so that it has width <code>d.width</code> |
|
2042 |
* and height <code>d.height</code>. |
|
2043 |
* @param d the dimension specifying the new size |
|
2044 |
* of this component |
|
2045 |
* @see #setSize |
|
2046 |
* @see #setBounds |
|
2047 |
* @since JDK1.1 |
|
2048 |
*/ |
|
2049 |
public void setSize(Dimension d) { |
|
2050 |
resize(d); |
|
2051 |
} |
|
2052 |
||
2053 |
/** |
|
2054 |
* @deprecated As of JDK version 1.1, |
|
2055 |
* replaced by <code>setSize(Dimension)</code>. |
|
2056 |
*/ |
|
2057 |
@Deprecated |
|
2058 |
public void resize(Dimension d) { |
|
2059 |
setSize(d.width, d.height); |
|
2060 |
} |
|
2061 |
||
2062 |
/** |
|
2063 |
* Gets the bounds of this component in the form of a |
|
2064 |
* <code>Rectangle</code> object. The bounds specify this |
|
2065 |
* component's width, height, and location relative to |
|
2066 |
* its parent. |
|
2067 |
* @return a rectangle indicating this component's bounds |
|
2068 |
* @see #setBounds |
|
2069 |
* @see #getLocation |
|
2070 |
* @see #getSize |
|
2071 |
*/ |
|
2072 |
public Rectangle getBounds() { |
|
2073 |
return bounds(); |
|
2074 |
} |
|
2075 |
||
2076 |
/** |
|
2077 |
* @deprecated As of JDK version 1.1, |
|
2078 |
* replaced by <code>getBounds()</code>. |
|
2079 |
*/ |
|
2080 |
@Deprecated |
|
2081 |
public Rectangle bounds() { |
|
2082 |
return new Rectangle(x, y, width, height); |
|
2083 |
} |
|
2084 |
||
2085 |
/** |
|
2086 |
* Moves and resizes this component. The new location of the top-left |
|
2087 |
* corner is specified by <code>x</code> and <code>y</code>, and the |
|
2088 |
* new size is specified by <code>width</code> and <code>height</code>. |
|
2089 |
* @param x the new <i>x</i>-coordinate of this component |
|
2090 |
* @param y the new <i>y</i>-coordinate of this component |
|
2091 |
* @param width the new <code>width</code> of this component |
|
2092 |
* @param height the new <code>height</code> of this |
|
2093 |
* component |
|
2094 |
* @see #getBounds |
|
2095 |
* @see #setLocation(int, int) |
|
2096 |
* @see #setLocation(Point) |
|
2097 |
* @see #setSize(int, int) |
|
2098 |
* @see #setSize(Dimension) |
|
2099 |
* @since JDK1.1 |
|
2100 |
*/ |
|
2101 |
public void setBounds(int x, int y, int width, int height) { |
|
2102 |
reshape(x, y, width, height); |
|
2103 |
} |
|
2104 |
||
2105 |
/** |
|
2106 |
* @deprecated As of JDK version 1.1, |
|
2107 |
* replaced by <code>setBounds(int, int, int, int)</code>. |
|
2108 |
*/ |
|
2109 |
@Deprecated |
|
2110 |
public void reshape(int x, int y, int width, int height) { |
|
2111 |
synchronized (getTreeLock()) { |
|
2112 |
try { |
|
2113 |
setBoundsOp(ComponentPeer.SET_BOUNDS); |
|
2114 |
boolean resized = (this.width != width) || (this.height != height); |
|
2115 |
boolean moved = (this.x != x) || (this.y != y); |
|
2116 |
if (!resized && !moved) { |
|
2117 |
return; |
|
2118 |
} |
|
2119 |
int oldX = this.x; |
|
2120 |
int oldY = this.y; |
|
2121 |
int oldWidth = this.width; |
|
2122 |
int oldHeight = this.height; |
|
2123 |
this.x = x; |
|
2124 |
this.y = y; |
|
2125 |
this.width = width; |
|
2126 |
this.height = height; |
|
2127 |
||
2128 |
if (resized) { |
|
2129 |
isPacked = false; |
|
2130 |
} |
|
2131 |
||
2132 |
boolean needNotify = true; |
|
2133 |
mixOnReshaping(); |
|
2134 |
if (peer != null) { |
|
2135 |
// LightwightPeer is an empty stub so can skip peer.reshape |
|
2136 |
if (!(peer instanceof LightweightPeer)) { |
|
2137 |
reshapeNativePeer(x, y, width, height, getBoundsOp()); |
|
2138 |
// Check peer actualy changed coordinates |
|
2139 |
resized = (oldWidth != this.width) || (oldHeight != this.height); |
|
2140 |
moved = (oldX != this.x) || (oldY != this.y); |
|
2141 |
// fix for 5025858: do not send ComponentEvents for toplevel |
|
2142 |
// windows here as it is done from peer or native code when |
|
2143 |
// the window is really resized or moved, otherwise some |
|
2144 |
// events may be sent twice |
|
2145 |
if (this instanceof Window) { |
|
2146 |
needNotify = false; |
|
2147 |
} |
|
2148 |
} |
|
2149 |
if (resized) { |
|
2150 |
invalidate(); |
|
2151 |
} |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2152 |
if (parent != null) { |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2153 |
parent.invalidateIfValid(); |
2 | 2154 |
} |
2155 |
} |
|
2156 |
if (needNotify) { |
|
2157 |
notifyNewBounds(resized, moved); |
|
2158 |
} |
|
2159 |
repaintParentIfNeeded(oldX, oldY, oldWidth, oldHeight); |
|
2160 |
} finally { |
|
2161 |
setBoundsOp(ComponentPeer.RESET_OPERATION); |
|
2162 |
} |
|
2163 |
} |
|
2164 |
} |
|
2165 |
||
2166 |
private void repaintParentIfNeeded(int oldX, int oldY, int oldWidth, |
|
2167 |
int oldHeight) |
|
2168 |
{ |
|
2169 |
if (parent != null && peer instanceof LightweightPeer && isShowing()) { |
|
2170 |
// Have the parent redraw the area this component occupied. |
|
2171 |
parent.repaint(oldX, oldY, oldWidth, oldHeight); |
|
2172 |
// Have the parent redraw the area this component *now* occupies. |
|
2173 |
repaint(); |
|
2174 |
} |
|
2175 |
} |
|
2176 |
||
2177 |
private void reshapeNativePeer(int x, int y, int width, int height, int op) { |
|
2178 |
// native peer might be offset by more than direct |
|
2179 |
// parent since parent might be lightweight. |
|
2180 |
int nativeX = x; |
|
2181 |
int nativeY = y; |
|
2182 |
for (Component c = parent; |
|
2183 |
(c != null) && (c.peer instanceof LightweightPeer); |
|
2184 |
c = c.parent) |
|
2185 |
{ |
|
2186 |
nativeX += c.x; |
|
2187 |
nativeY += c.y; |
|
2188 |
} |
|
2189 |
peer.setBounds(nativeX, nativeY, width, height, op); |
|
2190 |
} |
|
2191 |
||
2192 |
||
2193 |
private void notifyNewBounds(boolean resized, boolean moved) { |
|
2194 |
if (componentListener != null |
|
2195 |
|| (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 |
|
2196 |
|| Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) |
|
2197 |
{ |
|
2198 |
if (resized) { |
|
2199 |
ComponentEvent e = new ComponentEvent(this, |
|
2200 |
ComponentEvent.COMPONENT_RESIZED); |
|
2201 |
Toolkit.getEventQueue().postEvent(e); |
|
2202 |
} |
|
2203 |
if (moved) { |
|
2204 |
ComponentEvent e = new ComponentEvent(this, |
|
2205 |
ComponentEvent.COMPONENT_MOVED); |
|
2206 |
Toolkit.getEventQueue().postEvent(e); |
|
2207 |
} |
|
2208 |
} else { |
|
1172
a1d23c450f84
6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
1171
diff
changeset
|
2209 |
if (this instanceof Container && ((Container)this).countComponents() > 0) { |
2 | 2210 |
boolean enabledOnToolkit = |
2211 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK); |
|
2212 |
if (resized) { |
|
2213 |
||
2214 |
((Container)this).createChildHierarchyEvents( |
|
2215 |
HierarchyEvent.ANCESTOR_RESIZED, 0, enabledOnToolkit); |
|
2216 |
} |
|
2217 |
if (moved) { |
|
2218 |
((Container)this).createChildHierarchyEvents( |
|
2219 |
HierarchyEvent.ANCESTOR_MOVED, 0, enabledOnToolkit); |
|
2220 |
} |
|
2221 |
} |
|
2222 |
} |
|
2223 |
} |
|
2224 |
||
2225 |
/** |
|
2226 |
* Moves and resizes this component to conform to the new |
|
2227 |
* bounding rectangle <code>r</code>. This component's new |
|
2228 |
* position is specified by <code>r.x</code> and <code>r.y</code>, |
|
2229 |
* and its new size is specified by <code>r.width</code> and |
|
2230 |
* <code>r.height</code> |
|
2231 |
* @param r the new bounding rectangle for this component |
|
2232 |
* @see #getBounds |
|
2233 |
* @see #setLocation(int, int) |
|
2234 |
* @see #setLocation(Point) |
|
2235 |
* @see #setSize(int, int) |
|
2236 |
* @see #setSize(Dimension) |
|
2237 |
* @since JDK1.1 |
|
2238 |
*/ |
|
2239 |
public void setBounds(Rectangle r) { |
|
2240 |
setBounds(r.x, r.y, r.width, r.height); |
|
2241 |
} |
|
2242 |
||
2243 |
||
2244 |
/** |
|
2245 |
* Returns the current x coordinate of the components origin. |
|
2246 |
* This method is preferable to writing |
|
2247 |
* <code>component.getBounds().x</code>, |
|
2248 |
* or <code>component.getLocation().x</code> because it doesn't |
|
2249 |
* cause any heap allocations. |
|
2250 |
* |
|
2251 |
* @return the current x coordinate of the components origin |
|
2252 |
* @since 1.2 |
|
2253 |
*/ |
|
2254 |
public int getX() { |
|
2255 |
return x; |
|
2256 |
} |
|
2257 |
||
2258 |
||
2259 |
/** |
|
2260 |
* Returns the current y coordinate of the components origin. |
|
2261 |
* This method is preferable to writing |
|
2262 |
* <code>component.getBounds().y</code>, |
|
2263 |
* or <code>component.getLocation().y</code> because it |
|
2264 |
* doesn't cause any heap allocations. |
|
2265 |
* |
|
2266 |
* @return the current y coordinate of the components origin |
|
2267 |
* @since 1.2 |
|
2268 |
*/ |
|
2269 |
public int getY() { |
|
2270 |
return y; |
|
2271 |
} |
|
2272 |
||
2273 |
||
2274 |
/** |
|
2275 |
* Returns the current width of this component. |
|
2276 |
* This method is preferable to writing |
|
2277 |
* <code>component.getBounds().width</code>, |
|
2278 |
* or <code>component.getSize().width</code> because it |
|
2279 |
* doesn't cause any heap allocations. |
|
2280 |
* |
|
2281 |
* @return the current width of this component |
|
2282 |
* @since 1.2 |
|
2283 |
*/ |
|
2284 |
public int getWidth() { |
|
2285 |
return width; |
|
2286 |
} |
|
2287 |
||
2288 |
||
2289 |
/** |
|
2290 |
* Returns the current height of this component. |
|
2291 |
* This method is preferable to writing |
|
2292 |
* <code>component.getBounds().height</code>, |
|
2293 |
* or <code>component.getSize().height</code> because it |
|
2294 |
* doesn't cause any heap allocations. |
|
2295 |
* |
|
2296 |
* @return the current height of this component |
|
2297 |
* @since 1.2 |
|
2298 |
*/ |
|
2299 |
public int getHeight() { |
|
2300 |
return height; |
|
2301 |
} |
|
2302 |
||
2303 |
/** |
|
2304 |
* Stores the bounds of this component into "return value" <b>rv</b> and |
|
2305 |
* return <b>rv</b>. If rv is <code>null</code> a new |
|
2306 |
* <code>Rectangle</code> is allocated. |
|
2307 |
* This version of <code>getBounds</code> is useful if the caller |
|
2308 |
* wants to avoid allocating a new <code>Rectangle</code> object |
|
2309 |
* on the heap. |
|
2310 |
* |
|
2311 |
* @param rv the return value, modified to the components bounds |
|
2312 |
* @return rv |
|
2313 |
*/ |
|
2314 |
public Rectangle getBounds(Rectangle rv) { |
|
2315 |
if (rv == null) { |
|
2316 |
return new Rectangle(getX(), getY(), getWidth(), getHeight()); |
|
2317 |
} |
|
2318 |
else { |
|
2319 |
rv.setBounds(getX(), getY(), getWidth(), getHeight()); |
|
2320 |
return rv; |
|
2321 |
} |
|
2322 |
} |
|
2323 |
||
2324 |
/** |
|
2325 |
* Stores the width/height of this component into "return value" <b>rv</b> |
|
2326 |
* and return <b>rv</b>. If rv is <code>null</code> a new |
|
2327 |
* <code>Dimension</code> object is allocated. This version of |
|
2328 |
* <code>getSize</code> is useful if the caller wants to avoid |
|
2329 |
* allocating a new <code>Dimension</code> object on the heap. |
|
2330 |
* |
|
2331 |
* @param rv the return value, modified to the components size |
|
2332 |
* @return rv |
|
2333 |
*/ |
|
2334 |
public Dimension getSize(Dimension rv) { |
|
2335 |
if (rv == null) { |
|
2336 |
return new Dimension(getWidth(), getHeight()); |
|
2337 |
} |
|
2338 |
else { |
|
2339 |
rv.setSize(getWidth(), getHeight()); |
|
2340 |
return rv; |
|
2341 |
} |
|
2342 |
} |
|
2343 |
||
2344 |
/** |
|
2345 |
* Stores the x,y origin of this component into "return value" <b>rv</b> |
|
2346 |
* and return <b>rv</b>. If rv is <code>null</code> a new |
|
2347 |
* <code>Point</code> is allocated. |
|
2348 |
* This version of <code>getLocation</code> is useful if the |
|
2349 |
* caller wants to avoid allocating a new <code>Point</code> |
|
2350 |
* object on the heap. |
|
2351 |
* |
|
2352 |
* @param rv the return value, modified to the components location |
|
2353 |
* @return rv |
|
2354 |
*/ |
|
2355 |
public Point getLocation(Point rv) { |
|
2356 |
if (rv == null) { |
|
2357 |
return new Point(getX(), getY()); |
|
2358 |
} |
|
2359 |
else { |
|
2360 |
rv.setLocation(getX(), getY()); |
|
2361 |
return rv; |
|
2362 |
} |
|
2363 |
} |
|
2364 |
||
2365 |
/** |
|
2366 |
* Returns true if this component is completely opaque, returns |
|
2367 |
* false by default. |
|
2368 |
* <p> |
|
2369 |
* An opaque component paints every pixel within its |
|
2370 |
* rectangular region. A non-opaque component paints only some of |
|
2371 |
* its pixels, allowing the pixels underneath it to "show through". |
|
2372 |
* A component that does not fully paint its pixels therefore |
|
3237 | 2373 |
* provides a degree of transparency. |
2 | 2374 |
* <p> |
2375 |
* Subclasses that guarantee to always completely paint their |
|
3237 | 2376 |
* contents should override this method and return true. |
2 | 2377 |
* |
2378 |
* @return true if this component is completely opaque |
|
2379 |
* @see #isLightweight |
|
2380 |
* @since 1.2 |
|
2381 |
*/ |
|
2382 |
public boolean isOpaque() { |
|
2383 |
if (getPeer() == null) { |
|
2384 |
return false; |
|
2385 |
} |
|
2386 |
else { |
|
2387 |
return !isLightweight(); |
|
2388 |
} |
|
2389 |
} |
|
2390 |
||
2391 |
||
2392 |
/** |
|
2393 |
* A lightweight component doesn't have a native toolkit peer. |
|
2394 |
* Subclasses of <code>Component</code> and <code>Container</code>, |
|
2395 |
* other than the ones defined in this package like <code>Button</code> |
|
2396 |
* or <code>Scrollbar</code>, are lightweight. |
|
2397 |
* All of the Swing components are lightweights. |
|
2398 |
* <p> |
|
2399 |
* This method will always return <code>false</code> if this component |
|
2400 |
* is not displayable because it is impossible to determine the |
|
2401 |
* weight of an undisplayable component. |
|
2402 |
* |
|
2403 |
* @return true if this component has a lightweight peer; false if |
|
2404 |
* it has a native peer or no peer |
|
2405 |
* @see #isDisplayable |
|
2406 |
* @since 1.2 |
|
2407 |
*/ |
|
2408 |
public boolean isLightweight() { |
|
2409 |
return getPeer() instanceof LightweightPeer; |
|
2410 |
} |
|
2411 |
||
2412 |
||
2413 |
/** |
|
2414 |
* Sets the preferred size of this component to a constant |
|
2415 |
* value. Subsequent calls to <code>getPreferredSize</code> will always |
|
2416 |
* return this value. Setting the preferred size to <code>null</code> |
|
2417 |
* restores the default behavior. |
|
2418 |
* |
|
2419 |
* @param preferredSize The new preferred size, or null |
|
2420 |
* @see #getPreferredSize |
|
2421 |
* @see #isPreferredSizeSet |
|
2422 |
* @since 1.5 |
|
2423 |
*/ |
|
2424 |
public void setPreferredSize(Dimension preferredSize) { |
|
2425 |
Dimension old; |
|
2426 |
// If the preferred size was set, use it as the old value, otherwise |
|
2427 |
// use null to indicate we didn't previously have a set preferred |
|
2428 |
// size. |
|
2429 |
if (prefSizeSet) { |
|
2430 |
old = this.prefSize; |
|
2431 |
} |
|
2432 |
else { |
|
2433 |
old = null; |
|
2434 |
} |
|
2435 |
this.prefSize = preferredSize; |
|
2436 |
prefSizeSet = (preferredSize != null); |
|
2437 |
firePropertyChange("preferredSize", old, preferredSize); |
|
2438 |
} |
|
2439 |
||
2440 |
||
2441 |
/** |
|
2442 |
* Returns true if the preferred size has been set to a |
|
2443 |
* non-<code>null</code> value otherwise returns false. |
|
2444 |
* |
|
2445 |
* @return true if <code>setPreferredSize</code> has been invoked |
|
2446 |
* with a non-null value. |
|
2447 |
* @since 1.5 |
|
2448 |
*/ |
|
2449 |
public boolean isPreferredSizeSet() { |
|
2450 |
return prefSizeSet; |
|
2451 |
} |
|
2452 |
||
2453 |
||
2454 |
/** |
|
2455 |
* Gets the preferred size of this component. |
|
2456 |
* @return a dimension object indicating this component's preferred size |
|
2457 |
* @see #getMinimumSize |
|
2458 |
* @see LayoutManager |
|
2459 |
*/ |
|
2460 |
public Dimension getPreferredSize() { |
|
2461 |
return preferredSize(); |
|
2462 |
} |
|
2463 |
||
2464 |
||
2465 |
/** |
|
2466 |
* @deprecated As of JDK version 1.1, |
|
2467 |
* replaced by <code>getPreferredSize()</code>. |
|
2468 |
*/ |
|
2469 |
@Deprecated |
|
2470 |
public Dimension preferredSize() { |
|
2471 |
/* Avoid grabbing the lock if a reasonable cached size value |
|
2472 |
* is available. |
|
2473 |
*/ |
|
2474 |
Dimension dim = prefSize; |
|
2475 |
if (dim == null || !(isPreferredSizeSet() || isValid())) { |
|
2476 |
synchronized (getTreeLock()) { |
|
2477 |
prefSize = (peer != null) ? |
|
1964 | 2478 |
peer.getPreferredSize() : |
2 | 2479 |
getMinimumSize(); |
2480 |
dim = prefSize; |
|
2481 |
} |
|
2482 |
} |
|
2483 |
return new Dimension(dim); |
|
2484 |
} |
|
2485 |
||
2486 |
/** |
|
2487 |
* Sets the minimum size of this component to a constant |
|
2488 |
* value. Subsequent calls to <code>getMinimumSize</code> will always |
|
2489 |
* return this value. Setting the minimum size to <code>null</code> |
|
2490 |
* restores the default behavior. |
|
2491 |
* |
|
2492 |
* @param minimumSize the new minimum size of this component |
|
2493 |
* @see #getMinimumSize |
|
2494 |
* @see #isMinimumSizeSet |
|
2495 |
* @since 1.5 |
|
2496 |
*/ |
|
2497 |
public void setMinimumSize(Dimension minimumSize) { |
|
2498 |
Dimension old; |
|
2499 |
// If the minimum size was set, use it as the old value, otherwise |
|
2500 |
// use null to indicate we didn't previously have a set minimum |
|
2501 |
// size. |
|
2502 |
if (minSizeSet) { |
|
2503 |
old = this.minSize; |
|
2504 |
} |
|
2505 |
else { |
|
2506 |
old = null; |
|
2507 |
} |
|
2508 |
this.minSize = minimumSize; |
|
2509 |
minSizeSet = (minimumSize != null); |
|
2510 |
firePropertyChange("minimumSize", old, minimumSize); |
|
2511 |
} |
|
2512 |
||
2513 |
/** |
|
2514 |
* Returns whether or not <code>setMinimumSize</code> has been |
|
2515 |
* invoked with a non-null value. |
|
2516 |
* |
|
2517 |
* @return true if <code>setMinimumSize</code> has been invoked with a |
|
2518 |
* non-null value. |
|
2519 |
* @since 1.5 |
|
2520 |
*/ |
|
2521 |
public boolean isMinimumSizeSet() { |
|
2522 |
return minSizeSet; |
|
2523 |
} |
|
2524 |
||
2525 |
/** |
|
2526 |
* Gets the mininimum size of this component. |
|
2527 |
* @return a dimension object indicating this component's minimum size |
|
2528 |
* @see #getPreferredSize |
|
2529 |
* @see LayoutManager |
|
2530 |
*/ |
|
2531 |
public Dimension getMinimumSize() { |
|
2532 |
return minimumSize(); |
|
2533 |
} |
|
2534 |
||
2535 |
/** |
|
2536 |
* @deprecated As of JDK version 1.1, |
|
2537 |
* replaced by <code>getMinimumSize()</code>. |
|
2538 |
*/ |
|
2539 |
@Deprecated |
|
2540 |
public Dimension minimumSize() { |
|
2541 |
/* Avoid grabbing the lock if a reasonable cached size value |
|
2542 |
* is available. |
|
2543 |
*/ |
|
2544 |
Dimension dim = minSize; |
|
2545 |
if (dim == null || !(isMinimumSizeSet() || isValid())) { |
|
2546 |
synchronized (getTreeLock()) { |
|
2547 |
minSize = (peer != null) ? |
|
1964 | 2548 |
peer.getMinimumSize() : |
2 | 2549 |
size(); |
2550 |
dim = minSize; |
|
2551 |
} |
|
2552 |
} |
|
2553 |
return new Dimension(dim); |
|
2554 |
} |
|
2555 |
||
2556 |
/** |
|
2557 |
* Sets the maximum size of this component to a constant |
|
2558 |
* value. Subsequent calls to <code>getMaximumSize</code> will always |
|
2559 |
* return this value. Setting the maximum size to <code>null</code> |
|
2560 |
* restores the default behavior. |
|
2561 |
* |
|
2562 |
* @param maximumSize a <code>Dimension</code> containing the |
|
2563 |
* desired maximum allowable size |
|
2564 |
* @see #getMaximumSize |
|
2565 |
* @see #isMaximumSizeSet |
|
2566 |
* @since 1.5 |
|
2567 |
*/ |
|
2568 |
public void setMaximumSize(Dimension maximumSize) { |
|
2569 |
// If the maximum size was set, use it as the old value, otherwise |
|
2570 |
// use null to indicate we didn't previously have a set maximum |
|
2571 |
// size. |
|
2572 |
Dimension old; |
|
2573 |
if (maxSizeSet) { |
|
2574 |
old = this.maxSize; |
|
2575 |
} |
|
2576 |
else { |
|
2577 |
old = null; |
|
2578 |
} |
|
2579 |
this.maxSize = maximumSize; |
|
2580 |
maxSizeSet = (maximumSize != null); |
|
2581 |
firePropertyChange("maximumSize", old, maximumSize); |
|
2582 |
} |
|
2583 |
||
2584 |
/** |
|
2585 |
* Returns true if the maximum size has been set to a non-<code>null</code> |
|
2586 |
* value otherwise returns false. |
|
2587 |
* |
|
2588 |
* @return true if <code>maximumSize</code> is non-<code>null</code>, |
|
2589 |
* false otherwise |
|
2590 |
* @since 1.5 |
|
2591 |
*/ |
|
2592 |
public boolean isMaximumSizeSet() { |
|
2593 |
return maxSizeSet; |
|
2594 |
} |
|
2595 |
||
2596 |
/** |
|
2597 |
* Gets the maximum size of this component. |
|
2598 |
* @return a dimension object indicating this component's maximum size |
|
2599 |
* @see #getMinimumSize |
|
2600 |
* @see #getPreferredSize |
|
2601 |
* @see LayoutManager |
|
2602 |
*/ |
|
2603 |
public Dimension getMaximumSize() { |
|
2604 |
if (isMaximumSizeSet()) { |
|
2605 |
return new Dimension(maxSize); |
|
2606 |
} |
|
2607 |
return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); |
|
2608 |
} |
|
2609 |
||
2610 |
/** |
|
2611 |
* Returns the alignment along the x axis. This specifies how |
|
2612 |
* the component would like to be aligned relative to other |
|
2613 |
* components. The value should be a number between 0 and 1 |
|
2614 |
* where 0 represents alignment along the origin, 1 is aligned |
|
2615 |
* the furthest away from the origin, 0.5 is centered, etc. |
|
2616 |
*/ |
|
2617 |
public float getAlignmentX() { |
|
2618 |
return CENTER_ALIGNMENT; |
|
2619 |
} |
|
2620 |
||
2621 |
/** |
|
2622 |
* Returns the alignment along the y axis. This specifies how |
|
2623 |
* the component would like to be aligned relative to other |
|
2624 |
* components. The value should be a number between 0 and 1 |
|
2625 |
* where 0 represents alignment along the origin, 1 is aligned |
|
2626 |
* the furthest away from the origin, 0.5 is centered, etc. |
|
2627 |
*/ |
|
2628 |
public float getAlignmentY() { |
|
2629 |
return CENTER_ALIGNMENT; |
|
2630 |
} |
|
2631 |
||
2632 |
/** |
|
2633 |
* Returns the baseline. The baseline is measured from the top of |
|
2634 |
* the component. This method is primarily meant for |
|
2635 |
* <code>LayoutManager</code>s to align components along their |
|
2636 |
* baseline. A return value less than 0 indicates this component |
|
2637 |
* does not have a reasonable baseline and that |
|
2638 |
* <code>LayoutManager</code>s should not align this component on |
|
2639 |
* its baseline. |
|
2640 |
* <p> |
|
2641 |
* The default implementation returns -1. Subclasses that support |
|
2642 |
* baseline should override appropriately. If a value >= 0 is |
|
2643 |
* returned, then the component has a valid baseline for any |
|
2644 |
* size >= the minimum size and <code>getBaselineResizeBehavior</code> |
|
2645 |
* can be used to determine how the baseline changes with size. |
|
2646 |
* |
|
2647 |
* @param width the width to get the baseline for |
|
2648 |
* @param height the height to get the baseline for |
|
2649 |
* @return the baseline or < 0 indicating there is no reasonable |
|
2650 |
* baseline |
|
2651 |
* @throws IllegalArgumentException if width or height is < 0 |
|
2652 |
* @see #getBaselineResizeBehavior |
|
2653 |
* @see java.awt.FontMetrics |
|
2654 |
* @since 1.6 |
|
2655 |
*/ |
|
2656 |
public int getBaseline(int width, int height) { |
|
2657 |
if (width < 0 || height < 0) { |
|
2658 |
throw new IllegalArgumentException( |
|
2659 |
"Width and height must be >= 0"); |
|
2660 |
} |
|
2661 |
return -1; |
|
2662 |
} |
|
2663 |
||
2664 |
/** |
|
2665 |
* Returns an enum indicating how the baseline of the component |
|
2666 |
* changes as the size changes. This method is primarily meant for |
|
2667 |
* layout managers and GUI builders. |
|
2668 |
* <p> |
|
2669 |
* The default implementation returns |
|
2670 |
* <code>BaselineResizeBehavior.OTHER</code>. Subclasses that have a |
|
2671 |
* baseline should override appropriately. Subclasses should |
|
2672 |
* never return <code>null</code>; if the baseline can not be |
|
2673 |
* calculated return <code>BaselineResizeBehavior.OTHER</code>. Callers |
|
2674 |
* should first ask for the baseline using |
|
2675 |
* <code>getBaseline</code> and if a value >= 0 is returned use |
|
2676 |
* this method. It is acceptable for this method to return a |
|
2677 |
* value other than <code>BaselineResizeBehavior.OTHER</code> even if |
|
2678 |
* <code>getBaseline</code> returns a value less than 0. |
|
2679 |
* |
|
2680 |
* @return an enum indicating how the baseline changes as the component |
|
2681 |
* size changes |
|
2682 |
* @see #getBaseline(int, int) |
|
2683 |
* @since 1.6 |
|
2684 |
*/ |
|
2685 |
public BaselineResizeBehavior getBaselineResizeBehavior() { |
|
2686 |
return BaselineResizeBehavior.OTHER; |
|
2687 |
} |
|
2688 |
||
2689 |
/** |
|
2690 |
* Prompts the layout manager to lay out this component. This is |
|
2691 |
* usually called when the component (more specifically, container) |
|
2692 |
* is validated. |
|
2693 |
* @see #validate |
|
2694 |
* @see LayoutManager |
|
2695 |
*/ |
|
2696 |
public void doLayout() { |
|
2697 |
layout(); |
|
2698 |
} |
|
2699 |
||
2700 |
/** |
|
2701 |
* @deprecated As of JDK version 1.1, |
|
2702 |
* replaced by <code>doLayout()</code>. |
|
2703 |
*/ |
|
2704 |
@Deprecated |
|
2705 |
public void layout() { |
|
2706 |
} |
|
2707 |
||
2708 |
/** |
|
2709 |
* Ensures that this component has a valid layout. This method is |
|
2710 |
* primarily intended to operate on instances of <code>Container</code>. |
|
2711 |
* @see #invalidate |
|
2712 |
* @see #doLayout() |
|
2713 |
* @see LayoutManager |
|
2714 |
* @see Container#validate |
|
2715 |
* @since JDK1.0 |
|
2716 |
*/ |
|
2717 |
public void validate() { |
|
2718 |
synchronized (getTreeLock()) { |
|
2719 |
ComponentPeer peer = this.peer; |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2720 |
boolean wasValid = isValid(); |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2721 |
if (!wasValid && peer != null) { |
2 | 2722 |
Font newfont = getFont(); |
2723 |
Font oldfont = peerFont; |
|
2724 |
if (newfont != oldfont && (oldfont == null |
|
2725 |
|| !oldfont.equals(newfont))) { |
|
2726 |
peer.setFont(newfont); |
|
2727 |
peerFont = newfont; |
|
2728 |
} |
|
2729 |
peer.layout(); |
|
2730 |
} |
|
2731 |
valid = true; |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2732 |
if (!wasValid) { |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2733 |
mixOnValidating(); |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2734 |
} |
2 | 2735 |
} |
2736 |
} |
|
2737 |
||
2738 |
/** |
|
2739 |
* Invalidates this component. This component and all parents |
|
2740 |
* above it are marked as needing to be laid out. This method can |
|
2741 |
* be called often, so it needs to execute quickly. |
|
2742 |
* @see #validate |
|
2743 |
* @see #doLayout |
|
2744 |
* @see LayoutManager |
|
2745 |
* @since JDK1.0 |
|
2746 |
*/ |
|
2747 |
public void invalidate() { |
|
2748 |
synchronized (getTreeLock()) { |
|
2749 |
/* Nullify cached layout and size information. |
|
2750 |
* For efficiency, propagate invalidate() upwards only if |
|
2751 |
* some other component hasn't already done so first. |
|
2752 |
*/ |
|
2753 |
valid = false; |
|
2754 |
if (!isPreferredSizeSet()) { |
|
2755 |
prefSize = null; |
|
2756 |
} |
|
2757 |
if (!isMinimumSizeSet()) { |
|
2758 |
minSize = null; |
|
2759 |
} |
|
2760 |
if (!isMaximumSizeSet()) { |
|
2761 |
maxSize = null; |
|
2762 |
} |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2763 |
if (parent != null) { |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2764 |
parent.invalidateIfValid(); |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2765 |
} |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2766 |
} |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2767 |
} |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2768 |
|
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2769 |
/** Invalidates the component unless it is already invalid. |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2770 |
*/ |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2771 |
final void invalidateIfValid() { |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2772 |
if (isValid()) { |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
2773 |
invalidate(); |
2 | 2774 |
} |
2775 |
} |
|
2776 |
||
2777 |
/** |
|
2778 |
* Creates a graphics context for this component. This method will |
|
2779 |
* return <code>null</code> if this component is currently not |
|
2780 |
* displayable. |
|
2781 |
* @return a graphics context for this component, or <code>null</code> |
|
2782 |
* if it has none |
|
2783 |
* @see #paint |
|
2784 |
* @since JDK1.0 |
|
2785 |
*/ |
|
2786 |
public Graphics getGraphics() { |
|
2787 |
if (peer instanceof LightweightPeer) { |
|
2788 |
// This is for a lightweight component, need to |
|
2789 |
// translate coordinate spaces and clip relative |
|
2790 |
// to the parent. |
|
2791 |
if (parent == null) return null; |
|
2792 |
Graphics g = parent.getGraphics(); |
|
2793 |
if (g == null) return null; |
|
2794 |
if (g instanceof ConstrainableGraphics) { |
|
2795 |
((ConstrainableGraphics) g).constrain(x, y, width, height); |
|
2796 |
} else { |
|
2797 |
g.translate(x,y); |
|
2798 |
g.setClip(0, 0, width, height); |
|
2799 |
} |
|
2800 |
g.setFont(getFont()); |
|
2801 |
return g; |
|
2802 |
} else { |
|
2803 |
ComponentPeer peer = this.peer; |
|
2804 |
return (peer != null) ? peer.getGraphics() : null; |
|
2805 |
} |
|
2806 |
} |
|
2807 |
||
2808 |
final Graphics getGraphics_NoClientCode() { |
|
2809 |
ComponentPeer peer = this.peer; |
|
2810 |
if (peer instanceof LightweightPeer) { |
|
2811 |
// This is for a lightweight component, need to |
|
2812 |
// translate coordinate spaces and clip relative |
|
2813 |
// to the parent. |
|
2814 |
Container parent = this.parent; |
|
2815 |
if (parent == null) return null; |
|
2816 |
Graphics g = parent.getGraphics_NoClientCode(); |
|
2817 |
if (g == null) return null; |
|
2818 |
if (g instanceof ConstrainableGraphics) { |
|
2819 |
((ConstrainableGraphics) g).constrain(x, y, width, height); |
|
2820 |
} else { |
|
2821 |
g.translate(x,y); |
|
2822 |
g.setClip(0, 0, width, height); |
|
2823 |
} |
|
2824 |
g.setFont(getFont_NoClientCode()); |
|
2825 |
return g; |
|
2826 |
} else { |
|
2827 |
return (peer != null) ? peer.getGraphics() : null; |
|
2828 |
} |
|
2829 |
} |
|
2830 |
||
2831 |
/** |
|
2832 |
* Gets the font metrics for the specified font. |
|
2833 |
* Warning: Since Font metrics are affected by the |
|
2834 |
* {@link java.awt.font.FontRenderContext FontRenderContext} and |
|
2835 |
* this method does not provide one, it can return only metrics for |
|
2836 |
* the default render context which may not match that used when |
|
2837 |
* rendering on the Component if {@link Graphics2D} functionality is being |
|
2838 |
* used. Instead metrics can be obtained at rendering time by calling |
|
2839 |
* {@link Graphics#getFontMetrics()} or text measurement APIs on the |
|
2840 |
* {@link Font Font} class. |
|
2841 |
* @param font the font for which font metrics is to be |
|
2842 |
* obtained |
|
2843 |
* @return the font metrics for <code>font</code> |
|
2844 |
* @see #getFont |
|
2845 |
* @see #getPeer |
|
2846 |
* @see java.awt.peer.ComponentPeer#getFontMetrics(Font) |
|
2847 |
* @see Toolkit#getFontMetrics(Font) |
|
2848 |
* @since JDK1.0 |
|
2849 |
*/ |
|
2850 |
public FontMetrics getFontMetrics(Font font) { |
|
2851 |
// REMIND: PlatformFont flag should be obsolete soon... |
|
2852 |
if (sun.font.FontManager.usePlatformFontMetrics()) { |
|
2853 |
if (peer != null && |
|
2854 |
!(peer instanceof LightweightPeer)) { |
|
2855 |
return peer.getFontMetrics(font); |
|
2856 |
} |
|
2857 |
} |
|
2858 |
return sun.font.FontDesignMetrics.getMetrics(font); |
|
2859 |
} |
|
2860 |
||
2861 |
/** |
|
2862 |
* Sets the cursor image to the specified cursor. This cursor |
|
2863 |
* image is displayed when the <code>contains</code> method for |
|
2864 |
* this component returns true for the current cursor location, and |
|
2865 |
* this Component is visible, displayable, and enabled. Setting the |
|
2866 |
* cursor of a <code>Container</code> causes that cursor to be displayed |
|
2867 |
* within all of the container's subcomponents, except for those |
|
2868 |
* that have a non-<code>null</code> cursor. |
|
2869 |
* <p> |
|
2870 |
* The method may have no visual effect if the Java platform |
|
2871 |
* implementation and/or the native system do not support |
|
2872 |
* changing the mouse cursor shape. |
|
2873 |
* @param cursor One of the constants defined |
|
2874 |
* by the <code>Cursor</code> class; |
|
2875 |
* if this parameter is <code>null</code> |
|
2876 |
* then this component will inherit |
|
2877 |
* the cursor of its parent |
|
2878 |
* @see #isEnabled |
|
2879 |
* @see #isShowing |
|
2880 |
* @see #getCursor |
|
2881 |
* @see #contains |
|
2882 |
* @see Toolkit#createCustomCursor |
|
2883 |
* @see Cursor |
|
2884 |
* @since JDK1.1 |
|
2885 |
*/ |
|
2886 |
public void setCursor(Cursor cursor) { |
|
2887 |
this.cursor = cursor; |
|
2888 |
updateCursorImmediately(); |
|
2889 |
} |
|
2890 |
||
2891 |
/** |
|
2892 |
* Updates the cursor. May not be invoked from the native |
|
2893 |
* message pump. |
|
2894 |
*/ |
|
2895 |
final void updateCursorImmediately() { |
|
2896 |
if (peer instanceof LightweightPeer) { |
|
2897 |
Container nativeContainer = getNativeContainer(); |
|
2898 |
||
2899 |
if (nativeContainer == null) return; |
|
2900 |
||
2901 |
ComponentPeer cPeer = nativeContainer.getPeer(); |
|
2902 |
||
2903 |
if (cPeer != null) { |
|
2904 |
cPeer.updateCursorImmediately(); |
|
2905 |
} |
|
2906 |
} else if (peer != null) { |
|
2907 |
peer.updateCursorImmediately(); |
|
2908 |
} |
|
2909 |
} |
|
2910 |
||
2911 |
/** |
|
2912 |
* Gets the cursor set in the component. If the component does |
|
2913 |
* not have a cursor set, the cursor of its parent is returned. |
|
2914 |
* If no cursor is set in the entire hierarchy, |
|
2915 |
* <code>Cursor.DEFAULT_CURSOR</code> is returned. |
|
2916 |
* @see #setCursor |
|
2917 |
* @since JDK1.1 |
|
2918 |
*/ |
|
2919 |
public Cursor getCursor() { |
|
2920 |
return getCursor_NoClientCode(); |
|
2921 |
} |
|
2922 |
||
2923 |
final Cursor getCursor_NoClientCode() { |
|
2924 |
Cursor cursor = this.cursor; |
|
2925 |
if (cursor != null) { |
|
2926 |
return cursor; |
|
2927 |
} |
|
2928 |
Container parent = this.parent; |
|
2929 |
if (parent != null) { |
|
2930 |
return parent.getCursor_NoClientCode(); |
|
2931 |
} else { |
|
2932 |
return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); |
|
2933 |
} |
|
2934 |
} |
|
2935 |
||
2936 |
/** |
|
2937 |
* Returns whether the cursor has been explicitly set for this Component. |
|
2938 |
* If this method returns <code>false</code>, this Component is inheriting |
|
2939 |
* its cursor from an ancestor. |
|
2940 |
* |
|
2941 |
* @return <code>true</code> if the cursor has been explicitly set for this |
|
2942 |
* Component; <code>false</code> otherwise. |
|
2943 |
* @since 1.4 |
|
2944 |
*/ |
|
2945 |
public boolean isCursorSet() { |
|
2946 |
return (cursor != null); |
|
2947 |
} |
|
2948 |
||
2949 |
/** |
|
2950 |
* Paints this component. |
|
2951 |
* <p> |
|
2952 |
* This method is called when the contents of the component should |
|
2953 |
* be painted; such as when the component is first being shown or |
|
2954 |
* is damaged and in need of repair. The clip rectangle in the |
|
2955 |
* <code>Graphics</code> parameter is set to the area |
|
2956 |
* which needs to be painted. |
|
2957 |
* Subclasses of <code>Component</code> that override this |
|
2958 |
* method need not call <code>super.paint(g)</code>. |
|
2959 |
* <p> |
|
2960 |
* For performance reasons, <code>Component</code>s with zero width |
|
2961 |
* or height aren't considered to need painting when they are first shown, |
|
2962 |
* and also aren't considered to need repair. |
|
2963 |
* <p> |
|
2964 |
* <b>Note</b>: For more information on the paint mechanisms utilitized |
|
2965 |
* by AWT and Swing, including information on how to write the most |
|
2966 |
* efficient painting code, see |
|
2967 |
* <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. |
|
2968 |
* |
|
2969 |
* @param g the graphics context to use for painting |
|
2970 |
* @see #update |
|
2971 |
* @since JDK1.0 |
|
2972 |
*/ |
|
2973 |
public void paint(Graphics g) { |
|
2974 |
} |
|
2975 |
||
2976 |
/** |
|
2977 |
* Updates this component. |
|
2978 |
* <p> |
|
2979 |
* If this component is not a lightweight component, the |
|
2980 |
* AWT calls the <code>update</code> method in response to |
|
2981 |
* a call to <code>repaint</code>. You can assume that |
|
2982 |
* the background is not cleared. |
|
2983 |
* <p> |
|
2984 |
* The <code>update</code> method of <code>Component</code> |
|
2985 |
* calls this component's <code>paint</code> method to redraw |
|
2986 |
* this component. This method is commonly overridden by subclasses |
|
2987 |
* which need to do additional work in response to a call to |
|
2988 |
* <code>repaint</code>. |
|
2989 |
* Subclasses of Component that override this method should either |
|
2990 |
* call <code>super.update(g)</code>, or call <code>paint(g)</code> |
|
2991 |
* directly from their <code>update</code> method. |
|
2992 |
* <p> |
|
2993 |
* The origin of the graphics context, its |
|
2994 |
* (<code>0</code>, <code>0</code>) coordinate point, is the |
|
2995 |
* top-left corner of this component. The clipping region of the |
|
2996 |
* graphics context is the bounding rectangle of this component. |
|
2997 |
* |
|
2998 |
* <p> |
|
2999 |
* <b>Note</b>: For more information on the paint mechanisms utilitized |
|
3000 |
* by AWT and Swing, including information on how to write the most |
|
3001 |
* efficient painting code, see |
|
3002 |
* <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. |
|
3003 |
* |
|
3004 |
* @param g the specified context to use for updating |
|
3005 |
* @see #paint |
|
3006 |
* @see #repaint() |
|
3007 |
* @since JDK1.0 |
|
3008 |
*/ |
|
3009 |
public void update(Graphics g) { |
|
3010 |
paint(g); |
|
3011 |
} |
|
3012 |
||
3013 |
/** |
|
3014 |
* Paints this component and all of its subcomponents. |
|
3015 |
* <p> |
|
3016 |
* The origin of the graphics context, its |
|
3017 |
* (<code>0</code>, <code>0</code>) coordinate point, is the |
|
3018 |
* top-left corner of this component. The clipping region of the |
|
3019 |
* graphics context is the bounding rectangle of this component. |
|
3020 |
* |
|
3021 |
* @param g the graphics context to use for painting |
|
3022 |
* @see #paint |
|
3023 |
* @since JDK1.0 |
|
3024 |
*/ |
|
3025 |
public void paintAll(Graphics g) { |
|
3026 |
if (isShowing()) { |
|
3027 |
GraphicsCallback.PeerPaintCallback.getInstance(). |
|
3028 |
runOneComponent(this, new Rectangle(0, 0, width, height), |
|
3029 |
g, g.getClip(), |
|
3030 |
GraphicsCallback.LIGHTWEIGHTS | |
|
3031 |
GraphicsCallback.HEAVYWEIGHTS); |
|
3032 |
} |
|
3033 |
} |
|
3034 |
||
3035 |
/** |
|
3036 |
* Simulates the peer callbacks into java.awt for painting of |
|
3037 |
* lightweight Components. |
|
3038 |
* @param g the graphics context to use for painting |
|
3039 |
* @see #paintAll |
|
3040 |
*/ |
|
3041 |
void lightweightPaint(Graphics g) { |
|
3042 |
paint(g); |
|
3043 |
} |
|
3044 |
||
3045 |
/** |
|
3046 |
* Paints all the heavyweight subcomponents. |
|
3047 |
*/ |
|
3048 |
void paintHeavyweightComponents(Graphics g) { |
|
3049 |
} |
|
3050 |
||
3051 |
/** |
|
3052 |
* Repaints this component. |
|
3053 |
* <p> |
|
3054 |
* If this component is a lightweight component, this method |
|
3055 |
* causes a call to this component's <code>paint</code> |
|
3056 |
* method as soon as possible. Otherwise, this method causes |
|
3057 |
* a call to this component's <code>update</code> method as soon |
|
3058 |
* as possible. |
|
3059 |
* <p> |
|
3060 |
* <b>Note</b>: For more information on the paint mechanisms utilitized |
|
3061 |
* by AWT and Swing, including information on how to write the most |
|
3062 |
* efficient painting code, see |
|
3063 |
* <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. |
|
3064 |
||
3065 |
* |
|
3066 |
* @see #update(Graphics) |
|
3067 |
* @since JDK1.0 |
|
3068 |
*/ |
|
3069 |
public void repaint() { |
|
3070 |
repaint(0, 0, 0, width, height); |
|
3071 |
} |
|
3072 |
||
3073 |
/** |
|
3074 |
* Repaints the component. If this component is a lightweight |
|
3075 |
* component, this results in a call to <code>paint</code> |
|
3076 |
* within <code>tm</code> milliseconds. |
|
3077 |
* <p> |
|
3078 |
* <b>Note</b>: For more information on the paint mechanisms utilitized |
|
3079 |
* by AWT and Swing, including information on how to write the most |
|
3080 |
* efficient painting code, see |
|
3081 |
* <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. |
|
3082 |
* |
|
3083 |
* @param tm maximum time in milliseconds before update |
|
3084 |
* @see #paint |
|
3085 |
* @see #update(Graphics) |
|
3086 |
* @since JDK1.0 |
|
3087 |
*/ |
|
3088 |
public void repaint(long tm) { |
|
3089 |
repaint(tm, 0, 0, width, height); |
|
3090 |
} |
|
3091 |
||
3092 |
/** |
|
3093 |
* Repaints the specified rectangle of this component. |
|
3094 |
* <p> |
|
3095 |
* If this component is a lightweight component, this method |
|
3096 |
* causes a call to this component's <code>paint</code> method |
|
3097 |
* as soon as possible. Otherwise, this method causes a call to |
|
3098 |
* this component's <code>update</code> method as soon as possible. |
|
3099 |
* <p> |
|
3100 |
* <b>Note</b>: For more information on the paint mechanisms utilitized |
|
3101 |
* by AWT and Swing, including information on how to write the most |
|
3102 |
* efficient painting code, see |
|
3103 |
* <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. |
|
3104 |
* |
|
3105 |
* @param x the <i>x</i> coordinate |
|
3106 |
* @param y the <i>y</i> coordinate |
|
3107 |
* @param width the width |
|
3108 |
* @param height the height |
|
3109 |
* @see #update(Graphics) |
|
3110 |
* @since JDK1.0 |
|
3111 |
*/ |
|
3112 |
public void repaint(int x, int y, int width, int height) { |
|
3113 |
repaint(0, x, y, width, height); |
|
3114 |
} |
|
3115 |
||
3116 |
/** |
|
3117 |
* Repaints the specified rectangle of this component within |
|
3118 |
* <code>tm</code> milliseconds. |
|
3119 |
* <p> |
|
3120 |
* If this component is a lightweight component, this method causes |
|
3121 |
* a call to this component's <code>paint</code> method. |
|
3122 |
* Otherwise, this method causes a call to this component's |
|
3123 |
* <code>update</code> method. |
|
3124 |
* <p> |
|
3125 |
* <b>Note</b>: For more information on the paint mechanisms utilitized |
|
3126 |
* by AWT and Swing, including information on how to write the most |
|
3127 |
* efficient painting code, see |
|
3128 |
* <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. |
|
3129 |
* |
|
3130 |
* @param tm maximum time in milliseconds before update |
|
3131 |
* @param x the <i>x</i> coordinate |
|
3132 |
* @param y the <i>y</i> coordinate |
|
3133 |
* @param width the width |
|
3134 |
* @param height the height |
|
3135 |
* @see #update(Graphics) |
|
3136 |
* @since JDK1.0 |
|
3137 |
*/ |
|
3138 |
public void repaint(long tm, int x, int y, int width, int height) { |
|
3139 |
if (this.peer instanceof LightweightPeer) { |
|
3140 |
// Needs to be translated to parent coordinates since |
|
3141 |
// a parent native container provides the actual repaint |
|
3142 |
// services. Additionally, the request is restricted to |
|
3143 |
// the bounds of the component. |
|
3144 |
if (parent != null) { |
|
634
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3145 |
if (x < 0) { |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3146 |
width += x; |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3147 |
x = 0; |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3148 |
} |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3149 |
if (y < 0) { |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3150 |
height += y; |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3151 |
y = 0; |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3152 |
} |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3153 |
|
2 | 3154 |
int pwidth = (width > this.width) ? this.width : width; |
3155 |
int pheight = (height > this.height) ? this.height : height; |
|
634
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3156 |
|
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3157 |
if (pwidth <= 0 || pheight <= 0) { |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3158 |
return; |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3159 |
} |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3160 |
|
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3161 |
int px = this.x + x; |
34d4a2d5b8cb
6644301: lightweight components can repaint outside request bounds
son
parents:
441
diff
changeset
|
3162 |
int py = this.y + y; |
2 | 3163 |
parent.repaint(tm, px, py, pwidth, pheight); |
3164 |
} |
|
3165 |
} else { |
|
3166 |
if (isVisible() && (this.peer != null) && |
|
3167 |
(width > 0) && (height > 0)) { |
|
3168 |
PaintEvent e = new PaintEvent(this, PaintEvent.UPDATE, |
|
3169 |
new Rectangle(x, y, width, height)); |
|
3170 |
Toolkit.getEventQueue().postEvent(e); |
|
3171 |
} |
|
3172 |
} |
|
3173 |
} |
|
3174 |
||
3175 |
/** |
|
3176 |
* Prints this component. Applications should override this method |
|
3177 |
* for components that must do special processing before being |
|
3178 |
* printed or should be printed differently than they are painted. |
|
3179 |
* <p> |
|
3180 |
* The default implementation of this method calls the |
|
3181 |
* <code>paint</code> method. |
|
3182 |
* <p> |
|
3183 |
* The origin of the graphics context, its |
|
3184 |
* (<code>0</code>, <code>0</code>) coordinate point, is the |
|
3185 |
* top-left corner of this component. The clipping region of the |
|
3186 |
* graphics context is the bounding rectangle of this component. |
|
3187 |
* @param g the graphics context to use for printing |
|
3188 |
* @see #paint(Graphics) |
|
3189 |
* @since JDK1.0 |
|
3190 |
*/ |
|
3191 |
public void print(Graphics g) { |
|
3192 |
paint(g); |
|
3193 |
} |
|
3194 |
||
3195 |
/** |
|
3196 |
* Prints this component and all of its subcomponents. |
|
3197 |
* <p> |
|
3198 |
* The origin of the graphics context, its |
|
3199 |
* (<code>0</code>, <code>0</code>) coordinate point, is the |
|
3200 |
* top-left corner of this component. The clipping region of the |
|
3201 |
* graphics context is the bounding rectangle of this component. |
|
3202 |
* @param g the graphics context to use for printing |
|
3203 |
* @see #print(Graphics) |
|
3204 |
* @since JDK1.0 |
|
3205 |
*/ |
|
3206 |
public void printAll(Graphics g) { |
|
3207 |
if (isShowing()) { |
|
3208 |
GraphicsCallback.PeerPrintCallback.getInstance(). |
|
3209 |
runOneComponent(this, new Rectangle(0, 0, width, height), |
|
3210 |
g, g.getClip(), |
|
3211 |
GraphicsCallback.LIGHTWEIGHTS | |
|
3212 |
GraphicsCallback.HEAVYWEIGHTS); |
|
3213 |
} |
|
3214 |
} |
|
3215 |
||
3216 |
/** |
|
3217 |
* Simulates the peer callbacks into java.awt for printing of |
|
3218 |
* lightweight Components. |
|
3219 |
* @param g the graphics context to use for printing |
|
3220 |
* @see #printAll |
|
3221 |
*/ |
|
3222 |
void lightweightPrint(Graphics g) { |
|
3223 |
print(g); |
|
3224 |
} |
|
3225 |
||
3226 |
/** |
|
3227 |
* Prints all the heavyweight subcomponents. |
|
3228 |
*/ |
|
3229 |
void printHeavyweightComponents(Graphics g) { |
|
3230 |
} |
|
3231 |
||
3232 |
private Insets getInsets_NoClientCode() { |
|
3233 |
ComponentPeer peer = this.peer; |
|
3234 |
if (peer instanceof ContainerPeer) { |
|
1964 | 3235 |
return (Insets)((ContainerPeer)peer).getInsets().clone(); |
2 | 3236 |
} |
3237 |
return new Insets(0, 0, 0, 0); |
|
3238 |
} |
|
3239 |
||
3240 |
/** |
|
3241 |
* Repaints the component when the image has changed. |
|
3242 |
* This <code>imageUpdate</code> method of an <code>ImageObserver</code> |
|
3243 |
* is called when more information about an |
|
3244 |
* image which had been previously requested using an asynchronous |
|
3245 |
* routine such as the <code>drawImage</code> method of |
|
3246 |
* <code>Graphics</code> becomes available. |
|
3247 |
* See the definition of <code>imageUpdate</code> for |
|
3248 |
* more information on this method and its arguments. |
|
3249 |
* <p> |
|
3250 |
* The <code>imageUpdate</code> method of <code>Component</code> |
|
3251 |
* incrementally draws an image on the component as more of the bits |
|
3252 |
* of the image are available. |
|
3253 |
* <p> |
|
3254 |
* If the system property <code>awt.image.incrementaldraw</code> |
|
3255 |
* is missing or has the value <code>true</code>, the image is |
|
3256 |
* incrementally drawn. If the system property has any other value, |
|
3257 |
* then the image is not drawn until it has been completely loaded. |
|
3258 |
* <p> |
|
3259 |
* Also, if incremental drawing is in effect, the value of the |
|
3260 |
* system property <code>awt.image.redrawrate</code> is interpreted |
|
3261 |
* as an integer to give the maximum redraw rate, in milliseconds. If |
|
3262 |
* the system property is missing or cannot be interpreted as an |
|
3263 |
* integer, the redraw rate is once every 100ms. |
|
3264 |
* <p> |
|
3265 |
* The interpretation of the <code>x</code>, <code>y</code>, |
|
3266 |
* <code>width</code>, and <code>height</code> arguments depends on |
|
3267 |
* the value of the <code>infoflags</code> argument. |
|
3268 |
* |
|
3269 |
* @param img the image being observed |
|
3270 |
* @param infoflags see <code>imageUpdate</code> for more information |
|
3271 |
* @param x the <i>x</i> coordinate |
|
3272 |
* @param y the <i>y</i> coordinate |
|
3273 |
* @param w the width |
|
3274 |
* @param h the height |
|
3275 |
* @return <code>false</code> if the infoflags indicate that the |
|
3276 |
* image is completely loaded; <code>true</code> otherwise. |
|
3277 |
* |
|
3278 |
* @see java.awt.image.ImageObserver |
|
3279 |
* @see Graphics#drawImage(Image, int, int, Color, java.awt.image.ImageObserver) |
|
3280 |
* @see Graphics#drawImage(Image, int, int, java.awt.image.ImageObserver) |
|
3281 |
* @see Graphics#drawImage(Image, int, int, int, int, Color, java.awt.image.ImageObserver) |
|
3282 |
* @see Graphics#drawImage(Image, int, int, int, int, java.awt.image.ImageObserver) |
|
3283 |
* @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) |
|
3284 |
* @since JDK1.0 |
|
3285 |
*/ |
|
3286 |
public boolean imageUpdate(Image img, int infoflags, |
|
3287 |
int x, int y, int w, int h) { |
|
3288 |
int rate = -1; |
|
3289 |
if ((infoflags & (FRAMEBITS|ALLBITS)) != 0) { |
|
3290 |
rate = 0; |
|
3291 |
} else if ((infoflags & SOMEBITS) != 0) { |
|
3292 |
if (isInc) { |
|
3293 |
rate = incRate; |
|
3294 |
if (rate < 0) { |
|
3295 |
rate = 0; |
|
3296 |
} |
|
3297 |
} |
|
3298 |
} |
|
3299 |
if (rate >= 0) { |
|
3300 |
repaint(rate, 0, 0, width, height); |
|
3301 |
} |
|
3302 |
return (infoflags & (ALLBITS|ABORT)) == 0; |
|
3303 |
} |
|
3304 |
||
3305 |
/** |
|
3306 |
* Creates an image from the specified image producer. |
|
3307 |
* @param producer the image producer |
|
3308 |
* @return the image produced |
|
3309 |
* @since JDK1.0 |
|
3310 |
*/ |
|
3311 |
public Image createImage(ImageProducer producer) { |
|
3312 |
ComponentPeer peer = this.peer; |
|
3313 |
if ((peer != null) && ! (peer instanceof LightweightPeer)) { |
|
3314 |
return peer.createImage(producer); |
|
3315 |
} |
|
3316 |
return getToolkit().createImage(producer); |
|
3317 |
} |
|
3318 |
||
3319 |
/** |
|
3320 |
* Creates an off-screen drawable image |
|
3321 |
* to be used for double buffering. |
|
3322 |
* @param width the specified width |
|
3323 |
* @param height the specified height |
|
3324 |
* @return an off-screen drawable image, which can be used for double |
|
3325 |
* buffering. The return value may be <code>null</code> if the |
|
3326 |
* component is not displayable. This will always happen if |
|
3327 |
* <code>GraphicsEnvironment.isHeadless()</code> returns |
|
3328 |
* <code>true</code>. |
|
3329 |
* @see #isDisplayable |
|
3330 |
* @see GraphicsEnvironment#isHeadless |
|
3331 |
* @since JDK1.0 |
|
3332 |
*/ |
|
3333 |
public Image createImage(int width, int height) { |
|
3334 |
ComponentPeer peer = this.peer; |
|
3335 |
if (peer instanceof LightweightPeer) { |
|
3336 |
if (parent != null) { return parent.createImage(width, height); } |
|
3337 |
else { return null;} |
|
3338 |
} else { |
|
3339 |
return (peer != null) ? peer.createImage(width, height) : null; |
|
3340 |
} |
|
3341 |
} |
|
3342 |
||
3343 |
/** |
|
3344 |
* Creates a volatile off-screen drawable image |
|
3345 |
* to be used for double buffering. |
|
3346 |
* @param width the specified width. |
|
3347 |
* @param height the specified height. |
|
3348 |
* @return an off-screen drawable image, which can be used for double |
|
3349 |
* buffering. The return value may be <code>null</code> if the |
|
3350 |
* component is not displayable. This will always happen if |
|
3351 |
* <code>GraphicsEnvironment.isHeadless()</code> returns |
|
3352 |
* <code>true</code>. |
|
3353 |
* @see java.awt.image.VolatileImage |
|
3354 |
* @see #isDisplayable |
|
3355 |
* @see GraphicsEnvironment#isHeadless |
|
3356 |
* @since 1.4 |
|
3357 |
*/ |
|
3358 |
public VolatileImage createVolatileImage(int width, int height) { |
|
3359 |
ComponentPeer peer = this.peer; |
|
3360 |
if (peer instanceof LightweightPeer) { |
|
3361 |
if (parent != null) { |
|
3362 |
return parent.createVolatileImage(width, height); |
|
3363 |
} |
|
3364 |
else { return null;} |
|
3365 |
} else { |
|
3366 |
return (peer != null) ? |
|
3367 |
peer.createVolatileImage(width, height) : null; |
|
3368 |
} |
|
3369 |
} |
|
3370 |
||
3371 |
/** |
|
3372 |
* Creates a volatile off-screen drawable image, with the given capabilities. |
|
3373 |
* The contents of this image may be lost at any time due |
|
3374 |
* to operating system issues, so the image must be managed |
|
3375 |
* via the <code>VolatileImage</code> interface. |
|
3376 |
* @param width the specified width. |
|
3377 |
* @param height the specified height. |
|
3378 |
* @param caps the image capabilities |
|
3379 |
* @exception AWTException if an image with the specified capabilities cannot |
|
3380 |
* be created |
|
3381 |
* @return a VolatileImage object, which can be used |
|
3382 |
* to manage surface contents loss and capabilities. |
|
3383 |
* @see java.awt.image.VolatileImage |
|
3384 |
* @since 1.4 |
|
3385 |
*/ |
|
3386 |
public VolatileImage createVolatileImage(int width, int height, |
|
3387 |
ImageCapabilities caps) throws AWTException { |
|
3388 |
// REMIND : check caps |
|
3389 |
return createVolatileImage(width, height); |
|
3390 |
} |
|
3391 |
||
3392 |
/** |
|
3393 |
* Prepares an image for rendering on this component. The image |
|
3394 |
* data is downloaded asynchronously in another thread and the |
|
3395 |
* appropriate screen representation of the image is generated. |
|
3396 |
* @param image the <code>Image</code> for which to |
|
3397 |
* prepare a screen representation |
|
3398 |
* @param observer the <code>ImageObserver</code> object |
|
3399 |
* to be notified as the image is being prepared |
|
3400 |
* @return <code>true</code> if the image has already been fully |
|
3401 |
* prepared; <code>false</code> otherwise |
|
3402 |
* @since JDK1.0 |
|
3403 |
*/ |
|
3404 |
public boolean prepareImage(Image image, ImageObserver observer) { |
|
3405 |
return prepareImage(image, -1, -1, observer); |
|
3406 |
} |
|
3407 |
||
3408 |
/** |
|
3409 |
* Prepares an image for rendering on this component at the |
|
3410 |
* specified width and height. |
|
3411 |
* <p> |
|
3412 |
* The image data is downloaded asynchronously in another thread, |
|
3413 |
* and an appropriately scaled screen representation of the image is |
|
3414 |
* generated. |
|
3415 |
* @param image the instance of <code>Image</code> |
|
3416 |
* for which to prepare a screen representation |
|
3417 |
* @param width the width of the desired screen representation |
|
3418 |
* @param height the height of the desired screen representation |
|
3419 |
* @param observer the <code>ImageObserver</code> object |
|
3420 |
* to be notified as the image is being prepared |
|
3421 |
* @return <code>true</code> if the image has already been fully |
|
3422 |
* prepared; <code>false</code> otherwise |
|
3423 |
* @see java.awt.image.ImageObserver |
|
3424 |
* @since JDK1.0 |
|
3425 |
*/ |
|
3426 |
public boolean prepareImage(Image image, int width, int height, |
|
3427 |
ImageObserver observer) { |
|
3428 |
ComponentPeer peer = this.peer; |
|
3429 |
if (peer instanceof LightweightPeer) { |
|
3430 |
return (parent != null) |
|
3431 |
? parent.prepareImage(image, width, height, observer) |
|
3432 |
: getToolkit().prepareImage(image, width, height, observer); |
|
3433 |
} else { |
|
3434 |
return (peer != null) |
|
3435 |
? peer.prepareImage(image, width, height, observer) |
|
3436 |
: getToolkit().prepareImage(image, width, height, observer); |
|
3437 |
} |
|
3438 |
} |
|
3439 |
||
3440 |
/** |
|
3441 |
* Returns the status of the construction of a screen representation |
|
3442 |
* of the specified image. |
|
3443 |
* <p> |
|
3444 |
* This method does not cause the image to begin loading. An |
|
3445 |
* application must use the <code>prepareImage</code> method |
|
3446 |
* to force the loading of an image. |
|
3447 |
* <p> |
|
3448 |
* Information on the flags returned by this method can be found |
|
3449 |
* with the discussion of the <code>ImageObserver</code> interface. |
|
3450 |
* @param image the <code>Image</code> object whose status |
|
3451 |
* is being checked |
|
3452 |
* @param observer the <code>ImageObserver</code> |
|
3453 |
* object to be notified as the image is being prepared |
|
3454 |
* @return the bitwise inclusive <b>OR</b> of |
|
3455 |
* <code>ImageObserver</code> flags indicating what |
|
3456 |
* information about the image is currently available |
|
3457 |
* @see #prepareImage(Image, int, int, java.awt.image.ImageObserver) |
|
3458 |
* @see Toolkit#checkImage(Image, int, int, java.awt.image.ImageObserver) |
|
3459 |
* @see java.awt.image.ImageObserver |
|
3460 |
* @since JDK1.0 |
|
3461 |
*/ |
|
3462 |
public int checkImage(Image image, ImageObserver observer) { |
|
3463 |
return checkImage(image, -1, -1, observer); |
|
3464 |
} |
|
3465 |
||
3466 |
/** |
|
3467 |
* Returns the status of the construction of a screen representation |
|
3468 |
* of the specified image. |
|
3469 |
* <p> |
|
3470 |
* This method does not cause the image to begin loading. An |
|
3471 |
* application must use the <code>prepareImage</code> method |
|
3472 |
* to force the loading of an image. |
|
3473 |
* <p> |
|
3474 |
* The <code>checkImage</code> method of <code>Component</code> |
|
3475 |
* calls its peer's <code>checkImage</code> method to calculate |
|
3476 |
* the flags. If this component does not yet have a peer, the |
|
3477 |
* component's toolkit's <code>checkImage</code> method is called |
|
3478 |
* instead. |
|
3479 |
* <p> |
|
3480 |
* Information on the flags returned by this method can be found |
|
3481 |
* with the discussion of the <code>ImageObserver</code> interface. |
|
3482 |
* @param image the <code>Image</code> object whose status |
|
3483 |
* is being checked |
|
3484 |
* @param width the width of the scaled version |
|
3485 |
* whose status is to be checked |
|
3486 |
* @param height the height of the scaled version |
|
3487 |
* whose status is to be checked |
|
3488 |
* @param observer the <code>ImageObserver</code> object |
|
3489 |
* to be notified as the image is being prepared |
|
3490 |
* @return the bitwise inclusive <b>OR</b> of |
|
3491 |
* <code>ImageObserver</code> flags indicating what |
|
3492 |
* information about the image is currently available |
|
3493 |
* @see #prepareImage(Image, int, int, java.awt.image.ImageObserver) |
|
3494 |
* @see Toolkit#checkImage(Image, int, int, java.awt.image.ImageObserver) |
|
3495 |
* @see java.awt.image.ImageObserver |
|
3496 |
* @since JDK1.0 |
|
3497 |
*/ |
|
3498 |
public int checkImage(Image image, int width, int height, |
|
3499 |
ImageObserver observer) { |
|
3500 |
ComponentPeer peer = this.peer; |
|
3501 |
if (peer instanceof LightweightPeer) { |
|
3502 |
return (parent != null) |
|
3503 |
? parent.checkImage(image, width, height, observer) |
|
3504 |
: getToolkit().checkImage(image, width, height, observer); |
|
3505 |
} else { |
|
3506 |
return (peer != null) |
|
3507 |
? peer.checkImage(image, width, height, observer) |
|
3508 |
: getToolkit().checkImage(image, width, height, observer); |
|
3509 |
} |
|
3510 |
} |
|
3511 |
||
3512 |
/** |
|
3513 |
* Creates a new strategy for multi-buffering on this component. |
|
3514 |
* Multi-buffering is useful for rendering performance. This method |
|
3515 |
* attempts to create the best strategy available with the number of |
|
3516 |
* buffers supplied. It will always create a <code>BufferStrategy</code> |
|
3517 |
* with that number of buffers. |
|
3518 |
* A page-flipping strategy is attempted first, then a blitting strategy |
|
3519 |
* using accelerated buffers. Finally, an unaccelerated blitting |
|
3520 |
* strategy is used. |
|
3521 |
* <p> |
|
3522 |
* Each time this method is called, |
|
3523 |
* the existing buffer strategy for this component is discarded. |
|
3524 |
* @param numBuffers number of buffers to create, including the front buffer |
|
3525 |
* @exception IllegalArgumentException if numBuffers is less than 1. |
|
3526 |
* @exception IllegalStateException if the component is not displayable |
|
3527 |
* @see #isDisplayable |
|
3528 |
* @see Window#getBufferStrategy() |
|
3529 |
* @see Canvas#getBufferStrategy() |
|
3530 |
* @since 1.4 |
|
3531 |
*/ |
|
3532 |
void createBufferStrategy(int numBuffers) { |
|
3533 |
BufferCapabilities bufferCaps; |
|
3534 |
if (numBuffers > 1) { |
|
3535 |
// Try to create a page-flipping strategy |
|
3536 |
bufferCaps = new BufferCapabilities(new ImageCapabilities(true), |
|
3537 |
new ImageCapabilities(true), |
|
3538 |
BufferCapabilities.FlipContents.UNDEFINED); |
|
3539 |
try { |
|
3540 |
createBufferStrategy(numBuffers, bufferCaps); |
|
3541 |
return; // Success |
|
3542 |
} catch (AWTException e) { |
|
3543 |
// Failed |
|
3544 |
} |
|
3545 |
} |
|
3546 |
// Try a blitting (but still accelerated) strategy |
|
3547 |
bufferCaps = new BufferCapabilities(new ImageCapabilities(true), |
|
3548 |
new ImageCapabilities(true), |
|
3549 |
null); |
|
3550 |
try { |
|
3551 |
createBufferStrategy(numBuffers, bufferCaps); |
|
3552 |
return; // Success |
|
3553 |
} catch (AWTException e) { |
|
3554 |
// Failed |
|
3555 |
} |
|
3556 |
// Try an unaccelerated blitting strategy |
|
3557 |
bufferCaps = new BufferCapabilities(new ImageCapabilities(false), |
|
3558 |
new ImageCapabilities(false), |
|
3559 |
null); |
|
3560 |
try { |
|
3561 |
createBufferStrategy(numBuffers, bufferCaps); |
|
3562 |
return; // Success |
|
3563 |
} catch (AWTException e) { |
|
3564 |
// Failed |
|
3565 |
} |
|
3566 |
// Code should never reach here (an unaccelerated blitting |
|
3567 |
// strategy should always work) |
|
3568 |
throw new InternalError("Could not create a buffer strategy"); |
|
3569 |
} |
|
3570 |
||
3571 |
/** |
|
3572 |
* Creates a new strategy for multi-buffering on this component with the |
|
3573 |
* required buffer capabilities. This is useful, for example, if only |
|
3574 |
* accelerated memory or page flipping is desired (as specified by the |
|
3575 |
* buffer capabilities). |
|
3576 |
* <p> |
|
3577 |
* Each time this method |
|
3578 |
* is called, <code>dispose</code> will be invoked on the existing |
|
3579 |
* <code>BufferStrategy</code>. |
|
3580 |
* @param numBuffers number of buffers to create |
|
3581 |
* @param caps the required capabilities for creating the buffer strategy; |
|
3582 |
* cannot be <code>null</code> |
|
3583 |
* @exception AWTException if the capabilities supplied could not be |
|
3584 |
* supported or met; this may happen, for example, if there is not enough |
|
3585 |
* accelerated memory currently available, or if page flipping is specified |
|
3586 |
* but not possible. |
|
3587 |
* @exception IllegalArgumentException if numBuffers is less than 1, or if |
|
3588 |
* caps is <code>null</code> |
|
3589 |
* @see Window#getBufferStrategy() |
|
3590 |
* @see Canvas#getBufferStrategy() |
|
3591 |
* @since 1.4 |
|
3592 |
*/ |
|
3593 |
void createBufferStrategy(int numBuffers, |
|
3594 |
BufferCapabilities caps) throws AWTException { |
|
3595 |
// Check arguments |
|
3596 |
if (numBuffers < 1) { |
|
3597 |
throw new IllegalArgumentException( |
|
3598 |
"Number of buffers must be at least 1"); |
|
3599 |
} |
|
3600 |
if (caps == null) { |
|
3601 |
throw new IllegalArgumentException("No capabilities specified"); |
|
3602 |
} |
|
3603 |
// Destroy old buffers |
|
3604 |
if (bufferStrategy != null) { |
|
3605 |
bufferStrategy.dispose(); |
|
3606 |
} |
|
3607 |
if (numBuffers == 1) { |
|
3608 |
bufferStrategy = new SingleBufferStrategy(caps); |
|
3609 |
} else { |
|
887 | 3610 |
SunGraphicsEnvironment sge = (SunGraphicsEnvironment) |
3611 |
GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
3612 |
if (!caps.isPageFlipping() && sge.isFlipStrategyPreferred(peer)) { |
|
3613 |
caps = new ProxyCapabilities(caps); |
|
3614 |
} |
|
2 | 3615 |
// assert numBuffers > 1; |
3616 |
if (caps.isPageFlipping()) { |
|
3617 |
bufferStrategy = new FlipSubRegionBufferStrategy(numBuffers, caps); |
|
3618 |
} else { |
|
3619 |
bufferStrategy = new BltSubRegionBufferStrategy(numBuffers, caps); |
|
3620 |
} |
|
3621 |
} |
|
3622 |
} |
|
3623 |
||
3624 |
/** |
|
887 | 3625 |
* This is a proxy capabilities class used when a FlipBufferStrategy |
3626 |
* is created instead of the requested Blit strategy. |
|
3627 |
* |
|
3628 |
* @see sun.awt.SunGraphicsEnvironment#isFlipStrategyPreferred(ComponentPeer) |
|
3629 |
*/ |
|
3630 |
private class ProxyCapabilities extends ExtendedBufferCapabilities { |
|
3631 |
private BufferCapabilities orig; |
|
3632 |
private ProxyCapabilities(BufferCapabilities orig) { |
|
3633 |
super(orig.getFrontBufferCapabilities(), |
|
3634 |
orig.getBackBufferCapabilities(), |
|
3635 |
orig.getFlipContents() == |
|
3636 |
BufferCapabilities.FlipContents.BACKGROUND ? |
|
3637 |
BufferCapabilities.FlipContents.BACKGROUND : |
|
3638 |
BufferCapabilities.FlipContents.COPIED); |
|
3639 |
this.orig = orig; |
|
3640 |
} |
|
3641 |
} |
|
3642 |
||
3643 |
/** |
|
2 | 3644 |
* @return the buffer strategy used by this component |
3645 |
* @see Window#createBufferStrategy |
|
3646 |
* @see Canvas#createBufferStrategy |
|
3647 |
* @since 1.4 |
|
3648 |
*/ |
|
3649 |
BufferStrategy getBufferStrategy() { |
|
3650 |
return bufferStrategy; |
|
3651 |
} |
|
3652 |
||
3653 |
/** |
|
3654 |
* @return the back buffer currently used by this component's |
|
3655 |
* BufferStrategy. If there is no BufferStrategy or no |
|
3656 |
* back buffer, this method returns null. |
|
3657 |
*/ |
|
3658 |
Image getBackBuffer() { |
|
3659 |
if (bufferStrategy != null) { |
|
3660 |
if (bufferStrategy instanceof BltBufferStrategy) { |
|
3661 |
BltBufferStrategy bltBS = (BltBufferStrategy)bufferStrategy; |
|
3662 |
return bltBS.getBackBuffer(); |
|
3663 |
} else if (bufferStrategy instanceof FlipBufferStrategy) { |
|
3664 |
FlipBufferStrategy flipBS = (FlipBufferStrategy)bufferStrategy; |
|
3665 |
return flipBS.getBackBuffer(); |
|
3666 |
} |
|
3667 |
} |
|
3668 |
return null; |
|
3669 |
} |
|
3670 |
||
3671 |
/** |
|
3672 |
* Inner class for flipping buffers on a component. That component must |
|
3673 |
* be a <code>Canvas</code> or <code>Window</code>. |
|
3674 |
* @see Canvas |
|
3675 |
* @see Window |
|
3676 |
* @see java.awt.image.BufferStrategy |
|
3677 |
* @author Michael Martak |
|
3678 |
* @since 1.4 |
|
3679 |
*/ |
|
3680 |
protected class FlipBufferStrategy extends BufferStrategy { |
|
3681 |
/** |
|
3682 |
* The number of buffers |
|
3683 |
*/ |
|
3684 |
protected int numBuffers; // = 0 |
|
3685 |
/** |
|
3686 |
* The buffering capabilities |
|
3687 |
*/ |
|
3688 |
protected BufferCapabilities caps; // = null |
|
3689 |
/** |
|
3690 |
* The drawing buffer |
|
3691 |
*/ |
|
3692 |
protected Image drawBuffer; // = null |
|
3693 |
/** |
|
3694 |
* The drawing buffer as a volatile image |
|
3695 |
*/ |
|
3696 |
protected VolatileImage drawVBuffer; // = null |
|
3697 |
/** |
|
3698 |
* Whether or not the drawing buffer has been recently restored from |
|
3699 |
* a lost state. |
|
3700 |
*/ |
|
3701 |
protected boolean validatedContents; // = false |
|
3702 |
/** |
|
3703 |
* Size of the back buffers. (Note: these fields were added in 6.0 |
|
3704 |
* but kept package-private to avoid exposing them in the spec. |
|
3705 |
* None of these fields/methods really should have been marked |
|
3706 |
* protected when they were introduced in 1.4, but now we just have |
|
3707 |
* to live with that decision.) |
|
3708 |
*/ |
|
3709 |
int width; |
|
3710 |
int height; |
|
3711 |
||
3712 |
/** |
|
3713 |
* Creates a new flipping buffer strategy for this component. |
|
3714 |
* The component must be a <code>Canvas</code> or <code>Window</code>. |
|
3715 |
* @see Canvas |
|
3716 |
* @see Window |
|
3717 |
* @param numBuffers the number of buffers |
|
3718 |
* @param caps the capabilities of the buffers |
|
3719 |
* @exception AWTException if the capabilities supplied could not be |
|
3720 |
* supported or met |
|
3721 |
* @exception ClassCastException if the component is not a canvas or |
|
3722 |
* window. |
|
3723 |
*/ |
|
3724 |
protected FlipBufferStrategy(int numBuffers, BufferCapabilities caps) |
|
3725 |
throws AWTException |
|
3726 |
{ |
|
3727 |
if (!(Component.this instanceof Window) && |
|
3728 |
!(Component.this instanceof Canvas)) |
|
3729 |
{ |
|
3730 |
throw new ClassCastException( |
|
3731 |
"Component must be a Canvas or Window"); |
|
3732 |
} |
|
3733 |
this.numBuffers = numBuffers; |
|
3734 |
this.caps = caps; |
|
3735 |
createBuffers(numBuffers, caps); |
|
3736 |
} |
|
3737 |
||
3738 |
/** |
|
3739 |
* Creates one or more complex, flipping buffers with the given |
|
3740 |
* capabilities. |
|
3741 |
* @param numBuffers number of buffers to create; must be greater than |
|
3742 |
* one |
|
3743 |
* @param caps the capabilities of the buffers. |
|
3744 |
* <code>BufferCapabilities.isPageFlipping</code> must be |
|
3745 |
* <code>true</code>. |
|
3746 |
* @exception AWTException if the capabilities supplied could not be |
|
3747 |
* supported or met |
|
3748 |
* @exception IllegalStateException if the component has no peer |
|
3749 |
* @exception IllegalArgumentException if numBuffers is less than two, |
|
3750 |
* or if <code>BufferCapabilities.isPageFlipping</code> is not |
|
3751 |
* <code>true</code>. |
|
3752 |
* @see java.awt.BufferCapabilities#isPageFlipping() |
|
3753 |
*/ |
|
3754 |
protected void createBuffers(int numBuffers, BufferCapabilities caps) |
|
3755 |
throws AWTException |
|
3756 |
{ |
|
3757 |
if (numBuffers < 2) { |
|
3758 |
throw new IllegalArgumentException( |
|
3759 |
"Number of buffers cannot be less than two"); |
|
3760 |
} else if (peer == null) { |
|
3761 |
throw new IllegalStateException( |
|
3762 |
"Component must have a valid peer"); |
|
3763 |
} else if (caps == null || !caps.isPageFlipping()) { |
|
3764 |
throw new IllegalArgumentException( |
|
3765 |
"Page flipping capabilities must be specified"); |
|
3766 |
} |
|
3767 |
||
3768 |
// save the current bounds |
|
3769 |
width = getWidth(); |
|
3770 |
height = getHeight(); |
|
3771 |
||
887 | 3772 |
if (drawBuffer != null) { |
2 | 3773 |
// dispose the existing backbuffers |
3774 |
drawBuffer = null; |
|
3775 |
drawVBuffer = null; |
|
3776 |
destroyBuffers(); |
|
3777 |
// ... then recreate the backbuffers |
|
887 | 3778 |
} |
3779 |
||
3780 |
if (caps instanceof ExtendedBufferCapabilities) { |
|
3781 |
ExtendedBufferCapabilities ebc = |
|
3782 |
(ExtendedBufferCapabilities)caps; |
|
3783 |
if (ebc.getVSync() == VSYNC_ON) { |
|
3784 |
// if this buffer strategy is not allowed to be v-synced, |
|
3785 |
// change the caps that we pass to the peer but keep on |
|
3786 |
// trying to create v-synced buffers; |
|
3787 |
// do not throw IAE here in case it is disallowed, see |
|
3788 |
// ExtendedBufferCapabilities for more info |
|
3789 |
if (!VSyncedBSManager.vsyncAllowed(this)) { |
|
3790 |
caps = ebc.derive(VSYNC_DEFAULT); |
|
3791 |
} |
|
3792 |
} |
|
3793 |
} |
|
3794 |
||
3795 |
peer.createBuffers(numBuffers, caps); |
|
2 | 3796 |
updateInternalBuffers(); |
3797 |
} |
|
3798 |
||
3799 |
/** |
|
3800 |
* Updates internal buffers (both volatile and non-volatile) |
|
3801 |
* by requesting the back-buffer from the peer. |
|
3802 |
*/ |
|
3803 |
private void updateInternalBuffers() { |
|
3804 |
// get the images associated with the draw buffer |
|
3805 |
drawBuffer = getBackBuffer(); |
|
3806 |
if (drawBuffer instanceof VolatileImage) { |
|
3807 |
drawVBuffer = (VolatileImage)drawBuffer; |
|
3808 |
} else { |
|
3809 |
drawVBuffer = null; |
|
3810 |
} |
|
3811 |
} |
|
3812 |
||
3813 |
/** |
|
3814 |
* @return direct access to the back buffer, as an image. |
|
3815 |
* @exception IllegalStateException if the buffers have not yet |
|
3816 |
* been created |
|
3817 |
*/ |
|
3818 |
protected Image getBackBuffer() { |
|
3819 |
if (peer != null) { |
|
3820 |
return peer.getBackBuffer(); |
|
3821 |
} else { |
|
3822 |
throw new IllegalStateException( |
|
3823 |
"Component must have a valid peer"); |
|
3824 |
} |
|
3825 |
} |
|
3826 |
||
3827 |
/** |
|
3828 |
* Flipping moves the contents of the back buffer to the front buffer, |
|
3829 |
* either by copying or by moving the video pointer. |
|
3830 |
* @param flipAction an integer value describing the flipping action |
|
3831 |
* for the contents of the back buffer. This should be one of the |
|
3832 |
* values of the <code>BufferCapabilities.FlipContents</code> |
|
3833 |
* property. |
|
3834 |
* @exception IllegalStateException if the buffers have not yet |
|
3835 |
* been created |
|
3836 |
* @see java.awt.BufferCapabilities#getFlipContents() |
|
3837 |
*/ |
|
3838 |
protected void flip(BufferCapabilities.FlipContents flipAction) { |
|
3839 |
if (peer != null) { |
|
887 | 3840 |
Image backBuffer = getBackBuffer(); |
3841 |
if (backBuffer != null) { |
|
3842 |
peer.flip(0, 0, |
|
3843 |
backBuffer.getWidth(null), |
|
3844 |
backBuffer.getHeight(null), flipAction); |
|
3845 |
} |
|
3846 |
} else { |
|
3847 |
throw new IllegalStateException( |
|
3848 |
"Component must have a valid peer"); |
|
3849 |
} |
|
3850 |
} |
|
3851 |
||
3852 |
void flipSubRegion(int x1, int y1, int x2, int y2, |
|
3853 |
BufferCapabilities.FlipContents flipAction) |
|
3854 |
{ |
|
3855 |
if (peer != null) { |
|
3856 |
peer.flip(x1, y1, x2, y2, flipAction); |
|
2 | 3857 |
} else { |
3858 |
throw new IllegalStateException( |
|
3859 |
"Component must have a valid peer"); |
|
3860 |
} |
|
3861 |
} |
|
3862 |
||
3863 |
/** |
|
3864 |
* Destroys the buffers created through this object |
|
3865 |
*/ |
|
3866 |
protected void destroyBuffers() { |
|
887 | 3867 |
VSyncedBSManager.releaseVsync(this); |
2 | 3868 |
if (peer != null) { |
3869 |
peer.destroyBuffers(); |
|
3870 |
} else { |
|
3871 |
throw new IllegalStateException( |
|
3872 |
"Component must have a valid peer"); |
|
3873 |
} |
|
3874 |
} |
|
3875 |
||
3876 |
/** |
|
3877 |
* @return the buffering capabilities of this strategy |
|
3878 |
*/ |
|
3879 |
public BufferCapabilities getCapabilities() { |
|
887 | 3880 |
if (caps instanceof ProxyCapabilities) { |
3881 |
return ((ProxyCapabilities)caps).orig; |
|
3882 |
} else { |
|
3883 |
return caps; |
|
3884 |
} |
|
2 | 3885 |
} |
3886 |
||
3887 |
/** |
|
3888 |
* @return the graphics on the drawing buffer. This method may not |
|
3889 |
* be synchronized for performance reasons; use of this method by multiple |
|
3890 |
* threads should be handled at the application level. Disposal of the |
|
3891 |
* graphics object must be handled by the application. |
|
3892 |
*/ |
|
3893 |
public Graphics getDrawGraphics() { |
|
3894 |
revalidate(); |
|
3895 |
return drawBuffer.getGraphics(); |
|
3896 |
} |
|
3897 |
||
3898 |
/** |
|
3899 |
* Restore the drawing buffer if it has been lost |
|
3900 |
*/ |
|
3901 |
protected void revalidate() { |
|
3902 |
revalidate(true); |
|
3903 |
} |
|
3904 |
||
3905 |
void revalidate(boolean checkSize) { |
|
3906 |
validatedContents = false; |
|
3907 |
||
3908 |
if (checkSize && (getWidth() != width || getHeight() != height)) { |
|
3909 |
// component has been resized; recreate the backbuffers |
|
3910 |
try { |
|
3911 |
createBuffers(numBuffers, caps); |
|
3912 |
} catch (AWTException e) { |
|
3913 |
// shouldn't be possible |
|
3914 |
} |
|
3915 |
validatedContents = true; |
|
3916 |
} |
|
3917 |
||
3918 |
// get the buffers from the peer every time since they |
|
3919 |
// might have been replaced in response to a display change event |
|
3920 |
updateInternalBuffers(); |
|
3921 |
||
3922 |
// now validate the backbuffer |
|
3923 |
if (drawVBuffer != null) { |
|
3924 |
GraphicsConfiguration gc = |
|
3925 |
getGraphicsConfiguration_NoClientCode(); |
|
3926 |
int returnCode = drawVBuffer.validate(gc); |
|
3927 |
if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) { |
|
3928 |
try { |
|
3929 |
createBuffers(numBuffers, caps); |
|
3930 |
} catch (AWTException e) { |
|
3931 |
// shouldn't be possible |
|
3932 |
} |
|
3933 |
if (drawVBuffer != null) { |
|
3934 |
// backbuffers were recreated, so validate again |
|
3935 |
drawVBuffer.validate(gc); |
|
3936 |
} |
|
3937 |
validatedContents = true; |
|
3938 |
} else if (returnCode == VolatileImage.IMAGE_RESTORED) { |
|
3939 |
validatedContents = true; |
|
3940 |
} |
|
3941 |
} |
|
3942 |
} |
|
3943 |
||
3944 |
/** |
|
3945 |
* @return whether the drawing buffer was lost since the last call to |
|
3946 |
* <code>getDrawGraphics</code> |
|
3947 |
*/ |
|
3948 |
public boolean contentsLost() { |
|
3949 |
if (drawVBuffer == null) { |
|
3950 |
return false; |
|
3951 |
} |
|
3952 |
return drawVBuffer.contentsLost(); |
|
3953 |
} |
|
3954 |
||
3955 |
/** |
|
3956 |
* @return whether the drawing buffer was recently restored from a lost |
|
3957 |
* state and reinitialized to the default background color (white) |
|
3958 |
*/ |
|
3959 |
public boolean contentsRestored() { |
|
3960 |
return validatedContents; |
|
3961 |
} |
|
3962 |
||
3963 |
/** |
|
3964 |
* Makes the next available buffer visible by either blitting or |
|
3965 |
* flipping. |
|
3966 |
*/ |
|
3967 |
public void show() { |
|
3968 |
flip(caps.getFlipContents()); |
|
3969 |
} |
|
3970 |
||
3971 |
/** |
|
887 | 3972 |
* Makes specified region of the the next available buffer visible |
3973 |
* by either blitting or flipping. |
|
3974 |
*/ |
|
3975 |
void showSubRegion(int x1, int y1, int x2, int y2) { |
|
3976 |
flipSubRegion(x1, y1, x2, y2, caps.getFlipContents()); |
|
3977 |
} |
|
3978 |
||
3979 |
/** |
|
2 | 3980 |
* {@inheritDoc} |
3981 |
* @since 1.6 |
|
3982 |
*/ |
|
3983 |
public void dispose() { |
|
3984 |
if (Component.this.bufferStrategy == this) { |
|
3985 |
Component.this.bufferStrategy = null; |
|
3986 |
if (peer != null) { |
|
3987 |
destroyBuffers(); |
|
3988 |
} |
|
3989 |
} |
|
3990 |
} |
|
3991 |
||
3992 |
} // Inner class FlipBufferStrategy |
|
3993 |
||
3994 |
/** |
|
3995 |
* Inner class for blitting offscreen surfaces to a component. |
|
3996 |
* |
|
3997 |
* @author Michael Martak |
|
3998 |
* @since 1.4 |
|
3999 |
*/ |
|
4000 |
protected class BltBufferStrategy extends BufferStrategy { |
|
4001 |
||
4002 |
/** |
|
4003 |
* The buffering capabilities |
|
4004 |
*/ |
|
4005 |
protected BufferCapabilities caps; // = null |
|
4006 |
/** |
|
4007 |
* The back buffers |
|
4008 |
*/ |
|
4009 |
protected VolatileImage[] backBuffers; // = null |
|
4010 |
/** |
|
4011 |
* Whether or not the drawing buffer has been recently restored from |
|
4012 |
* a lost state. |
|
4013 |
*/ |
|
4014 |
protected boolean validatedContents; // = false |
|
4015 |
/** |
|
4016 |
* Size of the back buffers |
|
4017 |
*/ |
|
4018 |
protected int width; |
|
4019 |
protected int height; |
|
4020 |
||
4021 |
/** |
|
4022 |
* Insets for the hosting Component. The size of the back buffer |
|
4023 |
* is constrained by these. |
|
4024 |
*/ |
|
4025 |
private Insets insets; |
|
4026 |
||
4027 |
/** |
|
4028 |
* Creates a new blt buffer strategy around a component |
|
4029 |
* @param numBuffers number of buffers to create, including the |
|
4030 |
* front buffer |
|
4031 |
* @param caps the capabilities of the buffers |
|
4032 |
*/ |
|
4033 |
protected BltBufferStrategy(int numBuffers, BufferCapabilities caps) { |
|
4034 |
this.caps = caps; |
|
4035 |
createBackBuffers(numBuffers - 1); |
|
4036 |
} |
|
4037 |
||
4038 |
/** |
|
4039 |
* {@inheritDoc} |
|
4040 |
* @since 1.6 |
|
4041 |
*/ |
|
4042 |
public void dispose() { |
|
4043 |
if (backBuffers != null) { |
|
4044 |
for (int counter = backBuffers.length - 1; counter >= 0; |
|
4045 |
counter--) { |
|
4046 |
if (backBuffers[counter] != null) { |
|
4047 |
backBuffers[counter].flush(); |
|
4048 |
backBuffers[counter] = null; |
|
4049 |
} |
|
4050 |
} |
|
4051 |
} |
|
4052 |
if (Component.this.bufferStrategy == this) { |
|
4053 |
Component.this.bufferStrategy = null; |
|
4054 |
} |
|
4055 |
} |
|
4056 |
||
4057 |
/** |
|
4058 |
* Creates the back buffers |
|
4059 |
*/ |
|
4060 |
protected void createBackBuffers(int numBuffers) { |
|
4061 |
if (numBuffers == 0) { |
|
4062 |
backBuffers = null; |
|
4063 |
} else { |
|
4064 |
// save the current bounds |
|
4065 |
width = getWidth(); |
|
4066 |
height = getHeight(); |
|
4067 |
insets = getInsets_NoClientCode(); |
|
4068 |
int iWidth = width - insets.left - insets.right; |
|
4069 |
int iHeight = height - insets.top - insets.bottom; |
|
4070 |
||
4071 |
// It is possible for the component's width and/or height |
|
4072 |
// to be 0 here. Force the size of the backbuffers to |
|
4073 |
// be > 0 so that creating the image won't fail. |
|
4074 |
iWidth = Math.max(1, iWidth); |
|
4075 |
iHeight = Math.max(1, iHeight); |
|
4076 |
if (backBuffers == null) { |
|
4077 |
backBuffers = new VolatileImage[numBuffers]; |
|
4078 |
} else { |
|
4079 |
// flush any existing backbuffers |
|
4080 |
for (int i = 0; i < numBuffers; i++) { |
|
4081 |
if (backBuffers[i] != null) { |
|
4082 |
backBuffers[i].flush(); |
|
4083 |
backBuffers[i] = null; |
|
4084 |
} |
|
4085 |
} |
|
4086 |
} |
|
4087 |
||
4088 |
// create the backbuffers |
|
4089 |
for (int i = 0; i < numBuffers; i++) { |
|
4090 |
backBuffers[i] = createVolatileImage(iWidth, iHeight); |
|
4091 |
} |
|
4092 |
} |
|
4093 |
} |
|
4094 |
||
4095 |
/** |
|
4096 |
* @return the buffering capabilities of this strategy |
|
4097 |
*/ |
|
4098 |
public BufferCapabilities getCapabilities() { |
|
4099 |
return caps; |
|
4100 |
} |
|
4101 |
||
4102 |
/** |
|
4103 |
* @return the draw graphics |
|
4104 |
*/ |
|
4105 |
public Graphics getDrawGraphics() { |
|
4106 |
revalidate(); |
|
4107 |
Image backBuffer = getBackBuffer(); |
|
4108 |
if (backBuffer == null) { |
|
4109 |
return getGraphics(); |
|
4110 |
} |
|
4111 |
SunGraphics2D g = (SunGraphics2D)backBuffer.getGraphics(); |
|
4112 |
g.constrain(-insets.left, -insets.top, |
|
4113 |
backBuffer.getWidth(null) + insets.left, |
|
4114 |
backBuffer.getHeight(null) + insets.top); |
|
4115 |
return g; |
|
4116 |
} |
|
4117 |
||
4118 |
/** |
|
4119 |
* @return direct access to the back buffer, as an image. |
|
4120 |
* If there is no back buffer, returns null. |
|
4121 |
*/ |
|
4122 |
Image getBackBuffer() { |
|
4123 |
if (backBuffers != null) { |
|
4124 |
return backBuffers[backBuffers.length - 1]; |
|
4125 |
} else { |
|
4126 |
return null; |
|
4127 |
} |
|
4128 |
} |
|
4129 |
||
4130 |
/** |
|
4131 |
* Makes the next available buffer visible. |
|
4132 |
*/ |
|
4133 |
public void show() { |
|
4134 |
showSubRegion(insets.left, insets.top, |
|
4135 |
width - insets.right, |
|
4136 |
height - insets.bottom); |
|
4137 |
} |
|
4138 |
||
4139 |
/** |
|
4140 |
* Package-private method to present a specific rectangular area |
|
4141 |
* of this buffer. This class currently shows only the entire |
|
4142 |
* buffer, by calling showSubRegion() with the full dimensions of |
|
4143 |
* the buffer. Subclasses (e.g., BltSubRegionBufferStrategy |
|
4144 |
* and FlipSubRegionBufferStrategy) may have region-specific show |
|
4145 |
* methods that call this method with actual sub regions of the |
|
4146 |
* buffer. |
|
4147 |
*/ |
|
4148 |
void showSubRegion(int x1, int y1, int x2, int y2) { |
|
4149 |
if (backBuffers == null) { |
|
4150 |
return; |
|
4151 |
} |
|
4152 |
// Adjust location to be relative to client area. |
|
4153 |
x1 -= insets.left; |
|
4154 |
x2 -= insets.left; |
|
4155 |
y1 -= insets.top; |
|
4156 |
y2 -= insets.top; |
|
4157 |
Graphics g = getGraphics_NoClientCode(); |
|
4158 |
if (g == null) { |
|
4159 |
// Not showing, bail |
|
4160 |
return; |
|
4161 |
} |
|
4162 |
try { |
|
4163 |
// First image copy is in terms of Frame's coordinates, need |
|
4164 |
// to translate to client area. |
|
4165 |
g.translate(insets.left, insets.top); |
|
4166 |
for (int i = 0; i < backBuffers.length; i++) { |
|
4167 |
g.drawImage(backBuffers[i], |
|
4168 |
x1, y1, x2, y2, |
|
4169 |
x1, y1, x2, y2, |
|
4170 |
null); |
|
4171 |
g.dispose(); |
|
4172 |
g = null; |
|
4173 |
g = backBuffers[i].getGraphics(); |
|
4174 |
} |
|
4175 |
} finally { |
|
4176 |
if (g != null) { |
|
4177 |
g.dispose(); |
|
4178 |
} |
|
4179 |
} |
|
4180 |
} |
|
4181 |
||
4182 |
/** |
|
4183 |
* Restore the drawing buffer if it has been lost |
|
4184 |
*/ |
|
4185 |
protected void revalidate() { |
|
4186 |
revalidate(true); |
|
4187 |
} |
|
4188 |
||
4189 |
void revalidate(boolean checkSize) { |
|
4190 |
validatedContents = false; |
|
4191 |
||
4192 |
if (backBuffers == null) { |
|
4193 |
return; |
|
4194 |
} |
|
4195 |
||
4196 |
if (checkSize) { |
|
4197 |
Insets insets = getInsets_NoClientCode(); |
|
4198 |
if (getWidth() != width || getHeight() != height || |
|
4199 |
!insets.equals(this.insets)) { |
|
4200 |
// component has been resized; recreate the backbuffers |
|
4201 |
createBackBuffers(backBuffers.length); |
|
4202 |
validatedContents = true; |
|
4203 |
} |
|
4204 |
} |
|
4205 |
||
4206 |
// now validate the backbuffer |
|
4207 |
GraphicsConfiguration gc = getGraphicsConfiguration_NoClientCode(); |
|
4208 |
int returnCode = |
|
4209 |
backBuffers[backBuffers.length - 1].validate(gc); |
|
4210 |
if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) { |
|
4211 |
if (checkSize) { |
|
4212 |
createBackBuffers(backBuffers.length); |
|
4213 |
// backbuffers were recreated, so validate again |
|
4214 |
backBuffers[backBuffers.length - 1].validate(gc); |
|
4215 |
} |
|
4216 |
// else case means we're called from Swing on the toolkit |
|
4217 |
// thread, don't recreate buffers as that'll deadlock |
|
4218 |
// (creating VolatileImages invokes getting GraphicsConfig |
|
4219 |
// which grabs treelock). |
|
4220 |
validatedContents = true; |
|
4221 |
} else if (returnCode == VolatileImage.IMAGE_RESTORED) { |
|
4222 |
validatedContents = true; |
|
4223 |
} |
|
4224 |
} |
|
4225 |
||
4226 |
/** |
|
4227 |
* @return whether the drawing buffer was lost since the last call to |
|
4228 |
* <code>getDrawGraphics</code> |
|
4229 |
*/ |
|
4230 |
public boolean contentsLost() { |
|
4231 |
if (backBuffers == null) { |
|
4232 |
return false; |
|
4233 |
} else { |
|
4234 |
return backBuffers[backBuffers.length - 1].contentsLost(); |
|
4235 |
} |
|
4236 |
} |
|
4237 |
||
4238 |
/** |
|
4239 |
* @return whether the drawing buffer was recently restored from a lost |
|
4240 |
* state and reinitialized to the default background color (white) |
|
4241 |
*/ |
|
4242 |
public boolean contentsRestored() { |
|
4243 |
return validatedContents; |
|
4244 |
} |
|
4245 |
} // Inner class BltBufferStrategy |
|
4246 |
||
4247 |
/** |
|
4248 |
* Private class to perform sub-region flipping. |
|
4249 |
*/ |
|
4250 |
private class FlipSubRegionBufferStrategy extends FlipBufferStrategy |
|
4251 |
implements SubRegionShowable |
|
4252 |
{ |
|
4253 |
||
4254 |
protected FlipSubRegionBufferStrategy(int numBuffers, |
|
4255 |
BufferCapabilities caps) |
|
4256 |
throws AWTException |
|
4257 |
{ |
|
4258 |
super(numBuffers, caps); |
|
4259 |
} |
|
4260 |
||
4261 |
public void show(int x1, int y1, int x2, int y2) { |
|
887 | 4262 |
showSubRegion(x1, y1, x2, y2); |
2 | 4263 |
} |
4264 |
||
4265 |
// This is invoked by Swing on the toolkit thread. |
|
887 | 4266 |
public boolean showIfNotLost(int x1, int y1, int x2, int y2) { |
4267 |
if (!contentsLost()) { |
|
4268 |
showSubRegion(x1, y1, x2, y2); |
|
2 | 4269 |
return !contentsLost(); |
4270 |
} |
|
4271 |
return false; |
|
4272 |
} |
|
4273 |
} |
|
4274 |
||
4275 |
/** |
|
4276 |
* Private class to perform sub-region blitting. Swing will use |
|
4277 |
* this subclass via the SubRegionShowable interface in order to |
|
4278 |
* copy only the area changed during a repaint. |
|
4279 |
* @see javax.swing.BufferStrategyPaintManager |
|
4280 |
*/ |
|
4281 |
private class BltSubRegionBufferStrategy extends BltBufferStrategy |
|
4282 |
implements SubRegionShowable |
|
4283 |
{ |
|
4284 |
||
4285 |
protected BltSubRegionBufferStrategy(int numBuffers, |
|
4286 |
BufferCapabilities caps) |
|
4287 |
{ |
|
4288 |
super(numBuffers, caps); |
|
4289 |
} |
|
4290 |
||
4291 |
public void show(int x1, int y1, int x2, int y2) { |
|
4292 |
showSubRegion(x1, y1, x2, y2); |
|
4293 |
} |
|
4294 |
||
4295 |
// This method is called by Swing on the toolkit thread. |
|
887 | 4296 |
public boolean showIfNotLost(int x1, int y1, int x2, int y2) { |
4297 |
if (!contentsLost()) { |
|
2 | 4298 |
showSubRegion(x1, y1, x2, y2); |
4299 |
return !contentsLost(); |
|
4300 |
} |
|
4301 |
return false; |
|
4302 |
} |
|
4303 |
} |
|
4304 |
||
4305 |
/** |
|
4306 |
* Inner class for flipping buffers on a component. That component must |
|
4307 |
* be a <code>Canvas</code> or <code>Window</code>. |
|
4308 |
* @see Canvas |
|
4309 |
* @see Window |
|
4310 |
* @see java.awt.image.BufferStrategy |
|
4311 |
* @author Michael Martak |
|
4312 |
* @since 1.4 |
|
4313 |
*/ |
|
4314 |
private class SingleBufferStrategy extends BufferStrategy { |
|
4315 |
||
4316 |
private BufferCapabilities caps; |
|
4317 |
||
4318 |
public SingleBufferStrategy(BufferCapabilities caps) { |
|
4319 |
this.caps = caps; |
|
4320 |
} |
|
4321 |
public BufferCapabilities getCapabilities() { |
|
4322 |
return caps; |
|
4323 |
} |
|
4324 |
public Graphics getDrawGraphics() { |
|
4325 |
return getGraphics(); |
|
4326 |
} |
|
4327 |
public boolean contentsLost() { |
|
4328 |
return false; |
|
4329 |
} |
|
4330 |
public boolean contentsRestored() { |
|
4331 |
return false; |
|
4332 |
} |
|
4333 |
public void show() { |
|
4334 |
// Do nothing |
|
4335 |
} |
|
4336 |
} // Inner class SingleBufferStrategy |
|
4337 |
||
4338 |
/** |
|
4339 |
* Sets whether or not paint messages received from the operating system |
|
4340 |
* should be ignored. This does not affect paint events generated in |
|
4341 |
* software by the AWT, unless they are an immediate response to an |
|
4342 |
* OS-level paint message. |
|
4343 |
* <p> |
|
4344 |
* This is useful, for example, if running under full-screen mode and |
|
4345 |
* better performance is desired, or if page-flipping is used as the |
|
4346 |
* buffer strategy. |
|
4347 |
* |
|
4348 |
* @since 1.4 |
|
4349 |
* @see #getIgnoreRepaint |
|
4350 |
* @see Canvas#createBufferStrategy |
|
4351 |
* @see Window#createBufferStrategy |
|
4352 |
* @see java.awt.image.BufferStrategy |
|
4353 |
* @see GraphicsDevice#setFullScreenWindow |
|
4354 |
*/ |
|
4355 |
public void setIgnoreRepaint(boolean ignoreRepaint) { |
|
4356 |
this.ignoreRepaint = ignoreRepaint; |
|
4357 |
} |
|
4358 |
||
4359 |
/** |
|
4360 |
* @return whether or not paint messages received from the operating system |
|
4361 |
* should be ignored. |
|
4362 |
* |
|
4363 |
* @since 1.4 |
|
4364 |
* @see #setIgnoreRepaint |
|
4365 |
*/ |
|
4366 |
public boolean getIgnoreRepaint() { |
|
4367 |
return ignoreRepaint; |
|
4368 |
} |
|
4369 |
||
4370 |
/** |
|
4371 |
* Checks whether this component "contains" the specified point, |
|
4372 |
* where <code>x</code> and <code>y</code> are defined to be |
|
4373 |
* relative to the coordinate system of this component. |
|
4374 |
* @param x the <i>x</i> coordinate of the point |
|
4375 |
* @param y the <i>y</i> coordinate of the point |
|
4376 |
* @see #getComponentAt(int, int) |
|
4377 |
* @since JDK1.1 |
|
4378 |
*/ |
|
4379 |
public boolean contains(int x, int y) { |
|
4380 |
return inside(x, y); |
|
4381 |
} |
|
4382 |
||
4383 |
/** |
|
4384 |
* @deprecated As of JDK version 1.1, |
|
4385 |
* replaced by contains(int, int). |
|
4386 |
*/ |
|
4387 |
@Deprecated |
|
4388 |
public boolean inside(int x, int y) { |
|
4389 |
return (x >= 0) && (x < width) && (y >= 0) && (y < height); |
|
4390 |
} |
|
4391 |
||
4392 |
/** |
|
4393 |
* Checks whether this component "contains" the specified point, |
|
4394 |
* where the point's <i>x</i> and <i>y</i> coordinates are defined |
|
4395 |
* to be relative to the coordinate system of this component. |
|
4396 |
* @param p the point |
|
4397 |
* @see #getComponentAt(Point) |
|
4398 |
* @since JDK1.1 |
|
4399 |
*/ |
|
4400 |
public boolean contains(Point p) { |
|
4401 |
return contains(p.x, p.y); |
|
4402 |
} |
|
4403 |
||
4404 |
/** |
|
4405 |
* Determines if this component or one of its immediate |
|
4406 |
* subcomponents contains the (<i>x</i>, <i>y</i>) location, |
|
4407 |
* and if so, returns the containing component. This method only |
|
4408 |
* looks one level deep. If the point (<i>x</i>, <i>y</i>) is |
|
4409 |
* inside a subcomponent that itself has subcomponents, it does not |
|
4410 |
* go looking down the subcomponent tree. |
|
4411 |
* <p> |
|
4412 |
* The <code>locate</code> method of <code>Component</code> simply |
|
4413 |
* returns the component itself if the (<i>x</i>, <i>y</i>) |
|
4414 |
* coordinate location is inside its bounding box, and <code>null</code> |
|
4415 |
* otherwise. |
|
4416 |
* @param x the <i>x</i> coordinate |
|
4417 |
* @param y the <i>y</i> coordinate |
|
4418 |
* @return the component or subcomponent that contains the |
|
4419 |
* (<i>x</i>, <i>y</i>) location; |
|
4420 |
* <code>null</code> if the location |
|
4421 |
* is outside this component |
|
4422 |
* @see #contains(int, int) |
|
4423 |
* @since JDK1.0 |
|
4424 |
*/ |
|
4425 |
public Component getComponentAt(int x, int y) { |
|
4426 |
return locate(x, y); |
|
4427 |
} |
|
4428 |
||
4429 |
/** |
|
4430 |
* @deprecated As of JDK version 1.1, |
|
4431 |
* replaced by getComponentAt(int, int). |
|
4432 |
*/ |
|
4433 |
@Deprecated |
|
4434 |
public Component locate(int x, int y) { |
|
4435 |
return contains(x, y) ? this : null; |
|
4436 |
} |
|
4437 |
||
4438 |
/** |
|
4439 |
* Returns the component or subcomponent that contains the |
|
4440 |
* specified point. |
|
4441 |
* @param p the point |
|
4442 |
* @see java.awt.Component#contains |
|
4443 |
* @since JDK1.1 |
|
4444 |
*/ |
|
4445 |
public Component getComponentAt(Point p) { |
|
4446 |
return getComponentAt(p.x, p.y); |
|
4447 |
} |
|
4448 |
||
4449 |
/** |
|
4450 |
* @deprecated As of JDK version 1.1, |
|
4451 |
* replaced by <code>dispatchEvent(AWTEvent e)</code>. |
|
4452 |
*/ |
|
4453 |
@Deprecated |
|
4454 |
public void deliverEvent(Event e) { |
|
4455 |
postEvent(e); |
|
4456 |
} |
|
4457 |
||
4458 |
/** |
|
4459 |
* Dispatches an event to this component or one of its sub components. |
|
4460 |
* Calls <code>processEvent</code> before returning for 1.1-style |
|
4461 |
* events which have been enabled for the <code>Component</code>. |
|
4462 |
* @param e the event |
|
4463 |
*/ |
|
4464 |
public final void dispatchEvent(AWTEvent e) { |
|
4465 |
dispatchEventImpl(e); |
|
4466 |
} |
|
4467 |
||
4468 |
void dispatchEventImpl(AWTEvent e) { |
|
4469 |
int id = e.getID(); |
|
4470 |
||
4471 |
// Check that this component belongs to this app-context |
|
4472 |
AppContext compContext = appContext; |
|
4473 |
if (compContext != null && !compContext.equals(AppContext.getAppContext())) { |
|
4474 |
if (eventLog.isLoggable(Level.FINE)) { |
|
4475 |
eventLog.log(Level.FINE, "Event " + e + " is being dispatched on the wrong AppContext"); |
|
4476 |
} |
|
4477 |
} |
|
4478 |
||
4479 |
if (eventLog.isLoggable(Level.FINEST)) { |
|
4480 |
eventLog.log(Level.FINEST, "{0}", e); |
|
4481 |
} |
|
4482 |
||
4483 |
/* |
|
4484 |
* 0. Set timestamp and modifiers of current event. |
|
4485 |
*/ |
|
4486 |
EventQueue.setCurrentEventAndMostRecentTime(e); |
|
4487 |
||
4488 |
/* |
|
4489 |
* 1. Pre-dispatchers. Do any necessary retargeting/reordering here |
|
4490 |
* before we notify AWTEventListeners. |
|
4491 |
*/ |
|
4492 |
||
4493 |
if (e instanceof SunDropTargetEvent) { |
|
4494 |
((SunDropTargetEvent)e).dispatch(); |
|
4495 |
return; |
|
4496 |
} |
|
4497 |
||
4498 |
if (!e.focusManagerIsDispatching) { |
|
4499 |
// Invoke the private focus retargeting method which provides |
|
4500 |
// lightweight Component support |
|
4501 |
if (e.isPosted) { |
|
4502 |
e = KeyboardFocusManager.retargetFocusEvent(e); |
|
4503 |
e.isPosted = true; |
|
4504 |
} |
|
4505 |
||
4506 |
// Now, with the event properly targeted to a lightweight |
|
4507 |
// descendant if necessary, invoke the public focus retargeting |
|
4508 |
// and dispatching function |
|
4509 |
if (KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
4510 |
dispatchEvent(e)) |
|
4511 |
{ |
|
4512 |
return; |
|
4513 |
} |
|
4514 |
} |
|
4515 |
if ((e instanceof FocusEvent) && focusLog.isLoggable(Level.FINEST)) { |
|
4516 |
focusLog.log(Level.FINEST, "" + e); |
|
4517 |
} |
|
4518 |
// MouseWheel may need to be retargeted here so that |
|
4519 |
// AWTEventListener sees the event go to the correct |
|
4520 |
// Component. If the MouseWheelEvent needs to go to an ancestor, |
|
4521 |
// the event is dispatched to the ancestor, and dispatching here |
|
4522 |
// stops. |
|
4523 |
if (id == MouseEvent.MOUSE_WHEEL && |
|
4524 |
(!eventTypeEnabled(id)) && |
|
4525 |
(peer != null && !peer.handlesWheelScrolling()) && |
|
4526 |
(dispatchMouseWheelToAncestor((MouseWheelEvent)e))) |
|
4527 |
{ |
|
4528 |
return; |
|
4529 |
} |
|
4530 |
||
4531 |
/* |
|
4532 |
* 2. Allow the Toolkit to pass this to AWTEventListeners. |
|
4533 |
*/ |
|
4534 |
Toolkit toolkit = Toolkit.getDefaultToolkit(); |
|
4535 |
toolkit.notifyAWTEventListeners(e); |
|
4536 |
||
4537 |
||
4538 |
/* |
|
4539 |
* 3. If no one has consumed a key event, allow the |
|
4540 |
* KeyboardFocusManager to process it. |
|
4541 |
*/ |
|
4542 |
if (!e.isConsumed()) { |
|
4543 |
if (e instanceof java.awt.event.KeyEvent) { |
|
4544 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
4545 |
processKeyEvent(this, (KeyEvent)e); |
|
4546 |
if (e.isConsumed()) { |
|
4547 |
return; |
|
4548 |
} |
|
4549 |
} |
|
4550 |
} |
|
4551 |
||
4552 |
/* |
|
4553 |
* 4. Allow input methods to process the event |
|
4554 |
*/ |
|
4555 |
if (areInputMethodsEnabled()) { |
|
4556 |
// We need to pass on InputMethodEvents since some host |
|
4557 |
// input method adapters send them through the Java |
|
4558 |
// event queue instead of directly to the component, |
|
4559 |
// and the input context also handles the Java composition window |
|
4560 |
if(((e instanceof InputMethodEvent) && !(this instanceof CompositionArea)) |
|
4561 |
|| |
|
4562 |
// Otherwise, we only pass on input and focus events, because |
|
4563 |
// a) input methods shouldn't know about semantic or component-level events |
|
4564 |
// b) passing on the events takes time |
|
4565 |
// c) isConsumed() is always true for semantic events. |
|
4566 |
(e instanceof InputEvent) || (e instanceof FocusEvent)) { |
|
4567 |
InputContext inputContext = getInputContext(); |
|
4568 |
||
4569 |
||
4570 |
if (inputContext != null) { |
|
4571 |
inputContext.dispatchEvent(e); |
|
4572 |
if (e.isConsumed()) { |
|
4573 |
if ((e instanceof FocusEvent) && focusLog.isLoggable(Level.FINEST)) { |
|
4574 |
focusLog.log(Level.FINEST, "3579: Skipping " + e); |
|
4575 |
} |
|
4576 |
return; |
|
4577 |
} |
|
4578 |
} |
|
4579 |
} |
|
4580 |
} else { |
|
4581 |
// When non-clients get focus, we need to explicitly disable the native |
|
4582 |
// input method. The native input method is actually not disabled when |
|
4583 |
// the active/passive/peered clients loose focus. |
|
4584 |
if (id == FocusEvent.FOCUS_GAINED) { |
|
4585 |
InputContext inputContext = getInputContext(); |
|
4586 |
if (inputContext != null && inputContext instanceof sun.awt.im.InputContext) { |
|
4587 |
((sun.awt.im.InputContext)inputContext).disableNativeIM(); |
|
4588 |
} |
|
4589 |
} |
|
4590 |
} |
|
4591 |
||
4592 |
||
4593 |
/* |
|
4594 |
* 5. Pre-process any special events before delivery |
|
4595 |
*/ |
|
4596 |
switch(id) { |
|
4597 |
// Handling of the PAINT and UPDATE events is now done in the |
|
4598 |
// peer's handleEvent() method so the background can be cleared |
|
4599 |
// selectively for non-native components on Windows only. |
|
4600 |
// - Fred.Ecks@Eng.sun.com, 5-8-98 |
|
4601 |
||
4602 |
case KeyEvent.KEY_PRESSED: |
|
4603 |
case KeyEvent.KEY_RELEASED: |
|
4604 |
Container p = (Container)((this instanceof Container) ? this : parent); |
|
4605 |
if (p != null) { |
|
4606 |
p.preProcessKeyEvent((KeyEvent)e); |
|
4607 |
if (e.isConsumed()) { |
|
4608 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
4609 |
focusLog.log(Level.FINEST, "Pre-process consumed event"); |
|
4610 |
} |
|
4611 |
return; |
|
4612 |
} |
|
4613 |
} |
|
4614 |
break; |
|
4615 |
||
4616 |
case WindowEvent.WINDOW_CLOSING: |
|
4617 |
if (toolkit instanceof WindowClosingListener) { |
|
4618 |
windowClosingException = ((WindowClosingListener) |
|
4619 |
toolkit).windowClosingNotify((WindowEvent)e); |
|
4620 |
if (checkWindowClosingException()) { |
|
4621 |
return; |
|
4622 |
} |
|
4623 |
} |
|
4624 |
break; |
|
4625 |
||
4626 |
default: |
|
4627 |
break; |
|
4628 |
} |
|
4629 |
||
4630 |
/* |
|
4631 |
* 6. Deliver event for normal processing |
|
4632 |
*/ |
|
4633 |
if (newEventsOnly) { |
|
4634 |
// Filtering needs to really be moved to happen at a lower |
|
4635 |
// level in order to get maximum performance gain; it is |
|
4636 |
// here temporarily to ensure the API spec is honored. |
|
4637 |
// |
|
4638 |
if (eventEnabled(e)) { |
|
4639 |
processEvent(e); |
|
4640 |
} |
|
4641 |
} else if (id == MouseEvent.MOUSE_WHEEL) { |
|
4642 |
// newEventsOnly will be false for a listenerless ScrollPane, but |
|
4643 |
// MouseWheelEvents still need to be dispatched to it so scrolling |
|
4644 |
// can be done. |
|
4645 |
autoProcessMouseWheel((MouseWheelEvent)e); |
|
4646 |
} else if (!(e instanceof MouseEvent && !postsOldMouseEvents())) { |
|
4647 |
// |
|
4648 |
// backward compatibility |
|
4649 |
// |
|
4650 |
Event olde = e.convertToOld(); |
|
4651 |
if (olde != null) { |
|
4652 |
int key = olde.key; |
|
4653 |
int modifiers = olde.modifiers; |
|
4654 |
||
4655 |
postEvent(olde); |
|
4656 |
if (olde.isConsumed()) { |
|
4657 |
e.consume(); |
|
4658 |
} |
|
4659 |
// if target changed key or modifier values, copy them |
|
4660 |
// back to original event |
|
4661 |
// |
|
4662 |
switch(olde.id) { |
|
4663 |
case Event.KEY_PRESS: |
|
4664 |
case Event.KEY_RELEASE: |
|
4665 |
case Event.KEY_ACTION: |
|
4666 |
case Event.KEY_ACTION_RELEASE: |
|
4667 |
if (olde.key != key) { |
|
4668 |
((KeyEvent)e).setKeyChar(olde.getKeyEventChar()); |
|
4669 |
} |
|
4670 |
if (olde.modifiers != modifiers) { |
|
4671 |
((KeyEvent)e).setModifiers(olde.modifiers); |
|
4672 |
} |
|
4673 |
break; |
|
4674 |
default: |
|
4675 |
break; |
|
4676 |
} |
|
4677 |
} |
|
4678 |
} |
|
4679 |
||
4680 |
/* |
|
4681 |
* 8. Special handling for 4061116 : Hook for browser to close modal |
|
4682 |
* dialogs. |
|
4683 |
*/ |
|
4684 |
if (id == WindowEvent.WINDOW_CLOSING && !e.isConsumed()) { |
|
4685 |
if (toolkit instanceof WindowClosingListener) { |
|
4686 |
windowClosingException = |
|
4687 |
((WindowClosingListener)toolkit). |
|
4688 |
windowClosingDelivered((WindowEvent)e); |
|
4689 |
if (checkWindowClosingException()) { |
|
4690 |
return; |
|
4691 |
} |
|
4692 |
} |
|
4693 |
} |
|
4694 |
||
4695 |
/* |
|
4696 |
* 9. Allow the peer to process the event. |
|
4697 |
* Except KeyEvents, they will be processed by peer after |
|
4698 |
* all KeyEventPostProcessors |
|
4699 |
* (see DefaultKeyboardFocusManager.dispatchKeyEvent()) |
|
4700 |
*/ |
|
4701 |
if (!(e instanceof KeyEvent)) { |
|
4702 |
ComponentPeer tpeer = peer; |
|
4703 |
if (e instanceof FocusEvent && (tpeer == null || tpeer instanceof LightweightPeer)) { |
|
4704 |
// if focus owner is lightweight then its native container |
|
4705 |
// processes event |
|
4706 |
Component source = (Component)e.getSource(); |
|
4707 |
if (source != null) { |
|
4708 |
Container target = source.getNativeContainer(); |
|
4709 |
if (target != null) { |
|
4710 |
tpeer = target.getPeer(); |
|
4711 |
} |
|
4712 |
} |
|
4713 |
} |
|
4714 |
if (tpeer != null) { |
|
4715 |
tpeer.handleEvent(e); |
|
4716 |
} |
|
4717 |
} |
|
4718 |
} // dispatchEventImpl() |
|
4719 |
||
4720 |
/* |
|
4721 |
* If newEventsOnly is false, method is called so that ScrollPane can |
|
4722 |
* override it and handle common-case mouse wheel scrolling. NOP |
|
4723 |
* for Component. |
|
4724 |
*/ |
|
4725 |
void autoProcessMouseWheel(MouseWheelEvent e) {} |
|
4726 |
||
4727 |
/* |
|
4728 |
* Dispatch given MouseWheelEvent to the first ancestor for which |
|
4729 |
* MouseWheelEvents are enabled. |
|
4730 |
* |
|
4731 |
* Returns whether or not event was dispatched to an ancestor |
|
4732 |
*/ |
|
4733 |
boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) { |
|
4734 |
int newX, newY; |
|
4735 |
newX = e.getX() + getX(); // Coordinates take into account at least |
|
4736 |
newY = e.getY() + getY(); // the cursor's position relative to this |
|
4737 |
// Component (e.getX()), and this Component's |
|
4738 |
// position relative to its parent. |
|
4739 |
MouseWheelEvent newMWE; |
|
4740 |
||
4741 |
if (eventLog.isLoggable(Level.FINEST)) { |
|
4742 |
eventLog.log(Level.FINEST, "dispatchMouseWheelToAncestor"); |
|
4743 |
eventLog.log(Level.FINEST, "orig event src is of " + e.getSource().getClass()); |
|
4744 |
} |
|
4745 |
||
4746 |
/* parent field for Window refers to the owning Window. |
|
4747 |
* MouseWheelEvents should NOT be propagated into owning Windows |
|
4748 |
*/ |
|
4749 |
synchronized (getTreeLock()) { |
|
4750 |
Container anc = getParent(); |
|
4751 |
while (anc != null && !anc.eventEnabled(e)) { |
|
4752 |
// fix coordinates to be relative to new event source |
|
4753 |
newX += anc.getX(); |
|
4754 |
newY += anc.getY(); |
|
4755 |
||
4756 |
if (!(anc instanceof Window)) { |
|
4757 |
anc = anc.getParent(); |
|
4758 |
} |
|
4759 |
else { |
|
4760 |
break; |
|
4761 |
} |
|
4762 |
} |
|
4763 |
||
4764 |
if (eventLog.isLoggable(Level.FINEST)) { |
|
4765 |
eventLog.log(Level.FINEST, "new event src is " + anc.getClass()); |
|
4766 |
} |
|
4767 |
||
4768 |
if (anc != null && anc.eventEnabled(e)) { |
|
4769 |
// Change event to be from new source, with new x,y |
|
4770 |
// For now, just create a new event - yucky |
|
4771 |
||
4772 |
newMWE = new MouseWheelEvent(anc, // new source |
|
4773 |
e.getID(), |
|
4774 |
e.getWhen(), |
|
4775 |
e.getModifiers(), |
|
4776 |
newX, // x relative to new source |
|
4777 |
newY, // y relative to new source |
|
4778 |
e.getXOnScreen(), |
|
4779 |
e.getYOnScreen(), |
|
4780 |
e.getClickCount(), |
|
4781 |
e.isPopupTrigger(), |
|
4782 |
e.getScrollType(), |
|
4783 |
e.getScrollAmount(), |
|
121
c43b2dfab9ac
6524352: support for high-resolution mouse wheel
dcherepanov
parents:
119
diff
changeset
|
4784 |
e.getWheelRotation(), |
c43b2dfab9ac
6524352: support for high-resolution mouse wheel
dcherepanov
parents:
119
diff
changeset
|
4785 |
e.getPreciseWheelRotation()); |
2 | 4786 |
((AWTEvent)e).copyPrivateDataInto(newMWE); |
4787 |
// When dispatching a wheel event to |
|
4788 |
// ancestor, there is no need trying to find descendant |
|
4789 |
// lightweights to dispatch event to. |
|
4790 |
// If we dispatch the event to toplevel ancestor, |
|
4791 |
// this could encolse the loop: 6480024. |
|
4792 |
anc.dispatchEventToSelf(newMWE); |
|
4793 |
} |
|
4794 |
} |
|
4795 |
return true; |
|
4796 |
} |
|
4797 |
||
4798 |
boolean checkWindowClosingException() { |
|
4799 |
if (windowClosingException != null) { |
|
4800 |
if (this instanceof Dialog) { |
|
4801 |
((Dialog)this).interruptBlocking(); |
|
4802 |
} else { |
|
4803 |
windowClosingException.fillInStackTrace(); |
|
4804 |
windowClosingException.printStackTrace(); |
|
4805 |
windowClosingException = null; |
|
4806 |
} |
|
4807 |
return true; |
|
4808 |
} |
|
4809 |
return false; |
|
4810 |
} |
|
4811 |
||
4812 |
boolean areInputMethodsEnabled() { |
|
4813 |
// in 1.2, we assume input method support is required for all |
|
4814 |
// components that handle key events, but components can turn off |
|
4815 |
// input methods by calling enableInputMethods(false). |
|
4816 |
return ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) && |
|
4817 |
((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || keyListener != null); |
|
4818 |
} |
|
4819 |
||
4820 |
// REMIND: remove when filtering is handled at lower level |
|
4821 |
boolean eventEnabled(AWTEvent e) { |
|
4822 |
return eventTypeEnabled(e.id); |
|
4823 |
} |
|
4824 |
||
4825 |
boolean eventTypeEnabled(int type) { |
|
4826 |
switch(type) { |
|
4827 |
case ComponentEvent.COMPONENT_MOVED: |
|
4828 |
case ComponentEvent.COMPONENT_RESIZED: |
|
4829 |
case ComponentEvent.COMPONENT_SHOWN: |
|
4830 |
case ComponentEvent.COMPONENT_HIDDEN: |
|
4831 |
if ((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 || |
|
4832 |
componentListener != null) { |
|
4833 |
return true; |
|
4834 |
} |
|
4835 |
break; |
|
4836 |
case FocusEvent.FOCUS_GAINED: |
|
4837 |
case FocusEvent.FOCUS_LOST: |
|
4838 |
if ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 || |
|
4839 |
focusListener != null) { |
|
4840 |
return true; |
|
4841 |
} |
|
4842 |
break; |
|
4843 |
case KeyEvent.KEY_PRESSED: |
|
4844 |
case KeyEvent.KEY_RELEASED: |
|
4845 |
case KeyEvent.KEY_TYPED: |
|
4846 |
if ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || |
|
4847 |
keyListener != null) { |
|
4848 |
return true; |
|
4849 |
} |
|
4850 |
break; |
|
4851 |
case MouseEvent.MOUSE_PRESSED: |
|
4852 |
case MouseEvent.MOUSE_RELEASED: |
|
4853 |
case MouseEvent.MOUSE_ENTERED: |
|
4854 |
case MouseEvent.MOUSE_EXITED: |
|
4855 |
case MouseEvent.MOUSE_CLICKED: |
|
4856 |
if ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 || |
|
4857 |
mouseListener != null) { |
|
4858 |
return true; |
|
4859 |
} |
|
4860 |
break; |
|
4861 |
case MouseEvent.MOUSE_MOVED: |
|
4862 |
case MouseEvent.MOUSE_DRAGGED: |
|
4863 |
if ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 || |
|
4864 |
mouseMotionListener != null) { |
|
4865 |
return true; |
|
4866 |
} |
|
4867 |
break; |
|
4868 |
case MouseEvent.MOUSE_WHEEL: |
|
4869 |
if ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 || |
|
4870 |
mouseWheelListener != null) { |
|
4871 |
return true; |
|
4872 |
} |
|
4873 |
break; |
|
4874 |
case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: |
|
4875 |
case InputMethodEvent.CARET_POSITION_CHANGED: |
|
4876 |
if ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 || |
|
4877 |
inputMethodListener != null) { |
|
4878 |
return true; |
|
4879 |
} |
|
4880 |
break; |
|
4881 |
case HierarchyEvent.HIERARCHY_CHANGED: |
|
4882 |
if ((eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 || |
|
4883 |
hierarchyListener != null) { |
|
4884 |
return true; |
|
4885 |
} |
|
4886 |
break; |
|
4887 |
case HierarchyEvent.ANCESTOR_MOVED: |
|
4888 |
case HierarchyEvent.ANCESTOR_RESIZED: |
|
4889 |
if ((eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 || |
|
4890 |
hierarchyBoundsListener != null) { |
|
4891 |
return true; |
|
4892 |
} |
|
4893 |
break; |
|
4894 |
case ActionEvent.ACTION_PERFORMED: |
|
4895 |
if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0) { |
|
4896 |
return true; |
|
4897 |
} |
|
4898 |
break; |
|
4899 |
case TextEvent.TEXT_VALUE_CHANGED: |
|
4900 |
if ((eventMask & AWTEvent.TEXT_EVENT_MASK) != 0) { |
|
4901 |
return true; |
|
4902 |
} |
|
4903 |
break; |
|
4904 |
case ItemEvent.ITEM_STATE_CHANGED: |
|
4905 |
if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0) { |
|
4906 |
return true; |
|
4907 |
} |
|
4908 |
break; |
|
4909 |
case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED: |
|
4910 |
if ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0) { |
|
4911 |
return true; |
|
4912 |
} |
|
4913 |
break; |
|
4914 |
default: |
|
4915 |
break; |
|
4916 |
} |
|
4917 |
// |
|
4918 |
// Always pass on events defined by external programs. |
|
4919 |
// |
|
4920 |
if (type > AWTEvent.RESERVED_ID_MAX) { |
|
4921 |
return true; |
|
4922 |
} |
|
4923 |
return false; |
|
4924 |
} |
|
4925 |
||
4926 |
/** |
|
4927 |
* @deprecated As of JDK version 1.1, |
|
4928 |
* replaced by dispatchEvent(AWTEvent). |
|
4929 |
*/ |
|
4930 |
@Deprecated |
|
4931 |
public boolean postEvent(Event e) { |
|
4932 |
ComponentPeer peer = this.peer; |
|
4933 |
||
4934 |
if (handleEvent(e)) { |
|
4935 |
e.consume(); |
|
4936 |
return true; |
|
4937 |
} |
|
4938 |
||
4939 |
Component parent = this.parent; |
|
4940 |
int eventx = e.x; |
|
4941 |
int eventy = e.y; |
|
4942 |
if (parent != null) { |
|
4943 |
e.translate(x, y); |
|
4944 |
if (parent.postEvent(e)) { |
|
4945 |
e.consume(); |
|
4946 |
return true; |
|
4947 |
} |
|
4948 |
// restore coords |
|
4949 |
e.x = eventx; |
|
4950 |
e.y = eventy; |
|
4951 |
} |
|
4952 |
return false; |
|
4953 |
} |
|
4954 |
||
4955 |
// Event source interfaces |
|
4956 |
||
4957 |
/** |
|
4958 |
* Adds the specified component listener to receive component events from |
|
4959 |
* this component. |
|
4960 |
* If listener <code>l</code> is <code>null</code>, |
|
4961 |
* no exception is thrown and no action is performed. |
|
4962 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
4963 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
4964 |
* |
|
4965 |
* @param l the component listener |
|
4966 |
* @see java.awt.event.ComponentEvent |
|
4967 |
* @see java.awt.event.ComponentListener |
|
4968 |
* @see #removeComponentListener |
|
4969 |
* @see #getComponentListeners |
|
4970 |
* @since JDK1.1 |
|
4971 |
*/ |
|
4972 |
public synchronized void addComponentListener(ComponentListener l) { |
|
4973 |
if (l == null) { |
|
4974 |
return; |
|
4975 |
} |
|
4976 |
componentListener = AWTEventMulticaster.add(componentListener, l); |
|
4977 |
newEventsOnly = true; |
|
4978 |
} |
|
4979 |
||
4980 |
/** |
|
4981 |
* Removes the specified component listener so that it no longer |
|
4982 |
* receives component events from this component. This method performs |
|
4983 |
* no function, nor does it throw an exception, if the listener |
|
4984 |
* specified by the argument was not previously added to this component. |
|
4985 |
* If listener <code>l</code> is <code>null</code>, |
|
4986 |
* no exception is thrown and no action is performed. |
|
4987 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
4988 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
4989 |
* @param l the component listener |
|
4990 |
* @see java.awt.event.ComponentEvent |
|
4991 |
* @see java.awt.event.ComponentListener |
|
4992 |
* @see #addComponentListener |
|
4993 |
* @see #getComponentListeners |
|
4994 |
* @since JDK1.1 |
|
4995 |
*/ |
|
4996 |
public synchronized void removeComponentListener(ComponentListener l) { |
|
4997 |
if (l == null) { |
|
4998 |
return; |
|
4999 |
} |
|
5000 |
componentListener = AWTEventMulticaster.remove(componentListener, l); |
|
5001 |
} |
|
5002 |
||
5003 |
/** |
|
5004 |
* Returns an array of all the component listeners |
|
5005 |
* registered on this component. |
|
5006 |
* |
|
5007 |
* @return all of this comonent's <code>ComponentListener</code>s |
|
5008 |
* or an empty array if no component |
|
5009 |
* listeners are currently registered |
|
5010 |
* |
|
5011 |
* @see #addComponentListener |
|
5012 |
* @see #removeComponentListener |
|
5013 |
* @since 1.4 |
|
5014 |
*/ |
|
5015 |
public synchronized ComponentListener[] getComponentListeners() { |
|
5016 |
return (ComponentListener[]) (getListeners(ComponentListener.class)); |
|
5017 |
} |
|
5018 |
||
5019 |
/** |
|
5020 |
* Adds the specified focus listener to receive focus events from |
|
5021 |
* this component when this component gains input focus. |
|
5022 |
* If listener <code>l</code> is <code>null</code>, |
|
5023 |
* no exception is thrown and no action is performed. |
|
5024 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5025 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5026 |
* |
|
5027 |
* @param l the focus listener |
|
5028 |
* @see java.awt.event.FocusEvent |
|
5029 |
* @see java.awt.event.FocusListener |
|
5030 |
* @see #removeFocusListener |
|
5031 |
* @see #getFocusListeners |
|
5032 |
* @since JDK1.1 |
|
5033 |
*/ |
|
5034 |
public synchronized void addFocusListener(FocusListener l) { |
|
5035 |
if (l == null) { |
|
5036 |
return; |
|
5037 |
} |
|
5038 |
focusListener = AWTEventMulticaster.add(focusListener, l); |
|
5039 |
newEventsOnly = true; |
|
5040 |
||
5041 |
// if this is a lightweight component, enable focus events |
|
5042 |
// in the native container. |
|
5043 |
if (peer instanceof LightweightPeer) { |
|
5044 |
parent.proxyEnableEvents(AWTEvent.FOCUS_EVENT_MASK); |
|
5045 |
} |
|
5046 |
} |
|
5047 |
||
5048 |
/** |
|
5049 |
* Removes the specified focus listener so that it no longer |
|
5050 |
* receives focus events from this component. This method performs |
|
5051 |
* no function, nor does it throw an exception, if the listener |
|
5052 |
* specified by the argument was not previously added to this component. |
|
5053 |
* If listener <code>l</code> is <code>null</code>, |
|
5054 |
* no exception is thrown and no action is performed. |
|
5055 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5056 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5057 |
* |
|
5058 |
* @param l the focus listener |
|
5059 |
* @see java.awt.event.FocusEvent |
|
5060 |
* @see java.awt.event.FocusListener |
|
5061 |
* @see #addFocusListener |
|
5062 |
* @see #getFocusListeners |
|
5063 |
* @since JDK1.1 |
|
5064 |
*/ |
|
5065 |
public synchronized void removeFocusListener(FocusListener l) { |
|
5066 |
if (l == null) { |
|
5067 |
return; |
|
5068 |
} |
|
5069 |
focusListener = AWTEventMulticaster.remove(focusListener, l); |
|
5070 |
} |
|
5071 |
||
5072 |
/** |
|
5073 |
* Returns an array of all the focus listeners |
|
5074 |
* registered on this component. |
|
5075 |
* |
|
5076 |
* @return all of this component's <code>FocusListener</code>s |
|
5077 |
* or an empty array if no component |
|
5078 |
* listeners are currently registered |
|
5079 |
* |
|
5080 |
* @see #addFocusListener |
|
5081 |
* @see #removeFocusListener |
|
5082 |
* @since 1.4 |
|
5083 |
*/ |
|
5084 |
public synchronized FocusListener[] getFocusListeners() { |
|
5085 |
return (FocusListener[]) (getListeners(FocusListener.class)); |
|
5086 |
} |
|
5087 |
||
5088 |
/** |
|
5089 |
* Adds the specified hierarchy listener to receive hierarchy changed |
|
5090 |
* events from this component when the hierarchy to which this container |
|
5091 |
* belongs changes. |
|
5092 |
* If listener <code>l</code> is <code>null</code>, |
|
5093 |
* no exception is thrown and no action is performed. |
|
5094 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5095 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5096 |
* |
|
5097 |
* @param l the hierarchy listener |
|
5098 |
* @see java.awt.event.HierarchyEvent |
|
5099 |
* @see java.awt.event.HierarchyListener |
|
5100 |
* @see #removeHierarchyListener |
|
5101 |
* @see #getHierarchyListeners |
|
5102 |
* @since 1.3 |
|
5103 |
*/ |
|
5104 |
public void addHierarchyListener(HierarchyListener l) { |
|
5105 |
if (l == null) { |
|
5106 |
return; |
|
5107 |
} |
|
5108 |
boolean notifyAncestors; |
|
5109 |
synchronized (this) { |
|
5110 |
notifyAncestors = |
|
5111 |
(hierarchyListener == null && |
|
5112 |
(eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0); |
|
5113 |
hierarchyListener = AWTEventMulticaster.add(hierarchyListener, l); |
|
5114 |
notifyAncestors = (notifyAncestors && hierarchyListener != null); |
|
5115 |
newEventsOnly = true; |
|
5116 |
} |
|
5117 |
if (notifyAncestors) { |
|
5118 |
synchronized (getTreeLock()) { |
|
5119 |
adjustListeningChildrenOnParent(AWTEvent.HIERARCHY_EVENT_MASK, |
|
5120 |
1); |
|
5121 |
} |
|
5122 |
} |
|
5123 |
} |
|
5124 |
||
5125 |
/** |
|
5126 |
* Removes the specified hierarchy listener so that it no longer |
|
5127 |
* receives hierarchy changed events from this component. This method |
|
5128 |
* performs no function, nor does it throw an exception, if the listener |
|
5129 |
* specified by the argument was not previously added to this component. |
|
5130 |
* If listener <code>l</code> is <code>null</code>, |
|
5131 |
* no exception is thrown and no action is performed. |
|
5132 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5133 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5134 |
* |
|
5135 |
* @param l the hierarchy listener |
|
5136 |
* @see java.awt.event.HierarchyEvent |
|
5137 |
* @see java.awt.event.HierarchyListener |
|
5138 |
* @see #addHierarchyListener |
|
5139 |
* @see #getHierarchyListeners |
|
5140 |
* @since 1.3 |
|
5141 |
*/ |
|
5142 |
public void removeHierarchyListener(HierarchyListener l) { |
|
5143 |
if (l == null) { |
|
5144 |
return; |
|
5145 |
} |
|
5146 |
boolean notifyAncestors; |
|
5147 |
synchronized (this) { |
|
5148 |
notifyAncestors = |
|
5149 |
(hierarchyListener != null && |
|
5150 |
(eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0); |
|
5151 |
hierarchyListener = |
|
5152 |
AWTEventMulticaster.remove(hierarchyListener, l); |
|
5153 |
notifyAncestors = (notifyAncestors && hierarchyListener == null); |
|
5154 |
} |
|
5155 |
if (notifyAncestors) { |
|
5156 |
synchronized (getTreeLock()) { |
|
5157 |
adjustListeningChildrenOnParent(AWTEvent.HIERARCHY_EVENT_MASK, |
|
5158 |
-1); |
|
5159 |
} |
|
5160 |
} |
|
5161 |
} |
|
5162 |
||
5163 |
/** |
|
5164 |
* Returns an array of all the hierarchy listeners |
|
5165 |
* registered on this component. |
|
5166 |
* |
|
5167 |
* @return all of this component's <code>HierarchyListener</code>s |
|
5168 |
* or an empty array if no hierarchy |
|
5169 |
* listeners are currently registered |
|
5170 |
* |
|
5171 |
* @see #addHierarchyListener |
|
5172 |
* @see #removeHierarchyListener |
|
5173 |
* @since 1.4 |
|
5174 |
*/ |
|
5175 |
public synchronized HierarchyListener[] getHierarchyListeners() { |
|
5176 |
return (HierarchyListener[])(getListeners(HierarchyListener.class)); |
|
5177 |
} |
|
5178 |
||
5179 |
/** |
|
5180 |
* Adds the specified hierarchy bounds listener to receive hierarchy |
|
5181 |
* bounds events from this component when the hierarchy to which this |
|
5182 |
* container belongs changes. |
|
5183 |
* If listener <code>l</code> is <code>null</code>, |
|
5184 |
* no exception is thrown and no action is performed. |
|
5185 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5186 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5187 |
* |
|
5188 |
* @param l the hierarchy bounds listener |
|
5189 |
* @see java.awt.event.HierarchyEvent |
|
5190 |
* @see java.awt.event.HierarchyBoundsListener |
|
5191 |
* @see #removeHierarchyBoundsListener |
|
5192 |
* @see #getHierarchyBoundsListeners |
|
5193 |
* @since 1.3 |
|
5194 |
*/ |
|
5195 |
public void addHierarchyBoundsListener(HierarchyBoundsListener l) { |
|
5196 |
if (l == null) { |
|
5197 |
return; |
|
5198 |
} |
|
5199 |
boolean notifyAncestors; |
|
5200 |
synchronized (this) { |
|
5201 |
notifyAncestors = |
|
5202 |
(hierarchyBoundsListener == null && |
|
5203 |
(eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0); |
|
5204 |
hierarchyBoundsListener = |
|
5205 |
AWTEventMulticaster.add(hierarchyBoundsListener, l); |
|
5206 |
notifyAncestors = (notifyAncestors && |
|
5207 |
hierarchyBoundsListener != null); |
|
5208 |
newEventsOnly = true; |
|
5209 |
} |
|
5210 |
if (notifyAncestors) { |
|
5211 |
synchronized (getTreeLock()) { |
|
5212 |
adjustListeningChildrenOnParent( |
|
5213 |
AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, 1); |
|
5214 |
} |
|
5215 |
} |
|
5216 |
} |
|
5217 |
||
5218 |
/** |
|
5219 |
* Removes the specified hierarchy bounds listener so that it no longer |
|
5220 |
* receives hierarchy bounds events from this component. This method |
|
5221 |
* performs no function, nor does it throw an exception, if the listener |
|
5222 |
* specified by the argument was not previously added to this component. |
|
5223 |
* If listener <code>l</code> is <code>null</code>, |
|
5224 |
* no exception is thrown and no action is performed. |
|
5225 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5226 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5227 |
* |
|
5228 |
* @param l the hierarchy bounds listener |
|
5229 |
* @see java.awt.event.HierarchyEvent |
|
5230 |
* @see java.awt.event.HierarchyBoundsListener |
|
5231 |
* @see #addHierarchyBoundsListener |
|
5232 |
* @see #getHierarchyBoundsListeners |
|
5233 |
* @since 1.3 |
|
5234 |
*/ |
|
5235 |
public void removeHierarchyBoundsListener(HierarchyBoundsListener l) { |
|
5236 |
if (l == null) { |
|
5237 |
return; |
|
5238 |
} |
|
5239 |
boolean notifyAncestors; |
|
5240 |
synchronized (this) { |
|
5241 |
notifyAncestors = |
|
5242 |
(hierarchyBoundsListener != null && |
|
5243 |
(eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0); |
|
5244 |
hierarchyBoundsListener = |
|
5245 |
AWTEventMulticaster.remove(hierarchyBoundsListener, l); |
|
5246 |
notifyAncestors = (notifyAncestors && |
|
5247 |
hierarchyBoundsListener == null); |
|
5248 |
} |
|
5249 |
if (notifyAncestors) { |
|
5250 |
synchronized (getTreeLock()) { |
|
5251 |
adjustListeningChildrenOnParent( |
|
5252 |
AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, -1); |
|
5253 |
} |
|
5254 |
} |
|
5255 |
} |
|
5256 |
||
5257 |
// Should only be called while holding the tree lock |
|
5258 |
int numListening(long mask) { |
|
5259 |
// One mask or the other, but not neither or both. |
|
5260 |
if (eventLog.isLoggable(Level.FINE)) { |
|
5261 |
if ((mask != AWTEvent.HIERARCHY_EVENT_MASK) && |
|
5262 |
(mask != AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)) |
|
5263 |
{ |
|
5264 |
eventLog.log(Level.FINE, "Assertion failed"); |
|
5265 |
} |
|
5266 |
} |
|
5267 |
if ((mask == AWTEvent.HIERARCHY_EVENT_MASK && |
|
5268 |
(hierarchyListener != null || |
|
5269 |
(eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0)) || |
|
5270 |
(mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK && |
|
5271 |
(hierarchyBoundsListener != null || |
|
5272 |
(eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0))) { |
|
5273 |
return 1; |
|
5274 |
} else { |
|
5275 |
return 0; |
|
5276 |
} |
|
5277 |
} |
|
5278 |
||
5279 |
// Should only be called while holding tree lock |
|
5280 |
int countHierarchyMembers() { |
|
5281 |
return 1; |
|
5282 |
} |
|
5283 |
// Should only be called while holding the tree lock |
|
5284 |
int createHierarchyEvents(int id, Component changed, |
|
5285 |
Container changedParent, long changeFlags, |
|
5286 |
boolean enabledOnToolkit) { |
|
5287 |
switch (id) { |
|
5288 |
case HierarchyEvent.HIERARCHY_CHANGED: |
|
5289 |
if (hierarchyListener != null || |
|
5290 |
(eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 || |
|
5291 |
enabledOnToolkit) { |
|
5292 |
HierarchyEvent e = new HierarchyEvent(this, id, changed, |
|
5293 |
changedParent, |
|
5294 |
changeFlags); |
|
5295 |
dispatchEvent(e); |
|
5296 |
return 1; |
|
5297 |
} |
|
5298 |
break; |
|
5299 |
case HierarchyEvent.ANCESTOR_MOVED: |
|
5300 |
case HierarchyEvent.ANCESTOR_RESIZED: |
|
5301 |
if (eventLog.isLoggable(Level.FINE)) { |
|
5302 |
if (changeFlags != 0) { |
|
5303 |
eventLog.log(Level.FINE, "Assertion (changeFlags == 0) failed"); |
|
5304 |
} |
|
5305 |
} |
|
5306 |
if (hierarchyBoundsListener != null || |
|
5307 |
(eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 || |
|
5308 |
enabledOnToolkit) { |
|
5309 |
HierarchyEvent e = new HierarchyEvent(this, id, changed, |
|
5310 |
changedParent); |
|
5311 |
dispatchEvent(e); |
|
5312 |
return 1; |
|
5313 |
} |
|
5314 |
break; |
|
5315 |
default: |
|
5316 |
// assert false |
|
5317 |
if (eventLog.isLoggable(Level.FINE)) { |
|
5318 |
eventLog.log(Level.FINE, "This code must never be reached"); |
|
5319 |
} |
|
5320 |
break; |
|
5321 |
} |
|
5322 |
return 0; |
|
5323 |
} |
|
5324 |
||
5325 |
/** |
|
5326 |
* Returns an array of all the hierarchy bounds listeners |
|
5327 |
* registered on this component. |
|
5328 |
* |
|
5329 |
* @return all of this component's <code>HierarchyBoundsListener</code>s |
|
5330 |
* or an empty array if no hierarchy bounds |
|
5331 |
* listeners are currently registered |
|
5332 |
* |
|
5333 |
* @see #addHierarchyBoundsListener |
|
5334 |
* @see #removeHierarchyBoundsListener |
|
5335 |
* @since 1.4 |
|
5336 |
*/ |
|
5337 |
public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners() { |
|
5338 |
return (HierarchyBoundsListener[]) |
|
5339 |
(getListeners(HierarchyBoundsListener.class)); |
|
5340 |
} |
|
5341 |
||
5342 |
/* |
|
5343 |
* Should only be called while holding the tree lock. |
|
5344 |
* It's added only for overriding in java.awt.Window |
|
5345 |
* because parent in Window is owner. |
|
5346 |
*/ |
|
5347 |
void adjustListeningChildrenOnParent(long mask, int num) { |
|
5348 |
if (parent != null) { |
|
5349 |
parent.adjustListeningChildren(mask, num); |
|
5350 |
} |
|
5351 |
} |
|
5352 |
||
5353 |
/** |
|
5354 |
* Adds the specified key listener to receive key events from |
|
5355 |
* this component. |
|
5356 |
* If l is null, no exception is thrown and no action is performed. |
|
5357 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5358 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5359 |
* |
|
5360 |
* @param l the key listener. |
|
5361 |
* @see java.awt.event.KeyEvent |
|
5362 |
* @see java.awt.event.KeyListener |
|
5363 |
* @see #removeKeyListener |
|
5364 |
* @see #getKeyListeners |
|
5365 |
* @since JDK1.1 |
|
5366 |
*/ |
|
5367 |
public synchronized void addKeyListener(KeyListener l) { |
|
5368 |
if (l == null) { |
|
5369 |
return; |
|
5370 |
} |
|
5371 |
keyListener = AWTEventMulticaster.add(keyListener, l); |
|
5372 |
newEventsOnly = true; |
|
5373 |
||
5374 |
// if this is a lightweight component, enable key events |
|
5375 |
// in the native container. |
|
5376 |
if (peer instanceof LightweightPeer) { |
|
5377 |
parent.proxyEnableEvents(AWTEvent.KEY_EVENT_MASK); |
|
5378 |
} |
|
5379 |
} |
|
5380 |
||
5381 |
/** |
|
5382 |
* Removes the specified key listener so that it no longer |
|
5383 |
* receives key events from this component. This method performs |
|
5384 |
* no function, nor does it throw an exception, if the listener |
|
5385 |
* specified by the argument was not previously added to this component. |
|
5386 |
* If listener <code>l</code> is <code>null</code>, |
|
5387 |
* no exception is thrown and no action is performed. |
|
5388 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5389 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5390 |
* |
|
5391 |
* @param l the key listener |
|
5392 |
* @see java.awt.event.KeyEvent |
|
5393 |
* @see java.awt.event.KeyListener |
|
5394 |
* @see #addKeyListener |
|
5395 |
* @see #getKeyListeners |
|
5396 |
* @since JDK1.1 |
|
5397 |
*/ |
|
5398 |
public synchronized void removeKeyListener(KeyListener l) { |
|
5399 |
if (l == null) { |
|
5400 |
return; |
|
5401 |
} |
|
5402 |
keyListener = AWTEventMulticaster.remove(keyListener, l); |
|
5403 |
} |
|
5404 |
||
5405 |
/** |
|
5406 |
* Returns an array of all the key listeners |
|
5407 |
* registered on this component. |
|
5408 |
* |
|
5409 |
* @return all of this component's <code>KeyListener</code>s |
|
5410 |
* or an empty array if no key |
|
5411 |
* listeners are currently registered |
|
5412 |
* |
|
5413 |
* @see #addKeyListener |
|
5414 |
* @see #removeKeyListener |
|
5415 |
* @since 1.4 |
|
5416 |
*/ |
|
5417 |
public synchronized KeyListener[] getKeyListeners() { |
|
5418 |
return (KeyListener[]) (getListeners(KeyListener.class)); |
|
5419 |
} |
|
5420 |
||
5421 |
/** |
|
5422 |
* Adds the specified mouse listener to receive mouse events from |
|
5423 |
* this component. |
|
5424 |
* If listener <code>l</code> is <code>null</code>, |
|
5425 |
* no exception is thrown and no action is performed. |
|
5426 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5427 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5428 |
* |
|
5429 |
* @param l the mouse listener |
|
5430 |
* @see java.awt.event.MouseEvent |
|
5431 |
* @see java.awt.event.MouseListener |
|
5432 |
* @see #removeMouseListener |
|
5433 |
* @see #getMouseListeners |
|
5434 |
* @since JDK1.1 |
|
5435 |
*/ |
|
5436 |
public synchronized void addMouseListener(MouseListener l) { |
|
5437 |
if (l == null) { |
|
5438 |
return; |
|
5439 |
} |
|
5440 |
mouseListener = AWTEventMulticaster.add(mouseListener,l); |
|
5441 |
newEventsOnly = true; |
|
5442 |
||
5443 |
// if this is a lightweight component, enable mouse events |
|
5444 |
// in the native container. |
|
5445 |
if (peer instanceof LightweightPeer) { |
|
5446 |
parent.proxyEnableEvents(AWTEvent.MOUSE_EVENT_MASK); |
|
5447 |
} |
|
5448 |
} |
|
5449 |
||
5450 |
/** |
|
5451 |
* Removes the specified mouse listener so that it no longer |
|
5452 |
* receives mouse events from this component. This method performs |
|
5453 |
* no function, nor does it throw an exception, if the listener |
|
5454 |
* specified by the argument was not previously added to this component. |
|
5455 |
* If listener <code>l</code> is <code>null</code>, |
|
5456 |
* no exception is thrown and no action is performed. |
|
5457 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5458 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5459 |
* |
|
5460 |
* @param l the mouse listener |
|
5461 |
* @see java.awt.event.MouseEvent |
|
5462 |
* @see java.awt.event.MouseListener |
|
5463 |
* @see #addMouseListener |
|
5464 |
* @see #getMouseListeners |
|
5465 |
* @since JDK1.1 |
|
5466 |
*/ |
|
5467 |
public synchronized void removeMouseListener(MouseListener l) { |
|
5468 |
if (l == null) { |
|
5469 |
return; |
|
5470 |
} |
|
5471 |
mouseListener = AWTEventMulticaster.remove(mouseListener, l); |
|
5472 |
} |
|
5473 |
||
5474 |
/** |
|
5475 |
* Returns an array of all the mouse listeners |
|
5476 |
* registered on this component. |
|
5477 |
* |
|
5478 |
* @return all of this component's <code>MouseListener</code>s |
|
5479 |
* or an empty array if no mouse |
|
5480 |
* listeners are currently registered |
|
5481 |
* |
|
5482 |
* @see #addMouseListener |
|
5483 |
* @see #removeMouseListener |
|
5484 |
* @since 1.4 |
|
5485 |
*/ |
|
5486 |
public synchronized MouseListener[] getMouseListeners() { |
|
5487 |
return (MouseListener[]) (getListeners(MouseListener.class)); |
|
5488 |
} |
|
5489 |
||
5490 |
/** |
|
5491 |
* Adds the specified mouse motion listener to receive mouse motion |
|
5492 |
* events from this component. |
|
5493 |
* If listener <code>l</code> is <code>null</code>, |
|
5494 |
* no exception is thrown and no action is performed. |
|
5495 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5496 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5497 |
* |
|
5498 |
* @param l the mouse motion listener |
|
5499 |
* @see java.awt.event.MouseEvent |
|
5500 |
* @see java.awt.event.MouseMotionListener |
|
5501 |
* @see #removeMouseMotionListener |
|
5502 |
* @see #getMouseMotionListeners |
|
5503 |
* @since JDK1.1 |
|
5504 |
*/ |
|
5505 |
public synchronized void addMouseMotionListener(MouseMotionListener l) { |
|
5506 |
if (l == null) { |
|
5507 |
return; |
|
5508 |
} |
|
5509 |
mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener,l); |
|
5510 |
newEventsOnly = true; |
|
5511 |
||
5512 |
// if this is a lightweight component, enable mouse events |
|
5513 |
// in the native container. |
|
5514 |
if (peer instanceof LightweightPeer) { |
|
5515 |
parent.proxyEnableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK); |
|
5516 |
} |
|
5517 |
} |
|
5518 |
||
5519 |
/** |
|
5520 |
* Removes the specified mouse motion listener so that it no longer |
|
5521 |
* receives mouse motion events from this component. This method performs |
|
5522 |
* no function, nor does it throw an exception, if the listener |
|
5523 |
* specified by the argument was not previously added to this component. |
|
5524 |
* If listener <code>l</code> is <code>null</code>, |
|
5525 |
* no exception is thrown and no action is performed. |
|
5526 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5527 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5528 |
* |
|
5529 |
* @param l the mouse motion listener |
|
5530 |
* @see java.awt.event.MouseEvent |
|
5531 |
* @see java.awt.event.MouseMotionListener |
|
5532 |
* @see #addMouseMotionListener |
|
5533 |
* @see #getMouseMotionListeners |
|
5534 |
* @since JDK1.1 |
|
5535 |
*/ |
|
5536 |
public synchronized void removeMouseMotionListener(MouseMotionListener l) { |
|
5537 |
if (l == null) { |
|
5538 |
return; |
|
5539 |
} |
|
5540 |
mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, l); |
|
5541 |
} |
|
5542 |
||
5543 |
/** |
|
5544 |
* Returns an array of all the mouse motion listeners |
|
5545 |
* registered on this component. |
|
5546 |
* |
|
5547 |
* @return all of this component's <code>MouseMotionListener</code>s |
|
5548 |
* or an empty array if no mouse motion |
|
5549 |
* listeners are currently registered |
|
5550 |
* |
|
5551 |
* @see #addMouseMotionListener |
|
5552 |
* @see #removeMouseMotionListener |
|
5553 |
* @since 1.4 |
|
5554 |
*/ |
|
5555 |
public synchronized MouseMotionListener[] getMouseMotionListeners() { |
|
5556 |
return (MouseMotionListener[]) (getListeners(MouseMotionListener.class)); |
|
5557 |
} |
|
5558 |
||
5559 |
/** |
|
5560 |
* Adds the specified mouse wheel listener to receive mouse wheel events |
|
5561 |
* from this component. Containers also receive mouse wheel events from |
|
5562 |
* sub-components. |
|
5563 |
* <p> |
|
5564 |
* For information on how mouse wheel events are dispatched, see |
|
5565 |
* the class description for {@link MouseWheelEvent}. |
|
5566 |
* <p> |
|
5567 |
* If l is <code>null</code>, no exception is thrown and no |
|
5568 |
* action is performed. |
|
5569 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5570 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5571 |
* |
|
5572 |
* @param l the mouse wheel listener |
|
5573 |
* @see java.awt.event.MouseWheelEvent |
|
5574 |
* @see java.awt.event.MouseWheelListener |
|
5575 |
* @see #removeMouseWheelListener |
|
5576 |
* @see #getMouseWheelListeners |
|
5577 |
* @since 1.4 |
|
5578 |
*/ |
|
5579 |
public synchronized void addMouseWheelListener(MouseWheelListener l) { |
|
5580 |
if (l == null) { |
|
5581 |
return; |
|
5582 |
} |
|
5583 |
mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener,l); |
|
5584 |
newEventsOnly = true; |
|
5585 |
||
5586 |
// if this is a lightweight component, enable mouse events |
|
5587 |
// in the native container. |
|
5588 |
if (peer instanceof LightweightPeer) { |
|
5589 |
parent.proxyEnableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK); |
|
5590 |
} |
|
5591 |
} |
|
5592 |
||
5593 |
/** |
|
5594 |
* Removes the specified mouse wheel listener so that it no longer |
|
5595 |
* receives mouse wheel events from this component. This method performs |
|
5596 |
* no function, nor does it throw an exception, if the listener |
|
5597 |
* specified by the argument was not previously added to this component. |
|
5598 |
* If l is null, no exception is thrown and no action is performed. |
|
5599 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5600 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5601 |
* |
|
5602 |
* @param l the mouse wheel listener. |
|
5603 |
* @see java.awt.event.MouseWheelEvent |
|
5604 |
* @see java.awt.event.MouseWheelListener |
|
5605 |
* @see #addMouseWheelListener |
|
5606 |
* @see #getMouseWheelListeners |
|
5607 |
* @since 1.4 |
|
5608 |
*/ |
|
5609 |
public synchronized void removeMouseWheelListener(MouseWheelListener l) { |
|
5610 |
if (l == null) { |
|
5611 |
return; |
|
5612 |
} |
|
5613 |
mouseWheelListener = AWTEventMulticaster.remove(mouseWheelListener, l); |
|
5614 |
} |
|
5615 |
||
5616 |
/** |
|
5617 |
* Returns an array of all the mouse wheel listeners |
|
5618 |
* registered on this component. |
|
5619 |
* |
|
5620 |
* @return all of this component's <code>MouseWheelListener</code>s |
|
5621 |
* or an empty array if no mouse wheel |
|
5622 |
* listeners are currently registered |
|
5623 |
* |
|
5624 |
* @see #addMouseWheelListener |
|
5625 |
* @see #removeMouseWheelListener |
|
5626 |
* @since 1.4 |
|
5627 |
*/ |
|
5628 |
public synchronized MouseWheelListener[] getMouseWheelListeners() { |
|
5629 |
return (MouseWheelListener[]) (getListeners(MouseWheelListener.class)); |
|
5630 |
} |
|
5631 |
||
5632 |
/** |
|
5633 |
* Adds the specified input method listener to receive |
|
5634 |
* input method events from this component. A component will |
|
5635 |
* only receive input method events from input methods |
|
5636 |
* if it also overrides <code>getInputMethodRequests</code> to return an |
|
5637 |
* <code>InputMethodRequests</code> instance. |
|
5638 |
* If listener <code>l</code> is <code>null</code>, |
|
5639 |
* no exception is thrown and no action is performed. |
|
5640 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5641 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5642 |
* |
|
5643 |
* @param l the input method listener |
|
5644 |
* @see java.awt.event.InputMethodEvent |
|
5645 |
* @see java.awt.event.InputMethodListener |
|
5646 |
* @see #removeInputMethodListener |
|
5647 |
* @see #getInputMethodListeners |
|
5648 |
* @see #getInputMethodRequests |
|
5649 |
* @since 1.2 |
|
5650 |
*/ |
|
5651 |
public synchronized void addInputMethodListener(InputMethodListener l) { |
|
5652 |
if (l == null) { |
|
5653 |
return; |
|
5654 |
} |
|
5655 |
inputMethodListener = AWTEventMulticaster.add(inputMethodListener, l); |
|
5656 |
newEventsOnly = true; |
|
5657 |
} |
|
5658 |
||
5659 |
/** |
|
5660 |
* Removes the specified input method listener so that it no longer |
|
5661 |
* receives input method events from this component. This method performs |
|
5662 |
* no function, nor does it throw an exception, if the listener |
|
5663 |
* specified by the argument was not previously added to this component. |
|
5664 |
* If listener <code>l</code> is <code>null</code>, |
|
5665 |
* no exception is thrown and no action is performed. |
|
5666 |
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" |
|
5667 |
* >AWT Threading Issues</a> for details on AWT's threading model. |
|
5668 |
* |
|
5669 |
* @param l the input method listener |
|
5670 |
* @see java.awt.event.InputMethodEvent |
|
5671 |
* @see java.awt.event.InputMethodListener |
|
5672 |
* @see #addInputMethodListener |
|
5673 |
* @see #getInputMethodListeners |
|
5674 |
* @since 1.2 |
|
5675 |
*/ |
|
5676 |
public synchronized void removeInputMethodListener(InputMethodListener l) { |
|
5677 |
if (l == null) { |
|
5678 |
return; |
|
5679 |
} |
|
5680 |
inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, l); |
|
5681 |
} |
|
5682 |
||
5683 |
/** |
|
5684 |
* Returns an array of all the input method listeners |
|
5685 |
* registered on this component. |
|
5686 |
* |
|
5687 |
* @return all of this component's <code>InputMethodListener</code>s |
|
5688 |
* or an empty array if no input method |
|
5689 |
* listeners are currently registered |
|
5690 |
* |
|
5691 |
* @see #addInputMethodListener |
|
5692 |
* @see #removeInputMethodListener |
|
5693 |
* @since 1.4 |
|
5694 |
*/ |
|
5695 |
public synchronized InputMethodListener[] getInputMethodListeners() { |
|
5696 |
return (InputMethodListener[]) (getListeners(InputMethodListener.class)); |
|
5697 |
} |
|
5698 |
||
5699 |
/** |
|
5700 |
* Returns an array of all the objects currently registered |
|
5701 |
* as <code><em>Foo</em>Listener</code>s |
|
5702 |
* upon this <code>Component</code>. |
|
5703 |
* <code><em>Foo</em>Listener</code>s are registered using the |
|
5704 |
* <code>add<em>Foo</em>Listener</code> method. |
|
5705 |
* |
|
5706 |
* <p> |
|
5707 |
* You can specify the <code>listenerType</code> argument |
|
5708 |
* with a class literal, such as |
|
5709 |
* <code><em>Foo</em>Listener.class</code>. |
|
5710 |
* For example, you can query a |
|
5711 |
* <code>Component</code> <code>c</code> |
|
5712 |
* for its mouse listeners with the following code: |
|
5713 |
* |
|
5714 |
* <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre> |
|
5715 |
* |
|
5716 |
* If no such listeners exist, this method returns an empty array. |
|
5717 |
* |
|
5718 |
* @param listenerType the type of listeners requested; this parameter |
|
5719 |
* should specify an interface that descends from |
|
5720 |
* <code>java.util.EventListener</code> |
|
5721 |
* @return an array of all objects registered as |
|
5722 |
* <code><em>Foo</em>Listener</code>s on this component, |
|
5723 |
* or an empty array if no such listeners have been added |
|
5724 |
* @exception ClassCastException if <code>listenerType</code> |
|
5725 |
* doesn't specify a class or interface that implements |
|
5726 |
* <code>java.util.EventListener</code> |
|
5727 |
* |
|
5728 |
* @see #getComponentListeners |
|
5729 |
* @see #getFocusListeners |
|
5730 |
* @see #getHierarchyListeners |
|
5731 |
* @see #getHierarchyBoundsListeners |
|
5732 |
* @see #getKeyListeners |
|
5733 |
* @see #getMouseListeners |
|
5734 |
* @see #getMouseMotionListeners |
|
5735 |
* @see #getMouseWheelListeners |
|
5736 |
* @see #getInputMethodListeners |
|
5737 |
* @see #getPropertyChangeListeners |
|
5738 |
* |
|
5739 |
* @since 1.3 |
|
5740 |
*/ |
|
5741 |
public <T extends EventListener> T[] getListeners(Class<T> listenerType) { |
|
5742 |
EventListener l = null; |
|
5743 |
if (listenerType == ComponentListener.class) { |
|
5744 |
l = componentListener; |
|
5745 |
} else if (listenerType == FocusListener.class) { |
|
5746 |
l = focusListener; |
|
5747 |
} else if (listenerType == HierarchyListener.class) { |
|
5748 |
l = hierarchyListener; |
|
5749 |
} else if (listenerType == HierarchyBoundsListener.class) { |
|
5750 |
l = hierarchyBoundsListener; |
|
5751 |
} else if (listenerType == KeyListener.class) { |
|
5752 |
l = keyListener; |
|
5753 |
} else if (listenerType == MouseListener.class) { |
|
5754 |
l = mouseListener; |
|
5755 |
} else if (listenerType == MouseMotionListener.class) { |
|
5756 |
l = mouseMotionListener; |
|
5757 |
} else if (listenerType == MouseWheelListener.class) { |
|
5758 |
l = mouseWheelListener; |
|
5759 |
} else if (listenerType == InputMethodListener.class) { |
|
5760 |
l = inputMethodListener; |
|
5761 |
} else if (listenerType == PropertyChangeListener.class) { |
|
5762 |
return (T[])getPropertyChangeListeners(); |
|
5763 |
} |
|
5764 |
return AWTEventMulticaster.getListeners(l, listenerType); |
|
5765 |
} |
|
5766 |
||
5767 |
/** |
|
5768 |
* Gets the input method request handler which supports |
|
5769 |
* requests from input methods for this component. A component |
|
5770 |
* that supports on-the-spot text input must override this |
|
5771 |
* method to return an <code>InputMethodRequests</code> instance. |
|
5772 |
* At the same time, it also has to handle input method events. |
|
5773 |
* |
|
5774 |
* @return the input method request handler for this component, |
|
5775 |
* <code>null</code> by default |
|
5776 |
* @see #addInputMethodListener |
|
5777 |
* @since 1.2 |
|
5778 |
*/ |
|
5779 |
public InputMethodRequests getInputMethodRequests() { |
|
5780 |
return null; |
|
5781 |
} |
|
5782 |
||
5783 |
/** |
|
5784 |
* Gets the input context used by this component for handling |
|
5785 |
* the communication with input methods when text is entered |
|
5786 |
* in this component. By default, the input context used for |
|
5787 |
* the parent component is returned. Components may |
|
5788 |
* override this to return a private input context. |
|
5789 |
* |
|
5790 |
* @return the input context used by this component; |
|
5791 |
* <code>null</code> if no context can be determined |
|
5792 |
* @since 1.2 |
|
5793 |
*/ |
|
5794 |
public InputContext getInputContext() { |
|
5795 |
Container parent = this.parent; |
|
5796 |
if (parent == null) { |
|
5797 |
return null; |
|
5798 |
} else { |
|
5799 |
return parent.getInputContext(); |
|
5800 |
} |
|
5801 |
} |
|
5802 |
||
5803 |
/** |
|
5804 |
* Enables the events defined by the specified event mask parameter |
|
5805 |
* to be delivered to this component. |
|
5806 |
* <p> |
|
5807 |
* Event types are automatically enabled when a listener for |
|
5808 |
* that event type is added to the component. |
|
5809 |
* <p> |
|
5810 |
* This method only needs to be invoked by subclasses of |
|
5811 |
* <code>Component</code> which desire to have the specified event |
|
5812 |
* types delivered to <code>processEvent</code> regardless of whether |
|
5813 |
* or not a listener is registered. |
|
5814 |
* @param eventsToEnable the event mask defining the event types |
|
5815 |
* @see #processEvent |
|
5816 |
* @see #disableEvents |
|
5817 |
* @see AWTEvent |
|
5818 |
* @since JDK1.1 |
|
5819 |
*/ |
|
5820 |
protected final void enableEvents(long eventsToEnable) { |
|
5821 |
long notifyAncestors = 0; |
|
5822 |
synchronized (this) { |
|
5823 |
if ((eventsToEnable & AWTEvent.HIERARCHY_EVENT_MASK) != 0 && |
|
5824 |
hierarchyListener == null && |
|
5825 |
(eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0) { |
|
5826 |
notifyAncestors |= AWTEvent.HIERARCHY_EVENT_MASK; |
|
5827 |
} |
|
5828 |
if ((eventsToEnable & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 && |
|
5829 |
hierarchyBoundsListener == null && |
|
5830 |
(eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0) { |
|
5831 |
notifyAncestors |= AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK; |
|
5832 |
} |
|
5833 |
eventMask |= eventsToEnable; |
|
5834 |
newEventsOnly = true; |
|
5835 |
} |
|
5836 |
||
5837 |
// if this is a lightweight component, enable mouse events |
|
5838 |
// in the native container. |
|
5839 |
if (peer instanceof LightweightPeer) { |
|
5840 |
parent.proxyEnableEvents(eventMask); |
|
5841 |
} |
|
5842 |
if (notifyAncestors != 0) { |
|
5843 |
synchronized (getTreeLock()) { |
|
5844 |
adjustListeningChildrenOnParent(notifyAncestors, 1); |
|
5845 |
} |
|
5846 |
} |
|
5847 |
} |
|
5848 |
||
5849 |
/** |
|
5850 |
* Disables the events defined by the specified event mask parameter |
|
5851 |
* from being delivered to this component. |
|
5852 |
* @param eventsToDisable the event mask defining the event types |
|
5853 |
* @see #enableEvents |
|
5854 |
* @since JDK1.1 |
|
5855 |
*/ |
|
5856 |
protected final void disableEvents(long eventsToDisable) { |
|
5857 |
long notifyAncestors = 0; |
|
5858 |
synchronized (this) { |
|
5859 |
if ((eventsToDisable & AWTEvent.HIERARCHY_EVENT_MASK) != 0 && |
|
5860 |
hierarchyListener == null && |
|
5861 |
(eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0) { |
|
5862 |
notifyAncestors |= AWTEvent.HIERARCHY_EVENT_MASK; |
|
5863 |
} |
|
5864 |
if ((eventsToDisable & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)!=0 && |
|
5865 |
hierarchyBoundsListener == null && |
|
5866 |
(eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0) { |
|
5867 |
notifyAncestors |= AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK; |
|
5868 |
} |
|
5869 |
eventMask &= ~eventsToDisable; |
|
5870 |
} |
|
5871 |
if (notifyAncestors != 0) { |
|
5872 |
synchronized (getTreeLock()) { |
|
5873 |
adjustListeningChildrenOnParent(notifyAncestors, -1); |
|
5874 |
} |
|
5875 |
} |
|
5876 |
} |
|
5877 |
||
1181
c5971dbeaaaa
6693974: Unify EventQueue$EventQueueItem and SunToolkit.$EventQueueItem classes
dav
parents:
1172
diff
changeset
|
5878 |
transient sun.awt.EventQueueItem[] eventCache; |
2 | 5879 |
|
5880 |
/** |
|
5881 |
* @see #isCoalescingEnabled |
|
5882 |
* @see #checkCoalescing |
|
5883 |
*/ |
|
5884 |
transient private boolean coalescingEnabled = checkCoalescing(); |
|
5885 |
||
5886 |
/** |
|
5887 |
* Weak map of known coalesceEvent overriders. |
|
5888 |
* Value indicates whether overriden. |
|
5889 |
* Bootstrap classes are not included. |
|
5890 |
*/ |
|
5891 |
private static final Map<Class<?>, Boolean> coalesceMap = |
|
5892 |
new java.util.WeakHashMap<Class<?>, Boolean>(); |
|
5893 |
||
5894 |
/** |
|
5895 |
* Indicates whether this class overrides coalesceEvents. |
|
5896 |
* It is assumed that all classes that are loaded from the bootstrap |
|
5897 |
* do not. |
|
5898 |
* The boostrap class loader is assumed to be represented by null. |
|
5899 |
* We do not check that the method really overrides |
|
5900 |
* (it might be static, private or package private). |
|
5901 |
*/ |
|
5902 |
private boolean checkCoalescing() { |
|
5903 |
if (getClass().getClassLoader()==null) { |
|
5904 |
return false; |
|
5905 |
} |
|
5906 |
final Class<? extends Component> clazz = getClass(); |
|
5907 |
synchronized (coalesceMap) { |
|
5908 |
// Check cache. |
|
5909 |
Boolean value = coalesceMap.get(clazz); |
|
5910 |
if (value != null) { |
|
5911 |
return value; |
|
5912 |
} |
|
5913 |
||
5914 |
// Need to check non-bootstraps. |
|
5915 |
Boolean enabled = java.security.AccessController.doPrivileged( |
|
5916 |
new java.security.PrivilegedAction<Boolean>() { |
|
5917 |
public Boolean run() { |
|
5918 |
return isCoalesceEventsOverriden(clazz); |
|
5919 |
} |
|
5920 |
} |
|
5921 |
); |
|
5922 |
coalesceMap.put(clazz, enabled); |
|
5923 |
return enabled; |
|
5924 |
} |
|
5925 |
} |
|
5926 |
||
5927 |
/** |
|
5928 |
* Parameter types of coalesceEvents(AWTEvent,AWTEVent). |
|
5929 |
*/ |
|
5930 |
private static final Class[] coalesceEventsParams = { |
|
5931 |
AWTEvent.class, AWTEvent.class |
|
5932 |
}; |
|
5933 |
||
5934 |
/** |
|
5935 |
* Indicates whether a class or its superclasses override coalesceEvents. |
|
5936 |
* Must be called with lock on coalesceMap and privileged. |
|
5937 |
* @see checkCoalsecing |
|
5938 |
*/ |
|
5939 |
private static boolean isCoalesceEventsOverriden(Class<?> clazz) { |
|
5940 |
assert Thread.holdsLock(coalesceMap); |
|
5941 |
||
5942 |
// First check superclass - we may not need to bother ourselves. |
|
5943 |
Class<?> superclass = clazz.getSuperclass(); |
|
5944 |
if (superclass == null) { |
|
5945 |
// Only occurs on implementations that |
|
5946 |
// do not use null to represent the bootsrap class loader. |
|
5947 |
return false; |
|
5948 |
} |
|
5949 |
if (superclass.getClassLoader() != null) { |
|
5950 |
Boolean value = coalesceMap.get(superclass); |
|
5951 |
if (value == null) { |
|
5952 |
// Not done already - recurse. |
|
5953 |
if (isCoalesceEventsOverriden(superclass)) { |
|
5954 |
coalesceMap.put(superclass, true); |
|
5955 |
return true; |
|
5956 |
} |
|
5957 |
} else if (value) { |
|
5958 |
return true; |
|
5959 |
} |
|
5960 |
} |
|
5961 |
||
5962 |
try { |
|
5963 |
// Throws if not overriden. |
|
5964 |
clazz.getDeclaredMethod( |
|
5965 |
"coalesceEvents", coalesceEventsParams |
|
5966 |
); |
|
5967 |
return true; |
|
5968 |
} catch (NoSuchMethodException e) { |
|
5969 |
// Not present in this class. |
|
5970 |
return false; |
|
5971 |
} |
|
5972 |
} |
|
5973 |
||
5974 |
/** |
|
5975 |
* Indicates whether coalesceEvents may do something. |
|
5976 |
*/ |
|
5977 |
final boolean isCoalescingEnabled() { |
|
5978 |
return coalescingEnabled; |
|
5979 |
} |
|
5980 |
||
5981 |
||
5982 |
/** |
|
5983 |
* Potentially coalesce an event being posted with an existing |
|
5984 |
* event. This method is called by <code>EventQueue.postEvent</code> |
|
5985 |
* if an event with the same ID as the event to be posted is found in |
|
5986 |
* the queue (both events must have this component as their source). |
|
5987 |
* This method either returns a coalesced event which replaces |
|
5988 |
* the existing event (and the new event is then discarded), or |
|
5989 |
* <code>null</code> to indicate that no combining should be done |
|
5990 |
* (add the second event to the end of the queue). Either event |
|
5991 |
* parameter may be modified and returned, as the other one is discarded |
|
5992 |
* unless <code>null</code> is returned. |
|
5993 |
* <p> |
|
5994 |
* This implementation of <code>coalesceEvents</code> coalesces |
|
5995 |
* two event types: mouse move (and drag) events, |
|
5996 |
* and paint (and update) events. |
|
5997 |
* For mouse move events the last event is always returned, causing |
|
5998 |
* intermediate moves to be discarded. For paint events, the new |
|
5999 |
* event is coalesced into a complex <code>RepaintArea</code> in the peer. |
|
6000 |
* The new <code>AWTEvent</code> is always returned. |
|
6001 |
* |
|
6002 |
* @param existingEvent the event already on the <code>EventQueue</code> |
|
6003 |
* @param newEvent the event being posted to the |
|
6004 |
* <code>EventQueue</code> |
|
6005 |
* @return a coalesced event, or <code>null</code> indicating that no |
|
6006 |
* coalescing was done |
|
6007 |
*/ |
|
6008 |
protected AWTEvent coalesceEvents(AWTEvent existingEvent, |
|
6009 |
AWTEvent newEvent) { |
|
6010 |
return null; |
|
6011 |
} |
|
6012 |
||
6013 |
/** |
|
6014 |
* Processes events occurring on this component. By default this |
|
6015 |
* method calls the appropriate |
|
6016 |
* <code>process<event type>Event</code> |
|
6017 |
* method for the given class of event. |
|
6018 |
* <p>Note that if the event parameter is <code>null</code> |
|
6019 |
* the behavior is unspecified and may result in an |
|
6020 |
* exception. |
|
6021 |
* |
|
6022 |
* @param e the event |
|
6023 |
* @see #processComponentEvent |
|
6024 |
* @see #processFocusEvent |
|
6025 |
* @see #processKeyEvent |
|
6026 |
* @see #processMouseEvent |
|
6027 |
* @see #processMouseMotionEvent |
|
6028 |
* @see #processInputMethodEvent |
|
6029 |
* @see #processHierarchyEvent |
|
6030 |
* @see #processMouseWheelEvent |
|
6031 |
* @since JDK1.1 |
|
6032 |
*/ |
|
6033 |
protected void processEvent(AWTEvent e) { |
|
6034 |
if (e instanceof FocusEvent) { |
|
6035 |
processFocusEvent((FocusEvent)e); |
|
6036 |
||
6037 |
} else if (e instanceof MouseEvent) { |
|
6038 |
switch(e.getID()) { |
|
6039 |
case MouseEvent.MOUSE_PRESSED: |
|
6040 |
case MouseEvent.MOUSE_RELEASED: |
|
6041 |
case MouseEvent.MOUSE_CLICKED: |
|
6042 |
case MouseEvent.MOUSE_ENTERED: |
|
6043 |
case MouseEvent.MOUSE_EXITED: |
|
6044 |
processMouseEvent((MouseEvent)e); |
|
6045 |
break; |
|
6046 |
case MouseEvent.MOUSE_MOVED: |
|
6047 |
case MouseEvent.MOUSE_DRAGGED: |
|
6048 |
processMouseMotionEvent((MouseEvent)e); |
|
6049 |
break; |
|
6050 |
case MouseEvent.MOUSE_WHEEL: |
|
6051 |
processMouseWheelEvent((MouseWheelEvent)e); |
|
6052 |
break; |
|
6053 |
} |
|
6054 |
||
6055 |
} else if (e instanceof KeyEvent) { |
|
6056 |
processKeyEvent((KeyEvent)e); |
|
6057 |
||
6058 |
} else if (e instanceof ComponentEvent) { |
|
6059 |
processComponentEvent((ComponentEvent)e); |
|
6060 |
} else if (e instanceof InputMethodEvent) { |
|
6061 |
processInputMethodEvent((InputMethodEvent)e); |
|
6062 |
} else if (e instanceof HierarchyEvent) { |
|
6063 |
switch (e.getID()) { |
|
6064 |
case HierarchyEvent.HIERARCHY_CHANGED: |
|
6065 |
processHierarchyEvent((HierarchyEvent)e); |
|
6066 |
break; |
|
6067 |
case HierarchyEvent.ANCESTOR_MOVED: |
|
6068 |
case HierarchyEvent.ANCESTOR_RESIZED: |
|
6069 |
processHierarchyBoundsEvent((HierarchyEvent)e); |
|
6070 |
break; |
|
6071 |
} |
|
6072 |
} |
|
6073 |
} |
|
6074 |
||
6075 |
/** |
|
6076 |
* Processes component events occurring on this component by |
|
6077 |
* dispatching them to any registered |
|
6078 |
* <code>ComponentListener</code> objects. |
|
6079 |
* <p> |
|
6080 |
* This method is not called unless component events are |
|
6081 |
* enabled for this component. Component events are enabled |
|
6082 |
* when one of the following occurs: |
|
6083 |
* <p><ul> |
|
6084 |
* <li>A <code>ComponentListener</code> object is registered |
|
6085 |
* via <code>addComponentListener</code>. |
|
6086 |
* <li>Component events are enabled via <code>enableEvents</code>. |
|
6087 |
* </ul> |
|
6088 |
* <p>Note that if the event parameter is <code>null</code> |
|
6089 |
* the behavior is unspecified and may result in an |
|
6090 |
* exception. |
|
6091 |
* |
|
6092 |
* @param e the component event |
|
6093 |
* @see java.awt.event.ComponentEvent |
|
6094 |
* @see java.awt.event.ComponentListener |
|
6095 |
* @see #addComponentListener |
|
6096 |
* @see #enableEvents |
|
6097 |
* @since JDK1.1 |
|
6098 |
*/ |
|
6099 |
protected void processComponentEvent(ComponentEvent e) { |
|
6100 |
ComponentListener listener = componentListener; |
|
6101 |
if (listener != null) { |
|
6102 |
int id = e.getID(); |
|
6103 |
switch(id) { |
|
6104 |
case ComponentEvent.COMPONENT_RESIZED: |
|
6105 |
listener.componentResized(e); |
|
6106 |
break; |
|
6107 |
case ComponentEvent.COMPONENT_MOVED: |
|
6108 |
listener.componentMoved(e); |
|
6109 |
break; |
|
6110 |
case ComponentEvent.COMPONENT_SHOWN: |
|
6111 |
listener.componentShown(e); |
|
6112 |
break; |
|
6113 |
case ComponentEvent.COMPONENT_HIDDEN: |
|
6114 |
listener.componentHidden(e); |
|
6115 |
break; |
|
6116 |
} |
|
6117 |
} |
|
6118 |
} |
|
6119 |
||
6120 |
/** |
|
6121 |
* Processes focus events occurring on this component by |
|
6122 |
* dispatching them to any registered |
|
6123 |
* <code>FocusListener</code> objects. |
|
6124 |
* <p> |
|
6125 |
* This method is not called unless focus events are |
|
6126 |
* enabled for this component. Focus events are enabled |
|
6127 |
* when one of the following occurs: |
|
6128 |
* <p><ul> |
|
6129 |
* <li>A <code>FocusListener</code> object is registered |
|
6130 |
* via <code>addFocusListener</code>. |
|
6131 |
* <li>Focus events are enabled via <code>enableEvents</code>. |
|
6132 |
* </ul> |
|
6133 |
* <p> |
|
6134 |
* If focus events are enabled for a <code>Component</code>, |
|
6135 |
* the current <code>KeyboardFocusManager</code> determines |
|
6136 |
* whether or not a focus event should be dispatched to |
|
6137 |
* registered <code>FocusListener</code> objects. If the |
|
6138 |
* events are to be dispatched, the <code>KeyboardFocusManager</code> |
|
6139 |
* calls the <code>Component</code>'s <code>dispatchEvent</code> |
|
6140 |
* method, which results in a call to the <code>Component</code>'s |
|
6141 |
* <code>processFocusEvent</code> method. |
|
6142 |
* <p> |
|
6143 |
* If focus events are enabled for a <code>Component</code>, calling |
|
6144 |
* the <code>Component</code>'s <code>dispatchEvent</code> method |
|
6145 |
* with a <code>FocusEvent</code> as the argument will result in a |
|
6146 |
* call to the <code>Component</code>'s <code>processFocusEvent</code> |
|
6147 |
* method regardless of the current <code>KeyboardFocusManager</code>. |
|
6148 |
* <p> |
|
6149 |
* <p>Note that if the event parameter is <code>null</code> |
|
6150 |
* the behavior is unspecified and may result in an |
|
6151 |
* exception. |
|
6152 |
* |
|
6153 |
* @param e the focus event |
|
6154 |
* @see java.awt.event.FocusEvent |
|
6155 |
* @see java.awt.event.FocusListener |
|
6156 |
* @see java.awt.KeyboardFocusManager |
|
6157 |
* @see #addFocusListener |
|
6158 |
* @see #enableEvents |
|
6159 |
* @see #dispatchEvent |
|
6160 |
* @since JDK1.1 |
|
6161 |
*/ |
|
6162 |
protected void processFocusEvent(FocusEvent e) { |
|
6163 |
FocusListener listener = focusListener; |
|
6164 |
if (listener != null) { |
|
6165 |
int id = e.getID(); |
|
6166 |
switch(id) { |
|
6167 |
case FocusEvent.FOCUS_GAINED: |
|
6168 |
listener.focusGained(e); |
|
6169 |
break; |
|
6170 |
case FocusEvent.FOCUS_LOST: |
|
6171 |
listener.focusLost(e); |
|
6172 |
break; |
|
6173 |
} |
|
6174 |
} |
|
6175 |
} |
|
6176 |
||
6177 |
/** |
|
6178 |
* Processes key events occurring on this component by |
|
6179 |
* dispatching them to any registered |
|
6180 |
* <code>KeyListener</code> objects. |
|
6181 |
* <p> |
|
6182 |
* This method is not called unless key events are |
|
6183 |
* enabled for this component. Key events are enabled |
|
6184 |
* when one of the following occurs: |
|
6185 |
* <p><ul> |
|
6186 |
* <li>A <code>KeyListener</code> object is registered |
|
6187 |
* via <code>addKeyListener</code>. |
|
6188 |
* <li>Key events are enabled via <code>enableEvents</code>. |
|
6189 |
* </ul> |
|
6190 |
* |
|
6191 |
* <p> |
|
6192 |
* If key events are enabled for a <code>Component</code>, |
|
6193 |
* the current <code>KeyboardFocusManager</code> determines |
|
6194 |
* whether or not a key event should be dispatched to |
|
6195 |
* registered <code>KeyListener</code> objects. The |
|
6196 |
* <code>DefaultKeyboardFocusManager</code> will not dispatch |
|
6197 |
* key events to a <code>Component</code> that is not the focus |
|
6198 |
* owner or is not showing. |
|
6199 |
* <p> |
|
6200 |
* As of J2SE 1.4, <code>KeyEvent</code>s are redirected to |
|
6201 |
* the focus owner. Please see the |
|
6202 |
* <a href="doc-files/FocusSpec.html">Focus Specification</a> |
|
6203 |
* for further information. |
|
6204 |
* <p> |
|
6205 |
* Calling a <code>Component</code>'s <code>dispatchEvent</code> |
|
6206 |
* method with a <code>KeyEvent</code> as the argument will |
|
6207 |
* result in a call to the <code>Component</code>'s |
|
6208 |
* <code>processKeyEvent</code> method regardless of the |
|
6209 |
* current <code>KeyboardFocusManager</code> as long as the |
|
6210 |
* component is showing, focused, and enabled, and key events |
|
6211 |
* are enabled on it. |
|
6212 |
* <p>If the event parameter is <code>null</code> |
|
6213 |
* the behavior is unspecified and may result in an |
|
6214 |
* exception. |
|
6215 |
* |
|
6216 |
* @param e the key event |
|
6217 |
* @see java.awt.event.KeyEvent |
|
6218 |
* @see java.awt.event.KeyListener |
|
6219 |
* @see java.awt.KeyboardFocusManager |
|
6220 |
* @see java.awt.DefaultKeyboardFocusManager |
|
6221 |
* @see #processEvent |
|
6222 |
* @see #dispatchEvent |
|
6223 |
* @see #addKeyListener |
|
6224 |
* @see #enableEvents |
|
6225 |
* @see #isShowing |
|
6226 |
* @since JDK1.1 |
|
6227 |
*/ |
|
6228 |
protected void processKeyEvent(KeyEvent e) { |
|
6229 |
KeyListener listener = keyListener; |
|
6230 |
if (listener != null) { |
|
6231 |
int id = e.getID(); |
|
6232 |
switch(id) { |
|
6233 |
case KeyEvent.KEY_TYPED: |
|
6234 |
listener.keyTyped(e); |
|
6235 |
break; |
|
6236 |
case KeyEvent.KEY_PRESSED: |
|
6237 |
listener.keyPressed(e); |
|
6238 |
break; |
|
6239 |
case KeyEvent.KEY_RELEASED: |
|
6240 |
listener.keyReleased(e); |
|
6241 |
break; |
|
6242 |
} |
|
6243 |
} |
|
6244 |
} |
|
6245 |
||
6246 |
/** |
|
6247 |
* Processes mouse events occurring on this component by |
|
6248 |
* dispatching them to any registered |
|
6249 |
* <code>MouseListener</code> objects. |
|
6250 |
* <p> |
|
6251 |
* This method is not called unless mouse events are |
|
6252 |
* enabled for this component. Mouse events are enabled |
|
6253 |
* when one of the following occurs: |
|
6254 |
* <p><ul> |
|
6255 |
* <li>A <code>MouseListener</code> object is registered |
|
6256 |
* via <code>addMouseListener</code>. |
|
6257 |
* <li>Mouse events are enabled via <code>enableEvents</code>. |
|
6258 |
* </ul> |
|
6259 |
* <p>Note that if the event parameter is <code>null</code> |
|
6260 |
* the behavior is unspecified and may result in an |
|
6261 |
* exception. |
|
6262 |
* |
|
6263 |
* @param e the mouse event |
|
6264 |
* @see java.awt.event.MouseEvent |
|
6265 |
* @see java.awt.event.MouseListener |
|
6266 |
* @see #addMouseListener |
|
6267 |
* @see #enableEvents |
|
6268 |
* @since JDK1.1 |
|
6269 |
*/ |
|
6270 |
protected void processMouseEvent(MouseEvent e) { |
|
6271 |
MouseListener listener = mouseListener; |
|
6272 |
if (listener != null) { |
|
6273 |
int id = e.getID(); |
|
6274 |
switch(id) { |
|
6275 |
case MouseEvent.MOUSE_PRESSED: |
|
6276 |
listener.mousePressed(e); |
|
6277 |
break; |
|
6278 |
case MouseEvent.MOUSE_RELEASED: |
|
6279 |
listener.mouseReleased(e); |
|
6280 |
break; |
|
6281 |
case MouseEvent.MOUSE_CLICKED: |
|
6282 |
listener.mouseClicked(e); |
|
6283 |
break; |
|
6284 |
case MouseEvent.MOUSE_EXITED: |
|
6285 |
listener.mouseExited(e); |
|
6286 |
break; |
|
6287 |
case MouseEvent.MOUSE_ENTERED: |
|
6288 |
listener.mouseEntered(e); |
|
6289 |
break; |
|
6290 |
} |
|
6291 |
} |
|
6292 |
} |
|
6293 |
||
6294 |
/** |
|
6295 |
* Processes mouse motion events occurring on this component by |
|
6296 |
* dispatching them to any registered |
|
6297 |
* <code>MouseMotionListener</code> objects. |
|
6298 |
* <p> |
|
6299 |
* This method is not called unless mouse motion events are |
|
6300 |
* enabled for this component. Mouse motion events are enabled |
|
6301 |
* when one of the following occurs: |
|
6302 |
* <p><ul> |
|
6303 |
* <li>A <code>MouseMotionListener</code> object is registered |
|
6304 |
* via <code>addMouseMotionListener</code>. |
|
6305 |
* <li>Mouse motion events are enabled via <code>enableEvents</code>. |
|
6306 |
* </ul> |
|
6307 |
* <p>Note that if the event parameter is <code>null</code> |
|
6308 |
* the behavior is unspecified and may result in an |
|
6309 |
* exception. |
|
6310 |
* |
|
6311 |
* @param e the mouse motion event |
|
6312 |
* @see java.awt.event.MouseEvent |
|
6313 |
* @see java.awt.event.MouseMotionListener |
|
6314 |
* @see #addMouseMotionListener |
|
6315 |
* @see #enableEvents |
|
6316 |
* @since JDK1.1 |
|
6317 |
*/ |
|
6318 |
protected void processMouseMotionEvent(MouseEvent e) { |
|
6319 |
MouseMotionListener listener = mouseMotionListener; |
|
6320 |
if (listener != null) { |
|
6321 |
int id = e.getID(); |
|
6322 |
switch(id) { |
|
6323 |
case MouseEvent.MOUSE_MOVED: |
|
6324 |
listener.mouseMoved(e); |
|
6325 |
break; |
|
6326 |
case MouseEvent.MOUSE_DRAGGED: |
|
6327 |
listener.mouseDragged(e); |
|
6328 |
break; |
|
6329 |
} |
|
6330 |
} |
|
6331 |
} |
|
6332 |
||
6333 |
/** |
|
6334 |
* Processes mouse wheel events occurring on this component by |
|
6335 |
* dispatching them to any registered |
|
6336 |
* <code>MouseWheelListener</code> objects. |
|
6337 |
* <p> |
|
6338 |
* This method is not called unless mouse wheel events are |
|
6339 |
* enabled for this component. Mouse wheel events are enabled |
|
6340 |
* when one of the following occurs: |
|
6341 |
* <p><ul> |
|
6342 |
* <li>A <code>MouseWheelListener</code> object is registered |
|
6343 |
* via <code>addMouseWheelListener</code>. |
|
6344 |
* <li>Mouse wheel events are enabled via <code>enableEvents</code>. |
|
6345 |
* </ul> |
|
6346 |
* <p> |
|
6347 |
* For information on how mouse wheel events are dispatched, see |
|
6348 |
* the class description for {@link MouseWheelEvent}. |
|
6349 |
* <p> |
|
6350 |
* Note that if the event parameter is <code>null</code> |
|
6351 |
* the behavior is unspecified and may result in an |
|
6352 |
* exception. |
|
6353 |
* |
|
6354 |
* @param e the mouse wheel event |
|
6355 |
* @see java.awt.event.MouseWheelEvent |
|
6356 |
* @see java.awt.event.MouseWheelListener |
|
6357 |
* @see #addMouseWheelListener |
|
6358 |
* @see #enableEvents |
|
6359 |
* @since 1.4 |
|
6360 |
*/ |
|
6361 |
protected void processMouseWheelEvent(MouseWheelEvent e) { |
|
6362 |
MouseWheelListener listener = mouseWheelListener; |
|
6363 |
if (listener != null) { |
|
6364 |
int id = e.getID(); |
|
6365 |
switch(id) { |
|
6366 |
case MouseEvent.MOUSE_WHEEL: |
|
6367 |
listener.mouseWheelMoved(e); |
|
6368 |
break; |
|
6369 |
} |
|
6370 |
} |
|
6371 |
} |
|
6372 |
||
6373 |
boolean postsOldMouseEvents() { |
|
6374 |
return false; |
|
6375 |
} |
|
6376 |
||
6377 |
/** |
|
6378 |
* Processes input method events occurring on this component by |
|
6379 |
* dispatching them to any registered |
|
6380 |
* <code>InputMethodListener</code> objects. |
|
6381 |
* <p> |
|
6382 |
* This method is not called unless input method events |
|
6383 |
* are enabled for this component. Input method events are enabled |
|
6384 |
* when one of the following occurs: |
|
6385 |
* <p><ul> |
|
6386 |
* <li>An <code>InputMethodListener</code> object is registered |
|
6387 |
* via <code>addInputMethodListener</code>. |
|
6388 |
* <li>Input method events are enabled via <code>enableEvents</code>. |
|
6389 |
* </ul> |
|
6390 |
* <p>Note that if the event parameter is <code>null</code> |
|
6391 |
* the behavior is unspecified and may result in an |
|
6392 |
* exception. |
|
6393 |
* |
|
6394 |
* @param e the input method event |
|
6395 |
* @see java.awt.event.InputMethodEvent |
|
6396 |
* @see java.awt.event.InputMethodListener |
|
6397 |
* @see #addInputMethodListener |
|
6398 |
* @see #enableEvents |
|
6399 |
* @since 1.2 |
|
6400 |
*/ |
|
6401 |
protected void processInputMethodEvent(InputMethodEvent e) { |
|
6402 |
InputMethodListener listener = inputMethodListener; |
|
6403 |
if (listener != null) { |
|
6404 |
int id = e.getID(); |
|
6405 |
switch (id) { |
|
6406 |
case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: |
|
6407 |
listener.inputMethodTextChanged(e); |
|
6408 |
break; |
|
6409 |
case InputMethodEvent.CARET_POSITION_CHANGED: |
|
6410 |
listener.caretPositionChanged(e); |
|
6411 |
break; |
|
6412 |
} |
|
6413 |
} |
|
6414 |
} |
|
6415 |
||
6416 |
/** |
|
6417 |
* Processes hierarchy events occurring on this component by |
|
6418 |
* dispatching them to any registered |
|
6419 |
* <code>HierarchyListener</code> objects. |
|
6420 |
* <p> |
|
6421 |
* This method is not called unless hierarchy events |
|
6422 |
* are enabled for this component. Hierarchy events are enabled |
|
6423 |
* when one of the following occurs: |
|
6424 |
* <p><ul> |
|
6425 |
* <li>An <code>HierarchyListener</code> object is registered |
|
6426 |
* via <code>addHierarchyListener</code>. |
|
6427 |
* <li>Hierarchy events are enabled via <code>enableEvents</code>. |
|
6428 |
* </ul> |
|
6429 |
* <p>Note that if the event parameter is <code>null</code> |
|
6430 |
* the behavior is unspecified and may result in an |
|
6431 |
* exception. |
|
6432 |
* |
|
6433 |
* @param e the hierarchy event |
|
6434 |
* @see java.awt.event.HierarchyEvent |
|
6435 |
* @see java.awt.event.HierarchyListener |
|
6436 |
* @see #addHierarchyListener |
|
6437 |
* @see #enableEvents |
|
6438 |
* @since 1.3 |
|
6439 |
*/ |
|
6440 |
protected void processHierarchyEvent(HierarchyEvent e) { |
|
6441 |
HierarchyListener listener = hierarchyListener; |
|
6442 |
if (listener != null) { |
|
6443 |
int id = e.getID(); |
|
6444 |
switch (id) { |
|
6445 |
case HierarchyEvent.HIERARCHY_CHANGED: |
|
6446 |
listener.hierarchyChanged(e); |
|
6447 |
break; |
|
6448 |
} |
|
6449 |
} |
|
6450 |
} |
|
6451 |
||
6452 |
/** |
|
6453 |
* Processes hierarchy bounds events occurring on this component by |
|
6454 |
* dispatching them to any registered |
|
6455 |
* <code>HierarchyBoundsListener</code> objects. |
|
6456 |
* <p> |
|
6457 |
* This method is not called unless hierarchy bounds events |
|
6458 |
* are enabled for this component. Hierarchy bounds events are enabled |
|
6459 |
* when one of the following occurs: |
|
6460 |
* <p><ul> |
|
6461 |
* <li>An <code>HierarchyBoundsListener</code> object is registered |
|
6462 |
* via <code>addHierarchyBoundsListener</code>. |
|
6463 |
* <li>Hierarchy bounds events are enabled via <code>enableEvents</code>. |
|
6464 |
* </ul> |
|
6465 |
* <p>Note that if the event parameter is <code>null</code> |
|
6466 |
* the behavior is unspecified and may result in an |
|
6467 |
* exception. |
|
6468 |
* |
|
6469 |
* @param e the hierarchy event |
|
6470 |
* @see java.awt.event.HierarchyEvent |
|
6471 |
* @see java.awt.event.HierarchyBoundsListener |
|
6472 |
* @see #addHierarchyBoundsListener |
|
6473 |
* @see #enableEvents |
|
6474 |
* @since 1.3 |
|
6475 |
*/ |
|
6476 |
protected void processHierarchyBoundsEvent(HierarchyEvent e) { |
|
6477 |
HierarchyBoundsListener listener = hierarchyBoundsListener; |
|
6478 |
if (listener != null) { |
|
6479 |
int id = e.getID(); |
|
6480 |
switch (id) { |
|
6481 |
case HierarchyEvent.ANCESTOR_MOVED: |
|
6482 |
listener.ancestorMoved(e); |
|
6483 |
break; |
|
6484 |
case HierarchyEvent.ANCESTOR_RESIZED: |
|
6485 |
listener.ancestorResized(e); |
|
6486 |
break; |
|
6487 |
} |
|
6488 |
} |
|
6489 |
} |
|
6490 |
||
6491 |
/** |
|
6492 |
* @deprecated As of JDK version 1.1 |
|
6493 |
* replaced by processEvent(AWTEvent). |
|
6494 |
*/ |
|
6495 |
@Deprecated |
|
6496 |
public boolean handleEvent(Event evt) { |
|
6497 |
switch (evt.id) { |
|
6498 |
case Event.MOUSE_ENTER: |
|
6499 |
return mouseEnter(evt, evt.x, evt.y); |
|
6500 |
||
6501 |
case Event.MOUSE_EXIT: |
|
6502 |
return mouseExit(evt, evt.x, evt.y); |
|
6503 |
||
6504 |
case Event.MOUSE_MOVE: |
|
6505 |
return mouseMove(evt, evt.x, evt.y); |
|
6506 |
||
6507 |
case Event.MOUSE_DOWN: |
|
6508 |
return mouseDown(evt, evt.x, evt.y); |
|
6509 |
||
6510 |
case Event.MOUSE_DRAG: |
|
6511 |
return mouseDrag(evt, evt.x, evt.y); |
|
6512 |
||
6513 |
case Event.MOUSE_UP: |
|
6514 |
return mouseUp(evt, evt.x, evt.y); |
|
6515 |
||
6516 |
case Event.KEY_PRESS: |
|
6517 |
case Event.KEY_ACTION: |
|
6518 |
return keyDown(evt, evt.key); |
|
6519 |
||
6520 |
case Event.KEY_RELEASE: |
|
6521 |
case Event.KEY_ACTION_RELEASE: |
|
6522 |
return keyUp(evt, evt.key); |
|
6523 |
||
6524 |
case Event.ACTION_EVENT: |
|
6525 |
return action(evt, evt.arg); |
|
6526 |
case Event.GOT_FOCUS: |
|
6527 |
return gotFocus(evt, evt.arg); |
|
6528 |
case Event.LOST_FOCUS: |
|
6529 |
return lostFocus(evt, evt.arg); |
|
6530 |
} |
|
6531 |
return false; |
|
6532 |
} |
|
6533 |
||
6534 |
/** |
|
6535 |
* @deprecated As of JDK version 1.1, |
|
6536 |
* replaced by processMouseEvent(MouseEvent). |
|
6537 |
*/ |
|
6538 |
@Deprecated |
|
6539 |
public boolean mouseDown(Event evt, int x, int y) { |
|
6540 |
return false; |
|
6541 |
} |
|
6542 |
||
6543 |
/** |
|
6544 |
* @deprecated As of JDK version 1.1, |
|
6545 |
* replaced by processMouseMotionEvent(MouseEvent). |
|
6546 |
*/ |
|
6547 |
@Deprecated |
|
6548 |
public boolean mouseDrag(Event evt, int x, int y) { |
|
6549 |
return false; |
|
6550 |
} |
|
6551 |
||
6552 |
/** |
|
6553 |
* @deprecated As of JDK version 1.1, |
|
6554 |
* replaced by processMouseEvent(MouseEvent). |
|
6555 |
*/ |
|
6556 |
@Deprecated |
|
6557 |
public boolean mouseUp(Event evt, int x, int y) { |
|
6558 |
return false; |
|
6559 |
} |
|
6560 |
||
6561 |
/** |
|
6562 |
* @deprecated As of JDK version 1.1, |
|
6563 |
* replaced by processMouseMotionEvent(MouseEvent). |
|
6564 |
*/ |
|
6565 |
@Deprecated |
|
6566 |
public boolean mouseMove(Event evt, int x, int y) { |
|
6567 |
return false; |
|
6568 |
} |
|
6569 |
||
6570 |
/** |
|
6571 |
* @deprecated As of JDK version 1.1, |
|
6572 |
* replaced by processMouseEvent(MouseEvent). |
|
6573 |
*/ |
|
6574 |
@Deprecated |
|
6575 |
public boolean mouseEnter(Event evt, int x, int y) { |
|
6576 |
return false; |
|
6577 |
} |
|
6578 |
||
6579 |
/** |
|
6580 |
* @deprecated As of JDK version 1.1, |
|
6581 |
* replaced by processMouseEvent(MouseEvent). |
|
6582 |
*/ |
|
6583 |
@Deprecated |
|
6584 |
public boolean mouseExit(Event evt, int x, int y) { |
|
6585 |
return false; |
|
6586 |
} |
|
6587 |
||
6588 |
/** |
|
6589 |
* @deprecated As of JDK version 1.1, |
|
6590 |
* replaced by processKeyEvent(KeyEvent). |
|
6591 |
*/ |
|
6592 |
@Deprecated |
|
6593 |
public boolean keyDown(Event evt, int key) { |
|
6594 |
return false; |
|
6595 |
} |
|
6596 |
||
6597 |
/** |
|
6598 |
* @deprecated As of JDK version 1.1, |
|
6599 |
* replaced by processKeyEvent(KeyEvent). |
|
6600 |
*/ |
|
6601 |
@Deprecated |
|
6602 |
public boolean keyUp(Event evt, int key) { |
|
6603 |
return false; |
|
6604 |
} |
|
6605 |
||
6606 |
/** |
|
6607 |
* @deprecated As of JDK version 1.1, |
|
6608 |
* should register this component as ActionListener on component |
|
6609 |
* which fires action events. |
|
6610 |
*/ |
|
6611 |
@Deprecated |
|
6612 |
public boolean action(Event evt, Object what) { |
|
6613 |
return false; |
|
6614 |
} |
|
6615 |
||
6616 |
/** |
|
6617 |
* Makes this <code>Component</code> displayable by connecting it to a |
|
6618 |
* native screen resource. |
|
6619 |
* This method is called internally by the toolkit and should |
|
6620 |
* not be called directly by programs. |
|
6621 |
* @see #isDisplayable |
|
6622 |
* @see #removeNotify |
|
6623 |
* @since JDK1.0 |
|
6624 |
*/ |
|
6625 |
public void addNotify() { |
|
6626 |
synchronized (getTreeLock()) { |
|
6627 |
ComponentPeer peer = this.peer; |
|
6628 |
if (peer == null || peer instanceof LightweightPeer){ |
|
6629 |
if (peer == null) { |
|
6630 |
// Update both the Component's peer variable and the local |
|
6631 |
// variable we use for thread safety. |
|
6632 |
this.peer = peer = getToolkit().createComponent(this); |
|
6633 |
} |
|
6634 |
||
6635 |
// This is a lightweight component which means it won't be |
|
6636 |
// able to get window-related events by itself. If any |
|
6637 |
// have been enabled, then the nearest native container must |
|
6638 |
// be enabled. |
|
6639 |
if (parent != null) { |
|
6640 |
long mask = 0; |
|
6641 |
if ((mouseListener != null) || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) { |
|
6642 |
mask |= AWTEvent.MOUSE_EVENT_MASK; |
|
6643 |
} |
|
6644 |
if ((mouseMotionListener != null) || |
|
6645 |
((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)) { |
|
6646 |
mask |= AWTEvent.MOUSE_MOTION_EVENT_MASK; |
|
6647 |
} |
|
6648 |
if ((mouseWheelListener != null ) || |
|
6649 |
((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0)) { |
|
6650 |
mask |= AWTEvent.MOUSE_WHEEL_EVENT_MASK; |
|
6651 |
} |
|
6652 |
if (focusListener != null || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) { |
|
6653 |
mask |= AWTEvent.FOCUS_EVENT_MASK; |
|
6654 |
} |
|
6655 |
if (keyListener != null || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0) { |
|
6656 |
mask |= AWTEvent.KEY_EVENT_MASK; |
|
6657 |
} |
|
6658 |
if (mask != 0) { |
|
6659 |
parent.proxyEnableEvents(mask); |
|
6660 |
} |
|
6661 |
} |
|
6662 |
} else { |
|
6663 |
// It's native. If the parent is lightweight it |
|
6664 |
// will need some help. |
|
6665 |
Container parent = this.parent; |
|
6666 |
if (parent != null && parent.peer instanceof LightweightPeer) { |
|
130 | 6667 |
relocateComponent(); |
3729
80d0cf73598d
6689468: test/closed/java/awt/Component/VisibleHwInLwContTest/VisibleHwInLwContTest.html fails
anthony
parents:
3727
diff
changeset
|
6668 |
if (!isRecursivelyVisible()) { |
80d0cf73598d
6689468: test/closed/java/awt/Component/VisibleHwInLwContTest/VisibleHwInLwContTest.html fails
anthony
parents:
3727
diff
changeset
|
6669 |
peer.setVisible(false); |
80d0cf73598d
6689468: test/closed/java/awt/Component/VisibleHwInLwContTest/VisibleHwInLwContTest.html fails
anthony
parents:
3727
diff
changeset
|
6670 |
} |
2 | 6671 |
} |
6672 |
} |
|
6673 |
invalidate(); |
|
6674 |
||
6675 |
int npopups = (popups != null? popups.size() : 0); |
|
6676 |
for (int i = 0 ; i < npopups ; i++) { |
|
6677 |
PopupMenu popup = (PopupMenu)popups.elementAt(i); |
|
6678 |
popup.addNotify(); |
|
6679 |
} |
|
6680 |
||
6681 |
if (dropTarget != null) dropTarget.addNotify(peer); |
|
6682 |
||
6683 |
peerFont = getFont(); |
|
6684 |
||
6685 |
if (getContainer() != null && !isAddNotifyComplete) { |
|
6686 |
getContainer().increaseComponentCount(this); |
|
6687 |
} |
|
6688 |
||
6689 |
||
6690 |
// Update stacking order |
|
2647
ea80a312972e
6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents:
2472
diff
changeset
|
6691 |
updateZOrder(); |
2 | 6692 |
|
6693 |
if (!isAddNotifyComplete) { |
|
6694 |
mixOnShowing(); |
|
6695 |
} |
|
6696 |
||
6697 |
isAddNotifyComplete = true; |
|
6698 |
||
6699 |
if (hierarchyListener != null || |
|
6700 |
(eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 || |
|
6701 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) { |
|
6702 |
HierarchyEvent e = |
|
6703 |
new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED, |
|
6704 |
this, parent, |
|
6705 |
HierarchyEvent.DISPLAYABILITY_CHANGED | |
|
6706 |
((isRecursivelyVisible()) |
|
6707 |
? HierarchyEvent.SHOWING_CHANGED |
|
6708 |
: 0)); |
|
6709 |
dispatchEvent(e); |
|
6710 |
} |
|
6711 |
} |
|
6712 |
} |
|
6713 |
||
6714 |
/** |
|
6715 |
* Makes this <code>Component</code> undisplayable by destroying it native |
|
6716 |
* screen resource. |
|
6717 |
* <p> |
|
6718 |
* This method is called by the toolkit internally and should |
|
6719 |
* not be called directly by programs. Code overriding |
|
6720 |
* this method should call <code>super.removeNotify</code> as |
|
6721 |
* the first line of the overriding method. |
|
6722 |
* |
|
6723 |
* @see #isDisplayable |
|
6724 |
* @see #addNotify |
|
6725 |
* @since JDK1.0 |
|
6726 |
*/ |
|
6727 |
public void removeNotify() { |
|
6728 |
KeyboardFocusManager.clearMostRecentFocusOwner(this); |
|
6729 |
if (KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
6730 |
getPermanentFocusOwner() == this) |
|
6731 |
{ |
|
6732 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
6733 |
setGlobalPermanentFocusOwner(null); |
|
6734 |
} |
|
6735 |
||
6736 |
synchronized (getTreeLock()) { |
|
441 | 6737 |
if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabledFor(this)) { |
6738 |
transferFocus(true); |
|
2 | 6739 |
} |
6740 |
||
6741 |
if (getContainer() != null && isAddNotifyComplete) { |
|
6742 |
getContainer().decreaseComponentCount(this); |
|
6743 |
} |
|
6744 |
||
6745 |
int npopups = (popups != null? popups.size() : 0); |
|
6746 |
for (int i = 0 ; i < npopups ; i++) { |
|
6747 |
PopupMenu popup = (PopupMenu)popups.elementAt(i); |
|
6748 |
popup.removeNotify(); |
|
6749 |
} |
|
6750 |
// If there is any input context for this component, notify |
|
6751 |
// that this component is being removed. (This has to be done |
|
6752 |
// before hiding peer.) |
|
6753 |
if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) { |
|
6754 |
InputContext inputContext = getInputContext(); |
|
6755 |
if (inputContext != null) { |
|
6756 |
inputContext.removeNotify(this); |
|
6757 |
} |
|
6758 |
} |
|
6759 |
||
6760 |
ComponentPeer p = peer; |
|
6761 |
if (p != null) { |
|
6762 |
boolean isLightweight = isLightweight(); |
|
6763 |
||
6764 |
if (bufferStrategy instanceof FlipBufferStrategy) { |
|
6765 |
((FlipBufferStrategy)bufferStrategy).destroyBuffers(); |
|
6766 |
} |
|
6767 |
||
6768 |
if (dropTarget != null) dropTarget.removeNotify(peer); |
|
6769 |
||
6770 |
// Hide peer first to stop system events such as cursor moves. |
|
6771 |
if (visible) { |
|
1964 | 6772 |
p.setVisible(false); |
2 | 6773 |
} |
6774 |
||
6775 |
peer = null; // Stop peer updates. |
|
6776 |
peerFont = null; |
|
6777 |
||
6778 |
Toolkit.getEventQueue().removeSourceEvents(this, false); |
|
6779 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
6780 |
discardKeyEvents(this); |
|
6781 |
||
6782 |
p.dispose(); |
|
6783 |
||
6784 |
mixOnHiding(isLightweight); |
|
6785 |
||
6786 |
isAddNotifyComplete = false; |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
6787 |
// Nullifying compoundShape means that the component has normal shape |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
6788 |
// (or has no shape at all). |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
6789 |
this.compoundShape = null; |
2 | 6790 |
} |
6791 |
||
6792 |
if (hierarchyListener != null || |
|
6793 |
(eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 || |
|
6794 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) { |
|
6795 |
HierarchyEvent e = |
|
6796 |
new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED, |
|
6797 |
this, parent, |
|
6798 |
HierarchyEvent.DISPLAYABILITY_CHANGED | |
|
6799 |
((isRecursivelyVisible()) |
|
6800 |
? HierarchyEvent.SHOWING_CHANGED |
|
6801 |
: 0)); |
|
6802 |
dispatchEvent(e); |
|
6803 |
} |
|
6804 |
} |
|
6805 |
} |
|
6806 |
||
6807 |
/** |
|
6808 |
* @deprecated As of JDK version 1.1, |
|
6809 |
* replaced by processFocusEvent(FocusEvent). |
|
6810 |
*/ |
|
6811 |
@Deprecated |
|
6812 |
public boolean gotFocus(Event evt, Object what) { |
|
6813 |
return false; |
|
6814 |
} |
|
6815 |
||
6816 |
/** |
|
6817 |
* @deprecated As of JDK version 1.1, |
|
6818 |
* replaced by processFocusEvent(FocusEvent). |
|
6819 |
*/ |
|
6820 |
@Deprecated |
|
6821 |
public boolean lostFocus(Event evt, Object what) { |
|
6822 |
return false; |
|
6823 |
} |
|
6824 |
||
6825 |
/** |
|
6826 |
* Returns whether this <code>Component</code> can become the focus |
|
6827 |
* owner. |
|
6828 |
* |
|
6829 |
* @return <code>true</code> if this <code>Component</code> is |
|
6830 |
* focusable; <code>false</code> otherwise |
|
6831 |
* @see #setFocusable |
|
6832 |
* @since JDK1.1 |
|
6833 |
* @deprecated As of 1.4, replaced by <code>isFocusable()</code>. |
|
6834 |
*/ |
|
6835 |
@Deprecated |
|
6836 |
public boolean isFocusTraversable() { |
|
6837 |
if (isFocusTraversableOverridden == FOCUS_TRAVERSABLE_UNKNOWN) { |
|
6838 |
isFocusTraversableOverridden = FOCUS_TRAVERSABLE_DEFAULT; |
|
6839 |
} |
|
6840 |
return focusable; |
|
6841 |
} |
|
6842 |
||
6843 |
/** |
|
6844 |
* Returns whether this Component can be focused. |
|
6845 |
* |
|
6846 |
* @return <code>true</code> if this Component is focusable; |
|
6847 |
* <code>false</code> otherwise. |
|
6848 |
* @see #setFocusable |
|
6849 |
* @since 1.4 |
|
6850 |
*/ |
|
6851 |
public boolean isFocusable() { |
|
6852 |
return isFocusTraversable(); |
|
6853 |
} |
|
6854 |
||
6855 |
/** |
|
6856 |
* Sets the focusable state of this Component to the specified value. This |
|
6857 |
* value overrides the Component's default focusability. |
|
6858 |
* |
|
6859 |
* @param focusable indicates whether this Component is focusable |
|
6860 |
* @see #isFocusable |
|
6861 |
* @since 1.4 |
|
6862 |
* @beaninfo |
|
6863 |
* bound: true |
|
6864 |
*/ |
|
6865 |
public void setFocusable(boolean focusable) { |
|
6866 |
boolean oldFocusable; |
|
6867 |
synchronized (this) { |
|
6868 |
oldFocusable = this.focusable; |
|
6869 |
this.focusable = focusable; |
|
6870 |
} |
|
6871 |
isFocusTraversableOverridden = FOCUS_TRAVERSABLE_SET; |
|
6872 |
||
6873 |
firePropertyChange("focusable", oldFocusable, focusable); |
|
6874 |
if (oldFocusable && !focusable) { |
|
441 | 6875 |
if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabled()) { |
6876 |
transferFocus(true); |
|
2 | 6877 |
} |
6878 |
KeyboardFocusManager.clearMostRecentFocusOwner(this); |
|
6879 |
} |
|
6880 |
} |
|
6881 |
||
6882 |
final boolean isFocusTraversableOverridden() { |
|
6883 |
return (isFocusTraversableOverridden != FOCUS_TRAVERSABLE_DEFAULT); |
|
6884 |
} |
|
6885 |
||
6886 |
/** |
|
6887 |
* Sets the focus traversal keys for a given traversal operation for this |
|
6888 |
* Component. |
|
6889 |
* <p> |
|
6890 |
* The default values for a Component's focus traversal keys are |
|
6891 |
* implementation-dependent. Sun recommends that all implementations for a |
|
6892 |
* particular native platform use the same default values. The |
|
6893 |
* recommendations for Windows and Unix are listed below. These |
|
6894 |
* recommendations are used in the Sun AWT implementations. |
|
6895 |
* |
|
6896 |
* <table border=1 summary="Recommended default values for a Component's focus traversal keys"> |
|
6897 |
* <tr> |
|
6898 |
* <th>Identifier</th> |
|
6899 |
* <th>Meaning</th> |
|
6900 |
* <th>Default</th> |
|
6901 |
* </tr> |
|
6902 |
* <tr> |
|
6903 |
* <td>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</td> |
|
6904 |
* <td>Normal forward keyboard traversal</td> |
|
6905 |
* <td>TAB on KEY_PRESSED, CTRL-TAB on KEY_PRESSED</td> |
|
6906 |
* </tr> |
|
6907 |
* <tr> |
|
6908 |
* <td>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</td> |
|
6909 |
* <td>Normal reverse keyboard traversal</td> |
|
6910 |
* <td>SHIFT-TAB on KEY_PRESSED, CTRL-SHIFT-TAB on KEY_PRESSED</td> |
|
6911 |
* </tr> |
|
6912 |
* <tr> |
|
6913 |
* <td>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</td> |
|
6914 |
* <td>Go up one focus traversal cycle</td> |
|
6915 |
* <td>none</td> |
|
6916 |
* </tr> |
|
6917 |
* </table> |
|
6918 |
* |
|
6919 |
* To disable a traversal key, use an empty Set; Collections.EMPTY_SET is |
|
6920 |
* recommended. |
|
6921 |
* <p> |
|
6922 |
* Using the AWTKeyStroke API, client code can specify on which of two |
|
6923 |
* specific KeyEvents, KEY_PRESSED or KEY_RELEASED, the focus traversal |
|
6924 |
* operation will occur. Regardless of which KeyEvent is specified, |
|
6925 |
* however, all KeyEvents related to the focus traversal key, including the |
|
6926 |
* associated KEY_TYPED event, will be consumed, and will not be dispatched |
|
6927 |
* to any Component. It is a runtime error to specify a KEY_TYPED event as |
|
6928 |
* mapping to a focus traversal operation, or to map the same event to |
|
6929 |
* multiple default focus traversal operations. |
|
6930 |
* <p> |
|
6931 |
* If a value of null is specified for the Set, this Component inherits the |
|
6932 |
* Set from its parent. If all ancestors of this Component have null |
|
6933 |
* specified for the Set, then the current KeyboardFocusManager's default |
|
6934 |
* Set is used. |
|
6935 |
* |
|
6936 |
* @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
6937 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or |
|
6938 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS |
|
6939 |
* @param keystrokes the Set of AWTKeyStroke for the specified operation |
|
6940 |
* @see #getFocusTraversalKeys |
|
6941 |
* @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS |
|
6942 |
* @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS |
|
6943 |
* @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS |
|
6944 |
* @throws IllegalArgumentException if id is not one of |
|
6945 |
* KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
6946 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or |
|
6947 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes |
|
6948 |
* contains null, or if any Object in keystrokes is not an |
|
6949 |
* AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, |
|
6950 |
* or if any keystroke already maps to another focus traversal |
|
6951 |
* operation for this Component |
|
6952 |
* @since 1.4 |
|
6953 |
* @beaninfo |
|
6954 |
* bound: true |
|
6955 |
*/ |
|
6956 |
public void setFocusTraversalKeys(int id, |
|
6957 |
Set<? extends AWTKeyStroke> keystrokes) |
|
6958 |
{ |
|
6959 |
if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) { |
|
6960 |
throw new IllegalArgumentException("invalid focus traversal key identifier"); |
|
6961 |
} |
|
6962 |
||
6963 |
setFocusTraversalKeys_NoIDCheck(id, keystrokes); |
|
6964 |
} |
|
6965 |
||
6966 |
/** |
|
6967 |
* Returns the Set of focus traversal keys for a given traversal operation |
|
6968 |
* for this Component. (See |
|
6969 |
* <code>setFocusTraversalKeys</code> for a full description of each key.) |
|
6970 |
* <p> |
|
6971 |
* If a Set of traversal keys has not been explicitly defined for this |
|
6972 |
* Component, then this Component's parent's Set is returned. If no Set |
|
6973 |
* has been explicitly defined for any of this Component's ancestors, then |
|
6974 |
* the current KeyboardFocusManager's default Set is returned. |
|
6975 |
* |
|
6976 |
* @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
6977 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or |
|
6978 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS |
|
6979 |
* @return the Set of AWTKeyStrokes for the specified operation. The Set |
|
6980 |
* will be unmodifiable, and may be empty. null will never be |
|
6981 |
* returned. |
|
6982 |
* @see #setFocusTraversalKeys |
|
6983 |
* @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS |
|
6984 |
* @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS |
|
6985 |
* @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS |
|
6986 |
* @throws IllegalArgumentException if id is not one of |
|
6987 |
* KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
6988 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or |
|
6989 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS |
|
6990 |
* @since 1.4 |
|
6991 |
*/ |
|
6992 |
public Set<AWTKeyStroke> getFocusTraversalKeys(int id) { |
|
6993 |
if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) { |
|
6994 |
throw new IllegalArgumentException("invalid focus traversal key identifier"); |
|
6995 |
} |
|
6996 |
||
6997 |
return getFocusTraversalKeys_NoIDCheck(id); |
|
6998 |
} |
|
6999 |
||
7000 |
// We define these methods so that Container does not need to repeat this |
|
7001 |
// code. Container cannot call super.<method> because Container allows |
|
7002 |
// DOWN_CYCLE_TRAVERSAL_KEY while Component does not. The Component method |
|
7003 |
// would erroneously generate an IllegalArgumentException for |
|
7004 |
// DOWN_CYCLE_TRAVERSAL_KEY. |
|
7005 |
final void setFocusTraversalKeys_NoIDCheck(int id, Set<? extends AWTKeyStroke> keystrokes) { |
|
7006 |
Set oldKeys; |
|
7007 |
||
7008 |
synchronized (this) { |
|
7009 |
if (focusTraversalKeys == null) { |
|
7010 |
initializeFocusTraversalKeys(); |
|
7011 |
} |
|
7012 |
||
7013 |
if (keystrokes != null) { |
|
7014 |
for (Iterator iter = keystrokes.iterator(); iter.hasNext(); ) { |
|
7015 |
Object obj = iter.next(); |
|
7016 |
||
7017 |
if (obj == null) { |
|
7018 |
throw new IllegalArgumentException("cannot set null focus traversal key"); |
|
7019 |
} |
|
7020 |
||
7021 |
// Fix for 6195828: |
|
7022 |
//According to javadoc this method should throw IAE instead of ClassCastException |
|
7023 |
if (!(obj instanceof AWTKeyStroke)) { |
|
7024 |
throw new IllegalArgumentException("object is expected to be AWTKeyStroke"); |
|
7025 |
} |
|
7026 |
AWTKeyStroke keystroke = (AWTKeyStroke)obj; |
|
7027 |
||
7028 |
if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) { |
|
7029 |
throw new IllegalArgumentException("focus traversal keys cannot map to KEY_TYPED events"); |
|
7030 |
} |
|
7031 |
||
7032 |
for (int i = 0; i < focusTraversalKeys.length; i++) { |
|
7033 |
if (i == id) { |
|
7034 |
continue; |
|
7035 |
} |
|
7036 |
||
7037 |
if (getFocusTraversalKeys_NoIDCheck(i).contains(keystroke)) |
|
7038 |
{ |
|
7039 |
throw new IllegalArgumentException("focus traversal keys must be unique for a Component"); |
|
7040 |
} |
|
7041 |
} |
|
7042 |
} |
|
7043 |
} |
|
7044 |
||
7045 |
oldKeys = focusTraversalKeys[id]; |
|
7046 |
focusTraversalKeys[id] = (keystrokes != null) |
|
7047 |
? Collections.unmodifiableSet(new HashSet(keystrokes)) |
|
7048 |
: null; |
|
7049 |
} |
|
7050 |
||
7051 |
firePropertyChange(focusTraversalKeyPropertyNames[id], oldKeys, |
|
7052 |
keystrokes); |
|
7053 |
} |
|
7054 |
final Set getFocusTraversalKeys_NoIDCheck(int id) { |
|
7055 |
// Okay to return Set directly because it is an unmodifiable view |
|
7056 |
Set keystrokes = (focusTraversalKeys != null) |
|
7057 |
? focusTraversalKeys[id] |
|
7058 |
: null; |
|
7059 |
||
7060 |
if (keystrokes != null) { |
|
7061 |
return keystrokes; |
|
7062 |
} else { |
|
7063 |
Container parent = this.parent; |
|
7064 |
if (parent != null) { |
|
7065 |
return parent.getFocusTraversalKeys(id); |
|
7066 |
} else { |
|
7067 |
return KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
7068 |
getDefaultFocusTraversalKeys(id); |
|
7069 |
} |
|
7070 |
} |
|
7071 |
} |
|
7072 |
||
7073 |
/** |
|
7074 |
* Returns whether the Set of focus traversal keys for the given focus |
|
7075 |
* traversal operation has been explicitly defined for this Component. If |
|
7076 |
* this method returns <code>false</code>, this Component is inheriting the |
|
7077 |
* Set from an ancestor, or from the current KeyboardFocusManager. |
|
7078 |
* |
|
7079 |
* @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
7080 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or |
|
7081 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS |
|
7082 |
* @return <code>true</code> if the the Set of focus traversal keys for the |
|
7083 |
* given focus traversal operation has been explicitly defined for |
|
7084 |
* this Component; <code>false</code> otherwise. |
|
7085 |
* @throws IllegalArgumentException if id is not one of |
|
7086 |
* KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
7087 |
* KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or |
|
7088 |
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS |
|
7089 |
* @since 1.4 |
|
7090 |
*/ |
|
7091 |
public boolean areFocusTraversalKeysSet(int id) { |
|
7092 |
if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) { |
|
7093 |
throw new IllegalArgumentException("invalid focus traversal key identifier"); |
|
7094 |
} |
|
7095 |
||
7096 |
return (focusTraversalKeys != null && focusTraversalKeys[id] != null); |
|
7097 |
} |
|
7098 |
||
7099 |
/** |
|
7100 |
* Sets whether focus traversal keys are enabled for this Component. |
|
7101 |
* Components for which focus traversal keys are disabled receive key |
|
7102 |
* events for focus traversal keys. Components for which focus traversal |
|
7103 |
* keys are enabled do not see these events; instead, the events are |
|
7104 |
* automatically converted to traversal operations. |
|
7105 |
* |
|
7106 |
* @param focusTraversalKeysEnabled whether focus traversal keys are |
|
7107 |
* enabled for this Component |
|
7108 |
* @see #getFocusTraversalKeysEnabled |
|
7109 |
* @see #setFocusTraversalKeys |
|
7110 |
* @see #getFocusTraversalKeys |
|
7111 |
* @since 1.4 |
|
7112 |
* @beaninfo |
|
7113 |
* bound: true |
|
7114 |
*/ |
|
7115 |
public void setFocusTraversalKeysEnabled(boolean |
|
7116 |
focusTraversalKeysEnabled) { |
|
7117 |
boolean oldFocusTraversalKeysEnabled; |
|
7118 |
synchronized (this) { |
|
7119 |
oldFocusTraversalKeysEnabled = this.focusTraversalKeysEnabled; |
|
7120 |
this.focusTraversalKeysEnabled = focusTraversalKeysEnabled; |
|
7121 |
} |
|
7122 |
firePropertyChange("focusTraversalKeysEnabled", |
|
7123 |
oldFocusTraversalKeysEnabled, |
|
7124 |
focusTraversalKeysEnabled); |
|
7125 |
} |
|
7126 |
||
7127 |
/** |
|
7128 |
* Returns whether focus traversal keys are enabled for this Component. |
|
7129 |
* Components for which focus traversal keys are disabled receive key |
|
7130 |
* events for focus traversal keys. Components for which focus traversal |
|
7131 |
* keys are enabled do not see these events; instead, the events are |
|
7132 |
* automatically converted to traversal operations. |
|
7133 |
* |
|
7134 |
* @return whether focus traversal keys are enabled for this Component |
|
7135 |
* @see #setFocusTraversalKeysEnabled |
|
7136 |
* @see #setFocusTraversalKeys |
|
7137 |
* @see #getFocusTraversalKeys |
|
7138 |
* @since 1.4 |
|
7139 |
*/ |
|
7140 |
public boolean getFocusTraversalKeysEnabled() { |
|
7141 |
return focusTraversalKeysEnabled; |
|
7142 |
} |
|
7143 |
||
7144 |
/** |
|
7145 |
* Requests that this Component get the input focus, and that this |
|
7146 |
* Component's top-level ancestor become the focused Window. This |
|
7147 |
* component must be displayable, focusable, visible and all of |
|
7148 |
* its ancestors (with the exception of the top-level Window) must |
|
7149 |
* be visible for the request to be granted. Every effort will be |
|
7150 |
* made to honor the request; however, in some cases it may be |
|
7151 |
* impossible to do so. Developers must never assume that this |
|
7152 |
* Component is the focus owner until this Component receives a |
|
7153 |
* FOCUS_GAINED event. If this request is denied because this |
|
7154 |
* Component's top-level Window cannot become the focused Window, |
|
7155 |
* the request will be remembered and will be granted when the |
|
7156 |
* Window is later focused by the user. |
|
7157 |
* <p> |
|
7158 |
* This method cannot be used to set the focus owner to no Component at |
|
7159 |
* all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner()</code> |
|
7160 |
* instead. |
|
7161 |
* <p> |
|
7162 |
* Because the focus behavior of this method is platform-dependent, |
|
7163 |
* developers are strongly encouraged to use |
|
7164 |
* <code>requestFocusInWindow</code> when possible. |
|
7165 |
* |
|
7166 |
* <p>Note: Not all focus transfers result from invoking this method. As |
|
7167 |
* such, a component may receive focus without this or any of the other |
|
7168 |
* {@code requestFocus} methods of {@code Component} being invoked. |
|
7169 |
* |
|
7170 |
* @see #requestFocusInWindow |
|
7171 |
* @see java.awt.event.FocusEvent |
|
7172 |
* @see #addFocusListener |
|
7173 |
* @see #isFocusable |
|
7174 |
* @see #isDisplayable |
|
7175 |
* @see KeyboardFocusManager#clearGlobalFocusOwner |
|
7176 |
* @since JDK1.0 |
|
7177 |
*/ |
|
7178 |
public void requestFocus() { |
|
7179 |
requestFocusHelper(false, true); |
|
7180 |
} |
|
7181 |
||
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
7182 |
boolean requestFocus(CausedFocusEvent.Cause cause) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
7183 |
return requestFocusHelper(false, true, cause); |
2 | 7184 |
} |
7185 |
||
7186 |
/** |
|
7187 |
* Requests that this <code>Component</code> get the input focus, |
|
7188 |
* and that this <code>Component</code>'s top-level ancestor |
|
7189 |
* become the focused <code>Window</code>. This component must be |
|
7190 |
* displayable, focusable, visible and all of its ancestors (with |
|
7191 |
* the exception of the top-level Window) must be visible for the |
|
7192 |
* request to be granted. Every effort will be made to honor the |
|
7193 |
* request; however, in some cases it may be impossible to do |
|
7194 |
* so. Developers must never assume that this component is the |
|
7195 |
* focus owner until this component receives a FOCUS_GAINED |
|
7196 |
* event. If this request is denied because this component's |
|
7197 |
* top-level window cannot become the focused window, the request |
|
7198 |
* will be remembered and will be granted when the window is later |
|
7199 |
* focused by the user. |
|
7200 |
* <p> |
|
7201 |
* This method returns a boolean value. If <code>false</code> is returned, |
|
7202 |
* the request is <b>guaranteed to fail</b>. If <code>true</code> is |
|
7203 |
* returned, the request will succeed <b>unless</b> it is vetoed, or an |
|
7204 |
* extraordinary event, such as disposal of the component's peer, occurs |
|
7205 |
* before the request can be granted by the native windowing system. Again, |
|
7206 |
* while a return value of <code>true</code> indicates that the request is |
|
7207 |
* likely to succeed, developers must never assume that this component is |
|
7208 |
* the focus owner until this component receives a FOCUS_GAINED event. |
|
7209 |
* <p> |
|
7210 |
* This method cannot be used to set the focus owner to no component at |
|
7211 |
* all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner</code> |
|
7212 |
* instead. |
|
7213 |
* <p> |
|
7214 |
* Because the focus behavior of this method is platform-dependent, |
|
7215 |
* developers are strongly encouraged to use |
|
7216 |
* <code>requestFocusInWindow</code> when possible. |
|
7217 |
* <p> |
|
7218 |
* Every effort will be made to ensure that <code>FocusEvent</code>s |
|
7219 |
* generated as a |
|
7220 |
* result of this request will have the specified temporary value. However, |
|
7221 |
* because specifying an arbitrary temporary state may not be implementable |
|
7222 |
* on all native windowing systems, correct behavior for this method can be |
|
7223 |
* guaranteed only for lightweight <code>Component</code>s. |
|
7224 |
* This method is not intended |
|
7225 |
* for general use, but exists instead as a hook for lightweight component |
|
7226 |
* libraries, such as Swing. |
|
7227 |
* |
|
7228 |
* <p>Note: Not all focus transfers result from invoking this method. As |
|
7229 |
* such, a component may receive focus without this or any of the other |
|
7230 |
* {@code requestFocus} methods of {@code Component} being invoked. |
|
7231 |
* |
|
7232 |
* @param temporary true if the focus change is temporary, |
|
7233 |
* such as when the window loses the focus; for |
|
7234 |
* more information on temporary focus changes see the |
|
7235 |
*<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a> |
|
7236 |
* @return <code>false</code> if the focus change request is guaranteed to |
|
7237 |
* fail; <code>true</code> if it is likely to succeed |
|
7238 |
* @see java.awt.event.FocusEvent |
|
7239 |
* @see #addFocusListener |
|
7240 |
* @see #isFocusable |
|
7241 |
* @see #isDisplayable |
|
7242 |
* @see KeyboardFocusManager#clearGlobalFocusOwner |
|
7243 |
* @since 1.4 |
|
7244 |
*/ |
|
7245 |
protected boolean requestFocus(boolean temporary) { |
|
7246 |
return requestFocusHelper(temporary, true); |
|
7247 |
} |
|
7248 |
||
7249 |
boolean requestFocus(boolean temporary, CausedFocusEvent.Cause cause) { |
|
7250 |
return requestFocusHelper(temporary, true, cause); |
|
7251 |
} |
|
7252 |
/** |
|
7253 |
* Requests that this Component get the input focus, if this |
|
7254 |
* Component's top-level ancestor is already the focused |
|
7255 |
* Window. This component must be displayable, focusable, visible |
|
7256 |
* and all of its ancestors (with the exception of the top-level |
|
7257 |
* Window) must be visible for the request to be granted. Every |
|
7258 |
* effort will be made to honor the request; however, in some |
|
7259 |
* cases it may be impossible to do so. Developers must never |
|
7260 |
* assume that this Component is the focus owner until this |
|
7261 |
* Component receives a FOCUS_GAINED event. |
|
7262 |
* <p> |
|
7263 |
* This method returns a boolean value. If <code>false</code> is returned, |
|
7264 |
* the request is <b>guaranteed to fail</b>. If <code>true</code> is |
|
7265 |
* returned, the request will succeed <b>unless</b> it is vetoed, or an |
|
7266 |
* extraordinary event, such as disposal of the Component's peer, occurs |
|
7267 |
* before the request can be granted by the native windowing system. Again, |
|
7268 |
* while a return value of <code>true</code> indicates that the request is |
|
7269 |
* likely to succeed, developers must never assume that this Component is |
|
7270 |
* the focus owner until this Component receives a FOCUS_GAINED event. |
|
7271 |
* <p> |
|
7272 |
* This method cannot be used to set the focus owner to no Component at |
|
7273 |
* all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner()</code> |
|
7274 |
* instead. |
|
7275 |
* <p> |
|
7276 |
* The focus behavior of this method can be implemented uniformly across |
|
7277 |
* platforms, and thus developers are strongly encouraged to use this |
|
7278 |
* method over <code>requestFocus</code> when possible. Code which relies |
|
7279 |
* on <code>requestFocus</code> may exhibit different focus behavior on |
|
7280 |
* different platforms. |
|
7281 |
* |
|
7282 |
* <p>Note: Not all focus transfers result from invoking this method. As |
|
7283 |
* such, a component may receive focus without this or any of the other |
|
7284 |
* {@code requestFocus} methods of {@code Component} being invoked. |
|
7285 |
* |
|
7286 |
* @return <code>false</code> if the focus change request is guaranteed to |
|
7287 |
* fail; <code>true</code> if it is likely to succeed |
|
7288 |
* @see #requestFocus |
|
7289 |
* @see java.awt.event.FocusEvent |
|
7290 |
* @see #addFocusListener |
|
7291 |
* @see #isFocusable |
|
7292 |
* @see #isDisplayable |
|
7293 |
* @see KeyboardFocusManager#clearGlobalFocusOwner |
|
7294 |
* @since 1.4 |
|
7295 |
*/ |
|
7296 |
public boolean requestFocusInWindow() { |
|
7297 |
return requestFocusHelper(false, false); |
|
7298 |
} |
|
7299 |
||
7300 |
boolean requestFocusInWindow(CausedFocusEvent.Cause cause) { |
|
7301 |
return requestFocusHelper(false, false, cause); |
|
7302 |
} |
|
7303 |
||
7304 |
/** |
|
7305 |
* Requests that this <code>Component</code> get the input focus, |
|
7306 |
* if this <code>Component</code>'s top-level ancestor is already |
|
7307 |
* the focused <code>Window</code>. This component must be |
|
7308 |
* displayable, focusable, visible and all of its ancestors (with |
|
7309 |
* the exception of the top-level Window) must be visible for the |
|
7310 |
* request to be granted. Every effort will be made to honor the |
|
7311 |
* request; however, in some cases it may be impossible to do |
|
7312 |
* so. Developers must never assume that this component is the |
|
7313 |
* focus owner until this component receives a FOCUS_GAINED event. |
|
7314 |
* <p> |
|
7315 |
* This method returns a boolean value. If <code>false</code> is returned, |
|
7316 |
* the request is <b>guaranteed to fail</b>. If <code>true</code> is |
|
7317 |
* returned, the request will succeed <b>unless</b> it is vetoed, or an |
|
7318 |
* extraordinary event, such as disposal of the component's peer, occurs |
|
7319 |
* before the request can be granted by the native windowing system. Again, |
|
7320 |
* while a return value of <code>true</code> indicates that the request is |
|
7321 |
* likely to succeed, developers must never assume that this component is |
|
7322 |
* the focus owner until this component receives a FOCUS_GAINED event. |
|
7323 |
* <p> |
|
7324 |
* This method cannot be used to set the focus owner to no component at |
|
7325 |
* all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner</code> |
|
7326 |
* instead. |
|
7327 |
* <p> |
|
7328 |
* The focus behavior of this method can be implemented uniformly across |
|
7329 |
* platforms, and thus developers are strongly encouraged to use this |
|
7330 |
* method over <code>requestFocus</code> when possible. Code which relies |
|
7331 |
* on <code>requestFocus</code> may exhibit different focus behavior on |
|
7332 |
* different platforms. |
|
7333 |
* <p> |
|
7334 |
* Every effort will be made to ensure that <code>FocusEvent</code>s |
|
7335 |
* generated as a |
|
7336 |
* result of this request will have the specified temporary value. However, |
|
7337 |
* because specifying an arbitrary temporary state may not be implementable |
|
7338 |
* on all native windowing systems, correct behavior for this method can be |
|
7339 |
* guaranteed only for lightweight components. This method is not intended |
|
7340 |
* for general use, but exists instead as a hook for lightweight component |
|
7341 |
* libraries, such as Swing. |
|
7342 |
* |
|
7343 |
* <p>Note: Not all focus transfers result from invoking this method. As |
|
7344 |
* such, a component may receive focus without this or any of the other |
|
7345 |
* {@code requestFocus} methods of {@code Component} being invoked. |
|
7346 |
* |
|
7347 |
* @param temporary true if the focus change is temporary, |
|
7348 |
* such as when the window loses the focus; for |
|
7349 |
* more information on temporary focus changes see the |
|
7350 |
*<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a> |
|
7351 |
* @return <code>false</code> if the focus change request is guaranteed to |
|
7352 |
* fail; <code>true</code> if it is likely to succeed |
|
7353 |
* @see #requestFocus |
|
7354 |
* @see java.awt.event.FocusEvent |
|
7355 |
* @see #addFocusListener |
|
7356 |
* @see #isFocusable |
|
7357 |
* @see #isDisplayable |
|
7358 |
* @see KeyboardFocusManager#clearGlobalFocusOwner |
|
7359 |
* @since 1.4 |
|
7360 |
*/ |
|
7361 |
protected boolean requestFocusInWindow(boolean temporary) { |
|
7362 |
return requestFocusHelper(temporary, false); |
|
7363 |
} |
|
7364 |
||
7365 |
boolean requestFocusInWindow(boolean temporary, CausedFocusEvent.Cause cause) { |
|
7366 |
return requestFocusHelper(temporary, false, cause); |
|
7367 |
} |
|
7368 |
||
7369 |
final boolean requestFocusHelper(boolean temporary, |
|
7370 |
boolean focusedWindowChangeAllowed) { |
|
7371 |
return requestFocusHelper(temporary, focusedWindowChangeAllowed, CausedFocusEvent.Cause.UNKNOWN); |
|
7372 |
} |
|
7373 |
||
7374 |
final boolean requestFocusHelper(boolean temporary, |
|
7375 |
boolean focusedWindowChangeAllowed, |
|
7376 |
CausedFocusEvent.Cause cause) |
|
7377 |
{ |
|
7378 |
if (!isRequestFocusAccepted(temporary, focusedWindowChangeAllowed, cause)) { |
|
7379 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7380 |
focusLog.log(Level.FINEST, "requestFocus is not accepted"); |
|
7381 |
} |
|
7382 |
return false; |
|
7383 |
} |
|
7384 |
||
7385 |
// Update most-recent map |
|
7386 |
KeyboardFocusManager.setMostRecentFocusOwner(this); |
|
7387 |
||
7388 |
Component window = this; |
|
7389 |
while ( (window != null) && !(window instanceof Window)) { |
|
7390 |
if (!window.isVisible()) { |
|
7391 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7392 |
focusLog.log(Level.FINEST, "component is recurively invisible"); |
|
7393 |
} |
|
7394 |
return false; |
|
7395 |
} |
|
7396 |
window = window.parent; |
|
7397 |
} |
|
7398 |
||
7399 |
ComponentPeer peer = this.peer; |
|
7400 |
Component heavyweight = (peer instanceof LightweightPeer) |
|
7401 |
? getNativeContainer() : this; |
|
7402 |
if (heavyweight == null || !heavyweight.isVisible()) { |
|
7403 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7404 |
focusLog.log(Level.FINEST, "Component is not a part of visible hierarchy"); |
|
7405 |
} |
|
7406 |
return false; |
|
7407 |
} |
|
7408 |
peer = heavyweight.peer; |
|
7409 |
if (peer == null) { |
|
7410 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7411 |
focusLog.log(Level.FINEST, "Peer is null"); |
|
7412 |
} |
|
7413 |
return false; |
|
7414 |
} |
|
7415 |
||
7416 |
// Focus this Component |
|
7417 |
long time = EventQueue.getMostRecentEventTime(); |
|
7418 |
boolean success = peer.requestFocus |
|
7419 |
(this, temporary, focusedWindowChangeAllowed, time, cause); |
|
7420 |
if (!success) { |
|
7421 |
KeyboardFocusManager.getCurrentKeyboardFocusManager |
|
7422 |
(appContext).dequeueKeyEvents(time, this); |
|
7423 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7424 |
focusLog.log(Level.FINEST, "Peer request failed"); |
|
7425 |
} |
|
7426 |
} else { |
|
7427 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7428 |
focusLog.log(Level.FINEST, "Pass for " + this); |
|
7429 |
} |
|
7430 |
} |
|
7431 |
return success; |
|
7432 |
} |
|
7433 |
||
7434 |
private boolean isRequestFocusAccepted(boolean temporary, |
|
7435 |
boolean focusedWindowChangeAllowed, |
|
7436 |
CausedFocusEvent.Cause cause) |
|
7437 |
{ |
|
7438 |
if (!isFocusable() || !isVisible()) { |
|
7439 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7440 |
focusLog.log(Level.FINEST, "Not focusable or not visible"); |
|
7441 |
} |
|
7442 |
return false; |
|
7443 |
} |
|
7444 |
||
7445 |
ComponentPeer peer = this.peer; |
|
7446 |
if (peer == null) { |
|
7447 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7448 |
focusLog.log(Level.FINEST, "peer is null"); |
|
7449 |
} |
|
7450 |
return false; |
|
7451 |
} |
|
7452 |
||
7453 |
Window window = getContainingWindow(); |
|
7454 |
if (window == null || !((Window)window).isFocusableWindow()) { |
|
7455 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7456 |
focusLog.log(Level.FINEST, "Component doesn't have toplevel"); |
|
7457 |
} |
|
7458 |
return false; |
|
7459 |
} |
|
7460 |
||
7461 |
// We have passed all regular checks for focus request, |
|
7462 |
// now let's call RequestFocusController and see what it says. |
|
7463 |
Component focusOwner = KeyboardFocusManager.getMostRecentFocusOwner(window); |
|
7464 |
if (focusOwner == null) { |
|
7465 |
// sometimes most recent focus owner may be null, but focus owner is not |
|
7466 |
// e.g. we reset most recent focus owner if user removes focus owner |
|
7467 |
focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); |
|
2451 | 7468 |
if (focusOwner != null && focusOwner.getContainingWindow() != window) { |
2 | 7469 |
focusOwner = null; |
7470 |
} |
|
7471 |
} |
|
7472 |
||
7473 |
if (focusOwner == this || focusOwner == null) { |
|
7474 |
// Controller is supposed to verify focus transfers and for this it |
|
7475 |
// should know both from and to components. And it shouldn't verify |
|
7476 |
// transfers from when these components are equal. |
|
7477 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7478 |
focusLog.log(Level.FINEST, "focus owner is null or this"); |
|
7479 |
} |
|
7480 |
return true; |
|
7481 |
} |
|
7482 |
||
7483 |
if (CausedFocusEvent.Cause.ACTIVATION == cause) { |
|
7484 |
// we shouldn't call RequestFocusController in case we are |
|
7485 |
// in activation. We do request focus on component which |
|
7486 |
// has got temporary focus lost and then on component which is |
|
7487 |
// most recent focus owner. But most recent focus owner can be |
|
7488 |
// changed by requestFocsuXXX() call only, so this transfer has |
|
7489 |
// been already approved. |
|
7490 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7491 |
focusLog.log(Level.FINEST, "cause is activation"); |
|
7492 |
} |
|
7493 |
return true; |
|
7494 |
} |
|
7495 |
||
7496 |
boolean ret = Component.requestFocusController.acceptRequestFocus(focusOwner, |
|
7497 |
this, |
|
7498 |
temporary, |
|
7499 |
focusedWindowChangeAllowed, |
|
7500 |
cause); |
|
7501 |
if (focusLog.isLoggable(Level.FINEST)) { |
|
7502 |
focusLog.log(Level.FINEST, "RequestFocusController returns {0}", ret); |
|
7503 |
} |
|
7504 |
||
7505 |
return ret; |
|
7506 |
} |
|
7507 |
||
7508 |
private static RequestFocusController requestFocusController = new DummyRequestFocusController(); |
|
7509 |
||
7510 |
// Swing access this method through reflection to implement InputVerifier's functionality. |
|
7511 |
// Perhaps, we should make this method public (later ;) |
|
7512 |
private static class DummyRequestFocusController implements RequestFocusController { |
|
7513 |
public boolean acceptRequestFocus(Component from, Component to, |
|
7514 |
boolean temporary, boolean focusedWindowChangeAllowed, |
|
7515 |
CausedFocusEvent.Cause cause) |
|
7516 |
{ |
|
7517 |
return true; |
|
7518 |
} |
|
7519 |
}; |
|
7520 |
||
7521 |
synchronized static void setRequestFocusController(RequestFocusController requestController) |
|
7522 |
{ |
|
7523 |
if (requestController == null) { |
|
7524 |
requestFocusController = new DummyRequestFocusController(); |
|
7525 |
} else { |
|
7526 |
requestFocusController = requestController; |
|
7527 |
} |
|
7528 |
} |
|
7529 |
||
7530 |
/** |
|
7531 |
* Returns the Container which is the focus cycle root of this Component's |
|
7532 |
* focus traversal cycle. Each focus traversal cycle has only a single |
|
7533 |
* focus cycle root and each Component which is not a Container belongs to |
|
7534 |
* only a single focus traversal cycle. Containers which are focus cycle |
|
7535 |
* roots belong to two cycles: one rooted at the Container itself, and one |
|
7536 |
* rooted at the Container's nearest focus-cycle-root ancestor. For such |
|
7537 |
* Containers, this method will return the Container's nearest focus-cycle- |
|
7538 |
* root ancestor. |
|
7539 |
* |
|
7540 |
* @return this Component's nearest focus-cycle-root ancestor |
|
7541 |
* @see Container#isFocusCycleRoot() |
|
7542 |
* @since 1.4 |
|
7543 |
*/ |
|
7544 |
public Container getFocusCycleRootAncestor() { |
|
7545 |
Container rootAncestor = this.parent; |
|
7546 |
while (rootAncestor != null && !rootAncestor.isFocusCycleRoot()) { |
|
7547 |
rootAncestor = rootAncestor.parent; |
|
7548 |
} |
|
7549 |
return rootAncestor; |
|
7550 |
} |
|
7551 |
||
7552 |
/** |
|
7553 |
* Returns whether the specified Container is the focus cycle root of this |
|
7554 |
* Component's focus traversal cycle. Each focus traversal cycle has only |
|
7555 |
* a single focus cycle root and each Component which is not a Container |
|
7556 |
* belongs to only a single focus traversal cycle. |
|
7557 |
* |
|
7558 |
* @param container the Container to be tested |
|
7559 |
* @return <code>true</code> if the specified Container is a focus-cycle- |
|
7560 |
* root of this Component; <code>false</code> otherwise |
|
7561 |
* @see Container#isFocusCycleRoot() |
|
7562 |
* @since 1.4 |
|
7563 |
*/ |
|
7564 |
public boolean isFocusCycleRoot(Container container) { |
|
7565 |
Container rootAncestor = getFocusCycleRootAncestor(); |
|
7566 |
return (rootAncestor == container); |
|
7567 |
} |
|
7568 |
||
441 | 7569 |
Container getTraversalRoot() { |
7570 |
return getFocusCycleRootAncestor(); |
|
7571 |
} |
|
7572 |
||
7573 |
/** |
|
7574 |
* Transfers the focus to the next component, as though this Component were |
|
7575 |
* the focus owner. |
|
7576 |
* @see #requestFocus() |
|
7577 |
* @since JDK1.1 |
|
7578 |
*/ |
|
7579 |
public void transferFocus() { |
|
7580 |
nextFocus(); |
|
7581 |
} |
|
7582 |
||
2 | 7583 |
/** |
7584 |
* @deprecated As of JDK version 1.1, |
|
7585 |
* replaced by transferFocus(). |
|
7586 |
*/ |
|
7587 |
@Deprecated |
|
7588 |
public void nextFocus() { |
|
441 | 7589 |
transferFocus(false); |
7590 |
} |
|
7591 |
||
7592 |
boolean transferFocus(boolean clearOnFailure) { |
|
2 | 7593 |
if (focusLog.isLoggable(Level.FINER)) { |
441 | 7594 |
focusLog.finer("clearOnFailure = " + clearOnFailure); |
7595 |
} |
|
7596 |
Component toFocus = getNextFocusCandidate(); |
|
7597 |
boolean res = false; |
|
7598 |
if (toFocus != null && !toFocus.isFocusOwner() && toFocus != this) { |
|
7599 |
res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_FORWARD); |
|
7600 |
} |
|
7601 |
if (clearOnFailure && !res) { |
|
7602 |
if (focusLog.isLoggable(Level.FINER)) { |
|
7603 |
focusLog.finer("clear global focus owner"); |
|
7604 |
} |
|
7605 |
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); |
|
7606 |
} |
|
7607 |
if (focusLog.isLoggable(Level.FINER)) { |
|
7608 |
focusLog.finer("returning result: " + res); |
|
7609 |
} |
|
7610 |
return res; |
|
7611 |
} |
|
7612 |
||
7613 |
final Component getNextFocusCandidate() { |
|
2 | 7614 |
Container rootAncestor = getTraversalRoot(); |
7615 |
Component comp = this; |
|
7616 |
while (rootAncestor != null && |
|
1171
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
7617 |
!(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner())) |
2 | 7618 |
{ |
7619 |
comp = rootAncestor; |
|
7620 |
rootAncestor = comp.getFocusCycleRootAncestor(); |
|
7621 |
} |
|
7622 |
if (focusLog.isLoggable(Level.FINER)) { |
|
441 | 7623 |
focusLog.finer("comp = " + comp + ", root = " + rootAncestor); |
7624 |
} |
|
7625 |
Component candidate = null; |
|
2 | 7626 |
if (rootAncestor != null) { |
7627 |
FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy(); |
|
7628 |
Component toFocus = policy.getComponentAfter(rootAncestor, comp); |
|
7629 |
if (focusLog.isLoggable(Level.FINER)) { |
|
441 | 7630 |
focusLog.finer("component after is " + toFocus); |
2 | 7631 |
} |
7632 |
if (toFocus == null) { |
|
7633 |
toFocus = policy.getDefaultComponent(rootAncestor); |
|
7634 |
if (focusLog.isLoggable(Level.FINER)) { |
|
441 | 7635 |
focusLog.finer("default component is " + toFocus); |
2 | 7636 |
} |
7637 |
} |
|
7638 |
if (toFocus == null) { |
|
7639 |
Applet applet = EmbeddedFrame.getAppletIfAncestorOf(this); |
|
7640 |
if (applet != null) { |
|
7641 |
toFocus = applet; |
|
7642 |
} |
|
7643 |
} |
|
441 | 7644 |
candidate = toFocus; |
7645 |
} |
|
7646 |
if (focusLog.isLoggable(Level.FINER)) { |
|
7647 |
focusLog.finer("Focus transfer candidate: " + candidate); |
|
7648 |
} |
|
7649 |
return candidate; |
|
2 | 7650 |
} |
7651 |
||
7652 |
/** |
|
7653 |
* Transfers the focus to the previous component, as though this Component |
|
7654 |
* were the focus owner. |
|
7655 |
* @see #requestFocus() |
|
7656 |
* @since 1.4 |
|
7657 |
*/ |
|
7658 |
public void transferFocusBackward() { |
|
441 | 7659 |
transferFocusBackward(false); |
7660 |
} |
|
7661 |
||
7662 |
boolean transferFocusBackward(boolean clearOnFailure) { |
|
2 | 7663 |
Container rootAncestor = getTraversalRoot(); |
7664 |
Component comp = this; |
|
7665 |
while (rootAncestor != null && |
|
1171
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
7666 |
!(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner())) |
2 | 7667 |
{ |
7668 |
comp = rootAncestor; |
|
7669 |
rootAncestor = comp.getFocusCycleRootAncestor(); |
|
7670 |
} |
|
441 | 7671 |
boolean res = false; |
2 | 7672 |
if (rootAncestor != null) { |
7673 |
FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy(); |
|
7674 |
Component toFocus = policy.getComponentBefore(rootAncestor, comp); |
|
7675 |
if (toFocus == null) { |
|
7676 |
toFocus = policy.getDefaultComponent(rootAncestor); |
|
7677 |
} |
|
7678 |
if (toFocus != null) { |
|
441 | 7679 |
res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD); |
7680 |
} |
|
7681 |
} |
|
7682 |
if (!res) { |
|
7683 |
if (focusLog.isLoggable(Level.FINER)) { |
|
7684 |
focusLog.finer("clear global focus owner"); |
|
7685 |
} |
|
7686 |
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); |
|
7687 |
} |
|
7688 |
if (focusLog.isLoggable(Level.FINER)) { |
|
7689 |
focusLog.finer("returning result: " + res); |
|
7690 |
} |
|
7691 |
return res; |
|
2 | 7692 |
} |
7693 |
||
7694 |
/** |
|
7695 |
* Transfers the focus up one focus traversal cycle. Typically, the focus |
|
7696 |
* owner is set to this Component's focus cycle root, and the current focus |
|
7697 |
* cycle root is set to the new focus owner's focus cycle root. If, |
|
7698 |
* however, this Component's focus cycle root is a Window, then the focus |
|
7699 |
* owner is set to the focus cycle root's default Component to focus, and |
|
7700 |
* the current focus cycle root is unchanged. |
|
7701 |
* |
|
7702 |
* @see #requestFocus() |
|
7703 |
* @see Container#isFocusCycleRoot() |
|
7704 |
* @see Container#setFocusCycleRoot(boolean) |
|
7705 |
* @since 1.4 |
|
7706 |
*/ |
|
7707 |
public void transferFocusUpCycle() { |
|
7708 |
Container rootAncestor; |
|
7709 |
for (rootAncestor = getFocusCycleRootAncestor(); |
|
7710 |
rootAncestor != null && !(rootAncestor.isShowing() && |
|
7711 |
rootAncestor.isFocusable() && |
|
7712 |
rootAncestor.isEnabled()); |
|
7713 |
rootAncestor = rootAncestor.getFocusCycleRootAncestor()) { |
|
7714 |
} |
|
7715 |
||
7716 |
if (rootAncestor != null) { |
|
7717 |
Container rootAncestorRootAncestor = |
|
7718 |
rootAncestor.getFocusCycleRootAncestor(); |
|
7719 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
7720 |
setGlobalCurrentFocusCycleRoot( |
|
7721 |
(rootAncestorRootAncestor != null) |
|
7722 |
? rootAncestorRootAncestor |
|
7723 |
: rootAncestor); |
|
7724 |
rootAncestor.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_UP); |
|
7725 |
} else { |
|
7726 |
Window window = getContainingWindow(); |
|
7727 |
||
7728 |
if (window != null) { |
|
7729 |
Component toFocus = window.getFocusTraversalPolicy(). |
|
7730 |
getDefaultComponent(window); |
|
7731 |
if (toFocus != null) { |
|
7732 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
7733 |
setGlobalCurrentFocusCycleRoot(window); |
|
7734 |
toFocus.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_UP); |
|
7735 |
} |
|
7736 |
} |
|
7737 |
} |
|
7738 |
} |
|
7739 |
||
7740 |
/** |
|
7741 |
* Returns <code>true</code> if this <code>Component</code> is the |
|
7742 |
* focus owner. This method is obsolete, and has been replaced by |
|
7743 |
* <code>isFocusOwner()</code>. |
|
7744 |
* |
|
7745 |
* @return <code>true</code> if this <code>Component</code> is the |
|
7746 |
* focus owner; <code>false</code> otherwise |
|
7747 |
* @since 1.2 |
|
7748 |
*/ |
|
7749 |
public boolean hasFocus() { |
|
7750 |
return (KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
7751 |
getFocusOwner() == this); |
|
7752 |
} |
|
7753 |
||
7754 |
/** |
|
7755 |
* Returns <code>true</code> if this <code>Component</code> is the |
|
7756 |
* focus owner. |
|
7757 |
* |
|
7758 |
* @return <code>true</code> if this <code>Component</code> is the |
|
7759 |
* focus owner; <code>false</code> otherwise |
|
7760 |
* @since 1.4 |
|
7761 |
*/ |
|
7762 |
public boolean isFocusOwner() { |
|
7763 |
return hasFocus(); |
|
7764 |
} |
|
7765 |
||
441 | 7766 |
/* |
7767 |
* Used to disallow auto-focus-transfer on disposal of the focus owner |
|
7768 |
* in the process of disposing its parent container. |
|
7769 |
*/ |
|
7770 |
private boolean autoFocusTransferOnDisposal = true; |
|
7771 |
||
7772 |
void setAutoFocusTransferOnDisposal(boolean value) { |
|
7773 |
autoFocusTransferOnDisposal = value; |
|
7774 |
} |
|
7775 |
||
7776 |
boolean isAutoFocusTransferOnDisposal() { |
|
7777 |
return autoFocusTransferOnDisposal; |
|
7778 |
} |
|
7779 |
||
2 | 7780 |
/** |
7781 |
* Adds the specified popup menu to the component. |
|
7782 |
* @param popup the popup menu to be added to the component. |
|
7783 |
* @see #remove(MenuComponent) |
|
7784 |
* @exception NullPointerException if {@code popup} is {@code null} |
|
7785 |
* @since JDK1.1 |
|
7786 |
*/ |
|
7787 |
public void add(PopupMenu popup) { |
|
7788 |
synchronized (getTreeLock()) { |
|
7789 |
if (popup.parent != null) { |
|
7790 |
popup.parent.remove(popup); |
|
7791 |
} |
|
7792 |
if (popups == null) { |
|
7793 |
popups = new Vector(); |
|
7794 |
} |
|
7795 |
popups.addElement(popup); |
|
7796 |
popup.parent = this; |
|
7797 |
||
7798 |
if (peer != null) { |
|
7799 |
if (popup.peer == null) { |
|
7800 |
popup.addNotify(); |
|
7801 |
} |
|
7802 |
} |
|
7803 |
} |
|
7804 |
} |
|
7805 |
||
7806 |
/** |
|
7807 |
* Removes the specified popup menu from the component. |
|
7808 |
* @param popup the popup menu to be removed |
|
7809 |
* @see #add(PopupMenu) |
|
7810 |
* @since JDK1.1 |
|
7811 |
*/ |
|
7812 |
public void remove(MenuComponent popup) { |
|
7813 |
synchronized (getTreeLock()) { |
|
7814 |
if (popups == null) { |
|
7815 |
return; |
|
7816 |
} |
|
7817 |
int index = popups.indexOf(popup); |
|
7818 |
if (index >= 0) { |
|
7819 |
PopupMenu pmenu = (PopupMenu)popup; |
|
7820 |
if (pmenu.peer != null) { |
|
7821 |
pmenu.removeNotify(); |
|
7822 |
} |
|
7823 |
pmenu.parent = null; |
|
7824 |
popups.removeElementAt(index); |
|
7825 |
if (popups.size() == 0) { |
|
7826 |
popups = null; |
|
7827 |
} |
|
7828 |
} |
|
7829 |
} |
|
7830 |
} |
|
7831 |
||
7832 |
/** |
|
7833 |
* Returns a string representing the state of this component. This |
|
7834 |
* method is intended to be used only for debugging purposes, and the |
|
7835 |
* content and format of the returned string may vary between |
|
7836 |
* implementations. The returned string may be empty but may not be |
|
7837 |
* <code>null</code>. |
|
7838 |
* |
|
7839 |
* @return a string representation of this component's state |
|
7840 |
* @since JDK1.0 |
|
7841 |
*/ |
|
7842 |
protected String paramString() { |
|
7843 |
String thisName = getName(); |
|
7844 |
String str = (thisName != null? thisName : "") + "," + x + "," + y + "," + width + "x" + height; |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
7845 |
if (!isValid()) { |
2 | 7846 |
str += ",invalid"; |
7847 |
} |
|
7848 |
if (!visible) { |
|
7849 |
str += ",hidden"; |
|
7850 |
} |
|
7851 |
if (!enabled) { |
|
7852 |
str += ",disabled"; |
|
7853 |
} |
|
7854 |
return str; |
|
7855 |
} |
|
7856 |
||
7857 |
/** |
|
7858 |
* Returns a string representation of this component and its values. |
|
7859 |
* @return a string representation of this component |
|
7860 |
* @since JDK1.0 |
|
7861 |
*/ |
|
7862 |
public String toString() { |
|
7863 |
return getClass().getName() + "[" + paramString() + "]"; |
|
7864 |
} |
|
7865 |
||
7866 |
/** |
|
7867 |
* Prints a listing of this component to the standard system output |
|
7868 |
* stream <code>System.out</code>. |
|
7869 |
* @see java.lang.System#out |
|
7870 |
* @since JDK1.0 |
|
7871 |
*/ |
|
7872 |
public void list() { |
|
7873 |
list(System.out, 0); |
|
7874 |
} |
|
7875 |
||
7876 |
/** |
|
7877 |
* Prints a listing of this component to the specified output |
|
7878 |
* stream. |
|
7879 |
* @param out a print stream |
|
7880 |
* @since JDK1.0 |
|
7881 |
*/ |
|
7882 |
public void list(PrintStream out) { |
|
7883 |
list(out, 0); |
|
7884 |
} |
|
7885 |
||
7886 |
/** |
|
7887 |
* Prints out a list, starting at the specified indentation, to the |
|
7888 |
* specified print stream. |
|
7889 |
* @param out a print stream |
|
7890 |
* @param indent number of spaces to indent |
|
7891 |
* @see java.io.PrintStream#println(java.lang.Object) |
|
7892 |
* @since JDK1.0 |
|
7893 |
*/ |
|
7894 |
public void list(PrintStream out, int indent) { |
|
7895 |
for (int i = 0 ; i < indent ; i++) { |
|
7896 |
out.print(" "); |
|
7897 |
} |
|
7898 |
out.println(this); |
|
7899 |
} |
|
7900 |
||
7901 |
/** |
|
7902 |
* Prints a listing to the specified print writer. |
|
7903 |
* @param out the print writer to print to |
|
7904 |
* @since JDK1.1 |
|
7905 |
*/ |
|
7906 |
public void list(PrintWriter out) { |
|
7907 |
list(out, 0); |
|
7908 |
} |
|
7909 |
||
7910 |
/** |
|
7911 |
* Prints out a list, starting at the specified indentation, to |
|
7912 |
* the specified print writer. |
|
7913 |
* @param out the print writer to print to |
|
7914 |
* @param indent the number of spaces to indent |
|
7915 |
* @see java.io.PrintStream#println(java.lang.Object) |
|
7916 |
* @since JDK1.1 |
|
7917 |
*/ |
|
7918 |
public void list(PrintWriter out, int indent) { |
|
7919 |
for (int i = 0 ; i < indent ; i++) { |
|
7920 |
out.print(" "); |
|
7921 |
} |
|
7922 |
out.println(this); |
|
7923 |
} |
|
7924 |
||
7925 |
/* |
|
7926 |
* Fetches the native container somewhere higher up in the component |
|
7927 |
* tree that contains this component. |
|
7928 |
*/ |
|
7929 |
Container getNativeContainer() { |
|
7930 |
Container p = parent; |
|
7931 |
while (p != null && p.peer instanceof LightweightPeer) { |
|
7932 |
p = p.getParent(); |
|
7933 |
} |
|
7934 |
return p; |
|
7935 |
} |
|
7936 |
||
7937 |
/** |
|
7938 |
* Adds a PropertyChangeListener to the listener list. The listener is |
|
7939 |
* registered for all bound properties of this class, including the |
|
7940 |
* following: |
|
7941 |
* <ul> |
|
7942 |
* <li>this Component's font ("font")</li> |
|
7943 |
* <li>this Component's background color ("background")</li> |
|
7944 |
* <li>this Component's foreground color ("foreground")</li> |
|
7945 |
* <li>this Component's focusability ("focusable")</li> |
|
7946 |
* <li>this Component's focus traversal keys enabled state |
|
7947 |
* ("focusTraversalKeysEnabled")</li> |
|
7948 |
* <li>this Component's Set of FORWARD_TRAVERSAL_KEYS |
|
7949 |
* ("forwardFocusTraversalKeys")</li> |
|
7950 |
* <li>this Component's Set of BACKWARD_TRAVERSAL_KEYS |
|
7951 |
* ("backwardFocusTraversalKeys")</li> |
|
7952 |
* <li>this Component's Set of UP_CYCLE_TRAVERSAL_KEYS |
|
7953 |
* ("upCycleFocusTraversalKeys")</li> |
|
7954 |
* <li>this Component's preferred size ("preferredSize")</li> |
|
7955 |
* <li>this Component's minimum size ("minimumSize")</li> |
|
7956 |
* <li>this Component's maximum size ("maximumSize")</li> |
|
7957 |
* <li>this Component's name ("name")</li> |
|
7958 |
* </ul> |
|
7959 |
* Note that if this <code>Component</code> is inheriting a bound property, then no |
|
7960 |
* event will be fired in response to a change in the inherited property. |
|
7961 |
* <p> |
|
7962 |
* If <code>listener</code> is <code>null</code>, |
|
7963 |
* no exception is thrown and no action is performed. |
|
7964 |
* |
|
7965 |
* @param listener the property change listener to be added |
|
7966 |
* |
|
7967 |
* @see #removePropertyChangeListener |
|
7968 |
* @see #getPropertyChangeListeners |
|
7969 |
* @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener) |
|
7970 |
*/ |
|
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
7971 |
public void addPropertyChangeListener( |
2 | 7972 |
PropertyChangeListener listener) { |
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
7973 |
synchronized (getObjectLock()) { |
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
7974 |
if (listener == null) { |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
7975 |
return; |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
7976 |
} |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
7977 |
if (changeSupport == null) { |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
7978 |
changeSupport = new PropertyChangeSupport(this); |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
7979 |
} |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
7980 |
changeSupport.addPropertyChangeListener(listener); |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
7981 |
} |
2 | 7982 |
} |
7983 |
||
7984 |
/** |
|
7985 |
* Removes a PropertyChangeListener from the listener list. This method |
|
7986 |
* should be used to remove PropertyChangeListeners that were registered |
|
7987 |
* for all bound properties of this class. |
|
7988 |
* <p> |
|
7989 |
* If listener is null, no exception is thrown and no action is performed. |
|
7990 |
* |
|
7991 |
* @param listener the PropertyChangeListener to be removed |
|
7992 |
* |
|
7993 |
* @see #addPropertyChangeListener |
|
7994 |
* @see #getPropertyChangeListeners |
|
7995 |
* @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener) |
|
7996 |
*/ |
|
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
7997 |
public void removePropertyChangeListener( |
2 | 7998 |
PropertyChangeListener listener) { |
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
7999 |
synchronized (getObjectLock()) { |
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8000 |
if (listener == null || changeSupport == null) { |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8001 |
return; |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8002 |
} |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8003 |
changeSupport.removePropertyChangeListener(listener); |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8004 |
} |
2 | 8005 |
} |
8006 |
||
8007 |
/** |
|
8008 |
* Returns an array of all the property change listeners |
|
8009 |
* registered on this component. |
|
8010 |
* |
|
8011 |
* @return all of this component's <code>PropertyChangeListener</code>s |
|
8012 |
* or an empty array if no property change |
|
8013 |
* listeners are currently registered |
|
8014 |
* |
|
8015 |
* @see #addPropertyChangeListener |
|
8016 |
* @see #removePropertyChangeListener |
|
8017 |
* @see #getPropertyChangeListeners(java.lang.String) |
|
8018 |
* @see java.beans.PropertyChangeSupport#getPropertyChangeListeners |
|
8019 |
* @since 1.4 |
|
8020 |
*/ |
|
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8021 |
public PropertyChangeListener[] getPropertyChangeListeners() { |
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
8022 |
synchronized (getObjectLock()) { |
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8023 |
if (changeSupport == null) { |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8024 |
return new PropertyChangeListener[0]; |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8025 |
} |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8026 |
return changeSupport.getPropertyChangeListeners(); |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8027 |
} |
2 | 8028 |
} |
8029 |
||
8030 |
/** |
|
8031 |
* Adds a PropertyChangeListener to the listener list for a specific |
|
8032 |
* property. The specified property may be user-defined, or one of the |
|
8033 |
* following: |
|
8034 |
* <ul> |
|
8035 |
* <li>this Component's font ("font")</li> |
|
8036 |
* <li>this Component's background color ("background")</li> |
|
8037 |
* <li>this Component's foreground color ("foreground")</li> |
|
8038 |
* <li>this Component's focusability ("focusable")</li> |
|
8039 |
* <li>this Component's focus traversal keys enabled state |
|
8040 |
* ("focusTraversalKeysEnabled")</li> |
|
8041 |
* <li>this Component's Set of FORWARD_TRAVERSAL_KEYS |
|
8042 |
* ("forwardFocusTraversalKeys")</li> |
|
8043 |
* <li>this Component's Set of BACKWARD_TRAVERSAL_KEYS |
|
8044 |
* ("backwardFocusTraversalKeys")</li> |
|
8045 |
* <li>this Component's Set of UP_CYCLE_TRAVERSAL_KEYS |
|
8046 |
* ("upCycleFocusTraversalKeys")</li> |
|
8047 |
* </ul> |
|
8048 |
* Note that if this <code>Component</code> is inheriting a bound property, then no |
|
8049 |
* event will be fired in response to a change in the inherited property. |
|
8050 |
* <p> |
|
8051 |
* If <code>propertyName</code> or <code>listener</code> is <code>null</code>, |
|
8052 |
* no exception is thrown and no action is taken. |
|
8053 |
* |
|
8054 |
* @param propertyName one of the property names listed above |
|
8055 |
* @param listener the property change listener to be added |
|
8056 |
* |
|
8057 |
* @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener) |
|
8058 |
* @see #getPropertyChangeListeners(java.lang.String) |
|
8059 |
* @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener) |
|
8060 |
*/ |
|
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8061 |
public void addPropertyChangeListener( |
2 | 8062 |
String propertyName, |
8063 |
PropertyChangeListener listener) { |
|
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
8064 |
synchronized (getObjectLock()) { |
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8065 |
if (listener == null) { |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8066 |
return; |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8067 |
} |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8068 |
if (changeSupport == null) { |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8069 |
changeSupport = new PropertyChangeSupport(this); |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8070 |
} |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8071 |
changeSupport.addPropertyChangeListener(propertyName, listener); |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8072 |
} |
2 | 8073 |
} |
8074 |
||
8075 |
/** |
|
8076 |
* Removes a <code>PropertyChangeListener</code> from the listener |
|
8077 |
* list for a specific property. This method should be used to remove |
|
8078 |
* <code>PropertyChangeListener</code>s |
|
8079 |
* that were registered for a specific bound property. |
|
8080 |
* <p> |
|
8081 |
* If <code>propertyName</code> or <code>listener</code> is <code>null</code>, |
|
8082 |
* no exception is thrown and no action is taken. |
|
8083 |
* |
|
8084 |
* @param propertyName a valid property name |
|
8085 |
* @param listener the PropertyChangeListener to be removed |
|
8086 |
* |
|
8087 |
* @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener) |
|
8088 |
* @see #getPropertyChangeListeners(java.lang.String) |
|
8089 |
* @see #removePropertyChangeListener(java.beans.PropertyChangeListener) |
|
8090 |
*/ |
|
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8091 |
public void removePropertyChangeListener( |
2 | 8092 |
String propertyName, |
8093 |
PropertyChangeListener listener) { |
|
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
8094 |
synchronized (getObjectLock()) { |
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8095 |
if (listener == null || changeSupport == null) { |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8096 |
return; |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8097 |
} |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8098 |
changeSupport.removePropertyChangeListener(propertyName, listener); |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8099 |
} |
2 | 8100 |
} |
8101 |
||
8102 |
/** |
|
8103 |
* Returns an array of all the listeners which have been associated |
|
8104 |
* with the named property. |
|
8105 |
* |
|
8106 |
* @return all of the <code>PropertyChangeListener</code>s associated with |
|
8107 |
* the named property; if no such listeners have been added or |
|
8108 |
* if <code>propertyName</code> is <code>null</code>, an empty |
|
8109 |
* array is returned |
|
8110 |
* |
|
8111 |
* @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener) |
|
8112 |
* @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener) |
|
8113 |
* @see #getPropertyChangeListeners |
|
8114 |
* @since 1.4 |
|
8115 |
*/ |
|
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8116 |
public PropertyChangeListener[] getPropertyChangeListeners( |
2 | 8117 |
String propertyName) { |
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
8118 |
synchronized (getObjectLock()) { |
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8119 |
if (changeSupport == null) { |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8120 |
return new PropertyChangeListener[0]; |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8121 |
} |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8122 |
return changeSupport.getPropertyChangeListeners(propertyName); |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8123 |
} |
2 | 8124 |
} |
8125 |
||
8126 |
/** |
|
8127 |
* Support for reporting bound property changes for Object properties. |
|
8128 |
* This method can be called when a bound property has changed and it will |
|
8129 |
* send the appropriate PropertyChangeEvent to any registered |
|
8130 |
* PropertyChangeListeners. |
|
8131 |
* |
|
8132 |
* @param propertyName the property whose value has changed |
|
8133 |
* @param oldValue the property's previous value |
|
8134 |
* @param newValue the property's new value |
|
8135 |
*/ |
|
8136 |
protected void firePropertyChange(String propertyName, |
|
8137 |
Object oldValue, Object newValue) { |
|
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8138 |
PropertyChangeSupport changeSupport; |
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
8139 |
synchronized (getObjectLock()) { |
123
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8140 |
changeSupport = this.changeSupport; |
96a10460ed63
6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents:
121
diff
changeset
|
8141 |
} |
2 | 8142 |
if (changeSupport == null || |
8143 |
(oldValue != null && newValue != null && oldValue.equals(newValue))) { |
|
8144 |
return; |
|
8145 |
} |
|
8146 |
changeSupport.firePropertyChange(propertyName, oldValue, newValue); |
|
8147 |
} |
|
8148 |
||
8149 |
/** |
|
8150 |
* Support for reporting bound property changes for boolean properties. |
|
8151 |
* This method can be called when a bound property has changed and it will |
|
8152 |
* send the appropriate PropertyChangeEvent to any registered |
|
8153 |
* PropertyChangeListeners. |
|
8154 |
* |
|
8155 |
* @param propertyName the property whose value has changed |
|
8156 |
* @param oldValue the property's previous value |
|
8157 |
* @param newValue the property's new value |
|
8158 |
* @since 1.4 |
|
8159 |
*/ |
|
8160 |
protected void firePropertyChange(String propertyName, |
|
8161 |
boolean oldValue, boolean newValue) { |
|
8162 |
PropertyChangeSupport changeSupport = this.changeSupport; |
|
8163 |
if (changeSupport == null || oldValue == newValue) { |
|
8164 |
return; |
|
8165 |
} |
|
8166 |
changeSupport.firePropertyChange(propertyName, oldValue, newValue); |
|
8167 |
} |
|
8168 |
||
8169 |
/** |
|
8170 |
* Support for reporting bound property changes for integer properties. |
|
8171 |
* This method can be called when a bound property has changed and it will |
|
8172 |
* send the appropriate PropertyChangeEvent to any registered |
|
8173 |
* PropertyChangeListeners. |
|
8174 |
* |
|
8175 |
* @param propertyName the property whose value has changed |
|
8176 |
* @param oldValue the property's previous value |
|
8177 |
* @param newValue the property's new value |
|
8178 |
* @since 1.4 |
|
8179 |
*/ |
|
8180 |
protected void firePropertyChange(String propertyName, |
|
8181 |
int oldValue, int newValue) { |
|
8182 |
PropertyChangeSupport changeSupport = this.changeSupport; |
|
8183 |
if (changeSupport == null || oldValue == newValue) { |
|
8184 |
return; |
|
8185 |
} |
|
8186 |
changeSupport.firePropertyChange(propertyName, oldValue, newValue); |
|
8187 |
} |
|
8188 |
||
8189 |
/** |
|
8190 |
* Reports a bound property change. |
|
8191 |
* |
|
8192 |
* @param propertyName the programmatic name of the property |
|
8193 |
* that was changed |
|
8194 |
* @param oldValue the old value of the property (as a byte) |
|
8195 |
* @param newValue the new value of the property (as a byte) |
|
8196 |
* @see #firePropertyChange(java.lang.String, java.lang.Object, |
|
8197 |
* java.lang.Object) |
|
8198 |
* @since 1.5 |
|
8199 |
*/ |
|
8200 |
public void firePropertyChange(String propertyName, byte oldValue, byte newValue) { |
|
8201 |
if (changeSupport == null || oldValue == newValue) { |
|
8202 |
return; |
|
8203 |
} |
|
8204 |
firePropertyChange(propertyName, Byte.valueOf(oldValue), Byte.valueOf(newValue)); |
|
8205 |
} |
|
8206 |
||
8207 |
/** |
|
8208 |
* Reports a bound property change. |
|
8209 |
* |
|
8210 |
* @param propertyName the programmatic name of the property |
|
8211 |
* that was changed |
|
8212 |
* @param oldValue the old value of the property (as a char) |
|
8213 |
* @param newValue the new value of the property (as a char) |
|
8214 |
* @see #firePropertyChange(java.lang.String, java.lang.Object, |
|
8215 |
* java.lang.Object) |
|
8216 |
* @since 1.5 |
|
8217 |
*/ |
|
8218 |
public void firePropertyChange(String propertyName, char oldValue, char newValue) { |
|
8219 |
if (changeSupport == null || oldValue == newValue) { |
|
8220 |
return; |
|
8221 |
} |
|
8222 |
firePropertyChange(propertyName, new Character(oldValue), new Character(newValue)); |
|
8223 |
} |
|
8224 |
||
8225 |
/** |
|
8226 |
* Reports a bound property change. |
|
8227 |
* |
|
8228 |
* @param propertyName the programmatic name of the property |
|
8229 |
* that was changed |
|
8230 |
* @param oldValue the old value of the property (as a short) |
|
8231 |
* @param newValue the old value of the property (as a short) |
|
8232 |
* @see #firePropertyChange(java.lang.String, java.lang.Object, |
|
8233 |
* java.lang.Object) |
|
8234 |
* @since 1.5 |
|
8235 |
*/ |
|
8236 |
public void firePropertyChange(String propertyName, short oldValue, short newValue) { |
|
8237 |
if (changeSupport == null || oldValue == newValue) { |
|
8238 |
return; |
|
8239 |
} |
|
8240 |
firePropertyChange(propertyName, Short.valueOf(oldValue), Short.valueOf(newValue)); |
|
8241 |
} |
|
8242 |
||
8243 |
||
8244 |
/** |
|
8245 |
* Reports a bound property change. |
|
8246 |
* |
|
8247 |
* @param propertyName the programmatic name of the property |
|
8248 |
* that was changed |
|
8249 |
* @param oldValue the old value of the property (as a long) |
|
8250 |
* @param newValue the new value of the property (as a long) |
|
8251 |
* @see #firePropertyChange(java.lang.String, java.lang.Object, |
|
8252 |
* java.lang.Object) |
|
8253 |
* @since 1.5 |
|
8254 |
*/ |
|
8255 |
public void firePropertyChange(String propertyName, long oldValue, long newValue) { |
|
8256 |
if (changeSupport == null || oldValue == newValue) { |
|
8257 |
return; |
|
8258 |
} |
|
8259 |
firePropertyChange(propertyName, Long.valueOf(oldValue), Long.valueOf(newValue)); |
|
8260 |
} |
|
8261 |
||
8262 |
/** |
|
8263 |
* Reports a bound property change. |
|
8264 |
* |
|
8265 |
* @param propertyName the programmatic name of the property |
|
8266 |
* that was changed |
|
8267 |
* @param oldValue the old value of the property (as a float) |
|
8268 |
* @param newValue the new value of the property (as a float) |
|
8269 |
* @see #firePropertyChange(java.lang.String, java.lang.Object, |
|
8270 |
* java.lang.Object) |
|
8271 |
* @since 1.5 |
|
8272 |
*/ |
|
8273 |
public void firePropertyChange(String propertyName, float oldValue, float newValue) { |
|
8274 |
if (changeSupport == null || oldValue == newValue) { |
|
8275 |
return; |
|
8276 |
} |
|
8277 |
firePropertyChange(propertyName, Float.valueOf(oldValue), Float.valueOf(newValue)); |
|
8278 |
} |
|
8279 |
||
8280 |
/** |
|
8281 |
* Reports a bound property change. |
|
8282 |
* |
|
8283 |
* @param propertyName the programmatic name of the property |
|
8284 |
* that was changed |
|
8285 |
* @param oldValue the old value of the property (as a double) |
|
8286 |
* @param newValue the new value of the property (as a double) |
|
8287 |
* @see #firePropertyChange(java.lang.String, java.lang.Object, |
|
8288 |
* java.lang.Object) |
|
8289 |
* @since 1.5 |
|
8290 |
*/ |
|
8291 |
public void firePropertyChange(String propertyName, double oldValue, double newValue) { |
|
8292 |
if (changeSupport == null || oldValue == newValue) { |
|
8293 |
return; |
|
8294 |
} |
|
8295 |
firePropertyChange(propertyName, Double.valueOf(oldValue), Double.valueOf(newValue)); |
|
8296 |
} |
|
8297 |
||
8298 |
||
8299 |
// Serialization support. |
|
8300 |
||
8301 |
/** |
|
8302 |
* Component Serialized Data Version. |
|
8303 |
* |
|
8304 |
* @serial |
|
8305 |
*/ |
|
8306 |
private int componentSerializedDataVersion = 4; |
|
8307 |
||
8308 |
/** |
|
8309 |
* This hack is for Swing serialization. It will invoke |
|
8310 |
* the Swing package private method <code>compWriteObjectNotify</code>. |
|
8311 |
*/ |
|
8312 |
private void doSwingSerialization() { |
|
8313 |
Package swingPackage = Package.getPackage("javax.swing"); |
|
8314 |
// For Swing serialization to correctly work Swing needs to |
|
8315 |
// be notified before Component does it's serialization. This |
|
8316 |
// hack accomodates this. |
|
8317 |
// |
|
8318 |
// Swing classes MUST be loaded by the bootstrap class loader, |
|
8319 |
// otherwise we don't consider them. |
|
8320 |
for (Class klass = Component.this.getClass(); klass != null; |
|
8321 |
klass = klass.getSuperclass()) { |
|
8322 |
if (klass.getPackage() == swingPackage && |
|
8323 |
klass.getClassLoader() == null) { |
|
8324 |
final Class swingClass = klass; |
|
8325 |
// Find the first override of the compWriteObjectNotify method |
|
8326 |
Method[] methods = (Method[])AccessController.doPrivileged( |
|
8327 |
new PrivilegedAction() { |
|
8328 |
public Object run() { |
|
8329 |
return swingClass.getDeclaredMethods(); |
|
8330 |
} |
|
8331 |
}); |
|
8332 |
for (int counter = methods.length - 1; counter >= 0; |
|
8333 |
counter--) { |
|
8334 |
final Method method = methods[counter]; |
|
8335 |
if (method.getName().equals("compWriteObjectNotify")){ |
|
8336 |
// We found it, use doPrivileged to make it accessible |
|
8337 |
// to use. |
|
8338 |
AccessController.doPrivileged(new PrivilegedAction() { |
|
8339 |
public Object run() { |
|
8340 |
method.setAccessible(true); |
|
8341 |
return null; |
|
8342 |
} |
|
8343 |
}); |
|
8344 |
// Invoke the method |
|
8345 |
try { |
|
8346 |
method.invoke(this, (Object[]) null); |
|
8347 |
} catch (IllegalAccessException iae) { |
|
8348 |
} catch (InvocationTargetException ite) { |
|
8349 |
} |
|
8350 |
// We're done, bail. |
|
8351 |
return; |
|
8352 |
} |
|
8353 |
} |
|
8354 |
} |
|
8355 |
} |
|
8356 |
} |
|
8357 |
||
8358 |
/** |
|
8359 |
* Writes default serializable fields to stream. Writes |
|
8360 |
* a variety of serializable listeners as optional data. |
|
8361 |
* The non-serializable listeners are detected and |
|
8362 |
* no attempt is made to serialize them. |
|
8363 |
* |
|
8364 |
* @param s the <code>ObjectOutputStream</code> to write |
|
8365 |
* @serialData <code>null</code> terminated sequence of |
|
8366 |
* 0 or more pairs; the pair consists of a <code>String</code> |
|
8367 |
* and an <code>Object</code>; the <code>String</code> indicates |
|
8368 |
* the type of object and is one of the following (as of 1.4): |
|
8369 |
* <code>componentListenerK</code> indicating an |
|
8370 |
* <code>ComponentListener</code> object; |
|
8371 |
* <code>focusListenerK</code> indicating an |
|
8372 |
* <code>FocusListener</code> object; |
|
8373 |
* <code>keyListenerK</code> indicating an |
|
8374 |
* <code>KeyListener</code> object; |
|
8375 |
* <code>mouseListenerK</code> indicating an |
|
8376 |
* <code>MouseListener</code> object; |
|
8377 |
* <code>mouseMotionListenerK</code> indicating an |
|
8378 |
* <code>MouseMotionListener</code> object; |
|
8379 |
* <code>inputMethodListenerK</code> indicating an |
|
8380 |
* <code>InputMethodListener</code> object; |
|
8381 |
* <code>hierarchyListenerK</code> indicating an |
|
8382 |
* <code>HierarchyListener</code> object; |
|
8383 |
* <code>hierarchyBoundsListenerK</code> indicating an |
|
8384 |
* <code>HierarchyBoundsListener</code> object; |
|
8385 |
* <code>mouseWheelListenerK</code> indicating an |
|
8386 |
* <code>MouseWheelListener</code> object |
|
8387 |
* @serialData an optional <code>ComponentOrientation</code> |
|
8388 |
* (after <code>inputMethodListener</code>, as of 1.2) |
|
8389 |
* |
|
8390 |
* @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener) |
|
8391 |
* @see #componentListenerK |
|
8392 |
* @see #focusListenerK |
|
8393 |
* @see #keyListenerK |
|
8394 |
* @see #mouseListenerK |
|
8395 |
* @see #mouseMotionListenerK |
|
8396 |
* @see #inputMethodListenerK |
|
8397 |
* @see #hierarchyListenerK |
|
8398 |
* @see #hierarchyBoundsListenerK |
|
8399 |
* @see #mouseWheelListenerK |
|
8400 |
* @see #readObject(ObjectInputStream) |
|
8401 |
*/ |
|
8402 |
private void writeObject(ObjectOutputStream s) |
|
8403 |
throws IOException |
|
8404 |
{ |
|
8405 |
doSwingSerialization(); |
|
8406 |
||
8407 |
s.defaultWriteObject(); |
|
8408 |
||
8409 |
AWTEventMulticaster.save(s, componentListenerK, componentListener); |
|
8410 |
AWTEventMulticaster.save(s, focusListenerK, focusListener); |
|
8411 |
AWTEventMulticaster.save(s, keyListenerK, keyListener); |
|
8412 |
AWTEventMulticaster.save(s, mouseListenerK, mouseListener); |
|
8413 |
AWTEventMulticaster.save(s, mouseMotionListenerK, mouseMotionListener); |
|
8414 |
AWTEventMulticaster.save(s, inputMethodListenerK, inputMethodListener); |
|
8415 |
||
8416 |
s.writeObject(null); |
|
8417 |
s.writeObject(componentOrientation); |
|
8418 |
||
8419 |
AWTEventMulticaster.save(s, hierarchyListenerK, hierarchyListener); |
|
8420 |
AWTEventMulticaster.save(s, hierarchyBoundsListenerK, |
|
8421 |
hierarchyBoundsListener); |
|
8422 |
s.writeObject(null); |
|
8423 |
||
8424 |
AWTEventMulticaster.save(s, mouseWheelListenerK, mouseWheelListener); |
|
8425 |
s.writeObject(null); |
|
8426 |
||
8427 |
} |
|
8428 |
||
8429 |
/** |
|
8430 |
* Reads the <code>ObjectInputStream</code> and if it isn't |
|
8431 |
* <code>null</code> adds a listener to receive a variety |
|
8432 |
* of events fired by the component. |
|
8433 |
* Unrecognized keys or values will be ignored. |
|
8434 |
* |
|
8435 |
* @param s the <code>ObjectInputStream</code> to read |
|
8436 |
* @see #writeObject(ObjectOutputStream) |
|
8437 |
*/ |
|
8438 |
private void readObject(ObjectInputStream s) |
|
8439 |
throws ClassNotFoundException, IOException |
|
8440 |
{ |
|
1169
23b1850f7d73
6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents:
635
diff
changeset
|
8441 |
objectLock = new Object(); |
432
ff3aa6ee3572
6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents:
130
diff
changeset
|
8442 |
|
2 | 8443 |
s.defaultReadObject(); |
8444 |
||
8445 |
appContext = AppContext.getAppContext(); |
|
8446 |
coalescingEnabled = checkCoalescing(); |
|
8447 |
if (componentSerializedDataVersion < 4) { |
|
8448 |
// These fields are non-transient and rely on default |
|
8449 |
// serialization. However, the default values are insufficient, |
|
8450 |
// so we need to set them explicitly for object data streams prior |
|
8451 |
// to 1.4. |
|
8452 |
focusable = true; |
|
8453 |
isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN; |
|
8454 |
initializeFocusTraversalKeys(); |
|
8455 |
focusTraversalKeysEnabled = true; |
|
8456 |
} |
|
8457 |
||
8458 |
Object keyOrNull; |
|
8459 |
while(null != (keyOrNull = s.readObject())) { |
|
8460 |
String key = ((String)keyOrNull).intern(); |
|
8461 |
||
8462 |
if (componentListenerK == key) |
|
8463 |
addComponentListener((ComponentListener)(s.readObject())); |
|
8464 |
||
8465 |
else if (focusListenerK == key) |
|
8466 |
addFocusListener((FocusListener)(s.readObject())); |
|
8467 |
||
8468 |
else if (keyListenerK == key) |
|
8469 |
addKeyListener((KeyListener)(s.readObject())); |
|
8470 |
||
8471 |
else if (mouseListenerK == key) |
|
8472 |
addMouseListener((MouseListener)(s.readObject())); |
|
8473 |
||
8474 |
else if (mouseMotionListenerK == key) |
|
8475 |
addMouseMotionListener((MouseMotionListener)(s.readObject())); |
|
8476 |
||
8477 |
else if (inputMethodListenerK == key) |
|
8478 |
addInputMethodListener((InputMethodListener)(s.readObject())); |
|
8479 |
||
8480 |
else // skip value for unrecognized key |
|
8481 |
s.readObject(); |
|
8482 |
||
8483 |
} |
|
8484 |
||
8485 |
// Read the component's orientation if it's present |
|
8486 |
Object orient = null; |
|
8487 |
||
8488 |
try { |
|
8489 |
orient = s.readObject(); |
|
8490 |
} catch (java.io.OptionalDataException e) { |
|
8491 |
// JDK 1.1 instances will not have this optional data. |
|
8492 |
// e.eof will be true to indicate that there is no more |
|
8493 |
// data available for this object. |
|
8494 |
// If e.eof is not true, throw the exception as it |
|
8495 |
// might have been caused by reasons unrelated to |
|
8496 |
// componentOrientation. |
|
8497 |
||
8498 |
if (!e.eof) { |
|
8499 |
throw (e); |
|
8500 |
} |
|
8501 |
} |
|
8502 |
||
8503 |
if (orient != null) { |
|
8504 |
componentOrientation = (ComponentOrientation)orient; |
|
8505 |
} else { |
|
8506 |
componentOrientation = ComponentOrientation.UNKNOWN; |
|
8507 |
} |
|
8508 |
||
8509 |
try { |
|
8510 |
while(null != (keyOrNull = s.readObject())) { |
|
8511 |
String key = ((String)keyOrNull).intern(); |
|
8512 |
||
8513 |
if (hierarchyListenerK == key) { |
|
8514 |
addHierarchyListener((HierarchyListener)(s.readObject())); |
|
8515 |
} |
|
8516 |
else if (hierarchyBoundsListenerK == key) { |
|
8517 |
addHierarchyBoundsListener((HierarchyBoundsListener) |
|
8518 |
(s.readObject())); |
|
8519 |
} |
|
8520 |
else { |
|
8521 |
// skip value for unrecognized key |
|
8522 |
s.readObject(); |
|
8523 |
} |
|
8524 |
} |
|
8525 |
} catch (java.io.OptionalDataException e) { |
|
8526 |
// JDK 1.1/1.2 instances will not have this optional data. |
|
8527 |
// e.eof will be true to indicate that there is no more |
|
8528 |
// data available for this object. |
|
8529 |
// If e.eof is not true, throw the exception as it |
|
8530 |
// might have been caused by reasons unrelated to |
|
8531 |
// hierarchy and hierarchyBounds listeners. |
|
8532 |
||
8533 |
if (!e.eof) { |
|
8534 |
throw (e); |
|
8535 |
} |
|
8536 |
} |
|
8537 |
||
8538 |
try { |
|
8539 |
while (null != (keyOrNull = s.readObject())) { |
|
8540 |
String key = ((String)keyOrNull).intern(); |
|
8541 |
||
8542 |
if (mouseWheelListenerK == key) { |
|
8543 |
addMouseWheelListener((MouseWheelListener)(s.readObject())); |
|
8544 |
} |
|
8545 |
else { |
|
8546 |
// skip value for unrecognized key |
|
8547 |
s.readObject(); |
|
8548 |
} |
|
8549 |
} |
|
8550 |
} catch (java.io.OptionalDataException e) { |
|
8551 |
// pre-1.3 instances will not have this optional data. |
|
8552 |
// e.eof will be true to indicate that there is no more |
|
8553 |
// data available for this object. |
|
8554 |
// If e.eof is not true, throw the exception as it |
|
8555 |
// might have been caused by reasons unrelated to |
|
8556 |
// mouse wheel listeners |
|
8557 |
||
8558 |
if (!e.eof) { |
|
8559 |
throw (e); |
|
8560 |
} |
|
8561 |
} |
|
8562 |
||
8563 |
if (popups != null) { |
|
8564 |
int npopups = popups.size(); |
|
8565 |
for (int i = 0 ; i < npopups ; i++) { |
|
8566 |
PopupMenu popup = (PopupMenu)popups.elementAt(i); |
|
8567 |
popup.parent = this; |
|
8568 |
} |
|
8569 |
} |
|
8570 |
} |
|
8571 |
||
8572 |
/** |
|
8573 |
* Sets the language-sensitive orientation that is to be used to order |
|
8574 |
* the elements or text within this component. Language-sensitive |
|
8575 |
* <code>LayoutManager</code> and <code>Component</code> |
|
8576 |
* subclasses will use this property to |
|
8577 |
* determine how to lay out and draw components. |
|
8578 |
* <p> |
|
8579 |
* At construction time, a component's orientation is set to |
|
8580 |
* <code>ComponentOrientation.UNKNOWN</code>, |
|
8581 |
* indicating that it has not been specified |
|
8582 |
* explicitly. The UNKNOWN orientation behaves the same as |
|
8583 |
* <code>ComponentOrientation.LEFT_TO_RIGHT</code>. |
|
8584 |
* <p> |
|
8585 |
* To set the orientation of a single component, use this method. |
|
8586 |
* To set the orientation of an entire component |
|
8587 |
* hierarchy, use |
|
8588 |
* {@link #applyComponentOrientation applyComponentOrientation}. |
|
8589 |
* |
|
8590 |
* @see ComponentOrientation |
|
8591 |
* |
|
8592 |
* @author Laura Werner, IBM |
|
8593 |
* @beaninfo |
|
8594 |
* bound: true |
|
8595 |
*/ |
|
8596 |
public void setComponentOrientation(ComponentOrientation o) { |
|
8597 |
ComponentOrientation oldValue = componentOrientation; |
|
8598 |
componentOrientation = o; |
|
8599 |
||
8600 |
// This is a bound property, so report the change to |
|
8601 |
// any registered listeners. (Cheap if there are none.) |
|
8602 |
firePropertyChange("componentOrientation", oldValue, o); |
|
8603 |
||
8604 |
// This could change the preferred size of the Component. |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
8605 |
invalidateIfValid(); |
2 | 8606 |
} |
8607 |
||
8608 |
/** |
|
8609 |
* Retrieves the language-sensitive orientation that is to be used to order |
|
8610 |
* the elements or text within this component. <code>LayoutManager</code> |
|
8611 |
* and <code>Component</code> |
|
8612 |
* subclasses that wish to respect orientation should call this method to |
|
8613 |
* get the component's orientation before performing layout or drawing. |
|
8614 |
* |
|
8615 |
* @see ComponentOrientation |
|
8616 |
* |
|
8617 |
* @author Laura Werner, IBM |
|
8618 |
*/ |
|
8619 |
public ComponentOrientation getComponentOrientation() { |
|
8620 |
return componentOrientation; |
|
8621 |
} |
|
8622 |
||
8623 |
/** |
|
8624 |
* Sets the <code>ComponentOrientation</code> property of this component |
|
8625 |
* and all components contained within it. |
|
8626 |
* |
|
8627 |
* @param orientation the new component orientation of this component and |
|
8628 |
* the components contained within it. |
|
8629 |
* @exception NullPointerException if <code>orientation</code> is null. |
|
8630 |
* @see #setComponentOrientation |
|
8631 |
* @see #getComponentOrientation |
|
8632 |
* @since 1.4 |
|
8633 |
*/ |
|
8634 |
public void applyComponentOrientation(ComponentOrientation orientation) { |
|
8635 |
if (orientation == null) { |
|
8636 |
throw new NullPointerException(); |
|
8637 |
} |
|
8638 |
setComponentOrientation(orientation); |
|
8639 |
} |
|
8640 |
||
1171
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
8641 |
final boolean canBeFocusOwner() { |
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
8642 |
// It is enabled, visible, focusable. |
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
8643 |
if (isEnabled() && isDisplayable() && isVisible() && isFocusable()) { |
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
8644 |
return true; |
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
8645 |
} |
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
8646 |
return false; |
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
8647 |
} |
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
8648 |
|
2 | 8649 |
/** |
8650 |
* Checks that this component meets the prerequesites to be focus owner: |
|
8651 |
* - it is enabled, visible, focusable |
|
8652 |
* - it's parents are all enabled and showing |
|
8653 |
* - top-level window is focusable |
|
8654 |
* - if focus cycle root has DefaultFocusTraversalPolicy then it also checks that this policy accepts |
|
8655 |
* this component as focus owner |
|
8656 |
* @since 1.5 |
|
8657 |
*/ |
|
1171
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
8658 |
final boolean canBeFocusOwnerRecursively() { |
2 | 8659 |
// - it is enabled, visible, focusable |
1171
a2782dd9f312
4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents:
1169
diff
changeset
|
8660 |
if (!canBeFocusOwner()) { |
2 | 8661 |
return false; |
8662 |
} |
|
8663 |
||
8664 |
// - it's parents are all enabled and showing |
|
8665 |
synchronized(getTreeLock()) { |
|
8666 |
if (parent != null) { |
|
8667 |
return parent.canContainFocusOwner(this); |
|
8668 |
} |
|
8669 |
} |
|
8670 |
return true; |
|
8671 |
} |
|
8672 |
||
8673 |
/** |
|
130 | 8674 |
* Fix the location of the HW component in a LW container hierarchy. |
8675 |
*/ |
|
8676 |
final void relocateComponent() { |
|
8677 |
synchronized (getTreeLock()) { |
|
8678 |
if (peer == null) { |
|
8679 |
return; |
|
8680 |
} |
|
8681 |
int nativeX = x; |
|
8682 |
int nativeY = y; |
|
8683 |
for (Component cont = getContainer(); |
|
8684 |
cont != null && cont.isLightweight(); |
|
8685 |
cont = cont.getContainer()) |
|
2 | 8686 |
{ |
130 | 8687 |
nativeX += cont.x; |
8688 |
nativeY += cont.y; |
|
8689 |
} |
|
8690 |
peer.setBounds(nativeX, nativeY, width, height, |
|
8691 |
ComponentPeer.SET_LOCATION); |
|
8692 |
} |
|
2 | 8693 |
} |
8694 |
||
8695 |
/** |
|
8696 |
* Returns the <code>Window</code> ancestor of the component. |
|
8697 |
* @return Window ancestor of the component or component by itself if it is Window; |
|
8698 |
* null, if component is not a part of window hierarchy |
|
8699 |
*/ |
|
8700 |
Window getContainingWindow() { |
|
2451 | 8701 |
return SunToolkit.getContainingWindow(this); |
8702 |
} |
|
2 | 8703 |
|
8704 |
/** |
|
8705 |
* Initialize JNI field and method IDs |
|
8706 |
*/ |
|
8707 |
private static native void initIDs(); |
|
8708 |
||
8709 |
/* |
|
8710 |
* --- Accessibility Support --- |
|
8711 |
* |
|
8712 |
* Component will contain all of the methods in interface Accessible, |
|
8713 |
* though it won't actually implement the interface - that will be up |
|
8714 |
* to the individual objects which extend Component. |
|
8715 |
*/ |
|
8716 |
||
8717 |
AccessibleContext accessibleContext = null; |
|
8718 |
||
8719 |
/** |
|
8720 |
* Gets the <code>AccessibleContext</code> associated |
|
8721 |
* with this <code>Component</code>. |
|
8722 |
* The method implemented by this base |
|
8723 |
* class returns null. Classes that extend <code>Component</code> |
|
8724 |
* should implement this method to return the |
|
8725 |
* <code>AccessibleContext</code> associated with the subclass. |
|
8726 |
* |
|
8727 |
* |
|
8728 |
* @return the <code>AccessibleContext</code> of this |
|
8729 |
* <code>Component</code> |
|
8730 |
* @since 1.3 |
|
8731 |
*/ |
|
8732 |
public AccessibleContext getAccessibleContext() { |
|
8733 |
return accessibleContext; |
|
8734 |
} |
|
8735 |
||
8736 |
/** |
|
8737 |
* Inner class of Component used to provide default support for |
|
8738 |
* accessibility. This class is not meant to be used directly by |
|
8739 |
* application developers, but is instead meant only to be |
|
8740 |
* subclassed by component developers. |
|
8741 |
* <p> |
|
8742 |
* The class used to obtain the accessible role for this object. |
|
8743 |
* @since 1.3 |
|
8744 |
*/ |
|
8745 |
protected abstract class AccessibleAWTComponent extends AccessibleContext |
|
8746 |
implements Serializable, AccessibleComponent { |
|
8747 |
||
8748 |
private static final long serialVersionUID = 642321655757800191L; |
|
8749 |
||
8750 |
/** |
|
8751 |
* Though the class is abstract, this should be called by |
|
8752 |
* all sub-classes. |
|
8753 |
*/ |
|
8754 |
protected AccessibleAWTComponent() { |
|
8755 |
} |
|
8756 |
||
8757 |
protected ComponentListener accessibleAWTComponentHandler = null; |
|
8758 |
protected FocusListener accessibleAWTFocusHandler = null; |
|
8759 |
||
8760 |
/** |
|
8761 |
* Fire PropertyChange listener, if one is registered, |
|
8762 |
* when shown/hidden.. |
|
8763 |
* @since 1.3 |
|
8764 |
*/ |
|
8765 |
protected class AccessibleAWTComponentHandler implements ComponentListener { |
|
8766 |
public void componentHidden(ComponentEvent e) { |
|
8767 |
if (accessibleContext != null) { |
|
8768 |
accessibleContext.firePropertyChange( |
|
8769 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
8770 |
AccessibleState.VISIBLE, null); |
|
8771 |
} |
|
8772 |
} |
|
8773 |
||
8774 |
public void componentShown(ComponentEvent e) { |
|
8775 |
if (accessibleContext != null) { |
|
8776 |
accessibleContext.firePropertyChange( |
|
8777 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
8778 |
null, AccessibleState.VISIBLE); |
|
8779 |
} |
|
8780 |
} |
|
8781 |
||
8782 |
public void componentMoved(ComponentEvent e) { |
|
8783 |
} |
|
8784 |
||
8785 |
public void componentResized(ComponentEvent e) { |
|
8786 |
} |
|
8787 |
} // inner class AccessibleAWTComponentHandler |
|
8788 |
||
8789 |
||
8790 |
/** |
|
8791 |
* Fire PropertyChange listener, if one is registered, |
|
8792 |
* when focus events happen |
|
8793 |
* @since 1.3 |
|
8794 |
*/ |
|
8795 |
protected class AccessibleAWTFocusHandler implements FocusListener { |
|
8796 |
public void focusGained(FocusEvent event) { |
|
8797 |
if (accessibleContext != null) { |
|
8798 |
accessibleContext.firePropertyChange( |
|
8799 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
8800 |
null, AccessibleState.FOCUSED); |
|
8801 |
} |
|
8802 |
} |
|
8803 |
public void focusLost(FocusEvent event) { |
|
8804 |
if (accessibleContext != null) { |
|
8805 |
accessibleContext.firePropertyChange( |
|
8806 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
8807 |
AccessibleState.FOCUSED, null); |
|
8808 |
} |
|
8809 |
} |
|
8810 |
} // inner class AccessibleAWTFocusHandler |
|
8811 |
||
8812 |
||
8813 |
/** |
|
8814 |
* Adds a <code>PropertyChangeListener</code> to the listener list. |
|
8815 |
* |
|
8816 |
* @param listener the property change listener to be added |
|
8817 |
*/ |
|
8818 |
public void addPropertyChangeListener(PropertyChangeListener listener) { |
|
8819 |
if (accessibleAWTComponentHandler == null) { |
|
8820 |
accessibleAWTComponentHandler = new AccessibleAWTComponentHandler(); |
|
8821 |
Component.this.addComponentListener(accessibleAWTComponentHandler); |
|
8822 |
} |
|
8823 |
if (accessibleAWTFocusHandler == null) { |
|
8824 |
accessibleAWTFocusHandler = new AccessibleAWTFocusHandler(); |
|
8825 |
Component.this.addFocusListener(accessibleAWTFocusHandler); |
|
8826 |
} |
|
8827 |
super.addPropertyChangeListener(listener); |
|
8828 |
} |
|
8829 |
||
8830 |
/** |
|
8831 |
* Remove a PropertyChangeListener from the listener list. |
|
8832 |
* This removes a PropertyChangeListener that was registered |
|
8833 |
* for all properties. |
|
8834 |
* |
|
8835 |
* @param listener The PropertyChangeListener to be removed |
|
8836 |
*/ |
|
8837 |
public void removePropertyChangeListener(PropertyChangeListener listener) { |
|
8838 |
if (accessibleAWTComponentHandler != null) { |
|
8839 |
Component.this.removeComponentListener(accessibleAWTComponentHandler); |
|
8840 |
accessibleAWTComponentHandler = null; |
|
8841 |
} |
|
8842 |
if (accessibleAWTFocusHandler != null) { |
|
8843 |
Component.this.removeFocusListener(accessibleAWTFocusHandler); |
|
8844 |
accessibleAWTFocusHandler = null; |
|
8845 |
} |
|
8846 |
super.removePropertyChangeListener(listener); |
|
8847 |
} |
|
8848 |
||
8849 |
// AccessibleContext methods |
|
8850 |
// |
|
8851 |
/** |
|
8852 |
* Gets the accessible name of this object. This should almost never |
|
8853 |
* return <code>java.awt.Component.getName()</code>, |
|
8854 |
* as that generally isn't a localized name, |
|
8855 |
* and doesn't have meaning for the user. If the |
|
8856 |
* object is fundamentally a text object (e.g. a menu item), the |
|
8857 |
* accessible name should be the text of the object (e.g. "save"). |
|
8858 |
* If the object has a tooltip, the tooltip text may also be an |
|
8859 |
* appropriate String to return. |
|
8860 |
* |
|
8861 |
* @return the localized name of the object -- can be |
|
8862 |
* <code>null</code> if this |
|
8863 |
* object does not have a name |
|
8864 |
* @see javax.accessibility.AccessibleContext#setAccessibleName |
|
8865 |
*/ |
|
8866 |
public String getAccessibleName() { |
|
8867 |
return accessibleName; |
|
8868 |
} |
|
8869 |
||
8870 |
/** |
|
8871 |
* Gets the accessible description of this object. This should be |
|
8872 |
* a concise, localized description of what this object is - what |
|
8873 |
* is its meaning to the user. If the object has a tooltip, the |
|
8874 |
* tooltip text may be an appropriate string to return, assuming |
|
8875 |
* it contains a concise description of the object (instead of just |
|
8876 |
* the name of the object - e.g. a "Save" icon on a toolbar that |
|
8877 |
* had "save" as the tooltip text shouldn't return the tooltip |
|
8878 |
* text as the description, but something like "Saves the current |
|
8879 |
* text document" instead). |
|
8880 |
* |
|
8881 |
* @return the localized description of the object -- can be |
|
8882 |
* <code>null</code> if this object does not have a description |
|
8883 |
* @see javax.accessibility.AccessibleContext#setAccessibleDescription |
|
8884 |
*/ |
|
8885 |
public String getAccessibleDescription() { |
|
8886 |
return accessibleDescription; |
|
8887 |
} |
|
8888 |
||
8889 |
/** |
|
8890 |
* Gets the role of this object. |
|
8891 |
* |
|
8892 |
* @return an instance of <code>AccessibleRole</code> |
|
8893 |
* describing the role of the object |
|
8894 |
* @see javax.accessibility.AccessibleRole |
|
8895 |
*/ |
|
8896 |
public AccessibleRole getAccessibleRole() { |
|
8897 |
return AccessibleRole.AWT_COMPONENT; |
|
8898 |
} |
|
8899 |
||
8900 |
/** |
|
8901 |
* Gets the state of this object. |
|
8902 |
* |
|
8903 |
* @return an instance of <code>AccessibleStateSet</code> |
|
8904 |
* containing the current state set of the object |
|
8905 |
* @see javax.accessibility.AccessibleState |
|
8906 |
*/ |
|
8907 |
public AccessibleStateSet getAccessibleStateSet() { |
|
8908 |
return Component.this.getAccessibleStateSet(); |
|
8909 |
} |
|
8910 |
||
8911 |
/** |
|
8912 |
* Gets the <code>Accessible</code> parent of this object. |
|
8913 |
* If the parent of this object implements <code>Accessible</code>, |
|
8914 |
* this method should simply return <code>getParent</code>. |
|
8915 |
* |
|
8916 |
* @return the <code>Accessible</code> parent of this |
|
8917 |
* object -- can be <code>null</code> if this |
|
8918 |
* object does not have an <code>Accessible</code> parent |
|
8919 |
*/ |
|
8920 |
public Accessible getAccessibleParent() { |
|
8921 |
if (accessibleParent != null) { |
|
8922 |
return accessibleParent; |
|
8923 |
} else { |
|
8924 |
Container parent = getParent(); |
|
8925 |
if (parent instanceof Accessible) { |
|
8926 |
return (Accessible) parent; |
|
8927 |
} |
|
8928 |
} |
|
8929 |
return null; |
|
8930 |
} |
|
8931 |
||
8932 |
/** |
|
8933 |
* Gets the index of this object in its accessible parent. |
|
8934 |
* |
|
8935 |
* @return the index of this object in its parent; or -1 if this |
|
8936 |
* object does not have an accessible parent |
|
8937 |
* @see #getAccessibleParent |
|
8938 |
*/ |
|
8939 |
public int getAccessibleIndexInParent() { |
|
8940 |
return Component.this.getAccessibleIndexInParent(); |
|
8941 |
} |
|
8942 |
||
8943 |
/** |
|
8944 |
* Returns the number of accessible children in the object. If all |
|
8945 |
* of the children of this object implement <code>Accessible</code>, |
|
8946 |
* then this method should return the number of children of this object. |
|
8947 |
* |
|
8948 |
* @return the number of accessible children in the object |
|
8949 |
*/ |
|
8950 |
public int getAccessibleChildrenCount() { |
|
8951 |
return 0; // Components don't have children |
|
8952 |
} |
|
8953 |
||
8954 |
/** |
|
8955 |
* Returns the nth <code>Accessible</code> child of the object. |
|
8956 |
* |
|
8957 |
* @param i zero-based index of child |
|
8958 |
* @return the nth <code>Accessible</code> child of the object |
|
8959 |
*/ |
|
8960 |
public Accessible getAccessibleChild(int i) { |
|
8961 |
return null; // Components don't have children |
|
8962 |
} |
|
8963 |
||
8964 |
/** |
|
8965 |
* Returns the locale of this object. |
|
8966 |
* |
|
8967 |
* @return the locale of this object |
|
8968 |
*/ |
|
8969 |
public Locale getLocale() { |
|
8970 |
return Component.this.getLocale(); |
|
8971 |
} |
|
8972 |
||
8973 |
/** |
|
8974 |
* Gets the <code>AccessibleComponent</code> associated |
|
8975 |
* with this object if one exists. |
|
8976 |
* Otherwise return <code>null</code>. |
|
8977 |
* |
|
8978 |
* @return the component |
|
8979 |
*/ |
|
8980 |
public AccessibleComponent getAccessibleComponent() { |
|
8981 |
return this; |
|
8982 |
} |
|
8983 |
||
8984 |
||
8985 |
// AccessibleComponent methods |
|
8986 |
// |
|
8987 |
/** |
|
8988 |
* Gets the background color of this object. |
|
8989 |
* |
|
8990 |
* @return the background color, if supported, of the object; |
|
8991 |
* otherwise, <code>null</code> |
|
8992 |
*/ |
|
8993 |
public Color getBackground() { |
|
8994 |
return Component.this.getBackground(); |
|
8995 |
} |
|
8996 |
||
8997 |
/** |
|
8998 |
* Sets the background color of this object. |
|
8999 |
* (For transparency, see <code>isOpaque</code>.) |
|
9000 |
* |
|
9001 |
* @param c the new <code>Color</code> for the background |
|
9002 |
* @see Component#isOpaque |
|
9003 |
*/ |
|
9004 |
public void setBackground(Color c) { |
|
9005 |
Component.this.setBackground(c); |
|
9006 |
} |
|
9007 |
||
9008 |
/** |
|
9009 |
* Gets the foreground color of this object. |
|
9010 |
* |
|
9011 |
* @return the foreground color, if supported, of the object; |
|
9012 |
* otherwise, <code>null</code> |
|
9013 |
*/ |
|
9014 |
public Color getForeground() { |
|
9015 |
return Component.this.getForeground(); |
|
9016 |
} |
|
9017 |
||
9018 |
/** |
|
9019 |
* Sets the foreground color of this object. |
|
9020 |
* |
|
9021 |
* @param c the new <code>Color</code> for the foreground |
|
9022 |
*/ |
|
9023 |
public void setForeground(Color c) { |
|
9024 |
Component.this.setForeground(c); |
|
9025 |
} |
|
9026 |
||
9027 |
/** |
|
9028 |
* Gets the <code>Cursor</code> of this object. |
|
9029 |
* |
|
9030 |
* @return the <code>Cursor</code>, if supported, |
|
9031 |
* of the object; otherwise, <code>null</code> |
|
9032 |
*/ |
|
9033 |
public Cursor getCursor() { |
|
9034 |
return Component.this.getCursor(); |
|
9035 |
} |
|
9036 |
||
9037 |
/** |
|
9038 |
* Sets the <code>Cursor</code> of this object. |
|
9039 |
* <p> |
|
9040 |
* The method may have no visual effect if the Java platform |
|
9041 |
* implementation and/or the native system do not support |
|
9042 |
* changing the mouse cursor shape. |
|
9043 |
* @param cursor the new <code>Cursor</code> for the object |
|
9044 |
*/ |
|
9045 |
public void setCursor(Cursor cursor) { |
|
9046 |
Component.this.setCursor(cursor); |
|
9047 |
} |
|
9048 |
||
9049 |
/** |
|
9050 |
* Gets the <code>Font</code> of this object. |
|
9051 |
* |
|
9052 |
* @return the <code>Font</code>, if supported, |
|
9053 |
* for the object; otherwise, <code>null</code> |
|
9054 |
*/ |
|
9055 |
public Font getFont() { |
|
9056 |
return Component.this.getFont(); |
|
9057 |
} |
|
9058 |
||
9059 |
/** |
|
9060 |
* Sets the <code>Font</code> of this object. |
|
9061 |
* |
|
9062 |
* @param f the new <code>Font</code> for the object |
|
9063 |
*/ |
|
9064 |
public void setFont(Font f) { |
|
9065 |
Component.this.setFont(f); |
|
9066 |
} |
|
9067 |
||
9068 |
/** |
|
9069 |
* Gets the <code>FontMetrics</code> of this object. |
|
9070 |
* |
|
9071 |
* @param f the <code>Font</code> |
|
9072 |
* @return the <code>FontMetrics</code>, if supported, |
|
9073 |
* the object; otherwise, <code>null</code> |
|
9074 |
* @see #getFont |
|
9075 |
*/ |
|
9076 |
public FontMetrics getFontMetrics(Font f) { |
|
9077 |
if (f == null) { |
|
9078 |
return null; |
|
9079 |
} else { |
|
9080 |
return Component.this.getFontMetrics(f); |
|
9081 |
} |
|
9082 |
} |
|
9083 |
||
9084 |
/** |
|
9085 |
* Determines if the object is enabled. |
|
9086 |
* |
|
9087 |
* @return true if object is enabled; otherwise, false |
|
9088 |
*/ |
|
9089 |
public boolean isEnabled() { |
|
9090 |
return Component.this.isEnabled(); |
|
9091 |
} |
|
9092 |
||
9093 |
/** |
|
9094 |
* Sets the enabled state of the object. |
|
9095 |
* |
|
9096 |
* @param b if true, enables this object; otherwise, disables it |
|
9097 |
*/ |
|
9098 |
public void setEnabled(boolean b) { |
|
9099 |
boolean old = Component.this.isEnabled(); |
|
9100 |
Component.this.setEnabled(b); |
|
9101 |
if (b != old) { |
|
9102 |
if (accessibleContext != null) { |
|
9103 |
if (b) { |
|
9104 |
accessibleContext.firePropertyChange( |
|
9105 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
9106 |
null, AccessibleState.ENABLED); |
|
9107 |
} else { |
|
9108 |
accessibleContext.firePropertyChange( |
|
9109 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
9110 |
AccessibleState.ENABLED, null); |
|
9111 |
} |
|
9112 |
} |
|
9113 |
} |
|
9114 |
} |
|
9115 |
||
9116 |
/** |
|
9117 |
* Determines if the object is visible. Note: this means that the |
|
9118 |
* object intends to be visible; however, it may not in fact be |
|
9119 |
* showing on the screen because one of the objects that this object |
|
9120 |
* is contained by is not visible. To determine if an object is |
|
9121 |
* showing on the screen, use <code>isShowing</code>. |
|
9122 |
* |
|
9123 |
* @return true if object is visible; otherwise, false |
|
9124 |
*/ |
|
9125 |
public boolean isVisible() { |
|
9126 |
return Component.this.isVisible(); |
|
9127 |
} |
|
9128 |
||
9129 |
/** |
|
9130 |
* Sets the visible state of the object. |
|
9131 |
* |
|
9132 |
* @param b if true, shows this object; otherwise, hides it |
|
9133 |
*/ |
|
9134 |
public void setVisible(boolean b) { |
|
9135 |
boolean old = Component.this.isVisible(); |
|
9136 |
Component.this.setVisible(b); |
|
9137 |
if (b != old) { |
|
9138 |
if (accessibleContext != null) { |
|
9139 |
if (b) { |
|
9140 |
accessibleContext.firePropertyChange( |
|
9141 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
9142 |
null, AccessibleState.VISIBLE); |
|
9143 |
} else { |
|
9144 |
accessibleContext.firePropertyChange( |
|
9145 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
9146 |
AccessibleState.VISIBLE, null); |
|
9147 |
} |
|
9148 |
} |
|
9149 |
} |
|
9150 |
} |
|
9151 |
||
9152 |
/** |
|
9153 |
* Determines if the object is showing. This is determined by checking |
|
9154 |
* the visibility of the object and ancestors of the object. Note: |
|
9155 |
* this will return true even if the object is obscured by another |
|
9156 |
* (for example, it happens to be underneath a menu that was pulled |
|
9157 |
* down). |
|
9158 |
* |
|
9159 |
* @return true if object is showing; otherwise, false |
|
9160 |
*/ |
|
9161 |
public boolean isShowing() { |
|
9162 |
return Component.this.isShowing(); |
|
9163 |
} |
|
9164 |
||
9165 |
/** |
|
9166 |
* Checks whether the specified point is within this object's bounds, |
|
9167 |
* where the point's x and y coordinates are defined to be relative to |
|
9168 |
* the coordinate system of the object. |
|
9169 |
* |
|
9170 |
* @param p the <code>Point</code> relative to the |
|
9171 |
* coordinate system of the object |
|
9172 |
* @return true if object contains <code>Point</code>; otherwise false |
|
9173 |
*/ |
|
9174 |
public boolean contains(Point p) { |
|
9175 |
return Component.this.contains(p); |
|
9176 |
} |
|
9177 |
||
9178 |
/** |
|
9179 |
* Returns the location of the object on the screen. |
|
9180 |
* |
|
9181 |
* @return location of object on screen -- can be |
|
9182 |
* <code>null</code> if this object is not on the screen |
|
9183 |
*/ |
|
9184 |
public Point getLocationOnScreen() { |
|
9185 |
synchronized (Component.this.getTreeLock()) { |
|
9186 |
if (Component.this.isShowing()) { |
|
9187 |
return Component.this.getLocationOnScreen(); |
|
9188 |
} else { |
|
9189 |
return null; |
|
9190 |
} |
|
9191 |
} |
|
9192 |
} |
|
9193 |
||
9194 |
/** |
|
9195 |
* Gets the location of the object relative to the parent in the form |
|
9196 |
* of a point specifying the object's top-left corner in the screen's |
|
9197 |
* coordinate space. |
|
9198 |
* |
|
9199 |
* @return an instance of Point representing the top-left corner of |
|
9200 |
* the object's bounds in the coordinate space of the screen; |
|
9201 |
* <code>null</code> if this object or its parent are not on the screen |
|
9202 |
*/ |
|
9203 |
public Point getLocation() { |
|
9204 |
return Component.this.getLocation(); |
|
9205 |
} |
|
9206 |
||
9207 |
/** |
|
9208 |
* Sets the location of the object relative to the parent. |
|
9209 |
* @param p the coordinates of the object |
|
9210 |
*/ |
|
9211 |
public void setLocation(Point p) { |
|
9212 |
Component.this.setLocation(p); |
|
9213 |
} |
|
9214 |
||
9215 |
/** |
|
9216 |
* Gets the bounds of this object in the form of a Rectangle object. |
|
9217 |
* The bounds specify this object's width, height, and location |
|
9218 |
* relative to its parent. |
|
9219 |
* |
|
9220 |
* @return a rectangle indicating this component's bounds; |
|
9221 |
* <code>null</code> if this object is not on the screen |
|
9222 |
*/ |
|
9223 |
public Rectangle getBounds() { |
|
9224 |
return Component.this.getBounds(); |
|
9225 |
} |
|
9226 |
||
9227 |
/** |
|
9228 |
* Sets the bounds of this object in the form of a |
|
9229 |
* <code>Rectangle</code> object. |
|
9230 |
* The bounds specify this object's width, height, and location |
|
9231 |
* relative to its parent. |
|
9232 |
* |
|
9233 |
* @param r a rectangle indicating this component's bounds |
|
9234 |
*/ |
|
9235 |
public void setBounds(Rectangle r) { |
|
9236 |
Component.this.setBounds(r); |
|
9237 |
} |
|
9238 |
||
9239 |
/** |
|
9240 |
* Returns the size of this object in the form of a |
|
9241 |
* <code>Dimension</code> object. The height field of the |
|
9242 |
* <code>Dimension</code> object contains this objects's |
|
9243 |
* height, and the width field of the <code>Dimension</code> |
|
9244 |
* object contains this object's width. |
|
9245 |
* |
|
9246 |
* @return a <code>Dimension</code> object that indicates |
|
9247 |
* the size of this component; <code>null</code> if |
|
9248 |
* this object is not on the screen |
|
9249 |
*/ |
|
9250 |
public Dimension getSize() { |
|
9251 |
return Component.this.getSize(); |
|
9252 |
} |
|
9253 |
||
9254 |
/** |
|
9255 |
* Resizes this object so that it has width and height. |
|
9256 |
* |
|
9257 |
* @param d - the dimension specifying the new size of the object |
|
9258 |
*/ |
|
9259 |
public void setSize(Dimension d) { |
|
9260 |
Component.this.setSize(d); |
|
9261 |
} |
|
9262 |
||
9263 |
/** |
|
9264 |
* Returns the <code>Accessible</code> child, |
|
9265 |
* if one exists, contained at the local |
|
9266 |
* coordinate <code>Point</code>. Otherwise returns |
|
9267 |
* <code>null</code>. |
|
9268 |
* |
|
9269 |
* @param p the point defining the top-left corner of |
|
9270 |
* the <code>Accessible</code>, given in the |
|
9271 |
* coordinate space of the object's parent |
|
9272 |
* @return the <code>Accessible</code>, if it exists, |
|
9273 |
* at the specified location; else <code>null</code> |
|
9274 |
*/ |
|
9275 |
public Accessible getAccessibleAt(Point p) { |
|
9276 |
return null; // Components don't have children |
|
9277 |
} |
|
9278 |
||
9279 |
/** |
|
9280 |
* Returns whether this object can accept focus or not. |
|
9281 |
* |
|
9282 |
* @return true if object can accept focus; otherwise false |
|
9283 |
*/ |
|
9284 |
public boolean isFocusTraversable() { |
|
9285 |
return Component.this.isFocusTraversable(); |
|
9286 |
} |
|
9287 |
||
9288 |
/** |
|
9289 |
* Requests focus for this object. |
|
9290 |
*/ |
|
9291 |
public void requestFocus() { |
|
9292 |
Component.this.requestFocus(); |
|
9293 |
} |
|
9294 |
||
9295 |
/** |
|
9296 |
* Adds the specified focus listener to receive focus events from this |
|
9297 |
* component. |
|
9298 |
* |
|
9299 |
* @param l the focus listener |
|
9300 |
*/ |
|
9301 |
public void addFocusListener(FocusListener l) { |
|
9302 |
Component.this.addFocusListener(l); |
|
9303 |
} |
|
9304 |
||
9305 |
/** |
|
9306 |
* Removes the specified focus listener so it no longer receives focus |
|
9307 |
* events from this component. |
|
9308 |
* |
|
9309 |
* @param l the focus listener |
|
9310 |
*/ |
|
9311 |
public void removeFocusListener(FocusListener l) { |
|
9312 |
Component.this.removeFocusListener(l); |
|
9313 |
} |
|
9314 |
||
9315 |
} // inner class AccessibleAWTComponent |
|
9316 |
||
9317 |
||
9318 |
/** |
|
9319 |
* Gets the index of this object in its accessible parent. |
|
9320 |
* If this object does not have an accessible parent, returns |
|
9321 |
* -1. |
|
9322 |
* |
|
9323 |
* @return the index of this object in its accessible parent |
|
9324 |
*/ |
|
9325 |
int getAccessibleIndexInParent() { |
|
9326 |
synchronized (getTreeLock()) { |
|
9327 |
int index = -1; |
|
9328 |
Container parent = this.getParent(); |
|
9329 |
if (parent != null && parent instanceof Accessible) { |
|
9330 |
Component ca[] = parent.getComponents(); |
|
9331 |
for (int i = 0; i < ca.length; i++) { |
|
9332 |
if (ca[i] instanceof Accessible) { |
|
9333 |
index++; |
|
9334 |
} |
|
9335 |
if (this.equals(ca[i])) { |
|
9336 |
return index; |
|
9337 |
} |
|
9338 |
} |
|
9339 |
} |
|
9340 |
return -1; |
|
9341 |
} |
|
9342 |
} |
|
9343 |
||
9344 |
/** |
|
9345 |
* Gets the current state set of this object. |
|
9346 |
* |
|
9347 |
* @return an instance of <code>AccessibleStateSet</code> |
|
9348 |
* containing the current state set of the object |
|
9349 |
* @see AccessibleState |
|
9350 |
*/ |
|
9351 |
AccessibleStateSet getAccessibleStateSet() { |
|
9352 |
synchronized (getTreeLock()) { |
|
9353 |
AccessibleStateSet states = new AccessibleStateSet(); |
|
9354 |
if (this.isEnabled()) { |
|
9355 |
states.add(AccessibleState.ENABLED); |
|
9356 |
} |
|
9357 |
if (this.isFocusTraversable()) { |
|
9358 |
states.add(AccessibleState.FOCUSABLE); |
|
9359 |
} |
|
9360 |
if (this.isVisible()) { |
|
9361 |
states.add(AccessibleState.VISIBLE); |
|
9362 |
} |
|
9363 |
if (this.isShowing()) { |
|
9364 |
states.add(AccessibleState.SHOWING); |
|
9365 |
} |
|
9366 |
if (this.isFocusOwner()) { |
|
9367 |
states.add(AccessibleState.FOCUSED); |
|
9368 |
} |
|
9369 |
if (this instanceof Accessible) { |
|
9370 |
AccessibleContext ac = ((Accessible) this).getAccessibleContext(); |
|
9371 |
if (ac != null) { |
|
9372 |
Accessible ap = ac.getAccessibleParent(); |
|
9373 |
if (ap != null) { |
|
9374 |
AccessibleContext pac = ap.getAccessibleContext(); |
|
9375 |
if (pac != null) { |
|
9376 |
AccessibleSelection as = pac.getAccessibleSelection(); |
|
9377 |
if (as != null) { |
|
9378 |
states.add(AccessibleState.SELECTABLE); |
|
9379 |
int i = ac.getAccessibleIndexInParent(); |
|
9380 |
if (i >= 0) { |
|
9381 |
if (as.isAccessibleChildSelected(i)) { |
|
9382 |
states.add(AccessibleState.SELECTED); |
|
9383 |
} |
|
9384 |
} |
|
9385 |
} |
|
9386 |
} |
|
9387 |
} |
|
9388 |
} |
|
9389 |
} |
|
9390 |
if (Component.isInstanceOf(this, "javax.swing.JComponent")) { |
|
9391 |
if (((javax.swing.JComponent) this).isOpaque()) { |
|
9392 |
states.add(AccessibleState.OPAQUE); |
|
9393 |
} |
|
9394 |
} |
|
9395 |
return states; |
|
9396 |
} |
|
9397 |
} |
|
9398 |
||
9399 |
/** |
|
9400 |
* Checks that the given object is instance of the given class. |
|
9401 |
* @param obj Object to be checked |
|
9402 |
* @param className The name of the class. Must be fully-qualified class name. |
|
9403 |
* @return true, if this object is instanceof given class, |
|
9404 |
* false, otherwise, or if obj or className is null |
|
9405 |
*/ |
|
9406 |
static boolean isInstanceOf(Object obj, String className) { |
|
9407 |
if (obj == null) return false; |
|
9408 |
if (className == null) return false; |
|
9409 |
||
9410 |
Class cls = obj.getClass(); |
|
9411 |
while (cls != null) { |
|
9412 |
if (cls.getName().equals(className)) { |
|
9413 |
return true; |
|
9414 |
} |
|
9415 |
cls = cls.getSuperclass(); |
|
9416 |
} |
|
9417 |
return false; |
|
9418 |
} |
|
9419 |
||
9420 |
||
9421 |
// ************************** MIXING CODE ******************************* |
|
9422 |
||
9423 |
/** |
|
126 | 9424 |
* Check whether we can trust the current bounds of the component. |
9425 |
* The return value of false indicates that the container of the |
|
9426 |
* component is invalid, and therefore needs to be layed out, which would |
|
9427 |
* probably mean changing the bounds of its children. |
|
9428 |
* Null-layout of the container or absence of the container mean |
|
9429 |
* the bounds of the component are final and can be trusted. |
|
9430 |
*/ |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9431 |
final boolean areBoundsValid() { |
126 | 9432 |
Container cont = getContainer(); |
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9433 |
return cont == null || cont.isValid() || cont.getLayout() == null; |
126 | 9434 |
} |
9435 |
||
9436 |
/** |
|
2 | 9437 |
* Applies the shape to the component |
9438 |
* @param shape Shape to be applied to the component |
|
9439 |
*/ |
|
9440 |
void applyCompoundShape(Region shape) { |
|
9441 |
checkTreeLock(); |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9442 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9443 |
if (!areBoundsValid()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9444 |
if (mixingLog.isLoggable(Level.FINE)) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9445 |
mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9446 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9447 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9448 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9449 |
|
2 | 9450 |
if (!isLightweight()) { |
9451 |
ComponentPeer peer = getPeer(); |
|
9452 |
if (peer != null) { |
|
9453 |
// The Region class has some optimizations. That's why |
|
9454 |
// we should manually check whether it's empty and |
|
9455 |
// substitute the object ourselves. Otherwise we end up |
|
9456 |
// with some incorrect Region object with loX being |
|
9457 |
// greater than the hiX for instance. |
|
9458 |
if (shape.isEmpty()) { |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9459 |
shape = Region.EMPTY_REGION; |
2 | 9460 |
} |
9461 |
||
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9462 |
|
2 | 9463 |
// Note: the shape is not really copied/cloned. We create |
9464 |
// the Region object ourselves, so there's no any possibility |
|
9465 |
// to modify the object outside of the mixing code. |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9466 |
// Nullifying compoundShape means that the component has normal shape |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9467 |
// (or has no shape at all). |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9468 |
if (shape.equals(getNormalShape())) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9469 |
if (this.compoundShape == null) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9470 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9471 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9472 |
this.compoundShape = null; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9473 |
peer.applyShape(null); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9474 |
} else { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9475 |
if (shape.equals(getAppliedShape())) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9476 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9477 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9478 |
this.compoundShape = shape; |
2 | 9479 |
Point compAbsolute = getLocationOnWindow(); |
9480 |
if (mixingLog.isLoggable(Level.FINER)) { |
|
9481 |
mixingLog.fine("this = " + this + |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9482 |
"; compAbsolute=" + compAbsolute + "; shape=" + shape); |
2 | 9483 |
} |
9484 |
peer.applyShape(shape.getTranslatedRegion(-compAbsolute.x, -compAbsolute.y)); |
|
9485 |
} |
|
9486 |
} |
|
9487 |
} |
|
9488 |
} |
|
9489 |
||
9490 |
/** |
|
9491 |
* Returns the shape previously set with applyCompoundShape(). |
|
9492 |
* If the component is LW or no shape was applied yet, |
|
9493 |
* the method returns the normal shape. |
|
9494 |
*/ |
|
9495 |
private Region getAppliedShape() { |
|
9496 |
checkTreeLock(); |
|
9497 |
//XXX: if we allow LW components to have a shape, this must be changed |
|
9498 |
return (this.compoundShape == null || isLightweight()) ? getNormalShape() : this.compoundShape; |
|
9499 |
} |
|
9500 |
||
9501 |
Point getLocationOnWindow() { |
|
9502 |
checkTreeLock(); |
|
9503 |
Point curLocation = getLocation(); |
|
9504 |
||
9505 |
for (Container parent = getContainer(); |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9506 |
parent != null && !(parent instanceof Window); |
2 | 9507 |
parent = parent.getContainer()) |
9508 |
{ |
|
9509 |
curLocation.x += parent.getX(); |
|
9510 |
curLocation.y += parent.getY(); |
|
9511 |
} |
|
9512 |
||
9513 |
return curLocation; |
|
9514 |
} |
|
9515 |
||
9516 |
/** |
|
9517 |
* Returns the full shape of the component located in window coordinates |
|
9518 |
*/ |
|
9519 |
final Region getNormalShape() { |
|
9520 |
checkTreeLock(); |
|
9521 |
//XXX: we may take into account a user-specified shape for this component |
|
9522 |
Point compAbsolute = getLocationOnWindow(); |
|
9523 |
return |
|
9524 |
Region.getInstanceXYWH( |
|
9525 |
compAbsolute.x, |
|
9526 |
compAbsolute.y, |
|
9527 |
getWidth(), |
|
9528 |
getHeight() |
|
9529 |
); |
|
9530 |
} |
|
9531 |
||
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9532 |
/** |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9533 |
* Returns the "opaque shape" of the component. |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9534 |
* |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9535 |
* The opaque shape of a lightweight components is the actual shape that |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9536 |
* needs to be cut off of the heavyweight components in order to mix this |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9537 |
* lightweight component correctly with them. |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9538 |
* |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9539 |
* The method is overriden in the java.awt.Container to handle non-opaque |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9540 |
* containers containing opaque children. |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9541 |
* |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9542 |
* See 6637655 for details. |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9543 |
*/ |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9544 |
Region getOpaqueShape() { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9545 |
checkTreeLock(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9546 |
if (mixingCutoutRegion != null) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9547 |
return mixingCutoutRegion; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9548 |
} else { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9549 |
return getNormalShape(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9550 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9551 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9552 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9553 |
final int getSiblingIndexAbove() { |
2 | 9554 |
checkTreeLock(); |
9555 |
Container parent = getContainer(); |
|
9556 |
if (parent == null) { |
|
9557 |
return -1; |
|
9558 |
} |
|
9559 |
||
9560 |
int nextAbove = parent.getComponentZOrder(this) - 1; |
|
9561 |
||
9562 |
return nextAbove < 0 ? -1 : nextAbove; |
|
9563 |
} |
|
9564 |
||
2462
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9565 |
final ComponentPeer getHWPeerAboveMe() { |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9566 |
checkTreeLock(); |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9567 |
|
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9568 |
Container cont = getContainer(); |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9569 |
int indexAbove = getSiblingIndexAbove(); |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9570 |
|
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9571 |
while (cont != null) { |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9572 |
for (int i = indexAbove; i > -1; i--) { |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9573 |
Component comp = cont.getComponent(i); |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9574 |
if (comp != null && comp.isDisplayable() && !comp.isLightweight()) { |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9575 |
return comp.getPeer(); |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9576 |
} |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9577 |
} |
3727
43b25dfd1129
6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents:
3237
diff
changeset
|
9578 |
// traversing the hierarchy up to the closest HW container; |
43b25dfd1129
6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents:
3237
diff
changeset
|
9579 |
// further traversing may return a component that is not actually |
43b25dfd1129
6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents:
3237
diff
changeset
|
9580 |
// a native sibling of this component and this kind of z-order |
43b25dfd1129
6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents:
3237
diff
changeset
|
9581 |
// request may not be allowed by the underlying system (6852051). |
43b25dfd1129
6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents:
3237
diff
changeset
|
9582 |
if (!cont.isLightweight()) { |
43b25dfd1129
6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents:
3237
diff
changeset
|
9583 |
break; |
43b25dfd1129
6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents:
3237
diff
changeset
|
9584 |
} |
2462
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9585 |
|
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9586 |
indexAbove = cont.getSiblingIndexAbove(); |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9587 |
cont = cont.getContainer(); |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9588 |
} |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9589 |
|
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9590 |
return null; |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9591 |
} |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
9592 |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9593 |
final int getSiblingIndexBelow() { |
2 | 9594 |
checkTreeLock(); |
9595 |
Container parent = getContainer(); |
|
9596 |
if (parent == null) { |
|
9597 |
return -1; |
|
9598 |
} |
|
9599 |
||
9600 |
int nextBelow = parent.getComponentZOrder(this) + 1; |
|
9601 |
||
9602 |
return nextBelow >= parent.getComponentCount() ? -1 : nextBelow; |
|
9603 |
} |
|
9604 |
||
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9605 |
final boolean isNonOpaqueForMixing() { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9606 |
return mixingCutoutRegion != null && |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9607 |
mixingCutoutRegion.isEmpty(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9608 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9609 |
|
2 | 9610 |
private Region calculateCurrentShape() { |
9611 |
checkTreeLock(); |
|
9612 |
Region s = getNormalShape(); |
|
9613 |
||
9614 |
if (mixingLog.isLoggable(Level.FINE)) { |
|
9615 |
mixingLog.fine("this = " + this + "; normalShape=" + s); |
|
9616 |
} |
|
9617 |
||
9618 |
if (getContainer() != null) { |
|
9619 |
Component comp = this; |
|
9620 |
Container cont = comp.getContainer(); |
|
9621 |
||
9622 |
while (cont != null) { |
|
9623 |
for (int index = comp.getSiblingIndexAbove(); index != -1; --index) { |
|
9624 |
/* It is assumed that: |
|
9625 |
* |
|
9626 |
* getComponent(getContainer().getComponentZOrder(comp)) == comp |
|
9627 |
* |
|
9628 |
* The assumption has been made according to the current |
|
9629 |
* implementation of the Container class. |
|
9630 |
*/ |
|
9631 |
Component c = cont.getComponent(index); |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9632 |
if (c.isLightweight() && c.isShowing()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9633 |
s = s.getDifference(c.getOpaqueShape()); |
2 | 9634 |
} |
9635 |
} |
|
9636 |
||
9637 |
if (cont.isLightweight()) { |
|
9638 |
s = s.getIntersection(cont.getNormalShape()); |
|
9639 |
} else { |
|
9640 |
break; |
|
9641 |
} |
|
9642 |
||
9643 |
comp = cont; |
|
9644 |
cont = cont.getContainer(); |
|
9645 |
} |
|
9646 |
} |
|
9647 |
||
9648 |
if (mixingLog.isLoggable(Level.FINE)) { |
|
9649 |
mixingLog.fine("currentShape=" + s); |
|
9650 |
} |
|
9651 |
||
9652 |
return s; |
|
9653 |
} |
|
9654 |
||
9655 |
void applyCurrentShape() { |
|
9656 |
checkTreeLock(); |
|
126 | 9657 |
if (!areBoundsValid()) { |
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9658 |
if (mixingLog.isLoggable(Level.FINE)) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9659 |
mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9660 |
} |
2 | 9661 |
return; // Because applyCompoundShape() ignores such components anyway |
9662 |
} |
|
9663 |
if (mixingLog.isLoggable(Level.FINE)) { |
|
9664 |
mixingLog.fine("this = " + this); |
|
9665 |
} |
|
9666 |
applyCompoundShape(calculateCurrentShape()); |
|
9667 |
} |
|
9668 |
||
9669 |
final void subtractAndApplyShape(Region s) { |
|
9670 |
checkTreeLock(); |
|
9671 |
||
9672 |
if (mixingLog.isLoggable(Level.FINE)) { |
|
9673 |
mixingLog.fine("this = " + this + "; s=" + s); |
|
9674 |
} |
|
9675 |
||
9676 |
applyCompoundShape(getAppliedShape().getDifference(s)); |
|
9677 |
} |
|
9678 |
||
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9679 |
private final void applyCurrentShapeBelowMe() { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9680 |
checkTreeLock(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9681 |
Container parent = getContainer(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9682 |
if (parent != null && parent.isShowing()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9683 |
// First, reapply shapes of my siblings |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9684 |
parent.recursiveApplyCurrentShape(getSiblingIndexBelow()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9685 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9686 |
// Second, if my container is non-opaque, reapply shapes of siblings of my container |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9687 |
Container parent2 = parent.getContainer(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9688 |
while (!parent.isOpaque() && parent2 != null) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9689 |
parent2.recursiveApplyCurrentShape(parent.getSiblingIndexBelow()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9690 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9691 |
parent = parent2; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9692 |
parent2 = parent.getContainer(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9693 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9694 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9695 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9696 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9697 |
final void subtractAndApplyShapeBelowMe() { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9698 |
checkTreeLock(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9699 |
Container parent = getContainer(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9700 |
if (parent != null && isShowing()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9701 |
Region opaqueShape = getOpaqueShape(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9702 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9703 |
// First, cut my siblings |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9704 |
parent.recursiveSubtractAndApplyShape(opaqueShape, getSiblingIndexBelow()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9705 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9706 |
// Second, if my container is non-opaque, cut siblings of my container |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9707 |
Container parent2 = parent.getContainer(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9708 |
while (!parent.isOpaque() && parent2 != null) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9709 |
parent2.recursiveSubtractAndApplyShape(opaqueShape, parent.getSiblingIndexBelow()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9710 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9711 |
parent = parent2; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9712 |
parent2 = parent.getContainer(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9713 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9714 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9715 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9716 |
|
2 | 9717 |
void mixOnShowing() { |
9718 |
synchronized (getTreeLock()) { |
|
9719 |
if (mixingLog.isLoggable(Level.FINE)) { |
|
9720 |
mixingLog.fine("this = " + this); |
|
9721 |
} |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9722 |
if (!isMixingNeeded()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9723 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9724 |
} |
2 | 9725 |
if (isLightweight()) { |
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9726 |
subtractAndApplyShapeBelowMe(); |
2 | 9727 |
} else { |
9728 |
applyCurrentShape(); |
|
9729 |
} |
|
9730 |
} |
|
9731 |
} |
|
9732 |
||
9733 |
void mixOnHiding(boolean isLightweight) { |
|
9734 |
// We cannot be sure that the peer exists at this point, so we need the argument |
|
9735 |
// to find out whether the hiding component is (well, actually was) a LW or a HW. |
|
9736 |
synchronized (getTreeLock()) { |
|
9737 |
if (mixingLog.isLoggable(Level.FINE)) { |
|
9738 |
mixingLog.fine("this = " + this + "; isLightweight = " + isLightweight); |
|
9739 |
} |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9740 |
if (!isMixingNeeded()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9741 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9742 |
} |
2 | 9743 |
if (isLightweight) { |
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9744 |
applyCurrentShapeBelowMe(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9745 |
} |
2 | 9746 |
} |
9747 |
} |
|
9748 |
||
9749 |
void mixOnReshaping() { |
|
9750 |
synchronized (getTreeLock()) { |
|
9751 |
if (mixingLog.isLoggable(Level.FINE)) { |
|
9752 |
mixingLog.fine("this = " + this); |
|
9753 |
} |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9754 |
if (!isMixingNeeded()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9755 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9756 |
} |
2 | 9757 |
if (isLightweight()) { |
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9758 |
applyCurrentShapeBelowMe(); |
2 | 9759 |
} else { |
9760 |
applyCurrentShape(); |
|
9761 |
} |
|
9762 |
} |
|
9763 |
} |
|
9764 |
||
9765 |
void mixOnZOrderChanging(int oldZorder, int newZorder) { |
|
9766 |
synchronized (getTreeLock()) { |
|
9767 |
boolean becameHigher = newZorder < oldZorder; |
|
9768 |
Container parent = getContainer(); |
|
9769 |
||
9770 |
if (mixingLog.isLoggable(Level.FINE)) { |
|
9771 |
mixingLog.fine("this = " + this + |
|
9772 |
"; oldZorder=" + oldZorder + "; newZorder=" + newZorder + "; parent=" + parent); |
|
9773 |
} |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9774 |
if (!isMixingNeeded()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9775 |
return; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9776 |
} |
2 | 9777 |
if (isLightweight()) { |
9778 |
if (becameHigher) { |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9779 |
if (parent != null && isShowing()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9780 |
parent.recursiveSubtractAndApplyShape(getOpaqueShape(), getSiblingIndexBelow(), oldZorder); |
2 | 9781 |
} |
9782 |
} else { |
|
9783 |
if (parent != null) { |
|
9784 |
parent.recursiveApplyCurrentShape(oldZorder, newZorder); |
|
9785 |
} |
|
9786 |
} |
|
9787 |
} else { |
|
9788 |
if (becameHigher) { |
|
9789 |
applyCurrentShape(); |
|
9790 |
} else { |
|
9791 |
if (parent != null) { |
|
9792 |
Region shape = getAppliedShape(); |
|
9793 |
||
9794 |
for (int index = oldZorder; index < newZorder; index++) { |
|
9795 |
Component c = parent.getComponent(index); |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9796 |
if (c.isLightweight() && c.isShowing()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9797 |
shape = shape.getDifference(c.getOpaqueShape()); |
2 | 9798 |
} |
9799 |
} |
|
9800 |
applyCompoundShape(shape); |
|
9801 |
} |
|
9802 |
} |
|
9803 |
} |
|
9804 |
} |
|
9805 |
} |
|
9806 |
||
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
9807 |
void mixOnValidating() { |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
9808 |
// This method gets overriden in the Container. Obviously, a plain |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
9809 |
// non-container components don't need to handle validation. |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
9810 |
} |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
1181
diff
changeset
|
9811 |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9812 |
final boolean isMixingNeeded() { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9813 |
if (SunToolkit.getSunAwtDisableMixing()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9814 |
if (mixingLog.isLoggable(Level.FINEST)) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9815 |
mixingLog.finest("this = " + this + "; Mixing disabled via sun.awt.disableMixing"); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9816 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9817 |
return false; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9818 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9819 |
if (!areBoundsValid()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9820 |
if (mixingLog.isLoggable(Level.FINE)) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9821 |
mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9822 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9823 |
return false; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9824 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9825 |
Window window = getContainingWindow(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9826 |
if (window != null) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9827 |
if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants()) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9828 |
if (mixingLog.isLoggable(Level.FINE)) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9829 |
mixingLog.fine("containing window = " + window + |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9830 |
"; has h/w descendants = " + window.hasHeavyweightDescendants() + |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9831 |
"; has l/w descendants = " + window.hasLightweightDescendants()); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9832 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9833 |
return false; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9834 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9835 |
} else { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9836 |
if (mixingLog.isLoggable(Level.FINE)) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9837 |
mixingLog.finest("this = " + this + "; containing window is null"); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9838 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9839 |
return false; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9840 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9841 |
return true; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9842 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1964
diff
changeset
|
9843 |
|
2 | 9844 |
// ****************** END OF MIXING CODE ******************************** |
2451 | 9845 |
|
2647
ea80a312972e
6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents:
2472
diff
changeset
|
9846 |
// Note that the method is overriden in the Window class, |
ea80a312972e
6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents:
2472
diff
changeset
|
9847 |
// a window doesn't need to be updated in the Z-order. |
ea80a312972e
6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents:
2472
diff
changeset
|
9848 |
void updateZOrder() { |
ea80a312972e
6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents:
2472
diff
changeset
|
9849 |
peer.setZOrder(getHWPeerAboveMe()); |
ea80a312972e
6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents:
2472
diff
changeset
|
9850 |
} |
ea80a312972e
6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents:
2472
diff
changeset
|
9851 |
|
2 | 9852 |
} |