Mp3dings 
20100427

net.sourceforge.mp3dings
Class AbstractTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by net.sourceforge.mp3dings.AbstractTableModel
All Implemented Interfaces:
HeaderPopupTableModel, SortableTableModel, Serializable, TableModel, FieldAssociatedTableModel, Mp3dingsTableModel
Direct Known Subclasses:
DataTableModel, DependentTableModel

public abstract class AbstractTableModel
extends AbstractTableModel
implements Mp3dingsTableModel

Aspects of the implementation of an Mp3dingsTableModel that are shared by all mp3dings tables.

Author:
Moritz Ringler
See Also:
Serialized Form

Nested Class Summary
protected  class AbstractTableModel.UpdateRunnable
          Description of the Class
 
Field Summary
protected static Aggregator aggregator
          This aggregator aggregates preference change events and updates this table model on the awt event thread.
protected  FilterCollection filters
          The filters acting on the fields in this table.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface de.mospace.swing.table.SortableTableModel
ASCENDING, DESCENDING
 
Constructor Summary
AbstractTableModel()
          Constructs a new AbstractTableModel.
 
Method Summary
 void addDataChangeListener(DataChangeListener l)
          Adds a feature to the DataChangeListener attribute of the AbstractTableModel object
 void addMessageListener(MessageListener l)
          Adds a feature to the MessageListener attribute of the AbstractTableModel object
 void addRowsToSorter(int rowCount, int newSize)
          Adds a feature to the RowsToSorter attribute of the AbstractTableModel object
 FilterCollection buildFilters()
          Loads the filters for this model from the user preferences.
 boolean discardChanges(Frame parent)
          Description of the Method
protected  void fireAllColumnsUpdated()
          Notifies listeners that all columns in this model have been updated.
 void fireDataChanged()
          Description of the Method
 void fireDataChanged(int n)
          Description of the Method
protected  void fireMessageSent(String s)
          Description of the Method
protected  void fireMessageSent(String s, int t)
          Description of the Method
 Object get(int row, int c)
          Gets the value of the specified table cell, converting FullTextString values to strings on the fly.
 int getColumn(Field field)
          Returns the table column for a field.
 Class getColumnClass(int c)
          Gets the class of objects in the specified column.
 int getColumnCount()
          Gets the number of columns in this model.
 String getColumnName(int col)
          Gets the name of the specified column.
abstract  boolean getEditable(Field field)
          Returns whether the specified field can be edited in this model.
 int getEntries(int row)
          Gets the entry represented by the specified row in the current sorting.
 int[] getEntries(int[] rows)
          Gets the entries represented by the specified rows in the current sorting.
 Field getField(int col)
          Returns the field for a table column.
 Field[] getFields()
          Gets the fields that are currently displayed.
abstract  File getFile(int row)
          Gets the file attribute of the AbstractTableModel object
 JPopupMenu getFilterEditPopup(MouseEvent e)
          Returns a popup menu that allows to configure the filters acting on a specific column in this model.
protected  JPopupMenu getFilterEditPopup(MouseEvent evt, Field field)
          Returns a popup menu that allows to configure the filters acting on a specific field in this model.
 FilterCollection getFilters()
          Gets the filters attribute of the AbstractTableModel object
 JPopupMenu getHeaderPopup(MouseEvent e)
          Gets the context menu for the column header of a table displaying this model.
 int[] getNextDuplicates(int[] rows, int startRowIndex, int[] cols)
          Looks for consecutive duplicates in rows, starting at startRowIndex.
 Preferences getPrefs()
          Gets the prefs attribute of the AbstractTableModel object
 int getRowCount()
          Gets the number of rows in this model.
 int getRows(int entry)
          Gets the current row number of an entry.
 int[] getRows(int[] entries)
          Gets the current row numbers for a list of entries.
 int getSortingColumn()
          Gets the column with top sorting precedence.
 int[][] getSortOrder()
          Gets the columns by which this table is sorted.
 Object getValueAt(int row, int c)
          Gets the value of the specified table cell.
protected  void init()
          new more comprehensive initialization routine
 boolean isCellEditable(int row, int c)
          Returns whether the specified table cell can be edited.
 boolean isFiltered(int column)
          Gets the filtered attribute of the AbstractTableModel object
 boolean isSorted()
          Gets the sorted attribute of the AbstractTableModel object
 void randomize()
          Shuffles the entries in this TableModel.
 void remAllRowsFromSorter()
          Description of the Method
 void removeDataChangeListener(DataChangeListener l)
          Description of the Method
 void removeMessageListener(MessageListener l)
          Description of the Method
 void remRowFromSorter(int entry)
          Description of the Method
 void remRowFromSorter(int[] entry)
          Description of the Method
protected abstract  List reorganizeData(int[] old2new, int newlength)
          Description of the Method
 void resetChangeCounter()
          Description of the Method
 void set(Object v, int[] rows, int[] cols)
          Updates a range of cells without firing any events.
 void set(Object v, int row, int c)
          Updates the value of the specified table cell without firing any events.
protected abstract  void setData(List v)
          Sets the data attribute of the AbstractTableModel object
 void setSortBy(int col)
          Sets the column with top sorting precedence.
 void setSortBy(int[] cols)
          Sets the columns by which this table is sorted.
 void setSortBy(int col, boolean asc)
          Sets the column with top sorting precedence and the way it is to be sorted.
protected  void setSorted(boolean b)
          Sets the sorted attribute of the AbstractTableModel object
 void setValueAt(Object v, int[] rows, int[] cols)
          Updates a range of cells and notifies tables displaying this model of the change in the data.
 void setValueAt(Object v, int row, int c)
          Updates the value of the specified table cell and notifies tables displaying this model of the change in the data.
 void sort()
          Sorts the entries in this TableModel according to the criteria set by setSortBy(int).
 
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
 
Methods inherited from interface net.sourceforge.mp3dings.Mp3dingsTableModel
fireTableDataChanged, getPrefKey
 
Methods inherited from interface net.sourceforge.mp3dings.FieldAssociatedTableModel
getAllowedFields, getDefaultFields, getPersistentFields
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Field Detail

filters

protected FilterCollection filters
The filters acting on the fields in this table.


aggregator

protected static final Aggregator aggregator
This aggregator aggregates preference change events and updates this table model on the awt event thread.

Constructor Detail

AbstractTableModel

public AbstractTableModel()
Constructs a new AbstractTableModel.

Method Detail

getFilterEditPopup

public JPopupMenu getFilterEditPopup(MouseEvent e)
Returns a popup menu that allows to configure the filters acting on a specific column in this model. If the mouse event occured on the column header of a table that gets its data from this model then this method will return a popup menu that allows to configure the filters acting on that column.

Parameters:
e - a mouse click on the column header of a table displaying this model
Returns:
The popup menu that allows to configure filters or null if e is not the right kind of event.
See Also:
getHeaderPopup(MouseEvent)

getFilterEditPopup

protected JPopupMenu getFilterEditPopup(MouseEvent evt,
                                        Field field)
Returns a popup menu that allows to configure the filters acting on a specific field in this model. If the mouse event occured on the column header of an Mp3dingsTable that gets its data from this model then this method will return a popup menu that allows to configure the filters acting on that column. You should usually not call this method directly, use getFilterEditPopup(MouseEvent) instead.

Parameters:
evt - the mouse event that triggered the popup
field - the field whose filters will be edited
Returns:
a new popup menu for editing field filters
See Also:
getFilterEditPopup(MouseEvent)

getColumnName

public String getColumnName(int col)
Gets the name of the specified column.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
col - a column in this table model
Returns:
the name of the column

getColumnCount

public int getColumnCount()
Gets the number of columns in this model.

Specified by:
getColumnCount in interface TableModel
Returns:
the number of columns in this model.

getColumnClass

public Class getColumnClass(int c)
Gets the class of objects in the specified column.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
c - a column
Returns:
the class of the column

getEditable

public abstract boolean getEditable(Field field)
Returns whether the specified field can be edited in this model. This method can either return true or false for fields that are not currently included in this model, but it must not throw an exception for non-null arguments.

Specified by:
getEditable in interface FieldAssociatedTableModel
Parameters:
field - a field that can be displayed by this model
Returns:
whether the field can be edited
Throws:
RuntimeException - this method can throw a runtime exception if field is null.
See Also:
isCellEditable(int, int)

isCellEditable

public boolean isCellEditable(int row,
                              int c)
Returns whether the specified table cell can be edited.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
row - the row of the cell
c - the column of the cell
Returns:
whether the specified cell is editable
Throws:
RuntimeException - this method can throw a runtime exception if c is not a valid column number *

getValueAt

public Object getValueAt(int row,
                         int c)
Gets the value of the specified table cell.

Specified by:
getValueAt in interface TableModel
Parameters:
row - the row of the cell
c - the column of the cell
Returns:
the value of the cell

get

public Object get(int row,
                  int c)
Gets the value of the specified table cell, converting FullTextString values to strings on the fly.

Specified by:
get in interface Mp3dingsTableModel
Parameters:
row - the row of the cell
c - the column of the cell
Returns:
the value of the cell

setValueAt

public void setValueAt(Object v,
                       int row,
                       int c)
Updates the value of the specified table cell and notifies tables displaying this model of the change in the data.

This method must only be called from the AWT event dispatching thread, use set(Object, int, int) if you want to update the table from another thread.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
row - the row of the cell
c - the column of the cell
v - the new value of the cell

setValueAt

public void setValueAt(Object v,
                       int[] rows,
                       int[] cols)
Updates a range of cells and notifies tables displaying this model of the change in the data. This is faster than calling setValueAt(Object, int, int) for each cell.

This method must only be called from the AWT event dispatching thread, use set(Object, int[], int[]) if you want to update the table from another thread.

Specified by:
setValueAt in interface Mp3dingsTableModel
Parameters:
rows - the rows of the cells
cols - the columns of the cells
v - the new value of the cells

set

public void set(Object v,
                int row,
                int c)
Updates the value of the specified table cell without firing any events. If you want a table displaying this model to reflect the change in the data you must explicitly ask it to do so.

Specified by:
set in interface Mp3dingsTableModel
Parameters:
row - the row of the cell
c - the column of the cell
v - the new value of the cell
See Also:
setValueAt(Object, int, int)

set

public void set(Object v,
                int[] rows,
                int[] cols)
Updates a range of cells without firing any events. If you want a table displaying this model to reflect the change in the data you must explicitly ask it to do so.

Specified by:
set in interface Mp3dingsTableModel
Parameters:
rows - the rows of the cells
cols - the columns of the cells
v - the new value of the cells
See Also:
setValueAt(Object, int[], int[])

sort

public void sort()
Sorts the entries in this TableModel according to the criteria set by setSortBy(int).

Specified by:
sort in interface SortableTableModel
See Also:
TableSorter.sort(de.mospace.swing.table.SortableTableModel)

randomize

public void randomize()
Shuffles the entries in this TableModel.

Specified by:
randomize in interface SortableTableModel
See Also:
TableSorter.randomize(de.mospace.swing.table.SortableTableModel)

setSortBy

public void setSortBy(int col)
Sets the column with top sorting precedence. If col is already the column with top sorting precedence the sort order will be reversed, otherwise the entries in this model will be sorted in ascending order. This implementation remembers previous calls to this method to determine what to do when two entries have equal fields in col.

Specified by:
setSortBy in interface SortableTableModel
Parameters:
col - the table column
See Also:
setSortBy(int, boolean)

setSortBy

public void setSortBy(int[] cols)
Sets the columns by which this table is sorted. The entries will be sorted in ascending order.

Specified by:
setSortBy in interface Mp3dingsTableModel
Parameters:
cols - the columns to sort by in order of decreasing precedence
See Also:
setSortBy(int, boolean)

getNextDuplicates

public int[] getNextDuplicates(int[] rows,
                               int startRowIndex,
                               int[] cols)
Looks for consecutive duplicates in rows, starting at startRowIndex. The returned array contains the index of the first and the last rows that are identical in all columns specified by cols.

Consider calling setSortBy(int[] cols) and sort() before calling this method.

Specified by:
getNextDuplicates in interface Mp3dingsTableModel
Parameters:
rows - an array of table model rows to search for duplicates
startRowIndex - the index where the search will begin
cols - the cols that will be taken into account for comparison, if null all columns are used.
Returns:
the bounds of the next set of consecutive duplicate rows

setSortBy

public void setSortBy(int col,
                      boolean asc)
Sets the column with top sorting precedence and the way it is to be sorted. This implementation remembers previous calls to this method to determine what to do when two entries have equal fields in col.

Specified by:
setSortBy in interface SortableTableModel
Parameters:
col - the table column
asc - true for ascending order

getSortingColumn

public int getSortingColumn()
Gets the column with top sorting precedence.

Specified by:
getSortingColumn in interface SortableTableModel
Returns:
the column by which this table model is sorted.

getSortOrder

public int[][] getSortOrder()
Gets the columns by which this table is sorted. The returned array holds the information used for sorting the table. The array holds n pairs of integers in the order of decreasing sorting precedence. The first integer in each pair is a column number, if it is -1 this element and all following elements are ignored. The second integer is either ASCENDING or DESCENDING.

Specified by:
getSortOrder in interface SortableTableModel
Returns:
an array of {column, order} pairs with decreasing sorting precedence

getRows

public int getRows(int entry)
Gets the current row number of an entry.

Specified by:
getRows in interface SortableTableModel

getRows

public int[] getRows(int[] entries)
Gets the current row numbers for a list of entries.

Specified by:
getRows in interface SortableTableModel

getEntries

public int getEntries(int row)
Gets the entry represented by the specified row in the current sorting.

Specified by:
getEntries in interface SortableTableModel

getEntries

public int[] getEntries(int[] rows)
Gets the entries represented by the specified rows in the current sorting.

Specified by:
getEntries in interface SortableTableModel

getField

public Field getField(int col)
Returns the field for a table column.

Specified by:
getField in interface FieldAssociatedTableModel
Parameters:
col - the column number for which to retrieve the field
Returns:
the field or null if col is invalid

getColumn

public int getColumn(Field field)
Returns the table column for a field.

Specified by:
getColumn in interface FieldAssociatedTableModel
Parameters:
field - the field
Returns:
the column or -1 if there is no column for that field in this table

getFields

public Field[] getFields()
Gets the fields that are currently displayed.

Specified by:
getFields in interface FieldAssociatedTableModel
Specified by:
getFields in interface Mp3dingsTableModel
Returns:
the fields that are currently displayed

getRowCount

public int getRowCount()
Gets the number of rows in this model.

Specified by:
getRowCount in interface TableModel
Returns:
the number of table rows

buildFilters

public FilterCollection buildFilters()
Loads the filters for this model from the user preferences.

Returns:
the filters for this model

fireAllColumnsUpdated

protected void fireAllColumnsUpdated()
Notifies listeners that all columns in this model have been updated.


isFiltered

public boolean isFiltered(int column)
Gets the filtered attribute of the AbstractTableModel object

Specified by:
isFiltered in interface Mp3dingsTableModel
Parameters:
column - Description of the Parameter
Returns:
The filtered value

getPrefs

public Preferences getPrefs()
Gets the prefs attribute of the AbstractTableModel object

Specified by:
getPrefs in interface Mp3dingsTableModel
Returns:
The prefs value

discardChanges

public boolean discardChanges(Frame parent)
Description of the Method

Specified by:
discardChanges in interface Mp3dingsTableModel
Parameters:
parent - Description of the Parameter
Returns:
Description of the Return Value

resetChangeCounter

public void resetChangeCounter()
Description of the Method

Specified by:
resetChangeCounter in interface Mp3dingsTableModel

getFile

public abstract File getFile(int row)
Gets the file attribute of the AbstractTableModel object

Specified by:
getFile in interface Mp3dingsTableModel
Parameters:
row - Description of the Parameter
Returns:
The file value

reorganizeData

protected abstract List reorganizeData(int[] old2new,
                                       int newlength)
Description of the Method

Parameters:
old2new - Description of the Parameter
newlength - Description of the Parameter
Returns:
Description of the Return Value

setData

protected abstract void setData(List v)
Sets the data attribute of the AbstractTableModel object

Parameters:
v - The new data value

init

protected void init()
new more comprehensive initialization routine


getFilters

public FilterCollection getFilters()
Gets the filters attribute of the AbstractTableModel object

Specified by:
getFilters in interface Mp3dingsTableModel
Returns:
The filters value

isSorted

public boolean isSorted()
Gets the sorted attribute of the AbstractTableModel object

Specified by:
isSorted in interface SortableTableModel
Returns:
The sorted value

setSorted

protected void setSorted(boolean b)
Sets the sorted attribute of the AbstractTableModel object

Parameters:
b - The new sorted value

remAllRowsFromSorter

public void remAllRowsFromSorter()
Description of the Method


remRowFromSorter

public void remRowFromSorter(int entry)
Description of the Method

Parameters:
entry - Description of the Parameter

remRowFromSorter

public void remRowFromSorter(int[] entry)
Description of the Method

Parameters:
entry - Description of the Parameter

addRowsToSorter

public void addRowsToSorter(int rowCount,
                            int newSize)
Adds a feature to the RowsToSorter attribute of the AbstractTableModel object

Parameters:
rowCount - The feature to be added to the RowsToSorter attribute
newSize - The feature to be added to the RowsToSorter attribute

getHeaderPopup

public JPopupMenu getHeaderPopup(MouseEvent e)
Gets the context menu for the column header of a table displaying this model. By default this method delegates to getFilterEditPopup(MouseEvent).

Specified by:
getHeaderPopup in interface HeaderPopupTableModel
Parameters:
e - a mouse click on a column header of a table displaying this model
Returns:
a context menu or null
See Also:
getFilterEditPopup(MouseEvent)

addMessageListener

public void addMessageListener(MessageListener l)
Adds a feature to the MessageListener attribute of the AbstractTableModel object

Specified by:
addMessageListener in interface Mp3dingsTableModel
Parameters:
l - The feature to be added to the MessageListener attribute

removeMessageListener

public void removeMessageListener(MessageListener l)
Description of the Method

Parameters:
l - Description of the Parameter

fireMessageSent

protected void fireMessageSent(String s,
                               int t)
Description of the Method

Parameters:
s - Description of the Parameter
t - Description of the Parameter

fireMessageSent

protected void fireMessageSent(String s)
Description of the Method

Parameters:
s - Description of the Parameter

addDataChangeListener

public void addDataChangeListener(DataChangeListener l)
Adds a feature to the DataChangeListener attribute of the AbstractTableModel object

Specified by:
addDataChangeListener in interface Mp3dingsTableModel
Parameters:
l - The feature to be added to the DataChangeListener attribute

removeDataChangeListener

public void removeDataChangeListener(DataChangeListener l)
Description of the Method

Parameters:
l - Description of the Parameter

fireDataChanged

public void fireDataChanged(int n)
Description of the Method

Specified by:
fireDataChanged in interface Mp3dingsTableModel
Parameters:
n - Description of the Parameter

fireDataChanged

public void fireDataChanged()
Description of the Method


Mp3dings 
20100427