|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.gui.AbstractPaintable
edu.neu.ccs.gui.PaintableSequenceComposite
edu.neu.ccs.gui.MultiLineTextPaintable
Class MultiLineTextPaintable provides the
basic functionality of TextPaintable for text
that contains newlines.
The class TextPaintable accepts text with
newlines but does not treat them properly. The newlines
are simply ignored and all text is placed on one line.
There are deep technical reasons for this. The Java tools
that we use to render the text and later to test for mouse
hits is fundamentally a single-line technology. Since we
have no other way to test for mouse hits, we must rely on
this Java technology in TextPaintable.
In this class, we solve the problem of multi-line text
by breaking the text into an array of single-line strings,
using each line to create a TextPaintable,
and then collecting these TextPaintable
objects into an internal PaintableSequence.
Here is a summary of the parameter options:
Paintable can be
queried or modified as usualDepending on the constructor called, the parameters may be supplied or left to be the following defaults:
string: ""font: TextPaintable.getDefaultFont()fillpaint: Color.blacklocator: TextAnchor.LEFT_ASCENTLINEanchorX: 0anchorY: 0Of course, when the string is empty, nothing will be painted.
TextPaintable| Field Summary | |
private float |
anchorX
The x anchor position. |
private float |
anchorY
The y anchor position. |
private Paint |
fillpaint
The fill paint. |
private Font |
font
The font. |
private TextAnchor.Locator |
locator
The text anchor locator. |
static String |
SET_ANCHOR_LOCATOR
Bound property name for set anchor locator. |
static String |
SET_ANCHOR_POSITION
Bound property name for set anchor position. |
static String |
SET_FILL_PAINT
Bound property name for set fill paint. |
static String |
SET_FONT
Bound property name for set font. |
static String |
SET_STRING
Bound property name for set string. |
private TextBounds.Strategy |
strategy
The text bounds strategy. |
private String |
string
The text string. |
| Fields inherited from class edu.neu.ccs.gui.PaintableSequenceComposite |
|
| Fields inherited from class edu.neu.ccs.gui.AbstractPaintable |
SET_BACKGROUND_PAINT, SET_BACKGROUND_TILE |
| Fields inherited from interface edu.neu.ccs.gui.Paintable |
REMOVE_PAINTABLE, SET_CLIPPING_SHAPE, SET_DEFAULT_BOUNDS2D, SET_DEFAULT_CENTER, SET_DEFAULT_ORIGINAL_BOUNDS2D, SET_DEFAULT_ORIGINAL_CENTER, SET_MUTATOR, SET_OPACITY, SET_PAINTABLE, SET_VISIBLE, SHIFT_PAINTABLE |
| Fields inherited from interface edu.neu.ccs.util.JPTConstants |
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE |
| Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
| Constructor Summary | |
MultiLineTextPaintable()
The default constructor. |
|
MultiLineTextPaintable(String string)
The constructor that creates a MultiLineTextPaintable
with the given string. |
|
MultiLineTextPaintable(String string,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string and anchor position. |
|
MultiLineTextPaintable(String string,
Font font)
The constructor that creates a MultiLineTextPaintable
with the given string and font. |
|
MultiLineTextPaintable(String string,
Font font,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string, font, and anchor position. |
|
MultiLineTextPaintable(String string,
Font font,
Paint fillpaint)
The constructor that creates a MultiLineTextPaintable
with the given string, font, fill paint. |
|
MultiLineTextPaintable(String string,
Font font,
Paint fillpaint,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string, font, fill paint, and anchor position. |
|
MultiLineTextPaintable(String string,
Font font,
Paint fillpaint,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string, font, fill paint, bounds strategy,
anchor locator, and anchor position. |
|
MultiLineTextPaintable(String string,
Font font,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string, font, anchor locator, and anchor position. |
|
MultiLineTextPaintable(String string,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string, anchor locator, and anchor position. |
|
| Method Summary | |
TextAnchor.Locator |
getAnchorLocator()
Returns the TextAnchor.Locator for this
MultiLineTextPaintable. |
float[] |
getAnchorPosition()
Returns a copy of the anchor position for the first line this MultiLineTextPaintable
as an array float[2]. |
Paint |
getFillPaint()
Returns the fill paint for this MultiLineTextPaintable. |
Font |
getFont()
Returns the font for this MultiLineTextPaintable. |
String[] |
getLines()
Returns the string for this MultiLineTextPaintable
split into individual lines based on the newline character. |
XPoint2D |
getOriginalCenter()
Returns a copy of the center of the paint region affected by the originalPaint method. |
String |
getString()
Returns the string for this MultiLineTextPaintable. |
protected void |
initMLTP(String string,
Font font,
Paint fillpaint,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The helper method to carry out the work of the constructors. |
protected void |
makeMLTP()
The helper method to build the MultiLineTextPaintable
once the settings are established. |
void |
setAnchorLocator(TextAnchor.Locator locator)
Sets the TextAnchor.Locator for this
MultiLineTextPaintable. |
void |
setAnchorPosition(float[] position)
Sets the anchor position for the first line of this MultiLineTextPaintable
using an array float[2]. |
void |
setAnchorPosition(float anchorX,
float anchorY)
Sets the anchor position for the first line of this MultiLineTextPaintable. |
void |
setFillPaint(Paint fillpaint)
Sets the fill paint for this MultiLineTextPaintable. |
void |
setFont(Font font)
Sets the font for this MultiLineTextPaintable. |
void |
setString(String string)
Sets the string for this MultiLineTextPaintable. |
void |
shiftAnchorPosition(float dx,
float dy)
Shift the anchor position for each line of this MultiLineTextPaintable
by the given dx and dy. |
| Methods inherited from class edu.neu.ccs.gui.PaintableSequenceComposite |
clearBothInnerBackgrounds, clearInnerBackgroundPaint, clearInnerBackgroundTile, getActualBounds2D, getInnerBackgroundPaint, getInnerBackgroundTile, getPaintableSequence, originalContains, originalPaint, setInnerBackgroundPaint, setInnerBackgroundTile |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final String SET_STRING
public static final String SET_FONT
public static final String SET_FILL_PAINT
public static final String SET_ANCHOR_LOCATOR
public static final String SET_ANCHOR_POSITION
private String string
private Font font
private Paint fillpaint
private TextBounds.Strategy strategy
private TextAnchor.Locator locator
private float anchorX
private float anchorY
| Constructor Detail |
public MultiLineTextPaintable()
The default constructor.
The following defaults are set:
string: ""font: TextPaintable.getDefaultFont()fillpaint: Color.blacklocator: TextAnchor.LEFT_ASCENTLINEanchorX: 0anchorY: 0All properties may be changed after construction.
With the default settings, the paintable will display nothing since its text string is empty.
public MultiLineTextPaintable(String string)
The constructor that creates a MultiLineTextPaintable
with the given string.
string - the string to display on multiple lines
public MultiLineTextPaintable(String string,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string and anchor position.
string - the string to display on multiple linesanchorX - the anchor x-coordinate for the first lineanchorY - the anchor y-coordinate for the first line
public MultiLineTextPaintable(String string,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string, anchor locator, and anchor position.
string - the string to display on multiple lineslocator - the locator for the anchor positionanchorX - the anchor x-coordinate for the first lineanchorY - the anchor y-coordinate for the first line
public MultiLineTextPaintable(String string,
Font font)
The constructor that creates a MultiLineTextPaintable
with the given string and font.
string - the string to display on multiple linesfont - the font to use to display the string
public MultiLineTextPaintable(String string,
Font font,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string, font, and anchor position.
string - the string to display on multiple linesfont - the font to use to display the stringanchorX - the anchor x-coordinate for the first lineanchorY - the anchor y-coordinate for the first line
public MultiLineTextPaintable(String string,
Font font,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string, font, anchor locator, and anchor position.
string - the string to display on multiple linesfont - the font to use to display the stringlocator - the locator for the anchor positionanchorX - the anchor x-coordinate for the first lineanchorY - the anchor y-coordinate for the first line
public MultiLineTextPaintable(String string,
Font font,
Paint fillpaint)
The constructor that creates a MultiLineTextPaintable
with the given string, font, fill paint.
string - the string to display on multiple linesfont - the font to use to display the stringfillpaint - the paint to use to fill the string
public MultiLineTextPaintable(String string,
Font font,
Paint fillpaint,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string, font, fill paint, and anchor position.
string - the string to display on multiple linesfont - the font to use to display the stringfillpaint - the paint to use to fill the stringanchorX - the anchor x-coordinate for the first lineanchorY - the anchor y-coordinate for the first line
public MultiLineTextPaintable(String string,
Font font,
Paint fillpaint,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a MultiLineTextPaintable
with the given string, font, fill paint, bounds strategy,
anchor locator, and anchor position.
string - the string to display on multiple linesfont - the font to use to display the stringfillpaint - the paint to use to fill the stringlocator - the locator for the anchor positionanchorX - the anchor x-coordinate for the first lineanchorY - the anchor y-coordinate for the first line| Method Detail |
protected void initMLTP(String string,
Font font,
Paint fillpaint,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The helper method to carry out the work of the constructors.
string - the string to display on multiple linesfont - the font to use to display the stringfillpaint - the paint to use to fill the stringlocator - the locator for the anchor positionanchorX - the anchor x-coordinate for the first lineanchorY - the anchor y-coordinate for the first lineprotected void makeMLTP()
The helper method to build the MultiLineTextPaintable
once the settings are established.
public void setString(String string)
Sets the string for this MultiLineTextPaintable.
If the given string is null, it is set to
the zero length string.
Does nothing if the string is equal to the current string.
Fires property change: SET_STRING.
string - the string to display on multiple linespublic String getString()
MultiLineTextPaintable.
public String[] getLines()
MultiLineTextPaintable
split into individual lines based on the newline character.
public void setFont(Font font)
Sets the font for this MultiLineTextPaintable.
If the given font is null then it is set to
TextPaintable.getDefaultFont().
Does nothing if the font is equal to the current font.
Fires property change: SET_FONT.
font - the font to use to display the stringpublic Font getFont()
MultiLineTextPaintable.
public void setFillPaint(Paint fillpaint)
Sets the fill paint for this MultiLineTextPaintable.
If the given paint is null, it is set to
Color.black.
Fires property change: SET_FILL_PAINT.
fillpaint - the paint to use to fill the stringpublic Paint getFillPaint()
MultiLineTextPaintable.
public void setAnchorLocator(TextAnchor.Locator locator)
Sets the TextAnchor.Locator for this
MultiLineTextPaintable.
The following constants are provided in the class
TextAnchor as possible options for the
TextAnchor.Locator parameter:
TextAnchor.LEFT_BASELINETextAnchor.RIGHT_BASELINETextAnchor.CENTER_BASELINETextAnchor.LEFT_ASCENTLINETextAnchor.RIGHT_ASCENTLINETextAnchor.CENTER_ASCENTLINETextAnchor.LEFT_DESCENTLINETextAnchor.RIGHT_DESCENTLINETextAnchor.CENTER_DESCENTLINETextAnchor.LEFT_LEADINGLINETextAnchor.RIGHT_LEADINGLINETextAnchor.CENTER_LEADINGLINEIf the given locator is null, it is set to
TextAnchor.LEFT_ASCENTLINE.
Fires property change: SET_ANCHOR_LOCATOR.
locator - the locator for the anchor positionpublic TextAnchor.Locator getAnchorLocator()
Returns the TextAnchor.Locator for this
MultiLineTextPaintable.
public void setAnchorPosition(float anchorX,
float anchorY)
Sets the anchor position for the first line of
this MultiLineTextPaintable.
The anchor position for each subsequent line is then adjusted appropriately.
Fires property change: SET_ANCHOR_POSITION.
anchorX - the anchor x-coordinateanchorY - the anchor y-coordinatepublic void setAnchorPosition(float[] position)
Sets the anchor position for the first line of
this MultiLineTextPaintable
using an array float[2].
The anchor position for each subsequent line is then adjusted appropriately.
A null parameter is ignored.
Fires property change: SET_ANCHOR_POSITION.
position - the anchor position
public void shiftAnchorPosition(float dx,
float dy)
Shift the anchor position for each line of this
MultiLineTextPaintable
by the given dx and dy.
Fires property change: SET_ANCHOR_POSITION.
dx - the shift in the anchor x positiondy - the shift in the anchor y positionpublic float[] getAnchorPosition()
MultiLineTextPaintable
as an array float[2].
public XPoint2D getOriginalCenter()
Returns a copy of the center of the paint region affected
by the originalPaint method.
If the user has set a default original position then that is returned. Otherwise, we define the original center to be the anchor position. This will usually not be the geometric center.
getOriginalCenter in interface PaintablegetOriginalCenter in class AbstractPaintable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||