uk.ac.starlink.util.gui
Class ArrayTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by uk.ac.starlink.util.gui.ArrayTableModel
All Implemented Interfaces:
Serializable, TableModel
Direct Known Subclasses:
ResourceTableModel

public class ArrayTableModel
extends AbstractTableModel

TableModel which contains its data as an array of objects, one per row. The ArrayTableSorter class can be used in conjunction with this class to provide tables which can be sorted by clicking on column headers. The model works by having an array of column objects which know how to interrogate the array of data objects in such a way as to return cell values. The implementation of the column and data item objects is therefore interlinked.

Since:
14 Oct 2009
Author:
Mark Taylor
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
ArrayTableModel()
          Constructs a model with no columns or rows.
ArrayTableModel(ArrayTableColumn[] columns, Object[] items)
          Constructs a model with a given set of columns and rows.
 
Method Summary
 Class getColumnClass(int icol)
           
 int getColumnCount()
           
 String getColumnName(int icol)
           
 ArrayTableColumn[] getColumns()
          Returns the column specifiers used by this table.
 Object[] getItems()
          Returns the row data items used by this model.
 int getRowCount()
           
 Object getValueAt(int irow, int icol)
           
 void setColumns(ArrayTableColumn[] columns)
          Sets the column specifiers to be used by this table.
 void setItems(Object[] items)
          Sets the row data items to be used by this table.
 void sortByColumn(int icol, boolean descending)
          Sorts the rows in this table according to the ordering of the data in one of the columns.
 
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

ArrayTableModel

public ArrayTableModel()
Constructs a model with no columns or rows.


ArrayTableModel

public ArrayTableModel(ArrayTableColumn[] columns,
                       Object[] items)
Constructs a model with a given set of columns and rows.

Parameters:
columns - array of column specifiers
items - array of row data objects
Method Detail

setColumns

public void setColumns(ArrayTableColumn[] columns)
Sets the column specifiers to be used by this table.

Parameters:
columns - column specifiers

getColumns

public ArrayTableColumn[] getColumns()
Returns the column specifiers used by this table.

Returns:
column specifiers

setItems

public void setItems(Object[] items)
Sets the row data items to be used by this table.

Parameters:
items - row data items, one per row

getItems

public Object[] getItems()
Returns the row data items used by this model.

Returns:
row data items, one per row

sortByColumn

public void sortByColumn(int icol,
                         boolean descending)
Sorts the rows in this table according to the ordering of the data in one of the columns. The ordering may not be maintained if the data changes.

Parameters:
icol - index of column to sort by
descending - true to sort down, false to sort up

getColumnCount

public int getColumnCount()

getRowCount

public int getRowCount()

getValueAt

public Object getValueAt(int irow,
                         int icol)

getColumnName

public String getColumnName(int icol)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnClass

public Class getColumnClass(int icol)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.