Class StepFlow
- All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>
A multi-step flow: a checkout, a sign-up or a setup wizard. Each step has a
title, an optional subtitle and a body; a row of numbered markers shows
where the user is, and Back and Continue buttons move between the steps.
It is Flutter's Stepper, Material's stepper and the MUI Stepper.
TextField address = new TextField("", "Address");
StepFlow flow = new StepFlow()
.addStep("Shipping", "Where it goes", address)
.addStep("Payment", null, new Label("Card on file"))
.addStep("Review", null, new Label("Everything looks right"));
flow.setStepValidator((f, step) -> step != 0 || address.getText().length() > 0);
flow.addFinishListener(e -> Log.p("Order placed"));
Form form = new Form("Checkout", new BorderLayout());
form.add(BorderLayout.CENTER, flow);
form.show();
Steps before the current one are done and show a check, the current one is
filled and later ones are faded. #setError(int, boolean) marks a step as
failed and #setStepEnabled(int, boolean) skips it. A validator runs before
the user leaves a step forwards; when it refuses, the step is marked as an
error and the flow stays where it is. Going back never validates.
By default the markers run across the top and the body of the current step
fills the space below them. new StepFlow(true) lays the steps out in a
column instead, with the current step's body and buttons opening under its
title, the layout Flutter calls a vertical stepper.
For a read-only progress display with no bodies (order tracking, a
delivery status) use ActivityTimeline. The numeric Stepper control is
unrelated.
UIIDs: StepFlow for the whole component, StepFlowHeader for the row of
markers, StepFlowTitle and StepFlowSubtitle for a step's texts,
StepFlowContent for the body, StepFlowNavigation for the button bar,
StepFlowBackButton and StepFlowNextButton for its buttons. The marker
colours follow the theme's Slider colours unless StepFlowMarker is
styled; StepFlowMarkerError sets the error colour.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDecides whether the user may leave a step forwards. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe step being shown.static final intA step turned off with#setStepEnabled(int, boolean).static final intThe step's position relative to the current one decides how it is drawn: before it is done.static final intA step marked as failed with#setError(int, boolean).static final intA step after the current one.Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidListens for the user finishing the flow: Continue pressed on the last step after it validated.Adds a step at the end.voidListens for the current step changing.booleanback()Moves to the previous enabled step, without validating.voidRemoves every step.The Back button, to restyle it or give it an icon.intThe index of the step being shown.The Continue / Finish button.intgetState(int index) How a step is drawn now:#DONE,#CURRENT,#PENDING,#ERRORor#DISABLED.getStepContent(int index) The body of a step.intThe number of steps.protected voidinitUnselectedStyle(Style unselectedStyle) Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.booleanisStepEnabled(int index) Whether a step is on.booleanWhether taps on the steps move to them.booleanWhether the steps are stacked in a column.booleannext()Moves to the next enabled step after validating the current one.voidRemoves a finish listener.voidRemoves a step listener.voidsetAnimated(boolean animated) Whether moving between steps slides the body.voidsetButtonTexts(String back, String next, String finish) Sets the button texts.voidsetCurrentStep(int index) Shows a step without running the validator.voidsetError(int index, boolean error) Marks a step as failed, or clears the mark.voidsetNavigationVisible(boolean visible) Shows or hides the Back and Continue buttons, for a flow driven from the application's own buttons through#next()and#back().voidsetStepEnabled(int index, boolean enabled) Turns a step on or off.voidsetStepValidator(StepFlow.StepValidator validator) Sets the validator that runs before the user moves forwards.voidsetTapToJump(boolean tapToJump) Whether a tap on a step's marker or title moves to it.Methods inherited from class Container
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesMethods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addNativeDragOverListener, addNativeDropListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, canAcceptNativeDrop, consumesRawTextInput, contains, containsOrOwns, createNativeDragOperation, createStyleAnimation, deinitialize, deinitializeCustomStyle, deregisterFromAnimation, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAcceptedDropActions, getAcceptedDropMimeTypes, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getContextMenuCommands, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getHoverStyle, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeDragOperation, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getTopLevelContainer, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHovered, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isNativeDragSource, isNativeDropTarget, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyRepeated, laidOut, longKeyPress, longPointerPress, mouseWheel, nativeDragEnter, nativeDragExit, nativeDragOver, nativeDrop, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, registerForAnimation, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removeNativeDragOverListener, removeNativeDropListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAcceptedDropActions, setAcceptedDropMimeTypes, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setContextMenuCommands, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setHovered, setHoverStyle, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNativeDragOperation, setNativeDragSource, setNativeDropTarget, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stopScrollMomentum, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
DONE
public static final int DONEThe step's position relative to the current one decides how it is drawn: before it is done.- See Also:
-
CURRENT
public static final int CURRENTThe step being shown.- See Also:
-
PENDING
public static final int PENDINGA step after the current one.- See Also:
-
ERROR
public static final int ERRORA step marked as failed with#setError(int, boolean).- See Also:
-
DISABLED
public static final int DISABLEDA step turned off with#setStepEnabled(int, boolean).- See Also:
-
-
Constructor Details
-
StepFlow
public StepFlow()An empty flow with its markers across the top. -
StepFlow
public StepFlow(boolean vertical) An empty flow.
Parameters
vertical: true to stack the steps in a column, with the current step's body under its title; false for markers across the top
-
-
Method Details
-
initUnselectedStyle
Description copied from class:ComponentCan be overridden by subclasses to perform initialization when the unselected style is set to a new value.
Parameters
unselectedStyle: The unselected style.
- Overrides:
initUnselectedStylein classComponent
-
isVertical
public boolean isVertical()Whether the steps are stacked in a column.
Returns
true for a vertical flow
-
addStep
Adds a step at the end. The first step added becomes the current one.
Parameters
-
title: the step's title -
subtitle: a short line under the title, or null -
content: the step's body, or null for a step with no body
Returns
this, for chaining
-
-
clearSteps
public void clearSteps()Removes every step. -
getStepCount
public int getStepCount()The number of steps.
Returns
the step count
-
getCurrentStep
public int getCurrentStep()The index of the step being shown.
Returns
the current step, or -1 when the flow is empty
-
setCurrentStep
public void setCurrentStep(int index) Shows a step without running the validator. Use it to restore a flow or to move the user from code; the user's own moves go through
#next(),#back()and taps on the markers.Parameters
index: the step to show
-
getState
public int getState(int index) How a step is drawn now:
#DONE,#CURRENT,#PENDING,#ERRORor#DISABLED.Parameters
index: the step's index
Returns
the step's state
-
setError
public void setError(int index, boolean error) Marks a step as failed, or clears the mark. A step the validator refused is marked automatically and cleared when it next passes.
Parameters
-
index: the step's index -
error: true to show the step as an error
-
-
setStepEnabled
public void setStepEnabled(int index, boolean enabled) Turns a step on or off.
#next()and#back()skip a disabled step, and a tap on it does nothing.Parameters
-
index: the step's index -
enabled: false to skip the step
-
-
isStepEnabled
public boolean isStepEnabled(int index) Whether a step is on.
Parameters
index: the step's index
Returns
false when the step is skipped
-
getStepContent
The body of a step.
Parameters
index: the step's index
Returns
the component passed to
#addStep(String, String, Component) -
setStepValidator
Sets the validator that runs before the user moves forwards.
Parameters
validator: the validator, or null to allow every move
-
setTapToJump
public void setTapToJump(boolean tapToJump) Whether a tap on a step's marker or title moves to it. Moving back is always allowed; moving forwards validates every step in between. On by default.
Parameters
tapToJump: false to move only with the buttons
-
isTapToJump
public boolean isTapToJump()Whether taps on the steps move to them.
Returns
true when a tap moves to the step
-
setAnimated
public void setAnimated(boolean animated) Whether moving between steps slides the body. On by default.
Parameters
animated: false to switch bodies at once
-
setButtonTexts
-
getBackButton
The Back button, to restyle it or give it an icon.
Returns
the Back button
-
getNextButton
The Continue / Finish button.
Returns
the button that moves forwards
-
addStepListener
Listens for the current step changing. The event's source is this flow; read
#getCurrentStep().Parameters
l: the listener
-
removeStepListener
Removes a step listener.
Parameters
l: the listener
-
addFinishListener
Listens for the user finishing the flow: Continue pressed on the last step after it validated.
Parameters
l: the listener
-
removeFinishListener
Removes a finish listener.
Parameters
l: the listener
-
next
public boolean next()Moves to the next enabled step after validating the current one. On the last step it validates and then notifies the finish listeners.
Returns
true if the flow moved on or finished
-
back
public boolean back()Moves to the previous enabled step, without validating.
Returns
false when there is no earlier step
-