Class Field
TextField, a
ComboBox, a date picker, a check box, or a row of an amount and its currency.
TextField email = new TextField();
Field field = new Field("Email", email)
.setHelperText("We never share it")
.setRequired(true);
email.onChange(text -> field.setValidation(text.contains("@")
? Validation.NONE : Validation.ERROR, "Enter an address like ada@example.com"));
The caption names the control. It is drawn above the control in the step's label font,
muted, and a screen reader hears it as the control's name, on the part the keyboard lands on
(a date picker's field, an editable combo's text). An & in it marks the access letter
that brings the keyboard to the control, as a caption bound with Label.setLabelFor(limn.scene.Widget<?>) does.
A field built with no caption keeps everything else: a check box that must be ticked keeps its
own words and gains a line and the states. A caption beside its control, rather than above, is a
Grid(2) of a bound Label and a field with no caption.
The line under the control says one thing. While the state is not
Validation.NONE and a message is set, it is the message, in the state's Tone and
with the state's glyph before it, so the state never depends on colour alone; otherwise the
helper text, muted; otherwise nothing. A message set with NONE is not shown, and counts
as none. A control that refuses what it holds, a date field or a date picker holding a day out
of range say, says why on the line, in the error tone, ahead of the helper text and of an
Validation.INFO or Validation.SUCCESS message, which would otherwise say "looks
good" over a value still refused; an Validation.ERROR or Validation.WARNING
message the application set still takes the line, and the refusal returns to it when that
message goes, while the control still refuses. A screen reader hears the line as the control's
description, whichever it shows.
The line keeps its height. A field given helper text, or a state once, reserves its line from then on, so a form does not move when the first error appears or the last one is fixed. A field given neither reserves nothing.
The state is the application's, and a required field validates nothing.
setRequired(boolean) draws an asterisk after the caption, in the danger colour, and tells a
reader the field is required in the system's own words; whether an empty required field is an
error, and when to say so, is the application's, set with setValidation(limn.components.Validation). The state
colours the control's border where the control draws one (a text field, a text area, a combo box,
a spinner, a date field and a date picker; a field around a date field or a picker that refuses a
day stays red whatever state is set), and only Validation.ERROR reaches a reader as a
state, as invalid.
A field takes no focus and handles no key: Tab goes to the control. Reading right to left, the caption and the line start at the right edge, the asterisk follows the caption's end and the glyph leads the message.
-
Constructor Summary
ConstructorsConstructorDescriptionA field whose caption is a fixed string, aroundcontrol.Field(@Nullable I18nString label, Widget<?> control, Widget<?> placed) A field around a control that sits inside a wrapper: a field beside a switch, a sized box.Field(I18nString label, Widget<?> control) A field whose caption islabel, aroundcontrol. -
Method Summary
Modifier and TypeMethodDescriptionTakes the helper text away, assetHelperText(null)would: that call does not compile, becausenullfits more than one of the overloads.Takes the caption away, assetLabel(null)would: that call does not compile, becausenullfits more than one of the overloads.Takes the state and the message away: the border is the control's own again, and the line shows the helper text, or stays empty at its height.Widget<?> control()The control the caption names and the states are published on.@Nullable StringThe helper text in the language in effect, ornullfor none; seehelperTextSource()for the value behind it.@Nullable I18nStringThe localizable value behindhelperText(), ornullfor none.booleanWhether the field is required; seesetRequired(boolean).@Nullable Stringlabel()The caption as it currently reads, ornullfor none: its text in the language in effect, an access letter's&mark taken out ("&Name" reads "Name"); seelabelSource()for the value behind it.@Nullable I18nStringThe localizable value behindlabel(), ornullfor none.protected voidCalled when this widget enters a scene (attached to the tree).protected voidCalled when this widget leaves the scene: detached from the tree, moved into another scene (told this before theWidget.onAttached()of the scene it joins), or still in it when the scene's window closes, which detaches every widget the scene has.protected voidonLayout()Containers position children here (measure +Widget.layoutBox(float, float, float, float)per child).protected SizeonMeasure(Constraints constraints) Reports the size this widget wants withinconstraints.protected floatHow far the control may paint past this field's box: the reach of the theme's focus ring, since the control is laid out to the field's own edges.setHelperText(String text) setHelperText(I18nString)with a fixed string.setHelperText(@Nullable I18nString text) Sets the line under the control while no message stands in its place: how to fill the field, what it expects ("Eleven digits, as on the card").setLabel(I18nString)with a fixed string.setLabel(@Nullable I18nString newLabel) Replaces the caption;nulltakes it away, and the control keeps whatever names it otherwise (a check box its own words).setRequired(boolean newRequired) Marks the field as one that must be filled in: an asterisk after the caption, in the danger colour, and the required state on the control, which each system's reader says in its own words.setValidation(Validation state) Sets the state alone, with no message: the border and the reader's state follow it, and the line shows the helper text; seesetValidation(Validation, I18nString).setValidation(Validation state, String newMessage) setValidation(Validation, I18nString)with a fixed string.setValidation(Validation state, @Nullable I18nString newMessage) Sets what the application decided about the value the control holds, and what to say about it.The state the application set; seesetValidation(Validation, I18nString).@Nullable StringThe message about the control, as the line under the control says it: the one the application set withValidation.ERRORorValidation.WARNING; else the control's own reason while it refuses what it holds (a date field that refuses a day); else the one the application set withValidation.INFOorValidation.SUCCESS;nullwhen there is none of them.@Nullable I18nStringThe localizable value behindvalidationMessage(): the application's message withValidation.ERRORorValidation.WARNING, else the control's own reason, else the application's message withValidation.INFOorValidation.SUCCESS, elsenull.Methods inherited from class limn.scene.Widget
acceptsTextInput, accessibleLabelAccessKey, accessibleLabelTarget, accessibleLabelText, add, add, announceChange, backdropReach, baselineOffset, baselineOffsetOf, caretRect, children, clipboard, clipHeight, clipsChildren, clipWidth, clipX, clipY, controlSize, cursor, declaredControlSize, declaredLayoutDirection, declaredLocale, focusArrivedBackward, focusArrivedByTraversal, handleUserChange, height, hitTest, hitTestChild, id, imageCursor, inheritanceHost, invalidate, invalidate, invalidateAccessible, isEnabled, isFocusable, isFocused, isRightToLeft, isSelfEnabled, isShowing, isVisible, isVisibleByItsOwnFlag, layoutBox, layoutDirection, locale, localToScene, localToSceneBounds, markNeedsContainedLayout, markNeedsLayout, markNeedsLayoutInPlace, maxHeight, maxWidth, measure, minHeight, minWidth, moveChild, moveChild, moveChild, neutralBase, notifyChange, notifyTextEdit, observeChanges, onAccessibility, onAccessibilityAction, onAccessibilityChild, onAccessibilityChildAction, onAccessibilityChildIdentity, onCanEdit, onCharTyped, onDragExit, onDragOver, onDragStart, onDrop, onEdit, onFocusGained, onFocusLost, onHitTest, onKeyEvent, onMouseEvent, onPaint, onPaintOverlay, onPreedit, onSyntheticAction, overlayPassesPointer, paintChildren, paintsDecoration, paintsFromBackdrop, paintWidget, parent, remove, remove, requestFocus, requestFocus, revealInView, revealInView, runHandler, scene, sceneNanos, sceneToLocal, self, setAccessibleDescribedBy, setAccessibleDescription, setAccessibleDescription, setAccessibleIgnored, setAccessibleLabelledBy, setAccessibleName, setAccessibleName, setAccessibleRole, setControlSize, setCursor, setEnabled, setFocusable, setId, setImageCursor, setInheritanceHost, setLayoutDirection, setLocale, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setPresentedElsewhere, setTooltip, setTooltip, setVisible, shapeText, textRuler, tooltip, tooltipSource, width, x, y
-
Constructor Details
-
Field
A field whose caption islabel, aroundcontrol.- Parameters:
label- the caption, which follows the languagecontrol- what is named and laid out
-
Field
A field whose caption is a fixed string, aroundcontrol.- Parameters:
label- the captioncontrol- what is named and laid out
-
Field
A field around a control that sits inside a wrapper: a field beside a switch, a sized box. The caption namescontroland the states are published on it, whileplacedis what is laid out under the caption.- Parameters:
label- the caption, ornullfor nonecontrol- what is named, described and given the statesplaced- what is laid out:controlitself, or a widget that holds it- Throws:
IllegalArgumentException- whenplaceddoes not holdcontrol
-
-
Method Details
-
control
The control the caption names and the states are published on. -
label
The caption as it currently reads, ornullfor none: its text in the language in effect, an access letter's&mark taken out ("&Name" reads "Name"); seelabelSource()for the value behind it. -
labelSource
The localizable value behindlabel(), ornullfor none. -
setLabel
Replaces the caption;nulltakes it away, and the control keeps whatever names it otherwise (a check box its own words). UI thread only.- Parameters:
newLabel- the caption, ornull- Returns:
- this field
-
setLabel
setLabel(I18nString)with a fixed string. -
clearLabel
Takes the caption away, assetLabel(null)would: that call does not compile, becausenullfits more than one of the overloads.- Returns:
- this field
-
helperText
The helper text in the language in effect, ornullfor none; seehelperTextSource()for the value behind it. -
helperTextSource
The localizable value behindhelperText(), ornullfor none. -
setHelperText
Sets the line under the control while no message stands in its place: how to fill the field, what it expects ("Eleven digits, as on the card"). Shown with the focus elsewhere too, which a text field's placeholder and a mask's guide are not, and read to a screen reader as the control's description. From the first helper text on, the line keeps its height. UI thread only.- Parameters:
text- the helper text, ornullfor none- Returns:
- this field
-
setHelperText
setHelperText(I18nString)with a fixed string. -
clearHelperText
Takes the helper text away, assetHelperText(null)would: that call does not compile, becausenullfits more than one of the overloads.- Returns:
- this field
-
isRequired
public boolean isRequired()Whether the field is required; seesetRequired(boolean). -
setRequired
Marks the field as one that must be filled in: an asterisk after the caption, in the danger colour, and the required state on the control, which each system's reader says in its own words. Nothing is validated: an empty required field is an error when the application says so. UI thread only.- Parameters:
newRequired- whether the field is required- Returns:
- this field
-
validation
The state the application set; seesetValidation(Validation, I18nString). -
validationMessage
The message about the control, as the line under the control says it: the one the application set withValidation.ERRORorValidation.WARNING; else the control's own reason while it refuses what it holds (a date field that refuses a day); else the one the application set withValidation.INFOorValidation.SUCCESS;nullwhen there is none of them. A message set withValidation.NONEis not shown, and is not answered here either. It reads in the control's language, the one the control declares, else the one it takes from this field and the widgets above it, so a Portuguese date field in an English window is described in Portuguese, on the line and here. SeevalidationMessageSource()for the value behind it. -
validationMessageSource
The localizable value behindvalidationMessage(): the application's message withValidation.ERRORorValidation.WARNING, else the control's own reason, else the application's message withValidation.INFOorValidation.SUCCESS, elsenull. -
setValidation
Sets the state alone, with no message: the border and the reader's state follow it, and the line shows the helper text; seesetValidation(Validation, I18nString).- Parameters:
state- the state- Returns:
- this field
-
setValidation
Sets what the application decided about the value the control holds, and what to say about it. The state colours the control's border where it draws one; the message, while the state is notValidation.NONE, takes the line under the control in the state's tone, with the state's glyph, except that anValidation.INFOorValidation.SUCCESSmessage waits while the control refuses what it holds (a date field holding a day it refuses), whose reason the line shows instead;Validation.ERRORis the invalid state to a screen reader, which hears the line as the control's description. From the first state on, the line keeps its height. Called from the application's handler or watcher, when it chooses: on change, on leaving the field, on submitting. UI thread only.- Parameters:
state- the statenewMessage- what to say, ornullfor nothing: the helper text stays on the line. WithValidation.NONEit is neither shown nor read, nor answered byvalidationMessage()- Returns:
- this field
-
setValidation
setValidation(Validation, I18nString)with a fixed string. -
clearValidation
Takes the state and the message away: the border is the control's own again, and the line shows the helper text, or stays empty at its height. UI thread only.- Returns:
- this field
-
onAttached
protected void onAttached()Description copied from class:WidgetCalled when this widget enters a scene (attached to the tree).Widget.scene()is the scene it just joined. Fires top-down, so a parent runs before its children. Default no-op.- Overrides:
onAttachedin classWidget<Field>
-
onDetached
protected void onDetached()Description copied from class:WidgetCalled when this widget leaves the scene: detached from the tree, moved into another scene (told this before theWidget.onAttached()of the scene it joins), or still in it when the scene's window closes, which detaches every widget the scene has. What was taken inWidget.onAttached()from something that outlives the window (a listener's place in a list of the process's, a resource of the system's) is given back here.Widget.scene()still answers the scene being left, and becomesnullonce this returns, so releasing something the scene owns needs no field of your own to remember it by. Fires bottom-up, so children run before their parent, and every one of them can still reach the scene.Release resources here, but GPU resources must be handed to
Scene.disposeLater(limn.graphics.GpuSurface)(disposal needs the owning GL context, which is only current inside a frame). Not called onWidget.setVisible(boolean). Default no-op.- Overrides:
onDetachedin classWidget<Field>
-
paintOutset
protected float paintOutset()How far the control may paint past this field's box: the reach of the theme's focus ring, since the control is laid out to the field's own edges.- Overrides:
paintOutsetin classWidget<Field>
-
onMeasure
Description copied from class:WidgetReports the size this widget wants withinconstraints. Called once per layout pass, and the result is cached against the constraints and the resolved axes (size step, layout direction, locale), so it must be a pure function of them and of this widget's own state.Resolve the
ControlSizeand theLayoutDirectiononce each here and thread them down; never read either in a constructor. The locale needs no threading: it is in scope, andI18n.locale()answers it wherever text is resolved. -
onLayout
protected void onLayout()Description copied from class:WidgetContainers position children here (measure +Widget.layoutBox(float, float, float, float)per child).
-