Class RichTextModel
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 Class Summary
Nested classes/interfaces declared in class StyledTextModel
StyledTextModel.ListenerModifier and TypeClassDescriptionstatic interfaceReceives information about modifications of the model. -
Property Summary
PropertiesTypePropertyDescriptionfinal DoublePropertySpecifies the default tab stop interval for tabs beyond the last stop provided by the paragraph'sStyleAttributeMap.TAB_STOPSattribute, if any.Properties declared in class StyledTextModel
redoable, undoableTypePropertyDescriptionfinal ReadOnlyBooleanPropertyThe property describes if it's currently possible to redo the latest change of the content that was undone.final ReadOnlyBooleanPropertyThe property describes if it's currently possible to undo the latest change of the content that was done. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThis value of thedefaultTabStopsProperty()disables the default tab stops, making a tab characters appear as a single space.static final doubleThis value of thedefaultTabStopsProperty()results in a legacy behavior where the tab spacing corresponds to 8 spaces. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyParagraphStyle(int index, StyleAttributeMap attrs) Applies paragraph styles in the specified paragraph.protected voidapplyStyle(int index, int start, int end, StyleAttributeMap attrs, boolean merge) Applies style to the specified text range within a single paragraph.final DoublePropertySpecifies the default tab stop interval for tabs beyond the last stop provided by the paragraph'sStyleAttributeMap.TAB_STOPSattribute, if any.final doubleGets the value of thedefaultTabStopsproperty.getParagraph(int index) Returns aRichParagraphat the given model index.getPlainText(int index) Returns the plain text string for the specified paragraph.getStyleAttributeMap(StyleResolver resolver, TextPos pos, boolean forInsert) Returns theStyleAttributeMapof the character at the specified position'scharIndex.protected voidinsertLineBreak(int index, int offset) Inserts a line break at the specified position.protected voidinsertParagraph(int index, Supplier<Region> generator) Inserts a paragraph that contains a singleRegion.protected intinsertTextSegment(int index, int offset, String text, StyleAttributeMap attrs) This method is called to insert a single styled text segment at the given position.final booleanIndicates whether the model supports content modifications made viaapplyStyle(),replace(),undo(),redo()methods.protected RichParagraph.BuilderprepareParagraph(int index) Prepares the paragraph by populating a builder with the paragraph content.protected voidremoveRange(TextPos start, TextPos end) Removes the specified text range.final voidsetDefaultTabStops(double value) Sets the value of thedefaultTabStopsproperty.protected voidsetParagraphStyle(int index, StyleAttributeMap attrs) Replaces the paragraph styles in the specified paragraph.intsize()Returns the number of paragraphs in the model.Methods declared in class StyledTextModel
addListener, applyStyle, clamp, clearUndoRedo, documentProperties, export, exportParagraph, fireChangeEvent, fireStyleChangeEvent, getDataFormatHandler, getDocumentEnd, getEndOfParagraphTextPos, getLineEnding, getMarker, getParagraphLength, getSupportedAttributes, getSupportedDataFormats, handleDocumentProperties, isRedoable, isUndoable, isUndoRedoEnabled, read, redo, redoableProperty, registerDataFormatHandler, removeDataFormatHandler, removeListener, replace, replace, setLineEnding, setUndoRedoEnabled, undo, undoableProperty, versionString, writeModifier and TypeMethodDescriptionfinal voidaddListener(StyledTextModel.Listener listener) Adds aStyledTextModel.Listenerto this model.final voidapplyStyle(TextPos start, TextPos end, StyleAttributeMap attrs, boolean mergeAttributes) Applies the style attributes to the specified range in the document.final TextPosReturns the text position guaranteed to be within the document and paragraph limits.final voidClears the undo-redo stack.This method is called byStyledTextModel.export(TextPos, TextPos, StyledOutput)to ensure that the document properties, if any, are exported.final voidexport(TextPos start, TextPos end, StyledOutput out) Exports the stream ofStyledSegments in the given range to the specifiedStyledOutput.protected final voidexportParagraph(int index, int start, int end, boolean withParAttrs, StyledOutput out) Exports part of the paragraph as a sequence of styled segments.voidfireChangeEvent(TextPos start, TextPos end, int charsTop, int linesAdded, int charsBottom) Fires a text modification event for the given range.voidfireStyleChangeEvent(TextPos start, TextPos end) Fires a style change event for the given range.final DataFormatHandlergetDataFormatHandler(DataFormat format, boolean forExport) Returns aDataFormatHandlerinstance corresponding to the givenDataFormat.final TextPosReturns the text position corresponding to the end of the document.final TextPosgetEndOfParagraphTextPos(int index) Returns a TextPos corresponding to the end of paragraph at the given index.final LineEndingSpecifies the line ending characters.final MarkerReturns theMarkerat the specified position.intgetParagraphLength(int index) Returns the length of text in a paragraph at the specified index.protected Set<StyleAttribute<?>> Returns the set of attributes supported attributes.final List<DataFormat> getSupportedDataFormats(boolean forExport) Returns an immutable list of supported data formats for either export or import operations, in the order of priority - from high to low.protected voidhandleDocumentProperties(Map<String, String> props, boolean completeReplacement) This method is called by any of thereplace()methods when encountering aStyledSegment.Type.DOCUMENT_PROPERTIESsegment.final booleanGets the value of theredoableproperty.final booleanGets the value of theundoableproperty.final booleanIndicates whether undo/redo functionality is enabled.final voidread(StyleResolver r, DataFormat f, InputStream input) Replaces the content of the model with the data read from the input stream, using the specifiedDataFormat.final TextPos[]redo(StyleResolver resolver) Redoes the recent change, if possible, returning an array comprising [start, end] text positions prior to the change.final ReadOnlyBooleanPropertyThe property describes if it's currently possible to redo the latest change of the content that was undone.protected final voidregisterDataFormatHandler(DataFormatHandler h, boolean forExport, boolean forImport, int priority) Registers a format handler for export and/or import operations.protected final voidremoveDataFormatHandler(DataFormat f, boolean forExport, boolean forImport) Removes the data format handler registered previously withStyledTextModel.registerDataFormatHandler(DataFormatHandler, boolean, boolean, int).final voidremoveListener(StyledTextModel.Listener listener) Removes aStyledTextModel.Listenerfrom this model.final TextPosreplace(StyleResolver resolver, TextPos start, TextPos end, String text) Replaces the given range with the provided plain text.final TextPosreplace(StyleResolver resolver, TextPos start, TextPos end, StyledInput input) Replaces the given range with the provided styled text input.final voidsetLineEnding(LineEnding value) Sets the line ending characters.final voidsetUndoRedoEnabled(boolean on) Controls whether undo/redo functionality is enabled.final TextPos[]undo(StyleResolver resolver) Undoes the recent change, if possible, returning an array comprising [start, end] text positions prior to the change.final ReadOnlyBooleanPropertyThe property describes if it's currently possible to undo the latest change of the content that was done.protected StringThis method is called byStyledTextModel.export(TextPos, TextPos, StyledOutput)to export the model's version string, if any.final voidwrite(StyleResolver r, DataFormat f, OutputStream out) Writes the model content to the output stream using the specifiedDataFormat.
-
Property Details
-
defaultTabStops
Specifies the default tab stop interval for tabs beyond the last stop provided by the paragraph'sStyleAttributeMap.TAB_STOPSattribute, 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_FIXEDresults 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 valueDEFAULT_TAB_STOPS_DISABLEDdisables the default interval, rendering tab character as a single space.- Default value:
- DEFAULT_TAB_STOPS_FIXED
- Since:
- 27
- See Also:
-
-
Field Details
-
DEFAULT_TAB_STOPS_FIXED
public static final double DEFAULT_TAB_STOPS_FIXEDThis value of thedefaultTabStopsProperty()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
- See Also:
-
DEFAULT_TAB_STOPS_DISABLED
public static final double DEFAULT_TAB_STOPS_DISABLEDThis value of thedefaultTabStopsProperty()disables the default tab stops, making a tab characters appear as a single space.- Since:
- 27
- See Also:
-
-
Constructor Details
-
RichTextModel
public RichTextModel()Constructs the empty model.
-
-
Method Details
-
defaultTabStopsProperty
Specifies the default tab stop interval for tabs beyond the last stop provided by the paragraph'sStyleAttributeMap.TAB_STOPSattribute, 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_FIXEDresults 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 valueDEFAULT_TAB_STOPS_DISABLEDdisables the default interval, rendering tab character as a single space.- Default value:
- DEFAULT_TAB_STOPS_FIXED
- Returns:
- the default tab stop interval property
- Since:
- 27
- See Also:
-
setDefaultTabStops
public final void setDefaultTabStops(double value) Sets the value of thedefaultTabStopsproperty.- Property description:
- Specifies the default tab stop interval for tabs beyond the last stop provided
by the paragraph's
StyleAttributeMap.TAB_STOPSattribute, 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_FIXEDresults 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 valueDEFAULT_TAB_STOPS_DISABLEDdisables the default interval, rendering tab character as a single space. - Default value:
- DEFAULT_TAB_STOPS_FIXED
- Parameters:
value- the value for thedefaultTabStopsproperty- Since:
- 27
- See Also:
-
getDefaultTabStops
public final double getDefaultTabStops()Gets the value of thedefaultTabStopsproperty.- Property description:
- Specifies the default tab stop interval for tabs beyond the last stop provided
by the paragraph's
StyleAttributeMap.TAB_STOPSattribute, 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_FIXEDresults 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 valueDEFAULT_TAB_STOPS_DISABLEDdisables the default interval, rendering tab character as a single space. - Default value:
- DEFAULT_TAB_STOPS_FIXED
- Returns:
- the value of the
defaultTabStopsproperty - Since:
- 27
- See Also:
-
isWritable
public final boolean isWritable()Description copied from class:StyledTextModelIndicates whether the model supports content modifications made viaapplyStyle(),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.- Specified by:
isWritablein classStyledTextModel- Returns:
- true if the model supports content modifications
-
size
public int size()Description copied from class:StyledTextModelReturns the number of paragraphs in the model.- Specified by:
sizein classStyledTextModel- Returns:
- number of paragraphs
-
getPlainText
Description copied from class:StyledTextModelReturns 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 ofindexis within the valid document range, since doing otherwise might result in an exception or undetermined behavior.- Specified by:
getPlainTextin classStyledTextModel- Parameters:
index- the paragraph index in the range (0...StyledTextModel.size())- Returns:
- the non-null paragraph text string
-
getParagraph
Description copied from class:StyledTextModelReturns aRichParagraphat the given model index. The callers must ensure that the value ofindexis 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.
- Specified by:
getParagraphin classStyledTextModel- Parameters:
index- the paragraph index in the range (0...StyledTextModel.size())- Returns:
- the instance of
RichParagraph
-
prepareParagraph
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- the paragraph index- Returns:
- the builder
- Since:
- 26
-
insertTextSegment
Description copied from class:StyledTextModelThis method is called to insert a single styled text segment at the given position.- Specified by:
insertTextSegmentin classStyledTextModel- Parameters:
index- the paragraph indexoffset- the insertion offset within the paragraphtext- the text to insertattrs- the style attributes- Returns:
- the number of characters inserted
-
insertLineBreak
protected void insertLineBreak(int index, int offset) Description copied from class:StyledTextModelInserts a line break at the specified position.- Specified by:
insertLineBreakin classStyledTextModel- Parameters:
index- the model indexoffset- the text offset
-
removeRange
Description copied from class:StyledTextModelRemoves the specified text range. This method gets called only if the model is editable. The caller guarantees thatstartprecedesend.- Specified by:
removeRangein classStyledTextModel- Parameters:
start- the start of the range to be removedend- the end of the range to be removed, expected to be greater than the start position
-
insertParagraph
Description copied from class:StyledTextModelInserts a paragraph that contains a singleRegion.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.- Specified by:
insertParagraphin classStyledTextModel- Parameters:
index- model indexgenerator- code that will be used to create a Node instance
-
applyParagraphStyle
Description copied from class:StyledTextModelApplies paragraph styles in the specified paragraph.- Specified by:
applyParagraphStylein classStyledTextModel- Parameters:
index- the paragraph indexattrs- the paragraph attributes
-
setParagraphStyle
Description copied from class:StyledTextModelReplaces the paragraph styles in the specified paragraph.- Specified by:
setParagraphStylein classStyledTextModel- Parameters:
index- the paragraph indexattrs- the paragraph attributes
-
applyStyle
Description copied from class:StyledTextModelApplies style to the specified text range within a single paragraph. Theendargument may exceed the paragraph length, in which case the outcome should be the same as supplying the paragraph length value.- Specified by:
applyStylein classStyledTextModel- Parameters:
index- the paragraph indexstart- the start offsetend- the end offsetattrs- the character attributesmerge- determines whether to merge with or completely replace the existing attribute map
-
getStyleAttributeMap
public StyleAttributeMap getStyleAttributeMap(StyleResolver resolver, TextPos pos, boolean forInsert) Description copied from class:StyledTextModelReturns theStyleAttributeMapof the character at the specified position'scharIndex.When the position points to the boundary between two text segments with different attributes, the value of
forInsertdetermines which segment will be used: whentrue, the preceding segment's attributes will be returned so inserted/typed text has the same style as the preceding text. WhenforInsertisfalse, the returned attributes correspond exactly to the symbol indicated by the specified position.- Specified by:
getStyleAttributeMapin classStyledTextModel- Parameters:
resolver- the style resolverpos- the text positionforInsert- whether to pick preceding style at the segment boundary- Returns:
- the style attributes, non-null
-