Package org.fxmisc.richtext.model
Class ReadOnlyStyledDocument<PS,SEG,S>
- java.lang.Object
-
- org.fxmisc.richtext.model.ReadOnlyStyledDocument<PS,SEG,S>
-
- Type Parameters:
PS- The type of the paragraph style.SEG- The type of the segments in the paragraph (e.g.String).S- The type of the style of individual segments.
- All Implemented Interfaces:
StyledDocument<PS,SEG,S>,TwoDimensional
public final class ReadOnlyStyledDocument<PS,SEG,S> extends Object implements StyledDocument<PS,SEG,S>
An immutable implementation ofStyledDocumentthat does not allow editing. For aStyledDocumentthat can be edited, seeEditableStyledDocument. To create one, use its static factory "from"-prefixed methods orReadOnlyStyledDocumentBuilder.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.fxmisc.richtext.model.TwoDimensional
TwoDimensional.Bias, TwoDimensional.Position
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <PS,SEG,S>
Codec<StyledDocument<PS,SEG,S>>codec(Codec<PS> pCodec, Codec<StyledSegment<SEG,S>> segCodec, SegmentOps<SEG,S> segmentOps)Defines a codec for serializing aReadOnlyStyledDocument.ReadOnlyStyledDocument<PS,SEG,S>concat(StyledDocument<PS,SEG,S> other)booleanequals(Object other)static <PS,SEG,S>
ReadOnlyStyledDocument<PS,SEG,S>from(StyledDocument<PS,SEG,S> doc)Creates aReadOnlyStyledDocumentfrom the givenStyledDocument.static <PS,SEG,S>
ReadOnlyStyledDocument<PS,SEG,S>fromSegment(SEG segment, PS paragraphStyle, S style, SegmentOps<SEG,S> segmentOps)Creates aReadOnlyStyledDocumentfrom the given segment.static <PS,SEG,S>
ReadOnlyStyledDocument<PS,SEG,S>fromString(String str, PS paragraphStyle, S style, TextOps<SEG,S> segmentOps)Creates aReadOnlyStyledDocumentfrom the given string.Paragraph<PS,SEG,S>getParagraph(int index)intgetParagraphCount()List<Paragraph<PS,SEG,S>>getParagraphs()StringgetText()inthashCode()intlength()ReadOnlyStyledDocument<PS,SEG,S>mapParagraphs(UnaryOperator<Paragraph<PS,SEG,S>> mapper)Maps all of this document's paragraphs using the given mapper and returns them in a newReadOnlyStyledDocument.TwoDimensional.PositionoffsetToPosition(int offset, TwoDimensional.Bias bias)Creates a two dimensional position in some entity (e.g.TwoDimensional.Positionposition(int major, int minor)Creates a two dimensional position in some entity (e.g.Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,RichTextChange<PS,SEG,S>,MaterializedListModification<Paragraph<PS,SEG,S>>>replace(int paragraphIndex, int fromCol, int toCol, UnaryOperator<ReadOnlyStyledDocument<PS,SEG,S>> f)Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,RichTextChange<PS,SEG,S>,MaterializedListModification<Paragraph<PS,SEG,S>>>replace(int from, int to, UnaryOperator<ReadOnlyStyledDocument<PS,SEG,S>> mapper)Replaces the given portion"from..to"in the document by getting that portion of this document, passing it into the mapping function, and using the result as the replacement.Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,RichTextChange<PS,SEG,S>,MaterializedListModification<Paragraph<PS,SEG,S>>>replace(int from, int to, ReadOnlyStyledDocument<PS,SEG,S> replacement)Replaces the given portion"from..to"with the given replacement and returns the updated version of this document that includes the replacement, theRichTextChangethat represents the change from this document to the returned one, and the modification used to update an area's list of paragraphs.Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,RichTextChange<PS,SEG,S>,MaterializedListModification<Paragraph<PS,SEG,S>>>replace(Replacement<PS,SEG,S> replacement)Convenience method for callingreplace(int, int, ReadOnlyStyledDocument)with aReplacementargument.Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,List<RichTextChange<PS,SEG,S>>,List<MaterializedListModification<Paragraph<PS,SEG,S>>>>replaceMulti(List<Replacement<PS,SEG,S>> replacements)Replaces multiple portions of this document in an efficient manner and returns the updated version of this document that includes all of the replacements, the List ofRichTextChangethat represent all the changes from this document to the returned one, and the List of modifications used to update an area's list of paragraphs for each change.Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,RichTextChange<PS,SEG,S>,MaterializedListModification<Paragraph<PS,SEG,S>>>replaceParagraph(int parIdx, UnaryOperator<Paragraph<PS,SEG,S>> mapper)Maps the paragraph at the given index by callingreplace(int, int, UnaryOperator).Tuple2<ReadOnlyStyledDocument<PS,SEG,S>,ReadOnlyStyledDocument<PS,SEG,S>>split(int position)Splits this document into two at the given position and returns both halves.Tuple2<ReadOnlyStyledDocument<PS,SEG,S>,ReadOnlyStyledDocument<PS,SEG,S>>split(int paragraphIndex, int columnPosition)Splits this document into two at the given paragraph's column position and returns both halves.StyledDocument<PS,SEG,S>subSequence(int start, int end)StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.fxmisc.richtext.model.StyledDocument
charAt, getAbsolutePosition, getParagraphLength, getParagraphStyle, getParagraphStyleAtPosition, getStyleAtPosition, getStyleAtPosition, getStyleOfChar, getStyleOfChar, getStyleRangeAtPosition, getStyleRangeAtPosition, getStyleSpans, getStyleSpans, getStyleSpans, getText, getText, getText, subDocument, subSequence
-
-
-
-
Method Detail
-
fromString
public static <PS,SEG,S> ReadOnlyStyledDocument<PS,SEG,S> fromString(String str, PS paragraphStyle, S style, TextOps<SEG,S> segmentOps)
Creates aReadOnlyStyledDocumentfrom the given string.- Type Parameters:
PS- The type of the paragraph style.SEG- The type of the segments in the paragraph (e.g.String).S- The type of the style of individual segments.- Parameters:
str- the text to use to create the segmentsparagraphStyle- the paragraph style to use for each paragraph in the returned documentstyle- the style to use for each segment in the documentsegmentOps- the operations object that can create a segment froma given text
-
fromSegment
public static <PS,SEG,S> ReadOnlyStyledDocument<PS,SEG,S> fromSegment(SEG segment, PS paragraphStyle, S style, SegmentOps<SEG,S> segmentOps)
Creates aReadOnlyStyledDocumentfrom the given segment.- Type Parameters:
PS- The type of the paragraph style.SEG- The type of the segments in the paragraph (e.g.String).S- The type of the style of individual segments.- Parameters:
segment- the only segment in the only paragraph in the documentparagraphStyle- the paragraph style to use for each paragraph in the returned documentstyle- the style to use for each segment in the documentsegmentOps- the operations object that can create a segment froma given text
-
from
public static <PS,SEG,S> ReadOnlyStyledDocument<PS,SEG,S> from(StyledDocument<PS,SEG,S> doc)
Creates aReadOnlyStyledDocumentfrom the givenStyledDocument.- Type Parameters:
PS- The type of the paragraph style.SEG- The type of the segments in the paragraph (e.g.String).S- The type of the style of individual segments.
-
codec
public static <PS,SEG,S> Codec<StyledDocument<PS,SEG,S>> codec(Codec<PS> pCodec, Codec<StyledSegment<SEG,S>> segCodec, SegmentOps<SEG,S> segmentOps)
Defines a codec for serializing aReadOnlyStyledDocument.- Type Parameters:
PS- The type of the paragraph style.SEG- The type of the segments in the paragraph (e.g.String).S- The type of the style of individual segments.- Parameters:
pCodec- the codec for serializing aParagraphsegCodec- the codec for serializing aStyledSegmentsegmentOps- the operations object for operating on segments
-
length
public int length()
- Specified by:
lengthin interfaceStyledDocument<PS,SEG,S>
-
getParagraphCount
public int getParagraphCount()
-
getParagraph
public Paragraph<PS,SEG,S> getParagraph(int index)
- Specified by:
getParagraphin interfaceStyledDocument<PS,SEG,S>
-
getParagraphs
public List<Paragraph<PS,SEG,S>> getParagraphs()
- Specified by:
getParagraphsin interfaceStyledDocument<PS,SEG,S>
-
position
public TwoDimensional.Position position(int major, int minor)
Description copied from interface:TwoDimensionalCreates a two dimensional position in some entity (e.g. area, list of lists, list of some object with length) where themajorvalue is the index within the outer list) and theminorvalue is either the index within the inner list or some amount of length in a list of objects that have length.- Specified by:
positionin interfaceTwoDimensional
-
offsetToPosition
public TwoDimensional.Position offsetToPosition(int offset, TwoDimensional.Bias bias)
Description copied from interface:TwoDimensionalCreates a two dimensional position in some entity (e.g. area, list of lists, list of some object with length) where theoffsetvalue is an absolute position in that entity.- Specified by:
offsetToPositionin interfaceTwoDimensional
-
split
public Tuple2<ReadOnlyStyledDocument<PS,SEG,S>,ReadOnlyStyledDocument<PS,SEG,S>> split(int position)
Splits this document into two at the given position and returns both halves.
-
split
public Tuple2<ReadOnlyStyledDocument<PS,SEG,S>,ReadOnlyStyledDocument<PS,SEG,S>> split(int paragraphIndex, int columnPosition)
Splits this document into two at the given paragraph's column position and returns both halves.
-
concat
public ReadOnlyStyledDocument<PS,SEG,S> concat(StyledDocument<PS,SEG,S> other)
- Specified by:
concatin interfaceStyledDocument<PS,SEG,S>
-
subSequence
public StyledDocument<PS,SEG,S> subSequence(int start, int end)
- Specified by:
subSequencein interfaceStyledDocument<PS,SEG,S>
-
replaceMulti
public Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,List<RichTextChange<PS,SEG,S>>,List<MaterializedListModification<Paragraph<PS,SEG,S>>>> replaceMulti(List<Replacement<PS,SEG,S>> replacements)
Replaces multiple portions of this document in an efficient manner and returns- the updated version of this document that includes all of the replacements,
-
the List of
RichTextChangethat represent all the changes from this document to the returned one, and - the List of modifications used to update an area's list of paragraphs for each change.
-
replace
public Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,RichTextChange<PS,SEG,S>,MaterializedListModification<Paragraph<PS,SEG,S>>> replace(Replacement<PS,SEG,S> replacement)
Convenience method for callingreplace(int, int, ReadOnlyStyledDocument)with aReplacementargument.
-
replace
public Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,RichTextChange<PS,SEG,S>,MaterializedListModification<Paragraph<PS,SEG,S>>> replace(int from, int to, ReadOnlyStyledDocument<PS,SEG,S> replacement)
Replaces the given portion"from..to"with the given replacement and returns- the updated version of this document that includes the replacement,
-
the
RichTextChangethat represents the change from this document to the returned one, and - the modification used to update an area's list of paragraphs.
-
replace
public Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,RichTextChange<PS,SEG,S>,MaterializedListModification<Paragraph<PS,SEG,S>>> replace(int from, int to, UnaryOperator<ReadOnlyStyledDocument<PS,SEG,S>> mapper)
Replaces the given portion"from..to"in the document by getting that portion of this document, passing it into the mapping function, and using the result as the replacement. Returns- the updated version of this document that includes the replacement,
-
the
RichTextChangethat represents the change from this document to the returned one, and - the modification used to update an area's list of paragraphs.
-
replace
public Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,RichTextChange<PS,SEG,S>,MaterializedListModification<Paragraph<PS,SEG,S>>> replace(int paragraphIndex, int fromCol, int toCol, UnaryOperator<ReadOnlyStyledDocument<PS,SEG,S>> f)
-
replaceParagraph
public Tuple3<ReadOnlyStyledDocument<PS,SEG,S>,RichTextChange<PS,SEG,S>,MaterializedListModification<Paragraph<PS,SEG,S>>> replaceParagraph(int parIdx, UnaryOperator<Paragraph<PS,SEG,S>> mapper)
Maps the paragraph at the given index by callingreplace(int, int, UnaryOperator). Returns- the updated version of this document that includes the replacement,
-
the
RichTextChangethat represents the change from this document to the returned one, and - the modification used to update an area's list of paragraphs.
-
mapParagraphs
public ReadOnlyStyledDocument<PS,SEG,S> mapParagraphs(UnaryOperator<Paragraph<PS,SEG,S>> mapper)
Maps all of this document's paragraphs using the given mapper and returns them in a newReadOnlyStyledDocument.
-
-