-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWindow.java
More file actions
3510 lines (3289 loc) · 124 KB
/
Copy pathWindow.java
File metadata and controls
3510 lines (3289 loc) · 124 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
/*
* Some portions of this file have been modified by Robert Hanson hansonr.at.stolaf.edu 2012-2017
* for use in SwingJS via transpilation into JavaScript using Java2Script.
*
* Copyright (c) 1995, 2013, 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 jsjava.awt;
//import java.lang.ref.WeakReference;
//import java.lang.reflect.InvocationTargetException;
//import java.awt.AWTPermission;
//import java.awt.HeadlessException;
import java.awt.KeyboardFocusManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EventListener;
import java.util.Set;
import java.util.Vector;
import jsjava.applet.Applet;
import jsjava.awt.event.ComponentEvent;
import jsjava.awt.event.KeyEvent;
import jsjava.awt.event.MouseWheelEvent;
import jsjava.awt.event.WindowEvent;
import jsjava.awt.event.WindowFocusListener;
import jsjava.awt.event.WindowListener;
import jsjava.awt.event.WindowStateListener;
import jsjava.awt.peer.ComponentPeer;
import jsjava.awt.peer.WindowPeer;
import jsjava.beans.PropertyChangeListener;
import jsjava.util.Locale;
import jsjava.util.ResourceBundle;
import jsjavax.swing.JComponent;
import jsjavax.swing.JLayeredPane;
import jsjavax.swing.JRootPane;
import jsjavax.swing.RootPaneContainer;
import jssun.awt.AppContext;
import swingjs.JSToolkit;
//import java.util.concurrent.atomic.AtomicBoolean;
//import jsjava.util.logging.Logger;
/**
* A <code>Window</code> object is a top-level window with no borders and no
* menubar.
* The default layout for a window is <code>BorderLayout</code>.
* <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</code>
* on a different screen device by constructing the <code>Window</code>
* with {@link #Window(Window, GraphicsConfiguration)}. The
* <code>GraphicsConfiguration</code> object is one of the
* <code>GraphicsConfiguration</code> 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)."
* ALIGN=center HSPACE=10 VSPACE=7>
* <p>
* In such an environment, when calling <code>setLocation</code>,
* you must pass a virtual coordinate to this method. Similarly,
* calling <code>getLocationOnScreen</code> on a <code>Window</code> returns
* virtual device coordinates. Call the <code>getBounds</code> method
* of a <code>GraphicsConfiguration</code> to find its origin in the virtual
* coordinate system.
* <p>
* The following code sets the location of a <code>Window</code>
* at (10, 10) relative to the origin of the physical screen
* of the corresponding <code>GraphicsConfiguration</code>. If the
* bounds of the <code>GraphicsConfiguration</code> is not taken
* into account, the <code>Window</code> 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</code>.
*
* <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</code>s, <code>Frame</code>s, and <code>Dialog</code>s)
* are under the control of the desktop's window management system.
* Calls to <code>setLocation</code>, <code>setSize</code>, and
* <code>setBounds</code> 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</code> in a way
* that more closely matches the desktop settings.
* <p>
* Due to the asynchronous nature of native event handling, the results
* returned by <code>getBounds</code>, <code>getLocation</code>,
* <code>getLocationOnScreen</code>, and <code>getSize</code> 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 JDK1.0
*/
public class Window extends Container {
/**
* This represents the warning message that is
* to be displayed in a non secure window. ie :
* a window that has a security manager installed for
* which calling SecurityManager.checkTopLevelWindow()
* is false. This message can be displayed anywhere in
* the window.
*
* @serial
* @see #getWarningString
*/
String warningString;
/**
* {@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(List<? extends Image>)
*/
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;
boolean syncLWRequests = false;
transient boolean beforeFirstShow = true;
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;
/**
* A vector containing all the windows this
* window currently owns.
* @since 1.2
* @see #getOwnedWindows
*/
transient Vector<Window> ownedWindowList =
new Vector<Window>();
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;
// 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 transient 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;
/*
* Opacity level of the window
*
* @see #setOpacity(float)
* @see #getOpacity()
* @since 1.7
*/
private float opacity = 1.0f;
/*
* The shape assigned to this window. This field is set to null if
* no shape is set (rectangular window).
*
* @see #getShape()
* @see #setShape(Shape)
* @since 1.7
*/
private Shape shape = null;
private static final String base = "win";
private static int nameCounter = 0;
// /*
// * JDK 1.1 serialVersionUID
// */
// //private static final long serialVersionUID = 4497834738069338734L;
//
// private static final Logger log = Logger.getLogger("java.awt.Window");
// private static final boolean locationByPlatformProp;
transient boolean isTrayIconWindow = false;
/**
* Constructs a new, initially invisible window in the default size.
*
* <p>First, if there is a security manager, its
* <code>checkTopLevelWindow</code>
* method is called with <code>this</code>
* as its argument
* to see if it's ok to display the window without a warning banner.
* If the default implementation of <code>checkTopLevelWindow</code>
* is used (that is, that method is not overriden), then this results in
* a call to the security manager's <code>checkPermission</code> method
* with an <code>AWTPermission("showWindowWithoutWarningBanner")</code>
* permission. It that method raises a SecurityException,
* <code>checkTopLevelWindow</code> returns false, otherwise it
* returns true. If it returns false, a warning banner is created.
*
* @exception HeadlessException when
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see java.lang.SecurityManager#checkTopLevelWindow
*
*/
Window() {
//GraphicsEnvironment.checkHeadless();
initWinGC(null, null);
}
/**
* Constructs a new, initially invisible window in default size with the
* specified <code>GraphicsConfiguration</code>.
* <p>
* If there is a security manager, this method first calls
* the security manager's <code>checkTopLevelWindow</code>
* method with <code>this</code>
* as its argument to determine whether or not the window
* must be displayed with a warning banner.
*
* @param gc the <code>GraphicsConfiguration</code> of the target screen
* device. If <code>gc</code> is <code>null</code>, the system default
* <code>GraphicsConfiguration</code> is assumed
* @exception IllegalArgumentException if <code>gc</code>
* is not from a screen device
* @exception HeadlessException when
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see java.lang.SecurityManager#checkTopLevelWindow
*
*/
Window(GraphicsConfiguration gc) {
initWinGC(null, gc);
}
// /**
// * This was never ever any use, since Frame subclasses Window
// *
// * Constructs a new, initially invisible window with the specified
// * <code>Frame</code> as its owner. The window will not be focusable unless
// * its owner is showing on the screen.
// * <p>
// * If there is a security manager, this method first calls the security
// * manager's <code>checkTopLevelWindow</code> method with <code>this</code> as
// * its argument to determine whether or not the window must be displayed with
// * a warning banner.
// *
// * @param owner
// * the <code>Frame</code> to act as owner or <code>null</code> if
// * this window has no owner
// * @exception IllegalArgumentException
// * if the <code>owner</code>'s <code>GraphicsConfiguration</code>
// * is not from a screen device
// * @exception HeadlessException
// * when <code>GraphicsEnvironment.isHeadless</code> returns
// * <code>true</code>
// *
// * @see java.awt.GraphicsEnvironment#isHeadless
// * @see java.lang.SecurityManager#checkTopLevelWindow
// * @see #isShowing
// *
// */
// public Window(Frame owner) {
// this(owner, null);
// }
/**
* Constructs a new, initially invisible window with the specified
* <code>Window</code> as its owner. This window will not be focusable unless
* its nearest owning <code>Frame</code> or <code>Dialog</code> is showing on
* the screen.
* <p>
* If there is a security manager, this method first calls the security
* manager's <code>checkTopLevelWindow</code> method with <code>this</code> as
* its argument to determine whether or not the window must be displayed with
* a warning banner.
*
* @param owner
* the <code>Window</code> to act as owner or <code>null</code> if
* this window has no owner
* @exception IllegalArgumentException
* if the <code>owner</code>'s <code>GraphicsConfiguration</code>
* is not from a screen device
* @exception HeadlessException
* when <code>GraphicsEnvironment.isHeadless()</code> returns
* <code>true</code>
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see java.lang.SecurityManager#checkTopLevelWindow
* @see #isShowing
*
* @since 1.2
*
*/
public Window(Window owner) {
initWinGC(owner, null);
}
/**
* Constructs a new, initially invisible window with the specified owner
* <code>Window</code> and a <code>GraphicsConfiguration</code>
* of a screen device. The Window will not be focusable unless
* its nearest owning <code>Frame</code> or <code>Dialog</code>
* is showing on the screen.
* <p>
* If there is a security manager, this method first calls
* the security manager's <code>checkTopLevelWindow</code>
* method with <code>this</code>
* as its argument to determine whether or not the window
* must be displayed with a warning banner.
*
* @param owner the window to act as owner or <code>null</code>
* if this window has no owner
* @param gc the <code>GraphicsConfiguration</code> of the target
* screen device; if <code>gc</code> is <code>null</code>,
* the system default <code>GraphicsConfiguration</code> is assumed
* @exception IllegalArgumentException if <code>gc</code>
* is not from a screen device
* @exception HeadlessException when
* <code>GraphicsEnvironment.isHeadless()</code> returns
* <code>true</code>
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see java.lang.SecurityManager#checkTopLevelWindow
* @see GraphicsConfiguration#getBounds
* @see #isShowing
* @since 1.3
*
*/
public Window(Window owner, GraphicsConfiguration gc) {
// everything will pass through here, even Window(gc);
// We just adjust for the 1-parameter issue here
initWinGC(owner, gc);
}
/**
* The trick here is that with only one constructor, J2S will not check
* parameter types. Only the 1-parameter case is ambiguous.
*
* @param owner
* @param gc
*/
protected void initWinGC(Window owner, GraphicsConfiguration gc) {
setAppContext();
parent = owner;
if (owner != null)
owner.addOwnedWindow(this);
// GraphicsEnvironment.checkHeadless();
syncLWRequests = systemSyncLWRequests;
addToWindowList();
// setWarningString();
cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
visible = false;
// if (gc == null) {
// this.graphicsConfig =
// GraphicsEnvironment.getLocalGraphicsEnvironment().
// getDefaultScreenDevice().getDefaultConfiguration();
// } else {
// this.graphicsConfig = gc;
// }
// if (graphicsConfig.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 */
// SwingJS TODO ??
// Rectangle screenBounds = graphicsConfig.getBounds();
// Insets screenInsets = getToolkit().getScreenInsets(graphicsConfig);
// 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;
// sun.java2d.Disposer.addRecord(anchor, new
// WindowDisposerRecord(appContext, this));
}
// transient Object anchor = new Object();
// static class WindowDisposerRecord implements jssun.java2d.DisposerRecord {
// final WeakReference<Window> owner;
// final WeakReference weakThis;
// final AppContext context;
// WindowDisposerRecord(AppContext context, Window victim) {
// owner = new WeakReference<Window>(victim.getOwner());
// weakThis = victim.weakThis;
// this.context = context;
// }
// public void dispose() {
// Window parent = owner.get();
// if (parent != null) {
// parent.removeOwnedWindow(weakThis);
// }
// Window.removeFromWindowList(context, weakThis);
// }
// }
//
/**
* Construct a name for this component. Called by getName() when the
* name is null.
*/
@Override
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 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 platfrom-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
firePropertyChangeObject("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 JDK1.0
*/
@Override
public void addNotify() {
Container parent = this.parent;
if (parent != null && parent.getPeer() == null)
parent.addNotify();
getOrCreatePeer();
JSToolkit.getAppletViewer().addWindow(this);
super.addNotify();
}
@Override
protected ComponentPeer getOrCreatePeer() {
return (ui == null ? null : peer == null ? (peer = getToolkit().createWindow(this)) : peer);
}
/**
* {@inheritDoc}
*/
@Override
public void removeNotify() {
JSToolkit.getAppletViewer().allWindows.removeObj(this);
super.removeNotify();
}
/**
* Causes this Window to be sized to fit the preferred size
* and layouts of its subcomponents. If the window and/or its owner
* are not yet displayable, both are made displayable before
* calculating the preferred size. The Window will be validated
* after the preferredSize is calculated.
* @see Component#isDisplayable
*/
public void pack() {
Container parent = this.parent;
if (parent != null && parent.getPeer() == null) {
parent.addNotify();
}
if (peer == null) {
addNotify();
}
if(beforeFirstShow) {
isPacked = true;
}
repackContainer();
}
/**
* 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 specified by {@code setMinimumSize} the window
* is automatically enlarged to honor the {@code minimumSize}
* value. Setting the minimum size to {@code null} restores
* the default behavior.
* <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)
* @since 1.6
*/
@Override
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}.
*
* @see #getSize
* @see #setBounds
* @see #setMinimumSize
* @since 1.6
*/
@Override
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}.
*
* @see #getSize
* @see #setBounds
* @see #setMinimumSize
* @since 1.6
*/
@Override
public void setSize(int width, int height) {
super.setSize(width, height);
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>setBounds(int, int, int, int)</code>.
*/
@Override
@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);
}
// static private final AtomicBoolean
// beforeFirstWindowShown = new AtomicBoolean(true);
//
static final void closeSplashScreen() {
// if (beforeFirstWindowShown.getAndSet(false)) {
// SunToolkit.closeSplashScreen();
// }
}
/**
* Shows or hides this {@code Window} depending on the value of parameter
* {@code b}.
* @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
*/
@Override
public void setVisible(boolean b) {
super.setVisible(b);
if (b)
repaint(); // BH SwingJS needs this, because there is no system event set to do this.
}
/**
* Makes the Window visible. If the Window and/or its owner
* are not yet displayable, both are made displayable. The
* Window will be validated prior to being made visible.
* If the Window is already visible, this will bring the Window
* to the front.
* @see Component#isDisplayable
* @see #toFront
* @deprecated As of JDK version 1.5, replaced by
* {@link #setVisible(boolean)}.
*/
@Override
@Deprecated
public void show() {
// if (peer == null) {
// addNotify();
// }
validate();
isInShow = true;
if (visible) {
toFront();
} else {
beforeFirstShow = false;
closeSplashScreen();
// Dialog.checkShouldBeBlocked(this);
super.show();
// locationByPlatform = false;
for (int i = 0; i < ownedWindowList.size(); i++) {
Window child = ownedWindowList.elementAt(i);
if ((child != null) && child.showWithParent) {
child.show();
child.showWithParent = false;
} // endif
} // endfor
if (!isModalBlocked()) {
updateChildrenBlocking();
} else {
// fix for 6532736: after this window is shown, its blocker
// should be raised to front
modalBlocker.toFront_NoClientCode();
}
if (this instanceof Frame || this instanceof Dialog) {
updateChildFocusableWindowState(this);
}
}
isInShow = false;
// If first time shown, generate WindowOpened event
if ((state & OPENED) == 0) {
postWindowEvent(WindowEvent.WINDOW_OPENED);
state |= OPENED;
}
}
static void updateChildFocusableWindowState(Window w) {
// if (w.getPeer() != null && w.isShowing()) {
// ((WindowPeer)w.getPeer()).updateFocusableWindowState();
// }
for (int i = 0; i < w.ownedWindowList.size(); i++) {
Window child = w.ownedWindowList.elementAt(i);
if (child != null) {
updateChildFocusableWindowState(child);
}
}
}
synchronized void postWindowEvent(int id) {
if (windowListener != null
|| (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0
|| Toolkit.enabledOnToolkit(AWTEvent.WINDOW_EVENT_MASK)) {
WindowEvent e = new WindowEvent(this, id);
Toolkit.getEventQueue().postEvent(e);
}
}
/**
* Hide this Window, its subcomponents, and all of its owned children.
* The Window and its subcomponents can be made visible again
* with a call to {@code show}.
* </p>
* @see #show
* @see #dispose
* @deprecated As of JDK version 1.5, replaced by
* {@link #setVisible(boolean)}.
*/
@Override
@Deprecated
public void hide() {
synchronized(ownedWindowList) {
for (int i = 0; i < ownedWindowList.size(); i++) {
Window child = ownedWindowList.elementAt(i);
if ((child != null) && child.visible) {
child.hide();
child.showWithParent = true;
}
}
}
// if (isModalBlocked()) {
// modalBlocker.unblockWindow(this);
// }
super.hide();
}
@Override
final void clearMostRecentFocusOwnerOnHide() {
/* do nothing */
}
/**
* Releases all of the native screen resources used by this
* <code>Window</code>, its subcomponents, and all of its owned
* children. That is, the resources for these <code>Component</code>s
* will be destroyed, any memory they consume will be returned to the
* OS, and they will be marked as undisplayable.
* <p>
* The <code>Window</code> and its subcomponents can be made displayable
* again by rebuilding the native resources with a subsequent call to
* <code>pack</code> or <code>show</code>. The states of the recreated
* <code>Window</code> and its subcomponents will be identical to the
* states of these objects at the point where the <code>Window</code>
* was disposed (not accounting for additional modifications between
* those actions).
* <p>
* <b>Note</b>: When the last displayable window
* within the Java virtual machine (VM) is disposed of, the VM may
* terminate. See <a href="doc-files/AWTThreadIssues.html#Autoshutdown">
* AWT Threading Issues</a> for more information.
* @see Component#isDisplayable
* @see #pack
* @see #show
*/
public void dispose() {
doDispose();
}
/*
* Fix for 4872170.
* If dispose() is called on parent then its children have to be disposed as well
* as reported in javadoc. So we need to implement this functionality even if a
* child overrides dispose() in a wrong way without calling super.dispose().
*/
void disposeImpl() {
dispose();
// if (getPeer() != null) {
// doDispose();
// }
}
void doDispose() {
final Component me = this;
Runnable action = new Runnable() {
@Override
public void run() {
((JComponent) me).getUI().uninstallUI(null);
// Check if this window is the fullscreen window for the
// device. Exit the fullscreen mode prior to disposing