org.fest.swing.awt
Class AWT

java.lang.Object
  extended by org.fest.swing.awt.AWT

public class AWT
extends Object

Understands utility methods related to AWT.

Author:
Alex Ruiz

Method Summary
static Point centerOf(Component c)
          Returns a point at the center of the given Component.
static Point centerOf(Rectangle r)
          Returns a point at the center of the given Rectangle.
static Point centerOfVisibleRect(JComponent c)
          Returns a point at the center of the visible rectangle of the given JComponent.
static Insets insetsFrom(Container c)
          Returns the insets of the given Container, or an empty one if no insets can be found.
static Component invokerOf(Component c)
          Returns the invoker, if any, of the given Component; or null, if the Component is not on a pop-up of any sort.
static boolean isAppletViewer(Component c)
          Returns true if the given component is an Applet viewer.
static boolean isAWTTreeLockHeld()
          Indicates whether the AWT Tree Lock is currently held.
static boolean isHeavyWeightPopup(Component c)
          Returns whether the given Component is a heavy-weight pop-up, that is, a container for a JPopupMenu that is implemented with a heavy-weight component (usually a Window).
static boolean isPointInScreenBoundaries(JComponent c, Point p)
          Indicates whether the given point, relative to the given JComponent, is inside the screen boundaries.
static boolean isPointInScreenBoundaries(Point p)
          Indicates whether the given point is inside the screen boundaries.
static boolean isSharedInvisibleFrame(Component c)
          Returns whether the given component is the default Swing hidden frame.
static Point locationOnScreenOf(Component c)
          Safe version of Component.getLocationOnScreen(), which avoids lockup if an AWT pop-up menu is showing.
static Window[] ownerLessWindows()
          Returns an array of all Windows that have no owner.
static int popupMask()
          Returns the InputEvent mask for the pop-up trigger button.
static boolean popupOnPress()
          Returns whether the platform registers a pop-up on mouse press.
static Point translate(Component c, int x, int y)
          Translates the given coordinates to the location on screen of the given Component.
static Point visibleCenterOf(Component c)
          Returns a point at the center of the visible area of the given Component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isPointInScreenBoundaries

public static boolean isPointInScreenBoundaries(JComponent c,
                                                Point p)
Indicates whether the given point, relative to the given JComponent, is inside the screen boundaries.

Parameters:
c - the given JComponent.
p - the point to verify.
Returns:
true if the point is inside the screen boundaries; false otherwise.
Since:
1.2

isPointInScreenBoundaries

public static boolean isPointInScreenBoundaries(Point p)
Indicates whether the given point is inside the screen boundaries.

Parameters:
p - the point to verify.
Returns:
true if the point is inside the screen boundaries; false otherwise.
Since:
1.2

ownerLessWindows

public static Window[] ownerLessWindows()
Returns an array of all Windows that have no owner. They include Frames and ownerless Dialogs and Windows.

This method only works when using JDK 1.6 or later. For JDK 1.5, this method returns an empty array.

Returns:
an array of all Windows that have no owner.
Since:
1.2

translate

@RunsInCurrentThread
public static Point translate(Component c,
                                                  int x,
                                                  int y)
Translates the given coordinates to the location on screen of the given Component.

Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.

Parameters:
c - the given Component.
x - X coordinate.
y - Y coordinate.
Returns:
the translated coordinates.
Since:
1.1

visibleCenterOf

@RunsInEDT
public static Point visibleCenterOf(Component c)
Returns a point at the center of the visible area of the given Component.

Parameters:
c - the given Component.
Returns:
a point at the center of the visible area of the given Component.

centerOf

@RunsInCurrentThread
public static Point centerOf(Component c)
Returns a point at the center of the given Component.

Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.

Parameters:
c - the given Component.
Returns:
a point at the center of the given Component.

centerOfVisibleRect

@RunsInCurrentThread
public static Point centerOfVisibleRect(JComponent c)
Returns a point at the center of the visible rectangle of the given JComponent.

Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.

Parameters:
c - the given JComponent.
Returns:
a point at the center of the visible rectangle of the given JComponent.

centerOf

@RunsInCurrentThread
public static Point centerOf(Rectangle r)
Returns a point at the center of the given Rectangle.

Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.

Parameters:
r - the given Rectangle.
Returns:
a point at the center of the given Rectangle.

insetsFrom

@RunsInCurrentThread
public static Insets insetsFrom(Container c)
Returns the insets of the given Container, or an empty one if no insets can be found.

Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.

Parameters:
c - the given Container.
Returns:
the insets of the given Container, or an empty one if no insets can be found.

isAppletViewer

public static boolean isAppletViewer(Component c)
Returns true if the given component is an Applet viewer.

Parameters:
c - the component to check.
Returns:
true if the given component is an Applet viewer, false otherwise.

isSharedInvisibleFrame

public static boolean isSharedInvisibleFrame(Component c)
Returns whether the given component is the default Swing hidden frame.

Parameters:
c - the component to check.
Returns:
true if the given component is the default hidden frame, false otherwise.

isHeavyWeightPopup

@RunsInCurrentThread
public static boolean isHeavyWeightPopup(Component c)
Returns whether the given Component is a heavy-weight pop-up, that is, a container for a JPopupMenu that is implemented with a heavy-weight component (usually a Window).

Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.

Parameters:
c - the given Component.
Returns:
true if the given Component is a heavy-weight pop-up; false otherwise.
Since:
1.2

invokerOf

@RunsInCurrentThread
public static Component invokerOf(Component c)
Returns the invoker, if any, of the given Component; or null, if the Component is not on a pop-up of any sort.

Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.

Parameters:
c - the given Component.
Returns:
the invoker, if any, of the given Component; or null, if the Component is not on a pop-up of any sort.

locationOnScreenOf

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

Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.

Parameters:
c - the given Component.
Returns:
the a point specifying the Component's top-left corner in the screen's coordinate space, or null, if the Component is not showing on the screen.

popupOnPress

public static boolean popupOnPress()
Returns whether the platform registers a pop-up on mouse press.

Returns:
true if the platform registers a pop-up on mouse press, false otherwise.

popupMask

public static int popupMask()
Returns the InputEvent mask for the pop-up trigger button.

Returns:
the InputEvent mask for the pop-up trigger button.

isAWTTreeLockHeld

public static boolean isAWTTreeLockHeld()
Indicates whether the AWT Tree Lock is currently held.

Returns:
true if the AWT Tree Lock is currently held, false otherwise.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.