Class DefaultCaret
java.lang.Object
java.awt.geom.RectangularShape
java.awt.geom.Rectangle2D
java.awt.Rectangle
vaadinx.swing.text.DefaultCaret
- All Implemented Interfaces:
Shape, Serializable, Cloneable, EventListener, Caret, FocusListener, MouseListener, MouseMotionListener
public class DefaultCaret
extends Rectangle
implements Caret, FocusListener, MouseListener, MouseMotionListener
Emulator for
DefaultCaret — the caret every text
component installs, and the one its caret methods read and write:
DefaultCaret caret = (DefaultCaret) logArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); // follow appends from a worker too
logArea.getCaret().setDot(logArea.getDocument().getLength());
Dot and mark follow the component's Document as the JDK's do: under the default
UPDATE_WHEN_ON_EDT an edit on the UI thread moves them, an edit from a
background thread only clamps them. A NavigationFilter
installed on the component sees every setDot / moveDot, the user's
clicks and arrow keys included, since those arrive from the browser through the same
two methods.
The caret registers no focus or mouse listener on its component, unlike the JDK's:
each would install a peer bridge costing a round trip per focus change or click, and
the browser already places the caret. So focusGained(FocusEvent) and the mouse callbacks
run only when called, isSelectionVisible() stays false, and
paint(Graphics) and the blink timer do nothing.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Rectangle2D
Rectangle2D.Double, Rectangle2D.Float -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMoves the caret on every edit, whichever thread made it.protected ChangeEventprotected EventListenerListstatic final intNever moves the caret on an edit, only clamps it to the Document.static final intMoves the caret on an edit made on the UI thread; clamps it on any other.Fields inherited from class Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidadjustVisibility(Rectangle nloc) Scrolls nothing: the browser keeps its own caret in view.protected voidPaints nothing: the browser draws the caret (R_match_swing_errors sub-bucket (b)).voidWARNs and deinstalls nothing — seeinstall(javax.swing.text.JTextComponent).voidbooleanprotected voidNotifies the change listeners, last registered first, as the JDK does.voidvoidintprotected final JTextComponentintgetDot()<T extends EventListener>
T[]getListeners(Class<T> listenerType) intgetMark()intvoidWARNs and installs nothing.voidInstalls this caret onc: dot and mark reset to 0, and the caret starts followingc's Document and its"document"property.booleanisActive()booleanbooleanvoidvoidvoidvoidvoidvoidvoidprotected voidWARNs and moves nothing; a browser drag-select reachesmoveDot(int)directly.voidmoveDot(int dot) voidmoveDot(int dot, Position.Bias dotBias) Moves the dot, extending the selection from the mark.voidPaints nothing: user-authoredGraphicspaint is out of scope (R_match_swing_errors sub-bucket (b)).protected voidWARNs and moves nothing: mapping a mouse point to an offset needs the view geometry only the browser has.voidprotected final voidrepaint()voidsetBlinkRate(int rate) Stores the rate; nothing blinks, since the browser draws the caret.voidsetDot(int dot) voidsetDot(int dot, Position.Bias dotBias) Collapses the selection ontodot, clamped to the Document.voidvoidsetSelectionVisible(boolean vis) voidsetUpdatePolicy(int policy) voidsetVisible(boolean e) toString()Methods inherited from class Rectangle
add, add, add, contains, contains, contains, contains, createIntersection, createUnion, getBounds, getBounds2D, getHeight, getLocation, getSize, getWidth, getX, getY, grow, inside, intersection, intersects, isEmpty, move, outcode, reshape, resize, setBounds, setBounds, setLocation, setLocation, setRect, setSize, setSize, translate, unionMethods inherited from class Rectangle2D
add, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, setRect, unionMethods inherited from class RectangularShape
clone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonalMethods inherited from interface Shape
contains, contains, contains, contains, getPathIterator, getPathIterator, intersects, intersects
-
Field Details
-
UPDATE_WHEN_ON_EDT
public static final int UPDATE_WHEN_ON_EDTMoves the caret on an edit made on the UI thread; clamps it on any other. The default.- See Also:
-
NEVER_UPDATE
public static final int NEVER_UPDATENever moves the caret on an edit, only clamps it to the Document.- See Also:
-
ALWAYS_UPDATE
public static final int ALWAYS_UPDATEMoves the caret on every edit, whichever thread made it.- See Also:
-
listenerList
-
changeEvent
-
-
Constructor Details
-
DefaultCaret
public DefaultCaret()
-
-
Method Details
-
setUpdatePolicy
public void setUpdatePolicy(int policy) -
getUpdatePolicy
public int getUpdatePolicy() -
getComponent
-
repaint
protected final void repaint() -
damage
Paints nothing: the browser draws the caret (R_match_swing_errors sub-bucket (b)). -
adjustVisibility
Scrolls nothing: the browser keeps its own caret in view. -
positionCaret
WARNs and moves nothing: mapping a mouse point to an offset needs the view geometry only the browser has. A browser click reachessetDot(int)directly. -
moveCaret
WARNs and moves nothing; a browser drag-select reachesmoveDot(int)directly. -
focusGained
- Specified by:
focusGainedin interfaceFocusListener
-
focusLost
- Specified by:
focusLostin interfaceFocusListener
-
mouseClicked
- Specified by:
mouseClickedin interfaceMouseListener
-
mousePressed
- Specified by:
mousePressedin interfaceMouseListener
-
mouseReleased
- Specified by:
mouseReleasedin interfaceMouseListener
-
mouseEntered
- Specified by:
mouseEnteredin interfaceMouseListener
-
mouseExited
- Specified by:
mouseExitedin interfaceMouseListener
-
mouseDragged
- Specified by:
mouseDraggedin interfaceMouseMotionListener
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener
-
paint
-
install
Installs this caret onc: dot and mark reset to 0, and the caret starts followingc's Document and its"document"property.JTextComponent.setCaret(Caret)calls it. -
deinstall
-
install
WARNs and installs nothing. TheCaretinterface asks for the JDK'sJTextComponent, which a migrated app never holds;install(JTextComponent)is the onesetCaretcalls. -
deinstall
WARNs and deinstalls nothing — seeinstall(javax.swing.text.JTextComponent). -
addChangeListener
- Specified by:
addChangeListenerin interfaceCaret
-
removeChangeListener
- Specified by:
removeChangeListenerin interfaceCaret
-
getChangeListeners
-
fireStateChanged
protected void fireStateChanged()Notifies the change listeners, last registered first, as the JDK does. -
getListeners
-
setSelectionVisible
public void setSelectionVisible(boolean vis) - Specified by:
setSelectionVisiblein interfaceCaret
-
isSelectionVisible
public boolean isSelectionVisible()- Specified by:
isSelectionVisiblein interfaceCaret
-
isActive
public boolean isActive() -
isVisible
-
setVisible
public void setVisible(boolean e) - Specified by:
setVisiblein interfaceCaret
-
setBlinkRate
public void setBlinkRate(int rate) Stores the rate; nothing blinks, since the browser draws the caret.- Specified by:
setBlinkRatein interfaceCaret- Throws:
IllegalArgumentException- on a negative rate, as in the JDK
-
getBlinkRate
public int getBlinkRate()- Specified by:
getBlinkRatein interfaceCaret
-
getDot
-
getMark
-
setDot
-
moveDot
-
moveDot
Moves the dot, extending the selection from the mark. UnlikeJTextComponent.moveCaretPosition(int), it does not clamp: an offset past the Document's end is stored, as the JDK's is.- Throws:
IllegalArgumentException- ifdotBiasis null
-
setDot
Collapses the selection ontodot, clamped to the Document.- Throws:
IllegalArgumentException- ifdotBiasis null
-
getDotBias
-
getMarkBias
-
setMagicCaretPosition
- Specified by:
setMagicCaretPositionin interfaceCaret
-
getMagicCaretPosition
- Specified by:
getMagicCaretPositionin interfaceCaret
-
equals
-
toString
-