Top Description Fields Constructors Methods
org.fxmisc.richtext.model

public final Class Paragraph<PS, SEG, S>

extends Object
Class Inheritance
Type Parameters
<PS>
The type of the paragraph style.
<SEG>
The type of the content segments in the paragraph (e.g. String). Every paragraph, even an empty paragraph, must have at least one SEG object (even if that SEG object itself represents an empty segment).
<S>
The type of the style of individual segments.
Static Imports
org.fxmisc.richtext.model.TwoDimensional.Bias.*

One paragraph in the document that can itself be styled and which contains a list of styled segments.

It corresponds to a single line when the text is not wrapped or spans multiple lines when the text is wrapped. A Paragraph contains of a list of SEG objects which make up the individual segments of the Paragraph. By providing a specific segment object and an associated segment operations object, all required data and the necessary operations on this data for a single segment can be provided.

For more complex requirements (for example, when both text and images shall be part of the document), a different segment type must be provided. One should use something like Either<String, Image> for their segment type. Note that Paragraph is an immutable class - to modify a Paragraph, a new Paragraph object must be created. Paragraph itself contains some methods which take care of this, such as concat(), which appends some Paragraph to the current one and returns a new Paragraph.

Field Summary

Modifier and TypeField and Description
private int
private final PS
private final SegmentOps<SEG, S>
private final List<SEG>
private List<StyledSegment<SEG, S>>
private final StyleSpans<S>
private String

Constructor Summary

AccessConstructor and Description
public
Paragraph(PS paragraphStyle, SegmentOps<SEG, S> segmentOps, List<StyledSegment<SEG, S>> styledSegments)

Creates a paragraph using a list of styled segments

private
Paragraph(PS paragraphStyle, SegmentOps<SEG, S> segmentOps, Tuple2<List<SEG>, StyleSpans<S>> decomposedList)

public
Paragraph(PS paragraphStyle, SegmentOps<SEG, S> segmentOps, SEG segment, S style)

Creates a paragraph that has only one segment that has the same given style throughout.

public
Paragraph(PS paragraphStyle, SegmentOps<SEG, S> segmentOps, SEG segment, StyleSpans<S> styles)

Creates a paragraph that has only one segment but a number of different styles throughout that segment

public
Paragraph(PS paragraphStyle, SegmentOps<SEG, S> segmentOps, List<SEG> segments, StyleSpans<S> styles)

Creates a paragraph that has multiple segments with multiple styles throughout those segments

Method Summary

Modifier and TypeMethod and Description
public char
charAt(int index)

public Paragraph<PS, SEG, S>
concat(Paragraph<PS, SEG, S> p)

Concatenates this paragraph with the given paragraph p.

pack-priv Paragraph<PS, SEG, S>
concatR(Paragraph<PS, SEG, S> that)

Similar to concat(Paragraph), except in case both paragraphs are empty, the result's paragraph style will be that of the argument.

private List<StyledSegment<SEG, S>>
private static <SEG, S> Tuple2<List<SEG>, StyleSpans<S>>
decompose(List<StyledSegment<SEG, S>> list, SegmentOps<SEG, S> segmentOps)

public Paragraph<PS, SEG, S>
delete(int start, int end)

public boolean
equals(Object other)

Overrides java.lang.Object.equals.

Two paragraphs are defined to be equal if they have the same style (as defined by PS.equals) and the same list of segments (as defined by SEG.equals).

public PS
public List<SEG>
public S
getStyleAtPosition(int position)

Returns the style at the given position.

public List<StyledSegment<SEG, S>>
getStyledSegments()

Since the segments and styles in a paragraph are stored separate from another, combines these two collections into a single collection where each segment and its corresponding style are grouped into the same object.

public S
getStyleOfChar(int charIdx)

Returns the style of character with the given index.

public IndexRange
getStyleRangeAtPosition(int position)

Returns the range of homogeneous style that includes the given position.

public StyleSpans<S>
public StyleSpans<S>
getStyleSpans(int from, int to)

public String
getText()

Returns the plain text content of this paragraph, not including the line terminator.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public int
private static <T> List<T>
list(T head, T... tail)

public Paragraph<PS, SEG, S>

Returns:

The new paragraph with the restyled segments.
restyle
(S
The new style for each segment in the paragraph.
style
)

Restyles every segment in the paragraph to have the given style.

public Paragraph<PS, SEG, S>
restyle(int from, int to, S style)

public Paragraph<PS, SEG, S>
restyle(int from, StyleSpans<? extends S> styleSpans)

public Paragraph<PS, SEG, S>

Returns:

A new paragraph with the same segment contents, but a new paragraph style.
setParagraphStyle
(PS
The new paragraph style
paragraphStyle
)

Creates a new Paragraph which has the same contents as the current Paragraph, but the given paragraph style.

public Paragraph<PS, SEG, S>
subSequence(int start, int end)

public Paragraph<PS, SEG, S>
subSequence(int start)

public String
substring(int from, int to)

public String
substring(int from)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Paragraph<PS, SEG, S>
trim(int length)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

lengthback to summary
private int length
paragraphStyleback to summary
private final PS paragraphStyle
segmentOpsback to summary
private final SegmentOps<SEG, S> segmentOps
segmentsback to summary
private final List<SEG> segments
styledSegmentsback to summary
private List<StyledSegment<SEG, S>> styledSegments
stylesback to summary
private final StyleSpans<S> styles
textback to summary
private String text

Constructor Detail

Paragraphback to summary
public Paragraph(PS paragraphStyle, SegmentOps<SEG, S> segmentOps, List<StyledSegment<SEG, S>> styledSegments)

Creates a paragraph using a list of styled segments

Paragraphback to summary
private Paragraph(PS paragraphStyle, SegmentOps<SEG, S> segmentOps, Tuple2<List<SEG>, StyleSpans<S>> decomposedList)
Paragraphback to summary
public Paragraph(PS paragraphStyle, SegmentOps<SEG, S> segmentOps, SEG segment, S style)

Creates a paragraph that has only one segment that has the same given style throughout.

Paragraphback to summary
public Paragraph(PS paragraphStyle, SegmentOps<SEG, S> segmentOps, SEG segment, StyleSpans<S> styles)

Creates a paragraph that has only one segment but a number of different styles throughout that segment

Paragraphback to summary
public Paragraph(PS paragraphStyle, SegmentOps<SEG, S> segmentOps, List<SEG> segments, StyleSpans<S> styles)

Creates a paragraph that has multiple segments with multiple styles throughout those segments

Method Detail

charAtback to summary
public char charAt(int index)
concatback to summary
public Paragraph<PS, SEG, S> concat(Paragraph<PS, SEG, S> p)

Concatenates this paragraph with the given paragraph p. The paragraph style of the result will be that of this paragraph, unless this paragraph is empty and p is non-empty, in which case the paragraph style of the result will be that of p.

concatRback to summary
pack-priv Paragraph<PS, SEG, S> concatR(Paragraph<PS, SEG, S> that)

Similar to concat(Paragraph), except in case both paragraphs are empty, the result's paragraph style will be that of the argument.

createStyledSegmentsback to summary
private List<StyledSegment<SEG, S>> createStyledSegments()
decomposeback to summary
private static <SEG, S> Tuple2<List<SEG>, StyleSpans<S>> decompose(List<StyledSegment<SEG, S>> list, SegmentOps<SEG, S> segmentOps)
deleteback to summary
public Paragraph<PS, SEG, S> delete(int start, int end)
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Two paragraphs are defined to be equal if they have the same style (as defined by PS.equals) and the same list of segments (as defined by SEG.equals).

Annotations
@Override
getParagraphStyleback to summary
public PS getParagraphStyle()
getSegmentsback to summary
public List<SEG> getSegments()
getStyleAtPositionback to summary
public S getStyleAtPosition(int position)

Returns the style at the given position. That is the style of the character immediately preceding position. If position is 0, then the style of the first character (index 0) in this paragraph is returned. If this paragraph is empty, then some style previously used in this paragraph is returned. If position > this.length(), then it is equivalent to position == this.length().

In other words, getStyleAtPosition(p) is equivalent to getStyleOfChar(p-1).

getStyledSegmentsback to summary
public List<StyledSegment<SEG, S>> getStyledSegments()

Since the segments and styles in a paragraph are stored separate from another, combines these two collections into a single collection where each segment and its corresponding style are grouped into the same object. Essentially, returns List<Tuple2<Segment, Style>>.

getStyleOfCharback to summary
public S getStyleOfChar(int charIdx)

Returns the style of character with the given index. If charIdx < 0, returns the style at the beginning of this paragraph. If charIdx >= this.length(), returns the style at the end of this paragraph.

getStyleRangeAtPositionback to summary
public IndexRange getStyleRangeAtPosition(int position)

Returns the range of homogeneous style that includes the given position. If position points to a boundary between two styled ranges, then the range preceding position is returned.

getStyleSpansback to summary
public StyleSpans<S> getStyleSpans()
getStyleSpansback to summary
public StyleSpans<S> getStyleSpans(int from, int to)
getTextback to summary
public String getText()

Returns the plain text content of this paragraph, not including the line terminator.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
lengthback to summary
public int length()
listback to summary
private static <T> List<T> list(T head, T... tail)
Annotations
@SafeVarargs
restyleback to summary
public Paragraph<PS, SEG, S> restyle(S style)

Restyles every segment in the paragraph to have the given style.

Note

because Paragraph is immutable, this method returns a new Paragraph. The current Paragraph is unchanged.

Parameters
style:S

The new style for each segment in the paragraph.

Returns:Paragraph<PS, SEG, S>

The new paragraph with the restyled segments.

restyleback to summary
public Paragraph<PS, SEG, S> restyle(int from, int to, S style)
restyleback to summary
public Paragraph<PS, SEG, S> restyle(int from, StyleSpans<? extends S> styleSpans)
setParagraphStyleback to summary
public Paragraph<PS, SEG, S> setParagraphStyle(PS paragraphStyle)

Creates a new Paragraph which has the same contents as the current Paragraph, but the given paragraph style. Note that because Paragraph is immutable, a new Paragraph is returned. Despite the setX name, the current object is unchanged.

Parameters
paragraphStyle:PS

The new paragraph style

Returns:Paragraph<PS, SEG, S>

A new paragraph with the same segment contents, but a new paragraph style.

subSequenceback to summary
public Paragraph<PS, SEG, S> subSequence(int start, int end)
subSequenceback to summary
public Paragraph<PS, SEG, S> subSequence(int start)
substringback to summary
public String substring(int from, int to)
substringback to summary
public String substring(int from)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
trimback to summary
public Paragraph<PS, SEG, S> trim(int length)