Example #1
0
  /**
   * Sets the output text.
   *
   * @param t output text
   * @param s text size
   */
  public final void setText(final byte[] t, final int s) {
    // remove invalid characters and compare old with new string
    int ns = 0;
    final int ts = text.size();
    final byte[] tt = text.text();
    boolean eq = true;
    for (int r = 0; r < s; ++r) {
      final byte b = t[r];
      // support characters, highlighting codes, tabs and newlines
      if (b >= ' ' || b <= TokenBuilder.MARK || b == 0x09 || b == 0x0A) {
        t[ns++] = t[r];
      }
      eq &= ns < ts && ns < s && t[ns] == tt[ns];
    }
    eq &= ns == ts;

    // new text is different...
    if (!eq) {
      text = new BaseXTextTokens(Arrays.copyOf(t, ns));
      rend.setText(text);
      scroll.pos(0);
    }
    if (undo != null) undo.store(t.length != ns ? Arrays.copyOf(t, ns) : t, 0);
    SwingUtilities.invokeLater(calc);
  }
Example #2
0
 /**
  * Assigns the specified list entries and selects the first entry.
  *
  * @param elements result elements
  * @param srch content search string
  */
 void setElements(final TokenSet elements, final String srch) {
   SwingUtilities.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           // set new values and selections
           final int is = elements.size();
           final String[] list = new String[is];
           for (int i = 0; i < is; i++) list[i] = Token.string(elements.key(i + 1));
           if (changed(list)) {
             // check which old values had been selected
             final List<String> values = getSelectedValuesList();
             final IntList il = new IntList();
             for (final String value : values) {
               final byte[] val = Token.token(value);
               for (int i = 0; i < is; i++) {
                 if (Token.eq(val, elements.key(i + 1))) {
                   il.add(i);
                   break;
                 }
               }
             }
             setListData(list);
             setSelectedIndices(il.finish());
           }
           search = srch;
         }
       });
 }
Example #3
0
 /** Jumps to the end of the text. */
 public final void scrollToEnd() {
   SwingUtilities.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           text.pos(text.size());
           text.setCaret();
           showCursor(2);
         }
       });
 }
Example #4
0
 @Override
 public final void componentResized(final ComponentEvent e) {
   scroll.pos(0);
   SwingUtilities.invokeLater(calc);
 }