PageRenderTime 36ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 231 lines | 99 code | 18 blank | 114 comment | 1 complexity | 15cf21df230a2e5bafaf6da9ba3a0dc3 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.Iterator;
  40. import java.util.List;
  41. /**
  42. * The patriarch is the toplevel container for shapes in a sheet. It does
  43. * little other than act as a container for other shapes and groups.
  44. *
  45. * @author Glen Stampoultzis (glens at apache.org)
  46. */
  47. public class HSSFPatriarch
  48. implements HSSFShapeContainer
  49. {
  50. List shapes = new ArrayList();
  51. HSSFSheet sheet;
  52. int x1 = 0;
  53. int y1 = 0 ;
  54. int x2 = 1023;
  55. int y2 = 255;
  56. /**
  57. * Creates the patriarch.
  58. *
  59. * @param sheet the sheet this patriarch is stored in.
  60. */
  61. HSSFPatriarch(HSSFSheet sheet)
  62. {
  63. this.sheet = sheet;
  64. }
  65. /**
  66. * Creates a new group record stored under this patriarch.
  67. *
  68. * @param anchor the client anchor describes how this group is attached
  69. * to the sheet.
  70. * @return the newly created group.
  71. */
  72. public HSSFShapeGroup createGroup(HSSFClientAnchor anchor)
  73. {
  74. HSSFShapeGroup group = new HSSFShapeGroup(null, anchor);
  75. group.anchor = anchor;
  76. shapes.add(group);
  77. return group;
  78. }
  79. /**
  80. * Creates a simple shape. This includes such shapes as lines, rectangles,
  81. * and ovals.
  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 HSSFSimpleShape createSimpleShape(HSSFClientAnchor anchor)
  88. {
  89. HSSFSimpleShape shape = new HSSFSimpleShape(null, anchor);
  90. shape.anchor = anchor;
  91. shapes.add(shape);
  92. return shape;
  93. }
  94. /**
  95. * Creates a picture.
  96. *
  97. * @param anchor the client anchor describes how this group is attached
  98. * to the sheet.
  99. * @return the newly created shape.
  100. */
  101. public HSSFPicture createPicture(HSSFClientAnchor anchor, int pictureIndex)
  102. {
  103. HSSFPicture shape = new HSSFPicture(null, anchor);
  104. shape.setPictureIndex( pictureIndex );
  105. shape.anchor = anchor;
  106. shape.patriarch = this;
  107. shapes.add(shape);
  108. return shape;
  109. }
  110. /**
  111. * Creates a polygon
  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 HSSFPolygon createPolygon(HSSFClientAnchor anchor)
  118. {
  119. HSSFPolygon shape = new HSSFPolygon(null, anchor);
  120. shape.anchor = anchor;
  121. shapes.add(shape);
  122. return shape;
  123. }
  124. /**
  125. * Constructs a textbox under the patriarch.
  126. *
  127. * @param anchor the client anchor describes how this group is attached
  128. * to the sheet.
  129. * @return the newly created textbox.
  130. */
  131. public HSSFTextbox createTextbox(HSSFClientAnchor anchor)
  132. {
  133. HSSFTextbox shape = new HSSFTextbox(null, anchor);
  134. shape.anchor = anchor;
  135. shapes.add(shape);
  136. return shape;
  137. }
  138. /**
  139. * Constructs a cell comment.
  140. *
  141. * @param anchor the client anchor describes how this comment is attached
  142. * to the sheet.
  143. * @return the newly created comment.
  144. */
  145. public HSSFComment createComment(HSSFAnchor anchor)
  146. {
  147. HSSFComment shape = new HSSFComment(null, anchor);
  148. shape.anchor = anchor;
  149. shapes.add(shape);
  150. return shape;
  151. }
  152. /**
  153. * Returns a list of all shapes contained by the patriarch.
  154. */
  155. public List getChildren()
  156. {
  157. return shapes;
  158. }
  159. /**
  160. * Total count of all children and their children's children.
  161. */
  162. public int countOfAllChildren()
  163. {
  164. int count = shapes.size();
  165. for ( Iterator iterator = shapes.iterator(); iterator.hasNext(); )
  166. {
  167. HSSFShape shape = (HSSFShape) iterator.next();
  168. count += shape.countOfAllChildren();
  169. }
  170. return count;
  171. }
  172. /**
  173. * Sets the coordinate space of this group. All children are contrained
  174. * to these coordinates.
  175. */
  176. public void setCoordinates( int x1, int y1, int x2, int y2 )
  177. {
  178. this.x1 = x1;
  179. this.y1 = y1;
  180. this.x2 = x2;
  181. this.y2 = y2;
  182. }
  183. /**
  184. * The top left x coordinate of this group.
  185. */
  186. public int getX1()
  187. {
  188. return x1;
  189. }
  190. /**
  191. * The top left y coordinate of this group.
  192. */
  193. public int getY1()
  194. {
  195. return y1;
  196. }
  197. /**
  198. * The bottom right x coordinate of this group.
  199. */
  200. public int getX2()
  201. {
  202. return x2;
  203. }
  204. /**
  205. * The bottom right y coordinate of this group.
  206. */
  207. public int getY2()
  208. {
  209. return y2;
  210. }
  211. }