edu.umd.cs.piccolo.nodes
Class PText

java.lang.Object
  extended by edu.umd.cs.piccolo.PNode
      extended by edu.umd.cs.piccolo.nodes.PText
All Implemented Interfaces:
Printable, Serializable, Cloneable

public class PText
extends PNode

PText is a multi-line text node. The text will flow to base on the width of the node's bounds.

Version:
1.1
Author:
Jesse Grosjean
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.PNode
PNode.PSceneGraphDelegate
 
Field Summary
static Font DEFAULT_FONT
          Default font, 12 point "SansSerif".
static double DEFAULT_GREEK_THRESHOLD
          Default greek threshold, 5.5d.
static float DEFAULT_HORIZONTAL_ALIGNMENT
          Default horizontal alignment, Component.LEFT_ALIGNMENT.
static String DEFAULT_TEXT
          Default text, "".
static Paint DEFAULT_TEXT_PAINT
          Default text paint, Color.BLACK.
protected  double greekThreshold
          Greek threshold in screen font size for this text node.
static int PROPERTY_CODE_FONT
          The property code that identifies a change of this node's font (see getFont).
static int PROPERTY_CODE_TEXT
          The property code that identifies a change of this node's text (see getText).
static int PROPERTY_CODE_TEXT_PAINT
          The property code that identifies a change of this node's text paint (see getTextPaint).
static String PROPERTY_FONT
          The property name that identifies a change of this node's font (see getFont).
static String PROPERTY_TEXT
          The property name that identifies a change of this node's text (see getText).
static String PROPERTY_TEXT_PAINT
          The property name that identifies a change of this node's text paint (see getTextPaint).
 
Fields inherited from class edu.umd.cs.piccolo.PNode
FILL_STRATEGY_ASPECT_COVER, FILL_STRATEGY_ASPECT_FIT, FILL_STRATEGY_EXACT_FIT, PROPERTY_BOUNDS, PROPERTY_CHILDREN, PROPERTY_CHILDREN_PICKABLE, PROPERTY_CLIENT_PROPERTIES, PROPERTY_CODE_BOUNDS, PROPERTY_CODE_CHILDREN, PROPERTY_CODE_CHILDREN_PICKABLE, PROPERTY_CODE_CLIENT_PROPERTIES, PROPERTY_CODE_FULL_BOUNDS, PROPERTY_CODE_PAINT, PROPERTY_CODE_PARENT, PROPERTY_CODE_PICKABLE, PROPERTY_CODE_TRANSFORM, PROPERTY_CODE_TRANSPARENCY, PROPERTY_CODE_VISIBLE, PROPERTY_FULL_BOUNDS, PROPERTY_PAINT, PROPERTY_PARENT, PROPERTY_PICKABLE, PROPERTY_TRANSFORM, PROPERTY_TRANSPARENCY, PROPERTY_VISIBLE, SCENE_GRAPH_DELEGATE
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PText()
          Create a new text node with no text ("").
PText(String text)
          Create a new text node with the specified text.
 
Method Summary
protected  TextLayout computeNextLayout(LineBreakMeasurer lineBreakMeasurer, float availableWidth, int nextLineBreakOffset)
          Compute the next layout using the specified line break measurer, available width, and next line break offset.
 Font getFont()
          Return the font for this text node.
 double getGreekThreshold()
          Return the greek threshold in screen font size.
 float getHorizontalAlignment()
          Return the horizontal alignment for this text node.
 float getJustification()
          Deprecated. by getHorizontalAlignment()
 String getText()
          Return the text for this text node.
 Paint getTextPaint()
          Return the paint used to paint this node's text.
protected  void internalUpdateBounds(double x, double y, double width, double height)
          Gives nodes a chance to update their internal structure before bounds changed notifications are sent.
 boolean isConstrainHeightToTextHeight()
          Return true if this text node should constrain its height to the height of its text.
 boolean isConstrainWidthToTextWidth()
          Return true if this text node should constrain its width to the width of its text.
protected  void paint(PPaintContext paintContext)
          Paint this node behind any of its children nodes.
protected  void paintGreek(PPaintContext paintContext)
          Paint greek with the specified paint context.
protected  void paintText(PPaintContext paintContext)
          Paint text with the specified paint context.
 void recomputeLayout()
          Compute the bounds of the text wrapped by this node.
 void setConstrainHeightToTextHeight(boolean constrainHeightToTextHeight)
          Set to true if this text node should constrain its height to the height of its text.
 void setConstrainWidthToTextWidth(boolean constrainWidthToTextWidth)
          Set to true if this text node should constrain its width to the width of its text.
 void setFont(Font font)
          Set the font for this text node to font.
 void setGreekThreshold(double greekThreshold)
          Set the greek threshold in screen font size to greekThreshold.
 void setHorizontalAlignment(float horizontalAlignment)
          Set the horizontal alignment for this text node to horizontalAlignment.
 void setJustification(float justification)
          Deprecated. by setHorizontalAlignment(float)
 void setText(String newText)
          Set the text for this node to text.
 void setTextPaint(Paint textPaint)
          Set the paint used to paint this node's text to textPaint.
 
Methods inherited from class edu.umd.cs.piccolo.PNode
addActivity, addAttribute, addChild, addChild, addChildren, addClientProperty, addInputEventListener, addPropertyChangeListener, addPropertyChangeListener, animateToBounds, animateToColor, animateToPositionScaleRotation, animateToRelativePosition, animateToTransform, animateToTransparency, animateTransformToBounds, centerBoundsOnPoint, centerFullBoundsOnPoint, clone, computeFullBounds, endResizeBounds, findIntersectingNodes, fireChildPropertyChange, firePropertyChange, fullIntersects, fullPaint, fullPick, getAllNodes, getAllNodes, getAttribute, getAttribute, getBooleanAttribute, getBounds, getBoundsChanged, getBoundsReference, getBoundsVolatile, getChild, getChildBoundsInvalid, getChildBoundsVolatile, getChildPaintInvalid, getChildrenCount, getChildrenIterator, getChildrenPickable, getChildrenReference, getClientProperties, getClientProperty, getClientPropertyKeysEnumeration, getClientPropertyKeysIterator, getDoubleAttribute, getFullBounds, getFullBoundsInvalid, getFullBoundsReference, getGlobalBounds, getGlobalFullBounds, getGlobalRotation, getGlobalScale, getGlobalToLocalTransform, getGlobalTranslation, getHeight, getInputEventListeners, getIntegerAttribute, getInverseTransform, getListenerList, getLocalToGlobalTransform, getName, getOccluded, getOffset, getPaint, getPaintInvalid, getParent, getPickable, getPropertyChangeParentMask, getRoot, getRotation, getScale, getTransform, getTransformReference, getTransparency, getUnionOfChildrenBounds, getVisible, getWidth, getX, getXOffset, getY, getYOffset, globalToLocal, globalToLocal, globalToLocal, indexOfChild, intersects, invalidateFullBounds, invalidateLayout, invalidatePaint, isAncestorOf, isDescendentOf, isDescendentOfRoot, isOpaque, layoutChildren, lerp, localToGlobal, localToGlobal, localToGlobal, localToParent, localToParent, localToParent, moveInBackOf, moveInFrontOf, moveToBack, moveToFront, offset, paintAfterChildren, paramString, parentBoundsChanged, parentToLocal, parentToLocal, parentToLocal, pick, pickAfterChildren, position, print, print, removeAllChildren, removeChild, removeChild, removeChildren, removeFromParent, removeInputEventListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaintFrom, reparent, replaceWith, resetBounds, rotate, rotateAboutPoint, rotateAboutPoint, rotateInPlace, scale, scaleAboutPoint, scaleAboutPoint, setBounds, setBounds, setBoundsChanged, setChildBoundsInvalid, setChildBoundsVolatile, setChildPaintInvalid, setChildrenPickable, setFullBoundsInvalid, setGlobalRotation, setGlobalScale, setGlobalTranslation, setHeight, setName, setOccluded, setOffset, setOffset, setPaint, setPaintInvalid, setParent, setPickable, setPropertyChangeParentMask, setRotation, setScale, setTransform, setTransparency, setVisible, setWidth, setX, setY, signalBoundsChanged, startResizeBounds, toImage, toImage, toImage, toImage, transformBy, translate, validateFullBounds, validateFullPaint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_TEXT

public static final String PROPERTY_TEXT
The property name that identifies a change of this node's text (see getText). Both old and new value will be set in any property change event.

See Also:
Constant Field Values

PROPERTY_CODE_TEXT

public static final int PROPERTY_CODE_TEXT
The property code that identifies a change of this node's text (see getText). Both old and new value will be set in any property change event.

See Also:
Constant Field Values

PROPERTY_FONT

public static final String PROPERTY_FONT
The property name that identifies a change of this node's font (see getFont). Both old and new value will be set in any property change event.

See Also:
Constant Field Values

PROPERTY_CODE_FONT

public static final int PROPERTY_CODE_FONT
The property code that identifies a change of this node's font (see getFont). Both old and new value will be set in any property change event.

See Also:
Constant Field Values

PROPERTY_TEXT_PAINT

public static final String PROPERTY_TEXT_PAINT
The property name that identifies a change of this node's text paint (see getTextPaint). Both old and new value will be set in any property change event.

Since:
1.3
See Also:
Constant Field Values

PROPERTY_CODE_TEXT_PAINT

public static final int PROPERTY_CODE_TEXT_PAINT
The property code that identifies a change of this node's text paint (see getTextPaint). Both old and new value will be set in any property change event.

Since:
1.3
See Also:
Constant Field Values

DEFAULT_FONT

public static Font DEFAULT_FONT
Default font, 12 point "SansSerif". Will be made final in version 2.0.


DEFAULT_GREEK_THRESHOLD

public static double DEFAULT_GREEK_THRESHOLD
Default greek threshold, 5.5d. Will be made final in version 2.0.


DEFAULT_HORIZONTAL_ALIGNMENT

public static final float DEFAULT_HORIZONTAL_ALIGNMENT
Default horizontal alignment, Component.LEFT_ALIGNMENT.

Since:
1.3
See Also:
Constant Field Values

DEFAULT_TEXT

public static final String DEFAULT_TEXT
Default text, "".

Since:
1.3
See Also:
Constant Field Values

DEFAULT_TEXT_PAINT

public static final Paint DEFAULT_TEXT_PAINT
Default text paint, Color.BLACK.

Since:
1.3

greekThreshold

protected double greekThreshold
Greek threshold in screen font size for this text node. Will be made private in version 2.0.

Constructor Detail

PText

public PText()
Create a new text node with no text ("").


PText

public PText(String text)
Create a new text node with the specified text.

Parameters:
text - text for this text node
Method Detail

getJustification

public float getJustification()
Deprecated. by getHorizontalAlignment()

Returns:
the horizontal alignment value of this node

setJustification

public void setJustification(float justification)
Deprecated. by setHorizontalAlignment(float)

Parameters:
justification - horizontal alignment value to assign to this node

getHorizontalAlignment

public float getHorizontalAlignment()
Return the horizontal alignment for this text node. The horizontal alignment will be one of Component.LEFT_ALIGNMENT, Component.CENTER_ALIGNMENT, or Component.RIGHT_ALIGNMENT. Defaults to DEFAULT_HORIZONTAL_ALIGNMENT.

Returns:
the horizontal alignment for this text node
Since:
1.3

setHorizontalAlignment

public void setHorizontalAlignment(float horizontalAlignment)
Set the horizontal alignment for this text node to horizontalAlignment.

Parameters:
horizontalAlignment - horizontal alignment, must be one of Component.LEFT_ALIGNMENT, Component.CENTER_ALIGNMENT, or Component.RIGHT_ALIGNMENT
Since:
1.3

getTextPaint

public Paint getTextPaint()
Return the paint used to paint this node's text.

Returns:
the paint used to paint this node's text

setTextPaint

public void setTextPaint(Paint textPaint)
Set the paint used to paint this node's text to textPaint.

This is a bound property.

Parameters:
textPaint - text paint

isConstrainWidthToTextWidth

public boolean isConstrainWidthToTextWidth()
Return true if this text node should constrain its width to the width of its text. Defaults to true.

Returns:
true if this text node should constrain its width to the width of its text

setConstrainWidthToTextWidth

public void setConstrainWidthToTextWidth(boolean constrainWidthToTextWidth)
Set to true if this text node should constrain its width to the width of its text.

Parameters:
constrainWidthToTextWidth - true if this text node should constrain its width to the width of its text

isConstrainHeightToTextHeight

public boolean isConstrainHeightToTextHeight()
Return true if this text node should constrain its height to the height of its text. Defaults to true.

Returns:
true if this text node should constrain its height to the height of its text

setConstrainHeightToTextHeight

public void setConstrainHeightToTextHeight(boolean constrainHeightToTextHeight)
Set to true if this text node should constrain its height to the height of its text.

Parameters:
constrainHeightToTextHeight - true if this text node should constrain its height to the width of its text

getGreekThreshold

public double getGreekThreshold()
Return the greek threshold in screen font size. When the screen font size will be below this threshold the text is rendered as 'greek' instead of drawing the text glyphs. Defaults to DEFAULT_GREEK_THRESHOLD.

Returns:
the current greek threshold in screen font size
See Also:
paintGreek(PPaintContext)

setGreekThreshold

public void setGreekThreshold(double greekThreshold)
Set the greek threshold in screen font size to greekThreshold. When the screen font size will be below this threshold the text is rendered as 'greek' instead of drawing the text glyphs.

Parameters:
greekThreshold - greek threshold in screen font size
See Also:
paintGreek(PPaintContext)

getText

public String getText()
Return the text for this text node. Defaults to DEFAULT_TEXT.

Returns:
the text for this text node

setText

public void setText(String newText)
Set the text for this node to text. The text will be broken up into multiple lines based on the size of the text and the bounds width of this node.

This is a bound property.

Parameters:
newText - text for this text node

getFont

public Font getFont()
Return the font for this text node. Defaults to DEFAULT_FONT.

Returns:
the font for this text node

setFont

public void setFont(Font font)
Set the font for this text node to font. Note that in Piccolo if you want to change the size of a text object it's often a better idea to scale the PText node instead of changing the font size to get that same effect. Using very large font sizes can slow performance.

This is a bound property.

Parameters:
font - font for this text node

recomputeLayout

public void recomputeLayout()
Compute the bounds of the text wrapped by this node. The text layout is wrapped based on the bounds of this node.


computeNextLayout

protected TextLayout computeNextLayout(LineBreakMeasurer lineBreakMeasurer,
                                       float availableWidth,
                                       int nextLineBreakOffset)
Compute the next layout using the specified line break measurer, available width, and next line break offset.

Parameters:
lineBreakMeasurer - line break measurer
availableWidth - available width
nextLineBreakOffset - next line break offset
Returns:
the next layout computed using the specified line break measurer, available width, and next line break offset

paintGreek

protected void paintGreek(PPaintContext paintContext)
Paint greek with the specified paint context.

Parameters:
paintContext - paint context
Since:
1.3

paintText

protected void paintText(PPaintContext paintContext)
Paint text with the specified paint context.

Parameters:
paintContext - paint context
Since:
1.3

paint

protected void paint(PPaintContext paintContext)
Paint this node behind any of its children nodes. Subclasses that define a different appearance should override this method and paint themselves there.

Overrides:
paint in class PNode
Parameters:
paintContext - the paint context to use for painting the node

internalUpdateBounds

protected void internalUpdateBounds(double x,
                                    double y,
                                    double width,
                                    double height)
Gives nodes a chance to update their internal structure before bounds changed notifications are sent. When this message is recived the nodes bounds field will contain the new value. See PPath for an example that uses this method.

Overrides:
internalUpdateBounds in class PNode
Parameters:
x - x position of bounds
y - y position of bounds
width - width to apply to the bounds
height - height to apply to the bounds


Copyright © 1995-2011 Piccolo2D. All Rights Reserved.