org.geotoolkit.gui.swing.coverage
Class CategoryTable

Object
  extended by AbstractTableModel
      extended by ListTableModel<CategoryRecord>
          extended by CategoryTable
All Implemented Interfaces:
Serializable, TableModel

public class CategoryTable
extends ListTableModel<CategoryRecord>

An editable table model for a list of Category items. Instances of this class are typically created as below:

GridSampleDimension band = ...;
CategoryTable model = new CategoryTable(Locale.FRENCH);
model.setCategories(band.getCategories());

JTable table = ...;
model.configure(table);
The default implementation provides the following columns (implementors can subclass this model if they want to provides additional columns):

Some of the above-cited columns are inter-dependents. For example if the value of the offset or scale factor is modified, then the minimal and maximal geophysics values will be automatically recomputed. Or conversely, if the minimal or maximal geophysics values is modified, then the offset and scale factors will be recomputed.

Since:
3.13
Version:
3.15
Author:
Martin Desruisseaux (Geomatys)
See Also:
Serialized Form
Module:
display/geotk-widgets-swing (download)    View source code for this class

Field Summary
 
Fields inherited from class ListTableModel
elements
 
Fields inherited from class AbstractTableModel
listenerList
 
Constructor Summary
CategoryTable(CategoryTable table)
          Creates a new table initialized to the value of the given table.
CategoryTable(Locale locale)
          Creates a new, initially empty, table.
 
Method Summary
 void configure(JTable table)
          Configures the given JTable for use with this model.
 List<Category> getCategories()
          Returns all categories currently defined in this table.
 Class<?> getColumnClass(int column)
          Returns the type of the given column.
 int getColumnCount()
          Returns the number of columns in the table.
 String getColumnName(int column)
          Returns the name of the given column.
 Object getValueAt(int row, int column)
          Returns the value in the given cell.
 boolean isCellEditable(int row, int column)
          Returns true if the given cell is editable.
 boolean isEditable()
          Returns true if this table is editable.
 void setCategories(List<Category> categories)
          Sets the categories to be shown in the table.
 void setEditable(boolean editable)
          Sets whatever edition should be allowed for any cell in this table.
 void setValueAt(Object value, int row, int column)
          Sets the value in the given cell.
 
Methods inherited from class ListTableModel
add, getElements, getElements, getElements, getRowCount, insert, remove, remove, removeDuplicates, setElements, sort
 
Methods inherited from class AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CategoryTable

public CategoryTable(Locale locale)
Creates a new, initially empty, table.

Parameters:
locale - The locale to use for the column headers.

CategoryTable

public CategoryTable(CategoryTable table)
Creates a new table initialized to the value of the given table.

Parameters:
table - The table from which to copy the rows.
Method Detail

getCategories

public List<Category> getCategories()
Returns all categories currently defined in this table. This is a convenience which invoke CategoryRecord.getCategory() for each element returned by ListTableModel.getElements().

Returns:
The categories, or an empty list if none.

setCategories

public void setCategories(List<Category> categories)
Sets the categories to be shown in the table. This method removes every rows from this table, then adds all categories from the given list wrapped in CategoryRecords.

Alternatively, user can create CategoryRecord themself and invoke one of the add or insert methods directly.

Parameters:
categories - The categories to show, or null for clearing the table.

getColumnCount

public int getColumnCount()
Returns the number of columns in the table.


getColumnName

public String getColumnName(int column)
Returns the name of the given column.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
column - The index of the column being queried.
Returns:
The column name, localized in the local given to the constructor.

getColumnClass

public Class<?> getColumnClass(int column)
Returns the type of the given column. The default implementation returns the class of String, Integer, Double, TransferFunctionType or Object depending on the argument value.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
column - The index of the column being queried.
Returns:
The column type.

getValueAt

public Object getValueAt(int row,
                         int column)
Returns the value in the given cell.

Parameters:
row - The index of the row being queried.
column - The index of the column being queried.
Returns:
The value in the given cell, or null if none.

setValueAt

public void setValueAt(Object value,
                       int row,
                       int column)
Sets the value in the given cell.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
value - The new value.
row - The index of the row being modified.
column - The index of the column being modified.

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Returns true if the given cell is editable. The default implementation returns the same value than isEditable() for every cells.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
row - The index of the row being queried.
column - The index of the column being queried.
Returns:
true if the given cell is editable.

isEditable

public boolean isEditable()
Returns true if this table is editable. Every CategoryTable instances are editable by default.

Returns:
true if this table is editable.

setEditable

public void setEditable(boolean editable)
Sets whatever edition should be allowed for any cell in this table. Editions are enabled by default, like most Swing components.

Parameters:
editable - false for disabling edition, or true for re-enabling it.

configure

public void configure(JTable table)
Configures the given JTable for use with this model. This method performs the following steps:

Parameters:
table - The table in which to install the cell renderer and editors.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.