|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.gui.TableLayout
Layout manager effecting a table with an arbitrary number of rows and columns, each with their own width and height. Optional gaps with a distance of an arbitrary number of pixels can be set in the horizontal and vertical directions.
The alignment of components within their respective cells can be set to any of the nine compass directions. Alignments can be set for individual cells, table rows, table columns, or the table itself.
Empty rows and columns are not included in the rendering process and do not result in the application of a gap.
As of 2.5.0, adds methods to return the component at a given
row,col position or CellPosition. These methods
permit one to inspect the components without the need to call
the heavyweight method getComponentTable().
Corresponding methods to remove a component from a given cell position are also provided.
| Field Summary | |
protected int[][] |
cellAlignment
Alignment for cells in this table layout. |
protected int[] |
colAlignment
Default alignments for columns in this table layout. |
protected int |
cols
Number of columns in this table layout. |
static int |
DEFAULT_ALIGNMENT
Value of the default alignment. |
static int |
DEFAULT_ORIENTATION
Value of the default orientation. |
protected int |
hgap
Horizontal gap between columns in this table layout. |
static int |
INVALID_ALIGNMENT
Value designating an invalid alignment. |
protected int[] |
minColWidth
Minimum widths for columns in this table layout. |
protected int[] |
minRowHeight
Minimum heights for rows in this table layout. |
static int |
NO_ALIGNMENT_SET
Value designating an alignment explicitly not set. |
static int |
NO_MINIMUM_SET
Value designating a non-existent minimum size. |
protected int |
orientation
Orientation for this table layout. |
protected int[] |
rowAlignment
Default alignments for rows in this table layout. |
protected int |
rows
Number of rows in this table layout. |
protected Component[][] |
table
Table of components in this layout. |
protected int |
tableAlignment
Default alignment for cells in this table layout. |
protected int |
vgap
Vertical gap between rows in this table layout. |
| Fields inherited from interface edu.neu.ccs.util.JPTConstants |
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE |
| Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
| Constructor Summary | |
TableLayout(int rows,
int cols)
Constructs a table layout with the given number of rows and columns. |
|
TableLayout(int rows,
int cols,
int align)
Constructs a table layout with the given number of rows and columns, and the given default table cell alignment. |
|
TableLayout(int rows,
int cols,
int hgap,
int vgap)
Constructs a table layout with the given number of rows and columns, and the given horizontal and vertical gaps. |
|
TableLayout(int rows,
int cols,
int hgap,
int vgap,
int align)
Constructs a table layout with the given number of rows and columns, the given horizontal and vertical gaps, and the given default table cell alignment, |
|
TableLayout(int rows,
int cols,
int hgap,
int vgap,
int align,
int orientation)
Constructs a table layout with the given number of rows and columns, the given horizontal and vertical gaps, the given default table cell alignment, and the given layout orientation. |
|
| Method Summary | |
void |
addLayoutComponent(Component c,
Object position)
Adds the given component to this table layout at the given table position. |
void |
addLayoutComponent(String name,
Component c)
Adds the given component to this layout at the next available position. |
(package private) int |
adjustAlignment(int align)
Returns the alignment value corresponding to the given value, or
if the given value is invalid. |
protected Point |
applyAlignment(int x,
int y,
int cellWidth,
int cellHeight,
int componentWidth,
int componentHeight,
int align)
Returns the point, given in terms of the parent container's coordinate space, where a component of the given size should be located given a cell with the provided bounds and the given alignment value. |
int |
getCellAlignment(CellPosition p)
Returns the alignment value for the cell at the given position or the table alignment if an error occurs. |
int |
getCellAlignment(int row,
int col)
Returns the alignment value for the cell at the given position or the table alignment if an error occurs. |
int |
getColumnAlignment(int col)
Returns the default alignment value for the given column. |
int |
getColumnCount()
Returns the number of columns in this table layout. |
Component[][] |
getComponentTable()
Returns a copy of the table of components in this layout. |
int |
getEffectiveCellAlignment(CellPosition p)
Returns the effective alignment value for the cell at the given position, that is, either the cell's own alignment if it has been set or the alignment of the table as a whole. |
int |
getEffectiveCellAlignment(int row,
int col)
Returns the effective alignment value for the cell at the given position, that is, either the cell's own alignment if it has been set or the alignment of the table as a whole. |
int |
getHorizontalGap()
Returns the gap, in pixels, between columns in this table layout. |
float |
getLayoutAlignmentX(Container target)
Returns the alignment for this table layout along the x axis. |
float |
getLayoutAlignmentY(Container target)
Returns the alignment along the y axis. |
int |
getMinimumColumnWidth(int col)
Returns the minimum width set for the given column. |
int |
getMinimumRowHeight(int row)
Returns the minimum height set for the given row. |
protected CellPosition |
getNextAvailablePosition()
Returns the next empty position in the table layout, that is, a position that does not contain a component; if the table layout is full, returns a new position that will require either adding a column or a row to the internal component table. |
int |
getOrientation()
Returns the orientation for this table layout. |
int |
getRowAlignment(int row)
Returns the default alignment value for the given row. |
int |
getRowCount()
Returns the number of rows in this table layout. |
int |
getTableAlignment()
Returns the default alignment for cells in this table layout. |
Component |
getTableEntry(CellPosition position)
Returns the component at the given CellPosition position
in the table layout data structure. |
Component |
getTableEntry(int row,
int col)
Returns the component at the given row,col position in the table layout data structure. |
int |
getVerticalGap()
Returns the gap, in pixels, between rows in this table layout. |
void |
invalidateLayout(Container parent)
This method does nothing, as this layout does not cache information about its container. |
boolean |
isEmptyColumn(int col)
Returns whether or not the given column is empty. |
boolean |
isEmptyRow(int row)
Returns whether or not the given row is empty. |
boolean |
isValidColumn(int col)
Returns whether or not the given column index is valid. |
boolean |
isValidRow(int row)
Returns whether or not the given row index is valid. |
void |
layoutContainer(Container parent)
Lays out the components in the given parent container. |
protected void |
layoutContainer(int[] widths,
int[] heights,
Insets insets)
Lays out the components in the parent container using the given arrays of column widths and row heights. |
int |
maximumColumnWidth(int col)
Returns the actual maximum width for the given column. |
int[] |
maximumColumnWidths()
Returns the maximum widths for the columns in this table layout. |
Dimension |
maximumLayoutSize(Container parent)
Returns the maximum size for this table layout. |
int |
maximumRowHeight(int row)
Returns the actual maximum height for the given row. |
int[] |
maximumRowHeights()
Returns the maximum heights for the rows in this table layout. |
int |
minimumColumnWidth(int col)
Returns the actual minimum width for the given column. |
int[] |
minimumColumnWidths()
Returns the minimum widths for the columns in this table layout. |
Dimension |
minimumLayoutSize(Container parent)
Returns the minimum size for this table layout. |
int |
minimumRowHeight(int row)
Returns the actual minimum height for the given row. |
int[] |
minimumRowHeights()
Returns the minimum heights for the rows in this table layout. |
int |
preferredColumnWidth(int col)
Returns the actual preferred width for the given column. |
int[] |
preferredColumnWidths()
Returns the preferred widths for the columns in this table layout. |
Dimension |
preferredLayoutSize(Container parent)
Returns the preferred size for this table layout. |
int |
preferredRowHeight(int row)
Returns the actual preferred height for the given row. |
int[] |
preferredRowHeights()
Returns the preferred heights for the rows in this table layout. |
void |
removeLayoutComponent(CellPosition position)
Removes the component at the given CellPosition
from the data structure of this layout. |
void |
removeLayoutComponent(Component c)
Removes the given component from the data structure of this layout. |
void |
removeLayoutComponent(int row,
int col)
Removes the component at the given row,col position from the data structure of this layout. |
void |
setAllMinimumColumnWidths(int width)
Sets all minimum column widths to the same value. |
void |
setAllMinimumRowHeights(int height)
Sets all minimum row heights to the same value. |
void |
setCellAlignment(CellPosition p,
int align)
Sets the alignment for the cell at the given position to the given alignment value. |
void |
setCellAlignment(int row,
int col,
int align)
Sets the alignment for the cell at the given position to the given alignment value. |
(package private) void |
setCellAlignmentImpl(int row,
int col,
int align)
Sets the alignment for the cell at the given position to the given alignment value. |
void |
setColumnAlignment(int col,
int align)
Sets the alignment for cells in the given column to the given alignment value. |
(package private) void |
setColumns(int colCount)
Sets the number of columns in this table layout to the given number of columns. |
void |
setHorizontalGap(int hgap)
Sets the gap between columns in this table layout to the given value, in pixels. |
void |
setMinimumColumnWidth(int col,
int width)
Sets the minimum width for the given column to the given width in pixels. |
void |
setMinimumRowHeight(int row,
int height)
Sets the minimum height for the given row to the given height in pixels. |
void |
setOrientation(int orientation)
Sets the orientation for this table layout to the given orientation value. |
void |
setRowAlignment(int row,
int align)
Sets the alignment for cells in the given row to the given alignment value. |
(package private) void |
setRows(int rowCount)
Sets the number of rows in this table to the given number of rows. |
void |
setTableAlignment(int align)
Sets the alignment for cells in this table layout to the given alignment value. |
void |
setVerticalGap(int vgap)
Sets the gap between rows in this table layout to the given value, in pixels. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int DEFAULT_ALIGNMENT
public static final int DEFAULT_ORIENTATION
public static final int NO_ALIGNMENT_SET
public static final int INVALID_ALIGNMENT
public static final int NO_MINIMUM_SET
protected int rows
protected int cols
protected int hgap
protected int vgap
protected Component[][] table
protected int orientation
protected int tableAlignment
protected int[] rowAlignment
protected int[] colAlignment
protected int[][] cellAlignment
protected int[] minRowHeight
protected int[] minColWidth
| Constructor Detail |
public TableLayout(int rows,
int cols)
rows - the number of rows in this table layoutcols - the number of columns in this table layoutTableLayout(int, int, int),
TableLayout(int, int, int, int),
TableLayout(int, int, int, int, int),
TableLayout(int, int, int, int, int, int)
public TableLayout(int rows,
int cols,
int align)
rows - the number of rows in this table layoutcols - the number of columns in this table layoutalign - the default table cell alignmentTableLayout(int, int),
TableLayout(int, int, int, int),
TableLayout(int, int, int, int, int),
TableLayout(int, int, int, int, int, int),
JPTConstants.DEFAULT
public TableLayout(int rows,
int cols,
int hgap,
int vgap)
rows - the number of rows in this table layoutcols - the number of columns in this table layouthgap - the gap between columns, in pixelsvgap - the gap between rows, in pixelsTableLayout(int, int),
TableLayout(int, int, int),
TableLayout(int, int, int, int, int),
TableLayout(int, int, int, int, int, int)
public TableLayout(int rows,
int cols,
int hgap,
int vgap,
int align)
rows - the number of rows in this table layoutcols - the number of columns in this table layouthgap - the gap between columns, in pixelsvgap - the gap between rows, in pixelsalign - the default table cell alignmentTableLayout(int, int),
TableLayout(int, int, int),
TableLayout(int, int, int, int),
TableLayout(int, int, int, int, int, int),
JPTConstants.DEFAULT
public TableLayout(int rows,
int cols,
int hgap,
int vgap,
int align,
int orientation)
rows - the number of rows in this table layoutcols - the number of columns in this table layouthgap - the gap between columns, in pixelsvgap - the gap between rows, in pixelsalign - the default table cell alignmentorientation - the table layout orientationTableLayout(int, int),
TableLayout(int, int, int),
TableLayout(int, int, int, int),
TableLayout(int, int, int, int, int),
JPTConstants.DEFAULT| Method Detail |
public void addLayoutComponent(Component c,
Object position)
CellPosition,
the given component is added at the next available position.
If the given position is beyond
the number of rows or columns in this table,
the table is grown to accept the component
at the given position.
addLayoutComponent in interface LayoutManager2c - a component to be addedposition - the cell position for the componentaddLayoutComponent(String, Component),
getNextAvailablePosition()
public void addLayoutComponent(String name,
Component c)
addLayoutComponent in interface LayoutManagername - the name for the given component (ignored)c - a component to be addedaddLayoutComponent(Component, Object)public void removeLayoutComponent(Component c)
Removes the given component from the data structure of this layout.
If the given component is not in this layout, this layout is not changed.
removeLayoutComponent in interface LayoutManagerc - a component to be removed
public void removeLayoutComponent(int row,
int col)
Removes the component at the given row,col position from the data structure of this layout.
Does nothing if row,col is invalid.
row - the row position of the cell to removecol - the col position of the cell to removepublic void removeLayoutComponent(CellPosition position)
Removes the component at the given
CellPosition
from the data structure of this layout.
Does nothing if position
is null or invalid.
position - the CellPosition
of the cell to removepublic void invalidateLayout(Container parent)
invalidateLayout in interface LayoutManager2parent - the parent container for this layoutpublic void layoutContainer(Container parent)
layoutContainer in interface LayoutManagerparent - the parent container for this layoutpublic Dimension minimumLayoutSize(Container parent)
minimumLayoutSize in interface LayoutManagerparent - the parent container for this layoutpreferredLayoutSize(Container),
maximumLayoutSize(Container)public Dimension preferredLayoutSize(Container parent)
preferredLayoutSize in interface LayoutManagerparent - the parent container for this layoutminimumLayoutSize(Container),
maximumLayoutSize(Container)public Dimension maximumLayoutSize(Container parent)
maximumLayoutSize in interface LayoutManager2parent - the parent container for this layoutminimumLayoutSize(Container),
preferredLayoutSize(Container)public float getLayoutAlignmentX(Container target)
getLayoutAlignmentX in interface LayoutManager2target - the parent container for this layoutgetLayoutAlignmentY(Container)public float getLayoutAlignmentY(Container target)
getLayoutAlignmentY in interface LayoutManager2target - the parent container for this layoutgetLayoutAlignmentX(Container)public Component[][] getComponentTable()
public Component getTableEntry(int row,
int col)
Returns the component at the given row,col position in the table layout data structure.
Returns null if the position is invalid
or if there is no component in that cell.
row - the row position of the cellcol - the col position of the cellpublic Component getTableEntry(CellPosition position)
Returns the component at the given
CellPosition position
in the table layout data structure.
Returns null if position
is null or invalid.
position - the CellPosition of the cellpublic int getRowCount()
getColumnCount()public int getColumnCount()
getRowCount()public boolean isValidRow(int row)
row - the row in questionisValidColumn(int)public boolean isValidColumn(int col)
col - the column in questionisValidRow(int)public boolean isEmptyRow(int row)
row - the row in questionisEmptyColumn(int)public boolean isEmptyColumn(int col)
col - the column in questionisEmptyRow(int)public void setHorizontalGap(int hgap)
hgap - the desired gap, in pixelsgetHorizontalGap()public int getHorizontalGap()
setHorizontalGap(int)public void setVerticalGap(int vgap)
vgap - the desired gap, in pixelsgetVerticalGap()public int getVerticalGap()
setVerticalGap(int)public void setOrientation(int orientation)
Sets the orientation for this table layout to the given orientation value.
If the given orientation value is invalid, the orientation is not changed.
The default orientation is HORIZONTAL.
If the orientation is HORIZONTAL,
then the strategy for adding components whose position
is not explicitly specified is to add such components
column-by-column and to add new columns if needed.
If the orientation is VERTICAL,
then the strategy for adding components whose position
is not explicitly specified is to add such components
row-by-row and to add new rows if needed.
These policies are designed to be consistent with
the situation when the table layout is initially empty
and must be expanded at each step with either a
new column in the case of HORIZONTAL or a
new row in the case of VERTICAL.
orientation - the orientation for this layoutgetOrientation(),
SwingConstants.HORIZONTAL,
SwingConstants.VERTICAL,
JPTConstants.DEFAULTpublic int getOrientation()
setOrientation(int),
SwingConstants.HORIZONTAL,
SwingConstants.VERTICALpublic void setTableAlignment(int align)
align - the alignment value for cellsgetTableAlignment(),
JPTConstants.DEFAULTpublic int getTableAlignment()
setTableAlignment(int)
public void setRowAlignment(int row,
int align)
row - the row whose alignment is to be setalign - the alignment value for the rowgetRowAlignment(int),
JPTConstants.DEFAULTpublic int getRowAlignment(int row)
row - the row whose alignment value is desiredsetRowAlignment(int, int)
public void setColumnAlignment(int col,
int align)
col - the column whose alignment is to be setalign - the alignment value for the columngetColumnAlignment(int),
JPTConstants.DEFAULTpublic int getColumnAlignment(int col)
col - the column whose alignment value is desiredsetColumnAlignment(int, int)
public void setCellAlignment(CellPosition p,
int align)
p - the position of the cell whose alignment is to be changedalign - the alignment value for the cellsetCellAlignment(int, int, int),
getCellAlignment(CellPosition),
getCellAlignment(int, int),
getEffectiveCellAlignment(CellPosition),
getEffectiveCellAlignment(int, int),
JPTConstants.DEFAULT
public void setCellAlignment(int row,
int col,
int align)
row - the row for the cell whose alignment is to be changedcol - the column for the cell whose alignment is to be changedsetCellAlignment(CellPosition, int),
getCellAlignment(CellPosition),
getCellAlignment(int, int),
getEffectiveCellAlignment(CellPosition),
getEffectiveCellAlignment(int, int),
JPTConstants.DEFAULTpublic int getCellAlignment(CellPosition p)
p - the position of the cell whose alignment value is desiredsetCellAlignment(CellPosition, int),
setCellAlignment(int, int, int),
getCellAlignment(int, int),
getEffectiveCellAlignment(CellPosition),
getEffectiveCellAlignment(int, int),
JPTConstants.DEFAULT
public int getCellAlignment(int row,
int col)
row - the row for the cell whose alignment value is desiredcol - the column for the cell whose alignment value is desiredsetCellAlignment(CellPosition, int),
setCellAlignment(int, int, int),
getCellAlignment(CellPosition),
getEffectiveCellAlignment(CellPosition),
getEffectiveCellAlignment(int, int),
JPTConstants.DEFAULTpublic int getEffectiveCellAlignment(CellPosition p)
p - the position of the cell whose alignment value is desiredsetCellAlignment(CellPosition, int),
setCellAlignment(int, int, int),
getCellAlignment(CellPosition),
getCellAlignment(int, int),
getEffectiveCellAlignment(int, int),
JPTConstants.DEFAULT
public int getEffectiveCellAlignment(int row,
int col)
row - the row for the cell
whose alignment value is desiredcol - the column for the cell
whose alignment value is desiredsetCellAlignment(CellPosition, int),
setCellAlignment(int, int, int),
getCellAlignment(CellPosition),
getCellAlignment(int, int),
getEffectiveCellAlignment(CellPosition),
JPTConstants.DEFAULT
public void setMinimumRowHeight(int row,
int height)
row - the row whose minimum height is to be setheight - the height for the row in pixels
ArrayOutOfBoundsException - if the given row is invalidgetMinimumRowHeight(int)public int getMinimumRowHeight(int row)
row - the row whose minimum height is desired
ArrayOutOfBoundsException - if the given row is invalidsetMinimumRowHeight(int, int)public void setAllMinimumRowHeights(int height)
setMinimumRowHeight(int, int),
setAllMinimumColumnWidths(int)
public void setMinimumColumnWidth(int col,
int width)
col - the column whose minimum width is to be setwidth - the width for the column in pixels
ArrayOutOfBoundsException - if the given column is invalidgetMinimumColumnWidth(int)public int getMinimumColumnWidth(int col)
col - the column whose minimum width is desired
ArrayOutOfBoundsException - if the given column is invalidsetMinimumColumnWidth(int, int)public void setAllMinimumColumnWidths(int width)
setMinimumColumnWidth(int, int),
setAllMinimumRowHeights(int)public int minimumRowHeight(int row)
row - the row whose minimum height is desiredpreferredRowHeight(int),
maximumRowHeight(int)public int minimumColumnWidth(int col)
col - the column whose minimum width is desiredpreferredColumnWidth(int),
maximumColumnWidth(int)public int preferredRowHeight(int row)
row - the row whose preferred height is desiredminimumRowHeight(int),
maximumRowHeight(int)public int preferredColumnWidth(int col)
col - the column whose preferred width is desiredminimumColumnWidth(int),
maximumColumnWidth(int)public int maximumRowHeight(int row)
row - the row whose maximum height is desiredminimumRowHeight(int),
preferredRowHeight(int)public int maximumColumnWidth(int col)
col - the column whose maximum width is desiredminimumColumnWidth(int),
preferredColumnWidth(int)public int[] minimumRowHeights()
public int[] minimumColumnWidths()
public int[] preferredRowHeights()
public int[] preferredColumnWidths()
public int[] maximumRowHeights()
public int[] maximumColumnWidths()
protected void layoutContainer(int[] widths,
int[] heights,
Insets insets)
widths - the column widths for this layoutheights - the row heights for this layoutinsets - the insets of the parentprotected CellPosition getNextAvailablePosition()
Returns the next empty position in the table layout, that is, a position that does not contain a component; if the table layout is full, returns a new position that will require either adding a column or a row to the internal component table.
If the table orientation is HORIZONTAL,
then the strategy for adding components is to fill the
table column-by-column and to add new columns if needed.
Thus, for example, the cell position (1, 0) will be
returned before the cell position (0, 1) if both
cell positions are empty.
If the table layout is full, this method returns the
cell position (0, cols) that will require horizontal
expansion of the internal component table by the
layout manager.
If the table orientation is VERTICAL,
then the strategy for adding components is to fill the
table row-by-row and to add new rows if needed.
Thus, for example, the cell position (0, 1) will be
returned before the cell position (1, 0) if both
cell positions are empty.
If the table layout is full, this method returns the
cell position (rows, 0) that will require vertical
expansion of the internal component table by the
layout manager.
These policies are designed to be consistent with
the situation when the table layout is initially empty
and must be expanded at each step with either a
new column in the case of HORIZONTAL or a
new row in the case of VERTICAL.
Returns null if the orientation is set
improperly.
protected Point applyAlignment(int x,
int y,
int cellWidth,
int cellHeight,
int componentWidth,
int componentHeight,
int align)
x - the x-coordinate of the celly - the y-coordinate of the cellcellWidth - the width of the cellcellHeight - the height of the cellcomponentWidth - the width of the componentcomponentHeight - the height of the componentalign - the alignment value for the componentvoid setRows(int rowCount)
rowCount - the number of rows for this table layoutvoid setColumns(int colCount)
colCount - the number of columns for this table layout
void setCellAlignmentImpl(int row,
int col,
int align)
row - the row for the cellcol - the column for the cellalign - the alignment value for the given cellint adjustAlignment(int align)
INVALID_ALIGNMENT
if the given value is invalid.
align - the alignment value to adjust
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||