-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathWindow.java
More file actions
4465 lines (4123 loc) · 165 KB
/
Window.java
File metadata and controls
4465 lines (4123 loc) · 165 KB
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, 2025, 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.awt.event.ComponentEvent;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.geom.Path2D;
import java.awt.im.InputContext;
import java.awt.image.BufferStrategy;
import java.awt.peer.ComponentPeer;
import java.awt.peer.WindowPeer;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OptionalDataException;
import java.io.PrintStream;
import java.io.Serial;
import java.io.Serializable;
import java.lang.annotation.Native;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EventListener;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleState;
import javax.accessibility.AccessibleStateSet;
import com.jetbrains.exported.JBRApi;
import jdk.internal.misc.InnocuousThread;
import sun.awt.AWTAccessor;
import sun.awt.AppContext;
import sun.awt.DebugSettings;
import sun.awt.SunToolkit;
import sun.awt.util.IdentityArrayList;
import sun.awt.util.ThreadGroupUtils;
import sun.java2d.marlin.stats.StatDouble;
import sun.java2d.pipe.Region;
import sun.util.logging.PlatformLogger;
/**
* A {@code Window} object is a top-level window with no borders and no
* menubar.
* The default layout for a window is {@code BorderLayout}.
* <p>
* A window must have either a frame, dialog, or another window defined as its
* owner when it's constructed.
* <p>
* In a multi-screen environment, you can create a {@code Window}
* on a different screen device by constructing the {@code Window}
* with {@link #Window(Window, GraphicsConfiguration)}. The
* {@code GraphicsConfiguration} object is one of the
* {@code GraphicsConfiguration} objects of the target screen device.
* <p>
* In a virtual device multi-screen environment in which the desktop
* area could span multiple physical screen devices, the bounds of all
* configurations are relative to the virtual device coordinate system.
* The origin of the virtual-coordinate system is at the upper left-hand
* corner of the primary physical screen. Depending on the location of
* the primary screen in the virtual device, negative coordinates are
* possible, as shown in the following figure.
* <p>
* <img src="doc-files/MultiScreen.gif"
* alt="Diagram shows virtual device containing 4 physical screens. Primary
* physical screen shows coords (0,0), other screen shows (-80,-100)."
* style="margin: 7px 10px;">
* <p>
* In such an environment, when calling {@code setLocation},
* you must pass a virtual coordinate to this method. Similarly,
* calling {@code getLocationOnScreen} on a {@code Window} returns
* virtual device coordinates. Call the {@code getBounds} method
* of a {@code GraphicsConfiguration} to find its origin in the virtual
* coordinate system.
* <p>
* The following code sets the location of a {@code Window}
* at (10, 10) relative to the origin of the physical screen
* of the corresponding {@code GraphicsConfiguration}. If the
* bounds of the {@code GraphicsConfiguration} is not taken
* into account, the {@code Window} location would be set
* at (10, 10) relative to the virtual-coordinate system and would appear
* on the primary physical screen, which might be different from the
* physical screen of the specified {@code GraphicsConfiguration}.
*
* <pre>
* Window w = new Window(Window owner, GraphicsConfiguration gc);
* Rectangle bounds = gc.getBounds();
* w.setLocation(10 + bounds.x, 10 + bounds.y);
* </pre>
*
* <p>
* Note: the location and size of top-level windows (including
* {@code Window}s, {@code Frame}s, and {@code Dialog}s)
* are under the control of the desktop's window management system.
* Calls to {@code setLocation}, {@code setSize}, and
* {@code setBounds} are requests (not directives) which are
* forwarded to the window management system. Every effort will be
* made to honor such requests. However, in some cases the window
* management system may ignore such requests, or modify the requested
* geometry in order to place and size the {@code Window} in a way
* that more closely matches the desktop settings.
* <p>
* Visual effects such as halos, shadows, motion effects and animations may be
* applied to the window by the desktop window management system. These are
* outside the knowledge and control of the AWT and so for the purposes of this
* specification are not considered part of the top-level window.
* <p>
* Due to the asynchronous nature of native event handling, the results
* returned by {@code getBounds}, {@code getLocation},
* {@code getLocationOnScreen}, and {@code getSize} might not
* reflect the actual geometry of the Window on screen until the last
* request has been processed. During the processing of subsequent
* requests these values might change accordingly while the window
* management system fulfills the requests.
* <p>
* An application may set the size and location of an invisible
* {@code Window} arbitrarily, but the window management system may
* subsequently change its size and/or location when the
* {@code Window} is made visible. One or more {@code ComponentEvent}s
* will be generated to indicate the new geometry.
* <p>
* Windows are capable of generating the following WindowEvents:
* WindowOpened, WindowClosed, WindowGainedFocus, WindowLostFocus.
*
* @author Sami Shaio
* @author Arthur van Hoff
* @see WindowEvent
* @see #addWindowListener
* @see java.awt.BorderLayout
* @since 1.0
*/
public class Window extends Container implements Accessible {
/**
* Enumeration of available <i>window types</i>.
*
* A window type defines the generic visual appearance and behavior of a
* top-level window. For example, the type may affect the kind of
* decorations of a decorated {@code Frame} or {@code Dialog} instance.
* <p>
* Some platforms may not fully support a certain window type. Depending on
* the level of support, some properties of the window type may be
* disobeyed.
*
* @see #getType
* @see #setType
* @since 1.7
*/
public static enum Type {
/**
* Represents a <i>normal</i> window.
*
* This is the default type for objects of the {@code Window} class or
* its descendants. Use this type for regular top-level windows.
*/
NORMAL,
/**
* Represents a <i>utility</i> window.
*
* A utility window is usually a small window such as a toolbar or a
* palette. The native system may render the window with smaller
* title-bar if the window is either a {@code Frame} or a {@code
* Dialog} object, and if it has its decorations enabled.
*/
UTILITY,
/**
* Represents a <i>popup</i> window.
*
* A popup window is a temporary window such as a drop-down menu or a
* tooltip. On some platforms, windows of that type may be forcibly
* made undecorated even if they are instances of the {@code Frame} or
* {@code Dialog} class, and have decorations enabled.
*/
POPUP
}
/**
* {@code icons} is the graphical way we can
* represent the frames and dialogs.
* {@code Window} can't display icon but it's
* being inherited by owned {@code Dialog}s.
*
* @serial
* @see #getIconImages
* @see #setIconImages
*/
transient java.util.List<Image> icons;
/**
* Holds the reference to the component which last had focus in this window
* before it lost focus.
*/
private transient Component temporaryLostComponent;
static boolean systemSyncLWRequests = false;
/**
* @serial Focus transfers should be synchronous for lightweight component requests.
*/
boolean syncLWRequests = false;
transient boolean beforeFirstShow = true;
private transient boolean disposing = false;
transient WindowDisposerRecord disposerRecord = null;
static final int OPENED = 0x01;
/**
* An Integer value representing the Window State.
*
* @serial
* @since 1.2
* @see #show
*/
int state;
/**
* A boolean value representing Window always-on-top state
* @since 1.5
* @serial
* @see #setAlwaysOnTop
* @see #isAlwaysOnTop
*/
private boolean alwaysOnTop;
/**
* Contains all the windows that have a peer object associated,
* i. e. between addNotify() and removeNotify() calls. The list
* of all Window instances can be obtained from AppContext object.
*
* @since 1.6
*/
private static final IdentityArrayList<Window> allWindows = new IdentityArrayList<Window>();
/**
* A vector containing all the windows this
* window currently owns.
* @since 1.2
* @see #getOwnedWindows
*/
transient Vector<WeakReference<Window>> ownedWindowList =
new Vector<WeakReference<Window>>();
/*
* We insert a weak reference into the Vector of all Windows in AppContext
* instead of 'this' so that garbage collection can still take place
* correctly.
*/
private transient WeakReference<Window> weakThis;
transient boolean showWithParent;
/**
* Contains the modal dialog that blocks this window, or null
* if the window is unblocked.
*
* @since 1.6
*/
transient Dialog modalBlocker;
/**
* @serial
*
* @see java.awt.Dialog.ModalExclusionType
* @see #getModalExclusionType
* @see #setModalExclusionType
*
* @since 1.6
*/
Dialog.ModalExclusionType modalExclusionType;
transient WindowListener windowListener;
transient WindowStateListener windowStateListener;
transient WindowFocusListener windowFocusListener;
transient InputContext inputContext;
private transient Object inputContextLock = new Object();
/**
* Unused. Maintained for serialization backward-compatibility.
*
* @serial
* @since 1.2
*/
private FocusManager focusMgr;
/**
* Indicates whether this Window can become the focused Window.
*
* @serial
* @see #getFocusableWindowState
* @see #setFocusableWindowState
* @since 1.4
*/
private boolean focusableWindowState = true;
/**
* Indicates whether this window should receive focus on
* subsequently being shown (with a call to {@code setVisible(true)}), or
* being moved to the front (with a call to {@code toFront()}).
*
* @serial
* @see #setAutoRequestFocus
* @see #isAutoRequestFocus
* @since 1.7
*/
private volatile boolean autoRequestFocus = true;
/*
* Indicates that this window is being shown. This flag is set to true at
* the beginning of show() and to false at the end of show().
*
* @see #show()
* @see Dialog#shouldBlock
*/
transient boolean isInShow = false;
/**
* The opacity level of the window
*
* @serial
* @see #setOpacity(float)
* @see #getOpacity()
* @since 1.7
*/
private volatile float opacity = 1.0f;
/**
* The shape assigned to this window. This field is set to {@code null} if
* no shape is set (rectangular window).
*
* @serial
* @see #getShape()
* @see #setShape(Shape)
* @since 1.7
*/
@SuppressWarnings("serial") // Not statically typed as Serializable
private Shape shape = null;
/**
* For popup windows, the component that the popup
* "must intersect with or be at least partially adjacent to".
*/
private Component popupParent = null;
private static final String base = "win";
private static int nameCounter = 0;
/**
* Use serialVersionUID from JDK 1.1 for interoperability.
*/
@Serial
private static final long serialVersionUID = 4497834738069338734L;
private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Window");
private static final PlatformLogger focusRequestLog = PlatformLogger.getLogger("jb.focus.requests");
private static final PlatformLogger perfLog = PlatformLogger.getLogger("awt.window.counters");
private static final boolean locationByPlatformProp;
transient boolean isTrayIconWindow = false;
static {
/* ensure that the necessary native libraries are loaded */
Toolkit.loadLibraries();
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
String s = System.getProperty("java.awt.syncLWRequests");
systemSyncLWRequests = "true".equals(s);
String s2 = System.getProperty("java.awt.Window.locationByPlatform");
locationByPlatformProp = "true".equals(s2);
}
/**
* Initialize JNI field and method IDs for fields that may be
accessed from C.
*/
private static native void initIDs();
/**
* Constructs a new, initially invisible window in default size with the
* specified {@code GraphicsConfiguration}.
* <p>
*
* @param gc the {@code GraphicsConfiguration} of the target screen
* device. If {@code gc} is {@code null}, the system default
* {@code GraphicsConfiguration} is assumed
* @throws IllegalArgumentException if {@code gc}
* is not from a screen device
* @throws HeadlessException when
* {@code GraphicsEnvironment.isHeadless()} returns {@code true}
*
* @see java.awt.GraphicsEnvironment#isHeadless
*/
Window(GraphicsConfiguration gc) {
init(gc);
}
transient Object anchor = new Object();
static class WindowDisposerRecord implements sun.java2d.DisposerRecord {
WeakReference<Window> owner;
final WeakReference<Window> weakThis;
final WeakReference<AppContext> context;
WindowDisposerRecord(AppContext context, Window victim) {
weakThis = victim.weakThis;
this.context = new WeakReference<AppContext>(context);
}
public void updateOwner() {
Window victim = weakThis.get();
owner = (victim == null)
? null
: new WeakReference<Window>(victim.getOwner());
}
public void dispose() {
if (owner != null) {
Window parent = owner.get();
if (parent != null) {
parent.removeOwnedWindow(weakThis);
}
}
AppContext ac = context.get();
if (null != ac) {
Window.removeFromWindowList(ac, weakThis);
}
}
}
private GraphicsConfiguration initGC(GraphicsConfiguration gc) {
GraphicsEnvironment.checkHeadless();
if (gc == null) {
gc = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
}
setGraphicsConfiguration(gc);
return gc;
}
private void init(GraphicsConfiguration gc) {
GraphicsEnvironment.checkHeadless();
syncLWRequests = systemSyncLWRequests;
weakThis = new WeakReference<Window>(this);
addToWindowList();
this.cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
this.visible = false;
gc = initGC(gc);
if (gc.getDevice().getType() !=
GraphicsDevice.TYPE_RASTER_SCREEN) {
throw new IllegalArgumentException("not a screen device");
}
setLayout(new BorderLayout());
/* offset the initial location with the original of the screen */
/* and any insets */
Rectangle screenBounds = gc.getBounds();
Insets screenInsets = getToolkit().getScreenInsets(gc);
int x = getX() + screenBounds.x + screenInsets.left;
int y = getY() + screenBounds.y + screenInsets.top;
if (x != this.x || y != this.y) {
setLocation(x, y);
/* reset after setLocation */
setLocationByPlatform(locationByPlatformProp);
}
modalExclusionType = Dialog.ModalExclusionType.NO_EXCLUDE;
disposerRecord = new WindowDisposerRecord(appContext, this);
sun.java2d.Disposer.addRecord(anchor, disposerRecord);
SunToolkit.checkAndSetPolicy(this);
}
/**
* Constructs a new, initially invisible window in the default size.
* <p>
*
* @throws HeadlessException when
* {@code GraphicsEnvironment.isHeadless()} returns {@code true}
*
* @see java.awt.GraphicsEnvironment#isHeadless
*/
Window() throws HeadlessException {
GraphicsEnvironment.checkHeadless();
init((GraphicsConfiguration)null);
}
/**
* Constructs a new, initially invisible window with the specified
* {@code Frame} as its owner. The window will not be focusable
* unless its owner is showing on the screen.
*
* @param owner the {@code Frame} to act as owner or {@code null}
* if this window has no owner
* @throws IllegalArgumentException if the {@code owner}'s
* {@code GraphicsConfiguration} is not from a screen device
* @throws HeadlessException when
* {@code GraphicsEnvironment.isHeadless} returns {@code true}
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #isShowing
*/
public Window(Frame owner) {
this(owner == null ? (GraphicsConfiguration)null :
owner.getGraphicsConfiguration());
ownedInit(owner);
}
/**
* Constructs a new, initially invisible window with the specified
* {@code Window} as its owner. This window will not be focusable
* unless its nearest owning {@code Frame} or {@code Dialog}
* is showing on the screen.
*
* @param owner the {@code Window} to act as owner or
* {@code null} if this window has no owner
* @throws IllegalArgumentException if the {@code owner}'s
* {@code GraphicsConfiguration} is not from a screen device
* @throws HeadlessException when
* {@code GraphicsEnvironment.isHeadless()} returns
* {@code true}
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #isShowing
*
* @since 1.2
*/
public Window(Window owner) {
this(owner == null ? (GraphicsConfiguration)null :
owner.getGraphicsConfiguration());
ownedInit(owner);
}
/**
* Constructs a new, initially invisible window with the specified owner
* {@code Window} and a {@code GraphicsConfiguration}
* of a screen device. The Window will not be focusable unless
* its nearest owning {@code Frame} or {@code Dialog}
* is showing on the screen.
*
* @param owner the window to act as owner or {@code null}
* if this window has no owner
* @param gc the {@code GraphicsConfiguration} of the target
* screen device; if {@code gc} is {@code null},
* the system default {@code GraphicsConfiguration} is assumed
* @throws IllegalArgumentException if {@code gc}
* is not from a screen device
* @throws HeadlessException when
* {@code GraphicsEnvironment.isHeadless()} returns
* {@code true}
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see GraphicsConfiguration#getBounds
* @see #isShowing
* @since 1.3
*/
public Window(Window owner, GraphicsConfiguration gc) {
this(gc);
ownedInit(owner);
}
private void ownedInit(Window owner) {
this.parent = owner;
if (owner != null) {
owner.addOwnedWindow(weakThis);
if (owner.isAlwaysOnTop()) {
setAlwaysOnTop(true);
}
}
// WindowDisposerRecord requires a proper value of parent field.
disposerRecord.updateOwner();
}
/**
* Construct a name for this component. Called by getName() when the
* name is null.
*/
String constructComponentName() {
synchronized (Window.class) {
return base + nameCounter++;
}
}
/**
* Returns the sequence of images to be displayed as the icon for this window.
* <p>
* This method returns a copy of the internally stored list, so all operations
* on the returned object will not affect the window's behavior.
*
* @return the copy of icon images' list for this window, or
* empty list if this window doesn't have icon images.
* @see #setIconImages
* @see #setIconImage(Image)
* @since 1.6
*/
public java.util.List<Image> getIconImages() {
java.util.List<Image> icons = this.icons;
if (icons == null || icons.size() == 0) {
return new ArrayList<Image>();
}
return new ArrayList<Image>(icons);
}
/**
* Sets the sequence of images to be displayed as the icon
* for this window. Subsequent calls to {@code getIconImages} will
* always return a copy of the {@code icons} list.
* <p>
* Depending on the platform capabilities one or several images
* of different dimensions will be used as the window's icon.
* <p>
* The {@code icons} list can contain {@code MultiResolutionImage} images also.
* Suitable image depending on screen resolution is extracted from
* base {@code MultiResolutionImage} image and added to the icons list
* while base resolution image is removed from list.
* The {@code icons} list is scanned for the images of most
* appropriate dimensions from the beginning. If the list contains
* several images of the same size, the first will be used.
* <p>
* Ownerless windows with no icon specified use platform-default icon.
* The icon of an owned window may be inherited from the owner
* unless explicitly overridden.
* Setting the icon to {@code null} or empty list restores
* the default behavior.
* <p>
* Note : Native windowing systems may use different images of differing
* dimensions to represent a window, depending on the context (e.g.
* window decoration, window list, taskbar, etc.). They could also use
* just a single image for all contexts or no image at all.
*
* @param icons the list of icon images to be displayed.
* @see #getIconImages()
* @see #setIconImage(Image)
* @since 1.6
*/
public synchronized void setIconImages(java.util.List<? extends Image> icons) {
this.icons = (icons == null) ? new ArrayList<Image>() :
new ArrayList<Image>(icons);
WindowPeer peer = (WindowPeer)this.peer;
if (peer != null) {
peer.updateIconImages();
}
// Always send a property change event
firePropertyChange("iconImage", null, null);
}
/**
* Sets the image to be displayed as the icon for this window.
* <p>
* This method can be used instead of {@link #setIconImages setIconImages()}
* to specify a single image as a window's icon.
* <p>
* The following statement:
* <pre>
* setIconImage(image);
* </pre>
* is equivalent to:
* <pre>
* ArrayList<Image> imageList = new ArrayList<Image>();
* imageList.add(image);
* setIconImages(imageList);
* </pre>
* <p>
* Note : Native windowing systems may use different images of differing
* dimensions to represent a window, depending on the context (e.g.
* window decoration, window list, taskbar, etc.). They could also use
* just a single image for all contexts or no image at all.
*
* @param image the icon image to be displayed.
* @see #setIconImages
* @see #getIconImages()
* @since 1.6
*/
public void setIconImage(Image image) {
ArrayList<Image> imageList = new ArrayList<Image>();
if (image != null) {
imageList.add(image);
}
setIconImages(imageList);
}
/**
* Makes this Window displayable by creating the connection to its
* native screen resource.
* This method is called internally by the toolkit and should
* not be called directly by programs.
* @see Component#isDisplayable
* @see Container#removeNotify
* @since 1.0
*/
public void addNotify() {
synchronized (getTreeLock()) {
Container parent = this.parent;
if (parent != null && parent.peer == null) {
parent.addNotify();
}
if (peer == null) {
peer = getComponentFactory().createWindow(this);
}
synchronized (allWindows) {
allWindows.add(this);
}
super.addNotify();
}
}
/**
* {@inheritDoc}
*/
public void removeNotify() {
synchronized (getTreeLock()) {
synchronized (allWindows) {
allWindows.remove(this);
}
super.removeNotify();
}
}
/**
* Causes this Window to be sized to fit the preferred size
* and layouts of its subcomponents. The resulting width and
* height of the window are automatically enlarged if either
* of dimensions is less than the minimum size as specified
* by the previous call to the {@code setMinimumSize} method.
* <p>
* If the window and/or its owner are not displayable yet,
* both of them are made displayable before calculating
* the preferred size. The Window is validated after its
* size is being calculated.
*
* @see Component#isDisplayable
* @see #setMinimumSize
*/
public void pack() {
Container parent = this.parent;
if (parent != null && parent.peer == null) {
parent.addNotify();
}
if (peer == null) {
addNotify();
}
Dimension newSize = getPreferredSize();
if (peer != null) {
setClientSize(newSize.width, newSize.height);
}
if(beforeFirstShow) {
isPacked = true;
}
validateUnconditionally();
}
/**
* Sets the minimum size of this window to a constant
* value. Subsequent calls to {@code getMinimumSize}
* will always return this value. If current window's
* size is less than {@code minimumSize} the size of the
* window is automatically enlarged to honor the minimum size.
* <p>
* If the {@code setSize} or {@code setBounds} methods
* are called afterwards with a width or height less than
* that was specified by the {@code setMinimumSize} method
* the window is automatically enlarged to meet
* the {@code minimumSize} value. The {@code minimumSize}
* value also affects the behaviour of the {@code pack} method.
* <p>
* The default behavior is restored by setting the minimum size
* parameter to the {@code null} value.
* <p>
* Resizing operation may be restricted if the user tries
* to resize window below the {@code minimumSize} value.
* This behaviour is platform-dependent.
*
* @param minimumSize the new minimum size of this window
* @see Component#setMinimumSize
* @see #getMinimumSize
* @see #isMinimumSizeSet
* @see #setSize(Dimension)
* @see #pack
* @since 1.6
*/
public void setMinimumSize(Dimension minimumSize) {
synchronized (getTreeLock()) {
super.setMinimumSize(minimumSize);
Dimension size = getSize();
if (isMinimumSizeSet()) {
if (size.width < minimumSize.width || size.height < minimumSize.height) {
int nw = Math.max(width, minimumSize.width);
int nh = Math.max(height, minimumSize.height);
setSize(nw, nh);
}
}
if (peer != null) {
((WindowPeer)peer).updateMinimumSize();
}
}
}
/**
* {@inheritDoc}
* <p>
* The {@code d.width} and {@code d.height} values
* are automatically enlarged if either is less than
* the minimum size as specified by previous call to
* {@code setMinimumSize}.
* <p>
* The method changes the geometry-related data. Therefore,
* the native windowing system may ignore such requests, or it may modify
* the requested data, so that the {@code Window} object is placed and sized
* in a way that corresponds closely to the desktop settings.
*
* @see #getSize
* @see #setBounds
* @see #setMinimumSize
* @since 1.6
*/
public void setSize(Dimension d) {
super.setSize(d);
}
/**
* {@inheritDoc}
* <p>
* The {@code width} and {@code height} values
* are automatically enlarged if either is less than
* the minimum size as specified by previous call to
* {@code setMinimumSize}.
* <p>
* The method changes the geometry-related data. Therefore,
* the native windowing system may ignore such requests, or it may modify
* the requested data, so that the {@code Window} object is placed and sized
* in a way that corresponds closely to the desktop settings.
*
* @see #getSize
* @see #setBounds
* @see #setMinimumSize
* @since 1.6
*/
public void setSize(int width, int height) {
super.setSize(width, height);
}
/**
* {@inheritDoc}
* <p>
* The method changes the geometry-related data. Therefore,
* the native windowing system may ignore such requests, or it may modify
* the requested data, so that the {@code Window} object is placed and sized
* in a way that corresponds closely to the desktop settings.
*/
@Override
public void setLocation(int x, int y) {
super.setLocation(x, y);
}
/**
* {@inheritDoc}
* <p>
* The method changes the geometry-related data. Therefore,
* the native windowing system may ignore such requests, or it may modify
* the requested data, so that the {@code Window} object is placed and sized
* in a way that corresponds closely to the desktop settings.
*/
@Override
public void setLocation(Point p) {
super.setLocation(p);
}
/**
* @deprecated As of JDK version 1.1,
* replaced by {@code setBounds(int, int, int, int)}.
*/
@Deprecated
public void reshape(int x, int y, int width, int height) {
if (isMinimumSizeSet()) {
Dimension minSize = getMinimumSize();
if (width < minSize.width) {
width = minSize.width;
}
if (height < minSize.height) {
height = minSize.height;
}
}
super.reshape(x, y, width, height);
}
void setClientSize(int w, int h) {
synchronized (getTreeLock()) {
setBoundsOp(ComponentPeer.SET_CLIENT_SIZE);
setBounds(x, y, w, h);
}
}
private static final AtomicBoolean
beforeFirstWindowShown = new AtomicBoolean(true);
final void closeSplashScreen() {
if (isTrayIconWindow) {
return;
}
if (beforeFirstWindowShown.getAndSet(false)) {
// We don't use SplashScreen.getSplashScreen() to avoid instantiating
// the object if it hasn't been requested by user code explicitly
SunToolkit.closeSplashScreen();
SplashScreen.markClosed();
}
}
/**
* Shows or hides this {@code Window} depending on the value of parameter
* {@code b}.
* <p>
* If the method shows the window then the window is also made
* focused under the following conditions:
* <ul>
* <li> The {@code Window} meets the requirements outlined in the
* {@link #isFocusableWindow} method.
* <li> The {@code Window}'s {@code autoRequestFocus} property is of the {@code true} value.
* <li> Native windowing system allows the {@code Window} to get focused.
* </ul>
* There is an exception for the second condition (the value of the
* {@code autoRequestFocus} property). The property is not taken into account if the
* window is a modal dialog, which blocks the currently focused window.
* <p>
* Developers must never assume that the window is the focused or active window
* until it receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event.
* @param b if {@code true}, makes the {@code Window} visible,
* otherwise hides the {@code Window}.
* If the {@code Window} and/or its owner
* are not yet displayable, both are made displayable. The
* {@code Window} will be validated prior to being made visible.
* If the {@code Window} is already visible, this will bring the
* {@code Window} to the front.<p>
* If {@code false}, hides this {@code Window}, its subcomponents, and all
* of its owned children.
* The {@code Window} and its subcomponents can be made visible again
* with a call to {@code #setVisible(true)}.
* @see java.awt.Component#isDisplayable
* @see java.awt.Component#setVisible
* @see java.awt.Window#toFront
* @see java.awt.Window#dispose
* @see java.awt.Window#setAutoRequestFocus
* @see java.awt.Window#isFocusableWindow
*/