stella.jview
Class SensorTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by stella.jview.SensorTableModel
All Implemented Interfaces:
Serializable, Remote, TableModel, RmiDataCollecting, Initializable

public class SensorTableModel
extends AbstractTableModel
implements Initializable, RmiDataCollecting

A class that represents a table model for sensor data events. The data events received are stored in a hidden data map, which is queried from the getValueAt(int, int) method. As sensor tables should be small, there are always only four columns active, the sensor name, the current value, the minimum and the maximum value in the sampling period. The active set can be changed with a call to setActiveSource(int). To allow color-coding of the sensor readings (i.e. to define clear/bad sensors), the state of the sensor can be queried with getSensorState(int).
The table also implements the RmiDataCollecting interface to allow updates of the sensor readings from the outside.

See Also:
Serialized Form

Field Summary
private  long average
          The sampling interval of the table.
private  List columns
          The list of parameters.
private  Object[][] data
          The displayable data, a rowxcolumns array.
private static int EXPORTPORT
          The port where we want to export ourself.
private  List rows
          The list of sensor names.
private  int source
          The index of the first data column that is active.
private  int[] state
          The current state of the sensor.
private  String[] units
          The unit strings, filled on sensor data delivery.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
SensorTableModel(List sensors, List values)
          Constructs a new table model.
 
Method Summary
 int getActiveSource()
          Returns the active source.
 Class getColumnClass(int col)
          Returns the class object of the given column.
 int getColumnCount()
          Returns the number of columns to display.
 String getColumnName(int col)
          Returns the name of the sensor if column equal zero, otherwise the column label with offset source.
 int getRowCount()
          Returns the number of currently available targets.
 int getSensorState(int row)
          Returns the state of the sensor.
 Object getValueAt(int row, int col)
          Returns the value to display on the given row number.
 void init()
          Init simply assigns the data array.
 long rmiGetInterval()
          Returns the previously set sampling period.
 void rmiProcessData(Map readings, boolean weather)
          This method is called after the stella.sensor.ShortAverageRepository collected some data.
 void setActiveSource(int src)
          Sets the refresh interval.
 void setPeriod(long sample)
          Sets the averaging period of this table.
 void setValueAt(Object val, int row, int col)
          Sets the table value at the given index.
 void update(Map values)
          This method is called by the repository if the table's data should be updated.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

columns

private List columns
The list of parameters. Their name builds table columns.


rows

private List rows
The list of sensor names.


data

private Object[][] data
The displayable data, a rowxcolumns array.


units

private String[] units
The unit strings, filled on sensor data delivery.


state

private int[] state
The current state of the sensor.


average

private long average
The sampling interval of the table.


source

private int source
The index of the first data column that is active.


EXPORTPORT

private static final int EXPORTPORT
The port where we want to export ourself.

See Also:
Constant Field Values
Constructor Detail

SensorTableModel

public SensorTableModel(List sensors,
                        List values)
                 throws RemoteException
Constructs a new table model. Two lists are supplied, the list of sensor names to be displayed and the list of type of data in the columns.

Throws:
RemoteException
Method Detail

init

public void init()
Init simply assigns the data array. The number of parameters is the number of columns minus one.

Specified by:
init in interface Initializable

getColumnCount

public int getColumnCount()
Returns the number of columns to display. Always four.

Specified by:
getColumnCount in interface TableModel

getRowCount

public int getRowCount()
Returns the number of currently available targets. Relies on the value calculated during the most recent call to update(java.util.Map).

Specified by:
getRowCount in interface TableModel

getColumnName

public String getColumnName(int col)
Returns the name of the sensor if column equal zero, otherwise the column label with offset source.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnClass

public Class getColumnClass(int col)
Returns the class object of the given column. We are not sur on how JTable treats this, so we make sure that the internal data model always has the right run-time assignment.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

getValueAt

public Object getValueAt(int row,
                         int col)
Returns the value to display on the given row number.

Specified by:
getValueAt in interface TableModel

setValueAt

public void setValueAt(Object val,
                       int row,
                       int col)
Sets the table value at the given index. Called by rmiProcessData(java.util.Map, boolean). This method also fires a AbstractTableModel.fireTableDataChanged().

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel

getActiveSource

public int getActiveSource()
Returns the active source. This is the index in the sensor data to display.


setActiveSource

public void setActiveSource(int src)
Sets the refresh interval. This means that any timer task already present is canceled and a new timer task is constructed and scheduled. The first update occurs after the refresh interval.


getSensorState

public int getSensorState(int row)
Returns the state of the sensor.


setPeriod

public void setPeriod(long sample)
Sets the averaging period of this table. Needed for RmiDataCollecting.


rmiGetInterval

public long rmiGetInterval()
                    throws RemoteException
Returns the previously set sampling period.

Specified by:
rmiGetInterval in interface RmiDataCollecting
Throws:
RemoteException

rmiProcessData

public void rmiProcessData(Map readings,
                           boolean weather)
                    throws RemoteException
Description copied from interface: RmiDataCollecting
This method is called after the stella.sensor.ShortAverageRepository collected some data. In the argument, all sensors that have at least once in the liftime of the repository delivered data are mapped against the average DataEvent of all data events sent during the averaging period. Note that it is in principle possible that the sensor mapped has not produced a single data event in the last averaging period and therfore is mapped to null.

This version is the remote counterpart to DataCollecting. It should be used with data collectors that reside in a different VM than the repository

Specified by:
rmiProcessData in interface RmiDataCollecting
Throws:
RemoteException

update

public void update(Map values)
This method is called by the repository if the table's data should be updated. This method also fires a AbstractTableModel.fireTableDataChanged().