KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > BaseCellFeatures


1 /*********************************************************************
2 *
3 * Copyright (C) 2004 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 import jxl.write.biff.CellValue;
24 import jxl.biff.drawing.Comment;
25
26 /**
27  * Container for any additional cell features
28  */

29 public class BaseCellFeatures
30 {
31   /**
32    * The logger
33    */

34   public static Logger logger = Logger.getLogger(BaseCellFeatures.class);
35
36   /**
37    * The comment
38    */

39   private String JavaDoc comment;
40
41   /**
42    * The comment width in cells
43    */

44   private double commentWidth;
45
46   /**
47    * The comment height in cells
48    */

49   private double commentHeight;
50   
51   /**
52    * A handle to the drawing object
53    */

54   private Comment commentDrawing;
55
56   /**
57    * The cell to which this is attached, and which may need to be notified
58    */

59   private CellValue writableCell;
60
61   // Constants
62
private final static double defaultCommentWidth = 3;
63   private final static double defaultCommentHeight = 4;
64
65   /**
66    * Constructor
67    */

68   protected BaseCellFeatures()
69   {
70   }
71
72   /**
73    * Copy constructor
74    *
75    * @param the cell to copy
76    */

77   public BaseCellFeatures(BaseCellFeatures cf)
78   {
79     comment = cf.comment;
80     commentWidth = cf.commentWidth;
81     commentHeight = cf.commentHeight;
82   }
83
84   /**
85    * Accessor for the cell comment
86    */

87   protected String JavaDoc getComment()
88   {
89     return comment;
90   }
91
92   /**
93    * Accessor for the comment width
94    */

95   public double getCommentWidth()
96   {
97     return commentWidth;
98   }
99
100   /**
101    * Accessor for the comment height
102    */

103   public double getCommentHeight()
104   {
105     return commentHeight;
106   }
107
108   /**
109    * Called by the cell when the features are added
110    *
111    * @param wc the writable cell
112    */

113   public final void setWritableCell(CellValue wc)
114   {
115     writableCell = wc;
116   }
117
118   /**
119    * Internal method to set the cell comment. Used when reading
120    */

121   public void setReadComment(String JavaDoc s, double w, double h)
122   {
123     comment = s;
124     commentWidth = w;
125     commentHeight = h;
126   }
127
128   /**
129    * Sets the cell comment
130    *
131    * @param s the comment
132    */

133   public void setComment(String JavaDoc s)
134   {
135     setComment(s, defaultCommentWidth, defaultCommentHeight);
136   }
137
138   /**
139    * Sets the cell comment
140    *
141    * @param s the comment
142    * @param height the height of the comment box in cells
143    * @param width the width of the comment box in cells
144    */

145   public void setComment(String JavaDoc s, double width, double height)
146   {
147     comment = s;
148     commentWidth = width;
149     commentHeight = height;
150
151     if (commentDrawing != null)
152     {
153       commentDrawing.setCommentText(s);
154       commentDrawing.setWidth(width);
155       commentDrawing.setWidth(height);
156       // commentDrawing is set up when trying to modify a copied cell
157
}
158   }
159
160   /**
161    * Sets the comment drawing object
162    */

163   public final void setCommentDrawing(Comment c)
164   {
165     commentDrawing = c;
166   }
167
168   /**
169    * Accessor for the comment drawing
170    */

171   public final Comment getCommentDrawing()
172   {
173     return commentDrawing;
174   }
175 }
176
Popular Tags