399 sourceEvent.getModifiers()
400 | sourceEvent.getModifiersEx(),
401 p.x,p.y,
402 sourceEvent.getXOnScreen(),
403 sourceEvent.getYOnScreen(),
404 sourceEvent.getClickCount(),
405 sourceEvent.isPopupTrigger(),
406 sourceEvent.getButton());
407 }
408 return newEvent;
409 }
410
411
412 /**
413 * Convert a point from a component's coordinate system to
414 * screen coordinates.
415 *
416 * @param p a Point object (converted to the new coordinate system)
417 * @param c a Component object
418 */
419 public static void convertPointToScreen(Point p,Component c) {
420 Rectangle b;
421 int x,y;
422
423 do {
424 if(c instanceof JComponent) {
425 x = c.getX();
426 y = c.getY();
427 } else if(c instanceof java.applet.Applet ||
428 c instanceof java.awt.Window) {
429 try {
430 Point pp = c.getLocationOnScreen();
431 x = pp.x;
432 y = pp.y;
433 } catch (IllegalComponentStateException icse) {
434 x = c.getX();
435 y = c.getY();
436 }
437 } else {
438 x = c.getX();
439 y = c.getY();
440 }
441
442 p.x += x;
443 p.y += y;
444
445 if(c instanceof java.awt.Window || c instanceof java.applet.Applet)
446 break;
447 c = c.getParent();
448 } while(c != null);
449 }
450
451 /**
452 * Convert a point from a screen coordinates to a component's
453 * coordinate system
454 *
455 * @param p a Point object (converted to the new coordinate system)
456 * @param c a Component object
457 */
458 public static void convertPointFromScreen(Point p,Component c) {
459 Rectangle b;
460 int x,y;
461
462 do {
463 if(c instanceof JComponent) {
464 x = c.getX();
465 y = c.getY();
466 } else if(c instanceof java.applet.Applet ||
467 c instanceof java.awt.Window) {
468 try {
469 Point pp = c.getLocationOnScreen();
470 x = pp.x;
471 y = pp.y;
472 } catch (IllegalComponentStateException icse) {
473 x = c.getX();
474 y = c.getY();
475 }
476 } else {
477 x = c.getX();
1638 */
1639 public static JRootPane getRootPane(Component c) {
1640 if (c instanceof RootPaneContainer) {
1641 return ((RootPaneContainer)c).getRootPane();
1642 }
1643 for( ; c != null; c = c.getParent()) {
1644 if (c instanceof JRootPane) {
1645 return (JRootPane)c;
1646 }
1647 }
1648 return null;
1649 }
1650
1651
1652 /**
1653 * Returns the root component for the current component tree.
1654 *
1655 * @param c the component
1656 * @return the first ancestor of c that's a Window or the last Applet ancestor
1657 */
1658 public static Component getRoot(Component c) {
1659 Component applet = null;
1660 for(Component p = c; p != null; p = p.getParent()) {
1661 if (p instanceof Window) {
1662 return p;
1663 }
1664 if (p instanceof Applet) {
1665 applet = p;
1666 }
1667 }
1668 return applet;
1669 }
1670
1671 static JComponent getPaintingOrigin(JComponent c) {
1672 Container p = c;
1673 while ((p = p.getParent()) instanceof JComponent) {
1674 JComponent jp = (JComponent) p;
1675 if (jp.isPaintingOrigin()) {
1676 return jp;
1677 }
1678 }
1679 return null;
1680 }
1681
1682 /**
1683 * Process the key bindings for the <code>Component</code> associated with
1684 * <code>event</code>. This method is only useful if
1685 * <code>event.getComponent()</code> does not descend from
1686 * <code>JComponent</code>, or your are not invoking
1687 * <code>super.processKeyEvent</code> from within your
1688 * <code>JComponent</code> subclass. <code>JComponent</code>
1689 * automatically processes bindings from within its
1690 * <code>processKeyEvent</code> method, hence you rarely need
1691 * to directly invoke this method.
1692 *
1693 * @param event KeyEvent used to identify which bindings to process, as
1694 * well as which Component has focus.
1695 * @return true if a binding has found and processed
1696 * @since 1.4
1697 */
1698 public static boolean processKeyBindings(KeyEvent event) {
1699 if (event != null) {
1700 if (event.isConsumed()) {
1701 return false;
1702 }
1703
1704 Component component = event.getComponent();
1705 boolean pressed = (event.getID() == KeyEvent.KEY_PRESSED);
1706
1707 if (!isValidKeyEventForKeyBindings(event)) {
1708 return false;
1709 }
1710 // Find the first JComponent in the ancestor hierarchy, and
1711 // invoke processKeyBindings on it
1712 while (component != null) {
1713 if (component instanceof JComponent) {
1714 return ((JComponent)component).processKeyBindings(
1715 event, pressed);
1716 }
1717 if ((component instanceof Applet) ||
2192 /**
2193 * Retrieves the validate root of a given container.
2194 *
2195 * If the container is contained within a {@code CellRendererPane}, this
2196 * method returns {@code null} due to the synthetic nature of the {@code
2197 * CellRendererPane}.
2198 * <p>
2199 * The component hierarchy must be displayable up to the toplevel component
2200 * (either a {@code Frame} or an {@code Applet} object.) Otherwise this
2201 * method returns {@code null}.
2202 * <p>
2203 * If the {@code visibleOnly} argument is {@code true}, the found validate
2204 * root and all its parents up to the toplevel component must also be
2205 * visible. Otherwise this method returns {@code null}.
2206 *
2207 * @return the validate root of the given container or null
2208 * @see java.awt.Component#isDisplayable()
2209 * @see java.awt.Component#isVisible()
2210 * @since 1.7
2211 */
2212 static Container getValidateRoot(Container c, boolean visibleOnly) {
2213 Container root = null;
2214
2215 for (; c != null; c = c.getParent())
2216 {
2217 if (!c.isDisplayable() || c instanceof CellRendererPane) {
2218 return null;
2219 }
2220 if (c.isValidateRoot()) {
2221 root = c;
2222 break;
2223 }
2224 }
2225
2226 if (root == null) {
2227 return null;
2228 }
2229
2230 for (; c != null; c = c.getParent()) {
2231 if (!c.isDisplayable() || (visibleOnly && !c.isVisible())) {
|
399 sourceEvent.getModifiers()
400 | sourceEvent.getModifiersEx(),
401 p.x,p.y,
402 sourceEvent.getXOnScreen(),
403 sourceEvent.getYOnScreen(),
404 sourceEvent.getClickCount(),
405 sourceEvent.isPopupTrigger(),
406 sourceEvent.getButton());
407 }
408 return newEvent;
409 }
410
411
412 /**
413 * Convert a point from a component's coordinate system to
414 * screen coordinates.
415 *
416 * @param p a Point object (converted to the new coordinate system)
417 * @param c a Component object
418 */
419 @SuppressWarnings("deprecation")
420 public static void convertPointToScreen(Point p,Component c) {
421 Rectangle b;
422 int x,y;
423
424 do {
425 if(c instanceof JComponent) {
426 x = c.getX();
427 y = c.getY();
428 } else if(c instanceof java.applet.Applet ||
429 c instanceof java.awt.Window) {
430 try {
431 Point pp = c.getLocationOnScreen();
432 x = pp.x;
433 y = pp.y;
434 } catch (IllegalComponentStateException icse) {
435 x = c.getX();
436 y = c.getY();
437 }
438 } else {
439 x = c.getX();
440 y = c.getY();
441 }
442
443 p.x += x;
444 p.y += y;
445
446 if(c instanceof java.awt.Window || c instanceof java.applet.Applet)
447 break;
448 c = c.getParent();
449 } while(c != null);
450 }
451
452 /**
453 * Convert a point from a screen coordinates to a component's
454 * coordinate system
455 *
456 * @param p a Point object (converted to the new coordinate system)
457 * @param c a Component object
458 */
459 @SuppressWarnings("deprecation")
460 public static void convertPointFromScreen(Point p,Component c) {
461 Rectangle b;
462 int x,y;
463
464 do {
465 if(c instanceof JComponent) {
466 x = c.getX();
467 y = c.getY();
468 } else if(c instanceof java.applet.Applet ||
469 c instanceof java.awt.Window) {
470 try {
471 Point pp = c.getLocationOnScreen();
472 x = pp.x;
473 y = pp.y;
474 } catch (IllegalComponentStateException icse) {
475 x = c.getX();
476 y = c.getY();
477 }
478 } else {
479 x = c.getX();
1640 */
1641 public static JRootPane getRootPane(Component c) {
1642 if (c instanceof RootPaneContainer) {
1643 return ((RootPaneContainer)c).getRootPane();
1644 }
1645 for( ; c != null; c = c.getParent()) {
1646 if (c instanceof JRootPane) {
1647 return (JRootPane)c;
1648 }
1649 }
1650 return null;
1651 }
1652
1653
1654 /**
1655 * Returns the root component for the current component tree.
1656 *
1657 * @param c the component
1658 * @return the first ancestor of c that's a Window or the last Applet ancestor
1659 */
1660 @SuppressWarnings("deprecation")
1661 public static Component getRoot(Component c) {
1662 Component applet = null;
1663 for(Component p = c; p != null; p = p.getParent()) {
1664 if (p instanceof Window) {
1665 return p;
1666 }
1667 if (p instanceof Applet) {
1668 applet = p;
1669 }
1670 }
1671 return applet;
1672 }
1673
1674 static JComponent getPaintingOrigin(JComponent c) {
1675 Container p = c;
1676 while ((p = p.getParent()) instanceof JComponent) {
1677 JComponent jp = (JComponent) p;
1678 if (jp.isPaintingOrigin()) {
1679 return jp;
1680 }
1681 }
1682 return null;
1683 }
1684
1685 /**
1686 * Process the key bindings for the <code>Component</code> associated with
1687 * <code>event</code>. This method is only useful if
1688 * <code>event.getComponent()</code> does not descend from
1689 * <code>JComponent</code>, or your are not invoking
1690 * <code>super.processKeyEvent</code> from within your
1691 * <code>JComponent</code> subclass. <code>JComponent</code>
1692 * automatically processes bindings from within its
1693 * <code>processKeyEvent</code> method, hence you rarely need
1694 * to directly invoke this method.
1695 *
1696 * @param event KeyEvent used to identify which bindings to process, as
1697 * well as which Component has focus.
1698 * @return true if a binding has found and processed
1699 * @since 1.4
1700 */
1701 @SuppressWarnings("deprecation")
1702 public static boolean processKeyBindings(KeyEvent event) {
1703 if (event != null) {
1704 if (event.isConsumed()) {
1705 return false;
1706 }
1707
1708 Component component = event.getComponent();
1709 boolean pressed = (event.getID() == KeyEvent.KEY_PRESSED);
1710
1711 if (!isValidKeyEventForKeyBindings(event)) {
1712 return false;
1713 }
1714 // Find the first JComponent in the ancestor hierarchy, and
1715 // invoke processKeyBindings on it
1716 while (component != null) {
1717 if (component instanceof JComponent) {
1718 return ((JComponent)component).processKeyBindings(
1719 event, pressed);
1720 }
1721 if ((component instanceof Applet) ||
2196 /**
2197 * Retrieves the validate root of a given container.
2198 *
2199 * If the container is contained within a {@code CellRendererPane}, this
2200 * method returns {@code null} due to the synthetic nature of the {@code
2201 * CellRendererPane}.
2202 * <p>
2203 * The component hierarchy must be displayable up to the toplevel component
2204 * (either a {@code Frame} or an {@code Applet} object.) Otherwise this
2205 * method returns {@code null}.
2206 * <p>
2207 * If the {@code visibleOnly} argument is {@code true}, the found validate
2208 * root and all its parents up to the toplevel component must also be
2209 * visible. Otherwise this method returns {@code null}.
2210 *
2211 * @return the validate root of the given container or null
2212 * @see java.awt.Component#isDisplayable()
2213 * @see java.awt.Component#isVisible()
2214 * @since 1.7
2215 */
2216 @SuppressWarnings("deprecation")
2217 static Container getValidateRoot(Container c, boolean visibleOnly) {
2218 Container root = null;
2219
2220 for (; c != null; c = c.getParent())
2221 {
2222 if (!c.isDisplayable() || c instanceof CellRendererPane) {
2223 return null;
2224 }
2225 if (c.isValidateRoot()) {
2226 root = c;
2227 break;
2228 }
2229 }
2230
2231 if (root == null) {
2232 return null;
2233 }
2234
2235 for (; c != null; c = c.getParent()) {
2236 if (!c.isDisplayable() || (visibleOnly && !c.isVisible())) {
|