KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 1999-2002,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.util.RangeAddress;
20 import org.apache.poi.hssf.util.Region;
21
22 import java.io.IOException JavaDoc;
23
24 /**
25  * No-op implementation of ElementProcessor to handle the "Merge" tag.
26  * This element is a container of other elements and has several attributes.
27  *
28  * @author Danny Mui (danny@muibros.com)
29  * @version CVS $Id: EPMerge.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public class EPMerge extends BaseElementProcessor {
32
33     private String JavaDoc _cellRange;
34
35     /**
36      * constructor
37      */

38     public EPMerge() {
39         super(null);
40         _cellRange = null;
41     }
42
43     public String JavaDoc getCellRange() {
44         if (this._cellRange == null) {
45             //pulls in the content
46
_cellRange = this.getData();
47         }
48         return this._cellRange;
49     }
50
51     /**
52      * Setup the merged regions
53      * @exception IOException
54      */

55     public void endProcessing() throws IOException JavaDoc {
56         RangeAddress rangeAddress = new RangeAddress(getCellRange());
57         Sheet sheet = this.getSheet();
58
59         //subtracting one since rangeaddress starts at 1,1 where rows/cols
60
// start at 0,0
61
short fromCol =
62             (short) (rangeAddress.getXPosition(rangeAddress.getFromCell()) - 1);
63         int fromRow = rangeAddress.getYPosition(rangeAddress.getFromCell()) - 1;
64         short toCol =
65             (short) (rangeAddress.getXPosition(rangeAddress.getToCell()) - 1);
66         int toRow = rangeAddress.getYPosition(rangeAddress.getToCell()) - 1;
67
68         if (getLogger().isDebugEnabled()) {
69             getLogger().debug("Merging Range: Row (" + fromRow + ") Col ("
70                     + fromCol + ")" + " to Row (" + toRow + ") Col (" + toCol
71                     + ")");
72         }
73         Region region = new Region(fromRow, fromCol, toRow, toCol);
74         sheet.addMergedRegion(region);
75     }
76
77 } // end public class EPMerge
78
Popular Tags