KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 /**
24  * The patriarch is the toplevel container for shapes in a sheet. It does
25  * little other than act as a container for other shapes and groups.
26  *
27  * @author Glen Stampoultzis (glens at apache.org)
28  */

29 public class HSSFPatriarch
30         implements HSSFShapeContainer
31 {
32     List JavaDoc shapes = new ArrayList JavaDoc();
33     HSSFSheet sheet;
34     int x1 = 0;
35     int y1 = 0 ;
36     int x2 = 1023;
37     int y2 = 255;
38
39     /**
40      * Creates the patriarch.
41      *
42      * @param sheet the sheet this patriarch is stored in.
43      */

44     HSSFPatriarch(HSSFSheet sheet)
45     {
46         this.sheet = sheet;
47     }
48
49     /**
50      * Creates a new group record stored under this patriarch.
51      *
52      * @param anchor the client anchor describes how this group is attached
53      * to the sheet.
54      * @return the newly created group.
55      */

56     public HSSFShapeGroup createGroup(HSSFClientAnchor anchor)
57     {
58         HSSFShapeGroup group = new HSSFShapeGroup(null, anchor);
59         group.anchor = anchor;
60         shapes.add(group);
61         return group;
62     }
63
64     /**
65      * Creates a simple shape. This includes such shapes as lines, rectangles,
66      * and ovals.
67      *
68      * @param anchor the client anchor describes how this group is attached
69      * to the sheet.
70      * @return the newly created shape.
71      */

72     public HSSFSimpleShape createSimpleShape(HSSFClientAnchor anchor)
73     {
74         HSSFSimpleShape shape = new HSSFSimpleShape(null, anchor);
75         shape.anchor = anchor;
76         shapes.add(shape);
77         return shape;
78     }
79
80     /**
81      * Creates a polygon
82      *
83      * @param anchor the client anchor describes how this group is attached
84      * to the sheet.
85      * @return the newly created shape.
86      */

87     public HSSFPolygon createPolygon(HSSFClientAnchor anchor)
88     {
89         HSSFPolygon shape = new HSSFPolygon(null, anchor);
90         shape.anchor = anchor;
91         shapes.add(shape);
92         return shape;
93     }
94
95     /**
96      * Constructs a textbox under the patriarch.
97      *
98      * @param anchor the client anchor describes how this group is attached
99      * to the sheet.
100      * @return the newly created textbox.
101      */

102     public HSSFTextbox createTextbox(HSSFClientAnchor anchor)
103     {
104         HSSFTextbox shape = new HSSFTextbox(null, anchor);
105         shape.anchor = anchor;
106         shapes.add(shape);
107         return shape;
108     }
109
110     /**
111      * Returns a list of all shapes contained by the patriarch.
112      */

113     public List JavaDoc getChildren()
114     {
115         return shapes;
116     }
117
118     /**
119      * Total count of all children and their children's children.
120      */

121     public int countOfAllChildren()
122     {
123         int count = shapes.size();
124         for ( Iterator JavaDoc iterator = shapes.iterator(); iterator.hasNext(); )
125         {
126             HSSFShape shape = (HSSFShape) iterator.next();
127             count += shape.countOfAllChildren();
128         }
129         return count;
130     }
131     /**
132      * Sets the coordinate space of this group. All children are contrained
133      * to these coordinates.
134      */

135     public void setCoordinates( int x1, int y1, int x2, int y2 )
136     {
137         this.x1 = x1;
138         this.y1 = y1;
139         this.x2 = x2;
140         this.y2 = y2;
141     }
142
143     /**
144      * The top left x coordinate of this group.
145      */

146     public int getX1()
147     {
148         return x1;
149     }
150
151     /**
152      * The top left y coordinate of this group.
153      */

154     public int getY1()
155     {
156         return y1;
157     }
158
159     /**
160      * The bottom right x coordinate of this group.
161      */

162     public int getX2()
163     {
164         return x2;
165     }
166
167     /**
168      * The bottom right y coordinate of this group.
169      */

170     public int getY2()
171     {
172         return y2;
173     }
174
175 }
176
Popular Tags