📄 comment.java
字号:
/*********************************************************************
*
* Copyright (C) 2002 Andrew Khan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
package jxl.biff.drawing;
import java.io.IOException;
import java.io.FileInputStream;
import common.Assert;
import common.Logger;
import jxl.WorkbookSettings;
import jxl.biff.ByteData;
import jxl.biff.IntegerHelper;
import jxl.biff.StringHelper;
import jxl.biff.IndexMapping;
import jxl.biff.Type;
import jxl.biff.ContinueRecord;
import jxl.write.biff.File;
/**
* Contains the various biff records used to insert a cell note into a
* worksheet
*/
public class Comment implements DrawingGroupObject
{
/**
* The logger
*/
private static Logger logger = Logger.getLogger(Comment.class);
/**
* The spContainer that was read in
*/
private EscherContainer readSpContainer;
/**
* The spContainer that was generated
*/
private EscherContainer spContainer;
/**
* The MsoDrawingRecord associated with the drawing
*/
private MsoDrawingRecord msoDrawingRecord;
/**
* The ObjRecord associated with the drawing
*/
private ObjRecord objRecord;
/**
* Initialized flag
*/
private boolean initialized = false;
/**
* The object id, assigned by the drawing group
*/
private int objectId;
/**
* The blip id
*/
private int blipId;
/**
* The shape id
*/
private int shapeId;
/**
* The column
*/
private int column;
/**
* The row position of the image
*/
private int row;
/**
* The width of the image in cells
*/
private double width;
/**
* The height of the image in cells
*/
private double height;
/**
* The number of places this drawing is referenced
*/
private int referenceCount;
/**
* The top level escher container
*/
private EscherContainer escherData;
/**
* Where this image came from (read, written or a copy)
*/
private Origin origin;
/**
* The drawing group for all the images
*/
private DrawingGroup drawingGroup;
/**
* The drawing data
*/
private DrawingData drawingData;
/**
* The type of this drawing object
*/
private ShapeType type;
/**
* The drawing position on the sheet
*/
private int drawingNumber;
/**
* An mso drawing record, which sometimes appears
*/
private MsoDrawingRecord mso;
/**
* The text object record
*/
private TextObjectRecord txo;
/**
* The note record
*/
private NoteRecord note;
/**
* Text data from the first continue record
*/
private ContinueRecord text;
/**
* Formatting data from the second continue record
*/
private ContinueRecord formatting;
/**
* The comment text
*/
private String commentText;
/**
* The workbook settings
*/
private WorkbookSettings workbookSettings;
/**
* Constructor used when reading images
*
* @param mso the drawing record
* @param obj the object record
* @param dd the drawing data for all drawings on this sheet
* @param dg the drawing group
* @param ws the workbook settings
*/
public Comment(MsoDrawingRecord mso, ObjRecord obj, DrawingData dd,
DrawingGroup dg, WorkbookSettings ws)
{
drawingGroup = dg;
msoDrawingRecord = mso;
drawingData = dd;
objRecord = obj;
initialized = false;
workbookSettings = ws;
origin = Origin.READ;
drawingData.addData(msoDrawingRecord.getData());
drawingNumber = drawingData.getNumDrawings() - 1;
drawingGroup.addDrawing(this);
Assert.verify(mso != null && obj != null);
initialize();
}
/**
* Copy constructor used to copy drawings from read to write
*
* @param d the drawing to copy
*/
/*protected*/ public Comment(DrawingGroupObject dgo,
DrawingGroup dg,
WorkbookSettings ws)
{
Comment d = (Comment) dgo;
Assert.verify(d.origin == Origin.READ);
msoDrawingRecord = d.msoDrawingRecord;
objRecord = d.objRecord;
initialized = false;
origin = Origin.READ;
drawingData = d.drawingData;
drawingGroup = dg;
drawingNumber = d.drawingNumber;
drawingGroup.addDrawing(this);
mso = d.mso;
txo = d.txo;
text = d.text;
formatting = d.formatting;
note = d.note;
workbookSettings = ws;
}
/**
* Constructor invoked when writing the images
*
* @param text the comment text
* @param c the column
* @param r the row
* @param width the width in cells
* @param height the height in cells
*/
public Comment(String text, int c, int r)
{
initialized = true;
origin = Origin.WRITE;
column = c;
row = r;
this.width = width;
this.height = height;
referenceCount = 1;
type = ShapeType.TEXT_BOX;
commentText = text;
}
/**
* Initializes the member variables from the Escher stream data
*/
private void initialize()
{
readSpContainer = drawingData.getSpContainer(drawingNumber);
Assert.verify(readSpContainer != null);
EscherRecord[] children = readSpContainer.getChildren();
Sp sp = (Sp) readSpContainer.getChildren()[0];
objectId = objRecord.getObjectId();
shapeId = sp.getShapeId();
type = ShapeType.getType(sp.getShapeType());
if (type == ShapeType.UNKNOWN)
{
logger.warn("Unknown shape type");
}
Opt opt = (Opt) readSpContainer.getChildren()[1];
ClientAnchor clientAnchor = null;
for (int i = 0 ; i < children.length && clientAnchor == null ; i++)
{
if (children[i].getType() == EscherRecordType.CLIENT_ANCHOR)
{
clientAnchor = (ClientAnchor) children[i];
}
}
if (clientAnchor == null)
{
logger.warn("client anchor not found");
}
else
{
column = (int) clientAnchor.getX1() - 1;
row = (int) clientAnchor.getY1() + 1;
}
initialized = true;
}
/**
* Sets the object id. Invoked by the drawing group when the object is
* added to id
*
* @param objid the object id
* @param bip the blip id
* @param sid the shape id
*/
public final void setObjectId(int objid, int bip, int sid)
{
objectId = objid;
blipId = bip;
shapeId = sid;
if (origin == Origin.READ)
{
origin = Origin.READ_WRITE;
}
}
/**
* Accessor for the object id
*
* @return the object id
*/
public final int getObjectId()
{
if (!initialized)
{
initialize();
}
return objectId;
}
/**
* Accessor for the shape id
*
* @return the object id
*/
public final int getShapeId()
{
if (!initialized)
{
initialize();
}
return shapeId;
}
/**
* Accessor for the blip id
*
* @return the blip id
*/
public final int getBlipId()
{
if (!initialized)
{
initialize();
}
return blipId;
}
/**
* Gets the drawing record which was read in
*
* @return the drawing record
*/
public MsoDrawingRecord getMsoDrawingRecord()
{
return msoDrawingRecord;
}
/**
* Creates the main Sp container for the drawing
*
* @return the SP container
*/
public EscherContainer getSpContainer()
{
if (!initialized)
{
initialize();
}
if (origin == Origin.READ)
{
return getReadSpContainer();
}
if (spContainer == null)
{
spContainer = new SpContainer();
Sp sp = new Sp(type, shapeId, 2560);
spContainer.add(sp);
Opt opt = new Opt();
opt.addProperty(344, false, false, 0); // ?
opt.addProperty(385, false, false, 134217808); // fill colour
opt.addProperty(387, false, false, 134217808); // background colour
opt.addProperty(959, false, false, 131074); // hide
spContainer.add(opt);
ClientAnchor clientAnchor = new ClientAnchor(column + 1.3,
Math.max(0, row - 0.6),
column+3, row + 4);
spContainer.add(clientAnchor);
ClientData clientData = new ClientData();
spContainer.add(clientData);
ClientTextBox clientTextBox = new ClientTextBox();
spContainer.add(clientTextBox);
}
return spContainer;
}
/**
* Sets the drawing group for this drawing. Called by the drawing group
* when this drawing is added to it
*
* @param dg the drawing group
*/
public void setDrawingGroup(DrawingGroup dg)
{
drawingGroup = dg;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -