Class PeerCaret

java.lang.Object
com.vaadin.swingbridge.surrogates.swing.text.PeerCaret
All Implemented Interfaces:
Caret

public final class PeerCaret extends Object implements Caret
The Caret handed out by JTextComponentMixin.getCaret(), so the standard Swing idiom for repositioning a caret from inside a Document filter works as written:
int dot = field.getCaret().getDot();
field.getCaret().setDot(dot + inserted.length());   // pushes setSelectionRange to the browser

Dot, mark and the change listeners are real — they read and write the target's caret state, reach the browser, and fire on caret moves in both directions. The rest of the interface is presentation the browser owns (blink rate, visibility, painting) or machinery with no Vaadin counterpart (magic caret position): those WARN per R_vaadin_first and answer with the value a focused HTML input would give.

A null target is the deliberate fallback for a component with no text peer under it — a Div-peered emulator, or the RTE behind JEditorPane. Every method then WARNs and reads zero. That is the whole point of this class existing: getCaret() returning null put an NPE one line into every caller, which R_match_swing_errors's warn-and-continue contract forbids.

  • Constructor Details

  • Method Details

    • getDot

      public int getDot()
      Specified by:
      getDot in interface Caret
    • getMark

      public int getMark()
      Specified by:
      getMark in interface Caret
    • setDot

      public void setDot(int dot)
      Collapses the selection and moves the caret to dot.
      Specified by:
      setDot in interface Caret
      Throws:
      IllegalArgumentException - if dot is outside the Document, matching JTextComponent.setCaretPosition(int)
    • moveDot

      public void moveDot(int dot)
      Moves the caret to dot while leaving the mark, extending the selection.
      Specified by:
      moveDot in interface Caret
      Throws:
      IllegalArgumentException - if dot is outside the Document
    • isVisible

      public boolean isVisible()
      Specified by:
      isVisible in interface Caret
      Returns:
      always true — the browser draws a caret in a focused input, and cannot be told not to.
    • setVisible

      public void setVisible(boolean visible)
      Specified by:
      setVisible in interface Caret
    • isSelectionVisible

      public boolean isSelectionVisible()
      Specified by:
      isSelectionVisible in interface Caret
      Returns:
      always true — a selection in an HTML input is always rendered.
    • setSelectionVisible

      public void setSelectionVisible(boolean visible)
      Specified by:
      setSelectionVisible in interface Caret
    • getBlinkRate

      public int getBlinkRate()
      Specified by:
      getBlinkRate in interface Caret
      Returns:
      Swing's own default of 500ms; the real rate is the browser's and is not readable.
    • setBlinkRate

      public void setBlinkRate(int rate)
      Specified by:
      setBlinkRate in interface Caret
    • addChangeListener

      public void addChangeListener(ChangeListener l)
      Fires on every dot/mark move, the user's included — they arrive over the mixin's emul-selection bridge.
      Specified by:
      addChangeListener in interface Caret
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
      Specified by:
      removeChangeListener in interface Caret
    • getMagicCaretPosition

      public Point getMagicCaretPosition()
      Specified by:
      getMagicCaretPosition in interface Caret
    • setMagicCaretPosition

      public void setMagicCaretPosition(Point p)
      Specified by:
      setMagicCaretPosition in interface Caret
    • paint

      public void paint(Graphics g)
      User-authored Graphics paint is out of scope per R_match_swing_errors sub-bucket (b).
      Specified by:
      paint in interface Caret
    • install

      public void install(JTextComponent c)
      Specified by:
      install in interface Caret
    • deinstall

      public void deinstall(JTextComponent c)
      Specified by:
      deinstall in interface Caret