org.geotoolkit.gui.swing.referencing
Class CoordinateTableModel

Object
  extended by AbstractTableModel
      extended by CoordinateTableModel
All Implemented Interfaces:
Serializable, TableModel

public class CoordinateTableModel
extends AbstractTableModel

A table of direct positions. All coordinates contained in this table have the same coordinate reference system, which is specified at construction time.

This table model provides a way to display invalid coordinates in a different color. Invalid coordinates are defined here as coordinates outside the CRS domain of validity. This color display can be enabled by the following code:

CoordinateTableModel model = new CoordinateTableModel(crs);
JTable view = new JTable(model);
TableCellRenderer renderer = new CellRenderer();
view.setDefaultRenderer(Double.class, renderer);

Since:
2.3
Version:
3.00
Author:
Cédric Briançon (Geomatys), Hoa Nguyen (Geomatys), Martin Desruisseaux (IRD, Geomatys)
See Also:
Serialized Form
Module:
display/geotk-widgets-swing (download)    View source code for this class

Nested Class Summary
static class CoordinateTableModel.CellRenderer
          A cell renderer for the coordinate table model.
 
Field Summary
 
Fields inherited from class AbstractTableModel
listenerList
 
Constructor Summary
CoordinateTableModel(CoordinateReferenceSystem crs)
          Creates an initially empty table model using the specified coordinate reference system.
 
Method Summary
 void add(Collection<? extends DirectPosition> newPositions)
          Adds a collection of direct positions to this table.
 void add(DirectPosition newPosition)
          Adds a direct position to this table.
 Class<?> getColumnClass(int columnIndex)
          Returns tye type of data for the specified column.
 int getColumnCount()
          Returns the number of columns in the table.
 String getColumnName(int columnIndex)
          Returns the name for the specified column.
 CoordinateReferenceSystem getCoordinateReferenceSystem()
          Returns the CRS for this table model
 List<DirectPosition> getPositions()
          Returns all direct positions in this table.
 int getRowCount()
          Returns the number of rows in the table.
 Number getValueAt(int rowIndex, int columnIndex)
          Returns the value in the table at the specified postion.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Tells that the user can edit every rows in the table.
 boolean isValidCoordinate(int rowIndex)
          Returns true if the position at the specified row is inside the CRS domain of validity.
 void setValueAt(Object value, int rowIndex, int columnIndex)
          Sets the value for the specified cell.
 String toString()
          Returns a string representation of this table.
 
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, wait, wait, wait
 

Constructor Detail

CoordinateTableModel

public CoordinateTableModel(CoordinateReferenceSystem crs)
Creates an initially empty table model using the specified coordinate reference system.

Parameters:
crs - The Coordinate Reference System of all coordinates to appear in this model.
Method Detail

getCoordinateReferenceSystem

public CoordinateReferenceSystem getCoordinateReferenceSystem()
Returns the CRS for this table model

Returns:
The Coordinate Reference System of all coordinates to appear in this model.

getPositions

public List<DirectPosition> getPositions()
Returns all direct positions in this table. The returned list is unmodifiable.

Returns:
All direct positions in this table.
See Also:
add(DirectPosition), add(Collection)

getRowCount

public int getRowCount()
Returns the number of rows in the table.


getColumnCount

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


getColumnName

public String getColumnName(int columnIndex)
Returns the name for the specified column. The default implementation returns the name of the corresponding axis in the table CRS.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnClass

public Class<?> getColumnClass(int columnIndex)
Returns tye type of data for the specified column. For coordinate table, this is always Double.class.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

add

public void add(DirectPosition newPosition)
Adds a direct position to this table. The position is not cloned. Any cell edited in this table will write its change directly into the corresponding DirectPosition object.

Parameters:
newPosition - The position to add to this table.

add

public void add(Collection<? extends DirectPosition> newPositions)
Adds a collection of direct positions to this table. The position is not cloned. Any cell edited in this table will write its change directly into the corresponding DirectPosition object.

Parameters:
newPositions - The positions to add to this table.

getValueAt

public Number getValueAt(int rowIndex,
                         int columnIndex)
Returns the value in the table at the specified postion.

Parameters:
rowIndex - Cell row number.
columnIndex - Cell column number.
Returns:
The ordinate value, or null if no value is available for the specified cell.

setValueAt

public void setValueAt(Object value,
                       int rowIndex,
                       int columnIndex)
Sets the value for the specified cell.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
value - The new value for the cell.
rowIndex - Row number of the cell modified.
columnIndex - Column number of the cell modified.

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Tells that the user can edit every rows in the table.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel

isValidCoordinate

public boolean isValidCoordinate(int rowIndex)
Returns true if the position at the specified row is inside the CRS domain of validity. This method is invoked by CoordinateTableModel.CellRenderer in order to determine if this row should be colorized.

Parameters:
rowIndex - The index of the coordinate to test for validity.
Returns:
true if the coordinate at the given index is valid.

toString

public String toString()
Returns a string representation of this table. The default implementation list all coordinates.

Overrides:
toString in class Object


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