com.limegroup.gnutella.gui.tables
Class BasicDataLineModel

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended bycom.limegroup.gnutella.gui.tables.BasicDataLineModel
All Implemented Interfaces:
java.util.Comparator, DataLineModel, java.io.Serializable, javax.swing.table.TableModel
Direct Known Subclasses:
ConnectionModel, HashBasedDataLineModel

public class BasicDataLineModel
extends javax.swing.table.AbstractTableModel
implements DataLineModel

Handles common tasks associated with storing the DataLine's of a table. Previously, this class used to be split between a DataLineList and a AbstractTableModel. However, because the function of the DataLineList was really to handle all interactions with the data, it essentially was a model. Now, because the two classes are combined, the model can fire its own events.

See Also:
Serialized Form

Field Summary
protected  boolean _isSorted
          Variable for whether or not this list has been sorted at least once.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
BasicDataLineModel(java.lang.Class dataLineClass)
           
 
Method Summary
 int add(DataLine dl)
          Adds a DataLine to row 0.
 int add(DataLine dl, int row)
          Adds a DataLine to the list at a row.
 int add(java.lang.Object o)
          Helper function.
 int add(java.lang.Object o, int row)
          Helper function.
 int addSorted(DataLine dl)
          Helper function.
 int addSorted(java.lang.Object o)
          Helper function.
 void clear()
          Clear the table of all data.
 int compare(java.lang.Object a, java.lang.Object b)
          A generic compare function.
 boolean contains(java.lang.Object o)
          Determine if the list contains a row that was initialized by Object o.
 boolean contains(java.lang.Object o, int col)
          Determine if the list contains Object o in column col.
 DataLine createDataLine()
          Instantiates a DataLine.
 DataLine get(int row)
          Get the DataLine associated with the row.
 DataLine get(java.lang.Object o)
          Implements DataLineModel interface.
 DataLine get(java.lang.Object o, int col)
          Implements DataLineModel interface.
 java.lang.Class getColumnClass(int col)
          Returns the class of the TableColumn as specified by the data line.
 int getColumnCount()
          Returns the number of columns as speicifed by the data line.
 java.lang.Object getColumnId(int col)
          Returns the Id of the TableColumn as specified by the data line.
 java.lang.String getColumnName(int col)
          Returns the name of the TableColumn as specified by the data line.
 DataLine getNewDataLine(java.lang.Object o)
          Returns an initialized new dataline.
 int getRow(DataLine dl)
          Get the index of this DataLine.
 int getRow(java.lang.Object o)
          Get the index of the DataLine that was initialized by Object o.
 int getRow(java.lang.Object o, int col)
          Get the row of the row that contains Object o in column col.
 int getRowCount()
          Returns the size of _list.
 int getSortColumn()
          Returns the column by which the underlying data is sorted ascending.
 int getSortedPosition(DataLine dl)
          Determines where the DataLine should be inserted.
 LimeTableColumn getTableColumn(int col)
          Returns the LimeTableColumn at the specific column this data line.
 java.lang.String[] getToolTipArray(int row)
          Gets the tooltip for a specific row.
 java.lang.Object getValueAt(int row, int col)
           
 boolean isSortAscending()
          Returns whether or not the underlying data is sorted ascending.
 boolean isSorted()
          Whether or not the underlying data is sorted.
 boolean needsResort()
          Whether or not the underlying data needs to be resorted.
 java.lang.Object refresh()
          Basic linear update.
 void remove(DataLine line)
          Helper-function that resolves to remove(int).
 void remove(int row)
          Calls cleanup on the DataLine and then removes it from the list.
 void remove(java.lang.Object o)
          Helper function that resolves to remove(int).
 void resort()
          Resorts the underlying data.
 void setValueAt(java.lang.Object o, int row, int col)
           
 void sort(int col)
          Sort the underlying data by the column.
 int update(java.lang.Object o)
          Update a specific DataLine The DataLine updated is the one that was initialized by Object o
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, isCellEditable, removeTableModelListener
 

Field Detail

_isSorted

protected boolean _isSorted
Variable for whether or not this list has been sorted at least once.

Constructor Detail

BasicDataLineModel

public BasicDataLineModel(java.lang.Class dataLineClass)
Method Detail

getToolTipArray

public java.lang.String[] getToolTipArray(int row)
Description copied from interface: DataLineModel
Gets the tooltip for a specific row.

Specified by:
getToolTipArray in interface DataLineModel

isSortAscending

public boolean isSortAscending()
Description copied from interface: DataLineModel
Returns whether or not the underlying data is sorted ascending.

Specified by:
isSortAscending in interface DataLineModel

getSortColumn

public int getSortColumn()
Description copied from interface: DataLineModel
Returns the column by which the underlying data is sorted ascending.

Specified by:
getSortColumn in interface DataLineModel

isSorted

public boolean isSorted()
Description copied from interface: DataLineModel
Whether or not the underlying data is sorted.

Specified by:
isSorted in interface DataLineModel

sort

public void sort(int col)
Description copied from interface: DataLineModel
Sort the underlying data by the column.

Specified by:
sort in interface DataLineModel

resort

public void resort()
Description copied from interface: DataLineModel
Resorts the underlying data.

Specified by:
resort in interface DataLineModel

needsResort

public boolean needsResort()
Description copied from interface: DataLineModel
Whether or not the underlying data needs to be resorted.

Specified by:
needsResort in interface DataLineModel

clear

public void clear()
Description copied from interface: DataLineModel
Clear the table of all data.

Specified by:
clear in interface DataLineModel

refresh

public java.lang.Object refresh()
Basic linear update. Extending classes may wish to override this function to provide a fine-tuned refresh, possibly recieving feedback from each row after it is updated. The return value can be used to notify the Mediator of information related to the refresh.

Specified by:
refresh in interface DataLineModel
Returns:
null

update

public int update(java.lang.Object o)
Update a specific DataLine The DataLine updated is the one that was initialized by Object o

Specified by:
update in interface DataLineModel

createDataLine

public DataLine createDataLine()
Instantiates a DataLine. This uses reflection to create an instance of the DataLine class. The dataLineClass Class is used to determine which class should be created. Failure to create results in AssertFailures. Extending classes should override this to change the way DataLine's are instantiated.


getNewDataLine

public DataLine getNewDataLine(java.lang.Object o)
Returns an initialized new dataline.


getSortedPosition

public int getSortedPosition(DataLine dl)
Determines where the DataLine should be inserted. Runs in log(n) time ArrayLists and linear time for LinkedLists. Extending classes should override this to change the method used to determine where to insert a new DataLine. The current methodology is to use Collections.binarySearch with _list as the list, the DataLine as the key, and this as the Comparator.


add

public int add(java.lang.Object o)
Helper function. Adds a DataLine initialized by the object to row 0. This should be overriden only if you want the default, non-sorting add to go someplace other than row 0. Delegates to add(Object, int). Extending classes should maintain the delegation to add(Object, int).

Specified by:
add in interface DataLineModel

add

public int add(java.lang.Object o,
               int row)
Helper function. Uses getNewDataLine(Object) and add(DataLine, int). Extending classes can override this, but it is recommended that they override the two above methods instead.

Specified by:
add in interface DataLineModel

add

public int add(DataLine dl)
Adds a DataLine to row 0. Currently unused.

Specified by:
add in interface DataLineModel

add

public int add(DataLine dl,
               int row)
Adds a DataLine to the list at a row. All forms of add(..) eventually end up here. Extending classes should override this if they want to maintain a HashMap of any type for speedier access.

Specified by:
add in interface DataLineModel

addSorted

public int addSorted(java.lang.Object o)
Helper function. Uses getNewDataLine(Object), getSortedPosition(DataLine), and add(DataLine, int) Extending classes can override this, but it is recommended they override the above mentioned methods instead.

Specified by:
addSorted in interface DataLineModel

addSorted

public int addSorted(DataLine dl)
Helper function. Uses getSortedPosition(DataLine) and add(DataLine, int). Extending classes can override this, but it is recommended they override the above mentioned methods instead.

Specified by:
addSorted in interface DataLineModel

get

public DataLine get(int row)
Description copied from interface: DataLineModel
Get the DataLine associated with the row.

Specified by:
get in interface DataLineModel

get

public DataLine get(java.lang.Object o)
Implements DataLineModel interface. Delegates the row find to getRow(Object o). Returns the first DataLine initialized by object o. If no object matches, null is returned.

Specified by:
get in interface DataLineModel

get

public DataLine get(java.lang.Object o,
                    int col)
Implements DataLineModel interface. Delegates the row find to getRow(Object o, int col). Returns the first DataLine that contains object o in column col. If no object matches, null is returned.

Specified by:
get in interface DataLineModel

remove

public void remove(int row)
Calls cleanup on the DataLine and then removes it from the list.

Specified by:
remove in interface DataLineModel

remove

public void remove(DataLine line)
Helper-function that resolves to remove(int). Removes the line associated with the DataLine line. If no matching DataLine exists, nothing happens.

Specified by:
remove in interface DataLineModel

remove

public void remove(java.lang.Object o)
Helper function that resolves to remove(int). Removes the DataLine that was initialized by the Object o. Uses a linear search through the list to find a match. Extending objects that have large lists and call remove(Object) often may wish to override this, add(Object, int) and sort using a HashMap for more timely access.

Specified by:
remove in interface DataLineModel

getValueAt

public java.lang.Object getValueAt(int row,
                                   int col)
Specified by:
getValueAt in interface javax.swing.table.TableModel

setValueAt

public void setValueAt(java.lang.Object o,
                       int row,
                       int col)
Specified by:
setValueAt in interface javax.swing.table.TableModel

contains

public boolean contains(java.lang.Object o,
                        int col)
Description copied from interface: DataLineModel
Determine if the list contains Object o in column col.

Specified by:
contains in interface DataLineModel
Returns:
true if List contains the Object o in column col.

contains

public boolean contains(java.lang.Object o)
Description copied from interface: DataLineModel
Determine if the list contains a row that was initialized by Object o.

Specified by:
contains in interface DataLineModel
Returns:
true if the List contains a DataLine that was initialized by Object o.

getRow

public int getRow(DataLine dl)
Description copied from interface: DataLineModel
Get the index of this DataLine.

Specified by:
getRow in interface DataLineModel
Returns:
the index of the matching DataLine.

getRow

public int getRow(java.lang.Object o,
                  int col)
Description copied from interface: DataLineModel
Get the row of the row that contains Object o in column col.

Specified by:
getRow in interface DataLineModel
Returns:
the index of the first DataLine that contains Object o in column col.

getRow

public int getRow(java.lang.Object o)
Description copied from interface: DataLineModel
Get the index of the DataLine that was initialized by Object o.

Specified by:
getRow in interface DataLineModel
Returns:
the index of the first DataLine that was initialized by Object o.

compare

public int compare(java.lang.Object a,
                   java.lang.Object b)
A generic compare function.

Specified by:
compare in interface java.util.Comparator

getTableColumn

public LimeTableColumn getTableColumn(int col)
Returns the LimeTableColumn at the specific column this data line.

Specified by:
getTableColumn in interface DataLineModel

getRowCount

public int getRowCount()
Returns the size of _list.

Specified by:
getRowCount in interface javax.swing.table.TableModel

getColumnCount

public int getColumnCount()
Returns the number of columns as speicifed by the data line.

Specified by:
getColumnCount in interface javax.swing.table.TableModel

getColumnName

public java.lang.String getColumnName(int col)
Returns the name of the TableColumn as specified by the data line.

Specified by:
getColumnName in interface javax.swing.table.TableModel

getColumnId

public java.lang.Object getColumnId(int col)
Returns the Id of the TableColumn as specified by the data line.

Specified by:
getColumnId in interface DataLineModel

getColumnClass

public java.lang.Class getColumnClass(int col)
Returns the class of the TableColumn as specified by the data line.

Specified by:
getColumnClass in interface javax.swing.table.TableModel