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

    panel.setText("Something", parent);
    assertEquals(true, panel.needsLayout());

    panel.resetLayout();
    panel.setText("Something", parent);
    assertEquals(false, panel.needsLayout());

    panel.setText("Something Else", parent);
    assertEquals(true, panel.needsLayout());

    panel.resetLayout();
    assertEquals(false, panel.needsLayout());
  }
Пример #2
0
  @Test
  public void observerAddedForLineStyling() throws Exception {
    panel.setText("some text", parent);
    panel.buildLines();

    Style style = panel.getTextChunks().get(0).getStyle();
    assertEquals(true, style.hasObserver(panel));
  }
Пример #3
0
 @Test
 public void dimensionsWhenLastLineIsLongest() throws Exception {
   useFrame();
   panel.setText("1\n2\n3\nlongest", parent);
   panel.doLayout();
   assertEquals(true, panel.getWidth() >= 39 && panel.getWidth() <= 41);
   assertEquals(55, panel.getHeight());
 }
Пример #4
0
 @Test
 public void preferredSizeWithMoreText() throws Exception {
   useFrame();
   panel.setText(
       "Once upon a time, there was a developer working on a tool called Limelight.", parent);
   panel.doLayout();
   assertEquals(true, panel.getWidth() >= 97 && panel.getWidth() <= 99);
   assertEquals(69, panel.getHeight());
 }
Пример #5
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());
  }
Пример #6
0
  @Test
  public void textChunksOverwrittenOnCompile() throws Exception {
    panel.setText("Here is some original text.", parent);
    panel.buildLines();

    int originalChunks = panel.getTextChunks().size();

    panel.buildLines();

    assertEquals(originalChunks, panel.getTextChunks().size());
  }
Пример #7
0
  @Test
  public void layoutFlushedChangedText() throws Exception {
    panel.resetLayout();
    assertEquals(false, panel.needsLayout());

    panel.setText("Something", parent);
    assertEquals(true, panel.needsLayout());

    panel.doLayout();
    assertEquals(false, panel.needsLayout());
  }
Пример #8
0
 /**
  * Sets the output text.
  *
  * @param out cached output
  */
 public void setText(final ArrayOutput out) {
   final byte[] buf = out.buffer();
   final int size = (int) out.size();
   final byte[] chop = token(DOTS);
   if (out.finished() && size >= chop.length) {
     System.arraycopy(chop, 0, buf, size - chop.length, chop.length);
   }
   text.setText(buf, size);
   header.setText((out.finished() ? CHOPPED : "") + RESULT);
   home.setEnabled(gui.context.data() != null);
 }
Пример #9
0
  @Test
  public void teardownStyledTextBeforeDiscarding() throws Exception {
    panel.setText("Original Text", parent);
    panel.doLayout();
    List<StyleObserver> observers = panel.getStyle().getObservers();
    assertEquals(1, observers.size());
    StyleObserver observer = observers.get(0);

    panel.doLayout();
    List<StyleObserver> newObservers = panel.getStyle().getObservers();
    assertEquals(1, newObservers.size());
    StyleObserver newObserver = newObservers.get(0);
    assertNotSame(newObserver, observer);
  }
Пример #10
0
  @Test
  public void buildingLines() throws Exception {
    panel.setText("some text", parent);
    panel.buildLines();

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

    assertEquals(1, lines.size());
    TextLayout layout = lines.get(0);
    assertEquals(9, layout.getCharacterCount());
    assertSubString("family=" + defaultFontFace, layout.toString());
    assertSubString("name=" + defaultFontFace, layout.toString());
    assertSubString("size=" + defaultFontSize, layout.toString());
  }
Пример #11
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());
  }
Пример #12
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);
  }
Пример #13
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());
  }
Пример #14
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());
  }
Пример #15
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);
  }
Пример #16
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());
  }
Пример #17
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());
  }
Пример #18
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());
  }
Пример #19
0
  private void update() {
    if (update.isDisposed()) return;

    update.cancelAllRequests();
    update.addRequest(
        () -> {
          if (isDisposed()) return;

          VirtualFile file = getSelectedFile();
          actionEnabled = false;
          String charsetName = null;
          Pair<Charset, String> check = null;

          if (file != null) {
            check = EncodingUtil.checkSomeActionEnabled(file);
            Charset charset = null;

            if (LoadTextUtil.wasCharsetDetectedFromBytes(file) != null) {
              charset = cachedCharsetFromContent(file);
            }

            if (charset == null) {
              charset = file.getCharset();
            }

            actionEnabled = check == null || check.second == null;

            if (!actionEnabled) {
              charset = check.first;
            }

            if (charset != null) {
              charsetName = charset.displayName();
            }
          }

          if (charsetName == null) {
            charsetName = "n/a";
          }

          String toolTipText;

          if (actionEnabled) {
            toolTipText = String.format("File Encoding%n%s", charsetName);

            myComponent.setForeground(UIUtil.getActiveTextColor());
            myComponent.setTextAlignment(Component.LEFT_ALIGNMENT);
          } else {
            String failReason = check == null ? "" : check.second;
            toolTipText = String.format("File encoding is disabled%n%s", failReason);

            myComponent.setForeground(UIUtil.getInactiveTextColor());
            myComponent.setTextAlignment(Component.CENTER_ALIGNMENT);
          }

          myComponent.setToolTipText(toolTipText);
          myComponent.setText(charsetName);

          if (myStatusBar != null) {
            myStatusBar.updateWidget(ID());
          }
        },
        200,
        ModalityState.any());
  }