Exemple #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);
  }
Exemple #2
0
 public void focusGained(FocusEvent e) {
   inModalMode = true;
   if (debug) System.out.println("gained focus");
   setBlinkRate(500);
   // setCaretValue(caretValue);
   super.focusGained(e);
 }
Exemple #3
0
  @Override
  protected void fireStateChanged() {
    // If we have focus the caret should only flash if the range length is zero
    if (mFocused) setVisible(getComponent().isEditable());

    super.fireStateChanged();
  }
Exemple #4
0
 // This fixes the problem where when on the mac you have to ctrl left click to
 // get popup triggers the caret has code that only looks at button number.
 // see radar # 3125390
 @Override
 public void mousePressed(final MouseEvent e) {
   if (!e.isPopupTrigger()) {
     super.mousePressed(e);
     shouldSelectAllOnFocus = false;
   }
 }
Exemple #5
0
 // See <rdar://problem/3833837> 1.4.2_05-141.3: JTextField performance with
 // Aqua L&F. We are getting into a circular condition with the BasicCaret
 // paint code since it doesn't know about the fact that our damage routine
 // above elminates the border. Sadly we can't easily change either one, so
 // we will add a painting flag and not damage during a repaint.
 @Override
 public void paint(final Graphics g) {
   if (isVisible()) {
     fPainting = true;
     super.paint(g);
     fPainting = false;
   }
 }
Exemple #6
0
 @Override
 public void focusLost(final FocusEvent e) {
   mFocused = false;
   shouldSelectAllOnFocus = true;
   if (isMultiLineEditor) {
     setVisible(false);
     getComponent().repaint();
   } else {
     super.focusLost(e);
   }
 }
Exemple #7
0
  private void setCaretValue(int i) {

    caret.setVisible(true);

    caretValue = i;
    int min = 0;
    int max = getText().length();

    if (i < min) i = min;
    if (i > max) i = max;

    if (debug) System.out.println("setSelectionStart: " + i);
    setSelectionStart(i);
    setSelectionEnd(i);
  }
 public LineCursorTextArea() {
   super();
   caret =
       new DefaultCaret() {
         @Override
         protected synchronized void damage(Rectangle r) {
           if (r != null) {
             JTextComponent c = getComponent();
             x = 0;
             y = r.y;
             width = c.getSize().width;
             height = r.height;
             c.repaint();
           }
         }
       };
   caret.setBlinkRate(getCaret().getBlinkRate());
   setCaret(caret);
 }
Exemple #9
0
 /** Only show the flashing caret if the selection range is zero */
 @Override
 public void setVisible(boolean e) {
   if (e) e = getDot() == getMark();
   super.setVisible(e);
 }
Exemple #10
0
 @Override
 public void deinstall(final JTextComponent c) {
   c.removePropertyChangeListener(this);
   super.deinstall(c);
 }
Exemple #11
0
 @Override
 public void install(final JTextComponent c) {
   super.install(c);
   isMultiLineEditor = c instanceof JTextArea || c instanceof JEditorPane;
   c.addPropertyChangeListener(this);
 }