jwo.landserf.structure
Class AttributeTable

java.lang.Object
  extended by jwo.landserf.structure.AttributeTable
All Implemented Interfaces:
Serializable

public class AttributeTable
extends Object
implements Serializable

Represents a set of attributes that can be associated with a spatial model. The table must consist of a unique primary key that corresponds to the spatial object's primary attribute, and a set of one or more secondary attributes. These attributes can be numeric or textual.

Version:
2.3, 4th December, 2007.
Author:
Jo Wood
See Also:
Serialized Form

Constructor Summary
AttributeTable(AttributeTable oldTable)
          Creates a new clone of the given attribute table.
AttributeTable(int numCols)
          Creates an attribute table with the given number of columns.
AttributeTable(int numCols, String[] headings)
          Creates an attribute table with the given number of columns and given column headings.
 
Method Summary
 void addAttributes(float id, Object[] attributes)
          Adds a given set of attributes associated with the given attribute ID to the table.
 void addColumn()
          Adds a column with default name to the table.
 void addColumn(String columnName)
          Adds a column with the given name to the table.
 void addRow()
          Adds a blank row to the attribute table.
 int getActiveColumn()
          Reports the currently selected active column used for retrieving attributes, or -1 if table is empty.
 Object getAttribute(float id)
          Retrieves the attribute associated with the given ID.
 Object[] getAttributes(float id)
          Retrieves all the attributes associated with the given ID.
 Class getColumnClass(int column)
          Reports the type of object stored in the given column.
 int getColumnCount()
          Reports the number of columns in the table.
 String getColumnName(int col)
          Reports the given column heading.
 String getFormattedAttribute(float id)
          Retrieves a formatted version of the attribute associated with the given ID.
 float getNumericAttribute(float id)
          Retrieves a numeric attribute associated with the given ID.
 int getRowCount()
          Reports the number of rows in the table.
 AbstractTableModel getTableModel()
          Reports the table model used to store the attribute values.
 Object getValueAt(int row, int col)
          Reports the value stored in the table at the given coordinates.
 boolean isCellEditable(int row, int col)
          Reports whether the cell represented by the given coordinates is editable.
 boolean isNumeric()
          Reports whether the current active column contains numeric values.
 boolean isNumeric(int col)
          Reports whether the given column contains numeric values.
 void setActiveColumn(int activeCol)
          Sets the column to use for retrieving attributes.
 void setAttribute(float id, int column, Object newValue)
          Sets the attribute associated with the given ID and column value.
 void setColumnName(int col, String name)
          Sets the name of the given column.
 void setHeadings(String[] headings)
          Sets the headings associated with the table columns.
 void setValueAt(Object value, int row, int col)
          Sets the value stored in the table at the given coordinates.
 void validateColumns()
          Checks the numeric/text status of all cells.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AttributeTable

public AttributeTable(AttributeTable oldTable)
Creates a new clone of the given attribute table. If the supplied table is null, this will create an empty table with 1 column ready to store IDs.

Parameters:
oldTable - Table to clone.

AttributeTable

public AttributeTable(int numCols)
Creates an attribute table with the given number of columns. The first column will always be the primary ID, the remaining columns will hold the attributes associated with that ID.

Parameters:
numCols - Number of columns (equal to 1 + number of attributes).

AttributeTable

public AttributeTable(int numCols,
                      String[] headings)
Creates an attribute table with the given number of columns and given column headings. The first column will always be the primary ID, the remaining columns will hold the attributes associated with that ID.

Parameters:
numCols - Number of columns (equal to 1 + number of attributes).
headings - Array of column headings, or null if none provided.
Method Detail

setHeadings

public void setHeadings(String[] headings)
Sets the headings associated with the table columns. The array of headings must be the same length as the number of columns including the primary ID. If it is not, this method will silently fail and not change the column headings.

Parameters:
headings - List of column headings.

setActiveColumn

public void setActiveColumn(int activeCol)
Sets the column to use for retrieving attributes. A value of 0 indicates the ID, 1 the first attribute etc. Performs a check on the new active column see if values are numeric or not.

Parameters:
activeCol - The column to use for retrieving attributes.

validateColumns

public void validateColumns()
Checks the numeric/text status of all cells. If a column contains only numeric values, it is set to be numeric, if it contains any non-numeric cells, it will be set to store text. This is not applied to the first column which should always contain numeric IDs.


getTableModel

public AbstractTableModel getTableModel()
Reports the table model used to store the attribute values.

Returns:
Table model used to store attributes. This can be used by GUI elements that wish to display the attributes as a JTable.

getActiveColumn

public int getActiveColumn()
Reports the currently selected active column used for retrieving attributes, or -1 if table is empty. The object's ID is column 0, the first non-ID attribute in the table is 1 etc.

Returns:
Column used for retrieving attributes.

getAttribute

public Object getAttribute(float id)
Retrieves the attribute associated with the given ID. The attribute is determined by the ID itself and the currently selected 'active column'.

Parameters:
id - ID to search for.
Returns:
Matched attribute or null if ID not found.

getFormattedAttribute

public String getFormattedAttribute(float id)
Retrieves a formatted version of the attribute associated with the given ID. Useful for neat output, but should not be used for processing since attributes may be rounded. The attribute is determined by the ID itself and the currently selected 'active column'.

Parameters:
id - ID to search for.
Returns:
Formatted attribute or empty string if ID not found.

setAttribute

public void setAttribute(float id,
                         int column,
                         Object newValue)
Sets the attribute associated with the given ID and column value. If the ID does not exist, a new one will be created and the given value will be associated with it.

Parameters:
id - ID to search for.
column - Column number representing attribute to set (0 = ID).
newValue - New value to place in table.

getAttributes

public Object[] getAttributes(float id)
Retrieves all the attributes associated with the given ID. The returned attributes exclude the ID itself.

Parameters:
id - ID to search for.
Returns:
An array of attributes associated with the ID or null if ID not found.

getNumericAttribute

public float getNumericAttribute(float id)
Retrieves a numeric attribute associated with the given ID. The attribute is determined by the ID itself and the currently selected 'active column'. If the active column contains non-numeric data, the ID itself is returned.

Parameters:
id - ID to search for.
Returns:
Matched attribute or NO_VALUE if ID not found.

addAttributes

public void addAttributes(float id,
                          Object[] attributes)
Adds a given set of attributes associated with the given attribute ID to the table. If the ID already exists in the table, that set of attributes is replaced with this one. If the number of attributes to be added is not equal to the number of attributes (excluding ID), an error message is displayed and the attributes are not added.

Parameters:
id - ID associated with the attributes.
attributes - Array of attributes. Should be equal in size to the number of columns-1 defined when creating the attribute table.

addRow

public void addRow()
Adds a blank row to the attribute table. Will add a new unique ID using the largest existing ID +1.


addColumn

public void addColumn()
Adds a column with default name to the table.


addColumn

public void addColumn(String columnName)
Adds a column with the given name to the table.

Parameters:
columnName - Name of column to add.

isNumeric

public boolean isNumeric()
Reports whether the current active column contains numeric values.

Returns:
True if active column contains only numeric values.

isNumeric

public boolean isNumeric(int col)
Reports whether the given column contains numeric values.

Parameters:
col - Column to query.
Returns:
True if the given column contains only numeric values.

setColumnName

public void setColumnName(int col,
                          String name)
Sets the name of the given column.

Parameters:
col - Number of the column to change (first is column 0).
name - New name for the given column.

getColumnName

public String getColumnName(int col)
Reports the given column heading.

Parameters:
col - Column number to query.
Returns:
Column heading.

getRowCount

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

Returns:
Number of rows.

getColumnCount

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

Returns:
Number of columns.

getValueAt

public Object getValueAt(int row,
                         int col)
Reports the value stored in the table at the given coordinates.

Parameters:
row - Row coordinate to query.
col - Column coordinate to query.
Returns:
Object stored at the given coordinates.

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Reports whether the cell represented by the given coordinates is editable. Currently all cells are editable.

Parameters:
row - Row coordinate to query.
col - Column coordinate to query.
Returns:
True if cell is editable.

getColumnClass

public Class getColumnClass(int column)
Reports the type of object stored in the given column.

Parameters:
column - Column to query.
Returns:
Type of object stored in the given column.

setValueAt

public void setValueAt(Object value,
                       int row,
                       int col)
Sets the value stored in the table at the given coordinates.

Parameters:
value - Value to store in table.
row - Row coordinate of cell to set.
col - Column coordinate of cell to set.


Copyright Jo Wood, 1996-2009, last modified, 17th April, 2009