java.lang.Object | +----java.awt.Component | +----java.awt.Container | +----java.awt.Panel | +----TablePanel
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:
where
drawingPanel = frame.getDrawingPanel();
frame
is the instance of the AlgAnimFrame
class.
TableCanvas
,
which add an entry to the table and push the existing entries after
this newly added object one position down.
TableCanvas
,
which checks if the table contains a certain object specified by
the parameter.
repaint()
method of the table panel.
TableCanvas
.
TableCanvas
,
which checks if the table has been fully filled up.
TableCanvas
,
which obtains the object placed at the table row specified by the
parameter.
TableCanvas
,
which highlights the table entry with the row specified by the
parameter.
TableCanvas
,
which gets the location of an object in the table.
TableCanvas
,
which gets the number of rows in the table where the contents are
non-null objects.
TableCanvas
,
which checks if a particular row in the table has a non-null object.
TableCanvas
,
which restores any highlighted row.
TableCanvas
,
which sets the object specified by the first parameter to the table
row defined by the second parameter.
TableCanvas
,
which sets the size of the table and hence rescale the scrollbar.
TableCanvas
,
which gets the maximum size of the table.
public TablePanel(int max_elem)
public void init(int max_size)
TableCanvas
.
public void draw(Graphics g)
repaint()
method of the table panel.
public int getX()
public int getY()
public boolean full()
TableCanvas
,
which checks if the table has been fully filled up.
public int numOccupied()
TableCanvas
,
which gets the number of rows in the table where the contents are
non-null objects.
public boolean occupied(int i)
TableCanvas
,
which checks if a particular row in the table has a non-null object.
public void drawClusters(Graphics g, int x, int y)
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:
Adding an instance of this
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);
}
}
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)
.
public boolean contains(Object obj)
TableCanvas
,
which checks if the table contains a certain object specified by
the parameter.
public int indexOf(Object obj)
TableCanvas
,
which gets the location of an object in the table.
public void addTableEntry(Object obj, int posn)
TableCanvas
,
which add an entry to the table and push the existing entries after
this newly added object one position down.
public void scroll2posn(int posn)
public Object getTableEntryAt(int posn)
TableCanvas
,
which obtains the object placed at the table row specified by the
parameter.
public void setTableEntry(Object obj, int posn)
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.
public void setTableSize(int i)
TableCanvas
,
which sets the size of the table and hence rescale the scrollbar.
public int tableSize()
TableCanvas
,
which gets the maximum size of the table.
public void highlightRow(int i)
TableCanvas
,
which highlights the table entry with the row specified by the
parameter. There can only be one row highlighted at any one time.
public void restoreRow()
TableCanvas
,
which restores any highlighted row.
public void setDrawingPanel(DrawingPanel dpanel)
public boolean handleEvent(Event event)
public void delay()