Skip to content

Commit

Permalink
Take multiple StyledTexts in Paragraph constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasMikula committed Aug 12, 2014
1 parent ed8635d commit cad569f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions richtextfx/src/main/java/org/fxmisc/richtext/Paragraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
import org.fxmisc.richtext.TwoDimensional.Position;

public final class Paragraph<S> implements CharSequence {

@SafeVarargs
private static <T> List<T> list(T head, T... tail) {
if(tail.length == 0) {
return Collections.singletonList(head);
} else {
ArrayList<T> list = new ArrayList<>(1 + tail.length);
list.add(head);
for(T t: tail) list.add(t);
return list;
}
}

private final List<StyledText<S>> segments;
private final Optional<LineTerminator> terminator;
private final TwoLevelNavigator navigator;
Expand All @@ -47,8 +60,9 @@ public Paragraph(String text, S style) {
this(new StyledText<S>(text, style));
}

public Paragraph(StyledText<S> text) {
this(text, Optional.empty());
@SafeVarargs
public Paragraph(StyledText<S> text, StyledText<S>... texts) {
this(list(text, texts), Optional.empty());
}

private Paragraph(String text, S style, LineTerminator terminator) {
Expand Down

0 comments on commit cad569f

Please sign in to comment.