001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017: package org.apache.poi.hssf.usermodel;
018:
019: import org.apache.poi.hssf.record.EscherAggregate;
020: import org.apache.poi.hssf.record.NoteRecord;
021: import org.apache.poi.hssf.record.TextObjectRecord;
022: import org.apache.poi.ddf.*;
023:
024: import java.util.Map;
025: import java.util.List;
026: import java.util.Iterator;
027:
028: /**
029: * Represents a cell comment - a sticky note associated with a cell.
030: *
031: * @author Yegor Kozlov
032: */
033: public class HSSFComment extends HSSFTextbox {
034:
035: private boolean visible;
036: private short col, row;
037: private String author;
038:
039: private NoteRecord note = null;
040: private TextObjectRecord txo = null;
041:
042: /**
043: * Construct a new comment with the given parent and anchor.
044: *
045: * @param parent
046: * @param anchor defines position of this anchor in the sheet
047: */
048: public HSSFComment(HSSFShape parent, HSSFAnchor anchor) {
049: super (parent, anchor);
050: setShapeType(OBJECT_TYPE_COMMENT);
051:
052: //default color for comments
053: fillColor = 0x08000050;
054:
055: //by default comments are hidden
056: visible = false;
057:
058: author = "";
059: }
060:
061: protected HSSFComment(NoteRecord note, TextObjectRecord txo) {
062: this ((HSSFShape) null, (HSSFAnchor) null);
063: this .txo = txo;
064: this .note = note;
065: }
066:
067: /**
068: * Returns whether this comment is visible.
069: *
070: * @param visible <code>true</code> if the comment is visible, <code>false</code> otherwise
071: */
072: public void setVisible(boolean visible) {
073: if (note != null)
074: note.setFlags(visible ? NoteRecord.NOTE_VISIBLE
075: : NoteRecord.NOTE_HIDDEN);
076: this .visible = visible;
077: }
078:
079: /**
080: * Sets whether this comment is visible.
081: *
082: * @return <code>true</code> if the comment is visible, <code>false</code> otherwise
083: */
084: public boolean isVisible() {
085: return this .visible;
086: }
087:
088: /**
089: * Return the row of the cell that contains the comment
090: *
091: * @return the 0-based row of the cell that contains the comment
092: */
093: public int getRow() {
094: return row;
095: }
096:
097: /**
098: * Set the row of the cell that contains the comment
099: *
100: * @param row the 0-based row of the cell that contains the comment
101: */
102: public void setRow(int row) {
103: if (note != null)
104: note.setRow((short) row);
105: this .row = (short) row;
106: }
107:
108: /**
109: * Return the column of the cell that contains the comment
110: *
111: * @return the 0-based column of the cell that contains the comment
112: */
113: public short getColumn() {
114: return col;
115: }
116:
117: /**
118: * Set the column of the cell that contains the comment
119: *
120: * @param col the 0-based column of the cell that contains the comment
121: */
122: public void setColumn(short col) {
123: if (note != null)
124: note.setColumn(col);
125: this .col = col;
126: }
127:
128: /**
129: * Name of the original comment author
130: *
131: * @return the name of the original author of the comment
132: */
133: public String getAuthor() {
134: return author;
135: }
136:
137: /**
138: * Name of the original comment author
139: *
140: * @param author the name of the original author of the comment
141: */
142: public void setAuthor(String author) {
143: if (note != null)
144: note.setAuthor(author);
145: this .author = author;
146: }
147:
148: /**
149: * Sets the rich text string used by this comment.
150: *
151: * @param string Sets the rich text string used by this object.
152: */
153: public void setString(HSSFRichTextString string) {
154: //if font is not set we must set the default one
155: if (string.numFormattingRuns() == 0)
156: string.applyFont((short) 0);
157:
158: if (txo != null) {
159: int frLength = (string.numFormattingRuns() + 1) * 8;
160: txo.setFormattingRunLength((short) frLength);
161: txo.setTextLength((short) string.length());
162: txo.setStr(string);
163: }
164: super.setString(string);
165: }
166: }
|