com.jstatcom.ts
Class TSTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.jstatcom.ts.TSTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public final class TSTableModel
extends javax.swing.table.AbstractTableModel

A table model to be used with the TSTable component for representing merged time series data. The model takes an array of time series with possibly different time ranges but equal sub periodicities and merges the series to a common time range, which includes all ranges.

Author:
Markus Kraetzig
See Also:
Serialized Form

Constructor Summary
TSTableModel()
          TSTableModel default constructor.
 
Method Summary
 int[] findRowIndexOf(java.lang.Double val, int startIndex)
          Finds the index of the row, where the given Double value appears first, starting from a given row index.
 java.lang.Class<java.lang.String> getColumnClass(int col)
          Gets column class.
 int getColumnCount()
          Gets number of displayed TS.
 java.lang.String getColumnName(int col)
          Gets the name of the TS displayed in a certain column.
 double getDoubleValueAt(int row, int col)
          Gets underlying observation for a given row and column as a double value.
 int getRowCount()
          Gets number of displayed observations in time range of all TS.
 javax.swing.JViewport getRowHeader(javax.swing.JTable table)
          Gets a JViewport that can be used as row header for a scrollpane.
 TSDate getStartTSDate()
          Gets the TSDate where the very first observation in the model occurs.
 java.lang.Object getValueAt(int row, int col)
          Gets underlying observation for a given row and column.
 boolean isCellEditable(int row, int col)
          Gets whether given cell can be edited.
 void setTS(TS[] tsArray)
          Sets the TS to be held by the model.
 void setValueAt(java.lang.Object obj, int row, int col)
          Sets data at a given position and displays an error message if input cannot be parsed to a double.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TSTableModel

public TSTableModel()
TSTableModel default constructor.

Method Detail

findRowIndexOf

public int[] findRowIndexOf(java.lang.Double val,
                            int startIndex)
Finds the index of the row, where the given Double value appears first, starting from a given row index. It also gives back the row with the closest match for val. In case of an exact match, both values are the same. In case of no exact match, the first value is -1 and the second the index of the row containing the value that is closest to val.

Parameters:
val - the value to search for
startIndex - index to start from, if out of range start from 0
Returns:
two dimensional integer array of indices:
  • int[0] row index of 1st exact match or -1 if no exact match or if val == null
  • int[1] row index of closest match or -1 if val == null
Throws:
java.lang.IllegalStateException - if (getRowCount() == 0)

getColumnClass

public java.lang.Class<java.lang.String> getColumnClass(int col)
Gets column class. The method always returns String.class, to make sure that the string editor is choosen.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
col - does not matter
Returns:
String.class

getColumnCount

public int getColumnCount()
Gets number of displayed TS.

Returns:
column count

getColumnName

public java.lang.String getColumnName(int col)
Gets the name of the TS displayed in a certain column.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
col - column index
Returns:
time series name

getDoubleValueAt

public double getDoubleValueAt(int row,
                               int col)
Gets underlying observation for a given row and column as a double value.

Returns:
the observation as double

getRowCount

public int getRowCount()
Gets number of displayed observations in time range of all TS.

Returns:
row count

getRowHeader

public javax.swing.JViewport getRowHeader(javax.swing.JTable table)
Gets a JViewport that can be used as row header for a scrollpane. This contains the time axis that can be shown with the table together with an index for the current row. Use the method with the JScrollPane that encloses a TSTable using this model.

Parameters:
table - the JTable to synchronize selection with
Returns:
JViewport to be used as a row header for a JScrollPane

getStartTSDate

public TSDate getStartTSDate()
Gets the TSDate where the very first observation in the model occurs.

Returns:
the starting date for all series in the model

getValueAt

public java.lang.Object getValueAt(int row,
                                   int col)
Gets underlying observation for a given row and column.

Parameters:
row - index for row
col - index for column
Returns:
a Double wrapping the observation

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Gets whether given cell can be edited. This is the same for all cells and set for the whole model via the editable property.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel
Parameters:
row - index for row
col - index for column
Returns:
the editable property for the whole table

setTS

public void setTS(TS[] tsArray)
Sets the TS to be held by the model. It merges the series and creates the data and names arrays.

Parameters:
tsArray - an array of TS objects with the same sub periodicity

setValueAt

public void setValueAt(java.lang.Object obj,
                       int row,
                       int col)
Sets data at a given position and displays an error message if input cannot be parsed to a double.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel
Parameters:
obj - Object that the method tries to parse to a Double
row - index for row
col - index for column