edu.uiuc.cs.net.DPRPManager
Class DPRPLeaseTableModel

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--edu.uiuc.cs.net.DPRPManager.DPRPLeaseTableModel
All Implemented Interfaces:
DPRPLeaseListener, DPRPLeaseListenerConstants, java.util.EventListener, java.io.Serializable, javax.swing.table.TableModel

class DPRPLeaseTableModel
extends javax.swing.table.AbstractTableModel
implements DPRPLeaseListener

This class represents my custom model for the lease management table. Because I want the data in the table to be dynamic, I had to create a model that understood DPRP. The table itself is actually just a view on this model. Thus, it is important to understand how the model gets its data. I decided to simply make the model a DPRPLeaseListener. This means, that whenever a DPRPClient instance fires a lease event, it will flow both into the main GUI code (for displaying any appropriate dialogs), but also into this code, which will update the table.

TODO: column text alignment & fonts.

Version:
0.9a - October 30th, 2001
Author:
Andy Reitz (areitz@cs.uiuc.edu)
See Also:
Serialized Form

Field Summary
private static int COL_EXTERNAL_IP
          External IP address column index.
private static int COL_FLAGS
          The column index for the flags.
private static int COL_PORT
          Reservation External Port column index.
private static int COL_PROTOCOL
          Reservation protocol column index.
private static int COL_RENEWALS
          The column index for the number of renewals.
private static int COL_STOP_TIME
          The halt time for the reservation, column index.
private  java.lang.String[] columnNames
          Human-readable text descriptions for each column.
private  java.util.Vector leaseData
          A list of all of the leases in the table.
private  int nextIndex
          The next index in the list to use (I'm sort of using this Vector like an array, so as to make the JTable happy).
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface edu.uiuc.cs.net.DPRPManager.DPRPLeaseListenerConstants
NEW_LEASE_EVENT, REMOVE_LEASE_EVENT, UPDATE_LEASE_EVENT
 
Constructor Summary
DPRPLeaseTableModel()
          Default constructor.
 
Method Summary
 java.lang.Class getColumnClass(int c)
          Gets the class of the column headers.
 int getColumnCount()
          Returns the number of columns in the table.
 java.lang.String getColumnName(int col)
          Gets the name of a specific column.
 DPRPLease getLeaseAt(int row)
          Fetches the DPRPLease object that backs a given row.
 int getRowCount()
          Returns the number of rows in the table.
private  java.lang.Object getTableData(DPRPLease lea, int column)
          Returns the data, in the appropriate format, for the given column in the given lease.
 java.lang.Object getValueAt(int row, int column)
          Gets the specific object behind a specific cell.
 void receiveLease(DPRPLeaseEvent ple)
          This method represnts a rather interesting design decision.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

COL_EXTERNAL_IP

private static final int COL_EXTERNAL_IP
External IP address column index.

COL_PORT

private static final int COL_PORT
Reservation External Port column index.

COL_PROTOCOL

private static final int COL_PROTOCOL
Reservation protocol column index.

COL_STOP_TIME

private static final int COL_STOP_TIME
The halt time for the reservation, column index.

COL_RENEWALS

private static final int COL_RENEWALS
The column index for the number of renewals.

COL_FLAGS

private static final int COL_FLAGS
The column index for the flags.

columnNames

private final java.lang.String[] columnNames
Human-readable text descriptions for each column.

leaseData

private java.util.Vector leaseData
A list of all of the leases in the table.

nextIndex

private int nextIndex
The next index in the list to use (I'm sort of using this Vector like an array, so as to make the JTable happy).
Constructor Detail

DPRPLeaseTableModel

public DPRPLeaseTableModel()
Default constructor. Simply creates a new vector, and sets nextIndex to zero.
Method Detail

getRowCount

public int getRowCount()
Returns the number of rows in the table.
Overrides:
getRowCount in class javax.swing.table.AbstractTableModel

getColumnCount

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

getColumnName

public java.lang.String getColumnName(int col)
Gets the name of a specific column. If the specified column is out of bounds, a runtime exception is thrown.
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
col - The column number to lookup.
Returns:
A string representation of the column number (typically the header).

getColumnClass

public java.lang.Class getColumnClass(int c)
Gets the class of the column headers.
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel

getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)
Gets the specific object behind a specific cell.
Overrides:
getValueAt in class javax.swing.table.AbstractTableModel

getLeaseAt

public DPRPLease getLeaseAt(int row)
Fetches the DPRPLease object that backs a given row.

getTableData

private java.lang.Object getTableData(DPRPLease lea,
                                      int column)
Returns the data, in the appropriate format, for the given column in the given lease. Overloaded from the default implementation provided by the superclass. Here are the formats, as they stand currently:

 COL_EXTERNAL_IP -- String
 COL_PORT        -- Integer
 COL_PROTOCOL    -- String
 COL_STOP_TIME   -- String, format varies depending upon date distance.
 COL_RENEWALS    -- Integer
 COL_FLAGS       -- HexString
 

receiveLease

public void receiveLease(DPRPLeaseEvent ple)
This method represnts a rather interesting design decision. By making this table model into a DPRPLeaseListener, it can intercept lease events directly. This means that the table will be updated without any direct intervention from the GUI code. The alternative would have been to simply have the receiveLease() handler in the GUI simply call methods on this model. But, that would have required making the model reference class-global, and also, it wouldn't have been anywhere near as slick as this!
Specified by:
receiveLease in interface DPRPLeaseListener
Parameters:
ple - A DPRPLeaseEvent, representing some sort of event that must be noted in the table.