abbot.util
Class AWT

java.lang.Object
  extended by abbot.util.AWT

public class AWT
extends Object

Various AWT utilities to facilitate component-oriented operations.


Nested Class Summary
static interface AWT.ComponentPredicate
           
 
Field Summary
static String CONTAINS_HEAVYWEIGHT_COMPONENT
          Set this client property on components which contain a heavyweight component.
static Point DEFAULT_CASCADE
          Offset from the position of the currently active window to the position of a new window.
static int POPUP_TIMEOUT
           
(package private) static String ROOT_FRAME_CLASSNAME
           
 
Method Summary
static Color alpha(Color c, int alpha)
          Return a copy of the given color with a new alpha component.
static void cascade(Window w)
          Cascade the given window based on the currently active Frame.
static void cascade(Window w, int xoff, int yoff)
          Cascade the given window based on the currently active Frame.
static void centerOnFrame(Window window, Frame frame)
          Center on the specified frame.
static void centerOnScreen(Window window)
          Center the given Window on the default screen.
static Color combine(Color c1, Color c2)
          Combine the two colors with equal weight.
static Color combine(Color c1, Color c2, float weight)
          Combine the two colors, giving the requested weight to the first.
static boolean containsFocus(Component c)
          Return whether the given component either has focus or is the ancestor of the focused component.
static void dismissAWTPopup()
          Ensure any extant AWT popup is dismissed.
static void ensureOnScreen(Window w)
          Ensure the given window is visible on screen.
static boolean eventTypeEnabled(Component c, int id)
          WARNING: This uses 1.3/1.4 implementation details.
static Component find(Component root, AWT.ComponentPredicate test)
          Find the first component matching the given predicate, or null if none found.
static Component find(Component root, Class type)
          Find the first instance of the given class under the given component, or null if none found.
static JPopupMenu findActivePopupMenu()
          Find the currently active Swing popup menu, if any, waiting up to POPUP_TIMEOUT ms.
static Applet findAppletDescendent(Container c)
          Returns the Applet descendent of the given Container, if any.
static MenuItem[] findAWTMenuItems(Frame frame, String path)
          Returns all MenuItems matching the given label or path which are found in the given Frame's MenuBar.
static MenuItem[] findAWTPopupMenuItems(Component parent, String path)
          Returns all MenuItems matching the given label or path which are on PopupMenus on the given Component.
static RootPaneContainer findRootPaneContainer(Container c)
          Find the first instance of RootPaneContainer in the given container.
static JPopupMenu getActivePopupMenu()
          Returns the currently active popup menu, if any.
static Window getActiveWindow()
          NOTE: NOT necessarily the same thing as the focused window.
static sun.awt.AppContext getAppContext(Component c)
          For debugging purposes only.
static Window getFocusedWindow()
          NOTE: on pointer-focused systems, the frontmost window is not necessarily the one with focus.
static Component getFocusOwner()
          Return the focus owner under the given Window.
static Frame getFrame(Object o)
          Return the Frame corresponding to the given object.
static GraphicsConfiguration getGraphicsConfiguration(Point p)
          Returns the GraphicsConfiguration which contains the given point, or null if none.
static Insets getInsets(Container c)
           
static Component getInvoker(Component comp)
          Returns the invoker, if any, of the given component.
static Component getInvoker(MenuComponent mc)
          Returns the invoker, if any, of the given AWT menu component.
static String getKeyCode(int keycode)
           
static int getKeyCode(String code)
           
static String getKeyModifiers(int flags)
           
static Point getLocationOnScreen(Component c)
          Safe version of Component.getLocationOnScreen(), which avoids lockup if an AWT popup menu is showing.
static String getModifiers(InputEvent event)
          Convert the integer modifier flags into a string representation.
static int getModifiers(String mods)
          Convert the string representation into the actual modifier mask.
static String getMouseModifiers(int flags)
           
static String getPath(MenuItem item)
          Returns a unique path to the given MenuItem.
static int getPopupMask()
          Returns the InputEvent mask for the popup trigger button.
static PopupMenu[] getPopupMenus(Component c)
          Return all AWT popup menus associated with the given component.
static boolean getPopupOnPress()
          Returns whether the platform registers a popup on mouse press.
static int getTertiaryMask()
          Returns the InputEvent mask for the tertiary button.
static Rectangle getVirtualDisplayBounds(boolean includeInsets)
          Returns a Rectangle spanning all screens.
static Rectangle getVisibleBounds(GraphicsConfiguration gc)
          Return the visible bounds for the graphics configuration.
static Window getWindow(Component comp)
          Similar to SwingUtilities.getWindowAncestor(), but returns the component itself if it is a Window, or the invoker's window if on a popup.
static Window getWindow(Object o)
          Return the window corresponding to the given object.
static boolean hasDefaultName(Component c)
          Return whether the given Component has only its default name set.
static boolean hierarchyHasHeavyweightComponent(Component base)
           
static void invokeAction(Runnable action)
          Ensure the given action happens on the event dispatch thread.
static void invokeAndWait(Runnable action)
          Ensure the given action happens on the event dispatch thread.
static boolean isAppletViewerFrame(Component c)
           
static boolean isAWTPopupMenuBlocking()
          Returns whether there is an AWT popup menu currently showing.
static boolean isAWTTreeLockHeld(EventQueue eq)
          Returns whether the AWT Tree Lock is currently held.
static boolean isContentPane(Component c)
          Returns whether the given Component is the content pane for a RootPaneContainer.
static boolean isGlassPane(Component c)
          Returns whether the given Component is the Glass Pane for a JRootPane.
static boolean isHeavyweightPopup(Component c)
          Returns whether the given component is a heavyweight popup, that is, a container for a JPopupMenu that is implemented with a heavyweight component (usually a Window).
static boolean isInternalFrameDecoration(Component c)
          Return whether the given component is part of an internal frame's LAF decoration.
static boolean isLightweightPopup(Component c)
          Returns whether the given component is a lightweight popup, that is, a container for a JPopupMenu that is implemented with a lightweight component (usually JPanel).
static boolean isMenuActive(Component c)
          Returns true if there is an active menu on the JFrame (if any) containing the given component.
static boolean isModifier(int keycode)
           
static boolean isOnMenuBar(MenuComponent mc)
          Returns whether the menu component is on a MenuBar.
static boolean isOnPopup(Component comp)
          Returns whether the given component is on a top-level popup.
static boolean isOnPopup(MenuComponent mc)
          Returns whether the given MenuComponent is on a top-level AWT popup (that is, not under a MenuBar.
static boolean isSharedInvisibleFrame(Component c)
          Is the given component the default Swing hidden frame?
static boolean isTertiaryButton(int mods)
          Return whether this is the tertiary button, considering primary to be button1 and secondary to be the popup trigger button.
static boolean isToolTip(Component c)
          Return whether the given component is part of the transient wrapper around a tooltip.
static boolean isTransientDialog(Component c)
          Return whether the given component is part of a transient dialog.
static boolean isTransientPopup(Component c)
          Return whether the given component is part of the transient wrapper around a popup.
static int keyCodeToMask(int code)
           
static int maskToKeyCode(int mask)
          Convert the given modifier event mask to the equivalent key code.
static void moveFrameRelativeTo(Frame frame, Component relativeTo)
           
static boolean onScreen(Point p)
          Return whether the given Point is visible on any screen.
static boolean onScreen(Window w)
          Returns whether one of the upper corners of the given window is accessible.
static Component retargetMouseEvent(Component comp, int id, Point pt)
          If a component does not have mouse events enabled, use the first ancestor which does.
static void setHTMLPreferredWidth(JComponent c, int width)
          Ensure the given component renders its initial HTML wrapped at the given preferred width.
static void setLocationByPlatform(Window w)
          Set the position of the window in a platform-specific manner.
static void showFrameRelative(Frame frame, Component relativeTo)
          Display a frame relative to the given component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POPUP_TIMEOUT

public static int POPUP_TIMEOUT

CONTAINS_HEAVYWEIGHT_COMPONENT

public static final String CONTAINS_HEAVYWEIGHT_COMPONENT
Set this client property on components which contain a heavyweight component. Use Boolean.TRUE as the value.

See Also:
Constant Field Values

DEFAULT_CASCADE

public static final Point DEFAULT_CASCADE
Offset from the position of the currently active window to the position of a new window.


ROOT_FRAME_CLASSNAME

static final String ROOT_FRAME_CLASSNAME
Method Detail

onScreen

public static boolean onScreen(Point p)
Return whether the given Point is visible on any screen.


onScreen

public static boolean onScreen(Window w)
Returns whether one of the upper corners of the given window is accessible.


getGraphicsConfiguration

public static GraphicsConfiguration getGraphicsConfiguration(Point p)
Returns the GraphicsConfiguration which contains the given point, or null if none.


getVirtualDisplayBounds

public static Rectangle getVirtualDisplayBounds(boolean includeInsets)
Returns a Rectangle spanning all screens. Note that not all pixels within the rectangle are necessarily on a display.

Includes any toolbar/dashboard regions.


getVisibleBounds

public static Rectangle getVisibleBounds(GraphicsConfiguration gc)
Return the visible bounds for the graphics configuration. This will exclude any permanent menu bar or dashboard decorations.


ensureOnScreen

public static void ensureOnScreen(Window w)
Ensure the given window is visible on screen.


setLocationByPlatform

public static void setLocationByPlatform(Window w)
Set the position of the window in a platform-specific manner. Uses Window.setLocationByPlatform if available, otherwise centers on screen.


setHTMLPreferredWidth

public static void setHTMLPreferredWidth(JComponent c,
                                         int width)
Ensure the given component renders its initial HTML wrapped at the given preferred width.


combine

public static Color combine(Color c1,
                            Color c2)
Combine the two colors with equal weight.


combine

public static Color combine(Color c1,
                            Color c2,
                            float weight)
Combine the two colors, giving the requested weight to the first.


isMenuActive

public static boolean isMenuActive(Component c)
Returns true if there is an active menu on the JFrame (if any) containing the given component.


showFrameRelative

public static void showFrameRelative(Frame frame,
                                     Component relativeTo)
Display a frame relative to the given component.


centerOnScreen

public static void centerOnScreen(Window window)
Center the given Window on the default screen.


centerOnFrame

public static void centerOnFrame(Window window,
                                 Frame frame)
Center on the specified frame.


moveFrameRelativeTo

public static void moveFrameRelativeTo(Frame frame,
                                       Component relativeTo)

containsFocus

public static boolean containsFocus(Component c)
Return whether the given component either has focus or is the ancestor of the focused component.


getFocusedWindow

public static Window getFocusedWindow()
NOTE: on pointer-focused systems, the frontmost window is not necessarily the one with focus.


getActiveWindow

public static Window getActiveWindow()
NOTE: NOT necessarily the same thing as the focused window.


hierarchyHasHeavyweightComponent

public static boolean hierarchyHasHeavyweightComponent(Component base)
Returns:
whether the hierarchy within which the given Component sits contains a heavyweight component.

getFrame

public static Frame getFrame(Object o)
Return the Frame corresponding to the given object.


getWindow

public static Window getWindow(Object o)
Return the window corresponding to the given object.


alpha

public static Color alpha(Color c,
                          int alpha)
Return a copy of the given color with a new alpha component.


find

public static Component find(Component root,
                             Class type)
Find the first instance of the given class under the given component, or null if none found.


cascade

public static void cascade(Window w)
Cascade the given window based on the currently active Frame.


cascade

public static void cascade(Window w,
                           int xoff,
                           int yoff)
Cascade the given window based on the currently active Frame.


find

public static Component find(Component root,
                             AWT.ComponentPredicate test)
Find the first component matching the given predicate, or null if none found.


findRootPaneContainer

public static RootPaneContainer findRootPaneContainer(Container c)
Find the first instance of RootPaneContainer in the given container. Basically finds applets.


hasDefaultName

public static boolean hasDefaultName(Component c)
Return whether the given Component has only its default name set.


invokeAndWait

public static void invokeAndWait(Runnable action)
Ensure the given action happens on the event dispatch thread. Any component modifications must be invoked this way.


invokeAction

public static void invokeAction(Runnable action)
Ensure the given action happens on the event dispatch thread. Any component modifications must be invoked this way. Note that this is not the same as EventQueue.invokeLater, since if the current thread is the dispatch thread, the action is invoked immediately.


isOnMenuBar

public static boolean isOnMenuBar(MenuComponent mc)
Returns whether the menu component is on a MenuBar.


getInvoker

public static Component getInvoker(MenuComponent mc)
Returns the invoker, if any, of the given AWT menu component. Returns null if the menu component is not attached to anything, or if it is within a MenuBar hierarchy.


getInvoker

public static Component getInvoker(Component comp)
Returns the invoker, if any, of the given component. Returns null if the component is not on a popup of any sort.


getWindow

public static Window getWindow(Component comp)
Similar to SwingUtilities.getWindowAncestor(), but returns the component itself if it is a Window, or the invoker's window if on a popup.


isAWTPopupMenuBlocking

public static boolean isAWTPopupMenuBlocking()
Returns whether there is an AWT popup menu currently showing.


isAWTTreeLockHeld

public static boolean isAWTTreeLockHeld(EventQueue eq)
Returns whether the AWT Tree Lock is currently held.


dismissAWTPopup

public static void dismissAWTPopup()
Ensure any extant AWT popup is dismissed. This should only be called from off the EDT, since (at least on w32) the EDT is blocked while an AWT popup is showing.


isOnPopup

public static boolean isOnPopup(MenuComponent mc)
Returns whether the given MenuComponent is on a top-level AWT popup (that is, not under a MenuBar.


isOnPopup

public static boolean isOnPopup(Component comp)
Returns whether the given component is on a top-level popup. A top-level popup is one generated by a popup trigger, which means popups generated from a JMenu are not included.


isHeavyweightPopup

public static boolean isHeavyweightPopup(Component c)
Returns whether the given component is a heavyweight popup, that is, a container for a JPopupMenu that is implemented with a heavyweight component (usually a Window).


isLightweightPopup

public static boolean isLightweightPopup(Component c)
Returns whether the given component is a lightweight popup, that is, a container for a JPopupMenu that is implemented with a lightweight component (usually JPanel).


isContentPane

public static boolean isContentPane(Component c)
Returns whether the given Component is the content pane for a RootPaneContainer.

See Also:
RootPaneContainer.getContentPane()

isGlassPane

public static boolean isGlassPane(Component c)
Returns whether the given Component is the Glass Pane for a JRootPane.

See Also:
JRootPane.getGlassPane()

isTransientPopup

public static boolean isTransientPopup(Component c)
Return whether the given component is part of the transient wrapper around a popup.


isToolTip

public static boolean isToolTip(Component c)
Return whether the given component is part of the transient wrapper around a tooltip.


isInternalFrameDecoration

public static boolean isInternalFrameDecoration(Component c)
Return whether the given component is part of an internal frame's LAF decoration.


getPopupMask

public static int getPopupMask()
Returns the InputEvent mask for the popup trigger button.


getTertiaryMask

public static int getTertiaryMask()
Returns the InputEvent mask for the tertiary button.


getPopupOnPress

public static boolean getPopupOnPress()
Returns whether the platform registers a popup on mouse press.


getPopupMenus

public static PopupMenu[] getPopupMenus(Component c)
Return all AWT popup menus associated with the given component.


findAWTPopupMenuItems

public static MenuItem[] findAWTPopupMenuItems(Component parent,
                                               String path)
Returns all MenuItems matching the given label or path which are on PopupMenus on the given Component.


findAWTMenuItems

public static MenuItem[] findAWTMenuItems(Frame frame,
                                          String path)
Returns all MenuItems matching the given label or path which are found in the given Frame's MenuBar.


getPath

public static String getPath(MenuItem item)
Returns a unique path to the given MenuItem.


getFocusOwner

public static Component getFocusOwner()
Return the focus owner under the given Window. As of 1.4.x, components will report that they do not have focus if asked from a different AppContext than their own. Account for that here.


getAppContext

public static sun.awt.AppContext getAppContext(Component c)
For debugging purposes only.


eventTypeEnabled

public static boolean eventTypeEnabled(Component c,
                                       int id)
WARNING: This uses 1.3/1.4 implementation details.


isSharedInvisibleFrame

public static boolean isSharedInvisibleFrame(Component c)
Is the given component the default Swing hidden frame?


isAppletViewerFrame

public static boolean isAppletViewerFrame(Component c)

getActivePopupMenu

public static JPopupMenu getActivePopupMenu()
Returns the currently active popup menu, if any. If no popup is currently showing, returns null.


findActivePopupMenu

public static JPopupMenu findActivePopupMenu()
Find the currently active Swing popup menu, if any, waiting up to POPUP_TIMEOUT ms. Returns null if no popup found.


getLocationOnScreen

public static Point getLocationOnScreen(Component c)
Safe version of Component.getLocationOnScreen(), which avoids lockup if an AWT popup menu is showing. The AWT popup holds the AWT tree lock when showing, which lock is required by Component.getLocationOnScreen().


isTransientDialog

public static boolean isTransientDialog(Component c)
Return whether the given component is part of a transient dialog. This includes dialogs generated by JFileChooser, JOptionPane, JColorChooser, and ProgressMonitor.

Note that it is possible to use JOptionPane.createDialog to create a reusable dialog, so just because it's transient doesn't mean it will be disposed of when it is hidden.

Note that this won't detect transient Dialogs after their components have been reassigned to a new transient Dialog.


findAppletDescendent

public static Applet findAppletDescendent(Container c)
Returns the Applet descendent of the given Container, if any.


isTertiaryButton

public static boolean isTertiaryButton(int mods)
Return whether this is the tertiary button, considering primary to be button1 and secondary to be the popup trigger button.


getModifiers

public static int getModifiers(String mods)
Convert the string representation into the actual modifier mask.


getKeyModifiers

public static String getKeyModifiers(int flags)

getMouseModifiers

public static String getMouseModifiers(int flags)

getModifiers

public static String getModifiers(InputEvent event)
Convert the integer modifier flags into a string representation.


getKeyCode

public static String getKeyCode(int keycode)

getKeyCode

public static int getKeyCode(String code)

isModifier

public static boolean isModifier(int keycode)

keyCodeToMask

public static int keyCodeToMask(int code)

maskToKeyCode

public static int maskToKeyCode(int mask)
Convert the given modifier event mask to the equivalent key code.


retargetMouseEvent

public static Component retargetMouseEvent(Component comp,
                                           int id,
                                           Point pt)
If a component does not have mouse events enabled, use the first ancestor which does.


getInsets

public static Insets getInsets(Container c)


Copyright © 2002-2008 Timothy Wall. All Rights Reserved.
Abbot is hosted on

SourceForge