Package edu.umd.cs.piccolo.nodes
Class PText
java.lang.Object
edu.umd.cs.piccolo.PNode
edu.umd.cs.piccolo.nodes.PText
- All Implemented Interfaces:
Printable,Serializable,Cloneable
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.PNode
PNode.PSceneGraphDelegate -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic FontDefault font, 12 point"SansSerif".static doubleDefault greek threshold,5.5d.static final floatDefault horizontal alignment,Component.LEFT_ALIGNMENT.static final StringDefault text,"".static final PaintDefault text paint,Color.BLACK.protected doubleGreek threshold in screen font size for this text node.static final intThe property code that identifies a change of this node's font (seegetFont).static final intThe property code that identifies a change of this node's text (seegetText).static final intThe property code that identifies a change of this node's text paint (seegetTextPaint).static final StringThe property name that identifies a change of this node's font (seegetFont).static final StringThe property name that identifies a change of this node's text (seegetText).static final StringThe property name that identifies a change of this node's text paint (seegetTextPaint).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_DELEGATEFields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TextLayoutcomputeNextLayout(LineBreakMeasurer lineBreakMeasurer, float availableWidth, int nextLineBreakOffset) Compute the next layout using the specified line break measurer, available width, and next line break offset.getFont()Return the font for this text node.doubleReturn the greek threshold in screen font size.floatReturn the horizontal alignment for this text node.floatDeprecated.getText()Return the text for this text node.Return the paint used to paint this node's text.protected voidinternalUpdateBounds(double x, double y, double width, double height) Gives nodes a chance to update their internal structure before bounds changed notifications are sent.booleanReturn true if this text node should constrain its height to the height of its text.booleanReturn true if this text node should constrain its width to the width of its text.protected voidpaint(PPaintContext paintContext) Paint this node behind any of its children nodes.protected voidpaintGreek(PPaintContext paintContext) Paint greek with the specified paint context.protected voidpaintText(PPaintContext paintContext) Paint text with the specified paint context.voidCompute the bounds of the text wrapped by this node.voidsetConstrainHeightToTextHeight(boolean constrainHeightToTextHeight) Set totrueif this text node should constrain its height to the height of its text.voidsetConstrainWidthToTextWidth(boolean constrainWidthToTextWidth) Set totrueif this text node should constrain its width to the width of its text.voidSet the font for this text node tofont.voidsetGreekThreshold(double greekThreshold) Set the greek threshold in screen font size togreekThreshold.voidsetHorizontalAlignment(float horizontalAlignment) Set the horizontal alignment for this text node tohorizontalAlignment.voidsetJustification(float justification) Deprecated.voidSet the text for this node totext.voidsetTextPaint(Paint textPaint) Set the paint used to paint this node's text totextPaint.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
-
Field Details
-
PROPERTY_TEXT
The property name that identifies a change of this node's text (seegetText). Both old and new value will be set in any property change event.- See Also:
-
PROPERTY_CODE_TEXT
public static final int PROPERTY_CODE_TEXTThe property code that identifies a change of this node's text (seegetText). Both old and new value will be set in any property change event.- See Also:
-
PROPERTY_FONT
The property name that identifies a change of this node's font (seegetFont). Both old and new value will be set in any property change event.- See Also:
-
PROPERTY_CODE_FONT
public static final int PROPERTY_CODE_FONTThe property code that identifies a change of this node's font (seegetFont). Both old and new value will be set in any property change event.- See Also:
-
PROPERTY_TEXT_PAINT
The property name that identifies a change of this node's text paint (seegetTextPaint). Both old and new value will be set in any property change event.- Since:
- 1.3
- See Also:
-
PROPERTY_CODE_TEXT_PAINT
public static final int PROPERTY_CODE_TEXT_PAINTThe property code that identifies a change of this node's text paint (seegetTextPaint). Both old and new value will be set in any property change event.- Since:
- 1.3
- See Also:
-
DEFAULT_FONT
Default font, 12 point"SansSerif". Will be made final in version 2.0. -
DEFAULT_GREEK_THRESHOLD
public static double DEFAULT_GREEK_THRESHOLDDefault greek threshold,5.5d. Will be made final in version 2.0. -
DEFAULT_HORIZONTAL_ALIGNMENT
public static final float DEFAULT_HORIZONTAL_ALIGNMENTDefault horizontal alignment,Component.LEFT_ALIGNMENT.- Since:
- 1.3
- See Also:
-
DEFAULT_TEXT
Default text,"".- Since:
- 1.3
- See Also:
-
DEFAULT_TEXT_PAINT
Default text paint,Color.BLACK.- Since:
- 1.3
-
greekThreshold
protected double greekThresholdGreek threshold in screen font size for this text node. Will be made private in version 2.0.
-
-
Constructor Details
-
PText
public PText()Create a new text node with no text (""). -
PText
Create a new text node with the specified text.- Parameters:
text- text for this text node
-
-
Method Details
-
getJustification
public float getJustification()Deprecated.- Returns:
- the horizontal alignment value of this node
-
setJustification
public void setJustification(float justification) Deprecated.- 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 ofComponent.LEFT_ALIGNMENT,Component.CENTER_ALIGNMENT, orComponent.RIGHT_ALIGNMENT. Defaults toDEFAULT_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 tohorizontalAlignment.- Parameters:
horizontalAlignment- horizontal alignment, must be one ofComponent.LEFT_ALIGNMENT,Component.CENTER_ALIGNMENT, orComponent.RIGHT_ALIGNMENT- Since:
- 1.3
-
getTextPaint
Return the paint used to paint this node's text.- Returns:
- the paint used to paint this node's text
-
setTextPaint
Set the paint used to paint this node's text totextPaint.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 totrue.- Returns:
- true if this text node should constrain its width to the width of its text
-
setConstrainWidthToTextWidth
public void setConstrainWidthToTextWidth(boolean constrainWidthToTextWidth) Set totrueif 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 totrue.- Returns:
- true if this text node should constrain its height to the height of its text
-
setConstrainHeightToTextHeight
public void setConstrainHeightToTextHeight(boolean constrainHeightToTextHeight) Set totrueif 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 toDEFAULT_GREEK_THRESHOLD.- Returns:
- the current greek threshold in screen font size
- See Also:
-
setGreekThreshold
public void setGreekThreshold(double greekThreshold) Set the greek threshold in screen font size togreekThreshold. 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:
-
getText
Return the text for this text node. Defaults toDEFAULT_TEXT.- Returns:
- the text for this text node
-
setText
Set the text for this node totext. 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
Return the font for this text node. Defaults toDEFAULT_FONT.- Returns:
- the font for this text node
-
setFont
Set the font for this text node tofont. 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 measureravailableWidth- available widthnextLineBreakOffset- next line break offset- Returns:
- the next layout computed using the specified line break measurer, available width, and next line break offset
-
paintGreek
Paint greek with the specified paint context.- Parameters:
paintContext- paint context- Since:
- 1.3
-
paintText
Paint text with the specified paint context.- Parameters:
paintContext- paint context- Since:
- 1.3
-
paint
Paint this node behind any of its children nodes. Subclasses that define a different appearance should override this method and paint themselves there. -
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:
internalUpdateBoundsin classPNode- Parameters:
x- x position of boundsy- y position of boundswidth- width to apply to the boundsheight- height to apply to the bounds
-
getHorizontalAlignment()