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 of a visible part of the component relative to its
1316 * parent.
1317 *
1318 * @return the visible part of bounds
1319 */
1320 private Rectangle getRecursivelyVisibleBounds() {
1321 final Component container = getContainer();
1322 final Rectangle bounds = getBounds();
1323 if (container == null) {
1324 // we are top level window or haven't a container, return our bounds
1325 return bounds;
1326 }
1327 // translate the container's bounds to our coordinate space
1328 final Rectangle parentsBounds = container.getRecursivelyVisibleBounds();
1329 parentsBounds.setLocation(0, 0);
1330 return parentsBounds.intersection(bounds);
1331 }
1332
1333 /**
1334 * Translates absolute coordinates into coordinates in the coordinate
1335 * space of this component.
1336 */
1337 Point pointRelativeToComponent(Point absolute) {
1338 Point compCoords = getLocationOnScreen();
1339 return new Point(absolute.x - compCoords.x,
1340 absolute.y - compCoords.y);
1341 }
1342
1343 /**
1344 * Assuming that mouse location is stored in PointerInfo passed
1345 * to this method, it finds a Component that is in the same
1346 * Window as this Component and is located under the mouse pointer.
1347 * If no such Component exists, null is returned.
1348 * NOTE: this method should be called under the protection of
1349 * tree lock, as it is done in Component.getMousePosition() and
1350 * Container.getMousePosition(boolean).
1351 */
1352 Component findUnderMouseInWindow(PointerInfo pi) {
1353 if (!isShowing()) {
1489 * @see #isEnabled
1490 * @see #isLightweight
1491 * @since 1.1
1492 */
1493 public void setEnabled(boolean b) {
1494 enable(b);
1495 }
1496
1497 /**
1498 * @deprecated As of JDK version 1.1,
1499 * replaced by <code>setEnabled(boolean)</code>.
1500 */
1501 @Deprecated
1502 public void enable() {
1503 if (!enabled) {
1504 synchronized (getTreeLock()) {
1505 enabled = true;
1506 ComponentPeer peer = this.peer;
1507 if (peer != null) {
1508 peer.setEnabled(true);
1509 if (visible && !getRecursivelyVisibleBounds().isEmpty()) {
1510 updateCursorImmediately();
1511 }
1512 }
1513 }
1514 if (accessibleContext != null) {
1515 accessibleContext.firePropertyChange(
1516 AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1517 null, AccessibleState.ENABLED);
1518 }
1519 }
1520 }
1521
1522 /**
1523 * Enables or disables this component.
1524 *
1525 * @param b {@code true} to enable this component;
1526 * otherwise {@code false}
1527 *
1528 * @deprecated As of JDK version 1.1,
1529 * replaced by <code>setEnabled(boolean)</code>.
1543 */
1544 @Deprecated
1545 public void disable() {
1546 if (enabled) {
1547 KeyboardFocusManager.clearMostRecentFocusOwner(this);
1548 synchronized (getTreeLock()) {
1549 enabled = false;
1550 // A disabled lw container is allowed to contain a focus owner.
1551 if ((isFocusOwner() || (containsFocus() && !isLightweight())) &&
1552 KeyboardFocusManager.isAutoFocusTransferEnabled())
1553 {
1554 // Don't clear the global focus owner. If transferFocus
1555 // fails, we want the focus to stay on the disabled
1556 // Component so that keyboard traversal, et. al. still
1557 // makes sense to the user.
1558 transferFocus(false);
1559 }
1560 ComponentPeer peer = this.peer;
1561 if (peer != null) {
1562 peer.setEnabled(false);
1563 if (visible && !getRecursivelyVisibleBounds().isEmpty()) {
1564 updateCursorImmediately();
1565 }
1566 }
1567 }
1568 if (accessibleContext != null) {
1569 accessibleContext.firePropertyChange(
1570 AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
1571 null, AccessibleState.ENABLED);
1572 }
1573 }
1574 }
1575
1576 /**
1577 * Returns true if this component is painted to an offscreen image
1578 * ("buffer") that's copied to the screen later. Component
1579 * subclasses that support double buffering should override this
1580 * method to return true if double buffering is enabled.
1581 *
1582 * @return false by default
1583 */
|