Class Form

  • All Implemented Interfaces:
    FocusContainer

    public final class Form
    extends Split
    implements FocusContainer
    A stack of fields with internal Tab traversal: Tab and Shift-Tab cycle the fields, descending depth-first into nested forms. ESC fires the cancel handler.
    • Constructor Detail

      • Form

        public Form()
        Creates a vertical form whose fields are stacked top to bottom.
    • Method Detail

      • row

        public static Form row()
        Returns:
        a new horizontal form, fields laid out left to right
      • addField

        public Form addField​(Section field)
        Adds a focusable field spanning one cell along the form's axis.
        Parameters:
        field - the field to add
        Returns:
        this Form for chaining
      • addField

        public Form addField​(Section field,
                             int size)
        Adds a focusable field spanning a fixed number of cells along the form's axis.
        Parameters:
        field - the field to add
        size - the number of cells to span
        Returns:
        this Form for chaining
      • addField

        public Form addField​(Section field,
                             Constraint size)
        Adds a focusable field sized by an explicit layout constraint.
        Parameters:
        field - the field to add
        size - the constraint sizing the field along the form's axis
        Returns:
        this Form for chaining
      • addStatic

        public Form addStatic​(Section decoration,
                              int size)
        Adds non-focusable decoration (such as a label) spanning a fixed number of cells.
        Parameters:
        decoration - the section to add
        size - the number of cells to span
        Returns:
        this Form for chaining
      • onCancel

        public Form onCancel​(java.lang.Runnable handler)
        Sets the handler run when ESC is pressed while the form has focus.
        Parameters:
        handler - the cancel handler
        Returns:
        this Form for chaining
      • focusTargets

        public java.util.List<Section> focusTargets()
        Description copied from interface: FocusContainer
        Returns the focusable descendants this container manages internally.
        Specified by:
        focusTargets in interface FocusContainer
        Returns:
        the focus targets, in traversal order
      • activeFocusTarget

        public Section activeFocusTarget()
        Description copied from interface: FocusContainer
        Returns the currently focused internal target.
        Specified by:
        activeFocusTarget in interface FocusContainer
        Returns:
        the active focus target, or null when none is focused
      • advanceFocus

        public boolean advanceFocus​(boolean forward)
        Description copied from interface: FocusContainer
        Moves internal focus in the given direction.
        Specified by:
        advanceFocus in interface FocusContainer
        Parameters:
        forward - true to advance, false to move back
        Returns:
        true when focus moved internally, false at an edge so the parent advances instead