Interface JTextComponentMixin
- All Superinterfaces:
ComponentMixin, ContainerMixin, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, JComponentMixin, Serializable
- All Known Implementing Classes:
SJFormattedTextField, SJPasswordField, SJTextArea, SJTextField
JTextComponent (SD_sjtextfield). Layers the
JTextComponent surface on top of JComponentMixin. Shared across
SJTextField, SJPasswordField, and SJTextArea.
R_vaadin_first stance: Document-as-source-of-truth, R_swing_is_truth sync to peer
Per R_vaadin_first, surrogates reproduce the UI functionality of their Swing originals. TheDocument model is core JTextComponent functionality
— it drives DocumentListener fan-out, holds the editable text, and is
what user code mutates. The mixin keeps it as the source of truth and
R_swing_is_truth-syncs to a Vaadin TextFieldBase peer (TextField / PasswordField
/ TextArea all extend it). Highlighter / Keymap / NavigationFilter /
editor-kit machinery have no Vaadin counterpart and drop-and-WARN.
The caret and selection do have one: dot/mark live in
TextStateStore and reach the browser as a setSelectionRange
on the peer's own input element, so the auto-advance and
reposition-after-reformat idioms work. The reverse direction is
installSelectionBridge(), wired lazily on the first caret listener —
without a listener, dot/mark are a write-only mirror and
getCaretPosition() can lag a caret the user moved.
R_swing_is_truth Document↔peer sync
The two-way bridge mirrors the:emulators.swing.text.JTextComponent
implementation verbatim — same code shape, surrogate-side state holder:
installTextComponentBindings()(called from concrete's ctor) installs the defaultPlainDocumentviacreateDefaultDocument(), attaches the internaldocToPeerDocumentListener, and (when the peer is aTextFieldBase) setsValueChangeMode.EAGER+ wires the peer'saddValueChangeListenerto mirror back.- The internal
docToPeerlistener fires on insert/remove. IfpreventPeerEventsis set, it bails; else it sets the flag, callspeer.setValue(readDocument()), clears infinally. - The peer ValueChangeListener fires on user keystrokes (eager). Same flag check; mutates the Document under the flag.
setDocument(Document)swaps the Document, unhooks the listener from old, attaches to new, fires"document"PCE, then calls the internal mutation hook so the new doc's text reaches the peer.
getUI dropped — Vaadin Optional<UI> signature clash
Same shape SD_sjbutton records for Button.getIcon() and SD_sjpanel records
for JPanel.getUI(): Vaadin Component.getUI() returns
Optional<UI>, JDK JTextComponent.getUI() returns
TextUI. The mixin doesn't declare a JDK-shaped getter.
setUI(javax.swing.plaf.TextUI) survives as overload-safe
(no clash on parameter type).-
Nested Class Summary
Nested classes/interfaces inherited from interface JComponentMixin
JComponentMixin.ActionStandin -
Field Summary
Fields inherited from interface JComponentMixin
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW -
Method Summary
Modifier and TypeMethodDescriptiondefault voidRegisters a listener on theCaretrather than on the component; same fan-out.default voidFires on every caret move, including the ones the user makes — clicking into the text, arrowing, drag-selecting — which arrive over theemul-selectionbridgeinstallSelectionBridge()sets up.default com.vaadin.flow.shared.RegistrationaddSelectionReportListener(SelectionReportListener listener, int debounceMillis) Reports the browser's selection to a caller that keeps its own caret model, without touching this component's dot and mark:default voidcopy()default DocumentFactory hook for the defaultDocument.default voidcut()default Action[]default CaretgetCaret()default Colordefault CaretListener[]default intThe anchored end of the selection — Swing reaches it only throughCaret.getMark(), which is why this accessor has no JDK counterpart on JTextComponent itself.default intdefault Colordefault Documentdefault booleandefault DropModedefault chardefault Highlighterdefault Keymapdefault Insetsdefault NavigationFilterdefault Stringdefault Colordefault Colordefault intdefault intdefault StringgetText()default StringgetText(int offs, int len) default voidWires the browser's caret back to dot/mark, so a caret the *user* moved is readable server-side and fires listeners.default voidInstall the default Document, attach the docToPeer listener, and wire the peer's ValueChangeListener if the peer is aTextFieldBase.default booleanReadspeer.isReadOnly()(negated) when peer is aTextFieldBase.default RectanglemodelToView(int pos) default Rectangle2DmodelToView2D(int pos) default voidmoveCaretPosition(int pos) Moves the caret toposwhile leaving the mark where it is, so the selection grows or shrinks.default voidpaste()default booleanprint()default voiddefault voiddefault voiddefault voidrenderSelection(int start, int end, boolean backward) Shows[start, end]selected in the peer's input, the caret atstartwhenbackward.default voidreplaceSelection(String content) Replaces the selection withcontent(deleting it whencontentis null or empty), then leaves the caret after what was inserted.default voidselect(int start, int end) Selects[start, end), leaving the caret atend.default voiddefault voidWARNs and discards.default voiddefault voidsetCaretPosition(int position) default voiddefault voidsetDocument(Document doc) Swap the Document.default voidsetDragEnabled(boolean enabled) default voiddefault voidsetEditable(boolean b) Propagate topeer.setReadOnly, fire"editable"PCE.default voidsetFocusAccelerator(char c) default voiddefault voiddefault voiddefault voiddefault voiddefault voiddefault voidsetSelectionEnd(int end) default voidsetSelectionStart(int start) default voidReplace the Document's contents.default voiddefault voidupdateUI()Deliberate no-op — L&F dispatch isn't modelled.default intviewToModel(Point p) default intdefault voidMethods inherited from interface ComponentMixin
_installSwingClass, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, dispatchEvent, doLayout, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getComponentListeners, getCursor, getFocusListeners, getFont, getForeground, getGraphics, getHierarchyBoundsListeners, getHierarchyListeners, getKeyListeners, getLocation, getMaximumSize, getMinimumSize, getMouseListeners, getName, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolTipText, getX, getY, grabFocus, hasFocus, invalidate, isDisplayable, isFocusable, isFocusOwner, isShowing, paint, paintAll, print, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, revalidate, setBackground, setBounds, setBounds, setCursor, setFocusable, setFont, setForeground, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validateMethods inherited from interface ContainerMixin
addContainerListener, getContainerListeners, getLayout, paintComponents, printComponents, removeContainerListener, setLayoutMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabledMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface JComponentMixin
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, isDoubleBuffered, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintImmediately, paintImmediately, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, requestDefaultFocus, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction
-
Method Details
-
installTextComponentBindings
default void installTextComponentBindings()Install the default Document, attach the docToPeer listener, and wire the peer's ValueChangeListener if the peer is aTextFieldBase. Idempotent: a second call is a no-op once a Document is installed (same guard shape asAbstractButtonMixin.installButtonBindings). -
createDefaultDocument
-
getDocument
-
setDocument
Swap the Document. Detaches thedocToPeerlistener from the old Document, attaches to the new, fires"document"PCE, then mirrors the new doc's text to the peer so the UI reflects the swap immediately. Null is legal per JDK. -
getText
-
getText
- Throws:
BadLocationException
-
setText
Replace the Document's contents. Null normalises to empty string — JDK's AbstractDocument early-returns on null/empty, we make that explicit. BadLocationException on (0, length) of a live Document is effectively unreachable; swallow-and-warn per D_never_fail_on_gaps. -
isEditable
default boolean isEditable()Readspeer.isReadOnly()(negated) when peer is aTextFieldBase. Non-TextFieldBase peers always reporttrue— accepted lossy direction per R_vaadin_first (no reflection). -
setEditable
default void setEditable(boolean b) Propagate topeer.setReadOnly, fire"editable"PCE. No shadow store per R_vaadin_first Vaadin-first; readback viaisEditable(). Equality short-circuit reads the current peer state to avoid spurious PCE. -
copy
default void copy() -
cut
default void cut() -
paste
default void paste() -
getSelectionStart
default int getSelectionStart() -
getSelectionEnd
default int getSelectionEnd() -
setSelectionStart
default void setSelectionStart(int start) -
setSelectionEnd
default void setSelectionEnd(int end) -
select
default void select(int start, int end) Selects[start, end), leaving the caret atend.Out-of-range arguments clamp rather than throw, and an
endbelowstartcollapses tostart— the JDK's ownJTextComponent.select(int, int)contract, and the reason this method can't just delegate tosetCaretPosition(int), which throws instead. -
selectAll
default void selectAll() -
getSelectedText
- Returns:
- the selected text, or
nullwhen nothing is selected — the JDK's contract, not the empty string.
-
replaceSelection
Replaces the selection withcontent(deleting it whencontentis null or empty), then leaves the caret after what was inserted.Runs through the Document, so DocumentListeners fire and the R_swing_is_truth sync carries the new text to the peer — no separate value push.
-
getCaretPosition
default int getCaretPosition()- Returns:
- the caret offset — the value last written here, clamped to the Document, not a reading of where the browser's caret actually sits. A caret the user moved by clicking or arrowing is not observable server-side, so this lags in exactly that case.
-
setCaretPosition
default void setCaretPosition(int position) - Throws:
IllegalArgumentException- ifpositionis negative or past the end of the Document, perJTextComponent.setCaretPosition(int)(R_match_swing_errors — Swing throws here, so we do)
-
moveCaretPosition
default void moveCaretPosition(int pos) Moves the caret toposwhile leaving the mark where it is, so the selection grows or shrinks.- Throws:
IllegalArgumentException- ifposis outside the Document
-
getCaretMark
default int getCaretMark()The anchored end of the selection — Swing reaches it only throughCaret.getMark(), which is why this accessor has no JDK counterpart on JTextComponent itself. -
getCaret
- Returns:
- the same live view on every call, as Swing does; never
null, sogetCaret().setDot(n)is safe to chain.
-
setCaret
WARNs and discards. A user-supplied Caret exists to *paint* a caret, which is R_match_swing_errors sub-bucket (b) territory, and the browser draws its input's caret regardless of what we store. Honouring the setter would meangetCaret()handing back an object whose dot/mark no longer drive anything. -
addCaretListener
Fires on every caret move, including the ones the user makes — clicking into the text, arrowing, drag-selecting — which arrive over theemul-selectionbridgeinstallSelectionBridge()sets up. -
removeCaretListener
-
getCaretListeners
-
addCaretChangeListener
Registers a listener on theCaretrather than on the component; same fan-out. -
removeCaretChangeListener
-
installSelectionBridge
default void installSelectionBridge()Wires the browser's caret back to dot/mark, so a caret the *user* moved is readable server-side and fires listeners.Installed lazily on the first listener registration rather than in
installTextComponentBindings(): it costs a round trip per caret move, and a component nobody is listening to should not pay it.fireCaretUpdate(int, int)dedupes an unchanged dot/mark, which is what breaks the echo from our ownsetSelectionRangepush. -
addSelectionReportListener
default com.vaadin.flow.shared.Registration addSelectionReportListener(SelectionReportListener listener, int debounceMillis) Reports the browser's selection to a caller that keeps its own caret model, without touching this component's dot and mark:Registration r = field.addSelectionReportListener( (start, end, backward) -> caret.setDot(backward ? end : start), 1000);Two reports reach it. A move — a click, an arrow key, a drag, the caret advancing as the user types — is held for
debounceMillisof browser idleness, and Flow sends a held event ahead of any other DOM event the browser fires, so a click or key listener on the server already sees where the caret was. A pre-edit report goes at once on everybeforeinput, carrying the selection the edit is about to replace; it reaches the server ahead of the value change, so a Document filter reading the caret sees where the user typed.- Parameters:
debounceMillis- 0 to report every move as it happens- Returns:
- removes both listeners; the client-side reporter stays, and costs nothing without them
-
renderSelection
default void renderSelection(int start, int end, boolean backward) Shows[start, end]selected in the peer's input, the caret atstartwhenbackward. Render-only: this component's own dot and mark stay as they are and nothing fires, which is what a caller with its own caret model needs. -
getCaretColor
-
setCaretColor
-
getSelectionColor
-
setSelectionColor
-
getSelectedTextColor
-
setSelectedTextColor
-
getDisabledTextColor
-
setDisabledTextColor
-
getHighlighter
-
setHighlighter
-
getKeymap
-
setKeymap
-
getMargin
-
setMargin
-
getFocusAccelerator
default char getFocusAccelerator() -
setFocusAccelerator
default void setFocusAccelerator(char c) -
getDragEnabled
default boolean getDragEnabled() -
setDragEnabled
default void setDragEnabled(boolean enabled) -
getDropMode
-
setDropMode
-
getActions
-
viewToModel
-
viewToModel2D
-
modelToView
- Throws:
BadLocationException
-
modelToView2D
- Throws:
BadLocationException
-
print
- Throws:
PrinterException
-
read
- Throws:
IOException
-
write
- Throws:
IOException
-
updateUI
default void updateUI()Description copied from interface:JComponentMixinDeliberate no-op — L&F dispatch isn't modelled.- Specified by:
updateUIin interfaceJComponentMixin
-
setUI
-