|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--edu.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.2, the method getBounds2D was modified to use the
default Bounds2D rectangle if that rectangle is non-null
before making any other tests or computations.
| Field Summary | |
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. |
| Fields inherited from class edu.neu.ccs.gui.AbstractPaintable |
SET_DEFAULT_BOUNDS2D, SET_DEFAULT_CENTER, SET_OPACITY, SET_VISIBLE |
| 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. |
|
TextPaintable(String string,
Font font)
The constructor that creates a TextPaintable with
the given string and font. |
|
TextPaintable(String string,
Font font,
Paint fillpaint)
The constructor that creates a TextPaintable with
the given string, font, and fill paint. |
|
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. |
|
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. |
|
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. |
|
| Method Summary | |
boolean |
contains(double x,
double y)
Tests if a point specified by coordinates is inside the paintable. |
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. |
Rectangle2D |
getBounds2D()
Returns the bounds of the paintable based on the default settings or on more detailed computations. |
TextBounds.Strategy |
getBoundsStrategy()
Returns the bounds strategy for this TextPaintable. |
Point2D |
getCenter()
Returns a copy of the center of the paint region affected by the paint method. |
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. |
Rectangle2D |
getLooseBounds()
Returns the smallest rectangle that contains the pair of rectangles getStringBounds() and getTightBounds(). |
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. |
Rectangle2D |
getStringBounds()
Returns a copy of the 2-dimensional bounds of the 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. |
Rectangle2D |
getTightBounds()
Returns a copy of the 2-dimensional bounds of the 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. |
void |
paint(Graphics g)
Paints onto a Graphics context g using information
from this object. |
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. |
| 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
| Constructor Detail |
public TextPaintable()
The constructor that creates a TextPaintable with
all defaults.
The default anchor position is (0, 0) which must be changed to a more useful value by the caller.
setString(String),
setFont(Font),
setFillPaint(Paint),
setBoundsStrategy(TextBounds.Strategy),
setAnchorLocator(TextAnchor.Locator),
setAnchorPosition(float, float),
setAnchorPosition(float[]),
TextPaintable(String),
TextPaintable(String, Font),
TextPaintable(String, Font, Paint),
TextPaintable(String, Font, Paint, TextBounds.Strategy),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator, float, float)public TextPaintable(String string)
The constructor that creates a TextPaintable with
the given string.
The default anchor position is (0, 0) which must be changed to a more useful value by the caller.
string - the string to displaysetString(String),
setFont(Font),
setFillPaint(Paint),
setBoundsStrategy(TextBounds.Strategy),
setAnchorLocator(TextAnchor.Locator),
setAnchorPosition(float, float),
setAnchorPosition(float[]),
TextPaintable(),
TextPaintable(String, Font),
TextPaintable(String, Font, Paint),
TextPaintable(String, Font, Paint, TextBounds.Strategy),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator, float, float)
public TextPaintable(String string,
Font font)
The constructor that creates a TextPaintable with
the given string and font.
The default anchor position is (0, 0) which must be changed to a more useful value by the caller.
string - the string to displayfont - the font to use to display the stringsetString(String),
setFont(Font),
setFillPaint(Paint),
setBoundsStrategy(TextBounds.Strategy),
setAnchorLocator(TextAnchor.Locator),
setAnchorPosition(float, float),
setAnchorPosition(float[]),
TextPaintable(),
TextPaintable(String),
TextPaintable(String, Font, Paint),
TextPaintable(String, Font, Paint, TextBounds.Strategy),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator, float, float)
public TextPaintable(String string,
Font font,
Paint fillpaint)
The constructor that creates a TextPaintable with
the given string, font, and fill paint.
The default anchor position is (0, 0) which must be changed to a more useful value by the caller.
string - the string to displayfont - the font to use to display the stringfillpaint - the paint to use to fill the stringsetString(String),
setFont(Font),
setFillPaint(Paint),
setBoundsStrategy(TextBounds.Strategy),
setAnchorLocator(TextAnchor.Locator),
setAnchorPosition(float, float),
setAnchorPosition(float[]),
TextPaintable(),
TextPaintable(String),
TextPaintable(String, Font),
TextPaintable(String, Font, Paint, TextBounds.Strategy),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator, float, float)
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.
The default anchor position is (0, 0) which must be changed to a more useful value by the caller.
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 boundssetString(String),
setFont(Font),
setFillPaint(Paint),
setBoundsStrategy(TextBounds.Strategy),
setAnchorLocator(TextAnchor.Locator),
setAnchorPosition(float, float),
setAnchorPosition(float[]),
TextPaintable(),
TextPaintable(String),
TextPaintable(String, Font),
TextPaintable(String, Font, Paint),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator, float, float)
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.
The default anchor position is (0, 0) which must be changed to a more useful value by the caller.
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 positionsetString(String),
setFont(Font),
setFillPaint(Paint),
setBoundsStrategy(TextBounds.Strategy),
setAnchorLocator(TextAnchor.Locator),
setAnchorPosition(float, float),
setAnchorPosition(float[]),
TextPaintable(),
TextPaintable(String),
TextPaintable(String, Font),
TextPaintable(String, Font, Paint),
TextPaintable(String, Font, Paint, TextBounds.Strategy),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator, float, float)
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:
string: "" font: getDefaultFont() fillpaint: Color.black strategy: TextBounds.LOOSE locator: TextAnchor.LEFT_BASELINE
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-coordinatesetString(String),
setFont(Font),
setFillPaint(Paint),
setBoundsStrategy(TextBounds.Strategy),
setAnchorLocator(TextAnchor.Locator),
setAnchorPosition(float, float),
setAnchorPosition(float[]),
TextPaintable(),
TextPaintable(String),
TextPaintable(String, Font),
TextPaintable(String, Font, Paint),
TextPaintable(String, Font, Paint, TextBounds.Strategy),
TextPaintable(String, Font, Paint, TextBounds.Strategy, TextAnchor.Locator)| Method Detail |
public final void paint(Graphics g)
Paints onto a Graphics context g using information
from this object.
Does nothing if the encapsulated text string has zero length.
paint in interface Paintablepaint in class AbstractPaintableg - the graphics context on which to paintAbstractPaintable.getPreparedGraphics2D(Graphics)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 final Rectangle2D getStringBounds()
Returns a copy of the 2-dimensional bounds of the 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.
getTightBounds(),
getLooseBounds(),
getBounds2D()public final Rectangle2D getTightBounds()
Returns a copy of the 2-dimensional bounds of the 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.
getStringBounds(),
getLooseBounds(),
getBounds2D()public final Rectangle2D 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.
getStringBounds(),
getTightBounds(),
getBounds2D()public final Rectangle2D getBounds2D()
Returns the bounds of the paintable based on the default settings or on more detailed computations.
If the value of getDefaultBounds2D is non-null,
then this value is returned.
Otherwise, if the encapsulated text string has zero length, then returns a rectangle of zero width and height located at the anchor location.
Otherwise, returns a copy of the 2-dimensional bounds of the paint
region affected by the paint method according to the
current bounds strategy.
getBounds2D in interface PaintablegetBounds2D in class AbstractPaintablegetStringBounds(),
getTightBounds(),
getLooseBounds()public final Point2D getCenter()
Returns a copy of the center of the paint region affected
by the paint method.
The center is computed as the center of the base line.
This method uses the anchor locator.
getCenter in interface PaintablegetCenter in class AbstractPaintableAbstractPaintable.setDefaultCenter(Point2D),
AbstractPaintable.getDefaultCenter()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 object
public boolean contains(double x,
double y)
Tests if a point specified by coordinates is inside the paintable.
This method returns false if one or more of the following
conditions occurs:
getBounds2D.isVisible returns false.
x - the x-coordinate of the pointy - the y-coordinate of the point
public final 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 displaygetString()public final String getString()
TextPaintable.
setString(String)public final 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 stringgetFont()public final Font getFont()
TextPaintable.
setFont(Font)public final 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 stringgetFillPaint()public final Paint getFillPaint()
TextPaintable.
setFillPaint(Paint)public final 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 boundsgetBoundsStrategy()public final TextBounds.Strategy getBoundsStrategy()
TextPaintable.
setFillPaint(Paint)public final 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_BASELINE.
Fires property change: SET_ANCHOR_LOCATOR.
locator - the locator for the anchor positiongetAnchorLocator()public final TextAnchor.Locator getAnchorLocator()
Returns the TextAnchor.Locator for this
TextPaintable.
setAnchorLocator(TextAnchor.Locator)
public final 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-coordinatesetAnchorPosition(float[]),
getAnchorPosition()public final 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 positionsetAnchorPosition(float, float),
getAnchorPosition()public final float[] getAnchorPosition()
TextPaintable
as an array float[2].
setAnchorPosition(float, float),
setAnchorPosition(float[])public final float getLeftX()
Returns the left x-coordinate of this TextPaintable.
This method uses the anchor locator.
public final float getRightX()
Returns the right x-coordinate of this TextPaintable.
This method uses the anchor locator.
public final float getCenterX()
Returns the center x-coordinate of this TextPaintable.
This method uses the anchor locator.
public final float getBaseLineY()
Returns the base line y-coordinate of this TextPaintable.
This method uses the anchor locator.
public final float getAscentLineY()
Returns the ascent line y-coordinate of this TextPaintable.
This method uses the anchor locator.
public final float getDescentLineY()
Returns the descent line y-coordinate of this TextPaintable.
This method uses the anchor locator.
public final float getLeadingLineY()
Returns the leading line y-coordinate of this TextPaintable.
This methods uses the anchor locator.
public final float getWidth()
Returns the width of the area that will be occupied by this
TextPaintable.
This method uses the method getBounds2D.
public final 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 font
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||