Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

HSSFShapeGroup.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.usermodel;
  16. import org.apache.poi.ddf.EscherChildAnchorRecord;
  17. import org.apache.poi.ddf.EscherClientAnchorRecord;
  18. import org.apache.poi.ddf.EscherContainerRecord;
  19. import org.apache.poi.ddf.EscherRecord;
  20. import org.apache.poi.ddf.EscherSpgrRecord;
  21. import org.apache.poi.hssf.model.TextboxShape;
  22. import org.apache.poi.hssf.record.EscherAggregate;
  23. import org.apache.poi.hssf.record.ObjRecord;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import java.util.Iterator;
  27. /**
  28. * A shape group may contain other shapes. It was no actual form on the
  29. * sheet.
  30. *
  31. * @author Glen Stampoultzis (glens at apache.org)
  32. */
  33. public class HSSFShapeGroup
  34. extends HSSFShape
  35. implements HSSFShapeContainer
  36. {
  37. List<HSSFShape> shapes = new ArrayList<HSSFShape>();
  38. int x1 = 0;
  39. int y1 = 0 ;
  40. int x2 = 1023;
  41. int y2 = 255;
  42. public HSSFShapeGroup(EscherContainerRecord spgrContainer, ObjRecord objRecord) {
  43. super(spgrContainer, objRecord);
  44. // read internal and external coordinates from spgrContainer
  45. EscherContainerRecord spContainer = spgrContainer.getChildContainers().get(0);
  46. for(EscherRecord ch : spContainer.getChildRecords()){
  47. switch(ch.getRecordId()) {
  48. case EscherSpgrRecord.RECORD_ID:
  49. EscherSpgrRecord spgr = (EscherSpgrRecord)ch;
  50. setCoordinates(
  51. spgr.getRectX1(), spgr.getRectY1(),
  52. spgr.getRectX2(), spgr.getRectY2()
  53. );
  54. break;
  55. case EscherClientAnchorRecord.RECORD_ID:
  56. this.anchor = EscherAggregate.toClientAnchor((EscherClientAnchorRecord)ch);
  57. // TODO anchor = new HSSFClientAnchor((EscherChildAnchorRecord)ch);
  58. break;
  59. case EscherChildAnchorRecord.RECORD_ID:
  60. this.anchor = EscherAggregate.toChildAnchor((EscherChildAnchorRecord)ch);
  61. // TODO anchor = new HSSFChildAnchor((EscherClientAnchorRecord)ch);
  62. break;
  63. }
  64. }
  65. }
  66. public HSSFShapeGroup( HSSFShape parent, HSSFAnchor anchor )
  67. {
  68. super( parent, anchor );
  69. }
  70. /**
  71. * Create another group under this group.
  72. * @param anchor the position of the new group.
  73. * @return the group
  74. */
  75. public HSSFShapeGroup createGroup(HSSFChildAnchor anchor)
  76. {
  77. HSSFShapeGroup group = new HSSFShapeGroup(this, anchor);
  78. group.anchor = anchor;
  79. shapes.add(group);
  80. return group;
  81. }
  82. public void addShape(HSSFShape shape){
  83. shape._patriarch = this._patriarch;
  84. shapes.add(shape);
  85. }
  86. public void addTextBox(TextboxShape textboxShape){
  87. // HSSFTextbox shape = new HSSFTextbox(this, textboxShape.geanchor);
  88. // shapes.add(textboxShape);
  89. }
  90. /**
  91. * Create a new simple shape under this group.
  92. * @param anchor the position of the shape.
  93. * @return the shape
  94. */
  95. public HSSFSimpleShape createShape(HSSFChildAnchor anchor)
  96. {
  97. HSSFSimpleShape shape = new HSSFSimpleShape(this, anchor);
  98. shape.anchor = anchor;
  99. shapes.add(shape);
  100. return shape;
  101. }
  102. /**
  103. * Create a new textbox under this group.
  104. * @param anchor the position of the shape.
  105. * @return the textbox
  106. */
  107. public HSSFTextbox createTextbox(HSSFChildAnchor anchor)
  108. {
  109. HSSFTextbox shape = new HSSFTextbox(this, anchor);
  110. shape.anchor = anchor;
  111. shapes.add(shape);
  112. return shape;
  113. }
  114. /**
  115. * Creates a polygon
  116. *
  117. * @param anchor the client anchor describes how this group is attached
  118. * to the sheet.
  119. * @return the newly created shape.
  120. */
  121. public HSSFPolygon createPolygon(HSSFChildAnchor anchor)
  122. {
  123. HSSFPolygon shape = new HSSFPolygon(this, anchor);
  124. shape.anchor = anchor;
  125. shapes.add(shape);
  126. return shape;
  127. }
  128. /**
  129. * Creates a picture.
  130. *
  131. * @param anchor the client anchor describes how this group is attached
  132. * to the sheet.
  133. * @return the newly created shape.
  134. */
  135. public HSSFPicture createPicture(HSSFChildAnchor anchor, int pictureIndex)
  136. {
  137. HSSFPicture shape = new HSSFPicture(this, anchor);
  138. shape.anchor = anchor;
  139. shape.setPictureIndex( pictureIndex );
  140. shapes.add(shape);
  141. return shape;
  142. }
  143. /**
  144. * Return all children contained by this shape.
  145. */
  146. public List<HSSFShape> getChildren()
  147. {
  148. return shapes;
  149. }
  150. /**
  151. * Sets the coordinate space of this group. All children are constrained
  152. * to these coordinates.
  153. */
  154. public void setCoordinates( int x1, int y1, int x2, int y2 )
  155. {
  156. this.x1 = x1;
  157. this.y1 = y1;
  158. this.x2 = x2;
  159. this.y2 = y2;
  160. }
  161. /**
  162. * The top left x coordinate of this group.
  163. */
  164. public int getX1()
  165. {
  166. return x1;
  167. }
  168. /**
  169. * The top left y coordinate of this group.
  170. */
  171. public int getY1()
  172. {
  173. return y1;
  174. }
  175. /**
  176. * The bottom right x coordinate of this group.
  177. */
  178. public int getX2()
  179. {
  180. return x2;
  181. }
  182. /**
  183. * The bottom right y coordinate of this group.
  184. */
  185. public int getY2()
  186. {
  187. return y2;
  188. }
  189. /**
  190. * Count of all children and their childrens children.
  191. */
  192. public int countOfAllChildren()
  193. {
  194. int count = shapes.size();
  195. for ( Iterator iterator = shapes.iterator(); iterator.hasNext(); )
  196. {
  197. HSSFShape shape = (HSSFShape) iterator.next();
  198. count += shape.countOfAllChildren();
  199. }
  200. return count;
  201. }
  202. }