Class BasicTextModel
- Direct Known Subclasses:
CodeTextModel
This class provides no styling. Subclasses might override getParagraph(int)
to provide
syntax highlighting based on the model content.
This model supports custom content storage mechanism via BasicTextModel.Content
. By default,
the model provides an in-memory storage via its BasicTextModel.InMemoryContent
implementation.
- Since:
- 24
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
This interface describes the underlying storage mechanism for the BasicTextModel.static class
This content provides in-memory storage in anArrayList
ofString
s.Nested classes/interfaces declared in class jfx.incubator.scene.control.richtext.model.StyledTextModel
StyledTextModel.Listener
-
Property Summary
Properties declared in class jfx.incubator.scene.control.richtext.model.StyledTextModel
redoable, undoable
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty model with the in-memoryContent
.Constructs an empty model with the specifiedContent
. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
applyStyle
(int index, int start, int end, StyleAttributeMap a, boolean merge) Applies style to the specified text range within a single paragraph.getParagraph
(int index) Returns aRichParagraph
at the given model index.getPlainText
(int index) Returns the plain text string for the specified paragraph.getStyleAttributeMap
(StyleResolver resolver, TextPos pos) Returns theStyleAttributeMap
of the character at the specified position'scharIndex
.protected void
insertLineBreak
(int index, int offset) Inserts a line break at the specified position.protected void
insertParagraph
(int index, Supplier<Region> generator) Inserts a paragraph that contains a singleRegion
.void
insertText
(TextPos p, String text) Inserts text at the specified position.protected int
insertTextSegment
(int index, int offset, String text, StyleAttributeMap attrs) This method is called to insert a single styled text segment at the given position.final boolean
Determines whether the model is writable.protected void
removeRange
(TextPos start, TextPos end) Removes the specified text range.protected final void
setParagraphStyle
(int index, StyleAttributeMap a) Replaces the paragraph styles in the specified paragraph.int
size()
Returns the number of paragraphs in the model.Methods declared in class jfx.incubator.scene.control.richtext.model.StyledTextModel
addListener, applyStyle, clamp, clearUndoRedo, export, exportParagraph, fireChangeEvent, fireStyleChangeEvent, getDataFormatHandler, getDocumentEnd, getEndOfParagraphTextPos, getMarker, getParagraphLength, getSupportedAttributes, getSupportedDataFormats, isRedoable, isUndoable, read, redo, redoableProperty, registerDataFormatHandler, removeDataFormatHandler, removeListener, replace, replace, undo, undoableProperty, write
-
Constructor Details
-
BasicTextModel
Constructs an empty model with the specifiedContent
.- Parameters:
c
- the content to use
-
BasicTextModel
public BasicTextModel()Constructs an empty model with the in-memoryContent
.
-
-
Method Details
-
insertText
Inserts text at the specified position. This is a convenience shortcut forStyledTextModel.replace(StyleResolver, TextPos, TextPos, String, boolean)
.- Parameters:
p
- the insertion positiontext
- the text to insert- Throws:
NullPointerException
- if the model isnull
UnsupportedOperationException
- if the model is notwritable
-
size
public int size()Description copied from class:StyledTextModel
Returns the number of paragraphs in the model.- Specified by:
size
in classStyledTextModel
- Returns:
- number of paragraphs
-
getPlainText
Description copied from class:StyledTextModel
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 ofindex
is within the valid document range, since doing otherwise might result in an exception or undetermined behavior.- Specified by:
getPlainText
in classStyledTextModel
- Parameters:
index
- the paragraph index in the range (0...StyledTextModel.size()
)- Returns:
- the non-null paragraph text string
-
getParagraph
Description copied from class:StyledTextModel
Returns aRichParagraph
at the given model index. The callers must ensure that the value ofindex
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.
- Specified by:
getParagraph
in classStyledTextModel
- Parameters:
index
- the paragraph index in the range (0...StyledTextModel.size()
)- Returns:
- the instance of
RichParagraph
-
isWritable
public final boolean isWritable()Determines whether the model is writable.This method calls
BasicTextModel.Content.isWritable()
.- Specified by:
isWritable
in classStyledTextModel
- Returns:
- true if the model is writable
-
insertTextSegment
Description copied from class:StyledTextModel
This method is called to insert a single styled text segment at the given position.- Specified by:
insertTextSegment
in 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:StyledTextModel
Inserts a line break at the specified position.- Specified by:
insertLineBreak
in classStyledTextModel
- Parameters:
index
- the model indexoffset
- the text offset
-
removeRange
Description copied from class:StyledTextModel
Removes the specified text range. This method gets called only if the model is editable. The caller guarantees thatstart
precedesend
.- Specified by:
removeRange
in 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:StyledTextModel
Inserts a paragraph that contains a singleRegion
.The model should not cache or otherwise retain references to the created
Region
s, as they might be requested multiple times during the lifetime of the model, or by different views.This method allows for embedding
Control
s 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:
insertParagraph
in classStyledTextModel
- Parameters:
index
- model indexgenerator
- code that will be used to create a Node instance
-
getStyleAttributeMap
Description copied from class:StyledTextModel
Returns theStyleAttributeMap
of the character at the specified position'scharIndex
. When at the end of the document, returns the attributes of the last character.- Specified by:
getStyleAttributeMap
in classStyledTextModel
- Parameters:
resolver
- the style resolverpos
- the text position- Returns:
- the style attributes, non-null
-
setParagraphStyle
Description copied from class:StyledTextModel
Replaces the paragraph styles in the specified paragraph.- Specified by:
setParagraphStyle
in classStyledTextModel
- Parameters:
index
- the paragraph indexa
- the paragraph attributes
-
applyStyle
Description copied from class:StyledTextModel
Applies style to the specified text range within a single paragraph. The new attributes override any existing attributes. Theend
argument may exceed the paragraph length, in which case the outcome should be the same as supplying the paragraph length value.- Specified by:
applyStyle
in classStyledTextModel
- Parameters:
index
- the paragraph indexstart
- the start offsetend
- the end offseta
- the character attributesmerge
- determines whether to merge with or overwrite the existing attributes
-