Package ca.phon.ui
Class GUIHelper
java.lang.Object
ca.phon.ui.GUIHelper
A class similar to
SwingUtilities
that has some helper functions
for drawing things.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Point
centerTextInRectangle
(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> T
getAncestorOrSelfOfClass
(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 Rectangle
getInterior
(JComponent comp) Gets the interior drawing region of a component.static Color
Gets a color that "highlights" a given color.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.
-
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.CENTER
orSwingConstants.RIGHT
verticalAlignment
- the vertical alignment; one ofSwingConstants.TOP
,SwingConstants.CENTER
orSwingConstants.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
Gets a color that "highlights" a given color. If the given color is dark, the returned color is brighter, otherwise the returned color is darker.- Parameters:
c
- the color to highlight- Returns:
- a highlighted color
-
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
null
if no ancestor of the given class could be found - See Also:
-