Class BasicTextModel
- Direct Known Subclasses:
CodeTextModel
public class BasicTextModel extends StyledTextModel
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
| Modifier and Type | Class | Description |
|---|---|---|
static interface |
BasicTextModel.Content |
This interface describes the underlying storage mechanism for the BasicTextModel. |
static class |
BasicTextModel.InMemoryContent |
This content provides in-memory storage in an ArrayList of Strings. |
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
| Constructor | Description |
|---|---|
BasicTextModel() |
Constructs an empty model with the in-memory Content. |
BasicTextModel |
Constructs an empty model with the specified Content. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
protected final void |
applyStyle |
Applies style to the specified text range within a single paragraph. |
RichParagraph |
getParagraph |
Returns a RichParagraph at the given model index. |
String |
getPlainText |
Returns the plain text string for the specified paragraph. |
StyleAttributeMap |
getStyleAttributeMap |
Returns the StyleAttributeMap of the character at the specified position's charIndex. |
protected void |
insertLineBreak |
Inserts a line break at the specified position. |
protected void |
insertParagraph |
Inserts a paragraph that contains a single Region. |
void |
insertText |
Inserts text at the specified position. |
protected int |
insertTextSegment |
This method is called to insert a single styled text segment at the given position. |
final boolean |
isWritable() |
Determines whether the model is writable. |
protected void |
removeRange |
Removes the specified text range. |
protected final void |
setParagraphStyle |
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
public BasicTextModel(BasicTextModel.Content c)
Content.- Parameters:
-
c- the content to use
BasicTextModel
public BasicTextModel()
Content.Method Details
insertText
public void insertText(TextPos p, String text)
StyledTextModel.replace(StyleResolver, TextPos, TextPos, String, boolean).- Parameters:
-
p- the insertion position -
text- the text to insert - Throws:
-
NullPointerException- if the model isnull -
UnsupportedOperationException- if the model is notwritable
size
public int size()
StyledTextModel- Specified by:
-
sizein classStyledTextModel - Returns:
- number of paragraphs
getPlainText
public String getPlainText(int index)
StyledTextModelindex is 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
public RichParagraph getParagraph(int index)
StyledTextModelRichParagraph 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.
- Specified by:
-
getParagraphin classStyledTextModel - Parameters:
-
index- the paragraph index in the range (0...StyledTextModel.size()) - Returns:
- the instance of
RichParagraph
isWritable
public final boolean isWritable()
This method calls BasicTextModel.Content.isWritable().
- Specified by:
-
isWritablein classStyledTextModel - Returns:
- true if the model is writable
insertTextSegment
protected int insertTextSegment(int index, int offset, String text, StyleAttributeMap attrs)
StyledTextModel- Specified by:
-
insertTextSegmentin classStyledTextModel - Parameters:
-
index- the paragraph index -
offset- the insertion offset within the paragraph -
text- the text to insert -
attrs- the style attributes - Returns:
- the number of characters inserted
insertLineBreak
protected void insertLineBreak(int index, int offset)
StyledTextModel- Specified by:
-
insertLineBreakin classStyledTextModel - Parameters:
-
index- the model index -
offset- the text offset
removeRange
protected void removeRange(TextPos start, TextPos end)
StyledTextModelstart precedes end.- Specified by:
-
removeRangein classStyledTextModel - Parameters:
-
start- the start of the range to be removed -
end- the end of the range to be removed, expected to be greater than the start position
insertParagraph
protected void insertParagraph(int index, Supplier<Region> generator)
StyledTextModelRegion. 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 index -
generator- code that will be used to create a Node instance
getStyleAttributeMap
public StyleAttributeMap getStyleAttributeMap(StyleResolver resolver, TextPos pos)
StyledTextModelStyleAttributeMap of the character at the specified position's charIndex. When at the end of the document, returns the attributes of the last character.- Specified by:
-
getStyleAttributeMapin classStyledTextModel - Parameters:
-
resolver- the style resolver -
pos- the text position - Returns:
- the style attributes, non-null
setParagraphStyle
protected final void setParagraphStyle(int index, StyleAttributeMap a)
StyledTextModel- Specified by:
-
setParagraphStylein classStyledTextModel - Parameters:
-
index- the paragraph index -
a- the paragraph attributes
applyStyle
protected final void applyStyle(int index, int start, int end, StyleAttributeMap a, boolean merge)
StyledTextModelend argument 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 index -
start- the start offset -
end- the end offset -
a- the character attributes -
merge- determines whether to merge with or overwrite the existing attributes
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.