Class InlineStyles

java.lang.Object
com.codename1.ui.editor.InlineStyles

public final class InlineStyles extends Object
The per character inline style model for the pure rich text editor. It keeps one TextStyle reference for every character in the document, kept in lockstep with the text through #applyEdit. Runs of identical style are coalesced only at render time, which keeps edits simple and correct at the cost of one reference per character (rich documents are small enough for this to be a non issue).
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    A predicate over a style, used by #allInRange.
    static interface 
    A transform applied to a character's style, used to toggle bold, set a color, etc.
  • Constructor Summary

    Constructors
    Constructor
    Description
    InlineStyles(int length)
    Creates a model of the given length, all default style.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    allInRange(int start, int end, InlineStyles.StylePredicate p)
    True when every character in [start, end) satisfies the predicate.
    void
    applyEdit(int start, int removedLen, int insertedLen, TextStyle style)
    Keeps the model in sync with a text replacement: removes removedLen styles at start and inserts insertedLen copies of style.
    int
    Returns the number of characters covered.
    void
    reset(int length)
    Resets the model to the given length, all default style.
    void
    setAt(int index, TextStyle style)
    Sets the style of a single character.
    styleAt(int index)
    Returns the style of the character at index, or the default style out of range.
    void
    Applies a transform to every character's style in [start, end).

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • InlineStyles

      public InlineStyles(int length)
      Creates a model of the given length, all default style.
  • Method Details

    • reset

      public void reset(int length)
      Resets the model to the given length, all default style.
    • length

      public int length()
      Returns the number of characters covered.
    • styleAt

      public TextStyle styleAt(int index)
      Returns the style of the character at index, or the default style out of range.
    • applyEdit

      public void applyEdit(int start, int removedLen, int insertedLen, TextStyle style)

      Keeps the model in sync with a text replacement: removes removedLen styles at start and inserts insertedLen copies of style.

      Parameters
      • start: the offset of the edit

      • removedLen: number of characters removed

      • insertedLen: number of characters inserted

      • style: the style applied to the inserted characters

    • setAt

      public void setAt(int index, TextStyle style)
      Sets the style of a single character.
    • transformRange

      public void transformRange(int start, int end, InlineStyles.StyleTransform t)
      Applies a transform to every character's style in [start, end).
    • allInRange

      public boolean allInRange(int start, int end, InlineStyles.StylePredicate p)
      True when every character in [start, end) satisfies the predicate. An empty range checks the character just before the caret (the style typing would continue with).