001: /*
002: * Copyright (c) 2005 Einar Pehrson <einar@pehrson.nu>.
003: *
004: * This file is part of
005: * CleanSheets - a spreadsheet application for the Java platform.
006: *
007: * CleanSheets is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * CleanSheets is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with CleanSheets; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package csheets.core;
022:
023: import java.io.Serializable;
024: import java.util.SortedSet;
025:
026: import csheets.core.formula.Formula;
027: import csheets.core.formula.compiler.FormulaCompilationException;
028: import csheets.ext.Extensible;
029:
030: /**
031: * A cell in a spreadsheet.
032: * <p>The cell has content, which can be interpreted in
033: * different ways: <ul>
034: * <li>As a formula - The content should consitute a syntactically correct
035: * expression, and begin with an assignment.
036: * <li>As a value - If the cell contains a formula, the formula is evaluated to
037: * produce a value, provided that the cell does not contain calculation errors
038: * (e.g. division by 0). Otherwise, the content is interpreted as the value.
039: * </ul>
040: * @author Einar Pehrson
041: */
042: public interface Cell extends Comparable<Cell>, Extensible<Cell>,
043: Serializable {
044:
045: /*
046: * LOCATION
047: */
048:
049: /**
050: * Returns the spreadsheet to which the cell belongs.
051: * @return the spreadsheet to which the cell belongs
052: */
053: public Spreadsheet getSpreadsheet();
054:
055: /**
056: * Returns the address of the cell.
057: * @return the address of the cell
058: */
059: public Address getAddress();
060:
061: /*
062: * VALUE
063: */
064:
065: /**
066: * Returns the value of the cell.
067: * @return the value of the cell
068: */
069: public Value getValue();
070:
071: /*
072: * CONTENT
073: */
074:
075: /**
076: * Returns the content of the cell, as entered by the user.
077: * @return the content of the cell
078: */
079: public String getContent();
080:
081: /**
082: * Returns an expression representing the cell's formula.
083: * @return the cell's formula, or null if the cell does not contain one
084: */
085: public Formula getFormula();
086:
087: /**
088: * Sets the content of the cell and if it starts with the assignment operator
089: * attempts to parse a formula from it.
090: * @throws FormulaCompilationException if an incorrectly formatted formula was entered
091: */
092: public void setContent(String content)
093: throws FormulaCompilationException;
094:
095: /**
096: * Clears the content of the cell.
097: */
098: public void clear();
099:
100: /*
101: * DEPENDENCIES
102: */
103:
104: /**
105: * Returns the precedents of the cell, i.e. the cells that the
106: * formula in the cell references.
107: * @return a set of the cell's precedents
108: */
109: public SortedSet<Cell> getPrecedents();
110:
111: /**
112: * Returns the dependents of the cell, i.e. the cells that contain a reference
113: * to the cell in their formula.
114: * @return a set of the cells which depend on the cell
115: */
116: public SortedSet<Cell> getDependents();
117:
118: /*
119: * CLIPBOARD
120: */
121:
122: /**
123: * Copies all data from the source cell to this one.
124: * @param source the cell from which data should be copied
125: */
126: public void copyFrom(Cell source);
127:
128: /**
129: * Moves all data from the source cell to this one.
130: * @param source the cell from which data should be moved
131: */
132: public void moveFrom(Cell source);
133:
134: /*
135: * EVENT HANDLING
136: */
137:
138: /**
139: * Registers the given listener on the cell.
140: * @param listener the listener to be added
141: */
142: public void addCellListener(CellListener listener);
143:
144: /**
145: * Removes the given listener from the cell.
146: * @param listener the listener to be removed
147: */
148: public void removeCellListener(CellListener listener);
149:
150: /**
151: * Returns the listeners that have been registered on the cell.
152: * @return the listeners that have been registered on the cell
153: */
154: public CellListener[] getCellListeners();
155: }
|