Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AbstractShape.java 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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.model;
  16. import org.apache.poi.ddf.*;
  17. import org.apache.poi.hssf.record.ObjRecord;
  18. import org.apache.poi.hssf.usermodel.*;
  19. /**
  20. * An abstract shape is the lowlevel model for a shape.
  21. *
  22. * @author Glen Stampoultzis (glens at apache.org)
  23. */
  24. @Deprecated
  25. public abstract class AbstractShape
  26. {
  27. /**
  28. * Create a new shape object used to create the escher records.
  29. *
  30. * @param hssfShape The simple shape this is based on.
  31. */
  32. public static AbstractShape createShape( HSSFShape hssfShape, int shapeId )
  33. {
  34. AbstractShape shape;
  35. if (hssfShape instanceof HSSFComment)
  36. {
  37. shape = new CommentShape( (HSSFComment)hssfShape, shapeId );
  38. }
  39. else if (hssfShape instanceof HSSFTextbox)
  40. {
  41. shape = new TextboxShape( (HSSFTextbox)hssfShape, shapeId );
  42. }
  43. else if (hssfShape instanceof HSSFPolygon)
  44. {
  45. shape = new PolygonShape( (HSSFPolygon) hssfShape, shapeId );
  46. }
  47. else if (hssfShape instanceof HSSFSimpleShape)
  48. {
  49. HSSFSimpleShape simpleShape = (HSSFSimpleShape) hssfShape;
  50. switch ( simpleShape.getShapeType() )
  51. {
  52. case HSSFSimpleShape.OBJECT_TYPE_PICTURE:
  53. shape = new PictureShape( simpleShape, shapeId );
  54. break;
  55. case HSSFSimpleShape.OBJECT_TYPE_LINE:
  56. shape = new LineShape( simpleShape, shapeId );
  57. break;
  58. case HSSFSimpleShape.OBJECT_TYPE_OVAL:
  59. case HSSFSimpleShape.OBJECT_TYPE_RECTANGLE:
  60. shape = new SimpleFilledShape( simpleShape, shapeId );
  61. break;
  62. case HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX:
  63. shape = new ComboboxShape( simpleShape, shapeId );
  64. break;
  65. default:
  66. throw new IllegalArgumentException("Do not know how to handle this type of shape");
  67. }
  68. }
  69. else
  70. {
  71. throw new IllegalArgumentException("Unknown shape type");
  72. }
  73. EscherSpRecord sp = shape.getSpContainer().getChildById(EscherSpRecord.RECORD_ID);
  74. if (hssfShape.getParent() != null)
  75. sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_CHILD);
  76. return shape;
  77. }
  78. protected AbstractShape()
  79. {
  80. }
  81. /**
  82. * @return The shape container and it's children that can represent this
  83. * shape.
  84. */
  85. public abstract EscherContainerRecord getSpContainer();
  86. /**
  87. * @return The object record that is associated with this shape.
  88. */
  89. public abstract ObjRecord getObjRecord();
  90. /**
  91. * Creates an escher anchor record from a HSSFAnchor.
  92. *
  93. * @param userAnchor The high level anchor to convert.
  94. * @return An escher anchor record.
  95. */
  96. protected EscherRecord createAnchor( HSSFAnchor userAnchor )
  97. {
  98. return ConvertAnchor.createAnchor(userAnchor);
  99. }
  100. /**
  101. * Add standard properties to the opt record. These properties effect
  102. * all records.
  103. *
  104. * @param shape The user model shape.
  105. * @param opt The opt record to add the properties to.
  106. * @return The number of options added.
  107. */
  108. protected int addStandardOptions( HSSFShape shape, EscherOptRecord opt )
  109. {
  110. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x080000 ) );
  111. // opt.addEscherProperty( new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x080008 ) );
  112. if ( shape.isNoFill() )
  113. {
  114. // Wonderful... none of the spec's give any clue as to what these constants mean.
  115. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.FILL__NOFILLHITTEST, 0x00110000 ) );
  116. }
  117. else
  118. {
  119. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.FILL__NOFILLHITTEST, 0x00010000 ) );
  120. }
  121. opt.addEscherProperty( new EscherRGBProperty( EscherProperties.FILL__FILLCOLOR, shape.getFillColor() ) );
  122. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.GROUPSHAPE__PRINT, 0x080000 ) );
  123. opt.addEscherProperty( new EscherRGBProperty( EscherProperties.LINESTYLE__COLOR, shape.getLineStyleColor() ) );
  124. int options = 5;
  125. if (shape.getLineWidth() != HSSFShape.LINEWIDTH_DEFAULT)
  126. {
  127. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.LINESTYLE__LINEWIDTH, shape.getLineWidth()));
  128. options++;
  129. }
  130. if (shape.getLineStyle() != HSSFShape.LINESTYLE_SOLID)
  131. {
  132. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.LINESTYLE__LINEDASHING, shape.getLineStyle()));
  133. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.LINESTYLE__LINEENDCAPSTYLE, 0));
  134. if (shape.getLineStyle() == HSSFShape.LINESTYLE_NONE)
  135. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080000));
  136. else
  137. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
  138. options += 3;
  139. }
  140. opt.sortProperties();
  141. return options; // # options added
  142. }
  143. /**
  144. * Generate id for the CommonObjectDataSubRecord that stands behind this shape
  145. *
  146. * <p>
  147. * Typically objectId starts with 1, is unique among all Obj record within the worksheet stream
  148. * and increments by 1 for every new shape.
  149. * For most shapes there is a straight relationship between shapeId (generated by DDF) and objectId:
  150. * </p>
  151. * <p>
  152. * shapeId is unique and starts with 1024, hence objectId can be derived as <code>shapeId-1024</code>.
  153. * </p>
  154. * <p>
  155. * An exception from this rule is the CellComment shape whose objectId start with 1024.
  156. * See {@link CommentShape#getCmoObjectId(int)}
  157. * </p>
  158. *
  159. *
  160. *
  161. * @param shapeId shape id as generated by drawing manager
  162. * @return objectId object id that will be assigned to the Obj record
  163. */
  164. int getCmoObjectId(int shapeId){
  165. return shapeId - 1024;
  166. }
  167. }