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.ext;
022
023 import java.util.Iterator;
024 import java.util.SortedSet;
025
026 import csheets.core.Address;
027 import csheets.core.Cell;
028 import csheets.core.CellListener;
029 import csheets.core.Spreadsheet;
030 import csheets.core.Workbook;
031
032 /**
033 * A base class for extensions of spreadsheets that uses delegation
034 * to provide cell data.
035 * @author Einar Pehrson
036 */
037 public abstract class SpreadsheetExtension implements Spreadsheet {
038
039 /** The delegate of the extension */
040 private Spreadsheet delegate;
041
042 /** The name of the extension to which the spreadsheet extension belongs */
043 private String name;
044
045 /**
046 * Creates a new spreadsheet extension.
047 * @param delegate the delegate of the extension
048 * @param name the name of the extension to which the spreadsheet extension belongs
049 */
050 public SpreadsheetExtension(Spreadsheet delegate, String name) {
051 this.delegate = delegate;
052 this.name = name;
053 }
054
055 /**
056 * Returns the name of the extension to which the spreadsheet extension belongs.
057 * @return the name of the extension to which the spreadsheet extension belongs
058 */
059 public final String getName() {
060 return name;
061 }
062
063 public final String getTitle() {
064 return delegate.getTitle();
065 }
066
067 public final void setTitle(String title) {
068 delegate.setTitle(title);
069 }
070
071 public final Workbook getWorkbook() {
072 return delegate.getWorkbook();
073 }
074
075 public final int getColumnCount() {
076 return delegate.getColumnCount();
077 }
078
079 public final int getRowCount() {
080 return delegate.getRowCount();
081 }
082
083 public final Cell getCell(Address address) {
084 Cell cell = delegate.getCell(address);
085 Cell extension = cell.getExtension(name);
086 if (extension != null)
087 return extension;
088 else
089 return cell;
090 }
091
092 public final Cell getCell(int column, int row) {
093 return getCell(new Address(column, row));
094 }
095
096 public final SortedSet<Cell> getCells(Address address1, Address address2) {
097 return delegate.getCells(address1, address2);
098 }
099
100 public final Cell[] getColumn(int index) {
101 return delegate.getColumn(index);
102 }
103
104 public final Cell[] getRow(int index) {
105 return delegate.getRow(index);
106 }
107
108 public final Iterator<Cell> iterator() {
109 return delegate.iterator();
110 }
111
112 public void addCellListener(CellListener listener) {
113 delegate.addCellListener(listener);
114 }
115
116 public void removeCellListener(CellListener listener) {
117 delegate.removeCellListener(listener);
118 }
119
120 public CellListener[] getCellListeners() {
121 return delegate.getCellListeners();
122 }
123
124 public final Spreadsheet getExtension(String name) {
125 return delegate.getExtension(name);
126 }
127 }