PageRenderTime 126ms CodeModel.GetById 11ms RepoModel.GetById 3ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 156 lines | 68 code | 15 blank | 73 comment | 5 complexity | c684c958961cd9be6740a30893ceb9a4 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.hssf.record.*;
  39. import loci.poi.hssf.usermodel.HSSFComment;
  40. import loci.poi.hssf.usermodel.HSSFShape;
  41. import loci.poi.util.LittleEndian;
  42. import loci.poi.ddf.*;
  43. import java.util.List;
  44. import java.util.Iterator;
  45. /**
  46. * Represents a cell comment.
  47. * This class converts highlevel model data from <code>HSSFComment</code>
  48. * to low-level records.
  49. *
  50. * @author Yegor Kozlov
  51. */
  52. public class CommentShape extends TextboxShape {
  53. private NoteRecord note;
  54. /**
  55. * Creates the low-level records for a comment.
  56. *
  57. * @param hssfShape The highlevel shape.
  58. * @param shapeId The shape id to use for this shape.
  59. */
  60. public CommentShape( HSSFComment hssfShape, int shapeId )
  61. {
  62. super(hssfShape, shapeId);
  63. note = createNoteRecord(hssfShape, shapeId);
  64. ObjRecord obj = getObjRecord();
  65. List records = obj.getSubRecords();
  66. int cmoIdx = 0;
  67. for (int i = 0; i < records.size(); i++) {
  68. Object r = records.get(i);
  69. if (r instanceof CommonObjectDataSubRecord){
  70. //modify autofill attribute inherited from <code>TextObjectRecord</code>
  71. CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord)r;
  72. cmo.setAutofill(false);
  73. cmoIdx = i;
  74. }
  75. }
  76. //add NoteStructure sub record
  77. //we don't know it's format, for now the record data is empty
  78. NoteStructureSubRecord u = new NoteStructureSubRecord();
  79. obj.addSubRecord(cmoIdx+1, u);
  80. }
  81. /**
  82. * Creates the low level <code>NoteRecord</code>
  83. * which holds the comment attributes.
  84. */
  85. private NoteRecord createNoteRecord( HSSFComment shape, int shapeId )
  86. {
  87. NoteRecord note = new NoteRecord();
  88. note.setColumn(shape.getColumn());
  89. note.setRow((short)shape.getRow());
  90. note.setFlags(shape.isVisible() ? NoteRecord.NOTE_VISIBLE : NoteRecord.NOTE_HIDDEN);
  91. note.setShapeId((short)shapeId);
  92. note.setAuthor(shape.getAuthor() == null ? "" : shape.getAuthor());
  93. return note;
  94. }
  95. /**
  96. * Sets standard escher options for a comment.
  97. * This method is responsible for setting default background,
  98. * shading and other comment properties.
  99. *
  100. * @param shape The highlevel shape.
  101. * @param opt The escher records holding the proerties
  102. * @return number of escher options added
  103. */
  104. protected int addStandardOptions( HSSFShape shape, EscherOptRecord opt )
  105. {
  106. super.addStandardOptions(shape, opt);
  107. //remove unnecessary properties inherited from TextboxShape
  108. java.util.List props = opt.getEscherProperties();
  109. for ( Iterator iterator = props.iterator(); iterator.hasNext(); ) {
  110. EscherProperty prop = (EscherProperty) iterator.next();
  111. switch (prop.getId()){
  112. case EscherProperties.TEXT__TEXTLEFT:
  113. case EscherProperties.TEXT__TEXTRIGHT:
  114. case EscherProperties.TEXT__TEXTTOP:
  115. case EscherProperties.TEXT__TEXTBOTTOM:
  116. case EscherProperties.GROUPSHAPE__PRINT:
  117. case EscherProperties.FILL__FILLBACKCOLOR:
  118. case EscherProperties.LINESTYLE__COLOR:
  119. iterator.remove();
  120. break;
  121. }
  122. }
  123. HSSFComment comment = (HSSFComment)shape;
  124. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.GROUPSHAPE__PRINT, comment.isVisible() ? 0x000A0000 : 0x000A0002) );
  125. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x00030003 ) );
  126. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.SHADOWSTYLE__COLOR, 0x00000000 ) );
  127. opt.sortProperties();
  128. return opt.getEscherProperties().size(); // # options added
  129. }
  130. /**
  131. * Return the <code>NoteRecord</code> holding the comment attributes
  132. *
  133. * @return <code>NoteRecord</code> holding the comment attributes
  134. */
  135. public NoteRecord getNoteRecord()
  136. {
  137. return note;
  138. }
  139. }