Package edu.cnu.mdi.util
Class TextUtils
java.lang.Object
edu.cnu.mdi.util.TextUtils
Text measurement, comparison, and rotated drawing helpers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringarrayToCommaSeparated(String[] values) static String[]commaSeparatedToArray(String text) static voiddrawGhostText(Graphics g, String text, int x, int y) static voiddrawGhostText(Graphics g, String text, int x, int y, Color foreground, Color background) static voiddrawHaloText(Graphics g, String text, int x, int y) static voiddrawHaloText(Graphics g, String text, int x, int y, Color textColor, Color haloColor) static voiddrawRotatedText(Graphics2D g2, Point cp, String s, Font font, Color tcolor, double theta, int align) Draws rotated multi-line text with specified alignment.static booleanequalStringLists(List<String> list1, List<String> list2) Check to see if two vectors of strings are equal.static FontnextBiggerFont(Font font, int stepUp) static FontnextSmallerFont(Font font, int stepDown) static Rectanglestatic RectangletextBounds(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.static RectangletextBounds(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.static String[]
-
Method Details
-
drawGhostText
-
drawGhostText
-
drawHaloText
-
drawHaloText
-
sizeText
-
nextSmallerFont
-
nextBiggerFont
-
tokens
-
commaSeparatedToArray
-
arrayToCommaSeparated
-
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
g2is left completely unmodified.- Parameters:
g2- the Graphics context (never modified or disposed)cp- the center point for the text block and the rotation pivots- the text to draw (may contain newlines)font- the font to usetcolor- the text colortheta- the rotation angle in degreesalign- 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 linesfm- the FontMetrics object for measuring textleftMargin- 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- iflineSpacingis 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 linesfm- the FontMetrics object for measuring textleftMargin- 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- iflineSpacingis not finite (NaN or infinite)
-
equalStringLists
Check to see if two vectors of strings are equal.- Parameters:
list1- the first String vector.list2- the other String vector.- Returns:
trueif they are equal.
-