ikayaki.gui
Class MeasurementSequenceTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by ikayaki.gui.MeasurementSequenceTableModel
All Implemented Interfaces:
MeasurementListener, ProjectListener, Serializable, EventListener, TableModel

public class MeasurementSequenceTableModel
extends AbstractTableModel
implements ProjectListener, MeasurementListener

Handles the showing and editing of a project's measurement sequence. The columns that are being shown can be selected on a per project basis, and the selections are remembered even after the project has been closed.

Author:
Esko Luontola
See Also:
Serialized Form

Field Summary
private  List<SequenceColumn> possibleColumns
           
private  Project project
           
private static String VISIBLE_COLUMNS_PROPERTY
           
private  List<SequenceColumn> visibleColumns
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
MeasurementSequenceTableModel()
          Creates a new MeasurementSequenceTableModel with no active project.
 
Method Summary
 Class<?> getColumnClass(int columnIndex)
          Returns Object.class regardless of columnIndex.
 int getColumnCount()
          Returns the number of columns in the model.
 String getColumnName(int column)
          Returns a name for the column.
 String getColumnToolTip(int column)
          Returns the tooltip text for the specified column.
 SequenceColumn[] getPossibleColumns()
          Returns an array of columns that the current project can show.
 Project getProject()
          Returns the active project, or null if no project is active.
 int getRowCount()
          Returns the number of rows in the model.
 Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
private  void hideColumn(SequenceColumn column, boolean save)
          Hides the specified column.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns false.
 boolean isColumnVisible(SequenceColumn column)
          Tells if specified column is currently visible.
 void measurementUpdated(MeasurementEvent event)
          Refreshes the table to reflect the changes in the measurement steps.
 void projectUpdated(ProjectEvent event)
          Deprecated. The selected rows need to be saved before updating the table data, and that can only be done with access to the JTable. That's why it is on MeasurementSequencePanel's responsibility is to react to ProjectEvents and do the fireTableDataChanged().
private  void saveColumn(SequenceColumn column, boolean visible)
          Saves to the project's properties, whether the specified column should be shown or not.
 void setColumnVisible(SequenceColumn column, boolean visible)
          Sets visibility of the specified column.
 void setProject(Project project)
          Sets the project for this model.
 void setValueAt(Object data, int rowIndex, int columnIndex)
          Sets the value for the cell at columnIndex and rowIndex.
private  void showColumn(SequenceColumn column, boolean save)
          Shows the specified column.
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VISIBLE_COLUMNS_PROPERTY

private static final String VISIBLE_COLUMNS_PROPERTY
See Also:
Constant Field Values

project

private Project project

visibleColumns

private List<SequenceColumn> visibleColumns

possibleColumns

private List<SequenceColumn> possibleColumns
Constructor Detail

MeasurementSequenceTableModel

public MeasurementSequenceTableModel()
Creates a new MeasurementSequenceTableModel with no active project.

Method Detail

getProject

public Project getProject()
Returns the active project, or null if no project is active.


setProject

public void setProject(Project project)
Sets the project for this model. Unregisters MeasurementListener and ProjectListener from the old project, and registers them to the new project. Decides which colums to show in the table.

Parameters:
project - new active project, or null to make no project active.

projectUpdated

public void projectUpdated(ProjectEvent event)
Deprecated. The selected rows need to be saved before updating the table data, and that can only be done with access to the JTable. That's why it is on MeasurementSequencePanel's responsibility is to react to ProjectEvents and do the fireTableDataChanged().

Refreshes the table to reflect the changes in the project's data.

Specified by:
projectUpdated in interface ProjectListener
Parameters:
event - the event that happened.

measurementUpdated

public void measurementUpdated(MeasurementEvent event)
Refreshes the table to reflect the changes in the measurement steps.

Specified by:
measurementUpdated in interface MeasurementListener
Parameters:
event - the event that happened.

getPossibleColumns

public SequenceColumn[] getPossibleColumns()
Returns an array of columns that the current project can show. They are in the order of appearance.


showColumn

private void showColumn(SequenceColumn column,
                        boolean save)
Shows the specified column. Makes sure that the columns are always in the same order.

Parameters:
column - the column to be shown.
save - should this column change be saved to the project or not.

hideColumn

private void hideColumn(SequenceColumn column,
                        boolean save)
Hides the specified column.

Parameters:
column - the column to be hidden.
save - should this column change be saved to the project or not.

isColumnVisible

public boolean isColumnVisible(SequenceColumn column)
Tells if specified column is currently visible.

Parameters:
column - the column to be queried.
Returns:
true if the column is visible, otherwise false.
Throws:
NullPointerException - if column is null.

setColumnVisible

public void setColumnVisible(SequenceColumn column,
                             boolean visible)
Sets visibility of the specified column. Makes sure that the columns are always in the same order. Saves the visible columns to the project's properties.

Parameters:
column - the column to be changed.
visible - true if the column should be visible, otherwise false.
Throws:
NullPointerException - if column is null.

saveColumn

private void saveColumn(SequenceColumn column,
                        boolean visible)
Saves to the project's properties, whether the specified column should be shown or not. Will do nothing if the current project is null.

Parameters:
column - the column whose property is changed.
visible - true to show the column, false to hide it.

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 TableModel
Returns:
the number of rows in the model
See Also:
getColumnCount()

getColumnCount

public int getColumnCount()
Returns the number of columns in the model. A JTable uses this method to determine how many columns it should create and display by default.

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

getValueAt

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

Specified by:
getValueAt in interface 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(Object data,
                       int rowIndex,
                       int columnIndex)
Sets the value for the cell at columnIndex and rowIndex.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
data - new value of the cell
rowIndex - the row whose value is to be queried
columnIndex - the column whose value is to be queried

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns false. This is the default implementation for all cells.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
rowIndex - the row being queried
columnIndex - the column being queried
Returns:
false

getColumnName

public String getColumnName(int column)
Returns a name for the column. If column cannot be found, returns an empty string.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
column - the column being queried.
Returns:
a string containing the default name of column.

getColumnToolTip

public String getColumnToolTip(int column)
Returns the tooltip text for the specified column. Will be shown in the table header.


getColumnClass

public Class<?> getColumnClass(int columnIndex)
Returns Object.class regardless of columnIndex.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
columnIndex - the column being queried
Returns:
the Object.class