Class InstancesTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- javax.swing.table.DefaultTableModel
-
- adams.gui.visualization.instances.InstancesTableModel
-
- All Implemented Interfaces:
SpreadSheetSupporter,Serializable,TableModel,weka.core.Undoable
public class InstancesTableModel extends DefaultTableModel implements weka.core.Undoable, SpreadSheetSupporter
The model for the Instances. Supports simple undo by default, but can make use of aUndoHandlerWithQuickAccessas well.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected weka.core.Instancesm_Datathe dataprotected booleanm_IgnoreChangeswhether to ignore changes, i.e. not adding to undo historyprotected HashSet<TableModelListener>m_Listenersthe listenersprotected booleanm_NotificationEnabledwhether notification is enabledprotected booleanm_ReadOnlywhether the table is read-onlyprotected booleanm_ShowAttributeIndexwhether to display the attribute index in the table header.protected booleanm_ShowAttributeWeightswhether to show attribute weights.protected booleanm_ShowWeightsColumnwhether to show a weights column.protected booleanm_UndoEnabledwhether undo is activeprotected UndoHandlerWithQuickAccessm_UndoHandleroptional undo handler.protected List<File>m_UndoListthe undo list (contains temp. filenames)-
Fields inherited from class javax.swing.table.DefaultTableModel
columnIdentifiers, dataVector
-
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
-
Constructor Summary
Constructors Constructor Description InstancesTableModel()performs some initializationInstancesTableModel(weka.core.Instances data)initializes the model with the given data
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTableModelListener(TableModelListener l)adds a listener to the list that is notified each time a change to data model occursvoidaddUndoPoint()adds an undo point to the undo history, if the undo support is enabledvoidattributeAsClassAt(int columnIndex)sets the attribute at the given col index as the new class attribute, i.e.booleancanUndo()returns whether an undo is possible, i.e. whether there are any undo points saved so farvoidclearUndo()removes the undo historyInstancesTableModelcopy(weka.core.Instances data)Returns a new model with the same setup.voiddeleteAttributeAt(int columnIndex)deletes the attribute at the given col index. notifies the listeners.voiddeleteAttributeAt(int columnIndex, boolean notify)deletes the attribute at the given col indexvoiddeleteAttributes(int[] columnIndices)deletes the attributes at the given indicesvoiddeleteInstanceAt(int rowIndex)deletes the instance at the given indexvoiddeleteInstanceAt(int rowIndex, boolean notify)deletes the instance at the given indexvoiddeleteInstances(int[] rowIndices)deletes the instances at the given positionsweka.core.AttributegetAttributeAt(int columnIndex)returns the attribute at the given index, can be NULL if not an attribute columnintgetAttributeColumn(String name)returns the column of the given attribute name, -1 if not foundClass<?>getColumnClass(int columnIndex)returns the most specific superclass for all the cell values in the column (always String)intgetColumnCount()returns the number of columns in the modelStringgetColumnName(int columnIndex)returns the name of the column at columnIndexweka.core.InstancesgetInstances()returns the datadoublegetInstancesValueAt(int rowIndex, int columnIndex)returns the double value of the underlying Instances object at the given position, -1 if out of boundsintgetRowCount()returns the number of rows in the modelbooleangetShowAttributeIndex()Returns whether to display the attribute index in the header.booleangetShowAttributeWeights()Returns whether to display attribute weights.booleangetShowWeightsColumn()Returns whether to display a weights column.intgetType(int columnIndex)returns the TYPE of the attribute at the given positionintgetType(int rowIndex, int columnIndex)returns the TYPE of the attribute at the given positionUndoHandlerWithQuickAccessgetUndoHandler()Returns the undo handler in use.ObjectgetValueAt(int rowIndex, int columnIndex)returns the value for the cell at columnindex and rowIndexvoidinsertInstance(int index)voidinsertInstance(int index, boolean notify)booleanisCellEditable(int rowIndex, int columnIndex)returns true if the cell at rowindex and columnindexis editableprotected booleanisClassIndex(int columnIndex)checks whether the column represents the class or notbooleanisMissingAt(int rowIndex, int columnIndex)checks whether the value at the given position is missingbooleanisNotificationEnabled()returns whether the notification of changes is enabledbooleanisReadOnly()returns whether the model is read-onlybooleanisUndoEnabled()returns whether undo support is enabledvoidnotifyListener(TableModelEvent e)notfies all listener of the change of the modelvoidremoveTableModelListener(TableModelListener l)removes a listener from the list that is notified each time a change to the data model occursvoidrenameAttributeAt(int columnIndex, String newName)renames the attribute at the given col indexvoidsetInstances(weka.core.Instances data)sets the datavoidsetNotificationEnabled(boolean enabled)sets whether the notification of changes is enabledvoidsetReadOnly(boolean value)sets whether the model is read-onlyvoidsetShowAttributeIndex(boolean value)Sets whether to display the attribute index in the header.voidsetShowAttributeWeights(boolean value)Sets whether to display attribute weights.voidsetShowWeightsColumn(boolean value)Sets whether to display a weights column.voidsetUndoEnabled(boolean enabled)sets whether undo support is enabledvoidsetUndoHandler(UndoHandlerWithQuickAccess value)Sets the undo handler to use.voidsetValueAt(Object aValue, int rowIndex, int columnIndex)sets the value in the cell at columnIndex and rowIndex to aValue. but only the value and the value can be changedvoidsetValueAt(Object aValue, int rowIndex, int columnIndex, boolean notify)Sets the value in the cell at columnIndex and rowIndex to aValue. but only the value and the value can be changed.voidsortInstances(int columnIndex)sorts the instances via the given attributevoidsortInstances(int columnIndex, boolean ascending)sorts the instances via the given attributeSpreadSheettoSpreadSheet()Returns the content as spreadsheet.voidundo()undoes the last actionprotected booleanuseUndoHandler()Returns whether to use the undo handler.-
Methods inherited from class javax.swing.table.DefaultTableModel
addColumn, addColumn, addColumn, addRow, addRow, convertToVector, convertToVector, getDataVector, insertRow, insertRow, moveRow, newDataAvailable, newRowsAdded, removeRow, rowsRemoved, setColumnCount, setColumnIdentifiers, setColumnIdentifiers, setDataVector, setDataVector, setNumRows, setRowCount
-
Methods inherited from class javax.swing.table.AbstractTableModel
findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners
-
-
-
-
Field Detail
-
m_Listeners
protected HashSet<TableModelListener> m_Listeners
the listeners
-
m_Data
protected weka.core.Instances m_Data
the data
-
m_NotificationEnabled
protected boolean m_NotificationEnabled
whether notification is enabled
-
m_UndoHandler
protected UndoHandlerWithQuickAccess m_UndoHandler
optional undo handler.
-
m_UndoEnabled
protected boolean m_UndoEnabled
whether undo is active
-
m_IgnoreChanges
protected boolean m_IgnoreChanges
whether to ignore changes, i.e. not adding to undo history
-
m_ReadOnly
protected boolean m_ReadOnly
whether the table is read-only
-
m_ShowAttributeIndex
protected boolean m_ShowAttributeIndex
whether to display the attribute index in the table header.
-
m_ShowWeightsColumn
protected boolean m_ShowWeightsColumn
whether to show a weights column.
-
m_ShowAttributeWeights
protected boolean m_ShowAttributeWeights
whether to show attribute weights.
-
-
Method Detail
-
isNotificationEnabled
public boolean isNotificationEnabled()
returns whether the notification of changes is enabled- Returns:
- true if notification of changes is enabled
-
setNotificationEnabled
public void setNotificationEnabled(boolean enabled)
sets whether the notification of changes is enabled- Parameters:
enabled- enables/disables the notification
-
setUndoHandler
public void setUndoHandler(UndoHandlerWithQuickAccess value)
Sets the undo handler to use.- Parameters:
value- the handler, null if to turn off
-
getUndoHandler
public UndoHandlerWithQuickAccess getUndoHandler()
Returns the undo handler in use.- Returns:
- the handler, null if none set
-
useUndoHandler
protected boolean useUndoHandler()
Returns whether to use the undo handler.- Returns:
- the undo handler
-
isUndoEnabled
public boolean isUndoEnabled()
returns whether undo support is enabled- Specified by:
isUndoEnabledin interfaceweka.core.Undoable- Returns:
- true if undo support is enabled
-
setUndoEnabled
public void setUndoEnabled(boolean enabled)
sets whether undo support is enabled- Specified by:
setUndoEnabledin interfaceweka.core.Undoable- Parameters:
enabled- whether to enable/disable undo support
-
isReadOnly
public boolean isReadOnly()
returns whether the model is read-only- Returns:
- true if model is read-only
-
setReadOnly
public void setReadOnly(boolean value)
sets whether the model is read-only- Parameters:
value- if true the model is set to read-only
-
setInstances
public void setInstances(weka.core.Instances data)
sets the data- Parameters:
data- the data to use
-
getInstances
public weka.core.Instances getInstances()
returns the data- Returns:
- the current data
-
getAttributeAt
public weka.core.Attribute getAttributeAt(int columnIndex)
returns the attribute at the given index, can be NULL if not an attribute column- Parameters:
columnIndex- the index of the column- Returns:
- the attribute at the position
-
getType
public int getType(int columnIndex)
returns the TYPE of the attribute at the given position- Parameters:
columnIndex- the index of the column- Returns:
- the attribute type
-
getType
public int getType(int rowIndex, int columnIndex)returns the TYPE of the attribute at the given position- Parameters:
rowIndex- the index of the rowcolumnIndex- the index of the column- Returns:
- the attribute type
-
deleteAttributeAt
public void deleteAttributeAt(int columnIndex)
deletes the attribute at the given col index. notifies the listeners.- Parameters:
columnIndex- the index of the attribute to delete
-
deleteAttributeAt
public void deleteAttributeAt(int columnIndex, boolean notify)deletes the attribute at the given col index- Parameters:
columnIndex- the index of the attribute to deletenotify- whether to notify the listeners
-
deleteAttributes
public void deleteAttributes(int[] columnIndices)
deletes the attributes at the given indices- Parameters:
columnIndices- the column indices
-
renameAttributeAt
public void renameAttributeAt(int columnIndex, String newName)renames the attribute at the given col index- Parameters:
columnIndex- the index of the columnnewName- the new name of the attribute
-
attributeAsClassAt
public void attributeAsClassAt(int columnIndex)
sets the attribute at the given col index as the new class attribute, i.e. it moves it to the end of the attributes- Parameters:
columnIndex- the index of the column
-
deleteInstanceAt
public void deleteInstanceAt(int rowIndex)
deletes the instance at the given index- Parameters:
rowIndex- the index of the row
-
deleteInstanceAt
public void deleteInstanceAt(int rowIndex, boolean notify)deletes the instance at the given index- Parameters:
rowIndex- the index of the rownotify- whether to notify the listeners
-
insertInstance
public void insertInstance(int index)
-
insertInstance
public void insertInstance(int index, boolean notify)
-
deleteInstances
public void deleteInstances(int[] rowIndices)
deletes the instances at the given positions- Parameters:
rowIndices- the indices to delete
-
sortInstances
public void sortInstances(int columnIndex)
sorts the instances via the given attribute- Parameters:
columnIndex- the index of the column
-
sortInstances
public void sortInstances(int columnIndex, boolean ascending)sorts the instances via the given attribute- Parameters:
columnIndex- the index of the columnascending- ascending if true, otherwise descending
-
getAttributeColumn
public int getAttributeColumn(String name)
returns the column of the given attribute name, -1 if not found- Parameters:
name- the name of the attribute- Returns:
- the column index or -1 if not found
-
getColumnClass
public Class<?> getColumnClass(int columnIndex)
returns the most specific superclass for all the cell values in the column (always String)- Specified by:
getColumnClassin interfaceTableModel- Overrides:
getColumnClassin classAbstractTableModel- Parameters:
columnIndex- the column index- Returns:
- the class of the column
-
getColumnCount
public int getColumnCount()
returns the number of columns in the model- Specified by:
getColumnCountin interfaceTableModel- Overrides:
getColumnCountin classDefaultTableModel- Returns:
- the number of columns
-
isClassIndex
protected boolean isClassIndex(int columnIndex)
checks whether the column represents the class or not- Parameters:
columnIndex- the index of the column- Returns:
- true if the column is the class attribute
-
getColumnName
public String getColumnName(int columnIndex)
returns the name of the column at columnIndex- Specified by:
getColumnNamein interfaceTableModel- Overrides:
getColumnNamein classDefaultTableModel- Parameters:
columnIndex- the index of the column- Returns:
- the name of the column
-
getRowCount
public int getRowCount()
returns the number of rows in the model- Specified by:
getRowCountin interfaceTableModel- Overrides:
getRowCountin classDefaultTableModel- Returns:
- the number of rows
-
isMissingAt
public boolean isMissingAt(int rowIndex, int columnIndex)checks whether the value at the given position is missing- Parameters:
rowIndex- the row indexcolumnIndex- the column index- Returns:
- true if the value at the position is missing
-
getInstancesValueAt
public double getInstancesValueAt(int rowIndex, int columnIndex)returns the double value of the underlying Instances object at the given position, -1 if out of bounds- Parameters:
rowIndex- the row indexcolumnIndex- the column index- Returns:
- the underlying value in the Instances object
-
getValueAt
public Object getValueAt(int rowIndex, int columnIndex)
returns the value for the cell at columnindex and rowIndex- Specified by:
getValueAtin interfaceTableModel- Overrides:
getValueAtin classDefaultTableModel- Parameters:
rowIndex- the row indexcolumnIndex- the column index- Returns:
- the value at the position
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex)returns true if the cell at rowindex and columnindexis editable- Specified by:
isCellEditablein interfaceTableModel- Overrides:
isCellEditablein classDefaultTableModel- Parameters:
rowIndex- the index of the rowcolumnIndex- the index of the column- Returns:
- true if the cell is editable
-
setValueAt
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
sets the value in the cell at columnIndex and rowIndex to aValue. but only the value and the value can be changed- Specified by:
setValueAtin interfaceTableModel- Overrides:
setValueAtin classDefaultTableModel- Parameters:
aValue- the new valuerowIndex- the row indexcolumnIndex- the column index
-
setValueAt
public void setValueAt(Object aValue, int rowIndex, int columnIndex, boolean notify)
Sets the value in the cell at columnIndex and rowIndex to aValue. but only the value and the value can be changed. Ignores operation if value hasn't changed.- Parameters:
aValue- the new valuerowIndex- the row indexcolumnIndex- the column indexnotify- whether to notify the listeners
-
addTableModelListener
public void addTableModelListener(TableModelListener l)
adds a listener to the list that is notified each time a change to data model occurs- Specified by:
addTableModelListenerin interfaceTableModel- Overrides:
addTableModelListenerin classAbstractTableModel- Parameters:
l- the listener to add
-
removeTableModelListener
public void removeTableModelListener(TableModelListener l)
removes a listener from the list that is notified each time a change to the data model occurs- Specified by:
removeTableModelListenerin interfaceTableModel- Overrides:
removeTableModelListenerin classAbstractTableModel- Parameters:
l- the listener to remove
-
notifyListener
public void notifyListener(TableModelEvent e)
notfies all listener of the change of the model- Parameters:
e- the event to send to the listeners
-
clearUndo
public void clearUndo()
removes the undo history- Specified by:
clearUndoin interfaceweka.core.Undoable
-
canUndo
public boolean canUndo()
returns whether an undo is possible, i.e. whether there are any undo points saved so far- Specified by:
canUndoin interfaceweka.core.Undoable- Returns:
- returns TRUE if there is an undo possible
-
undo
public void undo()
undoes the last action- Specified by:
undoin interfaceweka.core.Undoable
-
addUndoPoint
public void addUndoPoint()
adds an undo point to the undo history, if the undo support is enabled- Specified by:
addUndoPointin interfaceweka.core.Undoable- See Also:
isUndoEnabled(),setUndoEnabled(boolean)
-
setShowAttributeIndex
public void setShowAttributeIndex(boolean value)
Sets whether to display the attribute index in the header.- Parameters:
value- if true then the attribute indices are displayed in the table header
-
getShowAttributeIndex
public boolean getShowAttributeIndex()
Returns whether to display the attribute index in the header.- Returns:
- true if the attribute indices are displayed in the table header
-
setShowWeightsColumn
public void setShowWeightsColumn(boolean value)
Sets whether to display a weights column.- Parameters:
value- if true then the weights get shown in a separate column
-
getShowWeightsColumn
public boolean getShowWeightsColumn()
Returns whether to display a weights column.- Returns:
- true if the weights get shown in a separate column
-
setShowAttributeWeights
public void setShowAttributeWeights(boolean value)
Sets whether to display attribute weights.- Parameters:
value- if true then the attributes weights get shown in the header
-
getShowAttributeWeights
public boolean getShowAttributeWeights()
Returns whether to display attribute weights.- Returns:
- true if the attributes weights get shown in the header
-
copy
public InstancesTableModel copy(weka.core.Instances data)
Returns a new model with the same setup.- Parameters:
data- the data to display- Returns:
- the new model
-
toSpreadSheet
public SpreadSheet toSpreadSheet()
Returns the content as spreadsheet.- Specified by:
toSpreadSheetin interfaceSpreadSheetSupporter- Returns:
- the content
-
-