Class SBoxLayout

java.lang.Object
games.stendhal.client.gui.layout.SBoxLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2

public class SBoxLayout extends Object implements LayoutManager2
A simple layout manager that does what BoxLayout fails to do, and provides a predictable layout with few hidden interactions.

Minimum size is properly supported within reasonable limits.

Maximum size has only a soft support, i.e. maximum size works as a limiting preferred size, even if the child component itself would suggest a larger size.

Component alignment is supported in the direction perpendicular to the layout direction.

SBoxLayout supports constraints of type SLayout. A single constraint flag can passed as the second parameter to Container.add(Component c, Object constraint). Constraints can be combined using the object returned by constraint(SLayout...) as the constraints object.

  • Field Details

  • Constructor Details

    • SBoxLayout

      public SBoxLayout(boolean direction)
      Create a new SBoxLayout.
      Parameters:
      direction - layout direction
    • SBoxLayout

      public SBoxLayout(boolean direction, int padding)
      Create a new SBoxLayout with padding between components.
      Parameters:
      direction - layout direction
      padding - component padding in pixels
  • Method Details

    • constraint

      public static Object constraint(SLayout... flags)
      Create a constraints object.
      Parameters:
      flags - constraint flags
      Returns:
      constraints object
    • setPadding

      public final void setPadding(int padding)
      Set the padding between the components. Typically you should use either 0 (the default), or COMMON_PADDING for consistent look. For the padding around everything use appropriate empty border instead.
      Parameters:
      padding - pixel width of the padding
    • addLayoutComponent

      public void addLayoutComponent(Component component, Object flags)
      Specified by:
      addLayoutComponent in interface LayoutManager2
    • addLayoutComponent

      public void addLayoutComponent(String id, Component component)
      Specified by:
      addLayoutComponent in interface LayoutManager
    • getLayoutAlignmentX

      public float getLayoutAlignmentX(Container target)
      Specified by:
      getLayoutAlignmentX in interface LayoutManager2
    • getLayoutAlignmentY

      public float getLayoutAlignmentY(Container target)
      Specified by:
      getLayoutAlignmentY in interface LayoutManager2
    • invalidateLayout

      public void invalidateLayout(Container target)
      Specified by:
      invalidateLayout in interface LayoutManager2
    • layoutContainer

      public void layoutContainer(Container parent)
      Specified by:
      layoutContainer in interface LayoutManager
    • maximumLayoutSize

      public Dimension maximumLayoutSize(Container parent)
      Specified by:
      maximumLayoutSize in interface LayoutManager2
    • minimumLayoutSize

      public Dimension minimumLayoutSize(Container parent)
      Specified by:
      minimumLayoutSize in interface LayoutManager
    • preferredLayoutSize

      public Dimension preferredLayoutSize(Container parent)
      Specified by:
      preferredLayoutSize in interface LayoutManager
    • removeLayoutComponent

      public void removeLayoutComponent(Component component)
      Specified by:
      removeLayoutComponent in interface LayoutManager
    • addSpring

      public static JComponent addSpring(Container target)
      Add a utility component that expands by default, to a container using SBoxLayout. Adding it rather than just creating the component is a workaround for components not passing information about new subcomponents if the user explicitly specifies the constraints.
      Parameters:
      target - the container where to add a string to
      Returns:
      A spring with preferred dimensions 0, 0.
    • createContainer

      public static JComponent createContainer(boolean direction)
      A convenience method for creating a container using SBoxLayout.
      Parameters:
      direction - layout direction
      Returns:
      A component using SBoxLayout
    • createContainer

      public static JComponent createContainer(boolean direction, int padding)
      A convenience method for creating a container using SBoxLayout with padding between the components.
      Parameters:
      direction - layout direction
      padding - padding in pixels between the components
      Returns:
      A component using SBoxLayout