Skip to content

BaseChoiceNode

abstract class BaseChoiceNode<V>
Extends: Node
Known subtypes: SwitchNode, BaseSelectorNode, BaseSliderNode
Package: dev.joid.lib.ui.node.impl.control.choice · Module: core · Source: BaseChoiceNode.java

The behavior shared by the controls that select one value among options: the switch, the selector and the sliders.

A choice holds a list of options and the selected one. New options keep the selected value when it is still one of them; otherwise the choice shows the value of fallback(...). A value given by a bound signal that is not an option yet waits until the options hold it; a plain value must be one of the options. The order of values(...) and value(...) does not matter. Attaching a choice without options throws an IllegalStateException.

ReturnsSignatureSummary
BaseChoiceNode(double x, double y, double width, double height) protectedCreates the choice at x, y with a width and a height in design pixels, from the constructor of a subclass.

PropertyTypeDefaultSummary
values signalV...none, values(...) is required before the attachThe options, at least one, in their order on screen.
valueVthe first optionThe selected option.
valueIndexint0, the first optionThe index of the selected option in the options.
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

ReturnsSignatureSummary
List<V>getValueList()Returns the options, as a read-only view that follows the options set later.
thischange(V value) fluentSelects an option as if the user picked it: beforeChange can refuse it, then onChange fires.
TbeforeChange(EventListener<NodeChangeEvent.Pre<T,V>> listener)Adds a listener that runs before a change that a gesture or change(...) asks for; cancel() refuses it.
ReturnsSignatureSummary
voidcreateOptions() hook protectedHook that JOID calls each time the options change, after the choice stored them.
Vfallback(V value) hook protectedHook that picks the value to show when the value asked for is not one of the options.
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

EventListenerSummary
onChangeEventListener<NodeChangeEvent.Post<T,V>>Adds a listener that runs after each real change of the selected value, 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

BaseChoiceNode(double x, double y, double width, double height) protected

Creates the choice at x, y with a width and a height in design pixels, from the constructor of a subclass.

  • this values(V... values) fluent
  • this values(Supplier<List<V>> values) fluent signal

Default: none, values(...) is required before the attach

The options, at least one, in their order on screen. The reactive setter takes a Supplier of a list, and the choice builds its options again each time the list changes. An empty list throws an IllegalArgumentException.

  • this value(V value) fluent
  • this value(Signal<V> value) fluent
  • V getValue()

Default: the first option

Throws:

  • IllegalStateException: The … has no values, call values(…) before getValue()

The selected option. A plain value is the start value, and throws an IllegalArgumentException when it is not one of the options; a signal binds the selection both ways.

  • this valueIndex(int valueIndex) fluent
  • this valueIndex(Signal<Integer> valueIndex) fluent
  • int getValueIndex()

Default: 0, the first option

The index of the selected option in the options. A plain index is the start value, and throws an IllegalArgumentException when it is out of the options; an IntegerSignal binds the index both ways.

List<V> getValueList()

Returns the options, as a read-only view that follows the options set later.

this change(V value) fluent

Selects an option as if the user picked it: beforeChange can refuse it, then onChange fires. Throws an IllegalArgumentException for a value that is not an option.

<T extends BaseChoiceNode<V>> T beforeChange(EventListener<NodeChangeEvent.Pre<T,V>> listener)

Adds a listener that runs before a change that a gesture or change(...) asks for; cancel() refuses it.

void createOptions() hook protected

Hook that JOID calls each time the options change, after the choice stored them. The switch and the selector build one node per option there; the default does nothing.

V fallback(V value) hook protected

Hook that picks the value to show when the value asked for is not one of the options. The default keeps the current value when it is still an option, else the first option; the sliders of numbers return the nearest option.

<T extends BaseChoiceNode<V>> T onChange(EventListener<NodeChangeEvent.Post<T,V>> listener)

Adds a listener that runs after each real change of the selected value, 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

Report a problem with this page