|
||||||||||
| 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.TextPaintable
A TextPaintable creates a Paintable
using a string, a font, and other related data.
In 2.3.5, the class was refactored to be consistent with
the new Paintable interface and
the new AbstractPaintable class.
In 2.4.0, the default anchor locator was changed from
TextAnchor.LEFT_BASELINE to
TextAnchor.LEFT_ASCENTLINE. The rationale for
this change is to allow text with the default anchor locator
and default anchor position of (0, 0) to be visible in a
panel or window whose upper left corner is also (0, 0). In
practice, a user is likely to want to set the anchor locator
and anchor position explicitly but this new default makes it
easier to do quick testing.
In 2.4.0, several constructors were added that permit the anchor locator and anchor position to be set without specifying other parameters.
In 2.4.0, this class was also updated to be consistent with
refinements to the Paintable interface.
In 2.6.0, changed getOriginalCenter() to return
a point equal to the anchor position unless the caller has set
a specific default original position.
In 2.6.0, changed setAnchorPostion by calling a
new method shiftAnchorPostion. This method makes
an adjustment to the internal mutator so that the net effect is
visually the same as if the shift had been applied by calling
the move method on the mutated paintable.
In 2.6.0, removed final designations on methods to allow for overrides.
MultiLineTextPaintable| 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_BOUNDS_STRATEGY
Bound property name for set bounds strategy. |
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. |
static FontRenderContext |
standardFRC
The standard font render context defined using the identity transform, anti-aliasing on, and fractional-metrics off. |
private TextBounds.Strategy |
strategy
The text bounds strategy. |
private String |
string
The text string. |
private TextLayout |
textLayout
The TextLayout for bounds computation and text rendering. |
| 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 | |
TextPaintable()
The constructor that creates a TextPaintable with
all defaults. |
|
TextPaintable(String string)
The constructor that creates a TextPaintable with
the given string
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string and anchor position
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
Font font)
The constructor that creates a TextPaintable with
the given string and font
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
Font font,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, and anchor position
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
Font font,
Paint fillpaint)
The constructor that creates a TextPaintable with
the given string, font, and fill paint
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
Font font,
Paint fillpaint,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, fill paint, and anchor position
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
Font font,
Paint fillpaint,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, fill paint, anchor locator, and anchor position
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
Font font,
Paint fillpaint,
TextBounds.Strategy strategy)
The constructor that creates a TextPaintable with
the given string, font, fill paint, and bounds strategy
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
Font font,
Paint fillpaint,
TextBounds.Strategy strategy,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, fill paint, bounds strategy, and anchor
position
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
Font font,
Paint fillpaint,
TextBounds.Strategy strategy,
TextAnchor.Locator locator)
The constructor that creates a TextPaintable with
the given string, font, fill paint, bounds strategy, and anchor
locator
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
Font font,
Paint fillpaint,
TextBounds.Strategy strategy,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, fill paint, bounds strategy, anchor locator,
and anchor position. |
|
TextPaintable(String string,
Font font,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, anchor locator, and anchor position
and with the defaults set as described in the default constructor. |
|
TextPaintable(String string,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, anchor locator, and anchor position
and with the defaults set as described in the default constructor. |
|
| Method Summary | |
XRect |
getActualBounds2D()
Returns the actual bounds of the original paintable or null if the paintable is effectively empty. |
TextAnchor.Locator |
getAnchorLocator()
Returns the TextAnchor.Locator for this
TextPaintable. |
float[] |
getAnchorPosition()
Returns a copy of the anchor position for this TextPaintable
as an array float[2]. |
float |
getAscentLineY()
Returns the ascent line y-coordinate of this TextPaintable. |
float |
getBaseLineY()
Returns the base line y-coordinate of this TextPaintable. |
TextBounds.Strategy |
getBoundsStrategy()
Returns the bounds strategy for this TextPaintable. |
float |
getCenterX()
Returns the center x-coordinate of this TextPaintable. |
static Font |
getDefaultFont()
Returns the default font for a JLabel in the
current UI settings. |
float |
getDescentLineY()
Returns the descent line y-coordinate of this TextPaintable. |
Paint |
getFillPaint()
Returns the fill paint for this TextPaintable. |
Font |
getFont()
Returns the font for this TextPaintable. |
float |
getHeight()
Returns the height of the area that will be occupied by this TextPaintable. |
float |
getLeadingLineY()
Returns the leading line y-coordinate of this TextPaintable. |
float |
getLeftX()
Returns the left x-coordinate of this TextPaintable. |
XRect |
getLooseBounds()
Returns the smallest rectangle that contains the pair of rectangles getStringBounds() and getTightBounds(). |
XPoint2D |
getOriginalCenter()
Returns a copy of the center of the paint region affected by the originalPaint method. |
Shape |
getOutline()
Returns the Shape that represents the outline of
the rendered text string in its font at its location. |
float |
getRightX()
Returns the right x-coordinate of this TextPaintable. |
String |
getString()
Returns the string for this TextPaintable. |
XRect |
getStringBounds()
Returns a copy of the 2-dimensional bounds of the original paint region as computed using the getStringBounds
method of the Font class together with the anchor
locator. |
TextLayout |
getTextLayout()
Returns the internal TextLayout that encapsulates
the text string and the font. |
XRect |
getTightBounds()
Returns a copy of the 2-dimensional bounds of the original paint region as computed using the getBounds method
of the TextLayout class together with the anchor
locator. |
float |
getWidth()
Returns the width of the area that will be occupied by this TextPaintable. |
boolean |
originalContains(double x,
double y)
Tests if a point specified by coordinates is inside the original paintable without mutation. |
void |
originalPaint(Graphics g)
Paints onto a Graphics context using information
from this object but without the use of the mutator transform. |
private void |
resetTextLayout()
Resets the text layout on string or font change. |
void |
setAnchorLocator(TextAnchor.Locator locator)
Sets the TextAnchor.Locator for this
TextPaintable. |
void |
setAnchorPosition(float[] position)
Sets the anchor position for this TextPaintable
using an array float[2]. |
void |
setAnchorPosition(float anchorX,
float anchorY)
Sets the anchor position for this TextPaintable. |
void |
setBoundsStrategy(TextBounds.Strategy strategy)
Sets the bounds strategy for this TextPaintable. |
void |
setFillPaint(Paint fillpaint)
Sets the fill paint for this TextPaintable. |
void |
setFont(Font font)
Sets the font for this TextPaintable. |
void |
setString(String string)
Sets the string for this TextPaintable. |
void |
shiftAnchorPosition(float dx,
float dy)
Shift the anchor position by the given dx and dy. |
| 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
public static final String SET_BOUNDS_STRATEGY
public static final FontRenderContext standardFRC
private String string
private Font font
private Paint fillpaint
private TextBounds.Strategy strategy
private TextAnchor.Locator locator
private float anchorX
private float anchorY
private TextLayout textLayout
| Constructor Detail |
public TextPaintable()
The constructor that creates a TextPaintable with
all defaults.
string: ""
font: getDefaultFont()
fillpaint: Color.black
strategy: TextBounds.LOOSE
locator: TextAnchor.LEFT_ASCENTLINE
anchorX: 0
anchorY: 0
public TextPaintable(String string)
The constructor that creates a TextPaintable with
the given string
and with the defaults set as described in the default constructor.
string - the string to displayTextPaintable()
public TextPaintable(String string,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string and anchor position
and with the defaults set as described in the default constructor.
string - the string to displayanchorX - the anchor x-coordinateanchorY - the anchor y-coordinateTextPaintable()
public TextPaintable(String string,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, anchor locator, and anchor position
and with the defaults set as described in the default constructor.
string - the string to displaylocator - the locator for the anchor positionanchorX - the anchor x-coordinateanchorY - the anchor y-coordinateTextPaintable()
public TextPaintable(String string,
Font font)
The constructor that creates a TextPaintable with
the given string and font
and with the defaults set as described in the default constructor.
string - the string to displayfont - the font to use to display the stringTextPaintable()
public TextPaintable(String string,
Font font,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, and anchor position
and with the defaults set as described in the default constructor.
string - the string to displayfont - the font to use to display the stringanchorX - the anchor x-coordinateanchorY - the anchor y-coordinateTextPaintable()
public TextPaintable(String string,
Font font,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, anchor locator, and anchor position
and with the defaults set as described in the default constructor.
string - the string to displayfont - the font to use to display the stringlocator - the locator for the anchor positionanchorX - the anchor x-coordinateanchorY - the anchor y-coordinateTextPaintable()
public TextPaintable(String string,
Font font,
Paint fillpaint)
The constructor that creates a TextPaintable with
the given string, font, and fill paint
and with the defaults set as described in the default constructor.
string - the string to displayfont - the font to use to display the stringfillpaint - the paint to use to fill the stringTextPaintable()
public TextPaintable(String string,
Font font,
Paint fillpaint,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, fill paint, and anchor position
and with the defaults set as described in the default constructor.
string - the string to displayfont - the font to use to display the stringfillpaint - the paint to use to fill the stringanchorX - the anchor x-coordinateanchorY - the anchor y-coordinateTextPaintable()
public TextPaintable(String string,
Font font,
Paint fillpaint,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, fill paint, anchor locator, and anchor position
and with the defaults set as described in the default constructor.
string - the string to displayfont - 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-coordinateanchorY - the anchor y-coordinateTextPaintable()
public TextPaintable(String string,
Font font,
Paint fillpaint,
TextBounds.Strategy strategy)
The constructor that creates a TextPaintable with
the given string, font, fill paint, and bounds strategy
and with the defaults set as described in the default constructor.
string - the string to displayfont - the font to use to display the stringfillpaint - the paint to use to fill the stringstrategy - the strategy to use to compute the paintable boundsTextPaintable()
public TextPaintable(String string,
Font font,
Paint fillpaint,
TextBounds.Strategy strategy,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, fill paint, bounds strategy, and anchor
position
and with the defaults set as described in the default constructor.
string - the string to displayfont - the font to use to display the stringfillpaint - the paint to use to fill the stringstrategy - the strategy to use to compute the paintable boundsanchorX - the anchor x-coordinateanchorY - the anchor y-coordinateTextPaintable()
public TextPaintable(String string,
Font font,
Paint fillpaint,
TextBounds.Strategy strategy,
TextAnchor.Locator locator)
The constructor that creates a TextPaintable with
the given string, font, fill paint, bounds strategy, and anchor
locator
and with the defaults set as described in the default constructor.
string - the string to displayfont - the font to use to display the stringfillpaint - the paint to use to fill the stringstrategy - the strategy to use to compute the paintable boundslocator - the locator for the anchor positionTextPaintable()
public TextPaintable(String string,
Font font,
Paint fillpaint,
TextBounds.Strategy strategy,
TextAnchor.Locator locator,
float anchorX,
float anchorY)
The constructor that creates a TextPaintable with
the given string, font, fill paint, bounds strategy, anchor locator,
and anchor position.
Parameters that are null are set to the following
defaults as in the default constructor:
string: ""
font: getDefaultFont()
fillpaint: Color.black
strategy: TextBounds.LOOSE
locator: TextAnchor.LEFT_ASCENTLINE
string - the string to displayfont - the font to use to display the stringfillpaint - the paint to use to fill the stringstrategy - the strategy to use to compute the paintable boundslocator - the locator for the anchor positionanchorX - the anchor x-coordinateanchorY - the anchor y-coordinateTextPaintable()| Method Detail |
public void originalPaint(Graphics g)
Paints onto a Graphics context using information
from this object but without the use of the mutator transform.
Does nothing if the encapsulated text string has zero length
or the graphics context is null.
originalPaint in interface PaintableoriginalPaint in class AbstractPaintableg - the graphics context on which to paintpublic XRect getActualBounds2D()
Returns the actual bounds of the original paintable or
null if the paintable is effectively empty.
getActualBounds2D in interface PaintablegetActualBounds2D in class AbstractPaintablepublic 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
public boolean originalContains(double x,
double y)
Tests if a point specified by coordinates is inside the original paintable without mutation.
originalContains in interface PaintableoriginalContains in class AbstractPaintablex - the x-coordinate of the pointy - the y-coordinate of the point
public TextLayout getTextLayout()
Returns the internal TextLayout that encapsulates
the text string and the font.
If the encapsulated text string has zero length, then returns
null.
TextLayout objectpublic XRect getStringBounds()
Returns a copy of the 2-dimensional bounds of the original
paint region as computed using the getStringBounds
method of the Font class together with the anchor
locator.
In the vertical direction, these bounds extend from the ascent line to the leading line. Thus, the height of these bounds do not depend on the particular string being rendered.
In the horizontal direction, these bounds extend from the left edge of string being painted and will include allowances for both leading and trailing white space. Unfortunately, however, if the string has no leading and trailing whitespace, it is possible for pixels to be painted outside of these bounds due to serifs or to the slant of an italic font.
If the encapsulated text string has zero length, then this method returns a rectangle at the anchor position of zero width and height.
public XRect getTightBounds()
Returns a copy of the 2-dimensional bounds of the original
paint region as computed using the getBounds method
of the TextLayout class together with the anchor
locator.
These bounds return a tight rectangle that includes all pixel positions that may be modified when the string is painted. The only exception to this rule is that anti-aliasing may cause some pixels adjacent to this rectangle to be rendered also. There is no Java code that is capable of testing for this effect.
The height of these bounds will vary from string to string depending on the height of the ascenders and descenders of the particular characters in the particular string.
These bounds do not include leading and trailing whitespace.
Be aware that if you have set the logical left edge of the paint area for a string to some value x then it is still possible for pixels to the left of x to be modified during rendering of the string due to the presence of serifs. The bounds returned by this method will include adjustments for such effects and will be as accurate as possible.
If the encapsulated text string has zero length, then this method returns a rectangle at the anchor position of zero width and height.
public XRect getLooseBounds()
Returns the smallest rectangle that contains the pair of rectangles
getStringBounds() and getTightBounds().
These bounds return a loose rectangle that includes all pixel positions that may be modified when the string is painted plus allowances for additional horizontal and vertical white space.
If the encapsulated text string has zero length, then this method returns a rectangle at the anchor position of zero width and height.
public Shape getOutline()
Returns the Shape that represents the outline of
the rendered text string in its font at its location.
Experimental tests show that the Shape returned
by this method is not 100% accurate. This is due to problems
in the getOutline method of the Java class
TextLayout.
If the encapsulated text string has zero length, then returns
an empty Shape.
Shape objectpublic void setString(String string)
Sets the string for this TextPaintable.
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 displaypublic String getString()
TextPaintable.
public void setFont(Font font)
Sets the font for this TextPaintable.
If the given font is null then it is set to
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()
TextPaintable.
public void setFillPaint(Paint fillpaint)
Sets the fill paint for this TextPaintable.
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()
TextPaintable.
public void setBoundsStrategy(TextBounds.Strategy strategy)
Sets the bounds strategy for this TextPaintable.
If the given strategy is null, it is set to
TextBounds.LOOSE.
Fires property change: SET_BOUNDS_STRATEGY.
strategy - the strategy to use to compute the paintable boundspublic TextBounds.Strategy getBoundsStrategy()
TextPaintable.
public void setAnchorLocator(TextAnchor.Locator locator)
Sets the TextAnchor.Locator for this
TextPaintable.
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
TextPaintable.
public void setAnchorPosition(float anchorX,
float anchorY)
Sets the anchor position for this TextPaintable.
Fires property change: SET_ANCHOR_POSITION.
anchorX - the anchor x-coordinateanchorY - the anchor y-coordinatepublic void setAnchorPosition(float[] position)
Sets the anchor position for this TextPaintable
using an array float[2].
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 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()
TextPaintable
as an array float[2].
public float getLeftX()
Returns the left x-coordinate of this TextPaintable.
This method uses the anchor locator.
public float getRightX()
Returns the right x-coordinate of this TextPaintable.
This method uses the anchor locator.
public float getCenterX()
Returns the center x-coordinate of this TextPaintable.
This method uses the anchor locator.
public float getBaseLineY()
Returns the base line y-coordinate of this TextPaintable.
This method uses the anchor locator.
public float getAscentLineY()
Returns the ascent line y-coordinate of this TextPaintable.
This method uses the anchor locator.
public float getDescentLineY()
Returns the descent line y-coordinate of this TextPaintable.
This method uses the anchor locator.
public float getLeadingLineY()
Returns the leading line y-coordinate of this TextPaintable.
This methods uses the anchor locator.
public float getWidth()
Returns the width of the area that will be occupied by this
TextPaintable.
This method uses the method getBounds2D.
public float getHeight()
Returns the height of the area that will be occupied by this
TextPaintable.
This method uses the method getBounds2D.
public static Font getDefaultFont()
Returns the default font for a JLabel in the
current UI settings. This font is used in constructing a
TextPaintable if the user does not specify a
font.
JLabel default fontprivate void resetTextLayout()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||