FieldNode
abstract class FieldNode<V>
Extends: Node
Known subtypes: LineFieldNode, MultilineTextFieldNode
Package: dev.joid.lib.ui.node.impl.control.field · Module: core · Source: FieldNode.java
The base of every text field: it edits a text, reads a value of type V from it, and handles the focus, the cursor, the selection and the clipboard.
Description
Section titled “Description”A field turns its text into a value with parse and a value into its text with format; TextFieldNode, IntegerFieldNode and MultilineTextFieldNode are ready to use, and a field of your own type extends LineFieldNode.
The field draws its text itself; its only part is an optional background.
A held Backspace, Delete or arrow key repeats after 500 ms, then every 100 ms.
Attaching a field without a TextInfo throws an IllegalStateException.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| FieldNode(double x, double y, double width, double height) protected | Creates the field at x, y with a width and a height in design pixels, from the constructor of a subclass. |
Properties
Section titled “Properties”Colors
Section titled “Colors”| Property | Type | Default | Summary |
|---|---|---|---|
| background | Node | null: no background | The node drawn behind the text, over the whole field, with a zindex of -1; optional. |
| cursorColor signal | Color | null: the color of info | The color of the blinking cursor; null uses the color of info. |
| selectionColor signal | Color | new Color(50, 152, 253, 100) | The color of the rectangle drawn over the selected text. |
| placeholderColor signal | Color | null: the color of info at half its opacity | The color of the placeholder; null uses the color of info at half its opacity. |
Hover and tooltips
Section titled “Hover and tooltips”| Property | Type | Default | Summary |
|---|---|---|---|
| cursorMargin signal | double | 0D | The distance, in design pixels, that the field keeps between the cursor and the edge of the visible text when it scrolls to follow the cursor. |
| cursorPosition | int | 0 | The index of the cursor in the text, kept within the text; a plain index is the start value. |
Other properties
Section titled “Other properties”| Property | Type | Default | Summary |
|---|---|---|---|
| text | String | "" | The text in the field. |
| placeholder signal | String | "" | The text shown while the field is empty and has no focus. |
| info signal | TextInfo | none, info(...) is required before the attach | The font, the size and the color of the text, as a TextInfo; required. |
| accept | Predicate<String> | text -> true | A test that every edit of the user must pass: an edit typed, pasted, cut or deleted whose text fails it is refused, and the text stays as it was. |
| normalize | UnaryOperator<String> | UnaryOperator.identity() | A function applied to the text before the field reads a value from it, such as String::trim. |
| allowEmpty signal | boolean | false | If true, an empty field is valid and its value is null. |
| maxTextLength signal | int | no limit | The largest number of characters of the text; -1 means no limit. |
| markup signal | boolean | false | If true, the text is read with the markups of info, so that the tags in the text style it; if false, the field shows the tags as typed. |
| margin signal | double | Sets the four margins at once. | |
| marginTop signal | double | 0D | The space, in design pixels, between the top edge and the text; a one-line field uses it with alignY(START) and to size a field of height 0. |
| marginBottom signal | double | 0D | The space, in design pixels, between the bottom edge and the text; a one-line field uses it with alignY(END) and to size a field of height 0. |
| marginLeft signal | double | 0D | The space, in design pixels, between the left edge and the text; the text is clipped there. |
| marginRight signal | double | 0D | The space, in design pixels, between the right edge and the text; the text is clipped there. |
| marginHorizontal signal | double | Sets the left and the right margins at once. | |
| marginVertical signal | double | Sets the top and the bottom margins at once. |
Inherited from Node (24)
x · y · width · height · position · anchor · anchorX · anchorY · aspectRatio · zindex · zlevel · skeleton · visible · enabled · interactive · cursor · hoverDuration · hoverEquation · hover · overflow · scrollSpeed · scrollbar · label · draggable
Redefined defaults:
| Property | Default here | Inherited default |
|---|---|---|
| cursor | Cursor.TEXT | null in Node |
Methods
Section titled “Methods”Hover and tooltips
Section titled “Hover and tooltips”| Returns | Signature | Summary |
|---|---|---|
T | cursorPosition(Signal | Binds the index of the cursor to a signal both ways. |
this | moveCursor(int position) fluent | Moves the cursor as if the user did: beforeCursorMove can refuse it, then onCursorMove fires. |
T | beforeCursorMove(EventListener<NodeChangeEvent.Pre<T,Integer>> listener) | Adds a listener that runs before the cursor moves on a key, a press or moveCursor(...); cancel() keeps it in place. |
| Returns | Signature | Summary |
|---|---|---|
T | focused(boolean focused) | Gives the field its start focus: true gives it the keyboard. |
T | focused(Signal | Binds the focus to a signal both ways: the field gains or loses the focus with the signal, and writes into it when the user focuses or blurs the field. |
this | focus() fluent | Gives the field the focus: beforeFocus can refuse it, then onFocus fires; unlike a press, it does not blur the other fields. |
T | beforeFocus(EventListener<NodeChangeEvent.Pre<T,Boolean>> listener) | Adds a listener that runs before the field gains the focus on a press or focus(); cancel() refuses the focus. |
boolean | isFocused() | If true, the field has the focus. |
Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
V | getValue() | Returns the value read from the text, normalized and brought into its bounds. |
boolean | isValid() | If true, the text passes accept, reads as a value and that value is already within its bounds; an empty text with allowEmpty(true) is valid. |
FieldSelection | getSelection() | Returns the selected range of the text; an empty range when nothing is selected. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
T | selection(int start, int end) | Gives the field its start selection, from start to end in any order, kept within the text. |
T | selection(Signal | Binds the selection to a signal of FieldSelection both ways. |
this | change(String text) fluent | Replaces the text as if the user typed it: beforeChange can refuse it, then onChange fires. |
T | beforeChange(EventListener<NodeFieldChangeEvent.Pre<T,V>> listener) | Adds a listener that runs before an edit of the user or change(...), with the text now, the text asked for and the value read from it; cancel() refuses the edit. |
this | blur() fluent | Blurs the field as a press elsewhere would: beforeBlur can refuse it, then onBlur fires. |
T | beforeBlur(EventListener<NodeChangeEvent.Pre<T,Boolean>> listener) | Adds a listener that runs before the field loses the focus on a press elsewhere, Escape, Enter or blur(); cancel() keeps the focus. |
this | select(int start, int end) fluent | Selects a range as if the user did: beforeSelect can refuse it, then onSelect fires. |
T | beforeSelect(EventListener<NodeChangeEvent.Pre<T,FieldSelection>> listener) | Adds a listener that runs before the selection changes on a key, a press or select(...); cancel() keeps the selection. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
void | layout() hook | Places the background over the whole field. |
void | draw(double mouseX, double mouseY) hook | Draws the field with drawField(), then repeats a held editing key. |
void | mousePressed(NodeMouseEvent<?> event) hook | On a press over the field that no one consumed, blurs the other fields, focuses this one, places the cursor and starts a selection, and consumes the press; a double press selects a word, a triple press a line. |
void | mouseReleased(NodeMouseEvent<?> event) hook | Ends the selection that a press started. |
void | mouseDragged(NodeMouseEvent<?> event) hook | Extends the selection to the character under the pointer. |
void | mouseScroll(NodeMouseScrollEvent<?> event) hook | Over the focused field, steps the value up or down with increment when its type has steps, and consumes the wheel. |
void | charTyped(NodeCharEvent<?> event) hook | While the field has the focus, inserts the character at the cursor, in place of the selection, and consumes it. |
void | keyPressed(NodeKeyEvent<?> event) hook | While the field has the focus, handles the editing, the cursor and the clipboard keys and consumes every key; Escape blurs the field. |
void | detach() hook | Blurs the field when it leaves the tree. |
boolean | holdsInput() hook protected | If true, the field has the focus or a selection by drag goes on: it keeps its keys and its drags while it is scrolled out of the area of its container. |
BoundingBox | getCursorArea() hook abstract | Returns the area of the text cursor, in design pixels of the UI, where drawField draws it while the field has the focus. |
void | drawField() hook abstract protected | Hook that draws the text, the cursor and the selection, on every frame. |
boolean | isMultiline() hook abstract protected | Hook that returns true when the text may hold line breaks; a one-line field drops them from a paste. |
boolean | handleKey(Key key) hook abstract protected | Hook that JOID calls first with each key pressed while the field has the focus. |
int | getPositionAt(double mouseX, double mouseY) hook abstract protected | Hook that returns the index in the text under a point of the UI, in design pixels. |
void | followCursorForward() hook abstract protected | Hook that scrolls the visible text after the cursor moved forward, so that the cursor stays in view with cursorMargin. |
void | followCursorBackward() hook abstract protected | Hook that scrolls the visible text after the cursor moved backward, so that the cursor stays in view with cursorMargin. |
V | parse(String text) hook abstract protected | Hook that turns a text into a value; return null when the text is not a value. |
String | format(V value) hook abstract protected | Hook that turns a value into the text that the field shows. |
V | correct(V value) hook protected | Hook that brings a value into its bounds, such as a minimum and a maximum; the default returns the value. |
boolean | accepts(String text) hook protected | Hook that refuses an edit whose text can never become a value, such as a letter in a number field; the default accepts every text. |
V | increment(V value, int count) hook protected | Hook that returns the value count steps away, for Up, Down and the wheel; count is negative to go down. |
void | fallback(V fallback) protected | Gives the value that the field holds while no text was valid yet, such as 0 for a number. |
this | startValue(V value) fluent protected | Gives the field a start value of its type, shown through format: the body of a public value(...) setter. |
this | bindValue(Signal | Binds the value to a signal of its type both ways: the field shows the signal through format, and writes the value of each valid edit into it. |
void | write(V value, boolean refusable) protected | Shows a value, brought into its bounds and formatted. |
void | revalidate() protected | Shows again the value asked for last, after a bound of the field changed, such as its min or its max. |
boolean | blurNow() protected | Blurs the field at once. |
boolean | insert(String text) protected | Inserts a text at the cursor, in place of the selection, as typing would: cleaned of control characters, cut to maxTextLength, and tested by accept and accepts. |
void | placeCursor(int position, boolean forward) protected | Moves the cursor to an index and scrolls to keep it in view; with Shift held, extends the selection. |
void | increaseCursor(int value) protected | Moves the cursor forward by a number of characters and scrolls to keep it in view. |
void | decreaseCursor(int value) protected | Moves the cursor backward by a number of characters and scrolls to keep it in view. |
TextInfo | getShownInfo() protected | Returns the TextInfo that draws the text: info with its markups, or without them when markup is false. |
TextInfo | getPlaceholderInfo() protected | Returns the TextInfo that draws the placeholder, in the color of placeholderColor. |
Color | getShownCursorColor() protected | Returns the color of the cursor on this frame, with the opacity of its blink. |
double | getLineX(String text, int[] tags, int start, int end, String prefix, int position) protected | Returns the horizontal offset, in design pixels, of a position within a line of the text from start to end, with the markup tags given by tags and a prefix of opened tags. |
int | getLinePosition(String text, int[] tags, int start, int end, String prefix, double x) protected | Returns the index of the line from start to end that is nearest to a horizontal offset, the inverse of getLineX. |
Inherited from Node (128)
load · render · renderHover · updateScroll · updateScrollX · updateScrollY · append · attach · body · clearChildren · getChild · getChildren · getNodeListAt · getParent · isAttached · getAbsoluteX · getAbsoluteY · getAbsoluteDefaultX · getAbsoluteDefaultY · toDrawX · toDrawY · w · h · dw · dh · mw · mh · aw · ah · ax · ay · getDefaultWidth · getDefaultHeight · removeHover · clearHover · refreshHover · getResolvedCursor · hoverValue · getHoverAnimator · isHovered · handleMousePressed · handleMouseReleased · handleMouseDragged · handleMouseScroll · handleCharTyped · handleKeyPressed · handleKeyReleased · getLastClickTime · getLastClickButton · getLastKey · getLastKeyTime · scrollX · scrollY · scrollTo · beforeScroll · hasOverflowX · hasOverflowY · getOverflowArea · getScrollX · getScrollY · getTargetScrollX · getTargetScrollY · getMaxScrollX · getMaxScrollY · isScrollEndX · isScrollEndY · startDragging · stopDragging · beforeDragStart · beforeDragDrop · isDragging · getDragX · getDragY · isDragged · getDragSource · getDraggedNode · getStartDragX · getStartDragY · getTargetDragX · getTargetDragY · effect · removeEffect · clearEffects · hasEffect · getEffect · layer · clearLayers · animate · removeAnimator · wait · watch · hasListener · isVisibleProperty · isMounted · getIndex · getUi · getHierarchy · getMappedIndex · getTaskList · getShortcutList · toJson · toString · getEventBus · getBodyConsumer · getDefaultX · getDefaultY · getLayoutX · getLayoutY · getShiftX · getShiftY · isStepping · getLastCodepoint · getLoadCount · getRenderTime · remove · self · copy · useStore · addTask · removeTask · addShortcut · removeShortcut · layoutPosition · layoutSize · fit · move · beforeMove · hoverColor
Events
Section titled “Events”| Event | Listener | Summary |
|---|---|---|
| onChange | EventListener<NodeFieldChangeEvent.Post<T,V>> | Adds a listener that runs after each real change of the text, whatever its source. |
| onFocus | EventListener<NodeChangeEvent.Post<T,Boolean>> | Adds a listener that runs each time the field gains the focus, whatever its source. |
| onBlur | EventListener<NodeChangeEvent.Post<T,Boolean>> | Adds a listener that runs each time the field loses the focus, after it rewrote its text from its value. |
| onCursorMove | EventListener<NodeChangeEvent.Post<T,Integer>> | Adds a listener that runs after each move of the cursor, whatever its source. |
| onSelect | EventListener<NodeChangeEvent.Post<T,FieldSelection>> | Adds a listener that runs after each change of the selection, whatever its source. |
Inherited from Node (21)
onUpdate · onDetach · onInit · onRender · onDraw · onMount · onHoverStart · onHover · onHoverEnd · onScroll · onScrollToEnd · onScrollEndReached · onDragStart · onDrag · onDragDrop · onDragSnap · onMove · onChildAppend · onClick · onAnimate · onWatch
Creation details
Section titled “Creation details”FieldNode
Section titled “FieldNode”FieldNode(double x, double y, double width, double height) protected
Creates the field at x, y with a width and a height in design pixels, from the constructor of a subclass.
Property details
Section titled “Property details”background
Section titled “background”this background(Node background)fluentNode getBackground()
Default: null: no background
The node drawn behind the text, over the whole field, with a zindex of -1; optional.
cursorColor
Section titled “cursorColor”this cursorColor(Color cursorColor)fluentthis cursorColor(Supplier<Color> cursorColor)fluent signalColor getCursorColor()
Default: null: the color of info
The color of the blinking cursor; null uses the color of info.
selectionColor
Section titled “selectionColor”this selectionColor(Color selectionColor)fluentthis selectionColor(Supplier<Color> selectionColor)fluent signalColor getSelectionColor()
Default: new Color(50, 152, 253, 100)
The color of the rectangle drawn over the selected text.
placeholderColor
Section titled “placeholderColor”this placeholderColor(Color placeholderColor)fluentthis placeholderColor(Supplier<Color> placeholderColor)fluent signalColor getPlaceholderColor()
Default: null: the color of info at half its opacity
The color of the placeholder; null uses the color of info at half its opacity.
cursorMargin
Section titled “cursorMargin”this cursorMargin(double cursorMargin)fluentthis cursorMargin(Supplier<Double> cursorMargin)fluent signaldouble getCursorMargin()
Default: 0D
The distance, in design pixels, that the field keeps between the cursor and the edge of the visible text when it scrolls to follow the cursor.
cursorPosition
Section titled “cursorPosition”this cursorPosition(int cursorPosition)fluentint getCursorPosition()
Default: 0
The index of the cursor in the text, kept within the text; a plain index is the start value.
getCursorPosition() reads it.
this text(String text)fluentthis text(Signal<String> text)fluentString getText()
Default: ""
The text in the field.
A plain text is the start value, and a signal binds the text both ways: the field shows the signal and writes each edit into it.
A text from code is cleaned of control characters and cut to maxTextLength; it is never refused.
placeholder
Section titled “placeholder”this placeholder(String placeholder)fluentthis placeholder(Supplier<String> placeholder)fluent signalString getPlaceholder()
Default: ""
The text shown while the field is empty and has no focus.
this info(TextInfo info)fluentthis info(Supplier<TextInfo> info)fluent signalTextInfo getInfo()
Default: none, info(...) is required before the attach
The font, the size and the color of the text, as a TextInfo; required.
accept
Section titled “accept”this accept(Predicate<String> accept)fluentPredicate<String> getAccept()
Default: text -> true
A test that every edit of the user must pass: an edit typed, pasted, cut or deleted whose text fails it is refused, and the text stays as it was. A text that fails it is not a valid value.
normalize
Section titled “normalize”this normalize(UnaryOperator<String> normalize)fluentUnaryOperator<String> getNormalize()
Default: UnaryOperator.identity()
A function applied to the text before the field reads a value from it, such as String::trim.
The field shows the normalized text when it loses the focus, and at once for a text given by a setter or a signal.
allowEmpty
Section titled “allowEmpty”this allowEmpty(boolean allowEmpty)fluentthis allowEmpty(Supplier<Boolean> allowEmpty)fluent signalboolean isAllowEmpty()
Default: false
If true, an empty field is valid and its value is null.
If false, the empty text goes through parse: a TextFieldNode then holds "", and a field whose parse returns null for it, such as IntegerFieldNode, takes back its last valid value when it loses the focus.
maxTextLength
Section titled “maxTextLength”this maxTextLength(int maxTextLength)fluentthis maxTextLength(Supplier<Integer> maxTextLength)fluent signalint getMaxTextLength()
Default: no limit
The largest number of characters of the text; -1 means no limit.
Typing and pasting stop at the limit, and a longer text from code is cut.
markup
Section titled “markup”this markup(boolean markup)fluentthis markup(Supplier<Boolean> markup)fluent signalboolean isMarkup()
Default: false
If true, the text is read with the markups of info, so that the tags in the text style it; if false, the field shows the tags as typed.
margin
Section titled “margin”this margin(double margin)fluentthis margin(Supplier<Double> margin)fluent signal
Sets the four margins at once.
marginTop
Section titled “marginTop”this marginTop(double marginTop)fluentthis marginTop(Supplier<Double> marginTop)fluent signaldouble getMarginTop()
Default: 0D
The space, in design pixels, between the top edge and the text; a one-line field uses it with alignY(START) and to size a field of height 0.
marginBottom
Section titled “marginBottom”this marginBottom(double marginBottom)fluentthis marginBottom(Supplier<Double> marginBottom)fluent signaldouble getMarginBottom()
Default: 0D
The space, in design pixels, between the bottom edge and the text; a one-line field uses it with alignY(END) and to size a field of height 0.
marginLeft
Section titled “marginLeft”this marginLeft(double marginLeft)fluentthis marginLeft(Supplier<Double> marginLeft)fluent signaldouble getMarginLeft()
Default: 0D
The space, in design pixels, between the left edge and the text; the text is clipped there.
marginRight
Section titled “marginRight”this marginRight(double marginRight)fluentthis marginRight(Supplier<Double> marginRight)fluent signaldouble getMarginRight()
Default: 0D
The space, in design pixels, between the right edge and the text; the text is clipped there.
marginHorizontal
Section titled “marginHorizontal”this marginHorizontal(double marginHorizontal)fluentthis marginHorizontal(Supplier<Double> marginHorizontal)fluent signal
Sets the left and the right margins at once.
marginVertical
Section titled “marginVertical”this marginVertical(double marginVertical)fluentthis marginVertical(Supplier<Double> marginVertical)fluent signal
Sets the top and the bottom margins at once.
Method details
Section titled “Method details”cursorPosition
Section titled “cursorPosition”<T extends FieldNode<V>> T cursorPosition(Signal<Integer> cursorPosition)
Binds the index of the cursor to a signal both ways.
Throws an IllegalArgumentException for a signal that cannot be written.
moveCursor
Section titled “moveCursor”this moveCursor(int position) fluent
Moves the cursor as if the user did: beforeCursorMove can refuse it, then onCursorMove fires.
beforeCursorMove
Section titled “beforeCursorMove”<T extends FieldNode<V>> T beforeCursorMove(EventListener<NodeChangeEvent.Pre<T,Integer>> listener)
Adds a listener that runs before the cursor moves on a key, a press or moveCursor(...); cancel() keeps it in place.
focused
Section titled “focused”<T extends FieldNode<V>> T focused(boolean focused)
Gives the field its start focus: true gives it the keyboard.
<T extends FieldNode<V>> T focused(Signal<Boolean> focused)
Binds the focus to a signal both ways: the field gains or loses the focus with the signal, and writes into it when the user focuses or blurs the field.
Throws an IllegalArgumentException for a signal that cannot be written.
this focus() fluent
Gives the field the focus: beforeFocus can refuse it, then onFocus fires; unlike a press, it does not blur the other fields.
beforeFocus
Section titled “beforeFocus”<T extends FieldNode<V>> T beforeFocus(EventListener<NodeChangeEvent.Pre<T,Boolean>> listener)
Adds a listener that runs before the field gains the focus on a press or focus(); cancel() refuses the focus.
isFocused
Section titled “isFocused”boolean isFocused()
If true, the field has the focus.
getValue
Section titled “getValue”V getValue()
Returns the value read from the text, normalized and brought into its bounds.
A text that is not a value gives the last valid value; an empty text with allowEmpty(true) gives null.
isValid
Section titled “isValid”boolean isValid()
If true, the text passes accept, reads as a value and that value is already within its bounds; an empty text with allowEmpty(true) is valid.
getSelection
Section titled “getSelection”FieldSelection getSelection()
Returns the selected range of the text; an empty range when nothing is selected.
selection
Section titled “selection”<T extends FieldNode<V>> T selection(int start, int end)
Gives the field its start selection, from start to end in any order, kept within the text.
A loss of the focus clears it, even while the text is too short to hold it.
<T extends FieldNode<V>> T selection(Signal<FieldSelection> selection)
Binds the selection to a signal of FieldSelection both ways.
Throws an IllegalArgumentException for a signal that cannot be written.
change
Section titled “change”this change(String text) fluent
Replaces the text as if the user typed it: beforeChange can refuse it, then onChange fires.
beforeChange
Section titled “beforeChange”<T extends FieldNode<V>> T beforeChange(EventListener<NodeFieldChangeEvent.Pre<T,V>> listener)
Adds a listener that runs before an edit of the user or change(...), with the text now, the text asked for and the value read from it; cancel() refuses the edit.
this blur() fluent
Blurs the field as a press elsewhere would: beforeBlur can refuse it, then onBlur fires.
beforeBlur
Section titled “beforeBlur”<T extends FieldNode<V>> T beforeBlur(EventListener<NodeChangeEvent.Pre<T,Boolean>> listener)
Adds a listener that runs before the field loses the focus on a press elsewhere, Escape, Enter or blur(); cancel() keeps the focus.
select
Section titled “select”this select(int start, int end) fluent
Selects a range as if the user did: beforeSelect can refuse it, then onSelect fires.
beforeSelect
Section titled “beforeSelect”<T extends FieldNode<V>> T beforeSelect(EventListener<NodeChangeEvent.Pre<T,FieldSelection>> listener)
Adds a listener that runs before the selection changes on a key, a press or select(...); cancel() keeps the selection.
layout
Section titled “layout”void layout() hook
Places the background over the whole field.
void draw(double mouseX, double mouseY) hook
Draws the field with drawField(), then repeats a held editing key.
An override calls super.draw(...).
mousePressed
Section titled “mousePressed”void mousePressed(NodeMouseEvent<?> event) hook
On a press over the field that no one consumed, blurs the other fields, focuses this one, places the cursor and starts a selection, and consumes the press; a double press selects a word, a triple press a line. Any other press blurs the field.
mouseReleased
Section titled “mouseReleased”void mouseReleased(NodeMouseEvent<?> event) hook
Ends the selection that a press started.
mouseDragged
Section titled “mouseDragged”void mouseDragged(NodeMouseEvent<?> event) hook
Extends the selection to the character under the pointer.
mouseScroll
Section titled “mouseScroll”void mouseScroll(NodeMouseScrollEvent<?> event) hook
Over the focused field, steps the value up or down with increment when its type has steps, and consumes the wheel.
charTyped
Section titled “charTyped”void charTyped(NodeCharEvent<?> event) hook
While the field has the focus, inserts the character at the cursor, in place of the selection, and consumes it. A character typed with Ctrl (Cmd on macOS) and without Alt is a shortcut and is not inserted.
keyPressed
Section titled “keyPressed”void keyPressed(NodeKeyEvent<?> event) hook
While the field has the focus, handles the editing, the cursor and the clipboard keys and consumes every key; Escape blurs the field.
It asks handleKey first.
detach
Section titled “detach”void detach() hook
Blurs the field when it leaves the tree.
holdsInput
Section titled “holdsInput”boolean holdsInput() hook protected
If true, the field has the focus or a selection by drag goes on: it keeps its keys and its drags while it is scrolled out of the area of its container.
getCursorArea
Section titled “getCursorArea”BoundingBox getCursorArea() hook abstract
Returns the area of the text cursor, in design pixels of the UI, where drawField draws it while the field has the focus.
drawField
Section titled “drawField”void drawField() hook abstract protected
Hook that draws the text, the cursor and the selection, on every frame.
isMultiline
Section titled “isMultiline”boolean isMultiline() hook abstract protected
Hook that returns true when the text may hold line breaks; a one-line field drops them from a paste.
handleKey
Section titled “handleKey”boolean handleKey(Key key) hook abstract protected
Hook that JOID calls first with each key pressed while the field has the focus.
Return true when the key is handled: the field does nothing else with it, and repeats it while it is held.
getPositionAt
Section titled “getPositionAt”int getPositionAt(double mouseX, double mouseY) hook abstract protected
Hook that returns the index in the text under a point of the UI, in design pixels.
followCursorForward
Section titled “followCursorForward”void followCursorForward() hook abstract protected
Hook that scrolls the visible text after the cursor moved forward, so that the cursor stays in view with cursorMargin.
followCursorBackward
Section titled “followCursorBackward”void followCursorBackward() hook abstract protected
Hook that scrolls the visible text after the cursor moved backward, so that the cursor stays in view with cursorMargin.
V parse(String text) hook abstract protected
Hook that turns a text into a value; return null when the text is not a value.
format
Section titled “format”String format(V value) hook abstract protected
Hook that turns a value into the text that the field shows.
correct
Section titled “correct”V correct(V value) hook protected
Hook that brings a value into its bounds, such as a minimum and a maximum; the default returns the value. A text whose value changes here is not valid while typed, and shows the corrected value when the field loses the focus.
accepts
Section titled “accepts”boolean accepts(String text) hook protected
Hook that refuses an edit whose text can never become a value, such as a letter in a number field; the default accepts every text.
An edit passes only when both accepts and accept let it through.
increment
Section titled “increment”V increment(V value, int count) hook protected
Hook that returns the value count steps away, for Up, Down and the wheel; count is negative to go down.
The default returns null: the type has no steps.
fallback
Section titled “fallback”void fallback(V fallback) protected
Gives the value that the field holds while no text was valid yet, such as 0 for a number.
startValue
Section titled “startValue”this startValue(V value) fluent protected
Gives the field a start value of its type, shown through format: the body of a public value(...) setter.
bindValue
Section titled “bindValue”this bindValue(Signal<V> value) fluent protected
Binds the value to a signal of its type both ways: the field shows the signal through format, and writes the value of each valid edit into it.
Throws an IllegalArgumentException for a signal that cannot be written.
void write(V value, boolean refusable) protected
Shows a value, brought into its bounds and formatted.
If refusable is true, the write acts like the user and goes through beforeChange: the body of a public change(...).
revalidate
Section titled “revalidate”void revalidate() protected
Shows again the value asked for last, after a bound of the field changed, such as its min or its max.
blurNow
Section titled “blurNow”boolean blurNow() protected
Blurs the field at once.
Returns true when the field lost the focus, false when a beforeBlur listener kept it.
insert
Section titled “insert”boolean insert(String text) protected
Inserts a text at the cursor, in place of the selection, as typing would: cleaned of control characters, cut to maxTextLength, and tested by accept and accepts.
Returns true when the text changed.
placeCursor
Section titled “placeCursor”void placeCursor(int position, boolean forward) protected
Moves the cursor to an index and scrolls to keep it in view; with Shift held, extends the selection.
forward is true for a move toward the end.
increaseCursor
Section titled “increaseCursor”void increaseCursor(int value) protected
Moves the cursor forward by a number of characters and scrolls to keep it in view.
decreaseCursor
Section titled “decreaseCursor”void decreaseCursor(int value) protected
Moves the cursor backward by a number of characters and scrolls to keep it in view.
getShownInfo
Section titled “getShownInfo”TextInfo getShownInfo() protected
Returns the TextInfo that draws the text: info with its markups, or without them when markup is false.
getPlaceholderInfo
Section titled “getPlaceholderInfo”TextInfo getPlaceholderInfo() protected
Returns the TextInfo that draws the placeholder, in the color of placeholderColor.
getShownCursorColor
Section titled “getShownCursorColor”Color getShownCursorColor() protected
Returns the color of the cursor on this frame, with the opacity of its blink.
getLineX
Section titled “getLineX”double getLineX(String text, int[] tags, int start, int end, String prefix, int position) protected
Returns the horizontal offset, in design pixels, of a position within a line of the text from start to end, with the markup tags given by tags and a prefix of opened tags.
getLinePosition
Section titled “getLinePosition”int getLinePosition(String text, int[] tags, int start, int end, String prefix, double x) protected
Returns the index of the line from start to end that is nearest to a horizontal offset, the inverse of getLineX.
Event details
Section titled “Event details”onChange
Section titled “onChange”<T extends FieldNode<V>> T onChange(EventListener<NodeFieldChangeEvent.Post<T,V>> listener)
Adds a listener that runs after each real change of the text, whatever its source.
onFocus
Section titled “onFocus”<T extends FieldNode<V>> T onFocus(EventListener<NodeChangeEvent.Post<T,Boolean>> listener)
Adds a listener that runs each time the field gains the focus, whatever its source.
onBlur
Section titled “onBlur”<T extends FieldNode<V>> T onBlur(EventListener<NodeChangeEvent.Post<T,Boolean>> listener)
Adds a listener that runs each time the field loses the focus, after it rewrote its text from its value.
onCursorMove
Section titled “onCursorMove”<T extends FieldNode<V>> T onCursorMove(EventListener<NodeChangeEvent.Post<T,Integer>> listener)
Adds a listener that runs after each move of the cursor, whatever its source.
onSelect
Section titled “onSelect”<T extends FieldNode<V>> T onSelect(EventListener<NodeChangeEvent.Post<T,FieldSelection>> listener)
Adds a listener that runs after each change of the selection, whatever its source.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
