gradeview.data
Class PeopleTableModel

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--gradeview.data.PeopleTableModel

public class PeopleTableModel
extends javax.swing.table.AbstractTableModel

A simple table model to keep track of people and their attributes. Everything is stored in a Vector table, whose items consists of HashMaps. These HashMaps keep track of a person's various attributes, such as name, e-mail address, and so on. For example, the following list of people:

could be added to a table using the following code: (Note: the Misc.buildHashMap(String) method is used to build the necessary HashMap. This reduces the amount of code needed to build the table's data.)

PeopleTableModel myModel = new AbstractPeopleTableModel();
myModel.add( Misc.buildHashMap( "name=David Ludwig,email=davidl@wpi.edu" );
myModel.add( Misc.buildHashMap( "name=James Abbatiello,email=abbeyj@wpi.edu" );
JTable myTable = new JTable( myModel );

See Also:
Serialized Form

Field Summary
protected  java.util.Vector peopleList
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
PeopleTableModel()
          Constructor.
 
Method Summary
 void add(java.util.HashMap newPerson)
          Adds a new person to the table.
 void delete(int row)
          Deletes one person/row from the table.
 void delete(int[] rows)
          Deletes multiple people/rows from the table.
 int getColumnCount()
          Gets the amount of columns in the table.
 java.lang.String getColumnName(int col)
          Gets the title/name of a particular column.
 int getRowCount()
          Gets the amount of rows in the table (which is equal to the number of people in the list.
 java.lang.Object getValueAt(int row, int col)
          Gets the value at the specified row and column.
 void read()
          Reads in a list of people from the database.
 void write()
          Writes the list of people to the database.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

peopleList

protected java.util.Vector peopleList
Constructor Detail

PeopleTableModel

public PeopleTableModel()
Constructor.
Method Detail

getColumnCount

public int getColumnCount()
Gets the amount of columns in the table.
Overrides:
getColumnCount in class javax.swing.table.AbstractTableModel
Returns:
The amount of columns in the table.

getRowCount

public int getRowCount()
Gets the amount of rows in the table (which is equal to the number of people in the list.
Overrides:
getRowCount in class javax.swing.table.AbstractTableModel
Returns:
The amount of rows (people) in the table.

getValueAt

public java.lang.Object getValueAt(int row,
                                   int col)
Gets the value at the specified row and column.
Overrides:
getValueAt in class javax.swing.table.AbstractTableModel
Parameters:
row - The row number (starting at 0 on the top of the table.)
col - The column index (starting at 0 on the left side of the table.)
Returns:
The value specified at row and col.

getColumnName

public java.lang.String getColumnName(int col)
Gets the title/name of a particular column.
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
col - The number of the column (starting at 0 on the left side of the table.
Returns:
The name of the column, specified by the col parameter.

add

public void add(java.util.HashMap newPerson)
Adds a new person to the table.
Parameters:
newPerson - The new person, represented as a HashMap. (See this class' description for information on the HashMap's structure.)
See Also:
Misc.buildHashMap(String)

delete

public void delete(int row)
Deletes one person/row from the table.
Parameters:
row - The row of the table to be deleted.

delete

public void delete(int[] rows)
Deletes multiple people/rows from the table.
Parameters:
rows - The rows to be deleted, represented by the type int[] (an array of ints.) IMPORTANT NOTE: The array must be sorted in ascending order. For example, the following array is sorted correctly: (0, 1, 3, 4, 6, 10)

read

public void read()
Reads in a list of people from the database.

write

public void write()
Writes the list of people to the database.