com.tensegrity.graphics
Class TextFormatter

java.lang.Object
  extended bycom.tensegrity.graphics.TextFormatter

public final class TextFormatter
extends java.lang.Object

The TextFormatter provides services for formatting text and breaking text lines. The formatter pays heed to the FontFormat of the text and the a transformation the text might be displayed with.

Version:
$Id: TextFormatter.java,v 1.28 2005/11/18 08:39:14 MichaelKegel Exp $
Author:
Michael Kegel

Field Summary
static TextFormatter DEFAULT_TEXTFORMATTER
          global variable that defines a default text formatter (never change this instance)
 int fontunit
          instance variable for the unit of the used font
static int KEEP_FIRST_CHARACTER
          Constant specifying the mode of this formatter
static int SHORTEN_LINES
          Constant specifying the mode of this formatter
static int WRAP_FIRST_WORD_CHARACTERS
          Constant specifying the mode of this formatter
static int WRAP_WORDS
          Constant specifying the mode of this formatter
 
Constructor Summary
TextFormatter(java.lang.String text)
          Constructor for TextFormatter specifying the text String to format.
TextFormatter(TextFormatter textformatter)
          Copy-Constructor for TextFormatter.
 
Method Summary
 void disableMode(int mode)
          Disables the given mode.
 void enableMode(int mode)
          Enables the given mode.
 FontFormat getFontFormat()
          Returns the FontFormat of this TextFormatter.
 int[] getLineHeights(java.lang.String[] lines)
          Returns an array containing the heights of the text lines given by the text-array lines under the given Transform2D.
 int[] getLineHeights(Transform2D xform_context, ScaleValues scalevalues)
          Returns a int-array containg the heights of the text-lines of this formatter.
 int getLineLength()
          Returns the set length of text-lines.
 java.lang.String[] getLines(Transform2D xform_context, ScaleValues scalevalues)
          Returns a String-array containing the text broken up into text-lines by means of the settings of this instance.
 int[] getLineWidths(java.lang.String[] lines)
          Returns a int-array containg the widths of the String-lines given as a parameter.
 int[] getLineWidths(Transform2D xform_context, ScaleValues scalevalues)
          Returns a int-array containg the widths of the broken single lines of text.
 int getMarginBottom()
          Returns the bottom margin.
 int getMarginLeft()
          Returns the left margin.
 int getMarginRight()
          Returns the right margin.
 int getMarginTop()
          Returns the top margin.
 int getModemask()
          Returns the set modemask for this formatter.
 int getPreferredHeight(Transform2D xform_context, ScaleValues scalevalues)
          Returns the preferred overall height for the formatted text under the given Transform2D.
 java.lang.String[] getPreferredLines()
          Returns an array holding the formatted text-lines.
 Size getPreferredSize(Transform2D xform_context, ScaleValues scalevalues)
          Returns the preferred overall size (height and width) for the formatted text under the given Transform2D.
 java.lang.String getText()
          Returns the text.
 int getTextHeight(int[] lineHeights)
          Returns the sum of all line heights given.
 int getTextHeight(java.lang.String[] lines)
          Returns the overall height needed for the text lines given in the array lines under the given transformation.
 int getTextHeight(Transform2D xform_context, ScaleValues scalevalues)
          Returns the overall height for the formatted text under the given Transform2D.
 Transform2D getTransform2D()
          Returns the actual set Transform2D of the formatter.
 boolean isModeEnabled(int mode)
          Returns true if the given mode is enabled.
 void setFontFormat(FontFormat font)
          Sets the FontFormat used by this formatter.
 void setLineLength(int linelength)
          Sets the demanded line-length to the one given by linelength.
 void setMarginBottom(int marginBottom)
          Sets the bottom margin to be used for the formatted text.
 void setMarginLeft(int marginLeft)
          Sets the left margin to be used for the formatted text.
 void setMarginRight(int marginRight)
          Sets the right margin to be used for the formatted text.
 void setMargins(int marginLeft, int marginTop, int marginRight, int marginBottom)
          Sets the left, top, right and bottom margin to the given values.
 void setMarginTop(int marginTop)
          Sets the top margin to be used for the formatted text.
 void setModemask(int modemask)
          Sets the mode of this formatter to the given one.
 void setText(java.lang.String text)
          Sets the text to format the the given text.
 void setTransform(Transform2D xform)
          Sets the Transform2D to be used for the calculations of this formatter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TEXTFORMATTER

public static final TextFormatter DEFAULT_TEXTFORMATTER
global variable that defines a default text formatter (never change this instance)


SHORTEN_LINES

public static final int SHORTEN_LINES
Constant specifying the mode of this formatter

See Also:
Constant Field Values

WRAP_WORDS

public static final int WRAP_WORDS
Constant specifying the mode of this formatter

See Also:
Constant Field Values

WRAP_FIRST_WORD_CHARACTERS

public static final int WRAP_FIRST_WORD_CHARACTERS
Constant specifying the mode of this formatter

See Also:
Constant Field Values

KEEP_FIRST_CHARACTER

public static final int KEEP_FIRST_CHARACTER
Constant specifying the mode of this formatter

See Also:
Constant Field Values

fontunit

public int fontunit
instance variable for the unit of the used font

Constructor Detail

TextFormatter

public TextFormatter(java.lang.String text)
Constructor for TextFormatter specifying the text String to format.

Parameters:
text - the text to format.

TextFormatter

public TextFormatter(TextFormatter textformatter)
Copy-Constructor for TextFormatter.

Parameters:
textformatter - the TextFormatter to be copied.
Method Detail

getLineLength

public final int getLineLength()
Returns the set length of text-lines.

Returns:
the set length of text-lines.

setLineLength

public final void setLineLength(int linelength)
Sets the demanded line-length to the one given by linelength.

Parameters:
linelength - the demanded line-length.

getMarginLeft

public final int getMarginLeft()
Returns the left margin.

Returns:
the left margin.

setMarginLeft

public final void setMarginLeft(int marginLeft)
Sets the left margin to be used for the formatted text.

Parameters:
marginLeft - the left margin.

getMarginRight

public final int getMarginRight()
Returns the right margin.

Returns:
the right margin.

setMarginRight

public final void setMarginRight(int marginRight)
Sets the right margin to be used for the formatted text.

Parameters:
marginRight - the right margin.

getMarginTop

public final int getMarginTop()
Returns the top margin.

Returns:
the top margin.

setMarginTop

public final void setMarginTop(int marginTop)
Sets the top margin to be used for the formatted text.

Parameters:
marginTop - the top margin.

getMarginBottom

public final int getMarginBottom()
Returns the bottom margin.

Returns:
the bottom margin.

setMarginBottom

public final void setMarginBottom(int marginBottom)
Sets the bottom margin to be used for the formatted text.

Parameters:
marginBottom - the bottom margin.

setMargins

public final void setMargins(int marginLeft,
                             int marginTop,
                             int marginRight,
                             int marginBottom)
Sets the left, top, right and bottom margin to the given values.

Parameters:
marginLeft - the margin on the left.
marginTop - the margin on the top.
marginRight - the margin on the right.
marginBottom - the margin on the bottom.

getText

public final java.lang.String getText()
Returns the text.

Returns:
the text.

setText

public final void setText(java.lang.String text)
Sets the text to format the the given text.

Parameters:
text - the text to format.

getFontFormat

public final FontFormat getFontFormat()
Returns the FontFormat of this TextFormatter.

Returns:
this Formatter's FontFormat.

setFontFormat

public final void setFontFormat(FontFormat font)
Sets the FontFormat used by this formatter.

Parameters:
font - the FontFormat to be used.

getTransform2D

public final Transform2D getTransform2D()
Returns the actual set Transform2D of the formatter.

Returns:
the actual set Transform2D of the formatter.

setTransform

public final void setTransform(Transform2D xform)
Sets the Transform2D to be used for the calculations of this formatter.

Parameters:
xform - the to use for calculations

getModemask

public final int getModemask()
Returns the set modemask for this formatter.

Returns:
the set modemask for this formatter.

setModemask

public final void setModemask(int modemask)
Sets the mode of this formatter to the given one. Valid values are any combination of the static constants SHORTEN_LINES, WRAP_WORDS and WRAP_FIRST_WORD_CHARACTER.

Parameters:
modemask - the modemask to set.

isModeEnabled

public final boolean isModeEnabled(int mode)
Returns true if the given mode is enabled.

Parameters:
mode - the mode to check.
Returns:
true if the given mode is enabled.

enableMode

public final void enableMode(int mode)
Enables the given mode. Valid values for mode are the static constants SHORTEN_LINES, WRAP_WORDS and WRAP_FIRST_WORD_CHARACTER.

Parameters:
mode - the mode to disable.

disableMode

public final void disableMode(int mode)
Disables the given mode. Valid values for mode are the static constants SHORTEN_LINES, WRAP_WORDS and WRAP_FIRST_WORD_CHARACTER.

Parameters:
mode - the mode to disable.

getLines

public final java.lang.String[] getLines(Transform2D xform_context,
                                         ScaleValues scalevalues)
Returns a String-array containing the text broken up into text-lines by means of the settings of this instance.

Parameters:
xform_context - the Transform2D to use
scalevalues - the values to scale the font the with
Returns:
the text broken into single lines

getLineWidths

public final int[] getLineWidths(Transform2D xform_context,
                                 ScaleValues scalevalues)
Returns a int-array containg the widths of the broken single lines of text.

Parameters:
xform_context - the Tranform2D to use
scalevalues - the values to scale the font the with
Returns:
the widths of the broken single lines of text

getLineWidths

public final int[] getLineWidths(java.lang.String[] lines)
Returns a int-array containg the widths of the String-lines given as a parameter.

Parameters:
lines - the text-lines to calculate the widths for.
Returns:
the widths of the given lines of text.

getLineHeights

public final int[] getLineHeights(Transform2D xform_context,
                                  ScaleValues scalevalues)
Returns a int-array containg the heights of the text-lines of this formatter.

Parameters:
xform_context - the Tranform2D to use
scalevalues - the values to scale the font the with
Returns:
the heights of the lines of text

getLineHeights

public final int[] getLineHeights(java.lang.String[] lines)
Returns an array containing the heights of the text lines given by the text-array lines under the given Transform2D.

Parameters:
lines - an array holding the text-lines.
Returns:
an array containing the heights of the given text lines.

getTextHeight

public final int getTextHeight(Transform2D xform_context,
                               ScaleValues scalevalues)
Returns the overall height for the formatted text under the given Transform2D.

Parameters:
xform_context - the Transform2D to use
scalevalues - the values to scale the font the with
Returns:
the preferred height for the formatted text

getTextHeight

public final int getTextHeight(java.lang.String[] lines)
Returns the overall height needed for the text lines given in the array lines under the given transformation.

Parameters:
lines - an array holding the lines of text.
Returns:
the overall height needed by the given text-lines.

getTextHeight

public final int getTextHeight(int[] lineHeights)
Returns the sum of all line heights given.

Parameters:
lineHeights - an array holding the line heights.
Returns:
the sum of all given line heights.

getPreferredLines

public final java.lang.String[] getPreferredLines()
Returns an array holding the formatted text-lines.

Returns:
an array holding the formatted text-lines.

getPreferredHeight

public final int getPreferredHeight(Transform2D xform_context,
                                    ScaleValues scalevalues)
Returns the preferred overall height for the formatted text under the given Transform2D.

Parameters:
xform_context - the Transform2D to use
scalevalues - the values to scale the font the with
Returns:
the preferred overall height for the formatted text

getPreferredSize

public final Size getPreferredSize(Transform2D xform_context,
                                   ScaleValues scalevalues)
Returns the preferred overall size (height and width) for the formatted text under the given Transform2D.

Parameters:
xform_context - the Transform2D to use
scalevalues - the values to scale the font the with
Returns:
the preferred size for the formatted text


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.