Class GridBagLayout

java.lang.Object
net.thevpc.common.lanterna.GridBagLayout
All Implemented Interfaces:
com.googlecode.lanterna.gui2.LayoutManager

public class GridBagLayout extends Object implements com.googlecode.lanterna.gui2.LayoutManager
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double[]
    This field holds the overrides to the column weights.
    int[]
    This field holds the overrides to the column minimum width.
    protected Hashtable<com.googlecode.lanterna.gui2.Component, GridCell>
    This hashtable maintains the association between a component and its gridbag constraints.
    protected GridCell
    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 the defaultConstraints.
    protected GridLayoutInfo
    This field holds the layout information for the gridbag.
    protected static final int
    This field is no longer used to reserve arrays and kept for backward compatibility.
    protected static final int
    The smallest grid that can be laid out by the grid bag layout.
    protected static final int
    The 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
    Constructor
    Description
    Creates a grid bag layout manager.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addLayoutComponent(com.googlecode.lanterna.gui2.Component comp, Object constraints)
    Adds the specified component to the layout, using the specified constraints object.
    void
    addLayoutComponent(String name, com.googlecode.lanterna.gui2.Component comp)
    Has no effect, since this layout manager does not use a per-component string.
    protected void
    Adjusts the x, y, width, and height fields to the correct values depending on the constraint geometry and pads.
    protected void
    This method is obsolete and supplied for backwards compatibility only; new code should call adjustForGravity instead.
    protected void
    arrangeGrid(com.googlecode.lanterna.gui2.Container parent)
    Lays out the grid.
    protected void
    ArrangeGrid(com.googlecode.lanterna.gui2.Container parent)
    This method is obsolete and supplied for backwards compatibility only; new code should call arrangeGrid instead.
    void
    doLayout(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.
    float
    getLayoutAlignmentX(com.googlecode.lanterna.gui2.Container parent)
    Returns the alignment along the x axis.
    float
    getLayoutAlignmentY(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 GridLayoutInfo
    getLayoutInfo(com.googlecode.lanterna.gui2.Container parent, int sizeflag)
    Fills in an instance of GridBagLayoutInfo for the current set of managed children.
    protected GridLayoutInfo
    GetLayoutInfo(com.googlecode.lanterna.gui2.Container parent, int sizeflag)
    This method is obsolete and supplied for backwards compatibility only; new code should call getLayoutInfo instead.
    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 Dimension
    getMinSize(com.googlecode.lanterna.gui2.Container parent, GridLayoutInfo info)
    Figures out the minimum size of the master based on the information from getLayoutInfo.
    protected Dimension
    GetMinSize(com.googlecode.lanterna.gui2.Container parent, GridLayoutInfo info)
    This method is obsolete and supplied for backwards compatibility only; new code should call getMinSize instead.
    com.googlecode.lanterna.TerminalSize
    getPreferredSize(List<com.googlecode.lanterna.gui2.Component> components)
     
    boolean
     
    void
    invalidateLayout(com.googlecode.lanterna.gui2.Container target)
    Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
    void
    layoutContainer(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 GridCell
    lookupConstraints(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 the parent container using this grid bag layout.
    preferredLayoutSize(com.googlecode.lanterna.gui2.Container parent)
    Determines the preferred size of the parent container using this grid bag layout.
    void
    removeLayoutComponent(com.googlecode.lanterna.gui2.Component comp)
    Removes the specified component from this layout.
    void
    setConstraints(com.googlecode.lanterna.gui2.Component comp, GridCell constraints)
    Sets the constraints for the specified component in this layout.
    Returns a string representation of this grid bag layout's values.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAXGRIDSIZE

      protected static final int MAXGRIDSIZE
      This 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 MINSIZE
      The smallest grid that can be laid out by the grid bag layout.
      See Also:
    • PREFERREDSIZE

      protected static final int PREFERREDSIZE
      The preferred grid size that can be laid out by the grid bag layout.
      See Also:
    • columnWidths

      public int[] columnWidths
      This field holds the overrides to the column minimum width. If this field is non-null the 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[] rowHeights
      This field holds the overrides to the row minimum heights. If this field is non-null the values are applied to the gridbag after all of the minimum row heights have been calculated. If rowHeights has more elements than the number of rows, rows are added to the gridbag to match the number of elements in rowHeights.
      See Also:
    • columnWeights

      public double[] columnWeights
      This field holds the overrides to the column weights. If this field is non-null the values are applied to the gridbag after all of the columns weights have been calculated. If columnWeights[i] > weight for column i, then column i is assigned the weight in columnWeights[i]. If columnWeights has more elements than the number of columns, the excess elements are ignored - they do not cause more columns to be created.
    • rowWeights

      public double[] rowWeights
      This field holds the overrides to the row weights. If this field is non-null the values are applied to the gridbag after all of the rows weights have been calculated. If rowWeights[i] > weight for row i, then row i is assigned the weight in rowWeights[i]. If rowWeights has more elements than the number of rows, the excess elements are ignored - they do not cause more rows to be created.
    • comptable

      protected Hashtable<com.googlecode.lanterna.gui2.Component, GridCell> comptable
      This hashtable maintains the association between a component and its gridbag constraints. The Keys in comptable are the components and the values are the instances of GridBagConstraints.
      See Also:
    • defaultConstraints

      protected GridCell 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 the defaultConstraints.
      See Also:
    • layoutInfo

      protected GridLayoutInfo 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. If layoutInfo is null this 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

      public void setConstraints(com.googlecode.lanterna.gui2.Component comp, GridCell constraints)
      Sets the constraints for the specified component in this layout.
      Parameters:
      comp - the component to be modified
      constraints - the constraints to be applied
    • getConstraints

      public GridCell getConstraints(com.googlecode.lanterna.gui2.Component comp)
      Gets the constraints for the specified component. A copy of the actual GridCell object 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

      protected GridCell lookupConstraints(com.googlecode.lanterna.gui2.Component comp)
      Retrieves the constraints for the specified component. The return value is not a copy, but is the actual GridCell object used by the layout mechanism.

      If comp is not in the GridBagLayout, a set of default GridCell are returned. A comp value of null is invalid and returns null.

      Parameters:
      comp - the component to be queried
      Returns:
      the constraints for the specified component
    • getLayoutOrigin

      public Point 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 the ComponentOrientation value 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

      public Point location(int x, int y)
      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 if x lies 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 if x lies 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 if y lies above the layout, and as the number of rows if y lies below the layout. The orientation of a container is determined by its ComponentOrientation property.

      Parameters:
      x - the x coordinate of a point
      y - the y coordinate of a point
      Returns:
      an ordered pair of indexes that indicate which cell in the layout grid contains the point (xy).
      Since:
      JDK1.1
      See Also:
    • addLayoutComponent

      public void addLayoutComponent(String name, com.googlecode.lanterna.gui2.Component comp)
      Has no effect, since this layout manager does not use a per-component string.
    • addLayoutComponent

      public void addLayoutComponent(com.googlecode.lanterna.gui2.Component comp, Object constraints)
      Adds the specified component to the layout, using the specified constraints object. Note that constraints are mutable and are, therefore, cloned when cached.
      Parameters:
      comp - the component to be added
      constraints - an object that determines how the component is added to the layout
      Throws:
      IllegalArgumentException - if constraints is not a GridBagConstraint
    • 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

      public Dimension preferredLayoutSize(com.googlecode.lanterna.gui2.Container parent)
      Determines the preferred size of the parent container 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 parent container
      See Also:
    • minimumLayoutSize

      public Dimension minimumLayoutSize(com.googlecode.lanterna.gui2.Container parent)
      Determines the minimum size of the parent container 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 parent container
      See Also:
    • maximumLayoutSize

      public Dimension maximumLayoutSize(com.googlecode.lanterna.gui2.Container target)
      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.5f to 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.5f to 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 this GridBagLayout object.

      Most applications do not call this method directly.

      Parameters:
      parent - the container in which to do the layout
      See Also:
    • toString

      public String toString()
      Returns a string representation of this grid bag layout's values.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this grid bag layout.
    • getLayoutInfo

      protected GridLayoutInfo getLayoutInfo(com.googlecode.lanterna.gui2.Container parent, int sizeflag)
      Fills in an instance of GridBagLayoutInfo for the current set of managed children. This requires three passes through the set of children:

      1. Figure out the dimensions of the layout grid.
      2. Determine which cells the components occupy.
      3. 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 container
      sizeflag - either PREFERREDSIZE or MINSIZE
      Returns:
      the GridBagLayoutInfo for the set of children
      Since:
      1.4
    • GetLayoutInfo

      protected GridLayoutInfo GetLayoutInfo(com.googlecode.lanterna.gui2.Container parent, int sizeflag)
      This method is obsolete and supplied for backwards compatibility only; new code should call getLayoutInfo instead. This method is the same as getLayoutInfo; refer to getLayoutInfo for details on parameters and return value.
    • adjustForGravity

      protected void adjustForGravity(GridCell constraints, Rectangle r)
      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 by GridBagLayout.
      Parameters:
      constraints - the constraints to be applied
      r - the Rectangle to be adjusted
      Since:
      1.4
    • AdjustForGravity

      protected void AdjustForGravity(GridCell constraints, Rectangle r)
      This method is obsolete and supplied for backwards compatibility only; new code should call adjustForGravity instead. This method is the same as adjustForGravity; refer to adjustForGravity for details on parameters.
    • getMinSize

      protected Dimension getMinSize(com.googlecode.lanterna.gui2.Container parent, GridLayoutInfo info)
      Figures out the minimum size of the master based on the information from getLayoutInfo. This method should only be used internally by GridBagLayout.
      Parameters:
      parent - the layout container
      info - the layout info for this parent
      Returns:
      a Dimension object containing the minimum size
      Since:
      1.4
    • GetMinSize

      protected Dimension GetMinSize(com.googlecode.lanterna.gui2.Container parent, GridLayoutInfo info)
      This method is obsolete and supplied for backwards compatibility only; new code should call getMinSize instead. This method is the same as getMinSize; refer to getMinSize for 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 by GridBagLayout.
      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 call arrangeGrid instead. This method is the same as arrangeGrid; refer to arrangeGrid for details on the parameter.
    • doLayout

      public void doLayout(com.googlecode.lanterna.TerminalSize area, List<com.googlecode.lanterna.gui2.Component> components)
      Specified by:
      doLayout in interface com.googlecode.lanterna.gui2.LayoutManager
    • getPreferredSize

      public com.googlecode.lanterna.TerminalSize getPreferredSize(List<com.googlecode.lanterna.gui2.Component> components)
      Specified by:
      getPreferredSize in interface com.googlecode.lanterna.gui2.LayoutManager
    • hasChanged

      public boolean hasChanged()
      Specified by:
      hasChanged in interface com.googlecode.lanterna.gui2.LayoutManager