001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.usermodel;
019:
020: import java.util.ArrayList;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: /**
025: * The patriarch is the toplevel container for shapes in a sheet. It does
026: * little other than act as a container for other shapes and groups.
027: *
028: * @author Glen Stampoultzis (glens at apache.org)
029: */
030: public class HSSFPatriarch implements HSSFShapeContainer {
031: List shapes = new ArrayList();
032: HSSFSheet sheet;
033: int x1 = 0;
034: int y1 = 0;
035: int x2 = 1023;
036: int y2 = 255;
037:
038: /**
039: * Creates the patriarch.
040: *
041: * @param sheet the sheet this patriarch is stored in.
042: */
043: HSSFPatriarch(HSSFSheet sheet) {
044: this .sheet = sheet;
045: }
046:
047: /**
048: * Creates a new group record stored under this patriarch.
049: *
050: * @param anchor the client anchor describes how this group is attached
051: * to the sheet.
052: * @return the newly created group.
053: */
054: public HSSFShapeGroup createGroup(HSSFClientAnchor anchor) {
055: HSSFShapeGroup group = new HSSFShapeGroup(null, anchor);
056: group.anchor = anchor;
057: shapes.add(group);
058: return group;
059: }
060:
061: /**
062: * Creates a simple shape. This includes such shapes as lines, rectangles,
063: * and ovals.
064: *
065: * @param anchor the client anchor describes how this group is attached
066: * to the sheet.
067: * @return the newly created shape.
068: */
069: public HSSFSimpleShape createSimpleShape(HSSFClientAnchor anchor) {
070: HSSFSimpleShape shape = new HSSFSimpleShape(null, anchor);
071: shape.anchor = anchor;
072: shapes.add(shape);
073: return shape;
074: }
075:
076: /**
077: * Creates a picture.
078: *
079: * @param anchor the client anchor describes how this group is attached
080: * to the sheet.
081: * @return the newly created shape.
082: */
083: public HSSFPicture createPicture(HSSFClientAnchor anchor,
084: int pictureIndex) {
085: HSSFPicture shape = new HSSFPicture(null, anchor);
086: shape.setPictureIndex(pictureIndex);
087: shape.anchor = anchor;
088: shape.patriarch = this ;
089: shapes.add(shape);
090: return shape;
091: }
092:
093: /**
094: * Creates a polygon
095: *
096: * @param anchor the client anchor describes how this group is attached
097: * to the sheet.
098: * @return the newly created shape.
099: */
100: public HSSFPolygon createPolygon(HSSFClientAnchor anchor) {
101: HSSFPolygon shape = new HSSFPolygon(null, anchor);
102: shape.anchor = anchor;
103: shapes.add(shape);
104: return shape;
105: }
106:
107: /**
108: * Constructs a textbox under the patriarch.
109: *
110: * @param anchor the client anchor describes how this group is attached
111: * to the sheet.
112: * @return the newly created textbox.
113: */
114: public HSSFTextbox createTextbox(HSSFClientAnchor anchor) {
115: HSSFTextbox shape = new HSSFTextbox(null, anchor);
116: shape.anchor = anchor;
117: shapes.add(shape);
118: return shape;
119: }
120:
121: /**
122: * Constructs a cell comment.
123: *
124: * @param anchor the client anchor describes how this comment is attached
125: * to the sheet.
126: * @return the newly created comment.
127: */
128: public HSSFComment createComment(HSSFAnchor anchor) {
129: HSSFComment shape = new HSSFComment(null, anchor);
130: shape.anchor = anchor;
131: shapes.add(shape);
132: return shape;
133: }
134:
135: /**
136: * Returns a list of all shapes contained by the patriarch.
137: */
138: public List getChildren() {
139: return shapes;
140: }
141:
142: /**
143: * Total count of all children and their children's children.
144: */
145: public int countOfAllChildren() {
146: int count = shapes.size();
147: for (Iterator iterator = shapes.iterator(); iterator.hasNext();) {
148: HSSFShape shape = (HSSFShape) iterator.next();
149: count += shape.countOfAllChildren();
150: }
151: return count;
152: }
153:
154: /**
155: * Sets the coordinate space of this group. All children are contrained
156: * to these coordinates.
157: */
158: public void setCoordinates(int x1, int y1, int x2, int y2) {
159: this .x1 = x1;
160: this .y1 = y1;
161: this .x2 = x2;
162: this .y2 = y2;
163: }
164:
165: /**
166: * The top left x coordinate of this group.
167: */
168: public int getX1() {
169: return x1;
170: }
171:
172: /**
173: * The top left y coordinate of this group.
174: */
175: public int getY1() {
176: return y1;
177: }
178:
179: /**
180: * The bottom right x coordinate of this group.
181: */
182: public int getX2() {
183: return x2;
184: }
185:
186: /**
187: * The bottom right y coordinate of this group.
188: */
189: public int getY2() {
190: return y2;
191: }
192:
193: }
|