PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/components/forks/poi/src/loci/poi/hssf/usermodel/HSSFShapeGroup.java

http://github.com/openmicroscopy/bioformats
Java | 203 lines | 91 code | 17 blank | 95 comment | 1 complexity | e2d5d76c6a10bbbf99c420548d2f8688 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.hssf.usermodel;
  38. import java.util.ArrayList;
  39. import java.util.List;
  40. import java.util.Iterator;
  41. /**
  42. * A shape group may contain other shapes. It was no actual form on the
  43. * sheet.
  44. *
  45. * @author Glen Stampoultzis (glens at apache.org)
  46. */
  47. public class HSSFShapeGroup
  48. extends HSSFShape
  49. implements HSSFShapeContainer
  50. {
  51. List shapes = new ArrayList();
  52. int x1 = 0;
  53. int y1 = 0 ;
  54. int x2 = 1023;
  55. int y2 = 255;
  56. public HSSFShapeGroup( HSSFShape parent, HSSFAnchor anchor )
  57. {
  58. super( parent, anchor );
  59. }
  60. /**
  61. * Create another group under this group.
  62. * @param anchor the position of the new group.
  63. * @return the group
  64. */
  65. public HSSFShapeGroup createGroup(HSSFChildAnchor anchor)
  66. {
  67. HSSFShapeGroup group = new HSSFShapeGroup(this, anchor);
  68. group.anchor = anchor;
  69. shapes.add(group);
  70. return group;
  71. }
  72. /**
  73. * Create a new simple shape under this group.
  74. * @param anchor the position of the shape.
  75. * @return the shape
  76. */
  77. public HSSFSimpleShape createShape(HSSFChildAnchor anchor)
  78. {
  79. HSSFSimpleShape shape = new HSSFSimpleShape(this, anchor);
  80. shape.anchor = anchor;
  81. shapes.add(shape);
  82. return shape;
  83. }
  84. /**
  85. * Create a new textbox under this group.
  86. * @param anchor the position of the shape.
  87. * @return the textbox
  88. */
  89. public HSSFTextbox createTextbox(HSSFChildAnchor anchor)
  90. {
  91. HSSFTextbox shape = new HSSFTextbox(this, anchor);
  92. shape.anchor = anchor;
  93. shapes.add(shape);
  94. return shape;
  95. }
  96. /**
  97. * Creates a polygon
  98. *
  99. * @param anchor the client anchor describes how this group is attached
  100. * to the sheet.
  101. * @return the newly created shape.
  102. */
  103. public HSSFPolygon createPolygon(HSSFChildAnchor anchor)
  104. {
  105. HSSFPolygon shape = new HSSFPolygon(this, anchor);
  106. shape.anchor = anchor;
  107. shapes.add(shape);
  108. return shape;
  109. }
  110. /**
  111. * Creates a picture.
  112. *
  113. * @param anchor the client anchor describes how this group is attached
  114. * to the sheet.
  115. * @return the newly created shape.
  116. */
  117. public HSSFPicture createPicture(HSSFChildAnchor anchor, int pictureIndex)
  118. {
  119. HSSFPicture shape = new HSSFPicture(this, anchor);
  120. shape.anchor = anchor;
  121. shape.setPictureIndex( pictureIndex );
  122. shapes.add(shape);
  123. return shape;
  124. }
  125. /**
  126. * Return all children contained by this shape.
  127. */
  128. public List getChildren()
  129. {
  130. return shapes;
  131. }
  132. /**
  133. * Sets the coordinate space of this group. All children are contrained
  134. * to these coordinates.
  135. */
  136. public void setCoordinates( int x1, int y1, int x2, int y2 )
  137. {
  138. this.x1 = x1;
  139. this.y1 = y1;
  140. this.x2 = x2;
  141. this.y2 = y2;
  142. }
  143. /**
  144. * The top left x coordinate of this group.
  145. */
  146. public int getX1()
  147. {
  148. return x1;
  149. }
  150. /**
  151. * The top left y coordinate of this group.
  152. */
  153. public int getY1()
  154. {
  155. return y1;
  156. }
  157. /**
  158. * The bottom right x coordinate of this group.
  159. */
  160. public int getX2()
  161. {
  162. return x2;
  163. }
  164. /**
  165. * The bottom right y coordinate of this group.
  166. */
  167. public int getY2()
  168. {
  169. return y2;
  170. }
  171. /**
  172. * Count of all children and their childrens children.
  173. */
  174. public int countOfAllChildren()
  175. {
  176. int count = shapes.size();
  177. for ( Iterator iterator = shapes.iterator(); iterator.hasNext(); )
  178. {
  179. HSSFShape shape = (HSSFShape) iterator.next();
  180. count += shape.countOfAllChildren();
  181. }
  182. return count;
  183. }
  184. }