Xj3D 2.0 VRML/X3D Code API

org.xj3d.ui.awt.widgets
Class DynamicGridLayout

java.lang.Object
  extended by org.xj3d.ui.awt.widgets.DynamicGridLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.io.Serializable

public class DynamicGridLayout
extends java.lang.Object
implements java.awt.LayoutManager, java.io.Serializable

A layout manager that lays out a container's components in a rectangular grid, with different sizes for each row/column.

As with GridLayout one component is placed in each rectangle, but the width of columns and height of rows are not necessarily the same. By default each row and column will be sized in proportion to the minimum size of the largest component in that row or column. Alternatively, individual rows or columns can be set to a fixed percentage of the container or their minimum size with various options. Components can also be set to fill the assigned area or use their minimum size and align themselves within that allocated space. If the grid itself doesn't completely fill the area assigned by the container there are methods to set this alignment too.

Here's a simple example of using a DynamicGridLayout.

   //create the layout and set it
   setLayout(dgl=new DynamicGridLayout(2,2,5,5));

   //set any styles, sizes or alignments
   dgl.setRowSize(0,dgl.MINIMUM);

   //add the components
   add(new Button("Row One/Col One"));
   add(new Button("Row One/Col Two"));

   add(new Button("Row Two/Col One"));
   add(new Button("Row Two/Col Two"));
 

Version:
$Revision: 1.3 $
Author:
Robert Nielsen
See Also:
Serialized Form

Field Summary
static int ABOVE_MINIMUM
           
static int BELOW_MINIMUM
           
static int BOTTOM
           
static int CENTER
           
static int DYNAMIC
           
static int FILL
           
static int LABEL_FILL
           
static int LABEL_MIN
           
static int LEFT
           
static int MINIMUM
           
static int RIGHT
           
static int TOP
           
 
Constructor Summary
DynamicGridLayout()
          Creates a grid layout with a default of one column per component, in a single row.
DynamicGridLayout(int rows, int cols)
          Creates a grid layout with the specified number of rows and columns.
DynamicGridLayout(int rows, int cols, int hgap, int vgap)
          Creates a grid layout with the specified number of rows and columns.
 
Method Summary
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          Adds the specified component with the specified name to the layout.
 int getColumns()
          Gets the number of columns in this layout.
 int getHgap()
          Gets the horizontal gap between components.
 int getRows()
          Gets the number of rows in this layout.
 int getVgap()
          Gets the vertical gap between components.
 void layoutContainer(java.awt.Container parent)
          Lays out the specified container using this layout.
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
          Determines the minimum size of the container argument using this grid layout.
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Determines the preferred size of the container argument using this grid layout.
 void removeLayoutComponent(java.awt.Component comp)
          Removes the specified component from the layout.
 void resetGrid()
          Resets the grid parameters.
 void setColumnAlignment(int col, int value)
          Sets the alignment for a particular column.
 void setColumnAlignments(int start, int end, int value)
          Sets the alignment of multiple columns.
 void setColumns(int cols)
          Sets the number of columns in this layout to the specified value.
 void setColumnSize(int col, int value)
          Sets the size of a column.
 void setColumnSizes(int start, int end, int value)
          Sets the size of multiple columns.
 void setHgap(int hgap)
          Sets the horizontal gap between components to the specified value.
 void setHorizontalAlignment(int value)
          This method is only required if there are no columns with dynamic widths which may cause the layout to be smaller than the allocated space.
 void setRowAlignment(int row, int value)
          Sets the alignment for a particular row.
 void setRowAlignments(int start, int end, int value)
          Sets the alignment of multiple rows.
 void setRows(int rows)
          Sets the number of rows in this layout to the specified value.
 void setRowSize(int row, int value)
          Sets the size of a row.
 void setRowSizes(int start, int end, int value)
          Sets the size of multiple rows.
 void setStyle(int style)
          Sets the style of this grid.
 void setVerticalAlignment(int value)
          This method is only required if there are no rows with dynamic heights which may cause the layout to be smaller than the allocated space.
 void setVgap(int vgap)
          Sets the vertical gap between components to the specified value.
 java.lang.String toString()
          Returns the string representation of this grid layout's values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DYNAMIC

public static final int DYNAMIC
See Also:
Constant Field Values

MINIMUM

public static final int MINIMUM
See Also:
Constant Field Values

ABOVE_MINIMUM

public static final int ABOVE_MINIMUM
See Also:
Constant Field Values

BELOW_MINIMUM

public static final int BELOW_MINIMUM
See Also:
Constant Field Values

FILL

public static final int FILL
See Also:
Constant Field Values

CENTER

public static final int CENTER
See Also:
Constant Field Values

LEFT

public static final int LEFT
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

TOP

public static final int TOP
See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
See Also:
Constant Field Values

LABEL_FILL

public static final int LABEL_FILL
See Also:
Constant Field Values

LABEL_MIN

public static final int LABEL_MIN
See Also:
Constant Field Values
Constructor Detail

DynamicGridLayout

public DynamicGridLayout()
Creates a grid layout with a default of one column per component, in a single row.


DynamicGridLayout

public DynamicGridLayout(int rows,
                         int cols)
Creates a grid layout with the specified number of rows and columns. All components in the layout are given equal size.

One, but not both, of rows and cols can be zero, which means that any number of objects can be placed in a row or in a column.

Parameters:
rows - the rows, with the value zero meaning any number of rows.
cols - the columns, with the value zero meaning any number of columns.

DynamicGridLayout

public DynamicGridLayout(int rows,
                         int cols,
                         int hgap,
                         int vgap)
Creates a grid layout with the specified number of rows and columns.

In addition, the horizontal and vertical gaps are set to the specified values. Horizontal gaps are placed at the left and right edges, and between each of the columns. Vertical gaps are placed at the top and bottom edges, and between each of the rows.

One, but not both, of rows and cols can be zero, which means that any number of objects can be placed in a row or in a column.

Parameters:
rows - the rows, with the value zero meaning any number of rows.
cols - the columns, with the value zero meaning any number of columns.
hgap - the horizontal gap.
vgap - the vertical gap.
Throws:
java.lang.IllegalArgumentException - if the of rows or cols is invalid.
Method Detail

getRows

public int getRows()
Gets the number of rows in this layout.

Returns:
the number of rows in this layout.

setRows

public void setRows(int rows)
Sets the number of rows in this layout to the specified value.

Parameters:
rows - the number of rows in this layout.
Throws:
java.lang.IllegalArgumentException - if the value of both rows and cols is set to zero.

getColumns

public int getColumns()
Gets the number of columns in this layout.

Returns:
the number of columns in this layout.
Since:
JDK1.1

setColumns

public void setColumns(int cols)
Sets the number of columns in this layout to the specified value.

Parameters:
cols - the number of columns in this layout.
Throws:
java.lang.IllegalArgumentException - if the value of both rows and cols is set to zero.

getHgap

public int getHgap()
Gets the horizontal gap between components.

Returns:
the horizontal gap between components.

setHgap

public void setHgap(int hgap)
Sets the horizontal gap between components to the specified value.

Parameters:
hgap - the horizontal gap between components.

getVgap

public int getVgap()
Gets the vertical gap between components.

Returns:
the vertical gap between components.

setVgap

public void setVgap(int vgap)
Sets the vertical gap between components to the specified value.

Parameters:
vgap - the vertical gap between components.

resetGrid

public void resetGrid()
Resets the grid parameters. All styles, alignments and sizes are reset to their default values.


setStyle

public void setStyle(int style)
Sets the style of this grid. This provides a shortcut to producing several standard styles of grid layout by setting various row alignments and sizes. The style can be tweaked by using the set(Row|Column)Alignment and set(Row|Column)Size methods after a call to this one.

The style parameter has the following parameters:

Parameters:
style - The style to be set.

setHorizontalAlignment

public void setHorizontalAlignment(int value)
This method is only required if there are no columns with dynamic widths which may cause the layout to be smaller than the allocated space. The horizontal alignment of the grid in this space can then be specified using this method. The default is centered. The available alignments are:

Parameters:
value - the alignment to set

setVerticalAlignment

public void setVerticalAlignment(int value)
This method is only required if there are no rows with dynamic heights which may cause the layout to be smaller than the allocated space. The vertical alignment of the grid in this space can then be specified using this method. The default is centered. The available alignments are:

Parameters:
value - the alignment to set

setRowAlignment

public void setRowAlignment(int row,
                            int value)
Sets the alignment for a particular row. If the alignment is not FILL, the preferred size of the component will be used unless it is greater than the available space, in which case it will be truncated. The default alignment is FILL for all rows. The available alignments are:

Parameters:
row - The row to set the alignment for
value - The alignment to set.

setRowAlignments

public void setRowAlignments(int start,
                             int end,
                             int value)
Sets the alignment of multiple rows. See setRowAlignment for details of alignment values.

Parameters:
start - the inclusive start row to set
end - the inclusive end row to set
value - the alignment to set
See Also:
setRowAlignment(int, int)

setColumnAlignment

public void setColumnAlignment(int col,
                               int value)
Sets the alignment for a particular column. If the alignment is not FILL, the preferred size of the component will be used unless it is greater than the available space, in which case it will be truncated. The default alignment is FILL for all columns. The available alignments are:

Parameters:
col - The column to set the alignment for
value - The alignment to set.

setColumnAlignments

public void setColumnAlignments(int start,
                                int end,
                                int value)
Sets the alignment of multiple columns. See setColumnAlignment for details of alignment values.

Parameters:
start - The inclusive start column to set
end - The inclusive end column to set
value - The alignment to set
See Also:
setColumnAlignment(int, int)

setRowSize

public void setRowSize(int row,
                       int value)
Sets the size of a row. The available sizes are:


setRowSizes

public void setRowSizes(int start,
                        int end,
                        int value)
Sets the size of multiple rows. See setRowSize for details of alignment values.

Parameters:
start - The inclusive start row to set
end - The inclusive end row to set
value - The size to set
See Also:
setRowSize(int, int)

setColumnSize

public void setColumnSize(int col,
                          int value)
Sets the size of a column. The available sizes are:


setColumnSizes

public void setColumnSizes(int start,
                           int end,
                           int value)
Sets the size of multiple columns. See setColumnSize for details of alignment values.

Parameters:
start - The inclusive start column to set
end - The inclusive end column to set
value - The size to set
See Also:
setColumnSize(int, int)

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
Adds the specified component with the specified name to the layout.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
Parameters:
name - the name of the component.
comp - the component to be added.

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Removes the specified component from the layout.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
Parameters:
comp - the component to be removed.

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Determines the preferred size of the container argument using this grid layout.

The preferred width of a grid layout is the largest preferred width of any of the widths in the container times the number of columns, plus the horizontal padding times the number of columns plus one, plus the left and right insets of the target container.

The preferred height of a grid layout is the largest preferred height of any of the heights in the container times the number of rows, plus the vertical padding times the number of rows plus one, plus the top and bottom insets of the target container.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - the container in which to do the layout.
Returns:
the preferred dimensions to lay out the subcomponents of the specified container.
See Also:
GridLayout.minimumLayoutSize(java.awt.Container), Container.getPreferredSize()

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Determines the minimum size of the container argument using this grid layout.

The minimum width of a grid layout is the largest minimum width of any of the widths in the container times the number of columns, plus the horizontal padding times the number of columns plus one, plus the left and right insets of the target container.

The minimum height of a grid layout is the largest minimum height of any of the heights in the container times the number of rows, plus the vertical padding times the number of rows plus one, plus the top and bottom insets of the target container.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - the container in which to do the layout.
Returns:
the minimum dimensions needed to lay out the subcomponents of the specified container.
See Also:
GridLayout.preferredLayoutSize(java.awt.Container), Container.doLayout()

layoutContainer

public void layoutContainer(java.awt.Container parent)
Lays out the specified container using this layout.

This method reshapes the components in the specified target container in order to satisfy the constraints of the GridLayout object.

The grid layout manager determines the size of individual components by dividing the free space in the container into equal-sized portions according to the number of rows and columns in the layout. The container's free space equals the container's size minus any insets and any specified horizontal or vertical gap. All components in a grid layout are given the same size.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
parent - the container in which to do the layout.
See Also:
Container, Container.doLayout()

toString

public java.lang.String toString()
Returns the string representation of this grid layout's values.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this grid layout.

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium