Class TablePanel

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

public class TablePanel
extends Panel
implements DrawingObj
This class creates a panel with a table canvas and a vertical scrollbar to the east of the canvas. Most of its methods are simply directing the method calls to the table canvas (instance of class TableCanvas) with methods of the same name (polymorphism).

Since this class is of type java.awt.Panel and the drawing panel is also of the same type, the layout manager of the drawing panel (DrawingPanel) has to be disabled prior to adding this table panel.

The way of adding the table panel to a drawing panel is similar to adding a histogram (they are of similar nature - both inheriting from java.awt.Panel).

The following line of codes can be used as an example to add a table panel to a drawing panel:

	TablePanel table = new TablePanel(max_table_size);
	drawingPanel.setLayout(null);
	drawingPanel.add(table);
	table.setDrawingPanel(drawingPanel);
	table.reshape(x, y, width, height);
 
drawingPanel is an instance of class DrawingPanel which is normally obtained by calling the getDrawingPanel() method from an instance of the AlgAnimFrame class:
 	drawingPanel = frame.getDrawingPanel();
 
where frame is the instance of the AlgAnimFrame class.

See Also:
TableCanvas, Histogram

Constructor Index

 o TablePanel(int)
Create a panel with a table canvas and a scrollbar to the east of the table canvas.

Method Index

 o addTableEntry(Object, int)
Pass the method call to the corresponding TableCanvas, which add an entry to the table and push the existing entries after this newly added object one position down.
 o contains(Object)
Pass the method call to the corresponding TableCanvas, which checks if the table contains a certain object specified by the parameter.
 o delay()
This method causes a delay of 200msec.
 o draw(Graphics)
Simply call the repaint() method of the table panel.
 o drawClusters(Graphics, int, int)
Pass the method call to the corresponding TableCanvas.
 o full()
Pass the method call to the corresponding TableCanvas, which checks if the table has been fully filled up.
 o getTableEntryAt(int)
Pass the method call to the corresponding TableCanvas, which obtains the object placed at the table row specified by the parameter.
 o getX()
Get the left most position of the table panel.
 o getY()
Get the top most position of the table panel.
 o handleEvent(Event)
The main purpose of this method is to handle the scrollbar event.
 o highlightRow(int)
Pass the method call to the corresponding TableCanvas, which highlights the table entry with the row specified by the parameter.
 o indexOf(Object)
Pass the method call to the corresponding TableCanvas, which gets the location of an object in the table.
 o init(int)
Set the size of the table and rescale the scrollbar governing the table.
 o numOccupied()
Pass the method call to the corresponding TableCanvas, which gets the number of rows in the table where the contents are non-null objects.
 o occupied(int)
Pass the method call to the corresponding TableCanvas, which checks if a particular row in the table has a non-null object.
 o restoreRow()
Pass the method call to the corresponding TableCanvas, which restores any highlighted row.
 o scroll2posn(int)
Scroll the display window of the table to shown the row specified by the parameter.
 o setDrawingPanel(DrawingPanel)
Set the parent panel where this table panel is going to reside.
 o setTableEntry(Object, int)
Pass the method call to the corresponding TableCanvas, which sets the object specified by the first parameter to the table row defined by the second parameter.
 o setTableSize(int)
Pass the method call to the corresponding TableCanvas, which sets the size of the table and hence rescale the scrollbar.
 o tableSize()
Pass the method call to the corresponding TableCanvas, which gets the maximum size of the table.

Constructors

 o TablePanel
 public TablePanel(int max_elem)
Create a panel with a table canvas and a scrollbar to the east of the table canvas. The maximum size of the table is initialized according to the parameter of this constructor.

Parameters:
max_elem - The maximum size of the table.

Methods

 o init
 public void init(int max_size)
Set the size of the table and rescale the scrollbar governing the table. This method calls the method with the same name in TableCanvas.

Parameters:
max_size - The maximum size of the table.
 o draw
 public void draw(Graphics g)
Simply call the repaint() method of the table panel.

 o getX
 public int getX()
Get the left most position of the table panel.

Returns:
The left most position of the table panel.
 o getY
 public int getY()
Get the top most position of the table panel.

Returns:
The top most position of the table panel.
 o full
 public boolean full()
Pass the method call to the corresponding TableCanvas, which checks if the table has been fully filled up.

Returns:
TRUE if all entries in the corresponding table canvas is non-null object; FALSE otherwise.
See Also:
full
 o numOccupied
 public int numOccupied()
Pass the method call to the corresponding TableCanvas, which gets the number of rows in the table where the contents are non-null objects.

Returns:
The number of non-null object in the table.
See Also:
numOccupied
 o occupied
 public boolean occupied(int i)
Pass the method call to the corresponding TableCanvas, which checks 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.
See Also:
occupied
 o drawClusters
 public void drawClusters(Graphics g,
                          int x,
                          int y)
Pass the method call to the corresponding TableCanvas. 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.

This method should be called from the draw method of one of the drawing object, which has been added to the drawing panel. For example, if an object class Eg has been defined to implement the DrawingObj interface, such that:

  class Eg implements DrawingObj {
      TablePanel table;
      ....
      public Eg(TablePanel table, ... ) {
          ....
          this.table = table;
      }
      ....
      public void draw(Graphics g) {
          ....
          if (table != null)
              table.drawClusters(g, x, y);
      }
  }
 
Adding an instance of this Eg class into the drawing panel (by using addDrawingObj) should result in drawing of the table status summary in the drawing panel with its top left corner at position (x, y).

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.
See Also:
TableCanvas@drawClusters
 o contains
 public boolean contains(Object obj)
Pass the method call to the corresponding TableCanvas, which checks if the table contains a certain object specified by the parameter.

Parameters:
obj - The object that is going to be checked for existence.
Returns:
TRUE if the object exists; FALSE otherwise.
See Also:
contains
 o indexOf
 public int indexOf(Object obj)
Pass the method call to the corresponding TableCanvas, which gets 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 a -1 if the object does not exist.
See Also:
indexOf
 o addTableEntry
 public void addTableEntry(Object obj,
                           int posn)
Pass the method call to the corresponding TableCanvas, which 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.
See Also:
addTableEntry
 o scroll2posn
 public void scroll2posn(int posn)
Scroll the display window of the table to shown the row specified by the parameter. If the parameter indicates a row that has already been in the current view window, nothing will happen.

Parameters:
posn - The row number of the table that will be displayed.
 o getTableEntryAt
 public Object getTableEntryAt(int posn)
Pass the method call to the corresponding TableCanvas, which obtains 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.
See Also:
getTableEntryAt
 o setTableEntry
 public void setTableEntry(Object obj,
                           int posn)
Pass the method call to the corresponding TableCanvas, which sets the object specified by the first parameter to the table row defined by the second parameter. The display window will scroll to include the row that has been newly added.

Parameters:
obj - The object to be added to the table.
posn - The row number where the object is going to be added.
See Also:
setTableEntry
 o setTableSize
 public void setTableSize(int i)
Pass the method call to the corresponding TableCanvas, which sets the size of the table and hence rescale the scrollbar.

Parameters:
size - The new size of this table.
See Also:
setTableSize
 o tableSize
 public int tableSize()
Pass the method call to the corresponding TableCanvas, which gets the maximum size of the table.

Returns:
The maximum size of the table.
See Also:
tableSize
 o highlightRow
 public void highlightRow(int i)
Pass the method call to the corresponding TableCanvas, which highlights the table entry with the row specified by the parameter. There can only be one row highlighted at any one time.

Parameters:
i - The row to be highlighted.
See Also:
highlightRow
 o restoreRow
 public void restoreRow()
Pass the method call to the corresponding TableCanvas, which restores any highlighted row.

See Also:
restoreRow
 o setDrawingPanel
 public void setDrawingPanel(DrawingPanel dpanel)
Set the parent panel where this table panel is going to reside.

Parameters:
dpanel - The parent drawing panel which this table panel resides.
 o handleEvent
 public boolean handleEvent(Event event)
The main purpose of this method is to handle the scrollbar event. The position of the scrollbar is obtained and used to position the view window of the table canvas.

Parameters:
event - The event captured.
Overrides:
handleEvent in class Component
 o delay
 public void delay()
This method causes a delay of 200msec.