Example #1
0
  @Override
  public void focusGained(final FocusEvent e) {
    final JTextComponent component = getComponent();
    if (!component.isEnabled() || !component.isEditable()) {
      super.focusGained(e);
      return;
    }

    mFocused = true;
    if (!shouldSelectAllOnFocus) {
      shouldSelectAllOnFocus = true;
      super.focusGained(e);
      return;
    }

    if (isMultiLineEditor) {
      super.focusGained(e);
      return;
    }

    final int end = component.getDocument().getLength();
    final int dot = getDot();
    final int mark = getMark();
    if (dot == mark) {
      if (dot == 0) {
        component.setCaretPosition(end);
        component.moveCaretPosition(0);
      } else if (dot == end) {
        component.setCaretPosition(0);
        component.moveCaretPosition(end);
      }
    }

    super.focusGained(e);
  }
Example #2
0
    public void actionPerformed(ActionEvent e) {
      JTextComponent textComponent = getTextComponent(e);
      if (!textComponent.isEditable() || !textComponent.isEnabled()) {
        return;
      }

      try {
        outdentText(textComponent);
      } catch (BadLocationException e1) {
        e1.printStackTrace();
      }
    }
Example #3
0
    public void actionPerformed(ActionEvent e) {
      JTextComponent textComponent = getTextComponent(e);
      if (!textComponent.isEditable() || !textComponent.isEnabled()) {
        return;
      }

      try {
        final int position = getCaretPosition();
        final Document document = getDocument();
        int docLen = document.getLength();

        if (docLen == 0) {
          return;
        }

        int fromIndex = Math.max(0, getText(0, position).lastIndexOf('\n'));
        int toIndex = getText(fromIndex + 1, docLen - fromIndex - 1).indexOf('\n');
        toIndex = toIndex < 0 ? docLen : fromIndex + toIndex + 1;
        String text = getText(fromIndex, toIndex - fromIndex);
        if (text.startsWith("\n") || toIndex >= docLen) {
          document.remove(fromIndex, toIndex - fromIndex);
        } else {
          document.remove(fromIndex, toIndex - fromIndex + 1);
        }

        int newPosition = 0;
        if (fromIndex > 0) {
          newPosition = fromIndex + 1;
        }
        docLen = document.getLength();
        if (newPosition > docLen) {
          newPosition = getText().lastIndexOf('\n') + 1;
        }
        setCaretPosition(newPosition);
      } catch (BadLocationException e1) {
        e1.printStackTrace();
      }
    }