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.List;
022: import java.util.Iterator;
023:
024: /**
025: * A shape group may contain other shapes. It was no actual form on the
026: * sheet.
027: *
028: * @author Glen Stampoultzis (glens at apache.org)
029: */
030: public class HSSFShapeGroup extends HSSFShape implements
031: HSSFShapeContainer {
032: List shapes = new ArrayList();
033: int x1 = 0;
034: int y1 = 0;
035: int x2 = 1023;
036: int y2 = 255;
037:
038: public HSSFShapeGroup(HSSFShape parent, HSSFAnchor anchor) {
039: super (parent, anchor);
040: }
041:
042: /**
043: * Create another group under this group.
044: * @param anchor the position of the new group.
045: * @return the group
046: */
047: public HSSFShapeGroup createGroup(HSSFChildAnchor anchor) {
048: HSSFShapeGroup group = new HSSFShapeGroup(this , anchor);
049: group.anchor = anchor;
050: shapes.add(group);
051: return group;
052: }
053:
054: /**
055: * Create a new simple shape under this group.
056: * @param anchor the position of the shape.
057: * @return the shape
058: */
059: public HSSFSimpleShape createShape(HSSFChildAnchor anchor) {
060: HSSFSimpleShape shape = new HSSFSimpleShape(this , anchor);
061: shape.anchor = anchor;
062: shapes.add(shape);
063: return shape;
064: }
065:
066: /**
067: * Create a new textbox under this group.
068: * @param anchor the position of the shape.
069: * @return the textbox
070: */
071: public HSSFTextbox createTextbox(HSSFChildAnchor anchor) {
072: HSSFTextbox shape = new HSSFTextbox(this , anchor);
073: shape.anchor = anchor;
074: shapes.add(shape);
075: return shape;
076: }
077:
078: /**
079: * Creates a polygon
080: *
081: * @param anchor the client anchor describes how this group is attached
082: * to the sheet.
083: * @return the newly created shape.
084: */
085: public HSSFPolygon createPolygon(HSSFChildAnchor anchor) {
086: HSSFPolygon shape = new HSSFPolygon(this , anchor);
087: shape.anchor = anchor;
088: shapes.add(shape);
089: return shape;
090: }
091:
092: /**
093: * Creates a picture.
094: *
095: * @param anchor the client anchor describes how this group is attached
096: * to the sheet.
097: * @return the newly created shape.
098: */
099: public HSSFPicture createPicture(HSSFChildAnchor anchor,
100: int pictureIndex) {
101: HSSFPicture shape = new HSSFPicture(this , anchor);
102: shape.anchor = anchor;
103: shape.setPictureIndex(pictureIndex);
104: shapes.add(shape);
105: return shape;
106: }
107:
108: /**
109: * Return all children contained by this shape.
110: */
111: public List getChildren() {
112: return shapes;
113: }
114:
115: /**
116: * Sets the coordinate space of this group. All children are contrained
117: * to these coordinates.
118: */
119: public void setCoordinates(int x1, int y1, int x2, int y2) {
120: this .x1 = x1;
121: this .y1 = y1;
122: this .x2 = x2;
123: this .y2 = y2;
124: }
125:
126: /**
127: * The top left x coordinate of this group.
128: */
129: public int getX1() {
130: return x1;
131: }
132:
133: /**
134: * The top left y coordinate of this group.
135: */
136: public int getY1() {
137: return y1;
138: }
139:
140: /**
141: * The bottom right x coordinate of this group.
142: */
143: public int getX2() {
144: return x2;
145: }
146:
147: /**
148: * The bottom right y coordinate of this group.
149: */
150: public int getY2() {
151: return y2;
152: }
153:
154: /**
155: * Count of all children and their childrens children.
156: */
157: public int countOfAllChildren() {
158: int count = shapes.size();
159: for (Iterator iterator = shapes.iterator(); iterator.hasNext();) {
160: HSSFShape shape = (HSSFShape) iterator.next();
161: count += shape.countOfAllChildren();
162: }
163: return count;
164: }
165:
166: }
|