1    /* ====================================================================
2    
3     * The Apache Software License, Version 1.1
4    
5     *
6    
7     * Copyright (c) 2002 The Apache Software Foundation.  All rights
8    
9     * reserved.
10   
11    *
12   
13    * Redistribution and use in source and binary forms, with or without
14   
15    * modification, are permitted provided that the following conditions
16   
17    * are met:
18   
19    *
20   
21    * 1. Redistributions of source code must retain the above copyright
22   
23    *    notice, this list of conditions and the following disclaimer.
24   
25    *
26   
27    * 2. Redistributions in binary form must reproduce the above copyright
28   
29    *    notice, this list of conditions and the following disclaimer in
30   
31    *    the documentation and/or other materials provided with the
32   
33    *    distribution.
34   
35    *
36   
37    * 3. The end-user documentation included with the redistribution,
38   
39    *    if any, must include the following acknowledgment:
40   
41    *       "This product includes software developed by the
42   
43    *        Apache Software Foundation (http://www.apache.org/)."
44   
45    *    Alternately, this acknowledgment may appear in the software itself,
46   
47    *    if and wherever such third-party acknowledgments normally appear.
48   
49    *
50   
51    * 4. The names "Apache" and "Apache Software Foundation" and
52   
53    *    "Apache POI" must not be used to endorse or promote products
54   
55    *    derived from this software without prior written permission. For
56   
57    *    written permission, please contact apache@apache.org.
58   
59    *
60   
61    * 5. Products derived from this software may not be called "Apache",
62   
63    *    "Apache POI", nor may "Apache" appear in their name, without
64   
65    *    prior written permission of the Apache Software Foundation.
66   
67    *
68   
69    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
70   
71    * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
72   
73    * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
74   
75    * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
76   
77    * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
78   
79    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
80   
81    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
82   
83    * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
84   
85    * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
86   
87    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
88   
89    * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
90   
91    * SUCH DAMAGE.
92   
93    * ====================================================================
94   
95    *
96   
97    * This software consists of voluntary contributions made by many
98   
99    * individuals on behalf of the Apache Software Foundation.  For more
100  
101   * information on the Apache Software Foundation, please see
102  
103   * <http://www.apache.org/>.
104  
105   */
106  
107  
108  
109  package org.apache.poi.hssf.usermodel;
110  
111  
112  
113  import org.apache.poi.hssf.record.HeaderRecord;
114  
115  
116  
117  /**
118  
119   * Class to read and manipulate the header.
120  
121   * <P>
122  
123   * The header works by having a left, center, and right side.  The total cannot
124  
125   * be more that 255 bytes long.  One uses this class by getting the HSSFHeader
126  
127   * from HSSFSheet and then getting or setting the left, center, and right side.
128  
129   * For special things (such as page numbers and date), one can use a the methods
130  
131   * that return the characters used to represent these.  One can also change the
132  
133   * fonts by using similar methods.
134  
135   * <P>
136  
137   * @author Shawn Laubach (laubach@acm.org)
138  
139   */
140  
141  public class HSSFHeader extends Object {
142  
143  
144  
145    HeaderRecord headerRecord;
146  
147    String left;
148  
149    String center;
150  
151    String right;
152  
153  
154  
155    /**
156  
157     * Constructor.  Creates a new header interface from a header record
158  
159     * @param headerRecord Header record to create the header with
160  
161     */
162  
163    protected HSSFHeader(HeaderRecord headerRecord) {
164  
165      this.headerRecord = headerRecord;
166  
167      String head = headerRecord.getHeader();
168  
169    }
170  
171  
172  
173    /**
174  
175     * Get the left side of the header.
176  
177     * @return The string representing the left side.
178  
179     */
180  
181    public String getLeft() {
182  
183      return left;
184  
185    }
186  
187  
188  
189    /**
190  
191     * Sets the left string.
192  
193     * @newLeft The string to set as the left side.
194  
195     */
196  
197    public void setLeft(String newLeft) {
198  
199      left = newLeft;
200  
201      createHeaderString();
202  
203    }
204  
205  
206  
207    /**
208  
209     * Get the center of the header.
210  
211     * @return The string representing the center.
212  
213     */
214  
215    public String getCenter() {
216  
217      return center;
218  
219    }
220  
221  
222  
223    /**
224  
225     * Sets the center string.
226  
227     * @newLeft The string to set as the center.
228  
229     */
230  
231    public void setCenter(String newCenter) {
232  
233      center = newCenter;
234  
235      createHeaderString();
236  
237    }
238  
239  
240  
241    /**
242  
243     * Get the right side of the header.
244  
245     * @return The string representing the right side.
246  
247     */
248  
249    public String getRight() {
250  
251      return right;
252  
253    }
254  
255  
256  
257    /**
258  
259     * Sets the right string.
260  
261     * @newLeft The string to set as the right side.
262  
263     */
264  
265    public void setRight(String newRight) {
266  
267      right = newRight;
268  
269      createHeaderString();
270  
271    }
272  
273  
274  
275    /**
276  
277     * Creates the complete header string based on the left, center, and middle
278  
279     * strings.
280  
281     */
282  
283    private void createHeaderString() {
284  
285      headerRecord.setHeader(
286  
287      "&C" + (center == null ? "" : center) +
288  
289      "&L" + (left == null ? "" : left) +
290  
291      "&R" + (right == null ? "" : right));
292  
293      headerRecord.setHeaderLength((byte)headerRecord.getHeader().length());
294  
295    }
296  
297  
298  
299    /**
300  
301     * Returns the string that represents the change in font size.
302  
303     * @param size the new font size
304  
305     * @return The special string to represent a new font size
306  
307     */
308  
309    public static String fontSize(short size) {
310  
311      return "&" + size;
312  
313    }
314  
315  
316  
317    /**
318  
319     * Returns the string that represents the change in font.
320  
321     * @param font the new font
322  
323     * @param style the fonts style
324  
325     * @return The special string to represent a new font size
326  
327     */
328  
329    public static String font(String font, String style) {
330  
331      return "&\"" + font + "," + style + "\"";
332  
333    }
334  
335  
336  
337    /**
338  
339     * Returns the string representing the current page number
340  
341     * @return The special string for page number
342  
343     */
344  
345    public static String page() {
346  
347      return "&P";
348  
349    }
350  
351  
352  
353    /**
354  
355     * Returns the string representing the number of pages.
356  
357     * @return The special string for the number of pages
358  
359     */
360  
361    public static String numPages() {
362  
363      return "&N";
364  
365    }
366  
367  
368  
369    /**
370  
371     * Returns the string representing the current date
372  
373     * @return The special string for the date
374  
375     */
376  
377    public static String date() {
378  
379      return "&D";
380  
381    }
382  
383  
384  
385    /**
386  
387     * Returns the string representing the current time
388  
389     * @return The special string for the time
390  
391     */
392  
393    public static String time() {
394  
395      return "&T";
396  
397    }
398  
399  
400  
401    /**
402  
403     * Returns the string representing the current file name
404  
405     * @return The special string for the file name
406  
407     */
408  
409    public static String file() {
410  
411      return "&F";
412  
413    }
414  
415  
416  
417    /**
418  
419     * Returns the string representing the current tab (sheet) name
420  
421     * @return The special string for tab name
422  
423     */
424  
425    public static String tab() {
426  
427      return "&A";
428  
429    }
430  
431  }
432  
433  
434  
435  ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????HSSFHeader?????????????????????????????????Object???HeaderRecord????????????????headerRecord??????????left??????????center??????????right????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????HSSFHeader????????????????????????HeaderRecord?????????????????????????headerRecord???????????????????headerRecord????????????????????????????????getHeader??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????getLeft????????????left???????????????????????????????????????????????????????????????????????????????????????????????????????????setLeft?????left????????????newLeft?????createHeaderString????????????????????????????????????????????????????????????????????????????????????????????????????????????????????getCenter????????????center??????????????????????????????????????????????????????????????????????????????????????????????????????????setCenter?????center??????????????newCenter?????createHeaderString????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????getRight????????????right?????????????????????????????????????????????????????????????????????????????????????????????????????????????setRight?????right?????????????newRight?????createHeaderString???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????createHeaderString?????headerRecord??????????????????setHeader?????????????center???????????????????????????????????center?????????????left?????????????????????????????????left?????????????right??????????????????????????????????right?????headerRecord??????????????????setHeaderLength????????????????????????????????????????headerRecord?????????????????????????????????????????????????????getHeader?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????fontSize??????????????????size??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????font????????????????????font?????????????????????????????????style????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????page?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????numPages??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????date??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????time????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????file??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????tab