-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Component.java
10538 lines (9774 loc) · 382 KB
/
Component.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt;
import java.applet.Applet;
import java.awt.dnd.DropTarget;
import java.awt.event.ActionEvent;
import java.awt.event.AdjustmentEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.awt.event.InputEvent;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.PaintEvent;
import java.awt.event.TextEvent;
import java.awt.im.InputContext;
import java.awt.im.InputMethodRequests;
import java.awt.image.BufferStrategy;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.image.VolatileImage;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.Transient;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Serial;
import java.io.Serializable;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.Collections;
import java.util.EventListener;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.Vector;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleComponent;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleSelection;
import javax.accessibility.AccessibleState;
import javax.accessibility.AccessibleStateSet;
import javax.swing.JComponent;
import javax.swing.JRootPane;
import sun.awt.AWTAccessor;
import sun.awt.AppContext;
import sun.awt.ComponentFactory;
import sun.awt.ConstrainableGraphics;
import sun.awt.EmbeddedFrame;
import sun.awt.RequestFocusController;
import sun.awt.SubRegionShowable;
import sun.awt.SunToolkit;
import sun.awt.dnd.SunDropTargetEvent;
import sun.awt.im.CompositionArea;
import sun.awt.image.VSyncedBSManager;
import sun.font.FontManager;
import sun.font.FontManagerFactory;
import sun.font.SunFontManager;
import sun.java2d.SunGraphics2D;
import sun.java2d.SunGraphicsEnvironment;
import sun.java2d.pipe.Region;
import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
import sun.security.action.GetPropertyAction;
import sun.swing.SwingAccessor;
import sun.util.logging.PlatformLogger;
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_DEFAULT;
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON;
/**
* A <em>component</em> is an object having a graphical representation
* that can be displayed on the screen and that can interact with the
* user. Examples of components are the buttons, checkboxes, and scrollbars
* of a typical graphical user interface. <p>
* The {@code Component} class is the abstract superclass of
* the nonmenu-related Abstract Window Toolkit components. Class
* {@code Component} can also be extended directly to create a
* lightweight component. A lightweight component is a component that is
* not associated with a native window. On the contrary, a heavyweight
* component is associated with a native window. The {@link #isLightweight()}
* method may be used to distinguish between the two kinds of the components.
* <p>
* Lightweight and heavyweight components may be mixed in a single component
* hierarchy. However, for correct operating of such a mixed hierarchy of
* components, the whole hierarchy must be valid. When the hierarchy gets
* invalidated, like after changing the bounds of components, or
* adding/removing components to/from containers, the whole hierarchy must be
* validated afterwards by means of the {@link Container#validate()} method
* invoked on the top-most invalid container of the hierarchy.
*
* <h2>Serialization</h2>
* It is important to note that only AWT listeners which conform
* to the {@code Serializable} protocol will be saved when
* the object is stored. If an AWT object has listeners that
* aren't marked serializable, they will be dropped at
* {@code writeObject} time. Developers will need, as always,
* to consider the implications of making an object serializable.
* One situation to watch out for is this:
* <pre>
* import java.awt.*;
* import java.awt.event.*;
* import java.io.Serializable;
*
* class MyApp implements ActionListener, Serializable
* {
* BigObjectThatShouldNotBeSerializedWithAButton bigOne;
* Button aButton = new Button();
*
* MyApp()
* {
* // Oops, now aButton has a listener with a reference
* // to bigOne!
* aButton.addActionListener(this);
* }
*
* public void actionPerformed(ActionEvent e)
* {
* System.out.println("Hello There");
* }
* }
* </pre>
* In this example, serializing {@code aButton} by itself
* will cause {@code MyApp} and everything it refers to
* to be serialized as well. The problem is that the listener
* is serializable by coincidence, not by design. To separate
* the decisions about {@code MyApp} and the
* {@code ActionListener} being serializable one can use a
* nested class, as in the following example:
* <pre>
* import java.awt.*;
* import java.awt.event.*;
* import java.io.Serializable;
*
* class MyApp implements java.io.Serializable
* {
* BigObjectThatShouldNotBeSerializedWithAButton bigOne;
* Button aButton = new Button();
*
* static class MyActionListener implements ActionListener
* {
* public void actionPerformed(ActionEvent e)
* {
* System.out.println("Hello There");
* }
* }
*
* MyApp()
* {
* aButton.addActionListener(new MyActionListener());
* }
* }
* </pre>
* <p>
* <b>Note</b>: For more information on the paint mechanisms utilized
* by AWT and Swing, including information on how to write the most
* efficient painting code, see
* <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
* <p>
* For details on the focus subsystem, see
* <a href="https://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
* How to Use the Focus Subsystem</a>,
* a section in <em>The Java Tutorial</em>, and the
* <a href="doc-files/FocusSpec.html">Focus Specification</a>
* for more information.
*
* @author Arthur van Hoff
* @author Sami Shaio
*/
public abstract class Component implements ImageObserver, MenuContainer,
Serializable
{
private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Component");
private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Component");
private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.Component");
private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Component");
/**
* The peer of the component. The peer implements the component's
* behavior. The peer is set when the {@code Component} is
* added to a container that also is a peer.
* @see #addNotify
* @see #removeNotify
*/
transient volatile ComponentPeer peer;
/**
* The parent of the object. It may be {@code null}
* for top-level components.
* @see #getParent
*/
transient Container parent;
/**
* The {@code AppContext} of the component. Applets/Plugin may
* change the AppContext.
*/
transient AppContext appContext;
/**
* The x position of the component in the parent's coordinate system.
*
* @serial
* @see #getLocation
*/
int x;
/**
* The y position of the component in the parent's coordinate system.
*
* @serial
* @see #getLocation
*/
int y;
/**
* The width of the component.
*
* @serial
* @see #getSize
*/
int width;
/**
* The height of the component.
*
* @serial
* @see #getSize
*/
int height;
/**
* The foreground color for this component.
* {@code foreground} can be {@code null}.
*
* @serial
* @see #getForeground
* @see #setForeground
*/
Color foreground;
/**
* The background color for this component.
* {@code background} can be {@code null}.
*
* @serial
* @see #getBackground
* @see #setBackground
*/
Color background;
/**
* The font used by this component.
* The {@code font} can be {@code null}.
*
* @serial
* @see #getFont
* @see #setFont
*/
volatile Font font;
/**
* The font which the peer is currently using.
* ({@code null} if no peer exists.)
*/
Font peerFont;
/**
* The cursor displayed when pointer is over this component.
* This value can be {@code null}.
*
* @serial
* @see #getCursor
* @see #setCursor
*/
Cursor cursor;
/**
* The locale for the component.
*
* @serial
* @see #getLocale
* @see #setLocale
*/
Locale locale;
/**
* A reference to a {@code GraphicsConfiguration} object
* used to describe the characteristics of a graphics
* destination.
* This value can be {@code null}.
*
* @since 1.3
* @serial
* @see GraphicsConfiguration
* @see #getGraphicsConfiguration
*/
private transient volatile GraphicsConfiguration graphicsConfig;
/**
* A reference to a {@code BufferStrategy} object
* used to manipulate the buffers on this component.
*
* @since 1.4
* @see java.awt.image.BufferStrategy
* @see #getBufferStrategy()
*/
private transient BufferStrategy bufferStrategy = null;
/**
* True when the object should ignore all repaint events.
*
* @since 1.4
* @serial
* @see #setIgnoreRepaint
* @see #getIgnoreRepaint
*/
boolean ignoreRepaint = false;
/**
* True when the object is visible. An object that is not
* visible is not drawn on the screen.
*
* @serial
* @see #isVisible
* @see #setVisible
*/
boolean visible = true;
/**
* True when the object is enabled. An object that is not
* enabled does not interact with the user.
*
* @serial
* @see #isEnabled
* @see #setEnabled
*/
boolean enabled = true;
/**
* True when the object is valid. An invalid object needs to
* be laid out. This flag is set to false when the object
* size is changed.
*
* @serial
* @see #isValid
* @see #validate
* @see #invalidate
*/
private volatile boolean valid;
/**
* The {@code DropTarget} associated with this component.
*
* @since 1.2
* @serial
* @see #setDropTarget
* @see #getDropTarget
*/
DropTarget dropTarget;
/**
* @serial
* @see #add
*/
Vector<PopupMenu> popups;
/**
* A component's name.
* This field can be {@code null}.
*
* @serial
* @see #getName
* @see #setName(String)
*/
private String name;
/**
* A bool to determine whether the name has
* been set explicitly. {@code nameExplicitlySet} will
* be false if the name has not been set and
* true if it has.
*
* @serial
* @see #getName
* @see #setName(String)
*/
private boolean nameExplicitlySet = false;
/**
* Indicates whether this Component can be focused.
*
* @serial
* @see #setFocusable
* @see #isFocusable
* @since 1.4
*/
private boolean focusable = true;
private static final int FOCUS_TRAVERSABLE_UNKNOWN = 0;
private static final int FOCUS_TRAVERSABLE_DEFAULT = 1;
private static final int FOCUS_TRAVERSABLE_SET = 2;
/**
* Tracks whether this Component is relying on default focus traversability.
*
* @serial
* @since 1.4
*/
private int isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN;
/**
* The focus traversal keys. These keys will generate focus traversal
* behavior for Components for which focus traversal keys are enabled. If a
* value of null is specified for a traversal key, this Component inherits
* that traversal key from its parent. If all ancestors of this Component
* have null specified for that traversal key, then the current
* KeyboardFocusManager's default traversal key is used.
*
* @serial
* @see #setFocusTraversalKeys
* @see #getFocusTraversalKeys
* @since 1.4
*/
@SuppressWarnings("serial") // Not statically typed as Serializable
Set<AWTKeyStroke>[] focusTraversalKeys;
private static final String[] focusTraversalKeyPropertyNames = {
"forwardFocusTraversalKeys",
"backwardFocusTraversalKeys",
"upCycleFocusTraversalKeys",
"downCycleFocusTraversalKeys"
};
/**
* Indicates whether focus traversal keys are enabled for this Component.
* Components for which focus traversal keys are disabled receive key
* events for focus traversal keys. Components for which focus traversal
* keys are enabled do not see these events; instead, the events are
* automatically converted to traversal operations.
*
* @serial
* @see #setFocusTraversalKeysEnabled
* @see #getFocusTraversalKeysEnabled
* @since 1.4
*/
private boolean focusTraversalKeysEnabled = true;
/**
* The locking object for AWT component-tree and layout operations.
*
* @see #getTreeLock
*/
static final Object LOCK = new AWTTreeLock();
static class AWTTreeLock {}
/*
* The component's AccessControlContext.
*/
@SuppressWarnings("removal")
private transient volatile AccessControlContext acc =
AccessController.getContext();
/**
* Minimum size.
* (This field perhaps should have been transient).
*
* @serial
*/
Dimension minSize;
/**
* Whether or not setMinimumSize has been invoked with a non-null value.
*/
boolean minSizeSet;
/**
* Preferred size.
* (This field perhaps should have been transient).
*
* @serial
*/
Dimension prefSize;
/**
* Whether or not setPreferredSize has been invoked with a non-null value.
*/
boolean prefSizeSet;
/**
* Maximum size
*
* @serial
*/
Dimension maxSize;
/**
* Whether or not setMaximumSize has been invoked with a non-null value.
*/
boolean maxSizeSet;
/**
* The orientation for this component.
* @see #getComponentOrientation
* @see #setComponentOrientation
*/
transient ComponentOrientation componentOrientation
= ComponentOrientation.UNKNOWN;
/**
* {@code newEventsOnly} will be true if the event is
* one of the event types enabled for the component.
* It will then allow for normal processing to
* continue. If it is false the event is passed
* to the component's parent and up the ancestor
* tree until the event has been consumed.
*
* @serial
* @see #dispatchEvent
*/
boolean newEventsOnly = false;
transient ComponentListener componentListener;
transient FocusListener focusListener;
transient HierarchyListener hierarchyListener;
transient HierarchyBoundsListener hierarchyBoundsListener;
transient KeyListener keyListener;
transient MouseListener mouseListener;
transient MouseMotionListener mouseMotionListener;
transient MouseWheelListener mouseWheelListener;
transient InputMethodListener inputMethodListener;
/** Internal, constants for serialization */
static final String actionListenerK = "actionL";
static final String adjustmentListenerK = "adjustmentL";
static final String componentListenerK = "componentL";
static final String containerListenerK = "containerL";
static final String focusListenerK = "focusL";
static final String itemListenerK = "itemL";
static final String keyListenerK = "keyL";
static final String mouseListenerK = "mouseL";
static final String mouseMotionListenerK = "mouseMotionL";
static final String mouseWheelListenerK = "mouseWheelL";
static final String textListenerK = "textL";
static final String ownedWindowK = "ownedL";
static final String windowListenerK = "windowL";
static final String inputMethodListenerK = "inputMethodL";
static final String hierarchyListenerK = "hierarchyL";
static final String hierarchyBoundsListenerK = "hierarchyBoundsL";
static final String windowStateListenerK = "windowStateL";
static final String windowFocusListenerK = "windowFocusL";
/**
* The {@code eventMask} is ONLY set by subclasses via
* {@code enableEvents}.
* The mask should NOT be set when listeners are registered
* so that we can distinguish the difference between when
* listeners request events and subclasses request them.
* One bit is used to indicate whether input methods are
* enabled; this bit is set by {@code enableInputMethods} and is
* on by default.
*
* @serial
* @see #enableInputMethods
* @see AWTEvent
*/
long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK;
/**
* Static properties for incremental drawing.
* @see #imageUpdate
*/
static boolean isInc;
static int incRate;
static {
/* ensure that the necessary native libraries are loaded */
Toolkit.loadLibraries();
/* initialize JNI field and method ids */
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
@SuppressWarnings("removal")
String s = java.security.AccessController.doPrivileged(
new GetPropertyAction("awt.image.incrementaldraw"));
isInc = (s == null || s.equals("true"));
@SuppressWarnings("removal")
String s2 = java.security.AccessController.doPrivileged(
new GetPropertyAction("awt.image.redrawrate"));
incRate = (s2 != null) ? Integer.parseInt(s2) : 100;
}
/**
* Ease-of-use constant for {@code getAlignmentY()}.
* Specifies an alignment to the top of the component.
* @see #getAlignmentY
*/
public static final float TOP_ALIGNMENT = 0.0f;
/**
* Ease-of-use constant for {@code getAlignmentY} and
* {@code getAlignmentX}. Specifies an alignment to
* the center of the component
* @see #getAlignmentX
* @see #getAlignmentY
*/
public static final float CENTER_ALIGNMENT = 0.5f;
/**
* Ease-of-use constant for {@code getAlignmentY}.
* Specifies an alignment to the bottom of the component.
* @see #getAlignmentY
*/
public static final float BOTTOM_ALIGNMENT = 1.0f;
/**
* Ease-of-use constant for {@code getAlignmentX}.
* Specifies an alignment to the left side of the component.
* @see #getAlignmentX
*/
public static final float LEFT_ALIGNMENT = 0.0f;
/**
* Ease-of-use constant for {@code getAlignmentX}.
* Specifies an alignment to the right side of the component.
* @see #getAlignmentX
*/
public static final float RIGHT_ALIGNMENT = 1.0f;
/**
* Use serialVersionUID from JDK 1.1 for interoperability.
*/
@Serial
private static final long serialVersionUID = -7644114512714619750L;
/**
* If any {@code PropertyChangeListeners} have been registered,
* the {@code changeSupport} field describes them.
*
* @serial
* @since 1.2
* @see #addPropertyChangeListener
* @see #removePropertyChangeListener
* @see #firePropertyChange
*/
private PropertyChangeSupport changeSupport;
/*
* In some cases using "this" as an object to synchronize by
* can lead to a deadlock if client code also uses synchronization
* by a component object. For every such situation revealed we should
* consider possibility of replacing "this" with the package private
* objectLock object introduced below. So far there are 3 issues known:
* - CR 6708322 (the getName/setName methods);
* - CR 6608764 (the PropertyChangeListener machinery);
* - CR 7108598 (the Container.paint/KeyboardFocusManager.clearMostRecentFocusOwner methods).
*
* Note: this field is considered final, though readObject() prohibits
* initializing final fields.
*/
private transient Object objectLock = new Object();
Object getObjectLock() {
return objectLock;
}
/*
* Returns the acc this component was constructed with.
*/
@SuppressWarnings("removal")
final AccessControlContext getAccessControlContext() {
if (acc == null) {
throw new SecurityException("Component is missing AccessControlContext");
}
return acc;
}
/**
* Whether the component is packed or not;
*/
boolean isPacked = false;
/**
* Pseudoparameter for direct Geometry API (setLocation, setBounds setSize
* to signal setBounds what's changing. Should be used under TreeLock.
* This is only needed due to the inability to change the cross-calling
* order of public and deprecated methods.
*/
private int boundsOp = ComponentPeer.DEFAULT_OPERATION;
/**
* Enumeration of the common ways the baseline of a component can
* change as the size changes. The baseline resize behavior is
* primarily for layout managers that need to know how the
* position of the baseline changes as the component size changes.
* In general the baseline resize behavior will be valid for sizes
* greater than or equal to the minimum size (the actual minimum
* size; not a developer specified minimum size). For sizes
* smaller than the minimum size the baseline may change in a way
* other than the baseline resize behavior indicates. Similarly,
* as the size approaches {@code Integer.MAX_VALUE} and/or
* {@code Short.MAX_VALUE} the baseline may change in a way
* other than the baseline resize behavior indicates.
*
* @see #getBaselineResizeBehavior
* @see #getBaseline(int,int)
* @since 1.6
*/
public enum BaselineResizeBehavior {
/**
* Indicates the baseline remains fixed relative to the
* y-origin. That is, {@code getBaseline} returns
* the same value regardless of the height or width. For example, a
* {@code JLabel} containing non-empty text with a
* vertical alignment of {@code TOP} should have a
* baseline type of {@code CONSTANT_ASCENT}.
*/
CONSTANT_ASCENT,
/**
* Indicates the baseline remains fixed relative to the height
* and does not change as the width is varied. That is, for
* any height H the difference between H and
* {@code getBaseline(w, H)} is the same. For example, a
* {@code JLabel} containing non-empty text with a
* vertical alignment of {@code BOTTOM} should have a
* baseline type of {@code CONSTANT_DESCENT}.
*/
CONSTANT_DESCENT,
/**
* Indicates the baseline remains a fixed distance from
* the center of the component. That is, for any height H the
* difference between {@code getBaseline(w, H)} and
* {@code H / 2} is the same (plus or minus one depending upon
* rounding error).
* <p>
* Because of possible rounding errors it is recommended
* you ask for the baseline with two consecutive heights and use
* the return value to determine if you need to pad calculations
* by 1. The following shows how to calculate the baseline for
* any height:
* <pre>
* Dimension preferredSize = component.getPreferredSize();
* int baseline = getBaseline(preferredSize.width,
* preferredSize.height);
* int nextBaseline = getBaseline(preferredSize.width,
* preferredSize.height + 1);
* // Amount to add to height when calculating where baseline
* // lands for a particular height:
* int padding = 0;
* // Where the baseline is relative to the mid point
* int baselineOffset = baseline - height / 2;
* if (preferredSize.height % 2 == 0 &&
* baseline != nextBaseline) {
* padding = 1;
* }
* else if (preferredSize.height % 2 == 1 &&
* baseline == nextBaseline) {
* baselineOffset--;
* padding = 1;
* }
* // The following calculates where the baseline lands for
* // the height z:
* int calculatedBaseline = (z + padding) / 2 + baselineOffset;
* </pre>
*/
CENTER_OFFSET,
/**
* Indicates the baseline resize behavior can not be expressed using
* any of the other constants. This may also indicate the baseline
* varies with the width of the component. This is also returned
* by components that do not have a baseline.
*/
OTHER
}
/*
* The shape set with the applyCompoundShape() method. It includes the result
* of the HW/LW mixing related shape computation. It may also include
* the user-specified shape of the component.
* The 'null' value means the component has normal shape (or has no shape at all)
* and applyCompoundShape() will skip the following shape identical to normal.
*/
private transient Region compoundShape = null;
/*
* Represents the shape of this lightweight component to be cut out from
* heavyweight components should they intersect. Possible values:
* 1. null - consider the shape rectangular
* 2. EMPTY_REGION - nothing gets cut out (children still get cut out)
* 3. non-empty - this shape gets cut out.
*/
private transient Region mixingCutoutRegion = null;
/*
* Indicates whether addNotify() is complete
* (i.e. the peer is created).
*/
private transient boolean isAddNotifyComplete = false;
/**
* Should only be used in subclass getBounds to check that part of bounds
* is actually changing
*/
int getBoundsOp() {
assert Thread.holdsLock(getTreeLock());
return boundsOp;
}
void setBoundsOp(int op) {
assert Thread.holdsLock(getTreeLock());
if (op == ComponentPeer.RESET_OPERATION) {
boundsOp = ComponentPeer.DEFAULT_OPERATION;
} else
if (boundsOp == ComponentPeer.DEFAULT_OPERATION) {
boundsOp = op;
}
}
// Whether this Component has had the background erase flag
// specified via SunToolkit.disableBackgroundErase(). This is
// needed in order to make this function work on X11 platforms,
// where currently there is no chance to interpose on the creation
// of the peer and therefore the call to XSetBackground.
transient boolean backgroundEraseDisabled;
static {
AWTAccessor.setComponentAccessor(new AWTAccessor.ComponentAccessor() {
public void setBackgroundEraseDisabled(Component comp, boolean disabled) {
comp.backgroundEraseDisabled = disabled;
}
public boolean getBackgroundEraseDisabled(Component comp) {
return comp.backgroundEraseDisabled;
}
public Rectangle getBounds(Component comp) {
return new Rectangle(comp.x, comp.y, comp.width, comp.height);
}
public void setGraphicsConfiguration(Component comp,
GraphicsConfiguration gc)
{
comp.setGraphicsConfiguration(gc);
}
public void requestFocus(Component comp, FocusEvent.Cause cause) {
comp.requestFocus(cause);
}
public boolean canBeFocusOwner(Component comp) {
return comp.canBeFocusOwner();
}
public boolean isVisible(Component comp) {
return comp.isVisible_NoClientCode();
}
public void setRequestFocusController
(RequestFocusController requestController)
{
Component.setRequestFocusController(requestController);
}
public AppContext getAppContext(Component comp) {
return comp.appContext;
}
public void setAppContext(Component comp, AppContext appContext) {
comp.appContext = appContext;
}
public Container getParent(Component comp) {
return comp.getParent_NoClientCode();
}
public void setParent(Component comp, Container parent) {
comp.parent = parent;
}
public void setSize(Component comp, int width, int height) {
comp.width = width;
comp.height = height;
}
public Point getLocation(Component comp) {
return comp.location_NoClientCode();
}
public void setLocation(Component comp, int x, int y) {
comp.x = x;
comp.y = y;
}
public boolean isEnabled(Component comp) {
return comp.isEnabledImpl();
}
public boolean isDisplayable(Component comp) {
return comp.peer != null;
}
public Cursor getCursor(Component comp) {
return comp.getCursor_NoClientCode();
}
@SuppressWarnings("unchecked")
public <T extends ComponentPeer> T getPeer(Component comp) {
return (T) comp.peer;
}
public void setPeer(Component comp, ComponentPeer peer) {
comp.peer = peer;
}
public boolean isLightweight(Component comp) {
return (comp.peer instanceof LightweightPeer);
}
public boolean getIgnoreRepaint(Component comp) {
return comp.ignoreRepaint;
}
public int getWidth(Component comp) {
return comp.width;
}
public int getHeight(Component comp) {
return comp.height;
}
public int getX(Component comp) {
return comp.x;
}
public int getY(Component comp) {
return comp.y;
}
public Color getForeground(Component comp) {
return comp.foreground;
}
public Color getBackground(Component comp) {
return comp.background;
}
public void setBackground(Component comp, Color background) {
comp.background = background;
}
public Font getFont(Component comp) {
return comp.getFont_NoClientCode();
}
public void processEvent(Component comp, AWTEvent e) {
comp.processEvent(e);
}
@SuppressWarnings("removal")
public AccessControlContext getAccessControlContext(Component comp) {
return comp.getAccessControlContext();
}
public void revalidateSynchronously(Component comp) {
comp.revalidateSynchronously();
}
@Override
public void createBufferStrategy(Component comp, int numBuffers,
BufferCapabilities caps) throws AWTException {
comp.createBufferStrategy(numBuffers, caps);
}
@Override
public BufferStrategy getBufferStrategy(Component comp) {
return comp.getBufferStrategy();
}
});
}