KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > usermodel > HSSFShapeGroup


1 /* ====================================================================
2    Copyright 2004 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.poi.hssf.usermodel;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 /**
24  * A shape group may contain other shapes. It was no actual form on the
25  * sheet.
26  *
27  * @author Glen Stampoultzis (glens at apache.org)
28  */

29 public class HSSFShapeGroup
30         extends HSSFShape
31         implements HSSFShapeContainer
32 {
33     List JavaDoc shapes = new ArrayList JavaDoc();
34     int x1 = 0;
35     int y1 = 0 ;
36     int x2 = 1023;
37     int y2 = 255;
38
39
40     public HSSFShapeGroup( HSSFShape parent, HSSFAnchor anchor )
41     {
42         super( parent, anchor );
43     }
44
45     /**
46      * Create another group under this group.
47      * @param anchor the position of the new group.
48      * @return the group
49      */

50     public HSSFShapeGroup createGroup(HSSFChildAnchor anchor)
51     {
52         HSSFShapeGroup group = new HSSFShapeGroup(this, anchor);
53         group.anchor = anchor;
54         shapes.add(group);
55         return group;
56     }
57
58     /**
59      * Create a new simple shape under this group.
60      * @param anchor the position of the shape.
61      * @return the shape
62      */

63     public HSSFSimpleShape createShape(HSSFChildAnchor anchor)
64     {
65         HSSFSimpleShape shape = new HSSFSimpleShape(this, anchor);
66         shape.anchor = anchor;
67         shapes.add(shape);
68         return shape;
69     }
70
71     /**
72      * Create a new textbox under this group.
73      * @param anchor the position of the shape.
74      * @return the textbox
75      */

76     public HSSFTextbox createTextbox(HSSFChildAnchor anchor)
77     {
78         HSSFTextbox shape = new HSSFTextbox(this, anchor);
79         shape.anchor = anchor;
80         shapes.add(shape);
81         return shape;
82     }
83
84     /**
85      * Creates a polygon
86      *
87      * @param anchor the client anchor describes how this group is attached
88      * to the sheet.
89      * @return the newly created shape.
90      */

91     public HSSFPolygon createPolygon(HSSFChildAnchor anchor)
92     {
93         HSSFPolygon shape = new HSSFPolygon(this, anchor);
94         shape.anchor = anchor;
95         shapes.add(shape);
96         return shape;
97     }
98
99     /**
100      * Return all children contained by this shape.
101      */

102     public List JavaDoc getChildren()
103     {
104         return shapes;
105     }
106
107     /**
108      * Sets the coordinate space of this group. All children are contrained
109      * to these coordinates.
110      */

111     public void setCoordinates( int x1, int y1, int x2, int y2 )
112     {
113         this.x1 = x1;
114         this.y1 = y1;
115         this.x2 = x2;
116         this.y2 = y2;
117     }
118
119     /**
120      * The top left x coordinate of this group.
121      */

122     public int getX1()
123     {
124         return x1;
125     }
126
127     /**
128      * The top left y coordinate of this group.
129      */

130     public int getY1()
131     {
132         return y1;
133     }
134
135     /**
136      * The bottom right x coordinate of this group.
137      */

138     public int getX2()
139     {
140         return x2;
141     }
142
143     /**
144      * The bottom right y coordinate of this group.
145      */

146     public int getY2()
147     {
148         return y2;
149     }
150
151     /**
152      * Count of all children and their childrens children.
153      */

154     public int countOfAllChildren()
155     {
156         int count = shapes.size();
157         for ( Iterator JavaDoc iterator = shapes.iterator(); iterator.hasNext(); )
158         {
159             HSSFShape shape = (HSSFShape) iterator.next();
160             count += shape.countOfAllChildren();
161         }
162         return count;
163     }
164 }
165
Popular Tags