java.lang.Object
net.miginfocom.layout.Grid
Holds components in a grid. Does most of the logic behind the layout manager.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
A simple representation of a cell in the grid.private final class
Wraps aComponent
together with its constraint.private static final class
private static class
A number of component wraps that share a layout "something" in one dimensionprivate static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ArrayList
<LayoutCallback> private final AC
The row and column specifications.private Grid.FlowSizeSpec
The in the constructor calculated min/pref/max sizes of the rows and columns.private final ArrayList<Grid.LinkedDimGroup>[]
Components that are connections in one dimension (such as baseline alignment for instance) are grouped together and stored here.The size of the grid.private final ContainerWrapper
The parent that is layout out and this grid is done for.private ArrayList
<int[]> If debug is on contains the bounds for things to paint when callingContainerWrapper.paintDebugCell(int, int, int, int)
private static final CC
Used for components that doesn't have a CC set.private static final DimConstraint
private final int
private final int
private static final ResizeConstraint
A constraint used for gaps.private static final ResizeConstraint
private final LinkedHashMap
<Integer, Grid.Cell> An x, y array implemented as a sparse array to accommodate for any grid size without wasting memory (or rather 15 bit (0-MAX_GRID * 0-MAX_GRID).private static final Float[]
private int[]
The in the constructor calculated min/pref/max size of the whole grid.private int
private int
private final LC
The constraints.If any of the absolute coordinates for component bounds has links the name of the target is in this Set.private static final int
Docking components will use the grid coordinates-MAX_DOCK_GRID -> 0
andMAX_GRID -> MAX_DOCK_GRID
.private static final int
This is the maximum grid position for "normal" components.private static WeakHashMap
<Object, ArrayList<Grid.WeakCell>> private static WeakHashMap<Object,
int[][]>[] private final Float[]
private final Float[]
private final AC
The row and column specifications.private Grid.FlowSizeSpec
The in the constructor calculated min/pref/max sizes of the rows and columns.private final ArrayList<Grid.LinkedDimGroup>[]
Components that are connections in one dimension (such as baseline alignment for instance) are grouped together and stored here.The size of the grid.static final boolean
private int[]
The in the constructor calculated min/pref/max size of the whole grid. -
Constructor Summary
ConstructorsConstructorDescriptionGrid
(ContainerWrapper container, LC lc, AC rowConstr, AC colConstr, Map<? extends ComponentWrapper, CC> ccMap, ArrayList<LayoutCallback> callbackList) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addDockingCell
(int[] dockInsets, int side, Grid.CompWrap cw) Adds a docking cell.private void
addLinkIDs
(CC cc) addToEndGroup
(HashMap<String, Integer> endGroups, String endGroup, int end) private static void
addToSizeGroup
(HashMap<String, int[]> sizeGroups, String sizeGroup, int[] size) private void
adjustMinPrefForSpanningComps
(DimConstraint[] specs, Float[] defPush, Grid.FlowSizeSpec fss, ArrayList<Grid.LinkedDimGroup>[] groupsLists) Adjust min/pref size for columns(or rows) that has components that spans multiple columns (or rows).private void
adjustSizeForAbsolute
(boolean isHor) Adjust grid's width or height for the absolute components' positions.private void
calcGridSizes
(int refWidth, int refHeight) private Grid.FlowSizeSpec
calcRowsOrColsSizes
(boolean isHor, int containerSize) Calculates Min, Preferred and Max size for the columns OR rows.private void
checkSizeCalcs
(int refWidth, int refHeight) private void
private static int
constrainSize
(int s) private static int
convertSpanToSparseGrid
(int curIx, int span, TreeSet<Integer> indexes) Spanning is specified in the uncompressed grid number.private static UnitValue
correctAlign
(CC cc, UnitValue rowAlign, boolean isHor, boolean fromEnd) private static void
correctMinMax
(int[] s) private ArrayList<Grid.LinkedDimGroup>[]
divideIntoLinkedGroups
(boolean isRows) For one dimension divide the component wraps into logical groups.private boolean
doAbsoluteCorrections
(Grid.CompWrap cw, int[] bounds) private void
ensureIndexSizes
(int colCount, int rowCount) private static Float[]
extractSubArray
(DimConstraint[] specs, Float[] arr, int ix, int len) private int[]
getAbsoluteDimBounds
(Grid.CompWrap cw, int refSize, boolean isHor) private static Grid.AboveBelow
getBaselineAboveBelow
(ArrayList<Grid.CompWrap> compWraps, int sType, boolean centerBaseline) private BoundSize[]
private static CC
getCC
(ComponentWrapper comp, Map<? extends ComponentWrapper, CC> ccMap) private Grid.Cell
getCell
(int r, int c) private static boolean[]
getComponentGapPush
(ArrayList<Grid.CompWrap> compWraps, boolean isHor) private static ResizeConstraint[]
getComponentResizeConstraints
(ArrayList<Grid.CompWrap> compWraps, boolean isHor) private static int[][]
getComponentSizes
(ArrayList<Grid.CompWrap> compWraps, boolean isHor) private Float[]
getDefaultPushWeights
(boolean isRows) private static int
getDockInsets
(TreeSet<Integer> set) private static int[][]
getGaps
(ArrayList<Grid.CompWrap> compWraps, boolean isHor) getGridPositions
(Object parComp) private static Grid.LinkedDimGroup
getGroupContaining
(ArrayList<Grid.LinkedDimGroup>[] groupLists, Grid.CompWrap cw) final int[]
final int[]
getHeight
(int refWidth) private int[]
getMinPrefMaxSumSize
(boolean isHor, int[][] sizes) private static int
getParentSize
(ComponentWrapper cw, boolean isHor) private UnitValue[]
getPos
(ComponentWrapper cw, CC cc) private int[][]
getRowGaps
(DimConstraint[] specs, int refSize, boolean isHor, boolean[] fillInPushGaps) Returns the row gaps in pixel sizes.private static ResizeConstraint[]
getRowResizeConstraints
(DimConstraint[] specs) (package private) static int[][]
getSizesAndIndexes
(Object parComp, boolean isRows) private static int
getTotalGroupsSizeParallel
(ArrayList<Grid.LinkedDimGroup> groups, int sType, boolean countSpanning) private static int
getTotalSizeParallel
(ArrayList<Grid.CompWrap> compWraps, int sType, boolean isHor) private static int
getTotalSizeSerial
(ArrayList<Grid.CompWrap> compWraps, int sType, boolean isHor) final int[]
getWidth()
final int[]
getWidth
(int refHeight) private boolean
hasDocks()
private int
increase
(int[] p, int cnt) Go to next cell.private void
void
If the container (parent) that this grid is laying out has changed its bounds, call this method to clear any cached values min/pref/max sizes of the components and rows/columns.private boolean
isCellFree
(int r, int c, ArrayList<int[]> occupiedRects) boolean
Does the actual layout.boolean
Deprecated.private static void
layoutBaseline
(ContainerWrapper parent, ArrayList<Grid.CompWrap> compWraps, DimConstraint dc, int start, int size, int sizeType, int spanCount) private boolean
layoutImpl
(int[] bounds, UnitValue alignX, UnitValue alignY, boolean debug, boolean trialRun) Does the actual layout.private void
layoutInOneDim
(int refSize, UnitValue align, boolean isRows, Float[] defaultPushWeights) private static void
layoutParallel
(ContainerWrapper parent, ArrayList<Grid.CompWrap> compWraps, DimConstraint dc, int start, int size, boolean isHor, boolean fromEnd) private static void
layoutSerial
(ContainerWrapper parent, ArrayList<Grid.CompWrap> compWraps, DimConstraint dc, int start, int size, boolean isHor, int spanCount, boolean fromEnd) private static int[]
mergeSizes
(int[] oldValues, int[] newValues) private static int
mergeSizes
(int oldValue, int newValue, boolean toMax) private static Grid.FlowSizeSpec
mergeSizesGapsAndResConstrs
(ResizeConstraint[] resConstr, boolean[] gapPush, int[][] minPrefMaxSizes, int[][] gapSizes) Merges sizes and gaps together with Resize Constraints.void
private static void
putSizesAndIndexes
(Object parComp, int[] sizes, int[] ixArr, boolean isRows) private void
resetLinkValues
(boolean parentSize, boolean compLinks) private static void
saveGrid
(ComponentWrapper parComp, LinkedHashMap<Integer, Grid.Cell> grid) private void
private static void
setCompWrapBounds
(ContainerWrapper parent, int[][] sizes, ArrayList<Grid.CompWrap> compWraps, UnitValue rowAlign, int start, int size, boolean isHor, boolean fromEnd) private static void
setCompWrapBounds
(ContainerWrapper parent, int[] allSizes, ArrayList<Grid.CompWrap> compWraps, UnitValue rowAlign, int start, int size, boolean isHor, boolean fromEnd) private boolean
setLinkedBounds
(ComponentWrapper cw, CC cc, int x, int y, int w, int h, boolean external) private static void
sortCellsByPlatform
(Collection<Grid.Cell> cells, ContainerWrapper parent) Sort components (normally buttons in a button bar) so they appear in the correct order.private void
Wraps to the next row or column depending on if horizontal flow or vertical flow is used.
-
Field Details
-
TEST_GAPS
public static final boolean TEST_GAPS- See Also:
-
GROW_100
-
DOCK_DIM_CONSTRAINT
-
MAX_GRID
private static final int MAX_GRIDThis is the maximum grid position for "normal" components. Docking components use the space out toMAX_DOCK_GRID
and below 0.- See Also:
-
MAX_DOCK_GRID
private static final int MAX_DOCK_GRIDDocking components will use the grid coordinates-MAX_DOCK_GRID -> 0
andMAX_GRID -> MAX_DOCK_GRID
.- See Also:
-
GAP_RC_CONST
A constraint used for gaps. -
GAP_RC_CONST_PUSH
-
DEF_CC
Used for components that doesn't have a CC set. Not that it's really really important that the CC is never changed in this Grid class. -
lc
The constraints. Nevernull
. -
container
The parent that is layout out and this grid is done for. Nevernull
. -
grid
An x, y array implemented as a sparse array to accommodate for any grid size without wasting memory (or rather 15 bit (0-MAX_GRID * 0-MAX_GRID). -
wrapGapMap
-
rowIndexes
The size of the grid. Row count and column count. -
colIndexes
The size of the grid. Row count and column count. -
rowConstr
The row and column specifications. -
colConstr
The row and column specifications. -
colFlowSpecs
The in the constructor calculated min/pref/max sizes of the rows and columns. -
rowFlowSpecs
The in the constructor calculated min/pref/max sizes of the rows and columns. -
colGroupLists
Components that are connections in one dimension (such as baseline alignment for instance) are grouped together and stored here. One for each row/column. -
rowGroupLists
Components that are connections in one dimension (such as baseline alignment for instance) are grouped together and stored here. One for each row/column. -
width
private int[] widthThe in the constructor calculated min/pref/max size of the whole grid. -
height
private int[] heightThe in the constructor calculated min/pref/max size of the whole grid. -
debugRects
If debug is on contains the bounds for things to paint when callingContainerWrapper.paintDebugCell(int, int, int, int)
-
linkTargetIDs
If any of the absolute coordinates for component bounds has links the name of the target is in this Set. Since it requires some memory and computations this is checked at the creation so that the link information is only created if needed later.The boolean is true for groups id:s and null for normal id:s.
-
dockOffY
private final int dockOffY -
dockOffX
private final int dockOffX -
pushXs
-
pushYs
-
callbackList
-
lastRefWidth
private int lastRefWidth -
lastRefHeight
private int lastRefHeight -
PARENT_ROWCOL_SIZES_MAP
-
PARENT_GRIDPOS_MAP
-
-
Constructor Details
-
Grid
public Grid(ContainerWrapper container, LC lc, AC rowConstr, AC colConstr, Map<? extends ComponentWrapper, CC> ccMap, ArrayList<LayoutCallback> callbackList) Constructor.- Parameters:
container
- The container that will be laid out.lc
- The form flow constraints.rowConstr
- The rows specifications. If more cell rows are required, the last element will be used for when there is no corresponding element in this array.colConstr
- The columns specifications. If more cell rows are required, the last element will be used for when there is no corresponding element in this array.ccMap
- The map containing the parsed constraints for each child component ofparent
. Will not be altered. Can have null CC which will use a common cached one.callbackList
- A list of callbacks ornull
if none. Will not be altered.
-
-
Method Details
-
ensureIndexSizes
private void ensureIndexSizes(int colCount, int rowCount) -
getCC
-
addLinkIDs
-
invalidateContainerSize
public void invalidateContainerSize()If the container (parent) that this grid is laying out has changed its bounds, call this method to clear any cached values min/pref/max sizes of the components and rows/columns.If any component can have changed cell the grid needs to be recreated.
-
invalidateComponentSizes
private void invalidateComponentSizes() -
layout
public boolean layout(int[] bounds, UnitValue alignX, UnitValue alignY, boolean debug, boolean notUsed) Deprecated.since 5.0 Last boolean is not needed and is gotten from the newComponentWrapper.getContentBias()
instead; -
layout
Does the actual layout. Uses many values calculated in the constructor.- Parameters:
bounds
- The bounds to layout against. Normally that of the parent. [x, y, width, height].alignX
- The alignment for the x-axis. Can be null.alignY
- The alignment for the y-axis. Can be null.debug
- If debug information should be saved indebugRects
.- Returns:
- If the layout has changed the preferred size and there is need for a new layout. This can happen if one or more components
in the grid has a content bias according to
ComponentWrapper.getContentBias()
. - Since:
- 5.0
-
layoutImpl
private boolean layoutImpl(int[] bounds, UnitValue alignX, UnitValue alignY, boolean debug, boolean trialRun) Does the actual layout. Uses many values calculated in the constructor.- Parameters:
bounds
- The bounds to layout against. Normally that of the parent. [x, y, width, height].alignX
- The alignment for the x-axis. Can be null.alignY
- The alignment for the y-axis. Can be null.debug
- If debug information should be saved indebugRects
.trialRun
- If true the bounds calculated will not be transferred to the components. Only the internal size of the components will be calculated.- Returns:
- If the layout has changed the preferred size and there is need for a new layout. This can happen if one or more components
in the grid has a content bias according to
ComponentWrapper.getContentBias()
. - Since:
- 5.0
-
paintDebug
public void paintDebug() -
getContainer
-
getWidth
public final int[] getWidth() -
getWidth
public final int[] getWidth(int refHeight) -
getHeight
public final int[] getHeight() -
getHeight
public final int[] getHeight(int refWidth) -
checkSizeCalcs
private void checkSizeCalcs(int refWidth, int refHeight) -
calcGridSizes
private void calcGridSizes(int refWidth, int refHeight) -
getPos
-
getCallbackSize
-
getDockInsets
-
setLinkedBounds
private boolean setLinkedBounds(ComponentWrapper cw, CC cc, int x, int y, int w, int h, boolean external) - Parameters:
cw
- Nevernull
.cc
- Nevernull
.external
- The bounds should be stored even if they are not inlinkTargetIDs
.- Returns:
- If a change has been made.
-
increase
private int increase(int[] p, int cnt) Go to next cell.- Parameters:
p
- The point to increasecnt
- How many cells to advance.- Returns:
- The new value in the "increasing" dimension.
-
wrap
Wraps to the next row or column depending on if horizontal flow or vertical flow is used.- Parameters:
cellXY
- The point to wrap and thus set either x or y to 0 and increase the other one.gapSize
- The gaps size specified in a "wrap XXX" or "newline XXX" ornull
if none.
-
sortCellsByPlatform
Sort components (normally buttons in a button bar) so they appear in the correct order.- Parameters:
cells
- The cells to sort.parent
- The parent.
-
getDefaultPushWeights
-
clearGroupLinkBounds
private void clearGroupLinkBounds() -
resetLinkValues
private void resetLinkValues(boolean parentSize, boolean compLinks) -
getGroupContaining
private static Grid.LinkedDimGroup getGroupContaining(ArrayList<Grid.LinkedDimGroup>[] groupLists, Grid.CompWrap cw) - Parameters:
groupLists
- The lists to search in.cw
- The component wrap to find.- Returns:
- The linked group or
null
if none had the component wrap.
-
doAbsoluteCorrections
-
adjustSizeForAbsolute
private void adjustSizeForAbsolute(boolean isHor) Adjust grid's width or height for the absolute components' positions. -
getAbsoluteDimBounds
-
layoutInOneDim
-
addToSizeGroup
-
addToEndGroup
-
calcRowsOrColsSizes
Calculates Min, Preferred and Max size for the columns OR rows.- Parameters:
isHor
- If it is the horizontal dimension to calculate.containerSize
- The reference container size in the dimension. If invalid input: '<'= 0 it will be replaced by the actual container's size.- Returns:
- The sizes in a
Grid.FlowSizeSpec
.
-
getParentSize
-
getMinPrefMaxSumSize
private int[] getMinPrefMaxSumSize(boolean isHor, int[][] sizes) -
getRowResizeConstraints
-
getComponentResizeConstraints
private static ResizeConstraint[] getComponentResizeConstraints(ArrayList<Grid.CompWrap> compWraps, boolean isHor) -
getComponentGapPush
-
getRowGaps
private int[][] getRowGaps(DimConstraint[] specs, int refSize, boolean isHor, boolean[] fillInPushGaps) Returns the row gaps in pixel sizes. One more than there arespecs
sent in.- Parameters:
specs
-refSize
-isHor
-fillInPushGaps
- If the gaps are pushing. NOTE! this argument will be filled in and thus changed!- Returns:
- The row gaps in pixel sizes. One more than there are
specs
sent in.
-
getGaps
-
hasDocks
private boolean hasDocks() -
adjustMinPrefForSpanningComps
private void adjustMinPrefForSpanningComps(DimConstraint[] specs, Float[] defPush, Grid.FlowSizeSpec fss, ArrayList<Grid.LinkedDimGroup>[] groupsLists) Adjust min/pref size for columns(or rows) that has components that spans multiple columns (or rows).- Parameters:
specs
- The specs for the columns or rows. Last index will be used ifcount
is greater than this array's length.defPush
- The default grow weight if the specs does not have anyone that will grow. Comes from "push" in the CC.fss
-groupsLists
-
-
divideIntoLinkedGroups
For one dimension divide the component wraps into logical groups. One group for component wraps that share a common something, line the property to layout by base line.- Parameters:
isRows
- If rows, and not columns, are to be divided.- Returns:
- One
ArrayList
for every row/column.
-
convertSpanToSparseGrid
Spanning is specified in the uncompressed grid number. They can for instance be more than 60000 for the outer edge dock grid cells. When the grid is compressed and indexed after only the cells that area occupied the span is erratic. This method use the row/col indexes and corrects the span to be correct for the compressed grid.- Parameters:
span
- The span in the uncompressed grid.LayoutUtil.INF
will be interpreted to span the rest of the column/row excluding the surrounding docking components.indexes
- The indexes in the correct dimension.- Returns:
- The converted span.
-
isCellFree
-
getCell
-
setCell
-
addDockingCell
Adds a docking cell. That cell is outside the normal cell indexes.- Parameters:
dockInsets
- The current dock insets. Will be updated!side
- top == 0, left == 1, bottom = 2, right = 3.cw
- The compwrap to put in a cell and add.
-
layoutBaseline
private static void layoutBaseline(ContainerWrapper parent, ArrayList<Grid.CompWrap> compWraps, DimConstraint dc, int start, int size, int sizeType, int spanCount) -
layoutSerial
private static void layoutSerial(ContainerWrapper parent, ArrayList<Grid.CompWrap> compWraps, DimConstraint dc, int start, int size, boolean isHor, int spanCount, boolean fromEnd) -
setCompWrapBounds
private static void setCompWrapBounds(ContainerWrapper parent, int[] allSizes, ArrayList<Grid.CompWrap> compWraps, UnitValue rowAlign, int start, int size, boolean isHor, boolean fromEnd) -
layoutParallel
private static void layoutParallel(ContainerWrapper parent, ArrayList<Grid.CompWrap> compWraps, DimConstraint dc, int start, int size, boolean isHor, boolean fromEnd) -
setCompWrapBounds
private static void setCompWrapBounds(ContainerWrapper parent, int[][] sizes, ArrayList<Grid.CompWrap> compWraps, UnitValue rowAlign, int start, int size, boolean isHor, boolean fromEnd) -
correctAlign
-
getBaselineAboveBelow
private static Grid.AboveBelow getBaselineAboveBelow(ArrayList<Grid.CompWrap> compWraps, int sType, boolean centerBaseline) -
getTotalSizeParallel
private static int getTotalSizeParallel(ArrayList<Grid.CompWrap> compWraps, int sType, boolean isHor) -
getTotalSizeSerial
-
getTotalGroupsSizeParallel
private static int getTotalGroupsSizeParallel(ArrayList<Grid.LinkedDimGroup> groups, int sType, boolean countSpanning) -
getComponentSizes
- Parameters:
compWraps
-isHor
-- Returns:
- Might contain LayoutUtil.NOT_SET
-
mergeSizesGapsAndResConstrs
private static Grid.FlowSizeSpec mergeSizesGapsAndResConstrs(ResizeConstraint[] resConstr, boolean[] gapPush, int[][] minPrefMaxSizes, int[][] gapSizes) Merges sizes and gaps together with Resize Constraints. For gapsGAP_RC_CONST
is used.- Parameters:
resConstr
- One resize constraint for every row/component. Can be lesser in length and the last element should be used for missing elements.gapPush
- If the corresponding gap should be considered pushing and thus want to take free space if left over. Should be one more than resConstrs!minPrefMaxSizes
- The sizes (min/pref/max) for every row/component.gapSizes
- The gaps before and after each row/component packed in one double sized array.- Returns:
- A holder for the merged values.
-
mergeSizes
private static int[] mergeSizes(int[] oldValues, int[] newValues) -
mergeSizes
private static int mergeSizes(int oldValue, int newValue, boolean toMax) -
constrainSize
private static int constrainSize(int s) -
correctMinMax
private static void correctMinMax(int[] s) -
extractSubArray
-
putSizesAndIndexes
-
getSizesAndIndexes
-
saveGrid
-
getGridPositions
-
ComponentWrapper.getContentBias()
instead;