com.miginfocom.ashape.shapes
Class TextAShape

java.lang.Object
  extended by com.miginfocom.ashape.shapes.AbstractAShape
      extended by com.miginfocom.ashape.shapes.TextAShape
All Implemented Interfaces:
AShape, PropertyProvider, StringProvider
Direct Known Subclasses:
FittingTextAShape

public class TextAShape
extends AbstractAShape
implements StringProvider

A shape that can draw text of different kinds. Rotated 90 degrees clock- or counter clock wise, multi line or singe line text.

The following attibutes is currently used by this shape:
A_TEXT_TYPE
A_TEXT_SHADOW_OFFSET
A_TEXT_SHADOW_COLOR
A_TEXT_LAYOUT_PADDING
A_TEXT_NO_OPTIMIZE_CLIP
A_TEXT_LINE_SPACE_CORRECTION
AShape.A_ALIGN_X
AShape.A_ALIGN_Y
AShape.A_ANTI_ALIAS
AShape.A_FONT
AShape.A_TEXT
Note that any attributes used by AbstractAShape will also be adhered to.


Field Summary
static PropertyKey A_TEXT_LAYOUT_PADDING
          Value type: Dimension or null.
static PropertyKey A_TEXT_LINE_SPACE_CORRECTION
          Value type: Integer or null.
static PropertyKey A_TEXT_NO_OPTIMIZE_CLIP
          Value type: Boolean.
static PropertyKey A_TEXT_SHADOW_COLOR
          Value type: Color.
static PropertyKey A_TEXT_SHADOW_OFFSET
          Value type: Point.
static PropertyKey A_TEXT_TYPE
          Value type: Integer, not null.
static char TEMPLATE_CHAR
           
static int TYPE_SINGE_LINE
          Deprecated. Typo
static int TYPE_SINGE_LINE_ROT_CCW
          Deprecated. Typo
static int TYPE_SINGE_LINE_ROT_CW
          Deprecated. Typo
static int TYPE_SINGLE_LINE
          Writes a single line, much faster than TYPE_WRAP_TEXT and should be used if text wrapping isn't needed.
static int TYPE_SINGLE_LINE_ROT_CCW
          Writes a single line rotated counter clockwise 90 degrees
static int TYPE_SINGLE_LINE_ROT_CW
          Writes a single line rotated clockwise 90 degrees
static int TYPE_WRAP_TEXT
          Wraps text at line/word boundary
 
Fields inherited from class com.miginfocom.ashape.shapes.AbstractAShape
hitShape, RETURN_LIVE_ATTR_MAP, SIZE_CONV_MAP
 
Fields inherited from interface com.miginfocom.ashape.shapes.AShape
A_ALIGN_X, A_ALIGN_Y, A_ANTI_ALIAS, A_BORDER, A_CLIP_TYPE, A_COMPOSITE, A_CROP, A_CROP_TO_VISIBILITY_BOUNDS, A_FONT, A_HIT_AREA_Z, A_ICON, A_IMAGE, A_INHERIT, A_LAYOUT, A_MAXIMUM_HEIGHT, A_MAXIMUM_WIDTH, A_MINIMUM_HEIGHT, A_MINIMUM_WIDTH, A_MOUSE_CURSOR, A_PAINT, A_PAINT_LAYER, A_PLACE_RECT, A_PREFERRED_HEIGHT, A_PREFERRED_WIDTH, A_REPORT_HIT_AREA, A_SHADOW_TARGET_PAINT, A_SHAPE, A_SHAPES, A_STROKE, A_SUB_SHAPE_SORTER, A_TEXT, A_TEXTURE_PAINT_ANCHOR, A_UNDERLINE_HEIGHT, A_VISIBILITY, A_WRAPPED_ASHAPE, CLIP_PARENT_BOUNDS, CLIP_PARENT_SHAPE
 
Constructor Summary
TextAShape()
          Empty constructor for XML builders.
TextAShape(java.lang.String name, java.lang.String templateText, PlaceRect placeRect, int type, java.awt.Font font, java.awt.Paint paint)
          Contructor for center/center alignmenment and wonät change anti aliasing from parent shape.
TextAShape(java.lang.String name, java.lang.String templateText, PlaceRect placeRect, int type, java.awt.Font font, java.awt.Paint paint, AtRefRangeNumber alignX, AtRefRangeNumber alignY, java.lang.Boolean antiAlias)
          Deprecated. Use the constructor with an int for the antiAliasHint.
TextAShape(java.lang.String name, java.lang.String templateText, PlaceRect placeRect, int type, java.awt.Font font, java.awt.Paint paint, AtRefRangeNumber alignX, AtRefRangeNumber alignY, java.lang.Boolean antiAlias, java.awt.Point shdOff, java.awt.Color shdColor)
          Deprecated. Use the constructor with an int for the antiAliasHint.
TextAShape(java.lang.String name, java.lang.String templateText, PlaceRect placeRect, int type, java.awt.Font font, java.awt.Paint paint, AtRefRangeNumber alignX, AtRefRangeNumber alignY, int antiAliasHint)
          Contructor
TextAShape(java.lang.String name, java.lang.String templateText, PlaceRect placeRect, int type, java.awt.Font font, java.awt.Paint paint, AtRefRangeNumber alignX, AtRefRangeNumber alignY, int antiAliasHint, java.awt.Point shdOff, java.awt.Color shdColor)
          Contructor
 
Method Summary
protected  java.lang.String expand(java.lang.String tText)
          Expands text by replacing text surrounded by $ signs with the overiding object with the name between the signs.
 java.awt.Shape getHitBounds(boolean forceCalcualte)
          Returns the bounds that this attributed shape's actual content spans.
 java.lang.Integer getLayoutSize(int type, int dim, java.lang.Integer otherDimSizeHint)
          Returns the min, max or preferred size in the horizontal or vertical dimension.
 java.awt.Dimension getNaturalSize()
          Returns the size that the shape finds most natural.
 java.lang.String getString(int ix)
          Returns the string for the index.
 int getStringCount()
          Returns the number of strings this provider can provide.
 java.awt.Shape paintShape(java.awt.Graphics2D g2, java.awt.Shape clip, java.awt.Rectangle visRect)
          Paints this shape only.
 void setUseClipOptimize(boolean b)
          Sets whether the shape should defer from painting the text if the paint bounds (translated place rect) isn't overlapping current clip.
 
Methods inherited from class com.miginfocom.ashape.shapes.AbstractAShape
addAttributes, addSubShape, addSubShape, addToHitShapeList, containsProperty, getAttribute, getAttributes, getClipShape, getDoubleAttribute, getFloatAttribute, getHitShape, getIntAttribute, getLayout, getLongAttribute, getModCount, getName, getPaintLayer, getParent, getProperty, getReferenceBounds, getRoot, getShapeBounds, getSubShapeDeep, getSubShapes, getSubShapesImpl, hasAttribute, increaseModCount, isRoot, isVisible, layout, paintBorder, paintSubTree, removeAttribute, removeSubShape, setAttribute, setAttributeDeep, setAttributes, setHitShape, setName, setParent, setReferenceBounds, setReferenceBounds, setSubShapes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

A_TEXT_TYPE

public static final PropertyKey A_TEXT_TYPE
Value type: Integer, not null. E.g. TYPE_SINGE_LINE_ROT_CCW


A_TEXT_SHADOW_OFFSET

public static final PropertyKey A_TEXT_SHADOW_OFFSET
Value type: Point. Optional offset for text shadow. If null no shadow will be painted.


A_TEXT_SHADOW_COLOR

public static final PropertyKey A_TEXT_SHADOW_COLOR
Value type: Color. Optional color for text shadow. If null no shadow will be painted.


A_TEXT_LAYOUT_PADDING

public static final PropertyKey A_TEXT_LAYOUT_PADDING
Value type: Dimension or null. When a text shape is calculating it's min/max/preferred layout size it is taking this padding into account as well, basically adding it to the returned size.
Note that the text will not be repositioned in any way depending in this attribute.


A_TEXT_NO_OPTIMIZE_CLIP

public static final PropertyKey A_TEXT_NO_OPTIMIZE_CLIP
Value type: Boolean. If not null and false turns off clip optimization. See setUseClipOptimize(boolean).


A_TEXT_LINE_SPACE_CORRECTION

public static final PropertyKey A_TEXT_LINE_SPACE_CORRECTION
Value type: Integer or null. Corrects the line spacing if type is TYPE_WRAP_TEXT. Normally a value of -2 gives a more space efficient text, yet still not "cramped". -2 is default. See setUseClipOptimize(boolean).


TEMPLATE_CHAR

public static final char TEMPLATE_CHAR
See Also:
Constant Field Values

TYPE_WRAP_TEXT

public static final int TYPE_WRAP_TEXT
Wraps text at line/word boundary

See Also:
TYPE_SINGLE_LINE, Constant Field Values

TYPE_SINGLE_LINE

public static final int TYPE_SINGLE_LINE
Writes a single line, much faster than TYPE_WRAP_TEXT and should be used if text wrapping isn't needed.

See Also:
Constant Field Values

TYPE_SINGLE_LINE_ROT_CW

public static final int TYPE_SINGLE_LINE_ROT_CW
Writes a single line rotated clockwise 90 degrees

See Also:
Constant Field Values

TYPE_SINGLE_LINE_ROT_CCW

public static final int TYPE_SINGLE_LINE_ROT_CCW
Writes a single line rotated counter clockwise 90 degrees

See Also:
Constant Field Values

TYPE_SINGE_LINE

public static final int TYPE_SINGE_LINE
Deprecated. Typo
See Also:
Constant Field Values

TYPE_SINGE_LINE_ROT_CW

public static final int TYPE_SINGE_LINE_ROT_CW
Deprecated. Typo
See Also:
Constant Field Values

TYPE_SINGE_LINE_ROT_CCW

public static final int TYPE_SINGE_LINE_ROT_CCW
Deprecated. Typo
See Also:
Constant Field Values
Constructor Detail

TextAShape

public TextAShape()
Empty constructor for XML builders.


TextAShape

public TextAShape(java.lang.String name,
                  java.lang.String templateText,
                  PlaceRect placeRect,
                  int type,
                  java.awt.Font font,
                  java.awt.Paint paint)
Contructor for center/center alignmenment and wonät change anti aliasing from parent shape.

Parameters:
name - The name used for referencing this shape/sub shape
templateText - The text template (or regular text) that may contain templates to be expanded and then painted.
placeRect - How the shape will fill the bounds (or the parent's bounds)
font - The font to use. Not null.
paint - The paint to use.
type - If the text should word/line wrap at end of rectangle. E.g. TYPE_WRAP_TEXT
See Also:
AtRefRangeNumber, AtStart, AtEnd, AtFraction

TextAShape

public TextAShape(java.lang.String name,
                  java.lang.String templateText,
                  PlaceRect placeRect,
                  int type,
                  java.awt.Font font,
                  java.awt.Paint paint,
                  AtRefRangeNumber alignX,
                  AtRefRangeNumber alignY,
                  java.lang.Boolean antiAlias)
Deprecated. Use the constructor with an int for the antiAliasHint.

Contructor

Parameters:
name - The name used for referencing this shape/sub shape
templateText - The text template (or regular text) that may contain templates to be expanded and then painted.
placeRect - How the shape will fill the bounds (or the parent's bounds)
type - If the text should word/line wrap at end of rectangle. E.g. TYPE_WRAP_TEXT
font - The font to use. Not null.
paint - The paint to use.
alignX - The x (horizontal) alignment. E.g. new AtFraction(0.2f) or new AtStart(10f).
alignY - The y (vertical) alignment. E.g. new AtFraction(1f) or new AtEnd(-10f).
antiAlias - If anti alias should be turned on, or off. if null the hint will not be changed
See Also:
AtRefRangeNumber, AtStart, AtEnd, AtFraction

TextAShape

public TextAShape(java.lang.String name,
                  java.lang.String templateText,
                  PlaceRect placeRect,
                  int type,
                  java.awt.Font font,
                  java.awt.Paint paint,
                  AtRefRangeNumber alignX,
                  AtRefRangeNumber alignY,
                  java.lang.Boolean antiAlias,
                  java.awt.Point shdOff,
                  java.awt.Color shdColor)
Deprecated. Use the constructor with an int for the antiAliasHint.

Contructor

Parameters:
name - The name used for referencing this shape/sub shape
templateText - The text template (or regular text) that may contain templates to be expanded and then painted.
placeRect - How the shape will fill the bounds (or the parent's bounds)
type - If the text should word/line wrap at end of rectangle. E.g. TYPE_WRAP_TEXT
font - The font to use. Not null.
paint - The paint to use.
alignX - The x (horizontal) alignment. E.g. new AtFraction(0.2f) or new AtStart(10f).
alignY - The y (vertical) alignment. E.g. new AtFraction(1f) or new AtEnd(-10f).
antiAlias - If anti alias should be turned on, or off. if null the hint will not be changed.
shdOff - The offset to draw a second text, problably a shadow.
shdColor - The color to draw the second (probably shadow) string with
See Also:
AtRefRangeNumber, AtStart, AtEnd, AtFraction

TextAShape

public TextAShape(java.lang.String name,
                  java.lang.String templateText,
                  PlaceRect placeRect,
                  int type,
                  java.awt.Font font,
                  java.awt.Paint paint,
                  AtRefRangeNumber alignX,
                  AtRefRangeNumber alignY,
                  int antiAliasHint)
Contructor

Parameters:
name - The name used for referencing this shape/sub shape
templateText - The text template (or regular text) that may contain templates to be expanded and then painted.
placeRect - How the shape will fill the bounds (or the parent's bounds)
type - If the text should word/line wrap at end of rectangle. E.g. TYPE_WRAP_TEXT
font - The font to use. Not null.
paint - The paint to use.
alignX - The x (horizontal) alignment. E.g. new AtFraction(0.2f) or new AtStart(10f).
alignY - The y (vertical) alignment. E.g. new AtFraction(1f) or new AtEnd(-10f).
antiAliasHint - The anti alias hint to set. E.g. GfxUtil.AA_HINT_ON
See Also:
AtRefRangeNumber, AtStart, AtEnd, AtFraction

TextAShape

public TextAShape(java.lang.String name,
                  java.lang.String templateText,
                  PlaceRect placeRect,
                  int type,
                  java.awt.Font font,
                  java.awt.Paint paint,
                  AtRefRangeNumber alignX,
                  AtRefRangeNumber alignY,
                  int antiAliasHint,
                  java.awt.Point shdOff,
                  java.awt.Color shdColor)
Contructor

Parameters:
name - The name used for referencing this shape/sub shape
templateText - The text template (or regular text) that may contain templates to be expanded and then painted.
placeRect - How the shape will fill the bounds (or the parent's bounds)
type - If the text should word/line wrap at end of rectangle. E.g. TYPE_WRAP_TEXT
font - The font to use. Not null.
paint - The paint to use.
alignX - The x (horizontal) alignment. E.g. new AtFraction(0.2f) or new AtStart(10f).
alignY - The y (vertical) alignment. E.g. new AtFraction(1f) or new AtEnd(-10f).
antiAliasHint - The anti alias hint to set. E.g. GfxUtil.AA_HINT_ON
shdOff - The offset to draw a second text, problably a shadow.
shdColor - The color to draw the second (probably shadow) string with
See Also:
AtRefRangeNumber, AtStart, AtEnd, AtFraction
Method Detail

paintShape

public java.awt.Shape paintShape(java.awt.Graphics2D g2,
                                 java.awt.Shape clip,
                                 java.awt.Rectangle visRect)
Description copied from interface: AShape
Paints this shape only. Called by AShape.paintSubTree(java.awt.Graphics2D, java.awt.Shape, java.awt.Rectangle, Integer).

Specified by:
paintShape in interface AShape
Parameters:
g2 - The object to draw in. Settings won't change. May be null in which case only the hit shape should be returned. This can be ued to get the layout size/shape.
clip - The shape to clip the graphics with. This shape is not already added to the clip if the Grahpics2D object sent in since this shape will also possible reduce the interaction area (hit area) that the shape presents. The Grahpics2D object's clip will not however since it may only be repainting a part of the shape. Can be null.
The difference to AShape.paintSubTree(java.awt.Graphics2D, java.awt.Shape, java.awt.Rectangle, java.lang.Integer)'s clip is that this clip should be obeyed blindly since paintAll has already filtered it depending on the values of attreibutes AShape.A_CROP_TO_VISIBILITY_BOUNDS and AShape.A_CLIP_TYPE.
visRect - Possibly outlines what is the outer bounds that is visible to the user. This might be for instance the bounds of the component. May be null.
Returns:
The shape of the content spanned. null if nothing was spanned. The returned shape can be the one sent in as well as a privately used shape. Do not change this shape. The sub shapes of this shape will relate to this returned shape.
See Also:
AShape.A_CROP_TO_VISIBILITY_BOUNDS, AShape.A_CLIP_TYPE

getHitBounds

public java.awt.Shape getHitBounds(boolean forceCalcualte)
Description copied from interface: AShape
Returns the bounds that this attributed shape's actual content spans.

For instance for a TextAShape this is the text's exact bounds. Its shape's bounds is the container in which the text is positioned.

Note that the returned rectangle might be expensive to calculate and usually means that for instance a text shape must do much if its work twise (once when calling this, which is usually during layout, and once again during paint). Caching of the bounds should be possible for implementing classes.

Specified by:
getHitBounds in interface AShape
Parameters:
forceCalcualte - If true the hit bounds will always be recaclulated and no caches used.
Returns:
A new Rectangle representing bounds that this attributed shape's actual content spans.

getNaturalSize

public java.awt.Dimension getNaturalSize()
Description copied from interface: AShape
Returns the size that the shape finds most natural. For instance an image shape would return the size of the image and a vector shape would return the bound's size of the Shape it has.

Specified by:
getNaturalSize in interface AShape
Returns:
The size or if indeteminable null.

getString

public java.lang.String getString(int ix)
Description copied from interface: StringProvider
Returns the string for the index. Throws exception if ix is >= the size

Specified by:
getString in interface StringProvider
Parameters:
ix - The index.
Returns:
The string for the index. Never null.

getStringCount

public int getStringCount()
Description copied from interface: StringProvider
Returns the number of strings this provider can provide.

Specified by:
getStringCount in interface StringProvider
Returns:
The number of strings this provider can provide.

getLayoutSize

public java.lang.Integer getLayoutSize(int type,
                                       int dim,
                                       java.lang.Integer otherDimSizeHint)
Description copied from interface: AShape
Returns the min, max or preferred size in the horizontal or vertical dimension. For instance a text shape would want to have a reference width to be able to calculate the preferred height. Also usable for shapes that want's to maintain some static aspect ratio or span a certain area.
This information is normally used by a AShapeLayout.
If no layout size is available for the shape, or any of its sub shape, and the preferred size is asked for, the natural size (for instance via AShape.getNaturalSize()) of the shape may be returned.

Specified by:
getLayoutSize in interface AShape
Overrides:
getLayoutSize in class AbstractAShape
Parameters:
type - The type of size to get. E.g. Distributor.MIN
dim - The dimension for which to return the layout size. E.g. SwingConstants.VERTICAL.
otherDimSizeHint - If the width/height layout size is interconnected is any way and the size in that other dimension is known already, that size if entered here.
Returns:
The size or null if there was no preference by any of the sub shapes.
See Also:
AShape.A_PREFERRED_WIDTH

expand

protected java.lang.String expand(java.lang.String tText)
Expands text by replacing text surrounded by $ signs with the overiding object with the name between the signs. For instance if "Hello, the start time is $startTime$" is in tText an attribute with the name startTime is looked up and replaced text between the $ signs (including the $ signs themselves).

Parameters:
tText - The template text to be expanded. May be null in which case null is returned.
Returns:
The expanded text or null if tText was null.

setUseClipOptimize

public void setUseClipOptimize(boolean b)
Sets whether the shape should defer from painting the text if the paint bounds (translated place rect) isn't overlapping current clip. The optimization may have to be turned off if the text's alignment (alignX and alignY) moves the text outside of the paint rect.
Default this optimization is on.

Parameters:
b - true means optimization on.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.