KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > sample > decorators > HssfTotalWrapper


1 /**
2  * Licensed under the Artistic License; you may not use this file
3  * except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://displaytag.sourceforge.net/license.html
7  *
8  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */

12
13 package org.displaytag.sample.decorators;
14
15 import org.apache.poi.hssf.usermodel.HSSFCell;
16 import org.apache.poi.hssf.usermodel.HSSFRow;
17 import org.apache.poi.hssf.usermodel.HSSFSheet;
18 import org.displaytag.decorator.hssf.DecoratesHssf;
19
20
21 /**
22  * Same idea implemented in HssfTableWriter applied to decorators.
23  * @see org.displaytag.render.HssfTableWriter
24  * @author Jorge L. Barroso
25  * @version $Revision$ ($Author$)
26  */

27 public class HssfTotalWrapper extends TotalWrapperTemplate implements DecoratesHssf
28 {
29
30     private HSSFSheet sheet;
31
32     private HSSFCell currentCell;
33
34     private HSSFRow currentRow;
35
36     private int colNum;
37
38     protected void writeCityTotal(String JavaDoc city, double total)
39     {
40         this.writeTotal(city, total);
41     }
42
43     private void writeTotal(String JavaDoc value, double total)
44     {
45         if (this.assertRequiredState())
46         {
47             int rowNum = this.sheet.getLastRowNum();
48             this.currentRow = this.sheet.createRow(++rowNum);
49             this.colNum = 0;
50             prepareCell();
51             prepareCell();
52             prepareCell();
53             this.currentCell.setCellValue("------------");
54
55             this.currentRow = this.sheet.createRow(++rowNum);
56             this.colNum = 0;
57             prepareCell();
58             prepareCell();
59             this.currentCell.setCellValue(value + " Total:");
60             prepareCell();
61             this.currentCell.setCellValue(total);
62         }
63     }
64
65     private void prepareCell()
66     {
67         this.currentCell = this.currentRow.createCell((short) this.colNum++);
68         this.currentCell.setEncoding(HSSFCell.ENCODING_UTF_16);
69     }
70
71     protected void writeGrandTotal(double total)
72     {
73         this.writeTotal("Grand", total);
74     }
75
76     public void setSheet(HSSFSheet sheet)
77     {
78         this.sheet = sheet;
79     }
80
81     /**
82      * Asserts that the sheet property needed have been set by the client.
83      * @return true if the required properties are not null; false otherwise.
84      */

85     private boolean assertRequiredState()
86     {
87         return this.sheet != null;
88     }
89 }
90
Popular Tags