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
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 ==================================================================== */
17 package org
.apache
.poi
.hssf
.usermodel
;
19 import org
.apache
.poi
.hssf
.record
.EscherAggregate
;
20 import org
.apache
.poi
.hssf
.record
.NoteRecord
;
21 import org
.apache
.poi
.hssf
.record
.TextObjectRecord
;
22 import org
.apache
.poi
.ddf
.*;
25 import java
.util
.List
;
26 import java
.util
.Iterator
;
29 * Represents a cell comment - a sticky note associated with a cell.
31 * @author Yegor Kozlov
33 public class HSSFComment
extends HSSFTextbox
{
35 private boolean visible
;
36 private short col
, row
;
37 private String author
;
39 private NoteRecord note
= null;
40 private TextObjectRecord txo
= null;
43 * Construct a new comment with the given parent and anchor.
46 * @param anchor defines position of this anchor in the sheet
48 public HSSFComment( HSSFShape parent
, HSSFAnchor anchor
)
50 super( parent
, anchor
);
51 setShapeType(OBJECT_TYPE_COMMENT
);
53 //default color for comments
54 fillColor
= 0x08000050;
56 //by default comments are hidden
62 protected HSSFComment( NoteRecord note
, TextObjectRecord txo
)
64 this( (HSSFShape
)null, (HSSFAnchor
)null );
70 * Returns whether this comment is visible.
72 * @param visible <code>true</code> if the comment is visible, <code>false</code> otherwise
74 public void setVisible(boolean visible
){
75 if(note
!= null) note
.setFlags(visible ? NoteRecord
.NOTE_VISIBLE
: NoteRecord
.NOTE_HIDDEN
);
76 this.visible
= visible
;
80 * Sets whether this comment is visible.
82 * @return <code>true</code> if the comment is visible, <code>false</code> otherwise
84 public boolean isVisible(){
89 * Return the row of the cell that contains the comment
91 * @return the 0-based row of the cell that contains the comment
98 * Set the row of the cell that contains the comment
100 * @param row the 0-based row of the cell that contains the comment
102 public void setRow(int row
){
103 if(note
!= null) note
.setRow((short)row
);
104 this.row
= (short)row
;
108 * Return the column of the cell that contains the comment
110 * @return the 0-based column of the cell that contains the comment
112 public short getColumn(){
117 * Set the column of the cell that contains the comment
119 * @param col the 0-based column of the cell that contains the comment
121 public void setColumn(short col
){
122 if(note
!= null) note
.setColumn(col
);
127 * Name of the original comment author
129 * @return the name of the original author of the comment
131 public String
getAuthor(){
136 * Name of the original comment author
138 * @param author the name of the original author of the comment
140 public void setAuthor(String author
){
141 if(note
!= null) note
.setAuthor(author
);
142 this.author
= author
;
146 * Sets the rich text string used by this comment.
148 * @param string Sets the rich text string used by this object.
150 public void setString( HSSFRichTextString string
) {
151 //if font is not set we must set the default one
152 if (string
.numFormattingRuns() == 0) string
.applyFont((short)0);
155 int frLength
= ( string
.numFormattingRuns() + 1 ) * 8;
156 txo
.setFormattingRunLength( (short) frLength
);
157 txo
.setTextLength( (short) string
.length() );
158 txo
.setStr( string
);
160 super.setString(string
);