com.jstatcom.ts
Class TSTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- com.jstatcom.ts.TSTableModel
-
- All Implemented Interfaces:
- java.io.Serializable, javax.swing.table.TableModel
public final class TSTableModel extends javax.swing.table.AbstractTableModelA table model to be used with theTSTablecomponent 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.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description TSTableModel()TSTableModeldefault constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description int[]findRowIndexOf(java.lang.Double val, int startIndex)Finds the index of the row, where the givenDoublevalue appears first, starting from a given row index.java.lang.Class<java.lang.String>getColumnClass(int col)Gets column class.intgetColumnCount()Gets number of displayedTS.java.lang.StringgetColumnName(int col)Gets the name of theTSdisplayed in a certain column.doublegetDoubleValueAt(int row, int col)Gets underlying observation for a given row and column as adoublevalue.intgetRowCount()Gets number of displayed observations in time range of allTS.javax.swing.JViewportgetRowHeader(javax.swing.JTable table)Gets aJViewportthat can be used as row header for a scrollpane.TSDategetStartTSDate()Gets theTSDatewhere the very first observation in the model occurs.java.lang.ObjectgetValueAt(int row, int col)Gets underlying observation for a given row and column.booleanisCellEditable(int row, int col)Gets whether given cell can be edited.voidsetArrays(java.lang.Double[][] data, java.lang.String[] names)voidsetTS(TS[] tsArray)Sets theTSto be held by the model.voidsetValueAt(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.voidupdateTable(java.lang.String[] array)-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
-
-
-
Method Detail
-
findRowIndexOf
public int[] findRowIndexOf(java.lang.Double val, int startIndex)Finds the index of the row, where the givenDoublevalue appears first, starting from a given row index. It also gives back the row with the closest match forval. In case of an exact match, both values are the same. In case of no exact match, the first value is-1and the second the index of the row containing the value that is closest toval.- Parameters:
val- the value to search forstartIndex- 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-1if no exact match or ifval == nullint[1]row index of closest match or-1ifval == 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 returnsString.class, to make sure that the string editor is choosen.- Specified by:
getColumnClassin interfacejavax.swing.table.TableModel- Overrides:
getColumnClassin classjavax.swing.table.AbstractTableModel- Parameters:
col- does not matter- Returns:
- String.class
-
getColumnCount
public int getColumnCount()
Gets number of displayedTS.- Returns:
- column count
-
getColumnName
public java.lang.String getColumnName(int col)
Gets the name of theTSdisplayed in a certain column.- Specified by:
getColumnNamein interfacejavax.swing.table.TableModel- Overrides:
getColumnNamein classjavax.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 adoublevalue.- Returns:
- the observation as double
-
getRowCount
public int getRowCount()
Gets number of displayed observations in time range of allTS.- Returns:
- row count
-
getRowHeader
public javax.swing.JViewport getRowHeader(javax.swing.JTable table)
Gets aJViewportthat 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 theJScrollPanethat encloses aTSTableusing 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 theTSDatewhere 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 rowcol- 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 theeditableproperty.- Specified by:
isCellEditablein interfacejavax.swing.table.TableModel- Overrides:
isCellEditablein classjavax.swing.table.AbstractTableModel- Parameters:
row- index for rowcol- index for column- Returns:
- the editable property for the whole table
-
setTS
public void setTS(TS[] tsArray)
Sets theTSto be held by the model. It merges the series and creates the data and names arrays.- Parameters:
tsArray- an array ofTSobjects with the same sub periodicity
-
setArrays
public void setArrays(java.lang.Double[][] data, java.lang.String[] names)
-
updateTable
public void updateTable(java.lang.String[] array)
-
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:
setValueAtin interfacejavax.swing.table.TableModel- Overrides:
setValueAtin classjavax.swing.table.AbstractTableModel- Parameters:
obj- Object that the method tries to parse to aDoublerow- index for rowcol- index for column
-
-
DMelt 3.0 © DataMelt by jWork.ORG