PageRenderTime 60ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/model/AbstractShape.java

http://github.com/openmicroscopy/bioformats
Java | 173 lines | 92 code | 10 blank | 71 comment | 17 complexity | 4b8479a67e34a342cfde58c7278efb63 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.model;
  38. import loci.poi.ddf.*;
  39. import loci.poi.hssf.record.ObjRecord;
  40. import loci.poi.hssf.usermodel.*;
  41. /**
  42. * An abstract shape is the lowlevel model for a shape.
  43. *
  44. * @author Glen Stampoultzis (glens at apache.org)
  45. */
  46. public abstract class AbstractShape
  47. {
  48. /**
  49. * Create a new shape object used to create the escher records.
  50. *
  51. * @param hssfShape The simple shape this is based on.
  52. */
  53. public static AbstractShape createShape( HSSFShape hssfShape, int shapeId )
  54. {
  55. AbstractShape shape;
  56. if (hssfShape instanceof HSSFComment)
  57. {
  58. shape = new CommentShape( (HSSFComment)hssfShape, shapeId );
  59. }
  60. else if (hssfShape instanceof HSSFTextbox)
  61. {
  62. shape = new TextboxShape( (HSSFTextbox)hssfShape, shapeId );
  63. }
  64. else if (hssfShape instanceof HSSFPolygon)
  65. {
  66. shape = new PolygonShape( (HSSFPolygon) hssfShape, shapeId );
  67. }
  68. else if (hssfShape instanceof HSSFSimpleShape)
  69. {
  70. HSSFSimpleShape simpleShape = (HSSFSimpleShape) hssfShape;
  71. switch ( simpleShape.getShapeType() )
  72. {
  73. case HSSFSimpleShape.OBJECT_TYPE_PICTURE:
  74. shape = new PictureShape( simpleShape, shapeId );
  75. break;
  76. case HSSFSimpleShape.OBJECT_TYPE_LINE:
  77. shape = new LineShape( simpleShape, shapeId );
  78. break;
  79. case HSSFSimpleShape.OBJECT_TYPE_OVAL:
  80. case HSSFSimpleShape.OBJECT_TYPE_RECTANGLE:
  81. shape = new SimpleFilledShape( simpleShape, shapeId );
  82. break;
  83. default:
  84. throw new IllegalArgumentException("Do not know how to handle this type of shape");
  85. }
  86. }
  87. else
  88. {
  89. throw new IllegalArgumentException("Unknown shape type");
  90. }
  91. EscherSpRecord sp = shape.getSpContainer().getChildById(EscherSpRecord.RECORD_ID);
  92. if (hssfShape.getParent() != null)
  93. sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_CHILD);
  94. return shape;
  95. }
  96. protected AbstractShape()
  97. {
  98. }
  99. /**
  100. * @return The shape container and it's children that can represent this
  101. * shape.
  102. */
  103. public abstract EscherContainerRecord getSpContainer();
  104. /**
  105. * @return The object record that is associated with this shape.
  106. */
  107. public abstract ObjRecord getObjRecord();
  108. /**
  109. * Creates an escher anchor record from a HSSFAnchor.
  110. *
  111. * @param userAnchor The high level anchor to convert.
  112. * @return An escher anchor record.
  113. */
  114. protected EscherRecord createAnchor( HSSFAnchor userAnchor )
  115. {
  116. return ConvertAnchor.createAnchor(userAnchor);
  117. }
  118. /**
  119. * Add standard properties to the opt record. These properties effect
  120. * all records.
  121. *
  122. * @param shape The user model shape.
  123. * @param opt The opt record to add the properties to.
  124. * @return The number of options added.
  125. */
  126. protected int addStandardOptions( HSSFShape shape, EscherOptRecord opt )
  127. {
  128. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x080000 ) );
  129. // opt.addEscherProperty( new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x080008 ) );
  130. if ( shape.isNoFill() )
  131. {
  132. // Wonderful... none of the spec's give any clue as to what these constants mean.
  133. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.FILL__NOFILLHITTEST, 0x00110000 ) );
  134. }
  135. else
  136. {
  137. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.FILL__NOFILLHITTEST, 0x00010000 ) );
  138. }
  139. opt.addEscherProperty( new EscherRGBProperty( EscherProperties.FILL__FILLCOLOR, shape.getFillColor() ) );
  140. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.GROUPSHAPE__PRINT, 0x080000 ) );
  141. opt.addEscherProperty( new EscherRGBProperty( EscherProperties.LINESTYLE__COLOR, shape.getLineStyleColor() ) );
  142. int options = 5;
  143. if (shape.getLineWidth() != HSSFShape.LINEWIDTH_DEFAULT)
  144. {
  145. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.LINESTYLE__LINEWIDTH, shape.getLineWidth()));
  146. options++;
  147. }
  148. if (shape.getLineStyle() != HSSFShape.LINESTYLE_SOLID)
  149. {
  150. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.LINESTYLE__LINEDASHING, shape.getLineStyle()));
  151. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.LINESTYLE__LINEENDCAPSTYLE, 0));
  152. if (shape.getLineStyle() == HSSFShape.LINESTYLE_NONE)
  153. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080000));
  154. else
  155. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
  156. options += 3;
  157. }
  158. opt.sortProperties();
  159. return options; // # options added
  160. }
  161. }