Class Table

java.lang.Object
  |
  +--AbstractBox
        |
        +--AbstractFlexibleBox
              |
              +--Table
All Implemented Interfaces:
Box, FlexibleBox

public class Table
extends AbstractFlexibleBox

This class models a table. A table is a box with several child-boxes. The child-boxes are laid out in rows and columns. You have to call endTableRow() at the end of a row, so that the table knows how many boxes to put into each row.


Fields inherited from class AbstractFlexibleBox
boxes
 
Fields inherited from class AbstractBox
height, min_width, pref_width, width
 
Constructor Summary
Table()
           
 
Method Summary
 void doLayout(java.awt.Graphics g, javax.swing.JComponent comp, int w)
          Makes the table calculate it's width and height.
 void drawAt(int x, int y, DocumentView v)
          Draws the box with it's upper-left corner at (x, y).
 void endTableRow()
          Ends the current row.
 int getMinimumWidth()
          The minimum width of this box.
 int getPreferredWidth()
          The preferred width of this box.
 void insert(Box b)
          Inserts another box into this box.
 
Methods inherited from class AbstractFlexibleBox
isEmpty
 
Methods inherited from class AbstractBox
getHeight, getWidth, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface Box
getHeight, getWidth, toString
 

Constructor Detail

Table

public Table()
Method Detail

endTableRow

public void endTableRow()
Ends the current row. This method should be called at least once at the end of a row, so that the table knows how many cells to put in each row.

insert

public void insert(Box b)
Description copied from interface: FlexibleBox
Inserts another box into this box.
Overrides:
insert in class AbstractFlexibleBox

doLayout

public void doLayout(java.awt.Graphics g,
                     javax.swing.JComponent comp,
                     int w)
Makes the table calculate it's width and height. This is done by laying out the child-boxes in rows and columns. Because of the complicated calculations, each box will be asked to do layout twice.

The columns will be sized according to the contents. As a minimum, each column will be as wide as the greatest minimum width of the boxes in that column, so that the boxes doens't bleed into each other. If there's still room left, the rest of the width is distributed amoung the columns, so that the column that needs the most space gets the most space. If a column is at it's preferred size, then it won't be resized.

The rows will be as heigh as necessary to accomodate for the contents.

Overrides:
doLayout in class AbstractFlexibleBox
Parameters:
g - the graphics context. Some boxes, like TextFragments, need a graphics context before they can determine their width and height.
c - the component into which the box will be drawn. An ImageBox needs to know the component to calculate the width and height.
w - the width available for to the Box.

getPreferredWidth

public int getPreferredWidth()
The preferred width of this box. This is the sum of the preferred widths of the columns. The preferred width of a column is the greatest of the preferred widths of the cells in that column.

If the box is resized to it's preferred width, all the cells in each row would fit on a single line.

Overrides:
getPreferredWidth in class AbstractBox
Returns:
the preferred width of the box.

getMinimumWidth

public int getMinimumWidth()
The minimum width of this box. This is the sum of the minimum widths of the columns. The minimum width of a column is the greatest of the minimum widths of the cells in that column.
Overrides:
getMinimumWidth in class AbstractBox
Returns:
the preferred width of the box.

drawAt

public void drawAt(int x,
                   int y,
                   DocumentView v)
Description copied from interface: Box
Draws the box with it's upper-left corner at (x, y).
Overrides:
drawAt in class AbstractBox
Following copied from interface: Box
Parameters:
v - the DocumentView that does the actual drawing.
x - the x-coordinate of the upper-left corner.
x - the y-coordinate of the upper-left corner.