Class TableCanvas

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----TableCanvas

public class TableCanvas
extends Panel
This class creates a panel to display a table. It is only called from the TablePanel class which adds a scrollbar to the east of the table canvas.

This TableCanvas class should not have to be used manually. All its methods are redirected from the TablePanel class.


Constructor Index

 o TableCanvas(TablePanel)
Constructor method of the TableCanvas class.

Method Index

 o addTableEntry(Object, int)
Add an entry to the table and push the existing entries after this newly added object one position down.
 o contains(Object)
Check if the table contains a certain object specified by the parameter.
 o drawBox(Graphics, int, int, String, Color, Color, int)
This method is only called by the paint() method to draw each entry of the table as a box.
 o drawClusters(Graphics, int, int)
Display a status summary of the table regarding the percentage of the table being occupied, the number of clusters in the table, and a rough idea of the location of the table being occupied.
 o full()
Check if the table has been fully filled up.
 o getTableEntryAt(int)
Obtain the object placed at the table row specified by the parameter.
 o highlightRow(int)
Highlight the table entry with the row specified by the parameter.
 o indexOf(Object)
Get the location of an object in the table.
 o init()
Initialize the table and set all entries to null.
 o numOccupied()
Get the number of rows in the table where the contents are non-null object.
 o occupied(int)
Check if a particular row in the table has a non-null object.
 o paint(Graphics)
Method to draw the table canvas.
 o preferredSize()
Define the default size of the table.
 o restoreRow()
This method is used to restore any highlighted row.
 o setStart(int)
Set the starting row, which will be displayed by the table.
 o setTableEntry(Object, int)
Set the object specified by the first parameter to the table row defined by the second parameter.
 o setTableSize(int)
This method is called to set the size of the table and hence rescale the scrollbar on the panel it resides in.
 o tableSize()
Get the maximum size of the table (including all null and non-null objects).
 o update(Graphics)
This method is invoked by the display manager when the repaint() method of the panel is called.

Constructors

 o TableCanvas
 public TableCanvas(TablePanel parent)
Constructor method of the TableCanvas class.

Parameters:
parent - The panel with a scrollbar where this table canvas is going to reside.

Methods

 o init
 public void init()
Initialize the table and set all entries to null.

 o setStart
 public void setStart(int start)
Set the starting row, which will be displayed by the table.

Parameters:
start - The first row to be shown at any one time.
 o highlightRow
 public void highlightRow(int i)
Highlight the table entry with the row specified by the parameter. There can only be one row highlighted at any one time. If a row has already been highlighted and this highlightRow method is called on another different row, the previously highlighted row will be restored and the new row will be highlighted.

Parameters:
i - The row to be highlighted.
 o restoreRow
 public void restoreRow()
This method is used to restore any highlighted row.

 o setTableSize
 public void setTableSize(int size)
This method is called to set the size of the table and hence rescale the scrollbar on the panel it resides in.

Parameters:
size - The new size of this table.
 o setTableEntry
 public void setTableEntry(Object obj,
                           int posn)
Set the object specified by the first parameter to the table row defined by the second parameter.

Parameters:
obj - The object to be added to the table.
posn - The row number where the object is going to be added.
 o getTableEntryAt
 public Object getTableEntryAt(int posn)
Obtain the object placed at the table row specified by the parameter.

Parameters:
posn - Table row where the object is to be obtained.
Returns:
The table object at the row specified by the parameter.
 o full
 public boolean full()
Check if the table has been fully filled up.

Returns:
TRUE if all entries in the table is non-null object; FALSE otherwise.
 o numOccupied
 public int numOccupied()
Get the number of rows in the table where the contents are non-null object.

Returns:
The number of non-null object in the table.
 o occupied
 public boolean occupied(int i)
Check if a particular row in the table has a non-null object.

Parameters:
i - The row number of the table to be checked.
Returns:
TRUE if the row specified by the parameter is occupied.
 o drawClusters
 public void drawClusters(Graphics g,
                          int x,
                          int y)
Display a status summary of the table regarding the percentage of the table being occupied, the number of clusters in the table, and a rough idea of the location of the table being occupied.

Parameters:
g - Graphical context of the drawing panel where the status information is going to be shown.
x - The left most position of the status information display.
y - The top most position of the status information display.
 o addTableEntry
 public void addTableEntry(Object obj,
                           int posn)
Add an entry to the table and push the existing entries after this newly added object one position down.

Parameters:
obj - The new object to be added to the table.
posn - The position in the table (row) where the new object is to be added.
 o tableSize
 public int tableSize()
Get the maximum size of the table (including all null and non-null objects).

Returns:
The maximum size of the table.
 o contains
 public boolean contains(Object obj)
Check if the table contains a certain object specified by the parameter.

Parameters:
obj - The object which is going to be checked for existence.
Returns:
TRUE if the object exists; FALSE otherwise.
 o indexOf
 public int indexOf(Object obj)
Get the location of an object in the table.

Parameters:
obj - The object which location is being checked.
Returns:
The row number of the object passed in as the parameter. This method will return -1 if the object does not exist within the current table.
 o preferredSize
 public Dimension preferredSize()
Define the default size of the table.

Returns:
The dimension of the table. By default is: 480x320.
Overrides:
preferredSize in class Container
 o update
 public void update(Graphics g)
This method is invoked by the display manager when the repaint() method of the panel is called. This method is overridden here to eliminate the flashing characteristic during the panel update.

Overrides:
update in class Container
 o paint
 public void paint(Graphics g)
Method to draw the table canvas.

Overrides:
paint in class Container
 o drawBox
 public void drawBox(Graphics g,
                     int x,
                     int y,
                     String str,
                     Color fg,
                     Color bg,
                     int max_length)
This method is only called by the paint() method to draw each entry of the table as a box.

Parameters:
g - Graphical context.
x - The left most position of the box.
y - The top most position of the box.
str - The String object to be drawn inside the box.
fg - Foreground color (i.e. the text color) of the box.
bg - Background color of the box.
max_length - The max_length of the string to be displayed in the box.