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 Paragraph
object
(even if that Paragraph
object itself represents an empty segment).S
- The type of the style of individual segments.public final class Paragraph<PS,SEG,S>
extends java.lang.Object
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 Paragraph
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.
Constructor | Description |
---|---|
Paragraph(PS paragraphStyle,
SegmentOps<SEG,S> segmentOps,
java.util.List<StyledSegment<SEG,S>> styledSegments) |
Creates a paragraph using a list of styled segments
|
Paragraph(PS paragraphStyle,
SegmentOps<SEG,S> segmentOps,
java.util.List<SEG> segments,
StyleSpans<S> styles) |
Creates a paragraph that has multiple segments with multiple styles throughout those segments
|
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
|
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.
|
Modifier and Type | Method | Description |
---|---|---|
char |
charAt(int index) |
|
Paragraph<PS,SEG,S> |
concat(Paragraph<PS,SEG,S> p) |
Concatenates this paragraph with the given paragraph
p . |
Paragraph<PS,SEG,S> |
delete(int start,
int end) |
|
boolean |
equals(java.lang.Object other) |
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).
|
PS |
getParagraphStyle() |
|
java.util.List<SEG> |
getSegments() |
|
S |
getStyleAtPosition(int position) |
Returns the style at the given position.
|
java.util.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.
|
S |
getStyleOfChar(int charIdx) |
Returns the style of character with the given index.
|
javafx.scene.control.IndexRange |
getStyleRangeAtPosition(int position) |
Returns the range of homogeneous style that includes the given position.
|
StyleSpans<S> |
getStyleSpans() |
|
StyleSpans<S> |
getStyleSpans(int from,
int to) |
|
java.lang.String |
getText() |
Returns the plain text content of this paragraph,
not including the line terminator.
|
int |
hashCode() |
|
int |
length() |
|
Paragraph<PS,SEG,S> |
restyle(int from,
int to,
S style) |
|
Paragraph<PS,SEG,S> |
restyle(int from,
StyleSpans<? extends S> styleSpans) |
|
Paragraph<PS,SEG,S> |
restyle(S style) |
Restyles every segment in the paragraph to have the given style.
|
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.
|
Paragraph<PS,SEG,S> |
subSequence(int start) |
|
Paragraph<PS,SEG,S> |
subSequence(int start,
int end) |
|
java.lang.String |
substring(int from) |
|
java.lang.String |
substring(int from,
int to) |
|
java.lang.String |
toString() |
|
Paragraph<PS,SEG,S> |
trim(int length) |
public Paragraph(PS paragraphStyle, SegmentOps<SEG,S> segmentOps, java.util.List<StyledSegment<SEG,S>> styledSegments)
public Paragraph(PS paragraphStyle, SegmentOps<SEG,S> segmentOps, SEG segment, S style)
public Paragraph(PS paragraphStyle, SegmentOps<SEG,S> segmentOps, SEG segment, StyleSpans<S> styles)
public Paragraph(PS paragraphStyle, SegmentOps<SEG,S> segmentOps, java.util.List<SEG> segments, StyleSpans<S> styles)
public java.util.List<StyledSegment<SEG,S>> getStyledSegments()
List<Tuple2<Segment, Style>>
.public java.util.List<SEG> getSegments()
public PS getParagraphStyle()
public int length()
public char charAt(int index)
public java.lang.String substring(int from, int to)
public java.lang.String substring(int from)
public Paragraph<PS,SEG,S> concat(Paragraph<PS,SEG,S> p)
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
.public Paragraph<PS,SEG,S> restyle(S style)
style
- The new style for each segment in the paragraph.public Paragraph<PS,SEG,S> setParagraphStyle(PS paragraphStyle)
paragraphStyle
- The new paragraph stylepublic S getStyleOfChar(int charIdx)
charIdx < 0
, returns the style at the beginning of this paragraph.
If charIdx >= this.length()
, returns the style at the end of this paragraph.public S getStyleAtPosition(int position)
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)
.
public javafx.scene.control.IndexRange getStyleRangeAtPosition(int position)
position
points to a boundary between two styled ranges,
then the range preceding position
is returned.public StyleSpans<S> getStyleSpans()
public StyleSpans<S> getStyleSpans(int from, int to)
public java.lang.String getText()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object