FileDocCategorySizeDatePackage
ArrayListTableModel.javaAPI DocExample3020Mon May 31 22:51:38 BST 2004com.darwinsys.swingui

ArrayListTableModel

public abstract class ArrayListTableModel extends AbstractTableModel
JTable model for ArrayList of heterogeneous objects. Subclasses must set String columnNames[] and Class columnClasses[], which MUST be in the same order. Subclasses need only implement these AbstractTableModel methods:
public int getColumnCount() {
public Object getValueAt(int row, int col) {
public void setValueAt(Object val, int row, int col) {

Fields Summary
protected String[]
columnNames
List of column names, must be provided by subclass.
protected Class[]
columnClasses
List of column names, must be provided by subclass.
protected ArrayList
methods
The list of Method object
private int
ROW_INVALID
for caching.
private int
prevRow
for caching, shared by get/set ValueAt
private Object
current
for caching, shared by get/set ValueAt
Constructors Summary
public ArrayListTableModel(ArrayList m)
Constructor requires the list of objects


	       
	   
		methods = m;
	
Methods Summary
public java.lang.ObjectgetCached(int row)
Cache one most-recently-used item. This is a convenience routine that subclasses are invited but not required to use. Normal use would be, in get/setValueAt():
public void setValueAt(int row, ...) {
MyDataType current = (MyDataType) getCached(row);
...
}

		if (row != prevRow) {
			current = methods.get(row);
			prevRow = row;
		}
		return current;
	
public java.lang.ClassgetColumnClass(int n)
Get the class of a given column, from the list provided by subclass

		if (columnClasses == null)
			throw new IllegalStateException("columnClasses not set");
		int max = columnClasses.length;
		if (n>=max)
			throw new ArrayIndexOutOfBoundsException(
			"columnClasses has " + max + " elements; you asked for " + max);
		return columnClasses[n];
	
public java.lang.StringgetColumnName(int n)
Get the name of a given column, from the list provided by subclass

		if (columnNames == null)
			throw new IllegalStateException("columnNames not set");
		int max = columnNames.length;
		if (n>=max)
			throw new ArrayIndexOutOfBoundsException(
			"columnNames has " + max + " elements; you asked for " + max);
		return columnNames[n];
	
public intgetRowCount()
Returns the number of objects in the list.

		return methods.size();
	
public voidinvalidateCache()
Invalidate the cache. Called automatically by setListData(); must be called if you otherwise change the ArrayList.

		prevRow = ROW_INVALID;
	
public booleanisCellEditable(int rowIndex, int columnIndex)
All cells are editable. Subclasses can override this if only some cells should be editable.

		return true;
	
voidsetListData(java.util.ArrayList v)
Allow the model to load the ArrayList all at once, as when loading a file.

		methods = v;
		invalidateCache();