KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.poi.hssf.usermodel.HSSFCell;
20 import org.apache.poi.hssf.usermodel.HSSFRow;
21
22 import java.io.IOException JavaDoc;
23
24 /**
25  * internal representation of a Row
26  *
27  * @author Marc Johnson (marc_johnson27591@hotmail.com)
28  * @version CVS $Id: Row.java 30932 2004-07-29 17:35:38Z vgritsenko $
29  */

30
31 // package scope
32

33 class Row {
34     private HSSFRow _row;
35     private Sheet _sheet;
36
37     /**
38      * Constructor Row
39      * @param row
40      */

41     Row(final HSSFRow row, final Sheet sheet) {
42         _row = row;
43         _sheet = sheet;
44     }
45
46     /**
47      * set a row's height
48      * @param points the height, in points
49      * @exception IOException if any arguments are illegal
50      */

51     void setHeight(final double points) throws IOException JavaDoc {
52         if (!isValid(points)) {
53             throw new IOException JavaDoc("points " + points + " is out of range");
54         }
55         _row.setHeight((short) (points * 20));
56     }
57
58     /**
59      * get the row height of a specified row
60      * @return row height in 1/20 of a point
61      */

62     short getHeight() {
63         return _row.getHeight();
64     }
65
66     /**
67      * create a cell in a specific column, with a specific type
68      * @param column the column number for the cell
69      * @param cellType the cell type, being an enum from the CellType class
70      * @return a new Cell object
71      * @exception IOException
72      */

73     Cell createCell(final int column, final int cellType) throws IOException JavaDoc {
74         if (column < 0 || column > Short.MAX_VALUE) {
75             throw new IOException JavaDoc("Illegal column value: " + column);
76         }
77         HSSFCell hssfCell = _row.createCell((short)column);
78         hssfCell.setCellType(CellType.convertCellType(cellType));
79
80         Cell cell = new Cell(hssfCell, cellType);
81         cell.setStyle(_sheet.getCellStyleForRegion(_row.getRowNum(),
82                 (short)column));
83         return cell;
84     }
85
86     private boolean isValid(double points) {
87         return ((points >= 0) && (points <= (((double)Short.MAX_VALUE) / 20)));
88     }
89 } // end package scope class Row
90
Popular Tags