mavis.gui
Class MagneticComponentTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by mavis.gui.MagneticComponentTableModel
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.table.TableModel, ProjectListener, SessionListener

public class MagneticComponentTableModel
extends javax.swing.table.AbstractTableModel
implements SessionListener, ProjectListener

This is basically an intermediate wrapper for the data in the actual JTable table which is found in the MagneticComponentPanel. The class mainly takes care of number format presentation, and notifies listening clients about data content changes. It will also tell the JTable to autoselect the newest table entry, if a new component was added (adding new components is done externally from this class). This class was cut-n-pasted from the original MeasurementSequenceTableModel.java

See Also:
Serialized Form

Field Summary
private  java.util.List<ComponentColumn> columns
           
private  Session session
           
private  javax.swing.JTable table
           
private static java.lang.String VISIBLE_COLUMNS_PROPERTY
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
MagneticComponentTableModel()
          Creates a new MeasurementSequenceTableModel with no active project.
 
Method Summary
 void changeNumberFormat(java.lang.String format)
          Changes certain columns into the specified number format.
 java.lang.Class<?> getColumnClass(int columnIndex)
          Returns Object.class regardless of columnIndex.
 int getColumnCount()
          Returns the number of columns in the model.
 java.lang.String getColumnName(int column)
          Returns a name for the column.
 java.lang.String getColumnToolTip(int column)
          Returns the tooltip text for the specified column.
 int getRowCount()
          Returns the number of rows in the model.
 Session getSession()
          Get the Session object reference that this class uses.
 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 can be edited.
 void projectUpdated(ProjectEvent event)
          This method is automatically invoked by the Project class, when the contents of the project changes.
 void sessionUpdated(SessionEvent event)
          This method is automatically invoked by the Session class, when the contents of the session changes.
 void setSession(Session sess)
          Set the Session object that this class should use.
 void setTable(javax.swing.JTable table)
          Associates a JTable with this class.
 void setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
          Sets the value for the cell at columnIndex and rowIndex.
 
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 java.lang.String VISIBLE_COLUMNS_PROPERTY
See Also:
Constant Field Values

table

private javax.swing.JTable table

session

private Session session

columns

private java.util.List<ComponentColumn> columns
Constructor Detail

MagneticComponentTableModel

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

Method Detail

getSession

public Session getSession()
Get the Session object reference that this class uses.

Returns:
Session object

setSession

public void setSession(Session sess)
Set the Session object that this class should use.

Parameters:
sess - The Session object.

setTable

public void setTable(javax.swing.JTable table)
Associates a JTable with this class. Very ugly "fix", see the autoselect code in sessionUpdated(). TODO: make a better solution


sessionUpdated

public void sessionUpdated(SessionEvent event)
This method is automatically invoked by the Session class, when the contents of the session changes.

Specified by:
sessionUpdated in interface SessionListener
Parameters:
event - SessionEvent object, contains the type of change

projectUpdated

public void projectUpdated(ProjectEvent event)
This method is automatically invoked by the Project class, when the contents of the project changes.

Specified by:
projectUpdated in interface ProjectListener
Parameters:
event - ProjectEvent object, contains the type of change

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. A JTable uses this method to determine how many columns it should create and display by default.

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

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 value,
                       int rowIndex,
                       int columnIndex)
Sets the value for the cell at columnIndex and rowIndex.

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

getColumnName

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

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

getColumnToolTip

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


getColumnClass

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

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

changeNumberFormat

public void changeNumberFormat(java.lang.String format)
Changes certain columns into the specified number format.

Parameters:
format - to use

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns true if the cell can be edited. See ComponentColumn.java

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