Пример #1
0
  @Test
  public void changingTestRequiresUpdates() throws Exception {
    parent.doLayout();
    assertEquals(false, panel.needsLayout());
    assertEquals(false, parent.needsLayout());

    panel.setText("New Text", parent);

    assertEquals(true, panel.needsLayout());
    assertEquals(true, parent.needsLayout());
  }
Пример #2
0
  @Before
  public void setUp() throws Exception {
    assumeTrue(TestUtil.notHeadless());
    parent = new MockProp();
    parent.setLocation(0, 0);
    parent.setSize(100, 100);
    style = parent.getStyle();
    panel = new TextPanel(parent, "Some Text");
    parent.add(panel);
    root = new ScenePanel(new FakePropProxy());
    root.setStage(new MockStage());
    root.add(parent);
    style.setTextColor("green");
    parent.prop.sceneProxy = new FakeSceneProxy();

    defaultFontFace = style.getFontFace();
    defaultFontSize = style.getFontSize();
    defaultFontStyle = style.getFontStyle();
    defaultTextColor = style.getCompiledTextColor().getColor();
  }
Пример #3
0
  @Test
  public void resizesTextWhenSizeChanges() throws Exception {
    panel.setText(
        "Some really long text so that there are multiple lines requiring layout when the size changes.",
        parent);
    panel.doLayout();

    int originalHeight = panel.getHeight();
    parent.setSize(400, 200);
    panel.doLayout();

    int newHeight = panel.getHeight();

    assertEquals(true, 200 - panel.getWidth() < 100);
    assertEquals(true, newHeight < originalHeight);
  }
Пример #4
0
  @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());
  }
Пример #5
0
  @Test
  public void styledAcrossLineBreak() {
    createStyles();
    parent.setSize(200, 100);
    panel.setText("This <my_other_style>some\n more</my_other_style> text", parent);

    panel.buildLines();

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

    TextLayout first = lines.get(0);
    TextLayout second = lines.get(1);
    assertSubString("name=Cuneiform", first.toString());
    assertSubString("name=" + defaultFontFace, first.toString());
    assertSubString("name=Cuneiform", second.toString());
    assertSubString("name=" + defaultFontFace, second.toString());
  }
Пример #6
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());
  }
Пример #7
0
  @Test
  public void styledTextOnSameLine() {
    createStyles();
    parent.setSize(200, 100);
    panel.setText("This <my_other_style>some </my_other_style> text", parent);
    panel.buildLines();

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

    String onlyLine = lines.get(0).toString();
    assertSubString("name=Cuneiform", onlyLine);
    assertSubString("size=19", onlyLine);
    assertSubString("style=italic", onlyLine);
    assertSubString("name=" + defaultFontFace, onlyLine);
    assertSubString("size=" + defaultFontSize, onlyLine);
    assertSubString("style=" + defaultFontStyle, onlyLine);
  }
Пример #8
0
  @Test
  public void stylingAppliedToLine() throws Exception {
    createStyles();

    parent.setSize(200, 100);
    panel.setText("<my_style>some text</my_style>", parent);
    panel.buildLines();

    List<TextLayout> lines = panel.getLines();

    TextLayout layout = lines.get(0);
    assertEquals(1, lines.size());
    assertEquals(9, layout.getCharacterCount());
    assertSubString("family=Helvetica", layout.toString());
    assertSubString("name=Helvetica", layout.toString());
    assertSubString("style=bold", layout.toString());
    assertSubString("size=20", layout.toString());
  }
Пример #9
0
  @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("family=Helvetica", layout.toString());
    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());
  }