|
|||||||||
| Home >> All >> org >> cantaloop >> tools >> [ layout overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.cantaloop.tools.layout
Class TableLayout

java.lang.Objectorg.cantaloop.tools.layout.TableLayout
- All Implemented Interfaces:
- java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable, TableLayoutConstants
- public class TableLayout
- extends java.lang.Object
- implements java.awt.LayoutManager2, java.io.Serializable, TableLayoutConstants
- extends java.lang.Object
TableLayout is a layout manager that arranges components in rows and columns like a spreadsheet. TableLayout allows each row or column to be a different size. A row or column can be given an absolute size in pixels, a percentage of the available space, or it can grow and shrink to fill the remaining space after other rows and columns have been resized.
Using spreadsheet terminology, a cell is the intersection of a row and column. Cells have finite, non-negative sizes measured in pixels. The dimensions of a cell depend solely upon the dimensions of its row and column.
A component occupies a rectangular group of one or more cells. If the component occupies more than one cell, the component is resized to fit perfectly in the rectangular region of cells. If the component occupies a single cell, it can be aligned in four ways within that cell.
A single cell component can be stretched horizontally to fit the cell (full justification), or it can be placed in the center of the cell. The component could also be left justified or right justified. Similarly, the component can be full, center, top, or bottom justified in the vertical.
public static void main (String args[])
{
// Create a frame
Frame frame = new Frame("Example of TableLayout");
frame.setBounds (100, 100, 300, 300);
// Create a TableLayout for the frame
double border = 10;
double size[][] =
{{border, 0.10, 20, TableLayout.FILL, 20, 0.20, border}, // Columns
{border, 0.20, 20, TableLayout.FILL, 20, 0.20, border}}; // Rows
frame.setLayout (new TableLayout(size));
// Create some buttons
String label[] = {"Top", "Bottom", "Left", "Right", "Center", "Overlap"};
Button button[] = new Button[label.length];
for (int i = 0; i < label.length; i++)
button[i] = new Button(label[i]);
// Add buttons
frame.add (button[0], "1, 1, 5, 1"); // Top
frame.add (button[1], "1, 5, 5, 5"); // Bottom
frame.add (button[2], "1, 3 "); // Left
frame.add (button[3], "5, 3 "); // Right
frame.add (button[4], "3, 3, c, c"); // Center
frame.add (button[5], "3, 3, 3, 5"); // Overlap
// Allow user to close the window to terminate the program
frame.addWindowListener
(new WindowListener()
{
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
public void windowOpened (WindowEvent e) {}
public void windowClosed (WindowEvent e) {}
public void windowIconified (WindowEvent e) {}
public void windowDeiconified (WindowEvent e) {}
public void windowActivated (WindowEvent e) {}
public void windowDeactivated (WindowEvent e) {}
}
);
// Show frame
frame.show();
}
| Nested Class Summary | |
protected class |
TableLayout.Entry
|
| Field Summary | |
protected int[] |
columnOffset
Offsets of columns in pixels. |
protected int[] |
columnSize
Widths of columns in pixels |
protected double[] |
columnSpec
Widths of columns expressed in absolute and relative terms |
protected static double[][] |
defaultSize
Default row/column size |
protected boolean |
dirty
Indicates whether or not the size of the cells are known for the last known size of the container. |
protected java.util.LinkedList |
list
List of components and their sizes |
protected int |
oldHeight
Previous known height of the container |
protected int |
oldWidth
Previous known width of the container |
protected int[] |
rowOffset
Offsets of rows in pixels. |
protected int[] |
rowSize
Heights of rows in pixels |
protected double[] |
rowSpec
Heights of rows expressed in absolute and relative terms |
| Fields inherited from interface org.cantaloop.tools.layout.TableLayoutConstants |
BOTTOM, CENTER, FILL, FULL, LEFT, MAX_ALIGN, MIN_ALIGN, MINIMUM, PREFERRED, RIGHT, TOP |
| Constructor Summary | |
TableLayout()
Constructs an instance of TableLayout. |
|
TableLayout(double[][] size)
Constructs an instance of TableLayout. |
|
| Method Summary | |
void |
addLayoutComponent(java.awt.Component component,
java.lang.Object constraint)
Adds the specified component with the specified name to the layout. |
void |
addLayoutComponent(java.lang.String name,
java.awt.Component component)
Adds the specified component with the specified name to the layout. |
protected int |
calculatePrefMinSize(int availableSize,
double typeOfSize,
boolean isColumn)
Assigned widths to preferred and minimum size columns and rows. |
protected void |
calculateSize(java.awt.Container container)
Calculates the sizes of the rows and columns based on the absolute and relative sizes specified in rowSpec and columnSpec
and the size of the container. |
void |
deleteColumn(int i)
Deletes a column in this layout. |
void |
deleteRow(int i)
Deletes a row in this layout. |
void |
drawGrid(java.awt.Container container,
java.awt.Graphics g)
Draws a grid on the given container. |
double[] |
getColumn()
Gets the sizes of columns in this layout. |
double |
getColumn(int i)
Gets the width of a single column in this layout. |
TableLayoutConstraints |
getConstraints(java.awt.Component component)
Gets the constraints of a given component. |
float |
getLayoutAlignmentX(java.awt.Container parent)
Returns the alignment along the x axis. |
float |
getLayoutAlignmentY(java.awt.Container parent)
Returns the alignment along the y axis. |
int |
getNumColumn()
Gets the number of columns in this layout. |
int |
getNumRow()
Gets the number of rows in this layout. |
double[] |
getRow()
Gets the height of a single row in this layout. |
double |
getRow(int i)
Gets the sizes of a row in this layout. |
boolean |
hidden()
Determines whether or not there are any hidden components. |
void |
insertColumn(int i,
double size)
Inserts a column in this layout. |
void |
insertRow(int i,
double size)
Inserts a row in this layout. |
void |
invalidateLayout(java.awt.Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
void |
layoutContainer(java.awt.Container container)
To lay out the specified container using this layout. |
java.awt.Dimension |
maximumLayoutSize(java.awt.Container target)
Returns the maximum dimensions for this layout given the components in the specified target container. |
java.awt.Dimension |
minimumLayoutSize(java.awt.Container container)
Determines the minimum size of the container argument using this layout. |
boolean |
overlapping()
Determines whether or not there are any overlapping components. |
java.awt.Dimension |
preferredLayoutSize(java.awt.Container container)
Determines the preferred size of the container argument using this layout. |
void |
removeLayoutComponent(java.awt.Component component)
Removes the specified component from the layout. |
void |
setColumn(double[] column)
Adjusts the number and sizes of rows in this layout. |
void |
setColumn(int i,
double size)
Adjusts the width of a single column in this layout. |
void |
setConstraints(java.awt.Component component,
TableLayoutConstraints constraint)
Sets the constraints of a given component. |
void |
setRow(double[] row)
Adjusts the number and sizes of rows in this layout. |
void |
setRow(int i,
double size)
Adjusts the height of a single row in this layout. |
java.lang.String |
toString()
Converts this TableLayout to a string. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
defaultSize
protected static final double[][] defaultSize
- Default row/column size
columnSpec
protected double[] columnSpec
- Widths of columns expressed in absolute and relative terms
rowSpec
protected double[] rowSpec
- Heights of rows expressed in absolute and relative terms
columnSize
protected int[] columnSize
- Widths of columns in pixels
rowSize
protected int[] rowSize
- Heights of rows in pixels
columnOffset
protected int[] columnOffset
- Offsets of columns in pixels. The left boarder of column n is at
columnOffset[n] and the right boarder is at columnOffset[n + 1] for all
columns including the last one. columnOffset.length = columnSize.length + 1
rowOffset
protected int[] rowOffset
- Offsets of rows in pixels. The left boarder of row n is at
rowOffset[n] and the right boarder is at rowOffset[n + 1] for all
rows including the last one. rowOffset.length = rowSize.length + 1
list
protected java.util.LinkedList list
- List of components and their sizes
dirty
protected boolean dirty
- Indicates whether or not the size of the cells are known for the last known
size of the container. If dirty is true or the container has been resized,
the cell sizes must be recalculated using calculateSize.
oldWidth
protected int oldWidth
- Previous known width of the container
oldHeight
protected int oldHeight
- Previous known height of the container
| Constructor Detail |
TableLayout
public TableLayout()
- Constructs an instance of TableLayout. This TableLayout will have one row
and one column.
TableLayout
public TableLayout(double[][] size)
- Constructs an instance of TableLayout.
| Method Detail |
getConstraints
public TableLayoutConstraints getConstraints(java.awt.Component component)
- Gets the constraints of a given component.
setConstraints
public void setConstraints(java.awt.Component component, TableLayoutConstraints constraint)
- Sets the constraints of a given component.
setColumn
public void setColumn(double[] column)
- Adjusts the number and sizes of rows in this layout. After calling this
method, the caller should request this layout manager to perform the
layout. This can be done with the following code:
layout.layoutContainer(container); container.repaint();orwindow.pack()If this is not done, the changes in the layout will not be seen until the container is resized.
setRow
public void setRow(double[] row)
- Adjusts the number and sizes of rows in this layout. After calling this
method, the caller should request this layout manager to perform the
layout. This can be done with the following code:
layout.layoutContainer(container); container.repaint();orwindow.pack()If this is not done, the changes in the layout will not be seen until the container is resized.
setColumn
public void setColumn(int i,
double size)
- Adjusts the width of a single column in this layout. After calling this
method, the caller should request this layout manager to perform the
layout. This can be done with the following code:
layout.layoutContainer(container); container.repaint();orwindow.pack()If this is not done, the changes in the layout will not be seen until the container is resized.
setRow
public void setRow(int i,
double size)
- Adjusts the height of a single row in this layout. After calling this
method, the caller should request this layout manager to perform the
layout. This can be done with the following code:
layout.layoutContainer(container); container.repaint();orwindow.pack()If this is not done, the changes in the layout will not be seen until the container is resized.
getColumn
public double[] getColumn()
- Gets the sizes of columns in this layout.
getRow
public double[] getRow()
- Gets the height of a single row in this layout.
getColumn
public double getColumn(int i)
- Gets the width of a single column in this layout.
getRow
public double getRow(int i)
- Gets the sizes of a row in this layout.
getNumColumn
public int getNumColumn()
- Gets the number of columns in this layout.
getNumRow
public int getNumRow()
- Gets the number of rows in this layout.
insertColumn
public void insertColumn(int i,
double size)
- Inserts a column in this layout. All components to the right of the
insertion point are moved right one column. The container will need to
be laid out after this method returns. See
setColumn.
insertRow
public void insertRow(int i,
double size)
- Inserts a row in this layout. All components below the insertion point
are moved down one row. The container will need to be laid out after this
method returns. See
setRow.
deleteColumn
public void deleteColumn(int i)
- Deletes a column in this layout. All components to the right of the
deletion point are moved left one column. The container will need to
be laid out after this method returns. See
setColumn.
deleteRow
public void deleteRow(int i)
- Deletes a row in this layout. All components below the deletion point are
moved up one row. The container will need to be laid out after this method
returns. See
setRow. There must be at least two rows in order to delete a row.
toString
public java.lang.String toString()
- Converts this TableLayout to a string.
drawGrid
public void drawGrid(java.awt.Container container, java.awt.Graphics g)
- Draws a grid on the given container. This is useful for seeing where the
rows and columns go. In the container's paint method, call this method.
hidden
public boolean hidden()
- Determines whether or not there are any hidden components. A hidden
component is one that will not be shown with this layout's current
configuration. Such a component is, at least partly, in an invalid row
or column. For example, on a table with five rows, row -1 and row 5 are both
invalid. Valid rows are 0 through 4, inclusively.
overlapping
public boolean overlapping()
- Determines whether or not there are any overlapping components. Two
components overlap if they cover at least one common cell.
calculateSize
protected void calculateSize(java.awt.Container container)
- Calculates the sizes of the rows and columns based on the absolute and
relative sizes specified in
rowSpecandcolumnSpecand the size of the container. The result is stored inrowSizeandcolumnSize.
calculatePrefMinSize
protected int calculatePrefMinSize(int availableSize,
double typeOfSize,
boolean isColumn)
- Assigned widths to preferred and minimum size columns and rows. This
reduces the available width and height. Minimum widths/heights must be
calculated first because they affect preferred widths/heights, but not vice
versa. The end result is that any component contained wholly or partly in
a column/row of minimum/preferred width will get at least its
minimum/preferred width, respectively.
layoutContainer
public void layoutContainer(java.awt.Container container)
- To lay out the specified container using this layout. This method reshapes
the components in the specified target container in order to satisfy the
constraints of all components.
User code should not have to call this method directly.
- Specified by:
layoutContainerin interfacejava.awt.LayoutManager
preferredLayoutSize
public java.awt.Dimension preferredLayoutSize(java.awt.Container container)
- Determines the preferred size of the container argument using this layout.
The preferred size is the smallest size that, if used for the container's
size, will ensure that all components are at least as large as their
preferred size. This method cannot guarantee that all components will be
their preferred size. For example, if component A and component B are each
allocate half of the container's width and component A wants to be 10 pixels
wide while component B wants to be 100 pixels wide, they cannot both be
accommodated. Since in general components rather be larger than their
preferred size instead of smaller, component B's request will be fulfilled.
The preferred size of the container would be 200 pixels.
- Specified by:
preferredLayoutSizein interfacejava.awt.LayoutManager
minimumLayoutSize
public java.awt.Dimension minimumLayoutSize(java.awt.Container container)
- Determines the minimum size of the container argument using this layout.
The minimum size is the smallest size that, if used for the container's
size, will ensure that all components are at least as large as their
minimum size. This method cannot guarantee that all components will be
their minimum size. For example, if component A and component B are each
allocate half of the container's width and component A wants to be 10 pixels
wide while component B wants to be 100 pixels wide, they cannot both be
accommodated. Since in general components rather be larger than their
minimum size instead of smaller, component B's request will be fulfilled.
The minimum size of the container would be 200 pixels.
- Specified by:
minimumLayoutSizein interfacejava.awt.LayoutManager
addLayoutComponent
public void addLayoutComponent(java.lang.String name, java.awt.Component component)
- Adds the specified component with the specified name to the layout.
- Specified by:
addLayoutComponentin interfacejava.awt.LayoutManager
addLayoutComponent
public void addLayoutComponent(java.awt.Component component, java.lang.Object constraint)
- Adds the specified component with the specified name to the layout.
- Specified by:
addLayoutComponentin interfacejava.awt.LayoutManager2
removeLayoutComponent
public void removeLayoutComponent(java.awt.Component component)
- Removes the specified component from the layout.
- Specified by:
removeLayoutComponentin interfacejava.awt.LayoutManager
maximumLayoutSize
public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
- Returns the maximum dimensions for this layout given the components in the
specified target container.
- Specified by:
maximumLayoutSizein interfacejava.awt.LayoutManager2
getLayoutAlignmentX
public float getLayoutAlignmentX(java.awt.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.
- Specified by:
getLayoutAlignmentXin interfacejava.awt.LayoutManager2
getLayoutAlignmentY
public float getLayoutAlignmentY(java.awt.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.
- Specified by:
getLayoutAlignmentYin interfacejava.awt.LayoutManager2
invalidateLayout
public void invalidateLayout(java.awt.Container target)
- Invalidates the layout, indicating that if the layout manager has cached
information it should be discarded.
- Specified by:
invalidateLayoutin interfacejava.awt.LayoutManager2
|
|||||||||
| Home >> All >> org >> cantaloop >> tools >> [ layout overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.cantaloop.tools.layout.TableLayout