src/share/classes/java/awt/Component.java

Print this page




 641      */
 642     private PropertyChangeSupport changeSupport;
 643 
 644     /*
 645      * In some cases using "this" as an object to synchronize by
 646      * can lead to a deadlock if client code also uses synchronization
 647      * by a component object. For every such situation revealed we should
 648      * consider possibility of replacing "this" with the package private
 649      * objectLock object introduced below. So far there're 2 issues known:
 650      * - CR 6708322 (the getName/setName methods);
 651      * - CR 6608764 (the PropertyChangeListener machinery).
 652      *
 653      * Note: this field is considered final, though readObject() prohibits
 654      * initializing final fields.
 655      */
 656     private transient Object objectLock = new Object();
 657     Object getObjectLock() {
 658         return objectLock;
 659     }
 660 








 661     boolean isPacked = false;
 662 
 663     /**
 664      * Pseudoparameter for direct Geometry API (setLocation, setBounds setSize
 665      * to signal setBounds what's changing. Should be used under TreeLock.
 666      * This is only needed due to the inability to change the cross-calling
 667      * order of public and deprecated methods.
 668      */
 669     private int boundsOp = ComponentPeer.DEFAULT_OPERATION;
 670 
 671     /**
 672      * Enumeration of the common ways the baseline of a component can
 673      * change as the size changes.  The baseline resize behavior is
 674      * primarily for layout managers that need to know how the
 675      * position of the baseline changes as the component size changes.
 676      * In general the baseline resize behavior will be valid for sizes
 677      * greater than or equal to the minimum size (the actual minimum
 678      * size; not a developer specified minimum size).  For sizes
 679      * smaller than the minimum size the baseline may change in a way
 680      * other than the baseline resize behavior indicates.  Similarly,


1539     }
1540 
1541     boolean containsFocus() {
1542         return isFocusOwner();
1543     }
1544 
1545     void clearMostRecentFocusOwnerOnHide() {
1546         KeyboardFocusManager.clearMostRecentFocusOwner(this);
1547     }
1548 
1549     void clearCurrentFocusCycleRootOnHide() {
1550         /* do nothing */
1551     }
1552 
1553     /**
1554      * @deprecated As of JDK version 1.1,
1555      * replaced by <code>setVisible(boolean)</code>.
1556      */
1557     @Deprecated
1558     public void hide() {
1559         isPacked = false;
1560 
1561         if (visible) {
1562             clearCurrentFocusCycleRootOnHide();
1563             clearMostRecentFocusOwnerOnHide();
1564             synchronized (getTreeLock()) {
1565                 visible = false;
1566                 mixOnHiding(isLightweight());
1567                 if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
1568                     transferFocus(true);
1569                 }
1570                 ComponentPeer peer = this.peer;
1571                 if (peer != null) {
1572                     peer.setVisible(false);
1573                     createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
1574                                           this, parent,
1575                                           HierarchyEvent.SHOWING_CHANGED,
1576                                           Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
1577                     if (peer instanceof LightweightPeer) {
1578                         repaint();
1579                     }
1580                     updateCursorImmediately();


2097      */
2098     @Deprecated
2099     public void reshape(int x, int y, int width, int height) {
2100         synchronized (getTreeLock()) {
2101             try {
2102                 setBoundsOp(ComponentPeer.SET_BOUNDS);
2103                 boolean resized = (this.width != width) || (this.height != height);
2104                 boolean moved = (this.x != x) || (this.y != y);
2105                 if (!resized && !moved) {
2106                     return;
2107                 }
2108                 int oldX = this.x;
2109                 int oldY = this.y;
2110                 int oldWidth = this.width;
2111                 int oldHeight = this.height;
2112                 this.x = x;
2113                 this.y = y;
2114                 this.width = width;
2115                 this.height = height;
2116 
2117                 if (resized) {
2118                     isPacked = false;
2119                 }
2120 
2121                 boolean needNotify = true;
2122                 mixOnReshaping();
2123                 if (peer != null) {
2124                     // LightwightPeer is an empty stub so can skip peer.reshape
2125                     if (!(peer instanceof LightweightPeer)) {
2126                         reshapeNativePeer(x, y, width, height, getBoundsOp());
2127                         // Check peer actualy changed coordinates
2128                         resized = (oldWidth != this.width) || (oldHeight != this.height);
2129                         moved = (oldX != this.x) || (oldY != this.y);
2130                         // fix for 5025858: do not send ComponentEvents for toplevel
2131                         // windows here as it is done from peer or native code when
2132                         // the window is really resized or moved, otherwise some
2133                         // events may be sent twice
2134                         if (this instanceof Window) {
2135                             needNotify = false;
2136                         }
2137                     }
2138                     if (resized) {
2139                         invalidate();
2140                     }




 641      */
 642     private PropertyChangeSupport changeSupport;
 643 
 644     /*
 645      * In some cases using "this" as an object to synchronize by
 646      * can lead to a deadlock if client code also uses synchronization
 647      * by a component object. For every such situation revealed we should
 648      * consider possibility of replacing "this" with the package private
 649      * objectLock object introduced below. So far there're 2 issues known:
 650      * - CR 6708322 (the getName/setName methods);
 651      * - CR 6608764 (the PropertyChangeListener machinery).
 652      *
 653      * Note: this field is considered final, though readObject() prohibits
 654      * initializing final fields.
 655      */
 656     private transient Object objectLock = new Object();
 657     Object getObjectLock() {
 658         return objectLock;
 659     }
 660 
 661     /**
 662      * Indicates if the window has been packed via pack().
 663      *
 664      * Note that this field belongs to the Window class, but it cannot be
 665      * moved to that class because it is not transient, and therefore must
 666      * stay at the Component class for backward-compatibility purposes.
 667      * The field SHOULD NOT be used anywhere outside of the Window class.
 668      */
 669     boolean isPacked = false;
 670 
 671     /**
 672      * Pseudoparameter for direct Geometry API (setLocation, setBounds setSize
 673      * to signal setBounds what's changing. Should be used under TreeLock.
 674      * This is only needed due to the inability to change the cross-calling
 675      * order of public and deprecated methods.
 676      */
 677     private int boundsOp = ComponentPeer.DEFAULT_OPERATION;
 678 
 679     /**
 680      * Enumeration of the common ways the baseline of a component can
 681      * change as the size changes.  The baseline resize behavior is
 682      * primarily for layout managers that need to know how the
 683      * position of the baseline changes as the component size changes.
 684      * In general the baseline resize behavior will be valid for sizes
 685      * greater than or equal to the minimum size (the actual minimum
 686      * size; not a developer specified minimum size).  For sizes
 687      * smaller than the minimum size the baseline may change in a way
 688      * other than the baseline resize behavior indicates.  Similarly,


1547     }
1548 
1549     boolean containsFocus() {
1550         return isFocusOwner();
1551     }
1552 
1553     void clearMostRecentFocusOwnerOnHide() {
1554         KeyboardFocusManager.clearMostRecentFocusOwner(this);
1555     }
1556 
1557     void clearCurrentFocusCycleRootOnHide() {
1558         /* do nothing */
1559     }
1560 
1561     /**
1562      * @deprecated As of JDK version 1.1,
1563      * replaced by <code>setVisible(boolean)</code>.
1564      */
1565     @Deprecated
1566     public void hide() {


1567         if (visible) {
1568             clearCurrentFocusCycleRootOnHide();
1569             clearMostRecentFocusOwnerOnHide();
1570             synchronized (getTreeLock()) {
1571                 visible = false;
1572                 mixOnHiding(isLightweight());
1573                 if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
1574                     transferFocus(true);
1575                 }
1576                 ComponentPeer peer = this.peer;
1577                 if (peer != null) {
1578                     peer.setVisible(false);
1579                     createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
1580                                           this, parent,
1581                                           HierarchyEvent.SHOWING_CHANGED,
1582                                           Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
1583                     if (peer instanceof LightweightPeer) {
1584                         repaint();
1585                     }
1586                     updateCursorImmediately();


2103      */
2104     @Deprecated
2105     public void reshape(int x, int y, int width, int height) {
2106         synchronized (getTreeLock()) {
2107             try {
2108                 setBoundsOp(ComponentPeer.SET_BOUNDS);
2109                 boolean resized = (this.width != width) || (this.height != height);
2110                 boolean moved = (this.x != x) || (this.y != y);
2111                 if (!resized && !moved) {
2112                     return;
2113                 }
2114                 int oldX = this.x;
2115                 int oldY = this.y;
2116                 int oldWidth = this.width;
2117                 int oldHeight = this.height;
2118                 this.x = x;
2119                 this.y = y;
2120                 this.width = width;
2121                 this.height = height;
2122 




2123                 boolean needNotify = true;
2124                 mixOnReshaping();
2125                 if (peer != null) {
2126                     // LightwightPeer is an empty stub so can skip peer.reshape
2127                     if (!(peer instanceof LightweightPeer)) {
2128                         reshapeNativePeer(x, y, width, height, getBoundsOp());
2129                         // Check peer actualy changed coordinates
2130                         resized = (oldWidth != this.width) || (oldHeight != this.height);
2131                         moved = (oldX != this.x) || (oldY != this.y);
2132                         // fix for 5025858: do not send ComponentEvents for toplevel
2133                         // windows here as it is done from peer or native code when
2134                         // the window is really resized or moved, otherwise some
2135                         // events may be sent twice
2136                         if (this instanceof Window) {
2137                             needNotify = false;
2138                         }
2139                     }
2140                     if (resized) {
2141                         invalidate();
2142                     }