PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 150 lines | 79 code | 18 blank | 53 comment | 5 complexity | de60a19c840cc93a41315152fddc45e8 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.record.EscherAggregate;
  41. import loci.poi.hssf.record.CommonObjectDataSubRecord;
  42. import loci.poi.hssf.record.EndSubRecord;
  43. import loci.poi.hssf.usermodel.HSSFSimpleShape;
  44. import loci.poi.hssf.usermodel.HSSFShape;
  45. public class SimpleFilledShape
  46. extends AbstractShape
  47. {
  48. private EscherContainerRecord spContainer;
  49. private ObjRecord objRecord;
  50. /**
  51. * Creates the low evel records for an oval.
  52. *
  53. * @param hssfShape The highlevel shape.
  54. * @param shapeId The shape id to use for this shape.
  55. */
  56. SimpleFilledShape( HSSFSimpleShape hssfShape, int shapeId )
  57. {
  58. spContainer = createSpContainer( hssfShape, shapeId );
  59. objRecord = createObjRecord( hssfShape, shapeId );
  60. }
  61. /**
  62. * Generates the shape records for this shape.
  63. *
  64. * @param hssfShape
  65. * @param shapeId
  66. */
  67. private EscherContainerRecord createSpContainer( HSSFSimpleShape hssfShape, int shapeId )
  68. {
  69. HSSFShape shape = hssfShape;
  70. EscherContainerRecord spContainer = new EscherContainerRecord();
  71. EscherSpRecord sp = new EscherSpRecord();
  72. EscherOptRecord opt = new EscherOptRecord();
  73. EscherClientDataRecord clientData = new EscherClientDataRecord();
  74. spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
  75. spContainer.setOptions( (short) 0x000F );
  76. sp.setRecordId( EscherSpRecord.RECORD_ID );
  77. short shapeType = objTypeToShapeType( hssfShape.getShapeType() );
  78. sp.setOptions( (short) ( ( shapeType << 4 ) | 0x2 ) );
  79. sp.setShapeId( shapeId );
  80. sp.setFlags( EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE );
  81. opt.setRecordId( EscherOptRecord.RECORD_ID );
  82. addStandardOptions(shape, opt);
  83. EscherRecord anchor = createAnchor( shape.getAnchor() );
  84. clientData.setRecordId( EscherClientDataRecord.RECORD_ID );
  85. clientData.setOptions( (short) 0x0000 );
  86. spContainer.addChildRecord( sp );
  87. spContainer.addChildRecord( opt );
  88. spContainer.addChildRecord( anchor );
  89. spContainer.addChildRecord( clientData );
  90. return spContainer;
  91. }
  92. private short objTypeToShapeType( int objType )
  93. {
  94. short shapeType;
  95. if (objType == HSSFSimpleShape.OBJECT_TYPE_OVAL)
  96. shapeType = EscherAggregate.ST_ELLIPSE;
  97. else if (objType == HSSFSimpleShape.OBJECT_TYPE_RECTANGLE)
  98. shapeType = EscherAggregate.ST_RECTANGLE;
  99. else
  100. throw new IllegalArgumentException("Unable to handle an object of this type");
  101. return shapeType;
  102. }
  103. /**
  104. * Creates the low level OBJ record for this shape.
  105. */
  106. private ObjRecord createObjRecord( HSSFShape hssfShape, int shapeId )
  107. {
  108. HSSFShape shape = hssfShape;
  109. ObjRecord obj = new ObjRecord();
  110. CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
  111. c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() );
  112. c.setObjectId( (short) ( shapeId ) );
  113. c.setLocked( true );
  114. c.setPrintable( true );
  115. c.setAutofill( true );
  116. c.setAutoline( true );
  117. EndSubRecord e = new EndSubRecord();
  118. obj.addSubRecord( c );
  119. obj.addSubRecord( e );
  120. return obj;
  121. }
  122. public EscherContainerRecord getSpContainer()
  123. {
  124. return spContainer;
  125. }
  126. public ObjRecord getObjRecord()
  127. {
  128. return objRecord;
  129. }
  130. }