org.ka2ddo.yaac.gui
Class ObjectPacketModel

java.lang.Object
  extended by org.ka2ddo.yaac.gui.ObjectPacketModel
All Implemented Interfaces:
javax.swing.table.TableModel, TrackerListener, AprsMessageContainingModel, ColumnSizingTableModel, FastComparableTableModel

public class ObjectPacketModel
extends java.lang.Object
implements javax.swing.table.TableModel, TrackerListener, AprsMessageContainingModel, FastComparableTableModel

This class is a table model for viewing all the historical messages received about a given object, as stored in its associated StationState object.


Constructor Summary
ObjectPacketModel(StationState ss, StationTracker tracker)
           
 
Method Summary
 void addTableModelListener(javax.swing.event.TableModelListener l)
          Adds a listener to the list that is notified each time a change to the data model occurs.
 int compareRows(int rowIndex1, int rowIndex2, int columnIndex)
          Compare the selected column of the two rows.
 java.lang.Class<?> getColumnClass(int columnIndex)
          Returns the most specific superclass for all the cell values in the column.
 int getColumnCount()
          Returns the number of columns in the model.
 java.lang.String getColumnName(int columnIndex)
          Returns the name of the column at columnIndex.
 int getColumnWidth(int columnIndex)
          Specifies the default initial width of a column from this model.
 AX25Message getMessageAt(int rowIndex)
          Fetch the AX25Message object at the specified index.
 int getRowCount()
          Returns the number of rows in the model.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns true if the cell at rowIndex and columnIndex is editable.
 boolean isSizeToFit(int columnIndex)
          Specifies whether setWidthToFit() should be enabled on this column
 void messageAdded(StationState ss, int index, AX25Message msg)
          Called when a Message is added to the history for a station in the tracker.
 void messageDeleted(StationState ss, int index, AX25Message msg)
          Called when a AX25Message is deleted from the history for a station in the tracker.
 void removeTableModelListener(javax.swing.event.TableModelListener l)
          Removes a listener from the list that is notified each time a change to the data model occurs.
 void setMode(RawPacketDisplayMode mode)
          Specify what display mode should be used to present the message body of the specified message when the body's column is requested with the getValueAt() method.
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
          Sets the value in the cell at columnIndex and rowIndex to aValue.
 void stationAdded(StationState ss, int index)
          Called when a new station is initially added to the tracker.
 void stationDeleted(StationState ss, int index)
          Called when an existing station is deleted from the tracker.
 void stationUpdated(StationState ss)
          Called when an existing station is updated with new information in the tracker.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectPacketModel

public ObjectPacketModel(StationState ss,
                         StationTracker tracker)
Method Detail

getRowCount

public int getRowCount()
Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
the number of rows in the model
See Also:
getColumnCount()

getColumnCount

public int getColumnCount()
Returns the number of columns in the model.

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
the number of columns in the model
See Also:
getRowCount()

getColumnName

public java.lang.String getColumnName(int columnIndex)
Returns the name of the column at columnIndex. This is used to initialize the table's column header name. Note: this name does not need to be unique; two columns in a table can have the same name.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Parameters:
columnIndex - the index of the column
Returns:
the name of the column

getColumnClass

public java.lang.Class<?> getColumnClass(int columnIndex)
Returns the most specific superclass for all the cell values in the column. This is used by the JTable to set up a default renderer and editor for the column.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Parameters:
columnIndex - the index of the column
Returns:
the common ancestor class of the object values in the model.

compareRows

public int compareRows(int rowIndex1,
                       int rowIndex2,
                       int columnIndex)
Compare the selected column of the two rows.

Specified by:
compareRows in interface FastComparableTableModel
Parameters:
rowIndex1 - zero-based model row index of first row to compare
rowIndex2 - zero-based model row index of second row to compare
columnIndex - zero-based model column index of column to compare
Returns:
+1 if the 1st row's column is after the 2nd row's column, -1 if before, or 0 if equal precedence

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns true if the cell at rowIndex and columnIndex is editable. Otherwise, setValueAt on the cell will not change the value of that cell.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Parameters:
rowIndex - the row whose value to be queried
columnIndex - the column whose value to be queried
Returns:
true if the cell is editable
See Also:
setValueAt(java.lang.Object, int, int)

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
rowIndex - the row whose value is to be queried
columnIndex - the column whose value is to be queried
Returns:
the value Object at the specified cell

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Sets the value in the cell at columnIndex and rowIndex to aValue.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Parameters:
aValue - the new value
rowIndex - the row whose value is to be changed
columnIndex - the column whose value is to be changed
See Also:
getValueAt(int, int), isCellEditable(int, int)

addTableModelListener

public void addTableModelListener(javax.swing.event.TableModelListener l)
Adds a listener to the list that is notified each time a change to the data model occurs.

Specified by:
addTableModelListener in interface javax.swing.table.TableModel
Parameters:
l - the TableModelListener

removeTableModelListener

public void removeTableModelListener(javax.swing.event.TableModelListener l)
Removes a listener from the list that is notified each time a change to the data model occurs.

Specified by:
removeTableModelListener in interface javax.swing.table.TableModel
Parameters:
l - the TableModelListener

getColumnWidth

public int getColumnWidth(int columnIndex)
Specifies the default initial width of a column from this model. Should only be queried at table creation time.

Specified by:
getColumnWidth in interface ColumnSizingTableModel
Parameters:
columnIndex - int index of the model's column whose width should be obtained
Returns:
the width, in the same units used by the TableColumn class's setWidth() method, or -1 to indicate the width should not be forced

isSizeToFit

public boolean isSizeToFit(int columnIndex)
Specifies whether setWidthToFit() should be enabled on this column

Specified by:
isSizeToFit in interface ColumnSizingTableModel
Parameters:
columnIndex - int index of the model's column whose width should be obtained
Returns:
boolean true if sizeWidthToFit() should be called on this column

getMessageAt

public AX25Message getMessageAt(int rowIndex)
                         throws java.lang.IndexOutOfBoundsException
Fetch the AX25Message object at the specified index.

Specified by:
getMessageAt in interface AprsMessageContainingModel
Parameters:
rowIndex - zero-based index to the specified Message
Returns:
AX25Message object
Throws:
java.lang.IndexOutOfBoundsException - if the row index is < 0 or >= the size of the Message list

setMode

public void setMode(RawPacketDisplayMode mode)
Specify what display mode should be used to present the message body of the specified message when the body's column is requested with the getValueAt() method. This method must be called from the AWT event thread.

Specified by:
setMode in interface AprsMessageContainingModel
Parameters:
mode - SnifferPacketDisplayMode enum specifying the display mode
See Also:
getValueAt(int, int)

stationAdded

public void stationAdded(StationState ss,
                         int index)
Called when a new station is initially added to the tracker.

Specified by:
stationAdded in interface TrackerListener
Parameters:
ss - StationState containing the station's information; the initial Message will not yet be stored within the StationState object
index - zero-based integer sequence number for this station in the StationTracker

stationUpdated

public void stationUpdated(StationState ss)
Called when an existing station is updated with new information in the tracker.

Specified by:
stationUpdated in interface TrackerListener
Parameters:
ss - StationState containing the station's information; the new Message will not yet be stored within the StationState object

stationDeleted

public void stationDeleted(StationState ss,
                           int index)
Called when an existing station is deleted from the tracker.

Specified by:
stationDeleted in interface TrackerListener
Parameters:
ss - StationState containing the station's information
index - zero-based integer sequence number for this station in the StationTracker

messageAdded

public void messageAdded(StationState ss,
                         int index,
                         AX25Message msg)
Called when a Message is added to the history for a station in the tracker.

Specified by:
messageAdded in interface TrackerListener
Parameters:
ss - StationState containing the station's information
index - zero-based index of the message added to the StationState object
msg - AX.25 Message object being added to the tracker

messageDeleted

public void messageDeleted(StationState ss,
                           int index,
                           AX25Message msg)
Called when a AX25Message is deleted from the history for a station in the tracker.

Specified by:
messageDeleted in interface TrackerListener
Parameters:
ss - StationState containing the station's information; the AX25Message will already be removed from the StationState object
index - zero-based index of the message removed from the StationState object
msg - APRS Message object being removed from the tracker; note that non-APRS packets that can still be decoded (such as OpenTRAC) will also be passed here; AX25Frames that cannot be decoded will pass null here