Package swingtree

Enum Class UI.Axis

All Implemented Interfaces:
Serializable, Comparable<UI.Axis>, Constable, UIEnum<UI.Axis>
Enclosing class:
UI

@Immutable public static enum UI.Axis extends Enum<UI.Axis> implements UIEnum<UI.Axis>
Names the axis along which a component or a layout manager arranges things: the axis a JSlider, JProgressBar, JSeparator, JSplitPane or JToolBar runs along, and the axis a BoxLayout stacks its children on.

Two of the four constants say which way a thing runs outright: HORIZONTAL and VERTICAL. The other two say it by way of the reading direction of the container: LINE is the way a line of text runs and PAGE is the way lines follow each other down a page. A BoxLayout is the only place in SwingTree where that detour changes the outcome, so every other component asks resolve() and reads LINE as HORIZONTAL and PAGE as VERTICAL. That way a view model which models its axis as LINE can feed a slider and a box layout from one property.

Create a box layout for your components by calling the UIForAnySwing.withBoxLayout(swingtree.UI.Axis) method, or use the Layout.box(swingtree.UI.Axis) factory method returning a Layout config object which can be passed to the style API (see UIForAnySwing.withStyle(Styler) and ComponentStyleDelegate.layout(Layout)).

See Also:
  • Enum Constant Details

    • HORIZONTAL

      public static final UI.Axis HORIZONTAL
      Specifies that something runs from left to right.
    • VERTICAL

      public static final UI.Axis VERTICAL
      Specifies that something runs from top to bottom.
    • LINE

      public static final UI.Axis LINE
      Specifies that something runs in the direction of a line of text, as determined by the target container's ComponentOrientation. That direction is always the horizontal one: ComponentOrientation is a final class offering three constants, LEFT_TO_RIGHT, RIGHT_TO_LEFT and UNKNOWN, and all three report ComponentOrientation.isHorizontal() as true. So resolve() answers HORIZONTAL here, and a BoxLayout is the one place which still tells the two apart: given LINE it places the children from right to left when the container reads right to left.
    • PAGE

      public static final UI.Axis PAGE
      Specifies that something runs in the direction that lines follow each other down a page, as determined by the target container's ComponentOrientation. Every one of the three orientations runs its lines of text horizontally, which leaves its pages running vertically, so resolve() answers VERTICAL here. A BoxLayout is the one place which still tells the two apart: given PAGE it mirrors the horizontal alignment of the stacked children when the container reads right to left.
  • Method Details

    • values

      public static UI.Axis[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static UI.Axis valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • resolve

      public UI.Axis resolve()
      Reduces this axis to the one of HORIZONTAL or VERTICAL it selects, which is what a JSlider or a JSeparator needs, because neither of them has a reading direction to honour.

      No orientation has to be passed in to do this: ComponentOrientation is a final class offering three constants, and all three run their lines of text horizontally, so LINE is a horizontal axis under every one of them.

      Returns:
      HORIZONTAL for HORIZONTAL and LINE, VERTICAL for VERTICAL and PAGE.
    • isHorizontal

      public boolean isHorizontal()
      Tells whether this axis runs from side to side rather than from top to bottom.
      Returns:
      True for HORIZONTAL and LINE, false for VERTICAL and PAGE.
    • perpendicular

      public UI.Axis perpendicular()
      Returns the axis at a right angle to this one, so that code holding one axis in a variable can name the other without spelling out both constants. A JSplitPane laid out along HORIZONTAL puts its two components side by side, which makes the divider between them a vertical bar.
      Returns:
      VERTICAL for HORIZONTAL and LINE, HORIZONTAL for VERTICAL and PAGE.
    • forBoxLayout

      public int forBoxLayout()
      Converts this axis into the constant a BoxLayout expects. A box layout is the one place which still tells LINE and PAGE apart from HORIZONTAL and VERTICAL, so this method keeps all four apart rather than resolving them the way resolve() does.
      Returns:
      BoxLayout.X_AXIS for HORIZONTAL, BoxLayout.Y_AXIS for VERTICAL, BoxLayout.LINE_AXIS for LINE and BoxLayout.PAGE_AXIS for PAGE.