APIdia Launch Partner
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, .Map, java.util.function.Function, .Supplier, javafx.beans.property.DoubleProperty, .SimpleDoubleProperty, javafx.scene.layout.Region, com.sun.jfx.incubator.scene.control.richtext.Params, com.sun.jfx.incubator.scene.control.richtext.util.RichUtils, 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
private 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
public static final double
DEFAULT_TAB_STOPS_DISABLED

This value of the defaultTabStopsProperty() disables the default tab stops, making a tab characters appear as a single space.

public static final double
DEFAULT_TAB_STOPS_FIXED

This value of the defaultTabStopsProperty() results in a legacy behavior where the tab spacing corresponds to 8 spaces.

private DoubleProperty
private final ArrayList<RichTextModel.RParagraph>
private static final String
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
applyParagraphStyle(int index, StyleAttributeMap attrs)

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

Applies paragraph styles in the specified paragraph.

protected void
applyStyle(int index, int start, int end, StyleAttributeMap attrs, boolean 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.

public final DoubleProperty

Returns:

the default tab stop interval property
defaultTabStopsProperty
()

Specifies the default tab stop interval for tabs beyond the last stop provided by the paragraph's StyleAttributeMap.TAB_STOPS attribute, if any.

protected Map<String, String>
documentProperties()

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

This method is called by export(TextPos, TextPos, StyledOutput) to ensure that the document properties, if any, are exported.

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 final double
public RichParagraph
getParagraph(int index)

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

Returns a RichParagraph at the given model index.

public int
getParagraphLength(int 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 index)

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

Returns the plain text string for the specified paragraph.

public StyleAttributeMap
getStyleAttributeMap(StyleResolver resolver, TextPos pos, boolean forInsert)

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

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

protected void
handleDocumentProperties(Map<String, String> p, boolean completeReplacement)

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

This method is called by any of the replace() methods when encountering a StyledSegment.Type#DOCUMENT_PROPERTIES segment.

protected void
insertLineBreak(int index, int offset)

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

Inserts a line break at the specified position.

protected void
insertParagraph(int index, Supplier<Region> generator)

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

Inserts a paragraph that contains a single Region.

protected int
insertTextSegment(int index, int offset, String text, StyleAttributeMap 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 RichParagraph.Builder

Returns:

the builder
prepareParagraph
(int
the paragraph index
index
)

Prepares the paragraph by populating a builder with the paragraph content.

protected void
removeRange(TextPos start, TextPos end)

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

Removes the specified text range.

public final void
setDefaultTabStops(double value)

protected void
setParagraphStyle(int index, StyleAttributeMap 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.

protected String
versionString()

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

This method is called by export(TextPos, TextPos, StyledOutput) to export the model's version string, if any.

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

Field Detail

DEFAULT_TAB_STOPS_DISABLEDback to summary
public static final double DEFAULT_TAB_STOPS_DISABLED

This value of the defaultTabStopsProperty() disables the default tab stops, making a tab characters appear as a single space.

Since
27
DEFAULT_TAB_STOPS_FIXEDback to summary
public static final double DEFAULT_TAB_STOPS_FIXED

This value of the defaultTabStopsProperty() results in a legacy behavior where the tab spacing corresponds to 8 spaces. This may result in milasigned columns when different text segments use different fonts.

Since
27
defaultTabStopsback to summary
private DoubleProperty defaultTabStops
paragraphsback to summary
private final ArrayList<RichTextModel.RParagraph> paragraphs
PROP_TABSback to summary
private static final String PROP_TABS
styleCacheback to summary
private final HashMap<StyleAttributeMap, StyleAttributeMap> styleCache

Constructor Detail

RichTextModelback to summary
public RichTextModel()

Constructs the empty model.

Method Detail

applyParagraphStyleback to summary
protected void applyParagraphStyle(int index, StyleAttributeMap attrs)

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

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

Applies paragraph styles in the specified paragraph.

Annotations
@Override
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 end argument may exceed the paragraph length, in which case the outcome should be the same as supplying the paragraph length value.

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

deduplicates style attributes.

defaultTabStopsPropertyback to summary
public final DoubleProperty defaultTabStopsProperty()

Specifies the default tab stop interval for tabs beyond the last stop provided by the paragraph's StyleAttributeMap.TAB_STOPS attribute, if any. This is a fixed repeating distance (in pixels) to the next tab stop computed at regular intervals relative to the document content leading edge.

Value DEFAULT_TAB_STOPS_FIXED results in a legacy behavior where the tab spacing corresponds to 8 spaces. This may result in milasigned columns when different text segments use different fonts. The value DEFAULT_TAB_STOPS_DISABLED disables the default interval, rendering tab character as a single space.

Returns:DoubleProperty

the default tab stop interval property

Default Value
DEFAULT_TAB_STOPS_FIXED
Since
27
documentPropertiesback to summary
protected Map<String, String> documentProperties()

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

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

This method is called by export(TextPos, TextPos, StyledOutput) to ensure that the document properties, if any, are exported.

Annotations
@Override
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)
getDefaultTabStopsback to summary
public final double getDefaultTabStops()
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.

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.

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.

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

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 the position points to the boundary between two text segments with different attributes, the value of forInsert determines which segment will be used: when true, the preceding segment's attributes will be returned so inserted/typed text has the same style as the preceding text. When forInsert is false, the returned attributes correspond exactly to the symbol indicated by the specified position.

Annotations
@Override
handleDocumentPropertiesback to summary
protected void handleDocumentProperties(Map<String, String> p, boolean completeReplacement)

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

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

This method is called by any of the replace() methods when encountering a StyledSegment.Type#DOCUMENT_PROPERTIES segment.

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.

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.

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.

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.

Annotations
@Override
prepareParagraphback to summary
protected RichParagraph.Builder prepareParagraph(int index)

Prepares the paragraph by populating a builder with the paragraph content. This method allows the custom model to add highlights and decorations without affecting the base class storage model.

Parameters
index:int

the paragraph index

Returns:RichParagraph.Builder

the builder

Since
26
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.

Annotations
@Override
setDefaultTabStopsback to summary
public final void setDefaultTabStops(double value)
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.

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.

Annotations
@Override
versionStringback to summary
protected String versionString()

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

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

This method is called by export(TextPos, TextPos, StyledOutput) to export the model's version string, if any.

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

private 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
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.Builder
public StyleAttributeMap
public String
public StyleAttributeMap

Returns:

the style attributes, non-null
getStyleAttributeMap
(int
the character index
charIndex
,
boolean
the leading/trailing bias
leading
,
boolean
whether to pick preceding style at the segment boundary
forInsert
)

Retrieves the style attributes at the specified position.

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

applyParagraphAttributesback to summary
public void applyParagraphAttributes(StyleAttributeMap a)
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

buildParagraphback to summary
private RichParagraph.Builder buildParagraph()
getParagraphAttributesback to summary
public StyleAttributeMap getParagraphAttributes()
getPlainTextback to summary
public String getPlainText()
getStyleAttributeMapback to summary
public StyleAttributeMap getStyleAttributeMap(int charIndex, boolean leading, boolean forInsert)

Retrieves the style attributes at the specified position.

Parameters
charIndex:int

the character index

leading:boolean

the leading/trailing bias

forInsert:boolean

whether to pick preceding style at the segment boundary

Returns:StyleAttributeMap

the style attributes, non-null

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()