Top Description Inners Fields Constructors Methods
jfx.incubator.scene.control.richtext.model

public Class BasicTextModel

extends StyledTextModel
Class Inheritance
Known Direct Subclasses
jfx.incubator.scene.control.richtext.model.CodeTextModel
Imports
java.util.ArrayList, java.util.function.Supplier, javafx.beans.property.BooleanProperty, .SimpleBooleanProperty, javafx.scene.layout.Region, jfx.incubator.scene.control.richtext.StyleResolver, .TextPos

A StyledTextModel based on plain text paragraphs.

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 and Inner Type Summary

Modifier and TypeClass and Description
public static interface
BasicTextModel.Content

This interface describes the underlying storage mechanism for the BasicTextModel.

public static class
BasicTextModel.InMemoryContent

This content provides in-memory storage in an ArrayList of Strings.

Field Summary

Modifier and TypeField and Description
private final BasicTextModel.Content

Constructor Summary

AccessConstructor and Description
public
BasicTextModel(BasicTextModel.Content
the content to use
c
)

Constructs an empty model with the specified Content.

public
BasicTextModel()

Constructs an empty model with the in-memory Content.

Method Summary

Modifier and TypeMethod and Description
protected final void
applyStyle(int
the paragraph index
index
,
int
the start offset
start
,
int
the end offset
end
,
StyleAttributeMap
the character attributes
a
,
boolean
determines whether to merge with or overwrite the existing attributes
merge
)

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

Applies style to the specified text range within a single paragraph.

public RichParagraph
getParagraph(int
the paragraph index in the range (0...size())
index
)

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

Returns a RichParagraph at the given model index.

public String
getPlainText(int
the paragraph index in the range (0...size())
index
)

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

Returns the plain text string for the specified paragraph.

public StyleAttributeMap
getStyleAttributeMap(StyleResolver
the style resolver
resolver
,
TextPos
the text position
pos
)

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

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

protected void
insertLineBreak(int
the model index
index
,
int
the text offset
offset
)

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

Inserts a line break at the specified position.

protected void
insertParagraph(int
model index
index
,
Supplier<Region>
code that will be used to create a Node instance
generator
)

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

Inserts a paragraph that contains a single Region.

public void
insertText(TextPos
the insertion position
p
,
String
the text to insert
text
)

Inserts text at the specified position.

protected int
insertTextSegment(int
the paragraph index
index
,
int
the insertion offset within the paragraph
offset
,
String
the text to insert
text
,
StyleAttributeMap
the style attributes
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

Returns:

true if the model is writable
isWritable
()

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

Determines whether the model is writable.

protected void
removeRange(TextPos
the start of the range to be removed
start
,
TextPos
the end of the range to be removed, expected to be greater than the start position
end
)

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

Removes the specified text range.

protected final void
setParagraphStyle(int
the paragraph index
index
,
StyleAttributeMap
the paragraph attributes
a
)

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.

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

Field Detail

contentback to summary
private final BasicTextModel.Content content

Constructor Detail

BasicTextModelback to summary
public BasicTextModel(BasicTextModel.Content c)

Constructs an empty model with the specified Content.

Parameters
c:BasicTextModel.Content

the content to use

BasicTextModelback to summary
public BasicTextModel()

Constructs an empty model with the in-memory Content.

Method Detail

applyStyleback to summary
protected final void applyStyle(int index, int start, int end, StyleAttributeMap a, 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 new attributes override any existing attributes. The end argument may exceed the paragraph length, in which case the outcome should be the same as supplying the paragraph length value.

Parameters
index:int

the paragraph index

start:int

the start offset

end:int

the end offset

a:StyleAttributeMap

the character attributes

merge:boolean

determines whether to merge with or overwrite the existing attributes

Annotations
@Override
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.

Parameters
index:int

the paragraph index in the range (0...size())

Returns:RichParagraph

the instance of RichParagraph

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.

Parameters
index:int

the paragraph index in the range (0...size())

Returns:String

the non-null paragraph text string

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

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 at the end of the document, returns the attributes of the last character.

Parameters
resolver:StyleResolver

the style resolver

pos:TextPos

the text position

Returns:StyleAttributeMap

the style attributes, non-null

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.

Parameters
index:int

the model index

offset:int

the text offset

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.

Parameters
index:int

model index

generator:Supplier<Region>

code that will be used to create a Node instance

Annotations
@Override
insertTextback to summary
public void insertText(TextPos p, String text)

Inserts text at the specified position. This is a convenience shortcut for replace(StyleResolver, TextPos, TextPos, String, boolean).

Parameters
p:TextPos

the insertion position

text:String

the text to insert

Exceptions
NullPointerException:
if the model is null
UnsupportedOperationException:
if the model is not writable
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.

Parameters
index:int

the paragraph index

offset:int

the insertion offset within the paragraph

text:String

the text to insert

attrs:StyleAttributeMap

the style attributes

Returns:int

the number of characters inserted

Annotations
@Override
isWritableback to summary
public final boolean isWritable()

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

Determines whether the model is writable.

This method calls BasicTextModel.Content#isWritable().

Returns:boolean

true if the model is writable

Annotations
@Override
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.

Parameters
start:TextPos

the start of the range to be removed

end:TextPos

the end of the range to be removed, expected to be greater than the start position

Annotations
@Override
setParagraphStyleback to summary
protected final void setParagraphStyle(int index, StyleAttributeMap a)

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.

Parameters
index:int

the paragraph index

a:StyleAttributeMap

the paragraph attributes

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.

Returns:int

number of paragraphs

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

public Interface BasicTextModel.Content

Known Direct Implementers
jfx.incubator.scene.control.richtext.model.BasicTextModel.InMemoryContent

This interface describes the underlying storage mechanism for the BasicTextModel.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the text string or null
getText
(int
the paragraph index in the range (0...size())
index
)

Returns the text string for the specified paragraph index.

public void
insertLineBreak(int
the model index
index
,
int
the text offset
offset
)

Inserts a line break.

public int

Returns:

the number of characters inserted
insertTextSegment
(int
the paragraph index
index
,
int
the insertion offset within the paragraph
offset
,
String
the text to insert
text
,
StyleAttributeMap
the style attributes
attrs
)

This method is called to insert a single text segment at the given position.

public boolean

Returns:

true if writable
isWritable
()

Determines whether this content is writable (i.e. supports modification).

public void
removeRange(TextPos
the start of the region to be removed
start
,
TextPos
the end of the region to be removed, expected to be greater than the start position
end
)

Removes the specified range.

public int

Returns:

the number paragraphs
size
()

Returns the number of paragraphs in this content.

Method Detail

getTextback to summary
public String getText(int index)

Returns the text string for the specified paragraph index. The returned text string cannot be null and must not contain any control characters other than TAB. The caller should never attempt to ask for a paragraph outside of the valid range.

Parameters
index:int

the paragraph index in the range (0...size())

Returns:String

the text string or null

insertLineBreakback to summary
public void insertLineBreak(int index, int offset)

Inserts a line break. The BasicTextModel guarantees that this method is only called when the content is writable.

Parameters
index:int

the model index

offset:int

the text offset

insertTextSegmentback to summary
public int insertTextSegment(int index, int offset, String text, StyleAttributeMap attrs)

This method is called to insert a single text segment at the given position. The BasicTextModel guarantees that this method is only called when the content is writable.

Parameters
index:int

the paragraph index

offset:int

the insertion offset within the paragraph

text:String

the text to insert

attrs:StyleAttributeMap

the style attributes

Returns:int

the number of characters inserted

isWritableback to summary
public boolean isWritable()

Determines whether this content is writable (i.e. supports modification).

Returns:boolean

true if writable

removeRangeback to summary
public void removeRange(TextPos start, TextPos end)

Removes the specified range. The BasicTextModel guarantees that this method is only called when the content is writable, and that start precedes end.

Parameters
start:TextPos

the start of the region to be removed

end:TextPos

the end of the region to be removed, expected to be greater than the start position

sizeback to summary
public int size()

Returns the number of paragraphs in this content.

Returns:int

the number paragraphs

jfx.incubator.scene.control.richtext.model back to summary

public Class BasicTextModel.InMemoryContent

extends Object
implements Content
Class Inheritance
  • java.lang.Object
  • jfx.incubator.scene.control.richtext.model.BasicTextModel.InMemoryContent
All Implemented Interfaces
jfx.incubator.scene.control.richtext.model.BasicTextModel.Content

This content provides in-memory storage in an ArrayList of Strings.

Field Summary

Modifier and TypeField and Description
private final ArrayList<String>

Constructor Summary

AccessConstructor and Description
public
InMemoryContent()

The constructor.

Method Summary

Modifier and TypeMethod and Description
public String
getText(int
the paragraph index in the range (0...size())
index
)

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.getText.

Returns the text string for the specified paragraph index.

public void
insertLineBreak(int
the model index
index
,
int
the text offset
offset
)

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.insertLineBreak.

Inserts a line break.

private static String
insertText(String text, int offset, String toInsert)

public int
insertTextSegment(int
the paragraph index
index
,
int
the insertion offset within the paragraph
offset
,
String
the text to insert
text
,
StyleAttributeMap
the style attributes
attrs
)

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.insertTextSegment.

This method is called to insert a single text segment at the given position.

public boolean
isWritable()

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.isWritable.

Determines whether this content is writable (i.e. supports modification).

public void
removeRange(TextPos
the start of the region to be removed
start
,
TextPos
the end of the region to be removed, expected to be greater than the start position
end
)

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.removeRange.

Removes the specified range.

private void
setText(int index, String text)

public int
size()

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.size.

Returns the number of paragraphs in this content.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

paragraphsback to summary
private final ArrayList<String> paragraphs

Constructor Detail

InMemoryContentback to summary
public InMemoryContent()

The constructor.

Method Detail

getTextback to summary
public String getText(int index)

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.getText.

Doc from jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.getText.

Returns the text string for the specified paragraph index. The returned text string cannot be null and must not contain any control characters other than TAB. The caller should never attempt to ask for a paragraph outside of the valid range.

Parameters
index:int

the paragraph index in the range (0...size())

Returns:String

the text string or null

Annotations
@Override
insertLineBreakback to summary
public void insertLineBreak(int index, int offset)

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.insertLineBreak.

Doc from jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.insertLineBreak.

Inserts a line break. The BasicTextModel guarantees that this method is only called when the content is writable.

Parameters
index:int

the model index

offset:int

the text offset

Annotations
@Override
insertTextback to summary
private static String insertText(String text, int offset, String toInsert)
insertTextSegmentback to summary
public int insertTextSegment(int index, int offset, String text, StyleAttributeMap attrs)

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.insertTextSegment.

Doc from jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.insertTextSegment.

This method is called to insert a single text segment at the given position. The BasicTextModel guarantees that this method is only called when the content is writable.

Parameters
index:int

the paragraph index

offset:int

the insertion offset within the paragraph

text:String

the text to insert

attrs:StyleAttributeMap

the style attributes

Returns:int

the number of characters inserted

Annotations
@Override
isWritableback to summary
public boolean isWritable()

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.isWritable.

Doc from jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.isWritable.

Determines whether this content is writable (i.e. supports modification).

Returns:boolean

true if writable

Annotations
@Override
removeRangeback to summary
public void removeRange(TextPos start, TextPos end)

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.removeRange.

Doc from jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.removeRange.

Removes the specified range. The BasicTextModel guarantees that this method is only called when the content is writable, and that start precedes end.

Parameters
start:TextPos

the start of the region to be removed

end:TextPos

the end of the region to be removed, expected to be greater than the start position

Annotations
@Override
setTextback to summary
private void setText(int index, String text)
sizeback to summary
public int size()

Implements jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.size.

Doc from jfx.incubator.scene.control.richtext.model.BasicTextModel.Content.size.

Returns the number of paragraphs in this content.

Returns:int

the number paragraphs

Annotations
@Override