Class PText

java.lang.Object
edu.umd.cs.piccolo.PNode
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:
  • Field Details

    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • DEFAULT_TEXT

      public static final String DEFAULT_TEXT
      Default text, "".
      Since:
      1.3
      See Also:
    • 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 Details

    • 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 Details

    • getJustification

      public float getJustification()
      Deprecated.
      Returns:
      the horizontal alignment value of this node
    • setJustification

      public void setJustification(float justification)
      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:
    • 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:
    • 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