public class WrappedText
extends Object
Modifier and Type | Field and Description |
---|---|
static String |
breakCharacters
The set of characters that can be used to split lines.
|
(package private) int |
columns
the number of columns to wrap.
|
(package private) boolean |
enableWrapping |
(package private) Font |
font
The font in which this text is to be rendered.
|
(package private) String |
s
The string being represented, as a single "line"
|
(package private) ArrayList<String> |
textLines
the set of lines already wrapped
|
Constructor and Description |
---|
WrappedText(String s)
Create a string to be wrapped, but turns off the wrapping function.
|
WrappedText(String s,
int cols)
Create a string to be wrapped at no wider than a certain number of characters.
|
Modifier and Type | Method and Description |
---|---|
void |
drawWrappedText(Graphics2D g,
Point2D.Double center)
Uses drawString to render the text on a graphics context.
|
void |
drawWrappedText(Graphics2D g,
Point2D.Double center,
Font font) |
int |
getColumns() |
Font |
getFont() |
ArrayList<String> |
getLines() |
int |
getNumLines()
Get the number of lines needed to render the wrapped text.
|
Dimension |
getSize(FontMetrics fm)
Find the size of the box in which the entire wrapped text fits.
|
Dimension |
getSize(Graphics2D g)
Find the size of the box in which the entire wrapped text fits.
|
boolean |
isEnableWrapping()
Whether to wrap the text or not
|
void |
setColumns(int columns)
Sets the number of characters wide to render the text.
|
void |
setEnableWrapping(boolean enableWrapping)
Tells the wrapper whether to actually wrap the text or consider it all on one line.
|
void |
setFont(Font font) |
ArrayList<String> |
stringBreak(String string,
String breakchars,
int maxChars)
Breaks up the string by breaking words at the occurrence of any member of set of break characters.
|
public static String breakCharacters
String s
Font font
ArrayList<String> textLines
int columns
boolean enableWrapping
public WrappedText(String s)
s
- public WrappedText(String s, int cols)
s
- the string to be wrappedcols
- the maximum numbers of characters per line.public int getColumns()
public void setColumns(int columns)
columns
- a number of characters wide for the text. If -1, then no wrapping is performed and exactly one line is produced.public Font getFont()
public void setFont(Font font)
public boolean isEnableWrapping()
public void setEnableWrapping(boolean enableWrapping)
enableWrapping
- public int getNumLines()
public void drawWrappedText(Graphics2D g, Point2D.Double center)
g
- the graphics context to be usedcenter
- the center point of the ENTIRE text. The method will figure
out how best to render the whole thing centered.public void drawWrappedText(Graphics2D g, Point2D.Double center, Font font)
public Dimension getSize(Graphics2D g)
g
- the graphics context which contains the font metrics.public Dimension getSize(FontMetrics fm)
fm
- the font metrics which controls the renderingpublic ArrayList<String> getLines()
public ArrayList<String> stringBreak(String string, String breakchars, int maxChars)
string
- the string to wrapbreakchars
- the characters from which to determine a break charactersmaxChars
- maximum number of characters per line when breaking. If -1 then don't break.