de.axelwernicke.mypod
Class ClipsTableModel

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended byde.axelwernicke.mypod.ClipsTableModel
All Implemented Interfaces:
java.util.EventListener, java.io.Serializable, javax.swing.table.TableModel, javax.swing.event.TableModelListener

public class ClipsTableModel
extends javax.swing.table.AbstractTableModel
implements javax.swing.event.TableModelListener

Model for a list view table. The model is mostly a wrapper around a playlist. Additionally all the stuff to sort a table by columns is in here...

Author:
axel wernicke
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
ClipsTableModel()
          Default Constructor
ClipsTableModel(Playlist _playlist)
          Creates a new instance of ListViewModel and initializes with playlist.
ClipsTableModel(Playlist _playlist, java.util.Vector _sortingColumns)
          Creates a new instance of ListViewModel and initializes with playlist and sorting.
 
Method Summary
 int compare(int row1, int row2)
          Compares two values of a column to sort by
 int compareRowsByColumn(int row1, int row2, int column)
          Compares two elements of a column.
 java.lang.Class getColumnClass(int column)
          gets the class of a column
 int getColumnCount()
          Gets the column count of the table.
 java.lang.String getColumnName(int column)
          gets the column name and adds a mark, if the table is sorted by this row
 Playlist getPlaylist()
          Gets the playlist behind the model.
 int getRowCount()
          gets the total count of rows in the model
 java.util.Vector getSortingColumns()
          Getter for property sortingColumns.
 java.lang.Object getValueAt(int row, int col)
          gets a value of the model
 boolean isValid()
          Checks if the data in the model has the same count of rows as the sorting index array.
 void reallocateIndexes()
          Reallocates sorting index.
 void setPlaylist(Playlist value)
          Sets a playlist to the model.
 void setSortingColumns(java.util.Vector _sortingColumns)
          Setter for property sortingColumns.
 void shuttlesort(int[] from, int[] to, int low, int high)
          This is a home-grown implementation which we have not had time to research - it may perform poorly in some circumstances.
 void sort()
          Sort the model.
 void sortByColumn(int column)
          Sorts a a table model by column ascending.
 void sortByColumn(int column, boolean ascending)
          Sorts a a table model by column.
 void swap(int i, int j)
          Swaps two elements.
 void tableChanged(javax.swing.event.TableModelEvent tableModelEvent)
          Inform everbody listening that the model changed.
 void validate()
          validates list view table model.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClipsTableModel

public ClipsTableModel()
Default Constructor


ClipsTableModel

public ClipsTableModel(Playlist _playlist)
Creates a new instance of ListViewModel and initializes with playlist.

Parameters:
_playlist - Playlist to initialize table with.

ClipsTableModel

public ClipsTableModel(Playlist _playlist,
                       java.util.Vector _sortingColumns)
Creates a new instance of ListViewModel and initializes with playlist and sorting.

Parameters:
_sortingColumns - columns to define sorting.
_playlist - Playlist to initialize playlist from.
Method Detail

setPlaylist

public void setPlaylist(Playlist value)
Sets a playlist to the model.

Parameters:
value - Playlist to set.

getPlaylist

public Playlist getPlaylist()
Gets the playlist behind the model.

Returns:
Playlist behind the model.

getColumnCount

public int getColumnCount()
Gets the column count of the table.

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
column count.

getColumnName

public java.lang.String getColumnName(int column)
gets the column name and adds a mark, if the table is sorted by this row

Specified by:
getColumnName in interface javax.swing.table.TableModel
Parameters:
column - index of the column
Returns:
name of the column

getColumnClass

public java.lang.Class getColumnClass(int column)
gets the class of a column

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Parameters:
column - index of the column
Returns:
class of the column

getRowCount

public int getRowCount()
gets the total count of rows in the model

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
total count of rows

getValueAt

public java.lang.Object getValueAt(int row,
                                   int col)
gets a value of the model

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
row - specifies the row
col - specifies the column
Returns:
the object from the position (row, col)

isValid

public boolean isValid()
Checks if the data in the model has the same count of rows as the sorting index array.

Returns:
true, if sorter index an playlist have the sampe size

validate

public void validate()
validates list view table model. check playlist.size() == sortIdx.length check playlist.totalClipsTime()


tableChanged

public void tableChanged(javax.swing.event.TableModelEvent tableModelEvent)
Inform everbody listening that the model changed.

Specified by:
tableChanged in interface javax.swing.event.TableModelListener
Parameters:
tableModelEvent - event to post

reallocateIndexes

public void reallocateIndexes()
Reallocates sorting index.


compareRowsByColumn

public int compareRowsByColumn(int row1,
                               int row2,
                               int column)
Compares two elements of a column.

Parameters:
row1 - to compare
row2 - to compare
column - to compare
Returns:
result to the comparison.

compare

public int compare(int row1,
                   int row2)
Compares two values of a column to sort by

Parameters:
row1 - value1
row2 - value2
Returns:
result

sort

public void sort()
Sort the model.

shuttlesort

public void shuttlesort(int[] from,
                        int[] to,
                        int low,
                        int high)
This is a home-grown implementation which we have not had time to research - it may perform poorly in some circumstances. It requires twice the space of an in-place algorithm and makes NlogN assigments shuttling the values between the two arrays. The number of compares appears to vary between N-1 and NlogN depending on the initial order but the main reason for using it here is that, unlike qsort, it is stable.

Parameters:
from - source array
to - destination array
low - index
high - index

swap

public void swap(int i,
                 int j)
Swaps two elements.

Parameters:
i - element to swap.
j - element to swap.

sortByColumn

public void sortByColumn(int column)
Sorts a a table model by column ascending.

Parameters:
column - to sort by

sortByColumn

public void sortByColumn(int column,
                         boolean ascending)
Sorts a a table model by column.

Parameters:
column - to sort by
ascending - sorting oder

getSortingColumns

public java.util.Vector getSortingColumns()
Getter for property sortingColumns.

Returns:
Value of property sortingColumns.

setSortingColumns

public void setSortingColumns(java.util.Vector _sortingColumns)
Setter for property sortingColumns.

Parameters:
_sortingColumns - vector containing the columns to sort the table by.