CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.cubetwister.doc
Class CubePartsTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by ch.randelshofer.cubetwister.doc.CubePartsTableModel
All Implemented Interfaces:
MutableTableModel, java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.swing.event.TreeModelListener, javax.swing.table.TableModel

public class CubePartsTableModel
extends javax.swing.table.AbstractTableModel
implements MutableTableModel, java.beans.PropertyChangeListener, javax.swing.event.TreeModelListener

Wraps the macros provided by CubeModel to make them accessible by a MutableJTable.

Version:
2.0 2006-06-03 Reworked.
1.0.1 2002-04-07 Method getInsertableRowTypes added.
1.0 2001-07-19
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
CubePartsTableModel()
          Creates a new CubeColorsTableModel which wraps a default CubeModel.
CubePartsTableModel(CubeModel n)
          Creates a new CubeColorsTableModel which wraps the provided CubeModel.
 
Method Summary
 void createRow(int row, java.lang.Object type)
          Invoke this to insert a new row into the table.
 java.awt.datatransfer.Transferable exportRowTransferable(int[] rows)
          Creates a Transferable to use as the source for a data transfer of the specified elements.
 java.lang.Class getColumnClass(int column)
          Returns the most specific superclass for all the cell values in the column.
 int getColumnCount()
          Returns the number of columns in the model.
 java.lang.String getColumnName(int columnIndex)
          Returns the name of the column at columnIndex.
 java.lang.Object getCreatableRowType(int row)
          Returns an empty array since insertion of parts is not allowed.
 java.lang.Object[] getCreatableRowTypes(int row)
          Returns an empty array since insertion of parts is not allowed.
 javax.swing.Action[] getRowActions(int[] rows)
          Gets actions for the specified rows.
 int getRowCount()
          Returns the number of rows in the model.
 CubePartModel getRowObject(int row)
           
 java.lang.Object getValueAt(int row, int column)
          Returns the value for the cell at columnIndex and rowIndex.
 int importRowTransferable(java.awt.datatransfer.Transferable transfer, int action, int row, boolean asChild)
          Causes a transfer to the model from a clipboard or a DND drop operation.
 boolean isCellEditable(int row, int column)
          Returns true if the cell at rowIndex and columnIndex is editable.
 boolean isRowAddable(int row)
          Returns true if a row can be added.
 boolean isRowDuplicateable(int row)
          Returns wether a row may be duplicated.
 boolean isRowImportable(java.awt.datatransfer.DataFlavor[] flavors, int action, int row, boolean asChild)
          Indicates whether the model would accept an import of the given set of data flavors prior to actually attempting to import it.
 boolean isRowInsertable(java.lang.Object type, int row)
          Returns wether a row may be inserted.
 boolean isRowRemovable(int row)
          Returns wether the specified node may be removed.
 void propertyChange(java.beans.PropertyChangeEvent evt)
           
 void removeRow(int row)
          Message this to remove a row from the table.
 void setModel(CubeModel value)
           
 void setValueAt(java.lang.Object value, int row, int column)
          Sets the value in the cell at columnIndex and rowIndex to aValue is the new value.
 void treeNodesChanged(javax.swing.event.TreeModelEvent evt)
          Invoked after a node (or a set of siblings) has changed in some way.
 void treeNodesInserted(javax.swing.event.TreeModelEvent evt)
          Invoked after nodes have been inserted into the tree.
 void treeNodesRemoved(javax.swing.event.TreeModelEvent evt)
          Invoked after nodes have been removed from the tree.
 void treeStructureChanged(javax.swing.event.TreeModelEvent evt)
          Invoked after the tree has drastically changed structure from a given node down.
 
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 javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Constructor Detail

CubePartsTableModel

public CubePartsTableModel()
Creates a new CubeColorsTableModel which wraps a default CubeModel.


CubePartsTableModel

public CubePartsTableModel(CubeModel n)
Creates a new CubeColorsTableModel which wraps the provided CubeModel.

Method Detail

setModel

public void setModel(CubeModel value)

getRowObject

public CubePartModel getRowObject(int row)

getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)
Returns the value for the cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
row - the row whose value is to be looked up
column - the column whose value is to be looked up
Returns:
the value Object at the specified cell

getColumnName

public java.lang.String getColumnName(int columnIndex)
Returns the name of the column at columnIndex. This is used to initialize the table's column header name. Note: this name does not need to be unique; two columns in a table can have the same name.

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

isRowInsertable

public boolean isRowInsertable(java.lang.Object type,
                               int row)
Returns wether a row may be inserted.

Parameters:
row - index of the new row.

isRowDuplicateable

public boolean isRowDuplicateable(int row)
Returns wether a row may be duplicated.

Parameters:
row - index of the new row.

getRowCount

public int getRowCount()
Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
the number or rows in the model
See Also:
getColumnCount()

createRow

public void createRow(int row,
                      java.lang.Object type)
Invoke this to insert a new row into the table.

Specified by:
createRow in interface MutableTableModel
Parameters:
row - index of the new row.
type - element type to be inserted.
Throws:
java.lang.IllegalStateException - if the row may not be inserted.

importRowTransferable

public int importRowTransferable(java.awt.datatransfer.Transferable transfer,
                                 int action,
                                 int row,
                                 boolean asChild)
Description copied from interface: MutableTableModel
Causes a transfer to the model from a clipboard or a DND drop operation.

Specified by:
importRowTransferable in interface MutableTableModel
Parameters:
transfer - The transfer data.
action - The action DnDConstants.ACTION_COPY, .ACTION_MOVE or .ACTION_LINK.
row - The insertion point. 0 <= row <= getRowCount()
asChild - Indicates that the item is to be imported as a child of the list item rather than as an individual element of the list.
Returns:
The number of imported elements.

isRowImportable

public boolean isRowImportable(java.awt.datatransfer.DataFlavor[] flavors,
                               int action,
                               int row,
                               boolean asChild)
Description copied from interface: MutableTableModel
Indicates whether the model would accept an import of the given set of data flavors prior to actually attempting to import it.

Specified by:
isRowImportable in interface MutableTableModel
Parameters:
flavors - the data formats available
action - The action DnDConstants.ACTION_COPY, .ACTION_MOVE or .ACTION_LINK.
row - The insertion point. 0 <= row <= getRowCount()
asChild - Indicates that the item is to be imported as a child of the list item rather than as an individual element / of the list.
Returns:
true if the data can be imported.
See Also:
DnDConstants

exportRowTransferable

public java.awt.datatransfer.Transferable exportRowTransferable(int[] rows)
Description copied from interface: MutableTableModel
Creates a Transferable to use as the source for a data transfer of the specified elements. Returns the representation of the rows to be transferred, or null if transfer is not possible.

Specified by:
exportRowTransferable in interface MutableTableModel
Parameters:
rows - Row indices.

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Returns true if the cell at rowIndex and columnIndex is editable. Otherwise, setValueAt() on the cell will not change the value of that cell.

Specified by:
isCellEditable in interface MutableTableModel
Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel
Parameters:
row - the row whose value is to be looked up
column - the column whose value is to be looked up
Returns:
true if the cell is editable.
See Also:
setValueAt(java.lang.Object, int, int)

setValueAt

public void setValueAt(java.lang.Object value,
                       int row,
                       int column)
Sets the value in the cell at columnIndex and rowIndex to aValue is the new value.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel
Parameters:
value - the new value
row - the row whose value is to be changed
column - the column whose value is to be changed
See Also:
getValueAt(int, int), isCellEditable(int, int)

getColumnClass

public java.lang.Class getColumnClass(int column)
Returns the most specific superclass for all the cell values in the column. This is used by the JTable to set up a default renderer and editor for the column.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Returns:
the common ancestor class of the object values in the model.

removeRow

public void removeRow(int row)
Message this to remove a row from the table.

Specified by:
removeRow in interface MutableTableModel
Parameters:
row - index of the row.
Throws:
java.lang.IllegalStateException - if the row may not be removed.
See Also:
MutableTableModel.isRowRemovable(int)

isRowRemovable

public boolean isRowRemovable(int row)
Returns wether the specified node may be removed.

Specified by:
isRowRemovable in interface MutableTableModel
Parameters:
row - index of the row.
See Also:
MutableTableModel.removeRow(int)

isRowAddable

public boolean isRowAddable(int row)
Description copied from interface: MutableTableModel
Returns true if a row can be added.

Specified by:
isRowAddable in interface MutableTableModel
Parameters:
row - index of the element. 0 <= index <= getSize()

getColumnCount

public int getColumnCount()
Returns the number of columns in the model. A JTable uses this method to determine how many columns it should create and display by default.

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
the number or columns in the model
See Also:
getRowCount()

getRowActions

public javax.swing.Action[] getRowActions(int[] rows)
Description copied from interface: MutableTableModel
Gets actions for the specified rows.

Specified by:
getRowActions in interface MutableTableModel
Parameters:
rows - The rows.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

treeStructureChanged

public void treeStructureChanged(javax.swing.event.TreeModelEvent evt)

Invoked after the tree has drastically changed structure from a given node down. If the path returned by e.getPath() is of length one and the first element does not identify the current root node the first element should become the new root of the tree.

evt.path() holds the path to the node.

evt.childIndices() returns null.

Specified by:
treeStructureChanged in interface javax.swing.event.TreeModelListener

treeNodesInserted

public void treeNodesInserted(javax.swing.event.TreeModelEvent evt)

Invoked after nodes have been inserted into the tree.

e.path() returns the parent of the new nodes

e.childIndices() returns the indices of the new nodes in ascending order.

Specified by:
treeNodesInserted in interface javax.swing.event.TreeModelListener

treeNodesRemoved

public void treeNodesRemoved(javax.swing.event.TreeModelEvent evt)

Invoked after nodes have been removed from the tree. Note that if a subtree is removed from the tree, this method may only be invoked once for the root of the removed subtree, not once for each individual set of siblings removed.

e.path() returns the former parent of the deleted nodes.

e.childIndices() returns the indices the nodes had before they were deleted in ascending order.

Specified by:
treeNodesRemoved in interface javax.swing.event.TreeModelListener

treeNodesChanged

public void treeNodesChanged(javax.swing.event.TreeModelEvent evt)

Invoked after a node (or a set of siblings) has changed in some way. The node(s) have not changed locations in the tree or altered their children arrays, but other attributes have changed and may affect presentation. Example: the name of a file has changed, but it is in the same location in the file system.

To indicate the root has changed, childIndices and children will be null.

evt.path() returns the path the parent of the changed node(s).

evt.childIndices() returns the index(es) of the changed node(s).

Specified by:
treeNodesChanged in interface javax.swing.event.TreeModelListener

getCreatableRowTypes

public java.lang.Object[] getCreatableRowTypes(int row)
Returns an empty array since insertion of parts is not allowed.

Specified by:
getCreatableRowTypes in interface MutableTableModel
Parameters:
row - The insertion point. 0 <= index <= getRowCount()
Returns:
an array of Object's that specify element types that can be inserted at the insertion point. Returns an empty array if no elements can be inserted here. Never returns null. This array must include the type returned by operation getCreatableType.

getCreatableRowType

public java.lang.Object getCreatableRowType(int row)
Returns an empty array since insertion of parts is not allowed.

Specified by:
getCreatableRowType in interface MutableTableModel
Parameters:
row - The insertion point. 0 <= index <= getRowCount()
Returns:
an Object that specifies the default element type that can be inserted at the insertion point. Returns null if no elements can be inserted here. The value must be one of the types returned by operation getCreatableTypes.

(c) Werner Randelshofer.
All rights reserved.