001    /*
002     * Copyright (c) 2005 Einar Pehrson
003     *
004     * This file is part of
005     * CleanSheets Extension for Style
006     *
007     * CleanSheets Extension for Style is free software; you can
008     * redistribute it and/or modify it under the terms of the GNU General Public
009     * License as published by the Free Software Foundation; either version 2 of
010     * the License, or (at your option) any later version.
011     *
012     * CleanSheets Extension for Style is distributed in the hope that
013     * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
014     * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
015     * See the 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 Extension for Style; if not, write to the
019     * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020     * Boston, MA  02111-1307  USA
021     */
022    package csheets.ext.style;
023    
024    import java.util.HashMap;
025    import java.util.Map;
026    
027    import csheets.core.Address;
028    import csheets.core.Spreadsheet;
029    import csheets.ext.SpreadsheetExtension;
030    
031    /**
032     * An extension of a spreadsheet, with support for style, i.e. row and column
033     * dimensions and cell spanning.
034     * @author Einar Pehrson
035     */
036    public class StylableSpreadsheet extends SpreadsheetExtension {
037    
038            /** The unique version identifier used for serialization */
039            private static final long serialVersionUID = -302349897603798290L;
040    
041            /** The width of the columns in the spreadsheet */
042            private Map<Integer, Integer> columnWidths = new HashMap<Integer, Integer>();
043    
044            /** The heights of the rows in the spreadsheet */
045            private Map<Integer, Integer> rowHeights = new HashMap<Integer, Integer>();
046    
047            /** The spans of cells in the spreadsheet */
048            @SuppressWarnings("unused")
049            private Map<Address, Address> cellSpans = new HashMap<Address, Address>();
050    
051            /*
052             * Possible additions:
053             * - Cell spanning
054             * - Grid visiblity (horizontal and vertical)
055             * - Grid color
056             * - Cell margin
057             */
058    
059            /**
060             * Creates a stylable cell spreadsheet for the given spreadsheet.
061             * @param spreadsheet the spreadsheet to extend
062             */
063            protected StylableSpreadsheet(Spreadsheet spreadsheet) {
064                    super(spreadsheet, StyleExtension.NAME);
065            }
066    
067            /**
068             * Returns the height of the given row.
069             * @param row the index of the row
070             * @return the height of the given row, or -1 if the default height applies
071             */
072            public int getRowHeight(int row) {
073                    Integer height = rowHeights.get(row);
074                    if (height != null)
075                            return height;
076                    else
077                            return -1;
078            }
079    
080            /**
081             * Sets the height of the given row.
082             * @param row the index of the row
083             * @param height the height of the row
084             */
085            public void setRowHeight(int row, int height) {
086                    rowHeights.put(row, height);
087            }
088    
089            /**
090             * Returns the width of the given column.
091             * @param column the index of the column
092             * @return the width of the given column, or -1 if the default width applies
093             */
094            public int getColumnWidth(int column) {
095                    Integer width = columnWidths.get(column);
096                    if (width != null)
097                            return width;
098                    else
099                            return -1;
100            }
101    
102            /**
103             * Sets the width of the given column.
104             * @param column the index of the column
105             * @param width the width of the column
106             */
107            public void setColumnWidth(int column, int width) {
108                    columnWidths.put(column, width);
109            }
110    }