com.ds.fw.types.string
Class FwStringSplitter

java.lang.Object
  |
  +--com.ds.fw.types.string.FwStringSplitter

public class FwStringSplitter
extends java.lang.Object

This class is used to split a long string into multiple lines while preserving whole words. It can split lines either by the number of characters per line or by the number of pixels per line.


Field Summary
static int CHARACTER
          The character mode constant
 java.awt.FontMetrics fontMetrics
          Current font metrics
 int mode
          Current mode
static int PIXEL
          The pixel mode constant
 int width
          Current text width
 
Constructor Summary
FwStringSplitter()
          Default constructor.
 
Method Summary
 java.lang.String getString(java.lang.String s)
          Returns the splitted string.
 java.util.Vector getVector(java.lang.String s)
          Splits the text in lines which are returned as a vector.
 void setFontMetrics(java.awt.FontMetrics fm)
          Sets the font metrics(for pixel mode).
 void setMode(int i)
          Sets the current splitting mode.
 void setWidth(int i)
          Sets the text width to be used for splitting.
static java.lang.String splitByCharacter(java.lang.String s, int w)
          Splits text by char width.
static java.lang.String splitByPixel(java.lang.String s, int w, java.awt.FontMetrics fm)
          Splits text by pixel width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARACTER

public static final int CHARACTER
The character mode constant

See Also:
Constant Field Values

PIXEL

public static final int PIXEL
The pixel mode constant

See Also:
Constant Field Values

width

public int width
Current text width


mode

public int mode
Current mode


fontMetrics

public java.awt.FontMetrics fontMetrics
Current font metrics

Constructor Detail

FwStringSplitter

public FwStringSplitter()
Default constructor. Sets character mode and 50 chars in line.

Method Detail

splitByPixel

public static java.lang.String splitByPixel(java.lang.String s,
                                            int w,
                                            java.awt.FontMetrics fm)
Splits text by pixel width.

Parameters:
s - the string to be split
w - the width in pixels
fm - the font metrics
Returns:
the splitted string

splitByCharacter

public static java.lang.String splitByCharacter(java.lang.String s,
                                                int w)
Splits text by char width.

Parameters:
s - the string to be split
w - the width in chars
Returns:
the splitted string

setWidth

public void setWidth(int i)
Sets the text width to be used for splitting.

Parameters:
i - pixels or chars count in relation with the splitting mode

setMode

public void setMode(int i)
Sets the current splitting mode.

Parameters:
i - 0- chars, 1- pixels

setFontMetrics

public void setFontMetrics(java.awt.FontMetrics fm)
Sets the font metrics(for pixel mode).

Parameters:
fm - the font metrics to be set

getVector

public java.util.Vector getVector(java.lang.String s)
Splits the text in lines which are returned as a vector.

Parameters:
s - text to split
Returns:
the resulting vector

getString

public java.lang.String getString(java.lang.String s)
Returns the splitted string. For splitting the current settings are used.

Parameters:
s - the text to be splitted
Returns:
the splitted text