Example #1
0
  @Override
  public final void mousePressed(final MouseEvent e) {
    if (!isEnabled() || !isFocusable()) return;

    requestFocusInWindow();
    caret(true);

    if (SwingUtilities.isMiddleMouseButton(e)) copy();

    final boolean shift = e.isShiftDown();
    final boolean selected = editor.selected();
    if (SwingUtilities.isLeftMouseButton(e)) {
      final int c = e.getClickCount();
      if (c == 1) {
        // selection mode
        if (shift) editor.startSelection(true);
        select(e.getPoint(), !shift);
      } else if (c == 2) {
        editor.selectWord();
      } else {
        editor.selectLine();
      }
    } else if (!selected) {
      select(e.getPoint(), true);
    }
  }
Example #2
0
  @Override
  public final void mousePressed(final MouseEvent e) {
    if (!isEnabled() || !isFocusable()) return;

    requestFocusInWindow();
    cursor(true);

    if (SwingUtilities.isMiddleMouseButton(e)) copy();

    final boolean marking = e.isShiftDown();
    final boolean nomark = !text.marked();
    if (SwingUtilities.isLeftMouseButton(e)) {
      final int c = e.getClickCount();
      if (c == 1) {
        // selection mode
        if (marking && nomark) text.startMark();
        rend.select(scroll.pos(), e.getPoint(), marking);
      } else if (c == 2) {
        text.selectWord();
      } else {
        text.selectLine();
      }
    } else if (nomark) {
      rend.select(scroll.pos(), e.getPoint(), false);
    }
  }
Example #3
0
 @Override
 public void mouseClicked(final MouseEvent e) {
   if (!SwingUtilities.isMiddleMouseButton(e)) return;
   if (!paste()) return;
   finish();
   repaint();
 }
Example #4
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 #5
0
  @Override
  public final void mouseDragged(final MouseEvent e) {
    if (!SwingUtilities.isLeftMouseButton(e)) return;

    // selection mode
    select(e.getPoint(), false);
    final int y = Math.max(20, Math.min(e.getY(), getHeight() - 20));
    if (y != e.getY()) scroll.pos(scroll.pos() + e.getY() - y);
  }
Example #6
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 #7
0
  @Override
  public void mouseReleased(final MouseEvent e) {
    if (linkListener == null) return;

    if (SwingUtilities.isLeftMouseButton(e)) {
      editor.endSelection();
      // evaluate link
      if (!editor.selected()) {
        final TextIterator iter = rend.jump(e.getPoint());
        final String link = iter.link();
        if (link != null) linkListener.linkClicked(link);
      }
    }
  }
Example #8
0
 @Override
 public void mouseClicked(final MouseEvent e) {
   if (!SwingUtilities.isMiddleMouseButton(e)) return;
   new PasteCmd().execute(gui);
 }
Example #9
0
 @Override
 public final void componentResized(final ComponentEvent e) {
   scroll.pos(0);
   SwingUtilities.invokeLater(calc);
 }
Example #10
0
 @Override
 public void mouseReleased(final MouseEvent e) {
   if (SwingUtilities.isLeftMouseButton(e)) rend.stopSelect();
 }