org.peace_tools.data
Class ESTTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.peace_tools.data.ESTTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public class ESTTableModel
extends javax.swing.table.AbstractTableModel

A bridge class between FASTA entries in a FASTA file and a JTable. This class serves as a bridge between the in-memory representation of fragments in a FASTA file to the actual display in JTable. This class enables reusing/sharing fragment data and displaying it different views with minimal memory footprint. The terminology used in this class is from the context of the Model-View-Controller (MVC) object-oriented design pattern.

Note: The number of columns displayed by this table model can be varied based on the column width set via a call to setColumnSize() method. By default this model provides only 2 columns.

See Also:
Serialized Form

Field Summary
private  int basesPerCol
          The number of base pairs per column.
private  ESTList estList
          Reference to the list of fragments that is actually exposed by this table model.
private  int maxESTLen
          The maximum length of an EST sequence to be adapted by this model.
private static long serialVersionUID
          A generated serialization UID included just to keep the compiler happy.
private  java.lang.Integer[] sortedIndexs
          This array contains a sorted list of indexes of fragments if a sorting scheme has been applied to the data set.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
ESTTableModel(ESTList estList)
          The default constructor.
 
Method Summary
 java.lang.Class<?> getColumnClass(int column)
          Obtain the class that describes the data type of a given column.
 int getColumnCount()
          This method overrides the interface method in TableModel to return the number of columns in the Table.
 java.lang.String getColumnName(int column)
          This method overrides the interface method in RowModel to return the title for the columns.
 EST getESTAt(int row)
          Obtain the EST entry at a given row.
 ESTList getESTList()
          Obtain the list of ESTs associated with this model.
 int getRowCount()
          Method to return the number of rows to be displayed in the table.
 java.lang.Object getValueAt(int row, int col)
          This method returns the subset of base pairs to be displayed in a given column for a given row.
 boolean isCellEditable(int row, int column)
          Interface method to determine if an entry in the JTable is editable.
 void setBasesPerCol(int basesPerCol)
          Method to change the number of bases to be displayed in each column.
 void sort(int order)
          Method to change the order in which fragments are ordered.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

estList

private final ESTList estList
Reference to the list of fragments that is actually exposed by this table model. This value is set in the constructor and is never changed during the life time of this class.


maxESTLen

private final int maxESTLen
The maximum length of an EST sequence to be adapted by this model. This value along with the basesPerCol determines the total number of columns that are logically represented by this model.


basesPerCol

private int basesPerCol
The number of base pairs per column. This value along with the maxESTLen determines the total number of columns that are logically represented by this model.


sortedIndexs

private java.lang.Integer[] sortedIndexs
This array contains a sorted list of indexes of fragments if a sorting scheme has been applied to the data set. If this array is not null then this table model returns entries using the order specified in this array. The entries in this array are indexes into the original set of fragments contained in the estList instance variable. clusters in the root. This list changes depending on the order of sorting requested by the user.


serialVersionUID

private static final long serialVersionUID
A generated serialization UID included just to keep the compiler happy.

See Also:
Constant Field Values
Constructor Detail

ESTTableModel

public ESTTableModel(ESTList estList)
The default constructor. The constructor computes the core information required for quick operation of this model class and sets up various instance variables to appropriate values.

Parameters:
estList - The list of fragments from a FASTA file to be used and suitably exposed by this model class. This parameter cannot be null.
Method Detail

getRowCount

public int getRowCount()
Method to return the number of rows to be displayed in the table.

Returns:
This method returns the number of entries in the FASTA file to be displayed in a table.

getColumnCount

public int getColumnCount()
This method overrides the interface method in TableModel to return the number of columns in the Table. This value is determined using a combination of maxLen and basesPerCol values.

Returns:
The number of columns to be displayed in this table. There are always a minimum of 3 columns.

getColumnName

public java.lang.String getColumnName(int column)
This method overrides the interface method in RowModel to return the title for the columns. The column titles are dynamically determined depending on the number of columns displayed in the table.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Returns:
The title for the columns. The title for the first two columns that contains the fragment index and fasta header information is fixed.

getValueAt

public java.lang.Object getValueAt(int row,
                                   int col)
This method returns the subset of base pairs to be displayed in a given column for a given row. This method overrides the interface method in TableModel to return the data to be displayed in a given row. The return value is computed as follows:
  1. For column 0, this method returns the logical index of the entry in the FASTA file.
  2. For column 1, this method always returns the FASTA identifier associated with the entry in the given row.
  3. For other columns, if basesPerEST == -1, then this method returns the complete fasta sequence to be displayed in the second column.
  4. If the node is an EST node and column * basesPerCol is less than EST length, then the bases logically associated with the column are returned.
  5. Otherwise this method returns an empty string.

Parameters:
row - The row for which the data is desired.
col - The column for which the data is desired.
Returns:
The data to be displayed for a given node (or row) and a given column.

getESTAt

public EST getESTAt(int row)
Obtain the EST entry at a given row.

Parameters:
row - The logical row from where the EST is to be retrieved. Note that this method pays heed to the sorted order. So the row is the logical row in the sorted list of entries and not the absolute index in the EST list.
Returns:
The EST at the given logical row.

sort

public void sort(int order)
Method to change the order in which fragments are ordered. This method resets the order in which fragments are presented by this class to the "view" that is displaying the FASTA fragments.

Parameters:
order - The order in which the clusters are to be sorted. The following values are valid for this parameter: 0: no sorting, 1: shorter fragments first, 2: shorter fragments last.

setBasesPerCol

public void setBasesPerCol(int basesPerCol)
Method to change the number of bases to be displayed in each column. This method must be used to change the number of bases per column to be presented my this model class.

Parameters:
basesPerCol - If this parameter is -1, then all sequences are presented as a single column. Otherwise the sequences are presented as multiple columns, with each column having no more than the specified number of neucleotides.

getColumnClass

public java.lang.Class<?> getColumnClass(int column)
Obtain the class that describes the data type of a given column.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
column - The zero-based index of the column whose Class type is to be returned.
Returns:
This method always returns String.class as the class of the data as this model exposes all the information as a String.

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Interface method to determine if an entry in the JTable is editable.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel
Returns:
This method always returns false to indicate that the data in the FASTA file cannot be edited.

getESTList

public ESTList getESTList()
Obtain the list of ESTs associated with this model.

Returns:
The EST list set for use by this model.