StyledTextModel based on a collection of styled segments.
This model is suitable for relatively small documents as it has neither disk storage backing nor storage of incremental changes.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | RichTextModel.
Model paragraph is a list of RSegments. |
| private static class | RichTextModel.
Represents a rich text segment having the same style attributes. |
| Modifier and Type | Field and Description |
|---|---|
| private final ArrayList | |
| private final HashMap |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | applyStyle(int index, int start, int end, StyleAttributeMap attrs, boolean merge)
Implements abstract jfx. Applies style to the specified text range within a single paragraph. |
| private StyleAttributeMap | |
| private static void | dump(StyledTextModel
the model model, PrintStream the output out)Temporary method added for testing; will be removed in production. |
| private void | |
| private void | |
| public RichParagraph | getParagraph(int index)
Implements abstract jfx. Returns a |
| public int | getParagraphLength(int index)
Overrides jfx. Returns the length of text in a paragraph at the specified index. |
| public String | getPlainText(int index)
Implements abstract jfx. Returns the plain text string for the specified paragraph. |
| public StyleAttributeMap | getStyleAttributeMap(StyleResolver resolver, TextPos pos)
Implements abstract jfx. Returns the |
| protected void | insertLineBreak(int index, int offset)
Implements abstract jfx. Inserts a line break at the specified position. |
| protected void | insertParagraph(int index, Supplier<Region> generator)
Implements abstract jfx. Inserts a paragraph that contains a single |
| protected int | insertTextSegment(int index, int offset, String text, StyleAttributeMap attrs)
Implements abstract jfx. This method is called to insert a single styled text segment at the given position. |
| public final boolean | isWritable()
Implements abstract jfx. Indicates whether the model supports content modifications made via
|
| protected void | removeRange(TextPos start, TextPos end)
Implements abstract jfx. Removes the specified text range. |
| protected void | setParagraphStyle(int index, StyleAttributeMap attrs)
Implements abstract jfx. Replaces the paragraph styles in the specified paragraph. |
| public int | size()
Implements abstract jfx. Returns the number of paragraphs in the model. |
| paragraphs | back to summary |
|---|---|
| private final ArrayList<RichTextModel. | |
| styleCache | back to summary |
|---|---|
| private final HashMap<StyleAttributeMap, StyleAttributeMap> styleCache | |
| RichTextModel | back to summary |
|---|---|
| public RichTextModel() Constructs the empty model. | |
| applyStyle | back to summary |
|---|---|
| protected void applyStyle(int index, int start, int end, StyleAttributeMap attrs, boolean merge) Implements abstract jfx. Doc from jfx. Applies style to the specified text range within a single paragraph.
The new attributes override any existing attributes.
The
| |
| dedup | back to summary |
|---|---|
| private StyleAttributeMap dedup(StyleAttributeMap a) deduplicates style attributes. | |
| dump | back to summary |
|---|---|
| private static void dump(StyledTextModel model, PrintStream out) Temporary method added for testing; will be removed in production.
| |
| dump | back to summary |
|---|---|
| private void dump(PrintStream out) | |
| dump | back to summary |
|---|---|
| private void dump(RichTextModel. | |
| getParagraph | back to summary |
|---|---|
| public RichParagraph getParagraph(int index) Implements abstract jfx. Doc from jfx. Returns a This method makes no guarantees that the same paragraph instance will be returned for the same model index.
| |
| getParagraphLength | back to summary |
|---|---|
| public int getParagraphLength(int index) Overrides jfx. Doc from jfx. Returns the length of text in a paragraph at the specified index.
| |
| getPlainText | back to summary |
|---|---|
| public String getPlainText(int index) Implements abstract jfx. Doc from jfx. Returns the plain text string for the specified paragraph. The returned text string cannot be null
and must not contain any control characters other than TAB.
The callers must ensure that the value of
| |
| getStyleAttributeMap | back to summary |
|---|---|
| public StyleAttributeMap getStyleAttributeMap(StyleResolver resolver, TextPos pos) Implements abstract jfx. Doc from jfx. Returns the
| |
| insertLineBreak | back to summary |
|---|---|
| protected void insertLineBreak(int index, int offset) Implements abstract jfx. Doc from jfx. Inserts a line break at the specified position.
| |
| insertParagraph | back to summary |
|---|---|
| protected void insertParagraph(int index, Supplier<Region> generator) Implements abstract jfx. Doc from jfx. Inserts a paragraph that contains a single
The model should not cache or otherwise retain references to the created
This method allows for embedding
| |
| insertTextSegment | back to summary |
|---|---|
| protected int insertTextSegment(int index, int offset, String text, StyleAttributeMap attrs) Implements abstract jfx. Doc from jfx. This method is called to insert a single styled text segment at the given position.
| |
| isWritable | back to summary |
|---|---|
| public final boolean isWritable() Implements abstract jfx. Doc from jfx. Indicates whether the model supports content modifications made via
Note that even when this method returns
| |
| removeRange | back to summary |
|---|---|
| protected void removeRange(TextPos start, TextPos end) Implements abstract jfx. Doc from jfx. Removes the specified text range.
This method gets called only if the model is editable.
The caller guarantees that
| |
| setParagraphStyle | back to summary |
|---|---|
| protected void setParagraphStyle(int index, StyleAttributeMap attrs) Implements abstract jfx. Doc from jfx. Replaces the paragraph styles in the specified paragraph.
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract jfx. Doc from jfx. Returns the number of paragraphs in the model.
| |
| Modifier and Type | Field and Description |
|---|---|
| private StyleAttributeMap |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | append(RichTextModel.
the paragraph to append pAppends the specified paragraph by adding all of its segments. |
| public void | applyStyle(int start, int end, StyleAttributeMap attrs, boolean merge, Function<StyleAttributeMap, StyleAttributeMap> dedup)
|
| private boolean | Returns: true if this segment has been merged with the previous segmentthe paragraph index ix, RichTextModel.the segment seg,the attributes a, boolean whether to merge or set merge, Function<StyleAttributeMap, StyleAttributeMap> the deduplicator dedup)Applies style to the segment. |
| private RichParagraph | |
| public StyleAttributeMap | |
| public String | |
| public StyleAttributeMap | Returns: the style infothe offset offset)Retrieves the style attributes from the previous character (or next, if at the beginning). |
| public int | |
| public RichTextModel. | Returns: the remaining portion of paragraphthe offset offset)Trims this paragraph and returns the remaining text to be inserted after the line break. |
| private boolean | Returns: true if the new segment has been merged with the previous segmentinserts a new segment with the specified, deduplicated attributes. |
| private boolean | Returns: true if a segment has been added.the segment index ix, String the plain text text, StyleAttributeMap the style attributes a)Inserts a new segment, or merges with adjacent segment if styles are the same. |
| public void | insertText(int
the insertion offset offset, String the plain text text, StyleAttributeMap the style attributes attrs)Inserts styled text at the specified offset. |
| private boolean | |
| private boolean | |
| public void | |
| public void | |
| private static int | whichCase(int off, int max, int start, int end)
paragraph: start [=============] end
case:
0: |-
0: |-
1: -------------------->
2: |----------------->
3: |-------------|
4: |--------|
5: |------------->
6: |---------|
7: |----|
8: -----------|
9: ----------------|
|
| paragraphAttrs | back to summary |
|---|---|
| private StyleAttributeMap paragraphAttrs | |
| RParagraph | back to summary |
|---|---|
| public RParagraph() Creates an instance | |
| append | back to summary |
|---|---|
| public void append(RichTextModel. Appends the specified paragraph by adding all of its segments.
| |
| applyStyle | back to summary |
|---|---|
| public void applyStyle(int start, int end, StyleAttributeMap attrs, boolean merge, Function<StyleAttributeMap, StyleAttributeMap> dedup) | |
| applyStyle | back to summary |
|---|---|
| private boolean applyStyle(int ix, RichTextModel. Applies style to the segment. If the new style is exactly the same as the style of the previous segment, it simply merges the two segments.
| |
| createRichParagraph | back to summary |
|---|---|
| private RichParagraph createRichParagraph() | |
| getParagraphAttributes | back to summary |
|---|---|
| public StyleAttributeMap getParagraphAttributes() | |
| getPlainText | back to summary |
|---|---|
| public String getPlainText() | |
| getStyleAttributeMap | back to summary |
|---|---|
| public StyleAttributeMap getStyleAttributeMap(int offset) Retrieves the style attributes from the previous character (or next, if at the beginning).
| |
| getTextLength | back to summary |
|---|---|
| public int getTextLength() | |
| insertLineBreak | back to summary |
|---|---|
| public RichTextModel. Trims this paragraph and returns the remaining text to be inserted after the line break.
| |
| insertSegment | back to summary |
|---|---|
| private boolean insertSegment(int ix, String text, StyleAttributeMap a) inserts a new segment with the specified, deduplicated attributes. if the new style is the same as the previous segment, merges text with the previous segment instead.
| |
| insertSegment2 | back to summary |
|---|---|
| private boolean insertSegment2(int ix, String text, StyleAttributeMap a) Inserts a new segment, or merges with adjacent segment if styles are the same. Returns true if a segment has been added.
| |
| insertText | back to summary |
|---|---|
| public void insertText(int offset, String text, StyleAttributeMap attrs) Inserts styled text at the specified offset.
| |
| isMerge | back to summary |
|---|---|
| private boolean isMerge(RichTextModel. | |
| isZeroWidth | back to summary |
|---|---|
| private boolean isZeroWidth() | |
| removeSpan | back to summary |
|---|---|
| public void removeSpan(int start, int end) | |
| setParagraphAttributes | back to summary |
|---|---|
| public void setParagraphAttributes(StyleAttributeMap a) | |
| whichCase | back to summary |
|---|---|
private static int whichCase(int off, int max, int start, int end)
paragraph: start [=============] end
case:
0: |-
0: |-
1: -------------------->
2: |----------------->
3: |-------------|
4: |--------|
5: |------------->
6: |---------|
7: |----|
8: -----------|
9: ----------------|
| |
| Modifier and Type | Field and Description |
|---|---|
| private StyleAttributeMap | |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public StyleAttributeMap | |
| public StyleAttributeMap | |
| public int | |
| public boolean | |
| public void | |
| public void | |
| public String |
| attrs | back to summary |
|---|---|
| private StyleAttributeMap attrs | |
| text | back to summary |
|---|---|
| private String text | |
| RSegment | back to summary |
|---|---|
| public RSegment(String text, StyleAttributeMap attrs) | |
| append | back to summary |
|---|---|
| public void append(String s) | |
| attrs | back to summary |
|---|---|
| public StyleAttributeMap attrs() | |
| getStyleAttributeMap | back to summary |
|---|---|
| public StyleAttributeMap getStyleAttributeMap() | |
| getTextLength | back to summary |
|---|---|
| public int getTextLength() | |
| removeRegion | back to summary |
|---|---|
| public boolean removeRegion(int start, int end) returns true if this segment becomes empty as a result | |
| setAttrs | back to summary |
|---|---|
| public void setAttrs(StyleAttributeMap a) | |
| setText | back to summary |
|---|---|
| public void setText(String s) | |
| text | back to summary |
|---|---|
| public String text() | |