コード例 #1
0
  @Test
  public void textColor() throws Exception {
    createStyles();
    panel.setText("text <my_other_style>here</my_other_style> man", parent);
    panel.buildLines();

    StyledText first = panel.getTextChunks().get(0);
    assertEquals(defaultTextColor, first.getColor());

    StyledText second = panel.getTextChunks().get(1);
    assertEquals(new Color(0x0000FF), second.getColor());

    StyledText third = panel.getTextChunks().get(2);
    assertEquals(defaultTextColor, third.getColor());
  }
コード例 #2
0
ファイル: TextPanel.java プロジェクト: slagyr/limelight
  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;
  }
コード例 #3
0
  @Test
  public void styledInheritsFromDefault() {
    createStyles();
    parent.setSize(200, 100);
    panel.setText("<size_only_style>This some text</size_only_style>", parent);
    panel.buildLines();

    List<TextLayout> lines = panel.getLines();
    assertEquals(1, lines.size());

    String onlyLine = lines.get(0).toString();
    assertSubString("name=" + defaultFontFace, onlyLine);
    assertSubString("size=" + "25", onlyLine);
    assertSubString("style=" + defaultFontStyle, onlyLine);

    StyledText first = panel.getTextChunks().get(0);
    assertEquals(defaultTextColor, first.getColor());
  }