net.sf.jga.swing.spreadsheet
Class Cell

java.lang.Object
  extended by java.util.Observable
      extended by net.sf.jga.swing.spreadsheet.Cell
All Implemented Interfaces:
java.util.Observer

public class Cell
extends java.util.Observable
implements java.util.Observer

A single cell in spreadsheet. Encapsulates information about the generator that provides the value of the cell, the cell's formatting information, and the editor and/or renderer used to display/update the cell's contents.

Copyright © 2004-2005 David A. Hall

Author:
David A. Hall

Field Summary
static java.lang.String CIRCULAR_REF_ERR
           
static java.lang.String CLASS_CAST_ERR
           
static java.lang.String EVALUATION_ERR
           
static java.lang.String NULL_POINTER_ERR
           
static java.lang.String PARSER_ERR
           
static java.lang.String REFERENCE_ERR
           
static java.lang.String UNDEFINED_ERR
           
 
Method Summary
 void clear()
          Clears the contents of the cell, setting to the default type and value.
 java.util.Iterator<Cell> dependsOn()
          returns an iterator over all cells on which this cell directly depends
 java.awt.Point getAddress()
          Returns the address of the cell.
 javax.swing.table.TableCellEditor getEditor()
          Returns the component used to edit the cell
 java.lang.String getErrorMsg()
          Returns the textual description of the last error associated with cell.
 java.lang.String getName()
           
 Generator<?> getReference()
          Returns a reference to the cell's formula.
 javax.swing.table.TableCellRenderer getRenderer()
          Returns the renderer used to paint the cell
 java.lang.Class<?> getType()
          Returns the type of values held by the cell.
 java.lang.Object getValue()
          Returns the value of the cell.
 boolean isEditable()
          Returns true if the cell is editable, false if it is read-only.
 boolean isUndefined()
          Returns true if the cell's value is undefined
 boolean isValid()
          Returns true if the cell's value can be retrieved without error
 void notifyObservers()
          Triggers cells (and other observers) that this cell's contents have been changed.
 boolean references(Cell c)
          Returns true if this cell references the given cell, either directly or indirectly.
 void setEditable(boolean b)
          Sets the cell as editable (or not).
 void setEditor(javax.swing.table.TableCellEditor editor)
          Sets the component used to edit the cell
<T> void
setFormat(UnaryFunctor<T,java.lang.String> formatter)
          Sets the format of the cell, if formatting is supported by the cell's renderer.
 void setFormula(Generator<?> formula)
          Sets the contents of the cell to the given formula, notifying all observers of the change.
 void setFormula(java.lang.String formula)
          Sets the contents of the cell to the given formula.
 void setRenderer(javax.swing.table.TableCellRenderer renderer)
          Sets the component used to paint the cell
<V> void
setValue(V value)
          Sets the contents of the cell to the given value.
 java.lang.String toString()
           
 void update(java.util.Observable observable, java.lang.Object object)
           
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_CAST_ERR

public static final java.lang.String CLASS_CAST_ERR
See Also:
Constant Field Values

EVALUATION_ERR

public static final java.lang.String EVALUATION_ERR
See Also:
Constant Field Values

CIRCULAR_REF_ERR

public static final java.lang.String CIRCULAR_REF_ERR
See Also:
Constant Field Values

NULL_POINTER_ERR

public static final java.lang.String NULL_POINTER_ERR
See Also:
Constant Field Values

REFERENCE_ERR

public static final java.lang.String REFERENCE_ERR
See Also:
Constant Field Values

UNDEFINED_ERR

public static final java.lang.String UNDEFINED_ERR
See Also:
Constant Field Values

PARSER_ERR

public static final java.lang.String PARSER_ERR
See Also:
Constant Field Values
Method Detail

getName

public java.lang.String getName()

getType

public java.lang.Class<?> getType()
Returns the type of values held by the cell.


isEditable

public boolean isEditable()
Returns true if the cell is editable, false if it is read-only.


setEditable

public void setEditable(boolean b)
Sets the cell as editable (or not).


getAddress

public java.awt.Point getAddress()
Returns the address of the cell.


getRenderer

public javax.swing.table.TableCellRenderer getRenderer()
Returns the renderer used to paint the cell


setRenderer

public void setRenderer(javax.swing.table.TableCellRenderer renderer)
Sets the component used to paint the cell


getEditor

public javax.swing.table.TableCellEditor getEditor()
Returns the component used to edit the cell


setEditor

public void setEditor(javax.swing.table.TableCellEditor editor)
Sets the component used to edit the cell


isValid

public boolean isValid()
Returns true if the cell's value can be retrieved without error


isUndefined

public boolean isUndefined()
Returns true if the cell's value is undefined


getErrorMsg

public java.lang.String getErrorMsg()
Returns the textual description of the last error associated with cell. The string will be used by the UI. If the cell's value can be retrieved without error, then this field will be null.


getValue

public java.lang.Object getValue()
Returns the value of the cell. If an exception is caught while evaluating the cell, then this will return null and the getErrorMsg() method will return a description of the problem.


clear

public void clear()
Clears the contents of the cell, setting to the default type and value.


setValue

public final <V> void setValue(V value)
Sets the contents of the cell to the given value.


setFormula

public final void setFormula(java.lang.String formula)
                      throws net.sf.jga.swing.spreadsheet.CircularReferenceException
Sets the contents of the cell to the given formula.

Throws:
net.sf.jga.swing.spreadsheet.CircularReferenceException

setFormula

public final void setFormula(Generator<?> formula)
Sets the contents of the cell to the given formula, notifying all observers of the change.


setFormat

public <T> void setFormat(UnaryFunctor<T,java.lang.String> formatter)
Sets the format of the cell, if formatting is supported by the cell's renderer. If formatting is not supported, invoking this method will have no effect.

Throws:
java.lang.ClassCastException - if the generic type of the formatter is not compatable with the generic type of the cell's renderer

getReference

public Generator<?> getReference()
Returns a reference to the cell's formula.


references

public boolean references(Cell c)
Returns true if this cell references the given cell, either directly or indirectly. Also returns true if this cell is the given cell.


dependsOn

public final java.util.Iterator<Cell> dependsOn()
returns an iterator over all cells on which this cell directly depends


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

update

public void update(java.util.Observable observable,
                   java.lang.Object object)
Specified by:
update in interface java.util.Observer

notifyObservers

public void notifyObservers()
Triggers cells (and other observers) that this cell's contents have been changed.

Overrides:
notifyObservers in class java.util.Observable


Copyright © 2002-2006 David A. Hall. All Rights Reserved.