-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextSegment.java
62 lines (51 loc) · 1.24 KB
/
TextSegment.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//package lightware.richtext;
import java.util.Optional;
import org.fxmisc.richtext.TextExt;
import javafx.scene.Node;
import javafx.scene.text.Text;
public class TextSegment extends AbstractSegment
{
private final String text;
public TextSegment( String text )
{
//super( text );
this.text = text.toString();
}
@Override
public Node createNode( String style )
{
Text textNode = new TextExt( text );
if ( style != null && ! style.isEmpty() ) textNode.getStyleClass().add( style );
return textNode;
}
@Override
public char charAt( int index )
{
return text.charAt( index );
}
@Override
public String getText() { return text; }
@Override
public int length() { return text.length(); }
@Override
public Optional<AbstractSegment> subSequence( int start, int end )
{
if ( start == 0 && end == length() ) return Optional.of( this );
return Optional.of
(
new TextSegment( text.substring( start, end ) )
);
}
@Override
public Optional<AbstractSegment> join( AbstractSegment nextSeg )
{
if ( nextSeg instanceof TextSegment )
{
return Optional.of
(
new TextSegment( text + nextSeg.getText() )
);
}
return Optional.empty();
}
}