KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > RangeImpl


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.biff;
21
22 import common.Logger;
23
24 import jxl.Range;
25 import jxl.Cell;
26 import jxl.Sheet;
27 import jxl.biff.formula.ExternalSheet;
28
29 /**
30  * Implementation class for the Range interface. This merely
31  * holds the raw range information, and when the time comes, it
32  * interrogates the workbook for the object.
33  * This does not keep handles to the objects for performance reasons,
34  * as this could impact garbage collection on larger spreadsheets
35  */

36 public class RangeImpl implements Range
37 {
38   /**
39    * The logger
40    */

41   private static Logger logger = Logger.getLogger(RangeImpl.class);
42
43   /**
44    * A handle to the workbook
45    */

46   private WorkbookMethods workbook;
47
48   /**
49    * The sheet index containing the column at the top left
50    */

51   private int sheet1;
52
53   /**
54    * The column number of the cell at the top left of the range
55    */

56   private int column1;
57
58   /**
59    * The row number of the cell at the top left of the range
60    */

61   private int row1;
62
63   /**
64    * The sheet index of the cell at the bottom right
65    */

66   private int sheet2;
67
68   /**
69    * The column index of the cell at the bottom right
70    */

71   private int column2;
72
73   /**
74    * The row index of the cell at the bottom right
75    */

76   private int row2;
77
78   /**
79    * Constructor
80    * @param w the workbook
81    * @param es the external sheet
82    * @param s1 the sheet of the top left cell of the range
83    * @param c1 the column number of the top left cell of the range
84    * @param r1 the row number of the top left cell of the range
85    * @param s2 the sheet of the bottom right cell
86    * @param c2 the column number of the bottom right cell of the range
87    * @param r2 the row number of the bottomr right cell of the range
88    */

89   public RangeImpl(WorkbookMethods w,
90                    int s1, int c1, int r1,
91                    int s2, int c2, int r2)
92   {
93     workbook = w;
94     sheet1 = s1;
95     sheet2 = s2;
96     row1 = r1;
97     row2 = r2;
98     column1 = c1;
99     column2 = c2;
100   }
101
102   /**
103    * Gets the cell at the top left of this range
104    *
105    * @return the cell at the top left
106    */

107   public Cell getTopLeft()
108   {
109     Sheet s = workbook.getReadSheet(sheet1);
110
111     if (column1 < s.getColumns() &&
112         row1 < s.getRows())
113     {
114       return s.getCell(column1, row1);
115     }
116     else
117     {
118       return new EmptyCell(column1, row1);
119     }
120   }
121
122   /**
123    * Gets the cell at the bottom right of this range
124    *
125    * @return the cell at the bottom right
126    */

127   public Cell getBottomRight()
128   {
129     Sheet s = workbook.getReadSheet(sheet2);
130
131     if (column2 < s.getColumns() &&
132         row2 < s.getRows())
133     {
134       return s.getCell(column2, row2);
135     }
136     else
137     {
138       return new EmptyCell(column2, row2);
139     }
140   }
141
142   /**
143    * Gets the index of the first sheet in the range
144    *
145    * @return the index of the first sheet in the range
146    */

147   public int getFirstSheetIndex()
148   {
149     return sheet1;
150   }
151
152   /**
153    * Gets the index of the last sheet in the range
154    *
155    * @return the index of the last sheet in the range
156    */

157   public int getLastSheetIndex()
158   {
159     return sheet2;
160   }
161 }
162
163
164
165
166
167
168
169
170
171
Popular Tags