Package ca.phon.ui

Class GUIHelper

java.lang.Object
ca.phon.ui.GUIHelper

public class GUIHelper extends Object
A class similar to SwingUtilities that has some helper functions for drawing things.
  • Constructor Details

    • GUIHelper

      public GUIHelper()
  • Method Details

    • centerTextInRectangle

      public static 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.
      Parameters:
      g - the graphics context to work with
      txt - the string
      rect - 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 with
      txt - the string
      rect - the rectangle to place the string in
      horizontalAlignment - the horizontal alignment; one of SwingConstants.LEFT, SwingConstants.CENTER or SwingConstants.RIGHT
      verticalAlignment - the vertical alignment; one of SwingConstants.TOP, SwingConstants.CENTER or SwingConstants.BOTTOM
      Returns:
      the point at which text should be drawn so that it is aligned appropriately with the given rectangle.
    • getInterior

      public static Rectangle getInterior(JComponent comp)
      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

      public static Color highlightColor(Color c)
      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

      public 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.
      Parameters:
      cls - the class to look for
      comp - 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: