PageRenderTime 34ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 146 lines | 71 code | 19 blank | 56 comment | 2 complexity | e8926e1642d96e5be85459525b4970cd 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.*;
  40. import loci.poi.hssf.usermodel.*;
  41. /**
  42. * Represents a line shape and creates all the line specific low level records.
  43. *
  44. * @author Glen Stampoultzis (glens at apache.org)
  45. */
  46. public class LineShape
  47. extends AbstractShape
  48. {
  49. private EscherContainerRecord spContainer;
  50. private ObjRecord objRecord;
  51. /**
  52. * Creates the line shape from the highlevel user shape. All low level
  53. * records are created at this point.
  54. *
  55. * @param hssfShape The user model shape.
  56. * @param shapeId The identifier to use for this shape.
  57. */
  58. LineShape( HSSFSimpleShape hssfShape, int shapeId )
  59. {
  60. spContainer = createSpContainer(hssfShape, shapeId);
  61. objRecord = createObjRecord(hssfShape, shapeId);
  62. }
  63. /**
  64. * Creates the lowerlevel escher records for this shape.
  65. */
  66. private EscherContainerRecord createSpContainer(HSSFSimpleShape hssfShape, int shapeId)
  67. {
  68. HSSFShape shape = hssfShape;
  69. EscherContainerRecord spContainer = new EscherContainerRecord();
  70. EscherSpRecord sp = new EscherSpRecord();
  71. EscherOptRecord opt = new EscherOptRecord();
  72. EscherRecord anchor = new EscherClientAnchorRecord();
  73. EscherClientDataRecord clientData = new EscherClientDataRecord();
  74. spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
  75. spContainer.setOptions( (short) 0x000F );
  76. sp.setRecordId( EscherSpRecord.RECORD_ID );
  77. sp.setOptions( (short) ( (EscherAggregate.ST_LINE << 4) | 0x2 ) );
  78. sp.setShapeId( shapeId );
  79. sp.setFlags( EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE );
  80. opt.setRecordId( EscherOptRecord.RECORD_ID );
  81. opt.addEscherProperty( new EscherShapePathProperty( EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX ) );
  82. opt.addEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 1048592 ) );
  83. addStandardOptions(shape, opt);
  84. HSSFAnchor userAnchor = shape.getAnchor();
  85. if (userAnchor.isHorizontallyFlipped())
  86. sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
  87. if (userAnchor.isVerticallyFlipped())
  88. sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT);
  89. anchor = createAnchor(userAnchor);
  90. clientData.setRecordId( EscherClientDataRecord.RECORD_ID );
  91. clientData.setOptions( (short) 0x0000 );
  92. spContainer.addChildRecord(sp);
  93. spContainer.addChildRecord(opt);
  94. spContainer.addChildRecord(anchor);
  95. spContainer.addChildRecord(clientData);
  96. return spContainer;
  97. }
  98. /**
  99. * Creates the low level OBJ record for this shape.
  100. */
  101. private ObjRecord createObjRecord(HSSFShape hssfShape, int shapeId)
  102. {
  103. HSSFShape shape = hssfShape;
  104. ObjRecord obj = new ObjRecord();
  105. CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
  106. c.setObjectType((short) ((HSSFSimpleShape)shape).getShapeType());
  107. c.setObjectId((short) ( shapeId ));
  108. c.setLocked(true);
  109. c.setPrintable(true);
  110. c.setAutofill(true);
  111. c.setAutoline(true);
  112. EndSubRecord e = new EndSubRecord();
  113. obj.addSubRecord(c);
  114. obj.addSubRecord(e);
  115. return obj;
  116. }
  117. public EscherContainerRecord getSpContainer()
  118. {
  119. return spContainer;
  120. }
  121. public ObjRecord getObjRecord()
  122. {
  123. return objRecord;
  124. }
  125. }