Class FlowCellConf
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 TypeMethodDescriptionalign(UI.VerticalAlignment alignment) TheUI.VerticalAlignmentof a flow cell tells theResponsiveGridFlowLayouthow to place the component vertically within the cell.
So if you want the component to be aligned at the top, useUI.VerticalAlignment.TOP, if you want it to be centered, useUI.VerticalAlignment.CENTER, and if you want it to be aligned at the bottom, useUI.VerticalAlignment.BOTTOM.booleanfill(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 totrue, 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!inthashCode()large(int span) Returns a new and updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.LARGE.
A parent container is considered "large" if its width is between 3/5 and 4/5 of its preferred width.intReturns the maximum number of cells that a component can span in a grid layout managed by aResponsiveGridFlowLayout.
The default value is 12, which is the maximum number of cells in a row of theResponsiveGridFlowLayout.medium(int span) Returns a new and updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.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 updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.OVERSIZE.
A parent container is considered "oversize" if its width is greater than its preferred width.Returns theSizeobject that represents the parent container's size.Returns theParentSizeClasscategory 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 updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.SMALL.
A parent container is considered "small" if its width is between 1/5 and 2/5 of its preferred width.toString()veryLarge(int span) Returns a new and updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.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 updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.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 updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill for a givenParentSizeClasscategory.
-
Method Details
-
maxCellsToFill
public int maxCellsToFill()Returns the maximum number of cells that a component can span in a grid layout managed by aResponsiveGridFlowLayout.
The default value is 12, which is the maximum number of cells in a row of theResponsiveGridFlowLayout. You may use this value to respond to it dynamically in theConfigurator.- Returns:
- The maximum number of cells that a component can span in a grid layout.
-
parentSize
Returns theSizeobject 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
Returns theParentSizeClasscategory 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
ParentSizeClasscategory 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, andParentSizeClass.OVERSIZEif it is significantly larger.- Returns:
- The category of the parent container's size.
-
with
Returns a new and updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill for a givenParentSizeClasscategory.- Parameters:
size- TheParentSizeClasscategory to set.cellsToFill- The number of cells to fill.- Returns:
- A new
FlowCellConfinstance with the givenParentSizeClassand number of cells to fill.
-
verySmall
Returns a new and updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.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 ofmaxCellsToFill()number of cells horizontally.- Returns:
- A new
FlowCellConfinstance with the given number of cells to fill for theParentSizeClass.VERY_SMALLcategory.
-
small
Returns a new and updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.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 ofmaxCellsToFill()number of cells horizontally.- Returns:
- A new
FlowCellConfinstance with the given number of cells to fill for theParentSizeClass.SMALLcategory.
-
medium
Returns a new and updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.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 ofmaxCellsToFill()number of cells horizontally.- Returns:
- A new
FlowCellConfinstance with the given number of cells to fill for theParentSizeClass.MEDIUMcategory.
-
large
Returns a new and updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.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 ofmaxCellsToFill()number of cells horizontally.- Returns:
- A new
FlowCellConfinstance with the given number of cells to fill for theParentSizeClass.LARGEcategory.
-
veryLarge
Returns a new and updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.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 ofmaxCellsToFill()number of cells horizontally.- Returns:
- A new
FlowCellConfinstance with the given number of cells to fill for theParentSizeClass.VERY_LARGEcategory.
-
oversize
Returns a new and updatedFlowCellConfinstance with an additionalFlowCellSpanPolicythat specifies the number of cells to fill when the parent container is categorized asParentSizeClass.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 ofmaxCellsToFill()number of cells horizontally.- Returns:
- A new
FlowCellConfinstance with the given number of cells to fill for theParentSizeClass.OVERSIZEcategory.
-
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 totrue, 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
FlowCellConfinstance with the given fill flag.
-
align
TheUI.VerticalAlignmentof a flow cell tells theResponsiveGridFlowLayouthow to place the component vertically within the cell.
So if you want the component to be aligned at the top, useUI.VerticalAlignment.TOP, if you want it to be centered, useUI.VerticalAlignment.CENTER, and if you want it to be aligned at the bottom, useUI.VerticalAlignment.BOTTOM.- Parameters:
alignment- The vertical alignment of the component within the cell.- Returns:
- A new
FlowCellConfinstance with the given vertical alignment policy.
-
toString
-
equals
-
hashCode
public int hashCode()
-