src/share/classes/java/awt/Window.java

Print this page




 747      * both of them are made displayable before calculating
 748      * the preferred size. The Window is validated after its
 749      * size is being calculated.
 750      *
 751      * @see Component#isDisplayable
 752      * @see #setMinimumSize
 753      */
 754     public void pack() {
 755         Container parent = this.parent;
 756         if (parent != null && parent.getPeer() == null) {
 757             parent.addNotify();
 758         }
 759         if (peer == null) {
 760             addNotify();
 761         }
 762         Dimension newSize = getPreferredSize();
 763         if (peer != null) {
 764             setClientSize(newSize.width, newSize.height);
 765         }
 766 
 767         if(beforeFirstShow) {
 768             isPacked = true;
 769         }
 770 
 771         validate();
 772     }
 773 
 774     /**
 775      * Sets the minimum size of this window to a constant
 776      * value.  Subsequent calls to {@code getMinimumSize}
 777      * will always return this value. If current window's
 778      * size is less than {@code minimumSize} the size of the
 779      * window is automatically enlarged to honor the minimum size.
 780      * <p>
 781      * If the {@code setSize} or {@code setBounds} methods
 782      * are called afterwards with a width or height less than
 783      * that was specified by the {@code setMinimumSize} method
 784      * the window is automatically enlarged to meet
 785      * the {@code minimumSize} value. The {@code minimumSize}
 786      * value also affects the behaviour of the {@code pack} method.
 787      * <p>


 849      */
 850     public void setSize(int width, int height) {
 851         super.setSize(width, height);
 852     }
 853 
 854     /**
 855      * @deprecated As of JDK version 1.1,
 856      * replaced by <code>setBounds(int, int, int, int)</code>.
 857      */
 858     @Deprecated
 859     public void reshape(int x, int y, int width, int height) {
 860         if (isMinimumSizeSet()) {
 861             Dimension minSize = getMinimumSize();
 862             if (width < minSize.width) {
 863                 width = minSize.width;
 864             }
 865             if (height < minSize.height) {
 866                 height = minSize.height;
 867             }
 868         }




 869         super.reshape(x, y, width, height);
 870     }

 871 
 872     void setClientSize(int w, int h) {
 873         synchronized (getTreeLock()) {
 874             setBoundsOp(ComponentPeer.SET_CLIENT_SIZE);
 875             setBounds(x, y, w, h);
 876         }
 877     }
 878 
 879     static private final AtomicBoolean
 880         beforeFirstWindowShown = new AtomicBoolean(true);
 881 
 882     final void closeSplashScreen() {
 883         if (isTrayIconWindow) {
 884             return;
 885         }
 886         if (beforeFirstWindowShown.getAndSet(false)) {
 887             SunToolkit.closeSplashScreen();
 888         }
 889     }
 890 


 997     synchronized void postWindowEvent(int id) {
 998         if (windowListener != null
 999             || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0
1000             ||  Toolkit.enabledOnToolkit(AWTEvent.WINDOW_EVENT_MASK)) {
1001             WindowEvent e = new WindowEvent(this, id);
1002             Toolkit.getEventQueue().postEvent(e);
1003         }
1004     }
1005 
1006     /**
1007      * Hide this Window, its subcomponents, and all of its owned children.
1008      * The Window and its subcomponents can be made visible again
1009      * with a call to {@code show}.
1010      * </p>
1011      * @see #show
1012      * @see #dispose
1013      * @deprecated As of JDK version 1.5, replaced by
1014      * {@link #setVisible(boolean)}.
1015      */
1016     @Deprecated

1017     public void hide() {


1018         synchronized(ownedWindowList) {
1019             for (int i = 0; i < ownedWindowList.size(); i++) {
1020                 Window child = ownedWindowList.elementAt(i).get();
1021                 if ((child != null) && child.visible) {
1022                     child.hide();
1023                     child.showWithParent = true;
1024                 }
1025             }
1026         }
1027         if (isModalBlocked()) {
1028             modalBlocker.unblockWindow(this);
1029         }
1030         super.hide();
1031     }
1032 
1033     final void clearMostRecentFocusOwnerOnHide() {
1034         /* do nothing */
1035     }
1036 
1037     /**


3780                     Point2D point, float alignmentX, float alignmentY)
3781             {
3782                 window.securityWarningPointX = point.getX();
3783                 window.securityWarningPointY = point.getY();
3784                 window.securityWarningAlignmentX = alignmentX;
3785                 window.securityWarningAlignmentY = alignmentY;
3786 
3787                 synchronized (window.getTreeLock()) {
3788                     WindowPeer peer = (WindowPeer)window.getPeer();
3789                     if (peer != null) {
3790                         peer.repositionSecurityWarning();
3791                     }
3792                 }
3793             }
3794 
3795             public Point2D calculateSecurityWarningPosition(Window window,
3796                     double x, double y, double w, double h)
3797             {
3798                 return window.calculateSecurityWarningPosition(x, y, w, h);
3799             }




3800         }); // WindowAccessor
3801     } // static
3802 
3803     // a window doesn't need to be updated in the Z-order.
3804     @Override
3805     void updateZOrder() {}
3806 
3807 } // class Window
3808 
3809 
3810 /**
3811  * This class is no longer used, but is maintained for Serialization
3812  * backward-compatibility.
3813  */
3814 class FocusManager implements java.io.Serializable {
3815     Container focusRoot;
3816     Component focusOwner;
3817 
3818     /*
3819      * JDK 1.1 serialVersionUID


 747      * both of them are made displayable before calculating
 748      * the preferred size. The Window is validated after its
 749      * size is being calculated.
 750      *
 751      * @see Component#isDisplayable
 752      * @see #setMinimumSize
 753      */
 754     public void pack() {
 755         Container parent = this.parent;
 756         if (parent != null && parent.getPeer() == null) {
 757             parent.addNotify();
 758         }
 759         if (peer == null) {
 760             addNotify();
 761         }
 762         Dimension newSize = getPreferredSize();
 763         if (peer != null) {
 764             setClientSize(newSize.width, newSize.height);
 765         }
 766 
 767         if (beforeFirstShow) {
 768             isPacked = true;
 769         }
 770 
 771         validate();
 772     }
 773 
 774     /**
 775      * Sets the minimum size of this window to a constant
 776      * value.  Subsequent calls to {@code getMinimumSize}
 777      * will always return this value. If current window's
 778      * size is less than {@code minimumSize} the size of the
 779      * window is automatically enlarged to honor the minimum size.
 780      * <p>
 781      * If the {@code setSize} or {@code setBounds} methods
 782      * are called afterwards with a width or height less than
 783      * that was specified by the {@code setMinimumSize} method
 784      * the window is automatically enlarged to meet
 785      * the {@code minimumSize} value. The {@code minimumSize}
 786      * value also affects the behaviour of the {@code pack} method.
 787      * <p>


 849      */
 850     public void setSize(int width, int height) {
 851         super.setSize(width, height);
 852     }
 853 
 854     /**
 855      * @deprecated As of JDK version 1.1,
 856      * replaced by <code>setBounds(int, int, int, int)</code>.
 857      */
 858     @Deprecated
 859     public void reshape(int x, int y, int width, int height) {
 860         if (isMinimumSizeSet()) {
 861             Dimension minSize = getMinimumSize();
 862             if (width < minSize.width) {
 863                 width = minSize.width;
 864             }
 865             if (height < minSize.height) {
 866                 height = minSize.height;
 867             }
 868         }
 869         synchronized (getTreeLock()) {
 870             if (this.width != width || this.height != height) {
 871                 isPacked = false;
 872             }
 873             super.reshape(x, y, width, height);
 874         }
 875     }
 876 
 877     void setClientSize(int w, int h) {
 878         synchronized (getTreeLock()) {
 879             setBoundsOp(ComponentPeer.SET_CLIENT_SIZE);
 880             setBounds(x, y, w, h);
 881         }
 882     }
 883 
 884     static private final AtomicBoolean
 885         beforeFirstWindowShown = new AtomicBoolean(true);
 886 
 887     final void closeSplashScreen() {
 888         if (isTrayIconWindow) {
 889             return;
 890         }
 891         if (beforeFirstWindowShown.getAndSet(false)) {
 892             SunToolkit.closeSplashScreen();
 893         }
 894     }
 895 


1002     synchronized void postWindowEvent(int id) {
1003         if (windowListener != null
1004             || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0
1005             ||  Toolkit.enabledOnToolkit(AWTEvent.WINDOW_EVENT_MASK)) {
1006             WindowEvent e = new WindowEvent(this, id);
1007             Toolkit.getEventQueue().postEvent(e);
1008         }
1009     }
1010 
1011     /**
1012      * Hide this Window, its subcomponents, and all of its owned children.
1013      * The Window and its subcomponents can be made visible again
1014      * with a call to {@code show}.
1015      * </p>
1016      * @see #show
1017      * @see #dispose
1018      * @deprecated As of JDK version 1.5, replaced by
1019      * {@link #setVisible(boolean)}.
1020      */
1021     @Deprecated
1022     @Override
1023     public void hide() {
1024         isPacked = false;
1025 
1026         synchronized(ownedWindowList) {
1027             for (int i = 0; i < ownedWindowList.size(); i++) {
1028                 Window child = ownedWindowList.elementAt(i).get();
1029                 if ((child != null) && child.visible) {
1030                     child.hide();
1031                     child.showWithParent = true;
1032                 }
1033             }
1034         }
1035         if (isModalBlocked()) {
1036             modalBlocker.unblockWindow(this);
1037         }
1038         super.hide();
1039     }
1040 
1041     final void clearMostRecentFocusOwnerOnHide() {
1042         /* do nothing */
1043     }
1044 
1045     /**


3788                     Point2D point, float alignmentX, float alignmentY)
3789             {
3790                 window.securityWarningPointX = point.getX();
3791                 window.securityWarningPointY = point.getY();
3792                 window.securityWarningAlignmentX = alignmentX;
3793                 window.securityWarningAlignmentY = alignmentY;
3794 
3795                 synchronized (window.getTreeLock()) {
3796                     WindowPeer peer = (WindowPeer)window.getPeer();
3797                     if (peer != null) {
3798                         peer.repositionSecurityWarning();
3799                     }
3800                 }
3801             }
3802 
3803             public Point2D calculateSecurityWarningPosition(Window window,
3804                     double x, double y, double w, double h)
3805             {
3806                 return window.calculateSecurityWarningPosition(x, y, w, h);
3807             }
3808 
3809             public boolean isPacked(Window window) {
3810                 return window.isPacked;
3811             }
3812         }); // WindowAccessor
3813     } // static
3814 
3815     // a window doesn't need to be updated in the Z-order.
3816     @Override
3817     void updateZOrder() {}
3818 
3819 } // class Window
3820 
3821 
3822 /**
3823  * This class is no longer used, but is maintained for Serialization
3824  * backward-compatibility.
3825  */
3826 class FocusManager implements java.io.Serializable {
3827     Container focusRoot;
3828     Component focusOwner;
3829 
3830     /*
3831      * JDK 1.1 serialVersionUID