Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

gnu.java.awt
Class AWTUtilities  view AWTUtilities download AWTUtilities.java

java.lang.Object
  extended bygnu.java.awt.AWTUtilities

public class AWTUtilities
extends java.lang.Object

This class mirrors the javax.swing.SwingUtilities class. It provides commonly needed functionalities for AWT classes without the need to reference classes in the javax.swing package.


Nested Class Summary
(package private) static class AWTUtilities.VisibleComponentList
          This List implementation wraps the Component[] returned by Container.getComponents()>Container.getComponents() 55 and iterates over the visible Components in that array.
 
Field Summary
(package private) static java.util.WeakHashMap visibleChildrenCache
          The cache for our List instances.
 
Constructor Summary
AWTUtilities()
           
 
Method Summary
static java.awt.Rectangle calculateInsetArea(java.awt.Rectangle base, java.awt.Insets insets, java.awt.Rectangle ret)
          Calculates the portion of the base rectangle which is inside the insets.
static java.awt.event.MouseEvent convertMouseEvent(java.awt.Component source, java.awt.event.MouseEvent sourceEvent, java.awt.Component destination)
          Convert a mouse event which refrers to one component to another.
static java.awt.Point convertPoint(java.awt.Component source, int x, int y, java.awt.Component destination)
          Converts a point (x,y) from the coordinate space of one component to another.
static void convertPointFromScreen(java.awt.Point p, java.awt.Component c)
          Converts a point from "screen" coordinates (such as the coordinate space mouse events are delivered in) to a component's local coordinate space.
static void convertPointToScreen(java.awt.Point p, java.awt.Component c)
          Converts a point from a component's local coordinate space to "screen" coordinates (such as the coordinate space mouse events are delivered in).
static java.awt.Rectangle convertRectangle(java.awt.Component source, java.awt.Rectangle rect, java.awt.Component destination)
          Converts a rectangle from the coordinate space of one component to another.
static java.awt.Container getAncestorNamed(java.lang.String name, java.awt.Component comp)
          Returns the least ancestor of comp which has the specified name.
static java.awt.Container getAncestorOfClass(java.lang.Class c, java.awt.Component comp)
          Returns the least ancestor of comp which is an instance of the specified class.
static java.awt.Component getDeepestComponentAt(java.awt.Component parent, int x, int y)
          Returns the deepest descendent of parent which is both visible and contains the point (x,y).
static java.awt.FontMetrics getFontMetrics(java.awt.Font font)
          Returns the font metrics object for a given font.
static java.awt.Rectangle getLocalBounds(java.awt.Component aComponent)
          Calculates the bounds of a component in the component's own coordinate space.
static java.awt.Component getRoot(java.awt.Component comp)
          Returns the "root" of the component tree containint comp The root is defined as either the least ancestor of comp which is a java.awt.Window, or the greatest ancestor of comp which is a java.applet.Applet if no java.awt.Window ancestors are found.
static java.util.List getVisibleChildren(java.awt.Container c)
          Returns the visible children of a java.awt.Container.
static void invokeAndWait(java.lang.Runnable doRun)
          Calls java.awt.EventQueue.invokeAndWait with the specified java.lang.Runnable.
static void invokeLater(java.lang.Runnable doRun)
          Calls java.awt.EventQueue.invokeLater with the specified java.lang.Runnable.
static boolean isDescendingFrom(java.awt.Component a, java.awt.Component b)
          Return true if a descends from b, in other words if b is an ancestor of a.
static boolean isEventDispatchThread()
          Calls java.awt.EventQueue.isEventDispatchThread.
static java.awt.Window windowForComponent(java.awt.Component comp)
          Equivalent to calling getAncestorOfClass(Window, comp).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

visibleChildrenCache

static java.util.WeakHashMap visibleChildrenCache
The cache for our List instances. We try to hold one instance of VisibleComponentList for each Component[] that is requested. Note that we use a WeakHashMap for caching, so that the cache itself does not keep the array or the List from beeing garbage collected if no other objects hold references to it.

Constructor Detail

AWTUtilities

public AWTUtilities()
Method Detail

getVisibleChildren

public static java.util.List getVisibleChildren(java.awt.Container c)
Returns the visible children of a java.awt.Container. This method is commonly needed in LayoutManagers, because they only have to layout the visible children of a Container.


calculateInsetArea

public static java.awt.Rectangle calculateInsetArea(java.awt.Rectangle base,
                                                    java.awt.Insets insets,
                                                    java.awt.Rectangle ret)
Calculates the portion of the base rectangle which is inside the insets.


getLocalBounds

public static java.awt.Rectangle getLocalBounds(java.awt.Component aComponent)
Calculates the bounds of a component in the component's own coordinate space. The result has the same height and width as the component's bounds, but its location is set to (0,0).


getFontMetrics

public static java.awt.FontMetrics getFontMetrics(java.awt.Font font)
Returns the font metrics object for a given font. The metrics can be used to calculate crude bounding boxes and positioning information, for laying out components with textual elements.


getAncestorNamed

public static java.awt.Container getAncestorNamed(java.lang.String name,
                                                  java.awt.Component comp)
Returns the least ancestor of comp which has the specified name.


getAncestorOfClass

public static java.awt.Container getAncestorOfClass(java.lang.Class c,
                                                    java.awt.Component comp)
Returns the least ancestor of comp which is an instance of the specified class.


windowForComponent

public static java.awt.Window windowForComponent(java.awt.Component comp)
Equivalent to calling getAncestorOfClass(Window, comp).


getRoot

public static java.awt.Component getRoot(java.awt.Component comp)
Returns the "root" of the component tree containint comp The root is defined as either the least ancestor of comp which is a java.awt.Window, or the greatest ancestor of comp which is a java.applet.Applet if no java.awt.Window ancestors are found.


isDescendingFrom

public static boolean isDescendingFrom(java.awt.Component a,
                                       java.awt.Component b)
Return true if a descends from b, in other words if b is an ancestor of a.


getDeepestComponentAt

public static java.awt.Component getDeepestComponentAt(java.awt.Component parent,
                                                       int x,
                                                       int y)
Returns the deepest descendent of parent which is both visible and contains the point (x,y). Returns parent when either parent is not a container, or has no children which contain (x,y). Returns null when either (x,y) is outside the bounds of parent, or parent is null.


convertPointToScreen

public static void convertPointToScreen(java.awt.Point p,
                                        java.awt.Component c)
Converts a point from a component's local coordinate space to "screen" coordinates (such as the coordinate space mouse events are delivered in). This operation is equivalent to translating the point by the location of the component (which is the origin of its coordinate space).


convertPointFromScreen

public static void convertPointFromScreen(java.awt.Point p,
                                          java.awt.Component c)
Converts a point from "screen" coordinates (such as the coordinate space mouse events are delivered in) to a component's local coordinate space. This operation is equivalent to translating the point by the negation of the component's location (which is the origin of its coordinate space).


convertPoint

public static java.awt.Point convertPoint(java.awt.Component source,
                                          int x,
                                          int y,
                                          java.awt.Component destination)
Converts a point (x,y) from the coordinate space of one component to another. This is equivalent to converting the point from source space to screen space, then back from screen space to destination space. If exactly one of the two Components is null, it is taken to refer to the root ancestor of the other component. If both are null, no transformation is done.


convertRectangle

public static java.awt.Rectangle convertRectangle(java.awt.Component source,
                                                  java.awt.Rectangle rect,
                                                  java.awt.Component destination)
Converts a rectangle from the coordinate space of one component to another. This is equivalent to converting the rectangle from source space to screen space, then back from screen space to destination space. If exactly one of the two Components is null, it is taken to refer to the root ancestor of the other component. If both are null, no transformation is done.


convertMouseEvent

public static java.awt.event.MouseEvent convertMouseEvent(java.awt.Component source,
                                                          java.awt.event.MouseEvent sourceEvent,
                                                          java.awt.Component destination)
Convert a mouse event which refrers to one component to another. This includes changing the mouse event's coordinate space, as well as the source property of the event. If source is null, it is taken to refer to destination's root component. If destination is null, the new event will remain expressed in source's coordinate system.


invokeLater

public static void invokeLater(java.lang.Runnable doRun)
Calls java.awt.EventQueue.invokeLater with the specified java.lang.Runnable.


invokeAndWait

public static void invokeAndWait(java.lang.Runnable doRun)
                          throws java.lang.InterruptedException,
                                 java.lang.reflect.InvocationTargetException
Calls java.awt.EventQueue.invokeAndWait with the specified java.lang.Runnable.


isEventDispatchThread

public static boolean isEventDispatchThread()
Calls java.awt.EventQueue.isEventDispatchThread.