Class ResponsiveGridFlowLayout

java.lang.Object
swingtree.layout.ResponsiveGridFlowLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2

public final class ResponsiveGridFlowLayout extends Object implements LayoutManager2
A flow layout arranges components in a directional flow, much like lines of text in a paragraph.
  • Constructor Details

    • ResponsiveGridFlowLayout

      public ResponsiveGridFlowLayout()
      Constructs a new FlowLayout with a centered alignment and a default 5-unit horizontal and vertical gap.
    • ResponsiveGridFlowLayout

      public ResponsiveGridFlowLayout(UI.HorizontalAlignment align)
      Constructs a new FlowLayout with the specified alignment and a default 5-unit horizontal and vertical gap. The value of the alignment argument must be one of FlowLayout.LEFT, FlowLayout.RIGHT, FlowLayout.CENTER, FlowLayout.LEADING, or FlowLayout.TRAILING.
      Parameters:
      align - the alignment value
    • ResponsiveGridFlowLayout

      public ResponsiveGridFlowLayout(UI.HorizontalAlignment align, int horizontalGapSize, int verticalGapSize)
      Creates a new flow layout manager with the indicated alignment and the indicated horizontal and vertical gaps.

      The value of the alignment argument must be one of UI.HorizontalAlignment.LEFT, UI.HorizontalAlignment.RIGHT, UI.HorizontalAlignment.CENTER, UI.HorizontalAlignment.LEADING, or UI.HorizontalAlignment.TRAILING.

      Parameters:
      align - the alignment value
      horizontalGapSize - the horizontal gap between components and between the components and the borders of the Container
      verticalGapSize - the vertical gap between components and between the components and the borders of the Container
  • Method Details

    • getAlignment

      public UI.HorizontalAlignment getAlignment()
      Returns:
      the alignment value for this layout
      See Also:
    • setAlignment

      public void setAlignment(UI.HorizontalAlignment align)
      Parameters:
      align - one of the alignment values shown above
      See Also:
    • horizontalGapSize

      public int horizontalGapSize()
      Gets the horizontal gap between components and between the components and the borders of the Container
      Returns:
      the horizontal gap between components and between the components and the borders of the Container
      See Also:
    • setHorizontalGapSize

      public void setHorizontalGapSize(int size)
      Sets the horizontal gap between components and between the components and the borders of the Container.
      Parameters:
      size - the horizontal gap between components and between the components and the borders of the Container
      See Also:
    • verticalGapSize

      public int verticalGapSize()
      Gets the vertical gap between components and between the components and the borders of the Container.
      Returns:
      the vertical gap between components and between the components and the borders of the Container
      See Also:
    • setVerticalGapSize

      public void setVerticalGapSize(int size)
      Sets the vertical gap between components and between the components and the borders of the Container.
      Parameters:
      size - the vertical gap between components and between the components and the borders of the Container
      See Also:
    • setAlignOnBaseline

      public void setAlignOnBaseline(boolean alignOnBaseline)
      Sets whether or not components should be vertically aligned along their baseline. Components that do not have a baseline will be centered. The default is false.
      Parameters:
      alignOnBaseline - whether or not components should be vertically aligned on their baseline
    • getAlignOnBaseline

      public boolean getAlignOnBaseline()
      Returns true if components are to be vertically aligned along their baseline. The default is false.
      Returns:
      true if components are to be vertically aligned along their baseline
    • addLayoutComponent

      public void addLayoutComponent(String name, Component comp)
      Adds the specified component to the layout. Not used by this class.
      Specified by:
      addLayoutComponent in interface LayoutManager
      Parameters:
      name - the name of the component
      comp - the component to be added
    • removeLayoutComponent

      public void removeLayoutComponent(Component comp)
      Removes the specified component from the layout. Not used by this class.
      Specified by:
      removeLayoutComponent in interface LayoutManager
      Parameters:
      comp - the component to remove
      See Also:
    • preferredLayoutSize

      public Dimension preferredLayoutSize(Container target)
      Returns the preferred dimensions for this layout given the visible components in the specified target container.
      Specified by:
      preferredLayoutSize in interface LayoutManager
      Parameters:
      target - the container that needs to be laid out
      Returns:
      the preferred dimensions to lay out the subcomponents of the specified container
      See Also:
    • preferredLayoutSizeAtWidth

      public Dimension preferredLayoutSizeAtWidth(Container target, int width)
      Returns the size this layout would like to have if its target container were width pixels wide.

      This layout wraps its children into rows, which makes it a width-for-height layout: the height it needs is a function of the width it is given, and it cannot be expressed as a single fixed number. A parent container which itself decides the width of this layout's target must therefore ask this method rather than preferredLayoutSize(Container), because at the time it asks, the target still has the width of the previous layout pass.

      The returned width does not depend on width: it is the "ideal" width of a single row holding all children, raised to the explicitly set preferred width of the target if there is one and it is larger. Only the height varies with width.

      Mind that the returned width is not necessarily the reference width against which the ParentSizeClass of the children is measured. That reference is the explicitly set preferred width whenever there is one, even when it is smaller than the ideal single row width — which is exactly how a nested grid keeps its own size categories usable without imposing its single row width on the grid it sits in. An explicitly set preferred size therefore acts as a lower bound on the returned size and, independently of that, as the reference width.

      Parameters:
      target - The container whose layout size should be computed.
      width - The width the container is assumed to have, where a value of 0 or less means that no width is known yet, in which case the children are assumed to fit into a single row.
      Returns:
      The preferred size of the given container at the given width.
    • minimumLayoutSize

      public Dimension minimumLayoutSize(Container target)
      Returns the minimum dimensions needed to layout the visible components contained in the specified target container.
      Specified by:
      minimumLayoutSize in interface LayoutManager
      Parameters:
      target - the container that needs to be laid out
      Returns:
      the minimum dimensions to lay out the subcomponents of the specified container
      See Also:
    • layoutContainer

      public void layoutContainer(Container target)
      Lays out the container. This method lets each visible component take its preferred size by reshaping the components in the target container in order to satisfy the alignment of this layout manager.
      Specified by:
      layoutContainer in interface LayoutManager
      Parameters:
      target - the specified component being laid out
      See Also:
    • toString

      public String toString()
      Returns a string representation of this FlowLayout object and its values.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this layout
    • addLayoutComponent

      public void addLayoutComponent(Component comp, Object constraints)
      Specified by:
      addLayoutComponent in interface LayoutManager2
    • maximumLayoutSize

      public Dimension maximumLayoutSize(Container target)
      Specified by:
      maximumLayoutSize in interface LayoutManager2
    • 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
    • cellFromCellConf

      public Optional<swingtree.layout.ResponsiveGridFlowLayout.Cell> cellFromCellConf(Component parent, FlowCell flowCell, Component child, AtomicInteger componentCounter, int maxWidth, int generalMaxWidth)