Main Page | Namespace List | Class Hierarchy | Class List | Class Members | Related Pages

layout::TableLayout Class Reference

Inheritance diagram for layout::TableLayout:

Inheritance graph
[legend]
Collaboration diagram for layout::TableLayout:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TableLayout ()
 TableLayout (double size[][])
TableLayoutConstraints getConstraints (Component component)
void setConstraints (Component component, TableLayoutConstraints constraint)
void setColumn (double column[])
void setRow (double row[])
void setColumn (int i, double size)
void setRow (int i, double size)
double[] getColumn ()
double[] getRow ()
double getColumn (int i)
double getRow (int i)
int getNumColumn ()
int getNumRow ()
void insertColumn (int i, double size)
void insertRow (int i, double size)
void deleteColumn (int i)
void deleteRow (int i)
String toString ()
void drawGrid (Container container, Graphics g)
boolean hidden ()
boolean overlapping ()
void layoutContainer (Container container)
Dimension preferredLayoutSize (Container container)
Dimension minimumLayoutSize (Container container)
void addLayoutComponent (String name, Component component)
void addLayoutComponent (Component component, Object constraint)
void removeLayoutComponent (Component component)
Dimension maximumLayoutSize (Container target)
float getLayoutAlignmentX (Container parent)
float getLayoutAlignmentY (Container parent)
void invalidateLayout (Container target)

Protected Member Functions

void calculateSize (Container container)

Protected Attributes

double columnSpec []
double rowSpec []
int columnSize []
int rowSize []
int columnOffset []
int rowOffset []
LinkedList list
boolean dirty
int oldWidth
int oldHeight

Static Protected Attributes

final double defaultSize [][] = {{}, {}}

Detailed Description

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);
 <spc>
     // 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
 <spc>
     frame.setLayout (new TableLayout(size));
 <spc>
     // Create some buttons
     String label[] = {"Top", "Bottom", "Left", "Right", "Center", "Overlap"};
     Button button[] = new Button[label.length];
 <spc>
     for (int i = 0; i < label.length; i++)
         button[i] = new Button(label[i]);
 <spc>
     // 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
 <spc>
     // Allow user to close the window to terminate the program
     frame.addWindowListener
         (new WindowListener()
             {
                 public void windowClosing (WindowEvent e)
                 {
                     System.exit (0);
                 }
 <spc>
                 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) {}
             }
         );
 <spc>
     // Show frame
     frame.show();
 }
 

Author:
Daniel E. Barbalace


Constructor & Destructor Documentation

layout::TableLayout::TableLayout  )  [inline]
 

Constructs an instance of TableLayout. This TableLayout will have one row and one column.

layout::TableLayout::TableLayout double  size[][]  )  [inline]
 

Constructs an instance of TableLayout.

Parameters:
size widths of columns and heights of rows in the format, {{col0, col1, col2, ..., colN}, {row0, row1, row2, ..., rowM}} If this parameter is invalid, the TableLayout will have exactly one row and one column.


Member Function Documentation

void layout::TableLayout::addLayoutComponent Component  component,
Object  constraint
[inline]
 

Adds the specified component with the specified name to the layout.

Parameters:
component component to add
constraint indicates entry's position and alignment

void layout::TableLayout::addLayoutComponent String  name,
Component  component
[inline]
 

Adds the specified component with the specified name to the layout.

Parameters:
name indicates entry's position and anchor
component component to add

void layout::TableLayout::calculateSize Container  container  )  [inline, protected]
 

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. The result is stored in rowSize and columnSize.

Parameters:
container container using this TableLayout

void layout::TableLayout::deleteColumn int  i  )  [inline]
 

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.

Parameters:
i zero-based index of column to delete
See also:
setColumn(int,double) setColumn(int,double)

deleteColumn(int) deleteColumn(int)

void layout::TableLayout::deleteRow int  i  )  [inline]
 

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.

Parameters:
i zero-based index of column to delete
See also:
setRow(int,double) setRow(int,double)

setRow(double[]) setRow(double[])

deleteRow(int) deleteRow(int)

void layout::TableLayout::drawGrid Container  container,
Graphics  g
[inline]
 

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.

Parameters:
container container using this TableLayout
g graphics content of container (can be offscreen)

double layout::TableLayout::getColumn int  i  )  [inline]
 

Gets the width of a single column in this layout.

Parameters:
i zero-based index of row to get. If this parameter is not valid, an ArrayOutOfBoundsException will be thrown.
Returns:
width of the requested column
See also:
setRow(int,double) setRow(int,double)

double [] layout::TableLayout::getColumn  )  [inline]
 

Gets the sizes of columns in this layout.

Returns:
widths of each of the columns
See also:
setColumn(double[])

TableLayoutConstraints layout::TableLayout::getConstraints Component  component  )  [inline]
 

Gets the constraints of a given component.

Parameters:
component desired component
Returns:
If the given component is found, the constraints associated with that component. If the given component is null or is not found, null is returned.

float layout::TableLayout::getLayoutAlignmentX Container  parent  )  [inline]
 

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:
unconditionally, 0.5

float layout::TableLayout::getLayoutAlignmentY Container  parent  )  [inline]
 

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:
unconditionally, 0.5

int layout::TableLayout::getNumColumn  )  [inline]
 

Gets the number of columns in this layout.

Returns:
the number of columns

int layout::TableLayout::getNumRow  )  [inline]
 

Gets the number of rows in this layout.

Returns:
the number of rows

double layout::TableLayout::getRow int  i  )  [inline]
 

Gets the sizes of a row in this layout.

Parameters:
i zero-based index of row to get. If this parameter is not valid, an ArrayOutOfBoundsException will be thrown.
Returns:
height of each of the requested row
See also:
setRow(int,double) setRow(int,double)

setRow(double[]) setRow(double[])

double [] layout::TableLayout::getRow  )  [inline]
 

Gets the height of a single row in this layout.

Returns:
height of the requested row
See also:
setRow(double[]) setRow(double[])

boolean layout::TableLayout::hidden  )  [inline]
 

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.

Returns:
True, if there are any hidden components. False, otherwise.
See also:
overlapping() overlapping()

void layout::TableLayout::insertColumn int  i,
double  size
[inline]
 

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.

Parameters:
i zero-based index at which to insert the column.
size size of the column to be inserted
See also:
setColumn(int,double) setColumn(int,double)

deleteColumn(int) deleteColumn(int)

void layout::TableLayout::insertRow int  i,
double  size
[inline]
 

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.

Parameters:
i zero-based index at which to insert the column.
size size of the row to be inserted
See also:
setRow(int,double) setRow(int,double)

setRow(double[]) setRow(double[])

deleteRow(int) deleteRow(int)

void layout::TableLayout::invalidateLayout Container  target  )  [inline]
 

Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

void layout::TableLayout::layoutContainer Container  container  )  [inline]
 

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.

Parameters:
container container being served by this layout manager

Dimension layout::TableLayout::maximumLayoutSize Container  target  )  [inline]
 

Returns the maximum dimensions for this layout given the components in the specified target container.

Parameters:
target the component which needs to be laid out
Returns:
unconditionally, a Dimension of Integer.MAX_VALUE by Integer.MAX_VALUE since TableLayout does not limit the maximum size of a container

Dimension layout::TableLayout::minimumLayoutSize Container  container  )  [inline]
 

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.

Parameters:
container container being served by this layout manager
Returns:
a dimension indicating the container's minimum size

boolean layout::TableLayout::overlapping  )  [inline]
 

Determines whether or not there are any overlapping components. Two components overlap if they cover at least one common cell.

Returns:
True, if there are any overlapping components. False, otherwise.
See also:
hidden() hidden()

Dimension layout::TableLayout::preferredLayoutSize Container  container  )  [inline]
 

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.

Parameters:
container container being served by this layout manager
Returns:
a dimension indicating the container's preferred size

void layout::TableLayout::removeLayoutComponent Component  component  )  [inline]
 

Removes the specified component from the layout.

Parameters:
component component being removed

void layout::TableLayout::setColumn int  i,
double  size
[inline]
 

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();

or

     window.pack()
 

If this is not done, the changes in the layout will not be seen until the container is resized.

Parameters:
i zero-based index of column to set. If this parameter is not valid, an ArrayOutOfBoundsException will be thrown.
size width of the column. This parameter cannot be null.
See also:
getColumn() getColumn()

getColumn(int) getColumn(int)

void layout::TableLayout::setColumn double  column[]  )  [inline]
 

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();
 

or

     window.pack()
 

If this is not done, the changes in the layout will not be seen until the container is resized.

Parameters:
column heights of each of the columns
See also:
getColumn() getColumn()

getColumn(int) getColumn(int)

void layout::TableLayout::setConstraints Component  component,
TableLayoutConstraints  constraint
[inline]
 

Sets the constraints of a given component. If the given component is found, the constraints associated with that component. If the given component is null or is not found, null is returned.

Parameters:
component desired component. This parameter cannot be null.
constraint new set of constraints. This parameter cannot be null.

void layout::TableLayout::setRow int  i,
double  size
[inline]
 

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();

or

     window.pack()
 

If this is not done, the changes in the layout will not be seen until the container is resized.

Parameters:
i zero-based index of row to set. If this parameter is not valid, an ArrayOutOfBoundsException will be thrown.
size height of the row. This parameter cannot be null.
See also:
getRow(int) getRow(int)

void layout::TableLayout::setRow double  row[]  )  [inline]
 

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();

or

     window.pack()
 

If this is not done, the changes in the layout will not be seen until the container is resized.

Parameters:
row widths of each of the rows. This parameter cannot be null.
See also:
getRow() getRow()

String layout::TableLayout::toString  )  [inline]
 

Converts this TableLayout to a string.

Returns:
a string representing the columns and row sizes in the form "{{col0, col1, col2, ..., colN}, {row0, row1, row2, ..., rowM}}"


Member Data Documentation

int layout::TableLayout::columnOffset[] [protected]
 

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

int layout::TableLayout::columnSize[] [protected]
 

Widths of columns in pixels

double layout::TableLayout::columnSpec[] [protected]
 

Widths of columns expressed in absolute and relative terms

final double layout::TableLayout::defaultSize[][] = {{}, {}} [static, protected]
 

Default row/column size

boolean layout::TableLayout::dirty [protected]
 

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.

LinkedList layout::TableLayout::list [protected]
 

List of components and their sizes

int layout::TableLayout::oldHeight [protected]
 

Previous known height of the container

int layout::TableLayout::oldWidth [protected]
 

Previous known width of the container

int layout::TableLayout::rowOffset[] [protected]
 

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

int layout::TableLayout::rowSize[] [protected]
 

Heights of rows in pixels

double layout::TableLayout::rowSpec[] [protected]
 

Heights of rows expressed in absolute and relative terms


The documentation for this class was generated from the following file:
Generated on Wed Jan 19 17:03:05 2005 by  doxygen 1.3.9.1