KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > elementprocessor > impl > poi > hssf > elements > EPStyleRegion


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements;
18
19 import java.util.Hashtable JavaDoc;
20
21 import org.apache.cocoon.components.elementprocessor.types.NumericConverter;
22 import org.apache.cocoon.components.elementprocessor.types.NumericResult;
23 import org.apache.cocoon.components.elementprocessor.ElementProcessor;
24 import org.apache.cocoon.components.elementprocessor.types.Attribute;
25
26 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
27 import org.apache.poi.hssf.util.Region;
28
29
30 import java.io.IOException JavaDoc;
31
32 /**
33  * No-op implementation of ElementProcessor to handle the
34  * "StyleRegion" tag
35  *
36  * This element is a container of other elements and has four
37  * attributes that define the boundaries of the region.
38  *
39  * @author Marc Johnson (marc_johnson27591@hotmail.com)
40  * @author Andrew C. Oliver (acoliver2@users.sourceforge.net)
41  * @version CVS $Id: EPStyleRegion.java 30932 2004-07-29 17:35:38Z vgritsenko $
42  */

43 public class EPStyleRegion extends BaseElementProcessor {
44     private static final String JavaDoc _start_col_attribute = "startCol";
45     private static final String JavaDoc _start_row_attribute = "startRow";
46     private static final String JavaDoc _end_col_attribute = "endCol";
47     private static final String JavaDoc _end_row_attribute = "endRow";
48     private NumericResult _start_col;
49     private NumericResult _start_row;
50     private NumericResult _end_col;
51     private NumericResult _end_row;
52
53     private HSSFCellStyle _style;
54     private Hashtable JavaDoc colorhash;
55
56     private boolean invalid;
57
58     //kludge constant to fix gnumeric's love of declaring large stlye regions
59
//for the blank sections of the sheet w/no apparent purpose that we can
60
//
61
private int MAX_AREA = 2001;
62
63     /**
64      * constructor
65      */

66     public EPStyleRegion() {
67         super(null);
68         _start_col = null;
69         _start_row = null;
70         _end_col = null;
71         _end_row = null;
72     }
73
74     /**
75      * Override of Initialize() implementation
76      * @param attributes the array of Attribute instances; may be empty, will
77      * never be null
78      * @param parent the parent ElementProcessor; may be null
79      * @exception IOException if anything is wrong
80      */

81     public void initialize(final Attribute[] attributes,
82                 final ElementProcessor parent) throws IOException JavaDoc {
83         super.initialize(attributes, parent);
84
85         Region region = new Region(getStartRow(), (short)getStartCol(),
86                 getEndRow(), (short)getEndCol());
87
88         // if (region.getRowFrom() == 0 &&
89
// region.getColumnFrom() ==0)
90
// getLogger().debug("got 0,0");
91

92         getLogger().debug("region area is " + region.getArea());
93         if (region.getArea() < MAX_AREA) {
94             //protect against stupid mega regions
95
//of generally NOTHING and no real
96
//puprose created by gnumeric
97
getLogger().debug("region added");
98             _style = getSheet().addStyleRegion(region); //test
99
} else {
100             invalid = true;
101         }
102         colorhash = ((EPStyles)parent).getColorHash();
103     }
104
105     /**
106      * @return start row
107      * @exception IOException
108      */

109     public int getStartRow() throws IOException JavaDoc {
110         if (_start_row == null) {
111             _start_row = NumericConverter.extractNonNegativeInteger(
112                     getValue(_start_row_attribute));
113         }
114         return _start_row.intValue();
115     }
116
117     /**
118      * @return start column
119      * @exception IOException
120      */

121     public int getStartCol() throws IOException JavaDoc {
122         if (_start_col == null) {
123             _start_col = NumericConverter.extractNonNegativeInteger(
124                     getValue(_start_col_attribute));
125         }
126         return _start_col.intValue();
127     }
128
129     /**
130      * @return end row
131      * @exception IOException
132      */

133     public int getEndRow() throws IOException JavaDoc {
134         if (_end_row == null) {
135             _end_row = NumericConverter.extractNonNegativeInteger(
136                     getValue(_end_row_attribute));
137         }
138         return _end_row.intValue();
139     }
140
141     /**
142      * @return end column
143      * @exception IOException
144      */

145     public int getEndCol() throws IOException JavaDoc {
146         if (_end_col == null) {
147             _end_col = NumericConverter.extractNonNegativeInteger(
148                     getValue(_end_col_attribute));
149         }
150         return _end_col.intValue();
151     }
152
153     /**
154      * @return HSSFCellStyle associated with this style region.
155      */

156     public HSSFCellStyle getStyle() {
157         return _style;
158     }
159
160     /**
161      * @return instance created in the EPStyles instance from
162      * HSSFColor.getTripletHash();
163      * @see org.apache.poi.hssf.util.HSSFColor#getTripletHash()
164      */

165     public Hashtable JavaDoc getColorHash() {
166         return colorhash;
167     }
168
169     /**
170      * @return validity (used to determine whether this is a big wasteful
171      * region with no purpose (gnumeric does this
172      */

173     public boolean isValid() {
174         return (!invalid);
175     }
176
177 } // end public class EPStyleRegion
178
Popular Tags