csheets.core
Class CellImpl

java.lang.Object
  extended by csheets.core.CellImpl
All Implemented Interfaces:
Cell, Extensible<Cell>, Serializable, Comparable<Cell>

public class CellImpl
extends Object
implements Cell

The implementation of the Cell interface.

Author:
Einar Pehrson
See Also:
Serialized Form

Constructor Summary
CellImpl(Spreadsheet spreadsheet, Address address)
          Creates a new cell at the given address in the given spreadsheet.
CellImpl(Spreadsheet spreadsheet, Address address, String content)
          Creates a new cell at the given address in the given spreadsheet, initialized with the given content (not intended to be used directly).
 
Method Summary
 void addCellListener(CellListener listener)
          Registers the given listener on the cell.
 void clear()
          Clears the content of the cell.
 int compareTo(Cell cell)
          Compares this cell with the specified cell for order, by comparing their addresses.
 void copyFrom(Cell source)
          Copies all data from the source cell to this one.
 Address getAddress()
          Returns the address of the cell.
 CellListener[] getCellListeners()
          Returns the listeners that have been registered on the cell.
 String getContent()
          Returns the content of the cell, as entered by the user.
 SortedSet<Cell> getDependents()
          Returns the dependents of the cell, i.e. the cells that contain a reference to the cell in their formula.
 Cell getExtension(String name)
          Returns the extension with the given key.
 Formula getFormula()
          Returns an expression representing the cell's formula.
 SortedSet<Cell> getPrecedents()
          Returns the precedents of the cell, i.e. the cells that the formula in the cell references.
 Spreadsheet getSpreadsheet()
          Returns the spreadsheet to which the cell belongs.
 Value getValue()
          Returns the value of the cell.
 void moveFrom(Cell source)
          Moves all data from the source cell to this one.
 void removeCellListener(CellListener listener)
          Removes the given listener from the cell.
 void setContent(String content)
          Sets the content of the cell and if it starts with the assignment operator attempts to parse a formula from it.
 String toString()
          Returns a string representation of the cell.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CellImpl

CellImpl(Spreadsheet spreadsheet,
         Address address)
Creates a new cell at the given address in the given spreadsheet. (not intended to be used directly).

Parameters:
spreadsheet - the spreadsheet
address - the address of the cell
See Also:
Spreadsheet.getCell(Address)

CellImpl

CellImpl(Spreadsheet spreadsheet,
         Address address,
         String content)
   throws FormulaCompilationException
Creates a new cell at the given address in the given spreadsheet, initialized with the given content (not intended to be used directly).

Parameters:
spreadsheet - the spreadsheet
address - the address of the cell
content - the content of the cell
Throws:
ExpressionSyntaxException - if an incorrectly formatted formula was entered
FormulaCompilationException
See Also:
Spreadsheet.getCell(Address)
Method Detail

getSpreadsheet

public Spreadsheet getSpreadsheet()
Description copied from interface: Cell
Returns the spreadsheet to which the cell belongs.

Specified by:
getSpreadsheet in interface Cell
Returns:
the spreadsheet to which the cell belongs

getAddress

public Address getAddress()
Description copied from interface: Cell
Returns the address of the cell.

Specified by:
getAddress in interface Cell
Returns:
the address of the cell

getValue

public Value getValue()
Description copied from interface: Cell
Returns the value of the cell.

Specified by:
getValue in interface Cell
Returns:
the value of the cell

getContent

public String getContent()
Description copied from interface: Cell
Returns the content of the cell, as entered by the user.

Specified by:
getContent in interface Cell
Returns:
the content of the cell

getFormula

public Formula getFormula()
Description copied from interface: Cell
Returns an expression representing the cell's formula.

Specified by:
getFormula in interface Cell
Returns:
the cell's formula, or null if the cell does not contain one

clear

public void clear()
Description copied from interface: Cell
Clears the content of the cell.

Specified by:
clear in interface Cell

setContent

public void setContent(String content)
                throws FormulaCompilationException
Description copied from interface: Cell
Sets the content of the cell and if it starts with the assignment operator attempts to parse a formula from it.

Specified by:
setContent in interface Cell
Throws:
FormulaCompilationException - if an incorrectly formatted formula was entered

getPrecedents

public SortedSet<Cell> getPrecedents()
Description copied from interface: Cell
Returns the precedents of the cell, i.e. the cells that the formula in the cell references.

Specified by:
getPrecedents in interface Cell
Returns:
a set of the cell's precedents

getDependents

public SortedSet<Cell> getDependents()
Description copied from interface: Cell
Returns the dependents of the cell, i.e. the cells that contain a reference to the cell in their formula.

Specified by:
getDependents in interface Cell
Returns:
a set of the cells which depend on the cell

copyFrom

public void copyFrom(Cell source)
Description copied from interface: Cell
Copies all data from the source cell to this one.

Specified by:
copyFrom in interface Cell
Parameters:
source - the cell from which data should be copied

moveFrom

public void moveFrom(Cell source)
Description copied from interface: Cell
Moves all data from the source cell to this one.

Specified by:
moveFrom in interface Cell
Parameters:
source - the cell from which data should be moved

addCellListener

public void addCellListener(CellListener listener)
Description copied from interface: Cell
Registers the given listener on the cell.

Specified by:
addCellListener in interface Cell
Parameters:
listener - the listener to be added

removeCellListener

public void removeCellListener(CellListener listener)
Description copied from interface: Cell
Removes the given listener from the cell.

Specified by:
removeCellListener in interface Cell
Parameters:
listener - the listener to be removed

getCellListeners

public CellListener[] getCellListeners()
Description copied from interface: Cell
Returns the listeners that have been registered on the cell.

Specified by:
getCellListeners in interface Cell
Returns:
the listeners that have been registered on the cell

getExtension

public Cell getExtension(String name)
Description copied from interface: Extensible
Returns the extension with the given key.

Specified by:
getExtension in interface Extensible<Cell>
Parameters:
name - the name of the extension (case-insensitive)
Returns:
the appropriate extension, or null if no extension with the given name was found

compareTo

public int compareTo(Cell cell)
Compares this cell with the specified cell for order, by comparing their addresses.

Specified by:
compareTo in interface Comparable<Cell>
Parameters:
cell - the cell to be compared
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

toString

public String toString()
Returns a string representation of the cell.

Overrides:
toString in class Object
Returns:
the cell's content