# 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.

##

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

##

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

##

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.

##

init

     public void init()

  Initialize the table and set all entries to null.

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.

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.

restoreRow

     public void restoreRow()

  This method is used to restore any highlighted row.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

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

paint

     public void paint(Graphics g)

  Method to draw the table canvas.

  Overrides:
    paint in class Container

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.