Class GridBagLayout
- All Implemented Interfaces:
com.googlecode.lanterna.gui2.LayoutManager
-
Field Summary
FieldsModifier and TypeFieldDescriptiondouble[]This field holds the overrides to the column weights.int[]This field holds the overrides to the column minimum width.This hashtable maintains the association between a component and its gridbag constraints.protected GridCellThis field holds a gridbag constraints instance containing the default values, so if a component does not have gridbag constraints associated with it, then the component will be assigned a copy of thedefaultConstraints.protected GridLayoutInfoThis field holds the layout information for the gridbag.protected static final intThis field is no longer used to reserve arrays and kept for backward compatibility.protected static final intThe smallest grid that can be laid out by the grid bag layout.protected static final intThe preferred grid size that can be laid out by the grid bag layout.int[]This field holds the overrides to the row minimum heights.double[]This field holds the overrides to the row weights. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLayoutComponent(com.googlecode.lanterna.gui2.Component comp, Object constraints) Adds the specified component to the layout, using the specifiedconstraintsobject.voidaddLayoutComponent(String name, com.googlecode.lanterna.gui2.Component comp) Has no effect, since this layout manager does not use a per-component string.protected voidadjustForGravity(GridCell constraints, Rectangle r) Adjusts the x, y, width, and height fields to the correct values depending on the constraint geometry and pads.protected voidAdjustForGravity(GridCell constraints, Rectangle r) This method is obsolete and supplied for backwards compatibility only; new code should calladjustForGravityinstead.protected voidarrangeGrid(com.googlecode.lanterna.gui2.Container parent) Lays out the grid.protected voidArrangeGrid(com.googlecode.lanterna.gui2.Container parent) This method is obsolete and supplied for backwards compatibility only; new code should callarrangeGridinstead.voiddoLayout(com.googlecode.lanterna.TerminalSize area, List<com.googlecode.lanterna.gui2.Component> components) getConstraints(com.googlecode.lanterna.gui2.Component comp) Gets the constraints for the specified component.floatgetLayoutAlignmentX(com.googlecode.lanterna.gui2.Container parent) Returns the alignment along the x axis.floatgetLayoutAlignmentY(com.googlecode.lanterna.gui2.Container parent) Returns the alignment along the y axis.int[][]Determines column widths and row heights for the layout grid.protected GridLayoutInfogetLayoutInfo(com.googlecode.lanterna.gui2.Container parent, int sizeflag) Fills in an instance ofGridBagLayoutInfofor the current set of managed children.protected GridLayoutInfoGetLayoutInfo(com.googlecode.lanterna.gui2.Container parent, int sizeflag) This method is obsolete and supplied for backwards compatibility only; new code should callgetLayoutInfoinstead.Determines the origin of the layout area, in the graphics coordinate space of the target container.double[][]Determines the weights of the layout grid's columns and rows.protected DimensiongetMinSize(com.googlecode.lanterna.gui2.Container parent, GridLayoutInfo info) Figures out the minimum size of the master based on the information fromgetLayoutInfo.protected DimensionGetMinSize(com.googlecode.lanterna.gui2.Container parent, GridLayoutInfo info) This method is obsolete and supplied for backwards compatibility only; new code should callgetMinSizeinstead.com.googlecode.lanterna.TerminalSizegetPreferredSize(List<com.googlecode.lanterna.gui2.Component> components) booleanvoidinvalidateLayout(com.googlecode.lanterna.gui2.Container target) Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.voidlayoutContainer(com.googlecode.lanterna.gui2.Container parent) Lays out the specified container using this grid bag layout.location(int x, int y) Determines which cell in the layout grid contains the point specified by(x, y).protected GridCelllookupConstraints(com.googlecode.lanterna.gui2.Component comp) Retrieves the constraints for the specified component.maximumLayoutSize(com.googlecode.lanterna.gui2.Container target) Returns the maximum dimensions for this layout given the components in the specified target container.minimumLayoutSize(com.googlecode.lanterna.gui2.Container parent) Determines the minimum size of theparentcontainer using this grid bag layout.preferredLayoutSize(com.googlecode.lanterna.gui2.Container parent) Determines the preferred size of theparentcontainer using this grid bag layout.voidremoveLayoutComponent(com.googlecode.lanterna.gui2.Component comp) Removes the specified component from this layout.voidsetConstraints(com.googlecode.lanterna.gui2.Component comp, GridCell constraints) Sets the constraints for the specified component in this layout.toString()Returns a string representation of this grid bag layout's values.
-
Field Details
-
MAXGRIDSIZE
protected static final int MAXGRIDSIZEThis field is no longer used to reserve arrays and kept for backward compatibility. Previously, this was the maximum number of grid positions (both horizontal and vertical) that could be laid out by the grid bag layout. Current implementation doesn't impose any limits on the size of a grid.- See Also:
-
MINSIZE
protected static final int MINSIZEThe smallest grid that can be laid out by the grid bag layout.- See Also:
-
PREFERREDSIZE
protected static final int PREFERREDSIZEThe preferred grid size that can be laid out by the grid bag layout.- See Also:
-
columnWidths
public int[] columnWidthsThis field holds the overrides to the column minimum width. If this field is non-nullthe values are applied to the gridbag after all of the minimum columns widths have been calculated. If columnWidths has more elements than the number of columns, columns are added to the gridbag to match the number of elements in columnWidth.- See Also:
-
rowHeights
public int[] rowHeightsThis field holds the overrides to the row minimum heights. If this field is non-nullthe values are applied to the gridbag after all of the minimum row heights have been calculated. IfrowHeightshas more elements than the number of rows, rows are added to the gridbag to match the number of elements inrowHeights.- See Also:
-
columnWeights
public double[] columnWeightsThis field holds the overrides to the column weights. If this field is non-nullthe values are applied to the gridbag after all of the columns weights have been calculated. IfcolumnWeights[i]> weight for column i, then column i is assigned the weight incolumnWeights[i]. IfcolumnWeightshas more elements than the number of columns, the excess elements are ignored - they do not cause more columns to be created. -
rowWeights
public double[] rowWeightsThis field holds the overrides to the row weights. If this field is non-nullthe values are applied to the gridbag after all of the rows weights have been calculated. IfrowWeights[i]> weight for row i, then row i is assigned the weight inrowWeights[i]. IfrowWeightshas more elements than the number of rows, the excess elements are ignored - they do not cause more rows to be created. -
comptable
-
defaultConstraints
This field holds a gridbag constraints instance containing the default values, so if a component does not have gridbag constraints associated with it, then the component will be assigned a copy of thedefaultConstraints.- See Also:
-
layoutInfo
This field holds the layout information for the gridbag. The information in this field is based on the most recent validation of the gridbag. IflayoutInfoisnullthis indicates that there are no components in the gridbag or if there are components, they have not yet been validated.- See Also:
-
-
Constructor Details
-
GridBagLayout
public GridBagLayout()Creates a grid bag layout manager.
-
-
Method Details
-
setConstraints
Sets the constraints for the specified component in this layout.- Parameters:
comp- the component to be modifiedconstraints- the constraints to be applied
-
getConstraints
Gets the constraints for the specified component. A copy of the actualGridCellobject is returned.- Parameters:
comp- the component to be queried- Returns:
- the constraint for the specified component in this grid bag layout; a copy of the actual constraint object is returned
-
lookupConstraints
Retrieves the constraints for the specified component. The return value is not a copy, but is the actualGridCellobject used by the layout mechanism.If
compis not in theGridBagLayout, a set of defaultGridCellare returned. Acompvalue ofnullis invalid and returnsnull.- Parameters:
comp- the component to be queried- Returns:
- the constraints for the specified component
-
getLayoutOrigin
Determines the origin of the layout area, in the graphics coordinate space of the target container. This value represents the pixel coordinates of the top-left corner of the layout area regardless of theComponentOrientationvalue of the container. This is distinct from the grid origin given by the cell coordinates (0,0). Most applications do not call this method directly.- Returns:
- the graphics origin of the cell in the top-left corner of the layout grid
- Since:
- JDK1.1
- See Also:
-
getLayoutDimensions
public int[][] getLayoutDimensions()Determines column widths and row heights for the layout grid.Most applications do not call this method directly.
- Returns:
- an array of two arrays, containing the widths of the layout columns and the heights of the layout rows
- Since:
- JDK1.1
-
getLayoutWeights
public double[][] getLayoutWeights()Determines the weights of the layout grid's columns and rows. Weights are used to calculate how much a given column or row stretches beyond its preferred size, if the layout has extra room to fill.Most applications do not call this method directly.
- Returns:
- an array of two arrays, representing the horizontal weights of the layout columns and the vertical weights of the layout rows
- Since:
- JDK1.1
-
location
Determines which cell in the layout grid contains the point specified by(x, y). Each cell is identified by its column index (ranging from 0 to the number of columns minus 1) and its row index (ranging from 0 to the number of rows minus 1).If the
(x, y)point lies outside the grid, the following rules are used. The column index is returned as zero ifxlies to the left of the layout for a left-to-right container or to the right of the layout for a right-to-left container. The column index is returned as the number of columns ifxlies to the right of the layout in a left-to-right container or to the left in a right-to-left container. The row index is returned as zero ifylies above the layout, and as the number of rows ifylies below the layout. The orientation of a container is determined by itsComponentOrientationproperty.- Parameters:
x- the x coordinate of a pointy- the y coordinate of a point- Returns:
- an ordered pair of indexes that indicate which cell in the layout grid contains the point (x, y).
- Since:
- JDK1.1
- See Also:
-
addLayoutComponent
Has no effect, since this layout manager does not use a per-component string. -
addLayoutComponent
Adds the specified component to the layout, using the specifiedconstraintsobject. Note that constraints are mutable and are, therefore, cloned when cached.- Parameters:
comp- the component to be addedconstraints- an object that determines how the component is added to the layout- Throws:
IllegalArgumentException- ifconstraintsis not aGridBagConstraint
-
removeLayoutComponent
public void removeLayoutComponent(com.googlecode.lanterna.gui2.Component comp) Removes the specified component from this layout.Most applications do not call this method directly.
- Parameters:
comp- the component to be removed.- See Also:
-
preferredLayoutSize
Determines the preferred size of theparentcontainer using this grid bag layout.Most applications do not call this method directly.
- Parameters:
parent- the container in which to do the layout- Returns:
- the preferred size of the
parentcontainer - See Also:
-
minimumLayoutSize
Determines the minimum size of theparentcontainer using this grid bag layout.Most applications do not call this method directly.
- Parameters:
parent- the container in which to do the layout- Returns:
- the minimum size of the
parentcontainer - See Also:
-
maximumLayoutSize
Returns the maximum dimensions for this layout given the components in the specified target container.- Parameters:
target- the container which needs to be laid out- Returns:
- the maximum dimensions for this layout
- See Also:
-
getLayoutAlignmentX
public float getLayoutAlignmentX(com.googlecode.lanterna.gui2.Container parent) Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.- Returns:
- the value
0.5fto indicate centered
-
getLayoutAlignmentY
public float getLayoutAlignmentY(com.googlecode.lanterna.gui2.Container parent) Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.- Returns:
- the value
0.5fto indicate centered
-
invalidateLayout
public void invalidateLayout(com.googlecode.lanterna.gui2.Container target) Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. -
layoutContainer
public void layoutContainer(com.googlecode.lanterna.gui2.Container parent) Lays out the specified container using this grid bag layout. This method reshapes components in the specified container in order to satisfy the constraints of thisGridBagLayoutobject.Most applications do not call this method directly.
- Parameters:
parent- the container in which to do the layout- See Also:
-
toString
-
getLayoutInfo
Fills in an instance ofGridBagLayoutInfofor the current set of managed children. This requires three passes through the set of children:- Figure out the dimensions of the layout grid.
- Determine which cells the components occupy.
- Distribute the weights and min sizes among the rows/columns.
This also caches the minsizes for all the children when they are first encountered (so subsequent loops don't need to ask again).
This method should only be used internally by
GridBagLayout.- Parameters:
parent- the layout containersizeflag- eitherPREFERREDSIZEorMINSIZE- Returns:
- the
GridBagLayoutInfofor the set of children - Since:
- 1.4
-
GetLayoutInfo
This method is obsolete and supplied for backwards compatibility only; new code should callgetLayoutInfoinstead. This method is the same asgetLayoutInfo; refer togetLayoutInfofor details on parameters and return value. -
adjustForGravity
Adjusts the x, y, width, and height fields to the correct values depending on the constraint geometry and pads. This method should only be used internally byGridBagLayout.- Parameters:
constraints- the constraints to be appliedr- theRectangleto be adjusted- Since:
- 1.4
-
AdjustForGravity
This method is obsolete and supplied for backwards compatibility only; new code should calladjustForGravityinstead. This method is the same asadjustForGravity; refer toadjustForGravityfor details on parameters. -
getMinSize
Figures out the minimum size of the master based on the information fromgetLayoutInfo. This method should only be used internally byGridBagLayout.- Parameters:
parent- the layout containerinfo- the layout info for this parent- Returns:
- a
Dimensionobject containing the minimum size - Since:
- 1.4
-
GetMinSize
This method is obsolete and supplied for backwards compatibility only; new code should callgetMinSizeinstead. This method is the same asgetMinSize; refer togetMinSizefor details on parameters and return value. -
arrangeGrid
protected void arrangeGrid(com.googlecode.lanterna.gui2.Container parent) Lays out the grid. This method should only be used internally byGridBagLayout.- Parameters:
parent- the layout container- Since:
- 1.4
-
ArrangeGrid
protected void ArrangeGrid(com.googlecode.lanterna.gui2.Container parent) This method is obsolete and supplied for backwards compatibility only; new code should callarrangeGridinstead. This method is the same asarrangeGrid; refer toarrangeGridfor details on the parameter. -
doLayout
public void doLayout(com.googlecode.lanterna.TerminalSize area, List<com.googlecode.lanterna.gui2.Component> components) - Specified by:
doLayoutin interfacecom.googlecode.lanterna.gui2.LayoutManager
-
getPreferredSize
public com.googlecode.lanterna.TerminalSize getPreferredSize(List<com.googlecode.lanterna.gui2.Component> components) - Specified by:
getPreferredSizein interfacecom.googlecode.lanterna.gui2.LayoutManager
-
hasChanged
public boolean hasChanged()- Specified by:
hasChangedin interfacecom.googlecode.lanterna.gui2.LayoutManager
-