org.geotools.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. Invalide coordinates are defined here as coordinates outside the CRS valid area. This color display can be enabled by the following code:

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

Since:
2.3
Author:
Cédric Briançon, Hoa Nguyen, Martin Desruisseaux
See Also:
Serialized Form
Module:

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 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.
 String getColumnName(int columnIndex)
          Returns the name for the specified column.
 CoordinateReferenceSystem getCoordinateReferenceSystem()
          Returns the CRS for this table model
 List getPositions()
          Returns all direct positions in this table.
 int getRowCount()
          Returns the number of rows in the table.
 Object getValueAt(int rowIndex, int columnIndex)
          Returns the value in the table at the specified postion.
 boolean isCellEditable(int rowIndex, int colIndex)
          Specifies that the user can fill all rows in the table.
 boolean isValidCoordinate(int rowIndex)
          Returns true if the position at the specified row is inside the CRS valid area.
 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.

Method Detail

getCoordinateReferenceSystem

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


getPositions

public List getPositions()
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.


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.


add

public void add(Collection 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.


getValueAt

public Object 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 colIndex)
Specifies that the user can fill all 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 valid area. This method is invoked by CoordinateTableModel.CellRenderer in order to determine if this row should be colorized.


toString

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

Overrides:
toString in class Object


Copyright © 1996-2009 Geotools. All Rights Reserved.