use of limelight.ui.text.StyledText in project limelight by slagyr.
the class TextPanelTest method interlacedTextAndStyledText.
@Test
public void interlacedTextAndStyledText() {
createStyles();
parent.setSize(200, 100);
panel.setText("This is <my_other_style>some </my_other_style> fantastic <my_style>text</my_style>", parent);
panel.buildLines();
List<StyledText> chunks = panel.getTextChunks();
assertEquals(4, chunks.size());
StyledText interlacedLayout = chunks.get(2);
assertNoSubString("name=Cuneiform", interlacedLayout.toString());
assertNoSubString("size=19", interlacedLayout.toString());
}
use of limelight.ui.text.StyledText in project limelight by slagyr.
the class TextPanelTest method multipleStylesAppliedToLine.
@Test
public void multipleStylesAppliedToLine() throws Exception {
createStyles();
parent.setSize(200, 100);
panel.setText("<my_style>some </my_style><my_other_style>text</my_other_style>", parent);
panel.buildLines();
List<StyledText> chunks = panel.getTextChunks();
StyledText layout = chunks.get(0);
assertEquals(5, layout.getText().length());
assertSubString("name=Helvetica", layout.toString());
assertSubString("style=bold", layout.toString());
assertSubString("size=20", layout.toString());
StyledText layout2 = chunks.get(1);
assertEquals(5, layout.getText().length());
assertSubString("family=Dialog", layout2.toString());
assertSubString("name=Cuneiform", layout2.toString());
assertSubString("style=italic", layout2.toString());
assertSubString("size=19", layout2.toString());
}
use of limelight.ui.text.StyledText in project limelight by slagyr.
the class TextPanel method buildLines.
public synchronized void buildLines() {
consumableArea = panel.getChildConsumableBounds();
lines = new LinkedList<TextLayout>();
if (text != null && text.length() > 0) {
StyledTextParser parser = new StyledTextParser();
textChunks = parser.parse(text);
final Scene root = getRoot();
if (// TODO MDM - It happens.... but how? Ah! Need to acquire tree lock when removing panels.
root != null) {
Map<String, RichStyle> styleMap = root.getStyles();
for (StyledText styledText : textChunks) styledText.setupStyles(styleMap, getStyle(), this);
// TODO MDM StyleObservers may cause a memory leak. Styles keep track of panels that are no longer used?
addLines();
}
}
}
use of limelight.ui.text.StyledText in project limelight by slagyr.
the class TextPanel method prepareAttributedString.
private AttributedString prepareAttributedString() {
List<StyledText> textChunks = getTextChunks();
StringBuilder buf = new StringBuilder();
for (StyledText textChunk : textChunks) {
buf.append(textChunk.getText());
}
AttributedString attributedString = new AttributedString(buf.toString());
int startIndex = 0;
int endIndex = 0;
for (StyledText textChunk : textChunks) {
if (textChunk == textChunks.get(textChunks.size() - 1))
endIndex = buf.length();
else
endIndex = startIndex + textChunk.getText().length();
attributedString.addAttribute(TextAttribute.FONT, textChunk.getFont(), startIndex, endIndex);
attributedString.addAttribute(TextAttribute.FOREGROUND, textChunk.getColor(), startIndex, endIndex);
startIndex += textChunk.getText().length();
}
return attributedString;
}
use of limelight.ui.text.StyledText in project limelight by slagyr.
the class TextPanelTest method unrecognizedInterlacedStyle.
@Test
public void unrecognizedInterlacedStyle() {
createStyles();
parent.setSize(200, 100);
panel.setText("This is <my_other_style>some </my_other_style><bogus_style>fantastic</bogus_style><my_style>text</my_style>", parent);
panel.buildLines();
List<StyledText> chunks = panel.getTextChunks();
assertEquals(4, chunks.size());
StyledText interlacedLayout = chunks.get(2);
assertNoSubString("name=Cuneiform", interlacedLayout.toString());
assertNoSubString("size=19", interlacedLayout.toString());
}
Aggregations