Class SimpleViewOnlyStyledModel
- 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
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. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddImage(InputStream in) Adds a paragraph containing an image.addNodeSegment(Supplier<Node> generator) Adds an inline Node to the last paragraph.addParagraph(Supplier<Region> generator) Adds a paragraph containing aRegion.addSegment(String text) Appends a text segment to the last paragraph.addSegment(String text, StyleAttributeMap a) Appends a text segment styled with the specified style attributes.addWavyUnderline(int start, int length, String... css) Adds a wavy underline (typically used as a spell checker indicator) to the specified range within the last paragraph, with the specified style name(s).addWavyUnderline(int start, int length, Color c) Adds a wavy underline (typically used as a spell checker indicator) to the specified range within the last paragraph.addWithInlineAndStyleNames(String text, String style, String... css) Appends a text segment styled with both the inline style and the stylesheet style names.addWithInlineStyle(String text, String style) Appends a text segment styled with the inline style.addWithStyleNames(String text, String... css) Appends a text segment styled with the stylesheet style names.getParagraph(int index) Returns aRichParagraphat the given model index.getPlainText(int index) Returns the plain text string for the specified paragraph.getStyleAttributeMap(StyleResolver r, TextPos pos, boolean forInsert) Returns theStyleAttributeMapof the character at the specified position'scharIndex.Adds a highlight of the given color to the specified range within the last paragraph, with the specified style name(s).Adds a highlight of the given color to the specified range within the last paragraph.nl()Adds a new paragraph (as if inserting a newline symbol into the text).nl(int count) Addsnnew paragraphs (as if inserting a newline symbol into the textntimes).static SimpleViewOnlyStyledModelCreates the model from the supplied text string by breaking it down into individual text segments, by splitting on newline characters.Sets the last paragraph's attributes.intsize()Returns the number of paragraphs in the model.Methods declared in class StyledTextModelViewOnlyBase
applyParagraphStyle, applyStyle, insertLineBreak, insertParagraph, insertTextSegment, isWritable, removeRange, setParagraphStyleModifier and TypeMethodDescriptionprotected final voidapplyParagraphStyle(int ix, StyleAttributeMap a) Applies paragraph styles in the specified paragraph.protected final voidapplyStyle(int ix, int start, int end, StyleAttributeMap a, boolean merge) Applies style to the specified text range within a single paragraph.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 voidremoveRange(TextPos start, TextPos end) Removes the specified text range.protected final voidsetParagraphStyle(int ix, StyleAttributeMap a) Replaces the paragraph styles in the specified paragraph.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.
-
Constructor Details
-
SimpleViewOnlyStyledModel
public SimpleViewOnlyStyledModel()The constructor.
-
-
Method Details
-
of
Creates the model from the supplied text string by breaking it down into individual text segments, by splitting on newline characters.- Parameters:
text- the input multi-line text- Returns:
- the new instance
- Throws:
IOException- if an I/O error occurs
-
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
-
addSegment
Appends a text segment to the last paragraph. The caller must ensure that thetextdoes not contain newline symbols, as the behavior is undefined in this case.This convenience method is equivalent to calling
addSegment(text, StyleAttributeMap.EMPTY);- Parameters:
text- the text to append, must not contain newline symbols, cannot be null- Returns:
- this model instance
-
addWithInlineAndStyleNames
public SimpleViewOnlyStyledModel addWithInlineAndStyleNames(String text, String style, String... css) Appends a text segment styled with both the inline style and the stylesheet style names. Thetextcannot contain newline (\n) symbols.- Parameters:
text- the text to append, must not contain\n, cannot be nullstyle- the inline style (example"-fx-fill:red;")css- the stylesheet style names- Returns:
- this model instance
-
addWithStyleNames
Appends a text segment styled with the stylesheet style names. Thetextcannot contain newline (\n) symbols.- Parameters:
text- the text to append, must not contain\n, cannot be nullcss- the stylesheet style names- Returns:
- this model instance
-
addWithInlineStyle
Appends a text segment styled with the inline style. Thetextcannot contain newline (\n) symbols.- Parameters:
text- the text to append, must not contain\n, cannot be nullstyle- the inline style (example"-fx-fill:red;"), or null- Returns:
- this model instance
-
addSegment
Appends a text segment styled with the specified style attributes.- Parameters:
text- the text to append, must not contain control symbols other than TAB.a- the style attributes- Returns:
- this model instance
-
highlight
Adds a highlight of the given color to the specified range within the last paragraph.- Parameters:
start- the start offsetlength- the length of the highlightc- the highlight color- Returns:
- this model instance
-
highlight
Adds a highlight of the given color to the specified range within the last paragraph, with the specified style name(s).- Parameters:
start- the start offsetlength- the length of the highlightcss- the highlight style name(s)- Returns:
- this model instance
- Since:
- 25
-
addWavyUnderline
Adds a wavy underline (typically used as a spell checker indicator) to the specified range within the last paragraph.- Parameters:
start- the start offsetlength- the length of the highlightc- the highlight color- Returns:
- this model instance
-
addWavyUnderline
Adds a wavy underline (typically used as a spell checker indicator) to the specified range within the last paragraph, with the specified style name(s).- Parameters:
start- the start offsetlength- the length of the highlightcss- the highlight style name(s)- Returns:
- this model instance
- Since:
- 25
-
addImage
Adds a paragraph containing an image. The image will be reduced in size as necessary to fit into the available area ifwrapTextproperty is set. This method does not close the input stream.- Parameters:
in- the input stream providing the image.- Returns:
- this model instance
-
addParagraph
Adds a paragraph containing aRegion.The supplied generator must not cache or keep reference to the created
Region, but the createdRegioncan keep a reference to the model or a property therein.For example, a bidirectional binding between an inline control and some property in the model would synchronize the model with all the views that use it.
- Parameters:
generator- the supplier of the paragraph content- Returns:
- this model instance
-
addNodeSegment
Adds an inline Node to the last paragraph.The supplied generator must not cache or keep reference to the created
Node, but the createdNodecan keep a reference to the model or a property therein.For example, a bidirectional binding between an inline control and some property in the model would synchronize the model with all the views that use it.
- Parameters:
generator- the supplier of the embedded Node- Returns:
- this model instance
-
nl
Adds a new paragraph (as if inserting a newline symbol into the text). This convenience method invokesnl(int)with a value of 1.- Returns:
- this model instance
-
nl
Addsnnew paragraphs (as if inserting a newline symbol into the textntimes).- Parameters:
count- the number of paragraphs to append- Returns:
- this model instance
-
getStyleAttributeMap
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:
r- the style resolverpos- the text positionforInsert- whether to pick preceding style at the segment boundary- Returns:
- the style attributes, non-null
-
setParagraphAttributes
Sets the last paragraph's attributes.- Parameters:
a- the paragraph attributes- Returns:
- this model instance
-