< prev index next >

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

Print this page




1295      */
1296     @Transient
1297     public boolean isVisible() {
1298         return isVisible_NoClientCode();
1299     }
1300     final boolean isVisible_NoClientCode() {
1301         return visible;
1302     }
1303 
1304     /**
1305      * Determines whether this component will be displayed on the screen.
1306      * @return <code>true</code> if the component and all of its ancestors
1307      *          until a toplevel window or null parent are visible,
1308      *          <code>false</code> otherwise
1309      */
1310     boolean isRecursivelyVisible() {
1311         return visible && (parent == null || parent.isRecursivelyVisible());
1312     }
1313 
1314     /**


















1315      * Translates absolute coordinates into coordinates in the coordinate
1316      * space of this component.
1317      */
1318     Point pointRelativeToComponent(Point absolute) {
1319         Point compCoords = getLocationOnScreen();
1320         return new Point(absolute.x - compCoords.x,
1321                          absolute.y - compCoords.y);
1322     }
1323 
1324     /**
1325      * Assuming that mouse location is stored in PointerInfo passed
1326      * to this method, it finds a Component that is in the same
1327      * Window as this Component and is located under the mouse pointer.
1328      * If no such Component exists, null is returned.
1329      * NOTE: this method should be called under the protection of
1330      * tree lock, as it is done in Component.getMousePosition() and
1331      * Container.getMousePosition(boolean).
1332      */
1333     Component findUnderMouseInWindow(PointerInfo pi) {
1334         if (!isShowing()) {


1470      * @see #isEnabled
1471      * @see #isLightweight
1472      * @since 1.1
1473      */
1474     public void setEnabled(boolean b) {
1475         enable(b);
1476     }
1477 
1478     /**
1479      * @deprecated As of JDK version 1.1,
1480      * replaced by <code>setEnabled(boolean)</code>.
1481      */
1482     @Deprecated
1483     public void enable() {
1484         if (!enabled) {
1485             synchronized (getTreeLock()) {
1486                 enabled = true;
1487                 ComponentPeer peer = this.peer;
1488                 if (peer != null) {
1489                     peer.setEnabled(true);
1490                     if (visible) {
1491                         updateCursorImmediately();
1492                     }
1493                 }
1494             }
1495             if (accessibleContext != null) {
1496                 accessibleContext.firePropertyChange(
1497                                                      AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1498                                                      null, AccessibleState.ENABLED);
1499             }
1500         }
1501     }
1502 
1503     /**
1504      * Enables or disables this component.
1505      *
1506      * @param  b {@code true} to enable this component;
1507      *         otherwise {@code false}
1508      *
1509      * @deprecated As of JDK version 1.1,
1510      * replaced by <code>setEnabled(boolean)</code>.


1524      */
1525     @Deprecated
1526     public void disable() {
1527         if (enabled) {
1528             KeyboardFocusManager.clearMostRecentFocusOwner(this);
1529             synchronized (getTreeLock()) {
1530                 enabled = false;
1531                 // A disabled lw container is allowed to contain a focus owner.
1532                 if ((isFocusOwner() || (containsFocus() && !isLightweight())) &&
1533                     KeyboardFocusManager.isAutoFocusTransferEnabled())
1534                 {
1535                     // Don't clear the global focus owner. If transferFocus
1536                     // fails, we want the focus to stay on the disabled
1537                     // Component so that keyboard traversal, et. al. still
1538                     // makes sense to the user.
1539                     transferFocus(false);
1540                 }
1541                 ComponentPeer peer = this.peer;
1542                 if (peer != null) {
1543                     peer.setEnabled(false);
1544                     if (visible) {
1545                         updateCursorImmediately();
1546                     }
1547                 }
1548             }
1549             if (accessibleContext != null) {
1550                 accessibleContext.firePropertyChange(
1551                                                      AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1552                                                      null, AccessibleState.ENABLED);
1553             }
1554         }
1555     }
1556 
1557     /**
1558      * Returns true if this component is painted to an offscreen image
1559      * ("buffer") that's copied to the screen later.  Component
1560      * subclasses that support double buffering should override this
1561      * method to return true if double buffering is enabled.
1562      *
1563      * @return false by default
1564      */




1295      */
1296     @Transient
1297     public boolean isVisible() {
1298         return isVisible_NoClientCode();
1299     }
1300     final boolean isVisible_NoClientCode() {
1301         return visible;
1302     }
1303 
1304     /**
1305      * Determines whether this component will be displayed on the screen.
1306      * @return <code>true</code> if the component and all of its ancestors
1307      *          until a toplevel window or null parent are visible,
1308      *          <code>false</code> otherwise
1309      */
1310     boolean isRecursivelyVisible() {
1311         return visible && (parent == null || parent.isRecursivelyVisible());
1312     }
1313 
1314     /**
1315      * Determines the bounds which will be displayed on the screen.
1316      *
1317      * @return the visible part of bounds in the coordinate space of this comp
1318      */
1319     private Rectangle getRecursivelyVisibleBounds() {
1320         final Component container = getContainer();
1321         final Rectangle bounds = getBounds();
1322         if (container == null) {
1323             // we are top level window or haven't a container, return our bounds
1324             return bounds;
1325         }
1326         // translate the container's bounds to our coordinate space
1327         final Rectangle parentsBounds = container.getRecursivelyVisibleBounds();
1328         parentsBounds.setLocation(0, 0);
1329         return parentsBounds.intersection(bounds);
1330     }
1331 
1332     /**
1333      * Translates absolute coordinates into coordinates in the coordinate
1334      * space of this component.
1335      */
1336     Point pointRelativeToComponent(Point absolute) {
1337         Point compCoords = getLocationOnScreen();
1338         return new Point(absolute.x - compCoords.x,
1339                          absolute.y - compCoords.y);
1340     }
1341 
1342     /**
1343      * Assuming that mouse location is stored in PointerInfo passed
1344      * to this method, it finds a Component that is in the same
1345      * Window as this Component and is located under the mouse pointer.
1346      * If no such Component exists, null is returned.
1347      * NOTE: this method should be called under the protection of
1348      * tree lock, as it is done in Component.getMousePosition() and
1349      * Container.getMousePosition(boolean).
1350      */
1351     Component findUnderMouseInWindow(PointerInfo pi) {
1352         if (!isShowing()) {


1488      * @see #isEnabled
1489      * @see #isLightweight
1490      * @since 1.1
1491      */
1492     public void setEnabled(boolean b) {
1493         enable(b);
1494     }
1495 
1496     /**
1497      * @deprecated As of JDK version 1.1,
1498      * replaced by <code>setEnabled(boolean)</code>.
1499      */
1500     @Deprecated
1501     public void enable() {
1502         if (!enabled) {
1503             synchronized (getTreeLock()) {
1504                 enabled = true;
1505                 ComponentPeer peer = this.peer;
1506                 if (peer != null) {
1507                     peer.setEnabled(true);
1508                     if (visible && !getRecursivelyVisibleBounds().isEmpty()) {
1509                         updateCursorImmediately();
1510                     }
1511                 }
1512             }
1513             if (accessibleContext != null) {
1514                 accessibleContext.firePropertyChange(
1515                                                      AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1516                                                      null, AccessibleState.ENABLED);
1517             }
1518         }
1519     }
1520 
1521     /**
1522      * Enables or disables this component.
1523      *
1524      * @param  b {@code true} to enable this component;
1525      *         otherwise {@code false}
1526      *
1527      * @deprecated As of JDK version 1.1,
1528      * replaced by <code>setEnabled(boolean)</code>.


1542      */
1543     @Deprecated
1544     public void disable() {
1545         if (enabled) {
1546             KeyboardFocusManager.clearMostRecentFocusOwner(this);
1547             synchronized (getTreeLock()) {
1548                 enabled = false;
1549                 // A disabled lw container is allowed to contain a focus owner.
1550                 if ((isFocusOwner() || (containsFocus() && !isLightweight())) &&
1551                     KeyboardFocusManager.isAutoFocusTransferEnabled())
1552                 {
1553                     // Don't clear the global focus owner. If transferFocus
1554                     // fails, we want the focus to stay on the disabled
1555                     // Component so that keyboard traversal, et. al. still
1556                     // makes sense to the user.
1557                     transferFocus(false);
1558                 }
1559                 ComponentPeer peer = this.peer;
1560                 if (peer != null) {
1561                     peer.setEnabled(false);
1562                     if (visible && !getRecursivelyVisibleBounds().isEmpty()) {
1563                         updateCursorImmediately();
1564                     }
1565                 }
1566             }
1567             if (accessibleContext != null) {
1568                 accessibleContext.firePropertyChange(
1569                                                      AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1570                                                      null, AccessibleState.ENABLED);
1571             }
1572         }
1573     }
1574 
1575     /**
1576      * Returns true if this component is painted to an offscreen image
1577      * ("buffer") that's copied to the screen later.  Component
1578      * subclasses that support double buffering should override this
1579      * method to return true if double buffering is enabled.
1580      *
1581      * @return false by default
1582      */


< prev index next >