Class FlowCellConf

java.lang.Object
swingtree.layout.FlowCellConf

@Immutable public final class FlowCellConf extends Object
An immutable configuration object used to define how a FlowCell should place its associated component within a ResponsiveGridFlowLayout.
Instances of this are passed to the Configurator of a FlowCell so that you can dynamically assign the number of cells a component should span, based on the size category of the parent container.

Use UILayoutConstants.AUTO_SPAN(Configurator) to create a FlowCell from a Configurator and pass it to the UIForAnySwing.add(AddConstraint, UIForAnySwing[]) of a SwingTree UI declaration.
Here an example demonstrating how this might be used:

    UI.panel().withPrefSize(400, 300)
    .withFlowLayout()
    .add(UI.AUTO_SPAN( it->it.small(12).medium(6).large(8) ),
         html("A red cell").withStyle(it->it
             .backgroundColor(UI.Color.RED)
         )
    )
    .add(UI.AUTO_SPAN( it->it.small(12).medium(6).large(4) ),
         html("a green cell").withStyle(it->it
             .backgroundColor(Color.GREEN)
         )
    )
  
In the above example, the it parameter of the Configurator is an instance of this class. The Configurator is called every time the ResponsiveGridFlowLayout updates the layout of the parent container, so that the number of cells a component spans can be adjusted dynamically.
The UIForAnySwing.withFlowLayout() creates a ResponsiveGridFlowLayout and attaches it to the panel.

Note that the FlowCell configuration may only take effect if the parent container has a ResponsiveGridFlowLayout as a LayoutManager installed.

Besides configuring the number of cells to span, you can also define how the cell should be filled vertically by the component and how the component should be aligned vertically within the cell.
Use the fill(boolean) method to set the fill flag to true if you want the component to fill the cell vertically.
Use the align(UI.VerticalAlignment) method to set the vertical alignment of the component within the cell to either UI.VerticalAlignment.TOP, UI.VerticalAlignment.CENTER, or UI.VerticalAlignment.BOTTOM.

  • Method Summary

    Modifier and Type
    Method
    Description
    The UI.VerticalAlignment of a flow cell tells the ResponsiveGridFlowLayout how to place the component vertically within the cell.
    So if you want the component to be aligned at the top, use UI.VerticalAlignment.TOP, if you want it to be centered, use UI.VerticalAlignment.CENTER, and if you want it to be aligned at the bottom, use UI.VerticalAlignment.BOTTOM.
    boolean
     
    fill(boolean fill)
    This flag defines how the grid cell in the flow layout should be filled by the component to which this cell configuration belongs.
    The default behavior is to not fill the cell, but rather to align the component vertically in the center of the cell and use the component's preferred height.
    If this flag is set to true, the component will fill the cell vertically and use the full height of the cell, which is also the full height of the row.
    Note that this will ignore the component's preferred height!
    int
     
    large(int span)
    Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.LARGE.
    A parent container is considered "large" if its width is between 3/5 and 4/5 of its preferred width.
    int
    Returns the maximum number of cells that a component can span in a grid layout managed by a ResponsiveGridFlowLayout.
    The default value is 12, which is the maximum number of cells in a row of the ResponsiveGridFlowLayout.
    medium(int span)
    Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.MEDIUM.
    A parent container is considered "medium" if its width is between 2/5 and 3/5 of its preferred width.
    oversize(int span)
    Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.OVERSIZE.
    A parent container is considered "oversize" if its width is greater than its preferred width.
    Returns the Size object that represents the parent container's size.
    Returns the ParentSizeClass category that represents the parent container's width relative to its preferred width.
    The cell exposes this information so that you can use for a more informed decision on how many cells a component should span.
    small(int span)
    Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.SMALL.
    A parent container is considered "small" if its width is between 1/5 and 2/5 of its preferred width.
     
    veryLarge(int span)
    Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.VERY_LARGE.
    A parent container is considered "very large" if its width is between 4/5 and 5/5 of its preferred width.
    verySmall(int span)
    Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.VERY_SMALL.
    A parent container is considered "very small" if its width is between 0/5 and 1/5 of its preferred width.
    with(ParentSizeClass size, int cellsToFill)
    Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill for a given ParentSizeClass category.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • maxCellsToFill

      public int maxCellsToFill()
      Returns the maximum number of cells that a component can span in a grid layout managed by a ResponsiveGridFlowLayout.
      The default value is 12, which is the maximum number of cells in a row of the ResponsiveGridFlowLayout. You may use this value to respond to it dynamically in the Configurator.
      Returns:
      The maximum number of cells that a component can span in a grid layout.
    • parentSize

      public Size parentSize()
      Returns the Size object that represents the parent container's size. The cell exposes this information so that you can use for a more informed decision on how many cells a component should span.
      Returns:
      The width and height of the parent container of the component associated with this cell span configuration.
    • parentSizeCategory

      public ParentSizeClass parentSizeCategory()
      Returns the ParentSizeClass category that represents the parent container's width relative to its preferred width.
      The cell exposes this information so that you can use for a more informed decision on how many cells a component should span.

      The ParentSizeClass category is calculated by dividing the parent container's width by the preferred width of the parent container.
      So a parent container is considered large if its size is close to the preferred size, and ParentSizeClass.OVERSIZE if it is significantly larger.

      Returns:
      The category of the parent container's size.
    • with

      public FlowCellConf with(ParentSizeClass size, int cellsToFill)
      Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill for a given ParentSizeClass category.
      Parameters:
      size - The ParentSizeClass category to set.
      cellsToFill - The number of cells to fill.
      Returns:
      A new FlowCellConf instance with the given ParentSizeClass and number of cells to fill.
    • verySmall

      public FlowCellConf verySmall(int span)
      Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.VERY_SMALL.
      A parent container is considered "very small" if its width is between 0/5 and 1/5 of its preferred width.

      The supplied number of cells to fill should be in the inclusive range of 0 to maxCellsToFill().
      Values outside this range will be clamped to the nearest valid value and a warning will be logged.

      Parameters:
      span - The number of cells to span as part of a grid with a total of maxCellsToFill() number of cells horizontally.
      Returns:
      A new FlowCellConf instance with the given number of cells to fill for the ParentSizeClass.VERY_SMALL category.
    • small

      public FlowCellConf small(int span)
      Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.SMALL.
      A parent container is considered "small" if its width is between 1/5 and 2/5 of its preferred width.

      The supplied number of cells to fill should be in the inclusive range of 0 to maxCellsToFill().
      Values outside this range will be clamped to the nearest valid value and a warning will be logged.

      Parameters:
      span - The number of cells to span as part of a grid with a total of maxCellsToFill() number of cells horizontally.
      Returns:
      A new FlowCellConf instance with the given number of cells to fill for the ParentSizeClass.SMALL category.
    • medium

      public FlowCellConf medium(int span)
      Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.MEDIUM.
      A parent container is considered "medium" if its width is between 2/5 and 3/5 of its preferred width.

      The supplied number of cells to fill should be in the inclusive range of 0 to maxCellsToFill().
      Values outside this range will be clamped to the nearest valid value and a warning will be logged.

      Parameters:
      span - The number of cells to span as part of a grid with a total of maxCellsToFill() number of cells horizontally.
      Returns:
      A new FlowCellConf instance with the given number of cells to fill for the ParentSizeClass.MEDIUM category.
    • large

      public FlowCellConf large(int span)
      Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.LARGE.
      A parent container is considered "large" if its width is between 3/5 and 4/5 of its preferred width.

      The supplied number of cells to fill should be in the inclusive range of 0 to maxCellsToFill().
      Values outside this range will be clamped to the nearest valid value and a warning will be logged.

      Parameters:
      span - The number of cells to span as part of a grid with a total of maxCellsToFill() number of cells horizontally.
      Returns:
      A new FlowCellConf instance with the given number of cells to fill for the ParentSizeClass.LARGE category.
    • veryLarge

      public FlowCellConf veryLarge(int span)
      Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.VERY_LARGE.
      A parent container is considered "very large" if its width is between 4/5 and 5/5 of its preferred width.

      The supplied number of cells to fill should be in the inclusive range of 0 to maxCellsToFill().
      Values outside this range will be clamped to the nearest valid value and a warning will be logged.

      Parameters:
      span - The number of cells to span as part of a grid with a total of maxCellsToFill() number of cells horizontally.
      Returns:
      A new FlowCellConf instance with the given number of cells to fill for the ParentSizeClass.VERY_LARGE category.
    • oversize

      public FlowCellConf oversize(int span)
      Returns a new and updated FlowCellConf instance with an additional FlowCellSpanPolicy that specifies the number of cells to fill when the parent container is categorized as ParentSizeClass.OVERSIZE.
      A parent container is considered "oversize" if its width is greater than its preferred width.

      The supplied number of cells to fill should be in the inclusive range of 0 to maxCellsToFill().
      Values outside this range will be clamped to the nearest valid value and a warning will be logged.

      Parameters:
      span - The number of cells to span as part of a grid with a total of maxCellsToFill() number of cells horizontally.
      Returns:
      A new FlowCellConf instance with the given number of cells to fill for the ParentSizeClass.OVERSIZE category.
    • fill

      public FlowCellConf fill(boolean fill)
      This flag defines how the grid cell in the flow layout should be filled by the component to which this cell configuration belongs.
      The default behavior is to not fill the cell, but rather to align the component vertically in the center of the cell and use the component's preferred height.
      If this flag is set to true, the component will fill the cell vertically and use the full height of the cell, which is also the full height of the row.
      Note that this will ignore the component's preferred height!
      Parameters:
      fill - Whether the cell should be filled by the component.
      Returns:
      A new FlowCellConf instance with the given fill flag.
    • align

      public FlowCellConf align(UI.VerticalAlignment alignment)
      The UI.VerticalAlignment of a flow cell tells the ResponsiveGridFlowLayout how to place the component vertically within the cell.
      So if you want the component to be aligned at the top, use UI.VerticalAlignment.TOP, if you want it to be centered, use UI.VerticalAlignment.CENTER, and if you want it to be aligned at the bottom, use UI.VerticalAlignment.BOTTOM.
      Parameters:
      alignment - The vertical alignment of the component within the cell.
      Returns:
      A new FlowCellConf instance with the given vertical alignment policy.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object