Class GUIHelper
java.lang.Object
ca.phon.ui.GUIHelper
A class similar to
SwingUtilities that has some helper functions
for drawing things.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PointcenterTextInRectangle(Graphics g, String txt, Rectangle rect) Returns the point at which to draw a string so that it appears center-aligned within a given rectangle.static <T> TgetAncestorOrSelfOfClass(Class<T> cls, Component comp) Returns the first ancestor of a given component that is of a specified class, or the component itself if it is an instance of the given class.static RectanglegetInterior(JComponent comp) Gets the interior drawing region of a component.static ColorGets a color that "highlights" a given color.static PointplaceTextInRectangle(Graphics g, String txt, Rectangle rect, int horizontalAlignment, int verticalAlignment) Returns the point at which to draw a string so that it appears aligned within a given rectangle.
-
Constructor Details
-
GUIHelper
public GUIHelper()
-
-
Method Details
-
centerTextInRectangle
Returns the point at which to draw a string so that it appears center-aligned within a given rectangle.- Parameters:
g- the graphics context to work withtxt- the stringrect- the rectangle to place the string in- Returns:
- the point at which text should be drawn so that it is aligned in the center of the given rectangle.
-
placeTextInRectangle
public static Point placeTextInRectangle(Graphics g, String txt, Rectangle rect, int horizontalAlignment, int verticalAlignment) Returns the point at which to draw a string so that it appears aligned within a given rectangle.- Parameters:
g- the graphics context to work withtxt- the stringrect- the rectangle to place the string inhorizontalAlignment- the horizontal alignment; one ofSwingConstants.LEFT,SwingConstants.CENTERorSwingConstants.RIGHTverticalAlignment- the vertical alignment; one ofSwingConstants.TOP,SwingConstants.CENTERorSwingConstants.BOTTOM- Returns:
- the point at which text should be drawn so that it is aligned appropriately with the given rectangle.
-
getInterior
Gets the interior drawing region of a component. That is, the drawing area inside of its border.- Parameters:
comp- the component to get the interior rectangle of- Returns:
- the interior rectangle
-
highlightColor
-
getAncestorOrSelfOfClass
Returns the first ancestor of a given component that is of a specified class, or the component itself if it is an instance of the given class.- Parameters:
cls- the class to look forcomp- the component to start searching from- Returns:
- the ancestor of the given class, or
nullif no ancestor of the given class could be found - See Also:
-