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();
      }
    }
 /*     */ public void paint(Graphics paramGraphics, Shape paramShape) /*     */ {
   /* 356 */ Rectangle localRectangle = (Rectangle) paramShape;
   /* 357 */ this.tabBase = localRectangle.x;
   /* 358 */ JTextComponent localJTextComponent = (JTextComponent) getContainer();
   /* 359 */ this.sel0 = localJTextComponent.getSelectionStart();
   /* 360 */ this.sel1 = localJTextComponent.getSelectionEnd();
   /* 361 */ this.unselected =
       (localJTextComponent.isEnabled()
           ? localJTextComponent.getForeground()
           : localJTextComponent.getDisabledTextColor());
   /*     */
   /* 363 */ Caret localCaret = localJTextComponent.getCaret();
   /* 364 */ this.selected =
       ((localCaret.isSelectionVisible()) && (localJTextComponent.getHighlighter() != null)
           ? localJTextComponent.getSelectedTextColor()
           : this.unselected);
   /*     */
   /* 366 */ paramGraphics.setFont(localJTextComponent.getFont());
   /*     */
   /* 369 */ super.paint(paramGraphics, paramShape);
   /*     */ }
Example #4
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();
      }
    }
 /**
  * This method indicates if a component would accept an import of the given set of data flavors
  * prior to actually attempting to import it.
  *
  * @param comp The component to receive the transfer. This argument is provided to enable sharing
  *     of TransferHandlers by multiple components.
  * @param flavors The data formats available.
  * @return <code>true</code> iff the data can be inserted.
  */
 public boolean canImport(JComponent comp, DataFlavor[] flavors) {
   JTextComponent c = (JTextComponent) comp;
   if (!(c.isEditable() && c.isEnabled())) return false;
   return (getImportFlavor(flavors, c) != null);
 }