Search in sources :

Example 1 with StyledText

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());
}
Also used : StyledText(limelight.ui.text.StyledText) Test(org.junit.Test)

Example 2 with StyledText

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());
}
Also used : StyledText(limelight.ui.text.StyledText) Test(org.junit.Test)

Example 3 with StyledText

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();
        }
    }
}
Also used : StyledText(limelight.ui.text.StyledText) RichStyle(limelight.styles.RichStyle) StyledTextParser(limelight.ui.text.StyledTextParser) AttributedString(java.text.AttributedString) TextLayout(java.awt.font.TextLayout)

Example 4 with StyledText

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;
}
Also used : StyledText(limelight.ui.text.StyledText) AttributedString(java.text.AttributedString)

Example 5 with StyledText

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());
}
Also used : StyledText(limelight.ui.text.StyledText) Test(org.junit.Test)

Aggregations

StyledText (limelight.ui.text.StyledText)7 Test (org.junit.Test)5 TextLayout (java.awt.font.TextLayout)2 AttributedString (java.text.AttributedString)2 RichStyle (limelight.styles.RichStyle)1 StyledTextParser (limelight.ui.text.StyledTextParser)1