gov.nasa.gsfc.drl.rtstps.library.layout
Class ScaledGridLayout

java.lang.Object
  extended by gov.nasa.gsfc.drl.rtstps.library.layout.ScaledGridLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable

public final class ScaledGridLayout
extends java.lang.Object
implements java.awt.LayoutManager2, java.io.Serializable

This class is a layout manager that lays out components in an adjustable grid. It is similar to GridLayout with several improvements. The rows and columns are not the same size by default. GridLayout determines the width of a column or the height of a row by using the maximum preferred size of all components in that row or column. You can configure ScaledGridLayout so that it does not grow a component beyond its maximum size. If a component is smaller than its cell, it sizes it to its maximum size and places in the cell based on the layout manager's X and Y alignments. Use honorMaxSize(true) to enable this feature. ScaledGridLayout adds components in a specific order -- across a column before progressing to the next row.

You may set hgap and vgap, which is the gap between components. The default is five pixels each. It does not apply to the border.

You may fix the size of columns or rows, which then work like GridLayout. All rows or columns are then the same size.

Use Box's struts, glue, and rigid to insert blank components.

You may set an inset, which is a blank border.

JPanel jp = new JPanel(new ScaledGridLayout(3,4)); //3 rows, 4 columns jp.add(comp1); jp.add(comp2);

See Also:
Serialized Form

Nested Class Summary
(package private)  class ScaledGridLayout.Axis
          Manages all rows or all columns.
 
Field Summary
private  float _alignX
           
private  float _alignY
           
private  ScaledGridLayout.Axis _columns
           
private  int _hgap
           
private  boolean _honorMaxSize
           
private  java.awt.Insets _insets
           
private  ScaledGridLayout.Axis _rows
           
private  boolean _valid
           
private  int _vgap
           
private static long serialVersionUID
           
 
Constructor Summary
ScaledGridLayout()
          Create a ScaledGridLayout object with one row and hgap=5, vgap=5.
ScaledGridLayout(int rows, int columns)
          Create a ScaledGridLayout object with hgap=5 and vgap=5.
ScaledGridLayout(int rows, int columns, int hgap, int vgap)
          Create a ScaledGridLayout object.
ScaledGridLayout(int rows, int columns, int hgap, int vgap, boolean honorMaximumSize)
          Create a ScaledGridLayout object.
 
Method Summary
 void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
          Adds the specified component to the layout using the specified constraint object.
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          Adds the specified component with the specified name to the layout.
 java.awt.Insets getInsets()
          Get the insets.
 float getLayoutAlignmentX(java.awt.Container parent)
          Get the X alignment.
 float getLayoutAlignmentY(java.awt.Container parent)
          Get the Y alignment.
 void honorMaxSize(boolean b)
          If set to true, the layout manager will not increase any component's size above its maximum.
 void invalidateLayout(java.awt.Container target)
          Cause the layout manager to lay out the components.
 void layoutContainer(java.awt.Container parent)
          Lay out the container.
private  void locateInCell(java.awt.Component comp, java.awt.Rectangle cell)
          Position a component in a cell.
 java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
          Get the maximum layout size.
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
          Get the minimum layout size.
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Get the preferred layout size.
 void removeLayoutComponent(java.awt.Component comp)
          Remove a component from the layout.
 void setFixedColumns(boolean ena)
          Set fixed height columns.
 void setFixedRows(boolean ena)
          Set fixed height rows.
 void setHgap(int gap)
          Set the horizontal gap between units on a row.
 void setInsets(java.awt.Insets in)
          Set insets, which is a blank border.
 void setLayoutAlignmentX(float x)
          Set the horizontal alignment.
 void setLayoutAlignmentY(float y)
          Set the vertical alignment.
private  void setLayoutHeight(java.awt.Container parent)
          Compute the layout heights -- min, max, and preferred.
private  void setLayoutWidth(java.awt.Container parent)
          Compute the layout widths -- min, max, and preferred.
 void setVgap(int gap)
          Set the vertical gap between units in a column.
private  void validate(java.awt.Container parent)
          Prepare the container for layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_rows

private ScaledGridLayout.Axis _rows

_columns

private ScaledGridLayout.Axis _columns

_insets

private java.awt.Insets _insets

_valid

private boolean _valid

_hgap

private int _hgap

_vgap

private int _vgap

_honorMaxSize

private boolean _honorMaxSize

_alignX

private float _alignX

_alignY

private float _alignY

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

ScaledGridLayout

public ScaledGridLayout()
Create a ScaledGridLayout object with one row and hgap=5, vgap=5.


ScaledGridLayout

public ScaledGridLayout(int rows,
                        int columns)
Create a ScaledGridLayout object with hgap=5 and vgap=5.

Parameters:
rows - Number of rows
columns - Number of columns

ScaledGridLayout

public ScaledGridLayout(int rows,
                        int columns,
                        int hgap,
                        int vgap)
Create a ScaledGridLayout object.

Parameters:
rows - Number of rows
columns - Number of columns
hgap - Horizontal gap between units in a row.
vgap - Vertical gap between units in a column.

ScaledGridLayout

public ScaledGridLayout(int rows,
                        int columns,
                        int hgap,
                        int vgap,
                        boolean honorMaximumSize)
Create a ScaledGridLayout object.

Parameters:
rows - Number of rows
columns - Number of columns
hgap - Horizontal gap between units in a row.
vgap - Vertical gap between units in a column.
honorMaximumSize - If true, the layout will not resize any component above its maximum size.
Method Detail

setHgap

public final void setHgap(int gap)
Set the horizontal gap between units on a row. It does not apply to the border.


setVgap

public final void setVgap(int gap)
Set the vertical gap between units in a column. It does not apply to the border.


honorMaxSize

public final void honorMaxSize(boolean b)
If set to true, the layout manager will not increase any component's size above its maximum. If the cell is bigger than a component, the manager will locate it in the cell depending on the manager X and Y alignment. (0f = top or left; 1f = right or bottom.) The default alignment is centered (.5f, .5f).


setInsets

public final void setInsets(java.awt.Insets in)
Set insets, which is a blank border. The default is no border.


getInsets

public final java.awt.Insets getInsets()
Get the insets.

Returns:
Return the insets.

setLayoutAlignmentX

public final void setLayoutAlignmentX(float x)
Set the horizontal alignment. The default is 0f.

Parameters:
x - Floating point between 0f and 1f.

setLayoutAlignmentY

public final void setLayoutAlignmentY(float y)
Set the vertical alignment. The default is 0f.

Parameters:
y - Floating point between 0f and 1f.

setFixedRows

public final void setFixedRows(boolean ena)
Set fixed height rows. If false, the row height can grow. Otherwise, all rows have the same height, which is the same behaviour as GridLayout. The default is false.


setFixedColumns

public final void setFixedColumns(boolean ena)
Set fixed height columns. If false, the column width can grow. Otherwise, all columns have the same width, which is the same behaviour as GridLayout. The default is false.


invalidateLayout

public final void invalidateLayout(java.awt.Container target)
Cause the layout manager to lay out the components.

Specified by:
invalidateLayout in interface java.awt.LayoutManager2
Parameters:
target - The container in which the manager is working.

addLayoutComponent

public final void addLayoutComponent(java.lang.String name,
                                     java.awt.Component comp)
Adds the specified component with the specified name to the layout. It does not usually apply to this layout manager.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager

addLayoutComponent

public final void addLayoutComponent(java.awt.Component comp,
                                     java.lang.Object constraints)
Adds the specified component to the layout using the specified constraint object. It does not usually apply to this layout manager.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2

removeLayoutComponent

public final void removeLayoutComponent(java.awt.Component comp)
Remove a component from the layout.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager

getLayoutAlignmentX

public final float getLayoutAlignmentX(java.awt.Container parent)
Get the X alignment.

Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2

getLayoutAlignmentY

public final float getLayoutAlignmentY(java.awt.Container parent)
Get the Y alignment.

Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2

layoutContainer

public void layoutContainer(java.awt.Container parent)
Lay out the container.

Specified by:
layoutContainer in interface java.awt.LayoutManager

locateInCell

private void locateInCell(java.awt.Component comp,
                          java.awt.Rectangle cell)
Position a component in a cell.


minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Get the minimum layout size.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Returns:
A dimension object containing the minimum height and width.

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Get the preferred layout size.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Returns:
A dimension object containing the preferred height and width.

maximumLayoutSize

public final java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
Get the maximum layout size.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
Returns:
A dimension object containing the maximum height and width.

validate

private void validate(java.awt.Container parent)
Prepare the container for layout.


setLayoutHeight

private void setLayoutHeight(java.awt.Container parent)
Compute the layout heights -- min, max, and preferred.


setLayoutWidth

private void setLayoutWidth(java.awt.Container parent)
Compute the layout widths -- min, max, and preferred.