Top Description Inners Fields Constructors Methods
jfx.incubator.scene.control.richtext.model

public Class RichTextModel

extends StyledTextModel
Class Inheritance
Imports
java.io.PrintStream, java.util.ArrayList, .HashMap, java.util.function.Function, .Supplier, javafx.scene.layout.Region, jfx.incubator.scene.control.richtext.StyleResolver, .TextPos

Editable, in-memory 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.

Since
24

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
RichTextModel.RParagraph

Model paragraph is a list of RSegments.

private static class
RichTextModel.RSegment

Represents a rich text segment having the same style attributes.

Field Summary

Modifier and TypeField and Description
private final ArrayList<RichTextModel.RParagraph>
private final HashMap<StyleAttributeMap, StyleAttributeMap>

Constructor Summary

AccessConstructor and Description
public
RichTextModel()

Constructs the empty model.

Method Summary

Modifier and TypeMethod and Description
protected void
applyStyle(int
the paragraph index
index
,
int
the start offset
start
,
int
the end offset
end
,
StyleAttributeMap
the character attributes
attrs
,
boolean
determines whether to merge with or overwrite the existing attributes
merge
)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.applyStyle.

Applies style to the specified text range within a single paragraph.

private StyleAttributeMap
dedup(StyleAttributeMap a)

deduplicates style attributes.

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
the paragraph index in the range (0...size())
index
)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.getParagraph.

Returns a RichParagraph at the given model index.

public int
getParagraphLength(int
the paragraph index
index
)

Overrides jfx.incubator.scene.control.richtext.model.StyledTextModel.getParagraphLength.

Returns the length of text in a paragraph at the specified index.

public String
getPlainText(int
the paragraph index in the range (0...size())
index
)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.getPlainText.

Returns the plain text string for the specified paragraph.

public StyleAttributeMap
getStyleAttributeMap(StyleResolver
the style resolver
resolver
,
TextPos
the text position
pos
)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.getStyleAttributeMap.

Returns the StyleAttributeMap of the character at the specified position's charIndex.

protected void
insertLineBreak(int
the model index
index
,
int
the text offset
offset
)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.insertLineBreak.

Inserts a line break at the specified position.

protected void
insertParagraph(int
model index
index
,
Supplier<Region>
code that will be used to create a Node instance
generator
)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.insertParagraph.

Inserts a paragraph that contains a single Region.

protected int
insertTextSegment(int
the paragraph index
index
,
int
the insertion offset within the paragraph
offset
,
String
the text to insert
text
,
StyleAttributeMap
the style attributes
attrs
)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.insertTextSegment.

This method is called to insert a single styled text segment at the given position.

public final boolean
isWritable()

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.isWritable.

Indicates whether the model supports content modifications made via applyStyle(), replace(), undo(), redo() methods.

protected void
removeRange(TextPos
the start of the range to be removed
start
,
TextPos
the end of the range to be removed, expected to be greater than the start position
end
)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.removeRange.

Removes the specified text range.

protected void
setParagraphStyle(int
the paragraph index
index
,
StyleAttributeMap
the paragraph attributes
attrs
)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.setParagraphStyle.

Replaces the paragraph styles in the specified paragraph.

public int
size()

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.size.

Returns the number of paragraphs in the model.

Inherited from jfx.incubator.scene.control.richtext.model.StyledTextModel:
addListenerapplyStyleclampclearUndoRedoexportexportParagraphfireChangeEventfireStyleChangeEventgetDataFormatHandlergetDocumentEndgetEndOfParagraphTextPosgetMarkergetSupportedAttributesgetSupportedDataFormatsisRedoableisUndoablereadredoredoablePropertyregisterDataFormatHandlerremoveDataFormatHandlerremoveListenerreplacereplaceundoundoablePropertywrite

Field Detail

paragraphsback to summary
private final ArrayList<RichTextModel.RParagraph> paragraphs
styleCacheback to summary
private final HashMap<StyleAttributeMap, StyleAttributeMap> styleCache

Constructor Detail

RichTextModelback to summary
public RichTextModel()

Constructs the empty model.

Method Detail

applyStyleback to summary
protected void applyStyle(int index, int start, int end, StyleAttributeMap attrs, boolean merge)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.applyStyle.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.applyStyle.

Applies style to the specified text range within a single paragraph. The new attributes override any existing attributes. The end argument may exceed the paragraph length, in which case the outcome should be the same as supplying the paragraph length value.

Parameters
index:int

the paragraph index

start:int

the start offset

end:int

the end offset

attrs:StyleAttributeMap

the character attributes

merge:boolean

determines whether to merge with or overwrite the existing attributes

Annotations
@Override
dedupback to summary
private StyleAttributeMap dedup(StyleAttributeMap a)

deduplicates style attributes.

dumpback to summary
private static void dump(StyledTextModel model, PrintStream out)

Temporary method added for testing; will be removed in production.

Parameters
model:StyledTextModel

the model

out:PrintStream

the output

dumpback to summary
private void dump(PrintStream out)
dumpback to summary
private void dump(RichTextModel.RParagraph p, PrintStream out)
getParagraphback to summary
public RichParagraph getParagraph(int index)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.getParagraph.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.getParagraph.

Returns a RichParagraph at the given model index. The callers must ensure that the value of index is within the valid document range, since doing otherwise might result in an exception or undetermined behavior.

This method makes no guarantees that the same paragraph instance will be returned for the same model index.

Parameters
index:int

the paragraph index in the range (0...size())

Returns:RichParagraph

the instance of RichParagraph

Annotations
@Override
getParagraphLengthback to summary
public int getParagraphLength(int index)

Overrides jfx.incubator.scene.control.richtext.model.StyledTextModel.getParagraphLength.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.getParagraphLength.

Returns the length of text in a paragraph at the specified index.

Parameters
index:int

the paragraph index

Returns:int

the length

Annotations
@Override
getPlainTextback to summary
public String getPlainText(int index)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.getPlainText.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.getPlainText.

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 index is within the valid document range, since doing otherwise might result in an exception or undetermined behavior.

Parameters
index:int

the paragraph index in the range (0...size())

Returns:String

the non-null paragraph text string

Annotations
@Override
getStyleAttributeMapback to summary
public StyleAttributeMap getStyleAttributeMap(StyleResolver resolver, TextPos pos)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.getStyleAttributeMap.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.getStyleAttributeMap.

Returns the StyleAttributeMap of the character at the specified position's charIndex. When at the end of the document, returns the attributes of the last character.

Parameters
resolver:StyleResolver

the style resolver

pos:TextPos

the text position

Returns:StyleAttributeMap

the style attributes, non-null

Annotations
@Override
insertLineBreakback to summary
protected void insertLineBreak(int index, int offset)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.insertLineBreak.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.insertLineBreak.

Inserts a line break at the specified position.

Parameters
index:int

the model index

offset:int

the text offset

Annotations
@Override
insertParagraphback to summary
protected void insertParagraph(int index, Supplier<Region> generator)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.insertParagraph.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.insertParagraph.

Inserts a paragraph that contains a single Region.

The model should not cache or otherwise retain references to the created Regions, as they might be requested multiple times during the lifetime of the model, or by different views.

This method allows for embedding Controls that handle user input. In this case, the model should declare necessary properties and provide bidirectional bindings between the properties in the model and the corresponding properties in the control, as well as handle copy, paste, writing to and reading from I/O streams.

Parameters
index:int

model index

generator:Supplier<Region>

code that will be used to create a Node instance

Annotations
@Override
insertTextSegmentback to summary
protected int insertTextSegment(int index, int offset, String text, StyleAttributeMap attrs)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.insertTextSegment.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.insertTextSegment.

This method is called to insert a single styled text segment at the given position.

Parameters
index:int

the paragraph index

offset:int

the insertion offset within the paragraph

text:String

the text to insert

attrs:StyleAttributeMap

the style attributes

Returns:int

the number of characters inserted

Annotations
@Override
isWritableback to summary
public final boolean isWritable()

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.isWritable.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.isWritable.

Indicates whether the model supports content modifications made via applyStyle(), replace(), undo(), redo() methods.

Note that even when this method returns false, the model itself may still update its content and fire the change events as a response, for example, to changes in its backing data storage.

Returns:boolean

true if the model supports content modifications

Annotations
@Override
removeRangeback to summary
protected void removeRange(TextPos start, TextPos end)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.removeRange.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.removeRange.

Removes the specified text range. This method gets called only if the model is editable. The caller guarantees that start precedes end.

Parameters
start:TextPos

the start of the range to be removed

end:TextPos

the end of the range to be removed, expected to be greater than the start position

Annotations
@Override
setParagraphStyleback to summary
protected void setParagraphStyle(int index, StyleAttributeMap attrs)

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.setParagraphStyle.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.setParagraphStyle.

Replaces the paragraph styles in the specified paragraph.

Parameters
index:int

the paragraph index

attrs:StyleAttributeMap

the paragraph attributes

Annotations
@Override
sizeback to summary
public int size()

Implements abstract jfx.incubator.scene.control.richtext.model.StyledTextModel.size.

Doc from jfx.incubator.scene.control.richtext.model.StyledTextModel.size.

Returns the number of paragraphs in the model.

Returns:int

number of paragraphs

Annotations
@Override
jfx.incubator.scene.control.richtext.model back to summary

pack-priv Class RichTextModel.RParagraph

extends ArrayList<RichTextModel.RSegment>
Class Inheritance

Model paragraph is a list of RSegments.

Field Summary

Modifier and TypeField and Description
private StyleAttributeMap

Constructor Summary

AccessConstructor and Description
public
RParagraph()

Creates an instance

Method Summary

Modifier and TypeMethod and Description
public void
append(RichTextModel.RParagraph
the paragraph to append
p
)

Appends 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 segment
applyStyle
(int
the paragraph index
ix
,
RichTextModel.RSegment
the segment
seg
,
StyleAttributeMap
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 info
getStyleAttributeMap
(int
the offset
offset
)

Retrieves the style attributes from the previous character (or next, if at the beginning).

public int
public RichTextModel.RParagraph

Returns:

the remaining portion of paragraph
insertLineBreak
(int
the 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 segment
insertSegment
(int ix, String text, StyleAttributeMap a)

inserts a new segment with the specified, deduplicated attributes.

private boolean

Returns:

true if a segment has been added.
insertSegment2
(int
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
removeSpan(int start, int end)

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:  ----------------|
Inherited from java.util.ArrayList:
addaddaddAlladdAlladdFirstaddLastclearclonecontainsensureCapacityequalsforEachgetgetFirstgetLasthashCodeindexOfisEmptyiteratorlastIndexOflistIteratorlistIteratorremoveremoveremoveAllremoveFirstremoveIfremoveLastremoveRangereplaceAllretainAllsetsizesortspliteratorsubListtoArraytoArraytrimToSize

Field Detail

paragraphAttrsback to summary
private StyleAttributeMap paragraphAttrs

Constructor Detail

RParagraphback to summary
public RParagraph()

Creates an instance

Method Detail

appendback to summary
public void append(RichTextModel.RParagraph p)

Appends the specified paragraph by adding all of its segments.

Parameters
p:RichTextModel.RParagraph

the paragraph to append

applyStyleback to summary
public void applyStyle(int start, int end, StyleAttributeMap attrs, boolean merge, Function<StyleAttributeMap, StyleAttributeMap> dedup)
applyStyleback to summary
private boolean applyStyle(int ix, RichTextModel.RSegment seg, StyleAttributeMap a, boolean merge, Function<StyleAttributeMap, StyleAttributeMap> dedup)

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.

Parameters
ix:int

the paragraph index

seg:RichTextModel.RSegment

the segment

a:StyleAttributeMap

the attributes

merge:boolean

whether to merge or set

dedup:Function<StyleAttributeMap, StyleAttributeMap>

the deduplicator

Returns:boolean

true if this segment has been merged with the previous segment

createRichParagraphback to summary
private RichParagraph createRichParagraph()
getParagraphAttributesback to summary
public StyleAttributeMap getParagraphAttributes()
getPlainTextback to summary
public String getPlainText()
getStyleAttributeMapback to summary
public StyleAttributeMap getStyleAttributeMap(int offset)

Retrieves the style attributes from the previous character (or next, if at the beginning).

Parameters
offset:int

the offset

Returns:StyleAttributeMap

the style info

getTextLengthback to summary
public int getTextLength()
insertLineBreakback to summary
public RichTextModel.RParagraph insertLineBreak(int offset)

Trims this paragraph and returns the remaining text to be inserted after the line break.

Parameters
offset:int

the offset

Returns:RichTextModel.RParagraph

the remaining portion of paragraph

insertSegmentback 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.

Returns:boolean

true if the new segment has been merged with the previous segment

insertSegment2back 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.

Parameters
ix:int

the segment index

text:String

the plain text

a:StyleAttributeMap

the style attributes

Returns:boolean

true if a segment has been added.

insertTextback to summary
public void insertText(int offset, String text, StyleAttributeMap attrs)

Inserts styled text at the specified offset.

Parameters
offset:int

the insertion offset

text:String

the plain text

attrs:StyleAttributeMap

the style attributes

isMergeback to summary
private boolean isMerge(RichTextModel.RParagraph p)
isZeroWidthback to summary
private boolean isZeroWidth()
removeSpanback to summary
public void removeSpan(int start, int end)
setParagraphAttributesback to summary
public void setParagraphAttributes(StyleAttributeMap a)
whichCaseback 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:  ----------------|

jfx.incubator.scene.control.richtext.model back to summary

private Class RichTextModel.RSegment

extends Object
Class Inheritance
  • java.lang.Object
  • jfx.incubator.scene.control.richtext.model.RichTextModel.RSegment

Represents a rich text segment having the same style attributes.

Field Summary

Modifier and TypeField and Description
private StyleAttributeMap
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public StyleAttributeMap
public StyleAttributeMap
public int
public boolean
removeRegion(int start, int end)

returns true if this segment becomes empty as a result

public void
public void
public String
text()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attrsback to summary
private StyleAttributeMap attrs
textback to summary
private String text

Constructor Detail

RSegmentback to summary
public RSegment(String text, StyleAttributeMap attrs)

Method Detail

appendback to summary
public void append(String s)
attrsback to summary
public StyleAttributeMap attrs()
getStyleAttributeMapback to summary
public StyleAttributeMap getStyleAttributeMap()
getTextLengthback to summary
public int getTextLength()
removeRegionback to summary
public boolean removeRegion(int start, int end)

returns true if this segment becomes empty as a result

setAttrsback to summary
public void setAttrs(StyleAttributeMap a)
setTextback to summary
public void setText(String s)
textback to summary
public String text()