guicomponents

## Class StyledString

- java.lang.Object
- - guicomponents.StyledString

- All Implemented Interfaces:
    Serializable

      public final class StyledString
      extends Object
      implements Serializable

  This class is used to represent text with attributes.
  It means that you don't have to have the same style of font or even the same font face over the whole length of the text.
  Most font features can be modified all except the text background which is transparent. There is a feature to highlight part of the string by having a different background colour but this is used for highlighting selected text in GTextField and GTextArea components.
  Author:
    Peter Lager
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StyledString(Graphics2D g2d, String startText)` This is assumed to be a single line of text (i.e.
    `StyledString(Graphics2D g2d, String startText, int lineWidth)` Supports multiple lines of text wrapped on word boundaries.
    `StyledString(String startText)` This is assumed to be a single line of text (i.e.
    `StyledString(String startText, int wrapWidth)` Supports multiple lines of text wrapped on word boundaries.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addAttribute(AttributedCharacterIterator.Attribute type, Object value)` Add an attribute that affects the whole length of the string.
    `void` | `addAttribute(AttributedCharacterIterator.Attribute type, Object value, int charStart, int charEnd)` Set charStart and charEnd to <0 if full length.
    `guicomponents.StyledString.TextLayoutHitInfo` | `calculateFromXY(Graphics2D g2d, float px, float py)`
    `void` | `clearAllAttributes()`
    `boolean` | `deleteCharacters(int fromPos, int nbrToRemove)` Remove a number of characters from the string
    `LinkedList<guicomponents.StyledString.TextLayoutInfo>` | `getLines(Graphics2D g2d)` Get the text layouts for display if the string has changed since last call to this method regenerate them.
    `float` | `getMaxLineHeight()` Get the height of the tallest line
    `float` | `getMaxLineLength()` Return the length of the longest line.
    `int` | `getNbrLines()` Return the number of lines in the layout
    `String` | `getPlainText()` Get the plain text as a STring.
    `float` | `getTextAreaHeight()` Return the height of the text line(s)
    `guicomponents.StyledString.TextLayoutInfo` | `getTLIforLineNo(int ln)` Get a layout based on line number
    `float` | `getWrapWidth()` Get the break width used to create the lines.
    `boolean` | `insertCharacters(int insertPos, String chars)`
    `int` | `length()` Get the number of characters in this styled string
    `static StyledString` | `load(PApplet papp, String fname)`
    `static void` | `save(PApplet papp, StyledString ss, String fname)` Save the named StyleString in the named file.
    `void` | `setFont(Font a_font)`
    `void` | `setJustify(boolean justify)` Text can be either left or fully justified.
    `void` | `setJustifyRatio(float jRatio)` Justify only if the line has sufficient text to do so.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StyledString

          public StyledString(String startText)

      This is assumed to be a single line of text (i.e. no wrap). EOL characters will be stripped from the text before use.
      Parameters:
        `startText` -

    - #### StyledString

          public StyledString(Graphics2D g2d,
                      String startText)

      This is assumed to be a single line of text (i.e. no wrap). EOL characters will be stripped from the text before use. It will use the first parameter to calculate StyledString metrics immediately.
      Parameters:
        `g2d` -
        `startText` -

    - #### StyledString

          public StyledString(String startText,
                      int wrapWidth)

      Supports multiple lines of text wrapped on word boundaries.
      Parameters:
        `startText` -
        `wrapWidth` - the maximum size after which the text is

    - #### StyledString

          public StyledString(Graphics2D g2d,
                      String startText,
                      int lineWidth)

      Supports multiple lines of text wrapped on word boundaries.
      It will use the first parameter to calculate StyledString metrics immediately.
      Parameters:
        `g2d` -
        `startText` -
        `lineWidth` -

  - ### Method Detail

    - #### getPlainText

          public String getPlainText()

      Get the plain text as a STring. Any line breaks will kept and will be represented by the character 'backslash n'
      Returns:
        the associated plain text

    - #### length

          public int length()

      Get the number of characters in this styled string
      Returns:

    - #### setJustify

          public void setJustify(boolean justify)

      Text can be either left or fully justified.
      Parameters:
        `justify` - true for full justification

    - #### setJustifyRatio

          public void setJustifyRatio(float jRatio)

      Justify only if the line has sufficient text to do so.
      Parameters:
        `jRatio` - ratio of text length to visibleWidth

    - #### addAttribute

          public void addAttribute(AttributedCharacterIterator.Attribute type,
                          Object value,
                          int charStart,
                          int charEnd)

      Set charStart and charEnd to <0 if full length.
      Parameters:
        `type` -
        `value` -
        `charStart` -
        `charEnd` -

    - #### addAttribute

          public void addAttribute(AttributedCharacterIterator.Attribute type,
                          Object value)

      Add an attribute that affects the whole length of the string.
      Parameters:
        `type` - attribute type
        `value` - attribute value

    - #### insertCharacters

          public boolean insertCharacters(int insertPos,
                                 String chars)

      Parameters:
        `chars` -
        `insertPos` - the position in the text

    - #### clearAllAttributes

          public void clearAllAttributes()

    - #### deleteCharacters

          public boolean deleteCharacters(int fromPos,
                                 int nbrToRemove)

      Remove a number of characters from the string
      Parameters:
        `nbrToRemove` - number of characters to remove
        `fromPos` - start location for removal
      Returns:

    - #### setFont

          public void setFont(Font a_font)

    - #### getLines

          public LinkedList<guicomponents.StyledString.TextLayoutInfo> getLines(Graphics2D g2d)

      Get the text layouts for display if the string has changed since last call to this method regenerate them.
      Parameters:
        `g2d` - Graphics2D display context
      Returns:

    - #### getNbrLines

          public int getNbrLines()

      Return the number of lines in the layout
      Returns:

    - #### getTextAreaHeight

          public float getTextAreaHeight()

      Return the height of the text line(s)

    - #### getMaxLineLength

          public float getMaxLineLength()

      Return the length of the longest line.

    - #### getMaxLineHeight

          public float getMaxLineHeight()

      Get the height of the tallest line

    - #### getWrapWidth

          public float getWrapWidth()

      Get the break width used to create the lines.
      Returns:

    - #### calculateFromXY

          public guicomponents.StyledString.TextLayoutHitInfo calculateFromXY(Graphics2D g2d,
                                                                     float px,
                                                                     float py)

    - #### getTLIforLineNo

          public guicomponents.StyledString.TextLayoutInfo getTLIforLineNo(int ln)

      Get a layout based on line number
      Parameters:
        `ln` -
      Returns:

    - #### save

          public static void save(PApplet papp,
                  StyledString ss,
                  String fname)

      Save the named StyleString in the named file.
      Parameters:
        `papp` -
        `ss` - the styled string
        `fname` -

    - #### load

          public static StyledString load(PApplet papp,
                          String fname)

Processing library guicomponents by Peter Lager. (C) 2012