Class TextUtils

java.lang.Object
edu.cnu.mdi.util.TextUtils

public final class TextUtils extends Object
Text measurement, comparison, and rotated drawing helpers.
  • Method Details

    • drawGhostText

      public static void drawGhostText(Graphics g, String text, int x, int y)
    • drawGhostText

      public static void drawGhostText(Graphics g, String text, int x, int y, Color foreground, Color background)
    • drawHaloText

      public static void drawHaloText(Graphics g, String text, int x, int y)
    • drawHaloText

      public static void drawHaloText(Graphics g, String text, int x, int y, Color textColor, Color haloColor)
    • sizeText

      public static Rectangle sizeText(Component component, Point basePoint, String text, Font font)
    • nextSmallerFont

      public static Font nextSmallerFont(Font font, int stepDown)
    • nextBiggerFont

      public static Font nextBiggerFont(Font font, int stepUp)
    • tokens

      public static String[] tokens(String text, String delimiters)
    • commaSeparatedToArray

      public static String[] commaSeparatedToArray(String text)
    • arrayToCommaSeparated

      public static String arrayToCommaSeparated(String[] values)
    • drawRotatedText

      public static void drawRotatedText(Graphics2D g2, Point cp, String s, Font font, Color tcolor, double theta, int align)
      Draws rotated multi-line text with specified alignment.

      This method creates its own Graphics2D copy so that the translate/rotate transforms and the dispose() call never affect the caller's context. The original g2 is left completely unmodified.

      Parameters:
      g2 - the Graphics context (never modified or disposed)
      cp - the center point for the text block and the rotation pivot
      s - the text to draw (may contain newlines)
      font - the font to use
      tcolor - the text color
      theta - the rotation angle in degrees
      align - Use SwingConstants.LEFT, CENTER, or RIGHT
    • textBounds

      public static Rectangle textBounds(String text, FontMetrics fm, int leftMargin, int rightMargin, int topMargin, int bottomMargin, float lineSpacing)
      Calculate the bounding rectangle for a block of text with given margins and line spacing.
      Parameters:
      text - the text content which can contain multiple lines
      fm - the FontMetrics object for measuring text
      leftMargin - the left margin in pixels; silently clamped to [0, 500]
      rightMargin - the right margin in pixels; silently clamped to [0, 500]
      topMargin - the top margin in pixels; silently clamped to [0, 500]
      bottomMargin - the bottom margin in pixels; silently clamped to [0, 500]
      lineSpacing - the line spacing factor (1.0 = normal, >1.0 = more space); silently clamped to [0.5, 3.0]
      Returns:
      the bounding Rectangle for the text block
      Throws:
      IllegalArgumentException - if lineSpacing is not finite (NaN or infinite)
    • textBounds

      public static Rectangle textBounds(String[] lines, FontMetrics fm, int leftMargin, int rightMargin, int topMargin, int bottomMargin, float lineSpacing)
      Calculate the bounding rectangle for a block of text with given margins and line spacing.
      Parameters:
      lines - the array of text lines
      fm - the FontMetrics object for measuring text
      leftMargin - the left margin in pixels; silently clamped to [0, 500]
      rightMargin - the right margin in pixels; silently clamped to [0, 500]
      topMargin - the top margin in pixels; silently clamped to [0, 500]
      bottomMargin - the bottom margin in pixels; silently clamped to [0, 500]
      lineSpacing - the line spacing factor (1.0 = normal, >1.0 = more space); silently clamped to [0.5, 3.0]
      Returns:
      the bounding Rectangle for the text block
      Throws:
      IllegalArgumentException - if lineSpacing is not finite (NaN or infinite)
    • equalStringLists

      public static boolean equalStringLists(List<String> list1, List<String> list2)
      Check to see if two vectors of strings are equal.
      Parameters:
      list1 - the first String vector.
      list2 - the other String vector.
      Returns:
      true if they are equal.