/**
   * @param codep
   * @return
   */
  protected Caret installCaret(CodePoint codep) {
    // The caret will track the positions across the users' editings.
    final DefaultCaret place = new DefaultCaret();
    place.setUpdatePolicy(DefaultCaret.UPDATE_WHEN_ON_EDT);
    place.install(txtEditor);
    // remove mouse listeners from component, since we don't want the mouse to modify our caret
    txtEditor.removeMouseListener(place);
    txtEditor.removeMouseMotionListener(place);
    txtEditor.removeFocusListener(place);
    // configure visibility and set proper positions
    place.setVisible(false);
    place.setSelectionVisible(false);
    place.setDot(codep.y);
    place.moveDot(codep.x);
    log.info("Installed Caret for " + codep);
    place.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent e) {
            log.fine(e.getSource() + " at " + e.toString());
            // when the caret changes, update the display
            updateName();
          }
        });
    return place;
  }
Пример #2
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);
  }
Пример #3
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);
 }