01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements;
19:
20: import org.apache.poi.hssf.usermodel.HSSFCell;
21: import org.apache.poi.hssf.usermodel.HSSFRow;
22:
23: import java.io.IOException;
24:
25: /**
26: * internal representation of a Row
27: *
28: * @author Marc Johnson (marc_johnson27591@hotmail.com)
29: * @version CVS $Id: Row.java 433543 2006-08-22 06:22:54Z crossley $
30: */
31:
32: // package scope
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 {
52: if (!isValid(points)) {
53: throw new IOException("points " + points
54: + " is out of range");
55: }
56: _row.setHeight((short) (points * 20));
57: }
58:
59: /**
60: * get the row height of a specified row
61: * @return row height in 1/20 of a point
62: */
63: short getHeight() {
64: return _row.getHeight();
65: }
66:
67: /**
68: * create a cell in a specific column, with a specific type
69: * @param column the column number for the cell
70: * @param cellType the cell type, being an enum from the CellType class
71: * @return a new Cell object
72: * @exception IOException
73: */
74: Cell createCell(final int column, final int cellType)
75: throws IOException {
76: if (column < 0 || column > Short.MAX_VALUE) {
77: throw new IOException("Illegal column value: " + column);
78: }
79: HSSFCell hssfCell = _row.createCell((short) column);
80: hssfCell.setCellType(CellType.convertCellType(cellType));
81:
82: Cell cell = new Cell(hssfCell, cellType);
83: cell.setStyle(_sheet.getCellStyleForRegion(_row.getRowNum(),
84: (short) column));
85: return cell;
86: }
87:
88: private boolean isValid(double points) {
89: return ((points >= 0) && (points <= (((double) Short.MAX_VALUE) / 20)));
90: }
91: } // end package scope class Row
|