package org.apache.poi.hssf.usermodel;
import org.apache.poi.ddf.DefaultEscherRecordFactory;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
import org.apache.poi.hssf.record.EndSubRecord;
import org.apache.poi.hssf.record.NoteRecord;
import org.apache.poi.hssf.record.NoteStructureSubRecord;
import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.hssf.record.TextObjectRecord;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.util.CellAddress;
public class extends HSSFTextbox implements Comment {
private final static int = 0;
private final static int = 3;
private final static int = 655362;
private final static int = 0x1000002;
private final static int = 0xFEFFFFFD;
private final NoteRecord ;
public (EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord, NoteRecord note) {
super(spContainer, objRecord, textObjectRecord);
_note = note;
}
public (HSSFShape parent, HSSFAnchor anchor) {
this(parent, anchor, createNoteRecord());
}
private (HSSFShape parent, HSSFAnchor anchor, NoteRecord note) {
super(parent, anchor);
_note = note;
setFillColor(0x08000050);
setVisible(false);
setAuthor("");
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0);
cod.setObjectType(CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT);
}
protected (NoteRecord note, TextObjectRecord txo) {
this(null, new HSSFClientAnchor(), note);
}
@Override
void (HSSFPatriarch patriarch) {
super.afterInsert(patriarch);
patriarch.getBoundAggregate().addTailRecord(getNoteRecord());
}
@Override
protected EscherContainerRecord () {
EscherContainerRecord spContainer = super.createSpContainer();
EscherOptRecord opt = spContainer.getChildById(EscherOptRecord.RECORD_ID);
opt.removeEscherProperty(EscherProperties.TEXT__TEXTLEFT);
opt.removeEscherProperty(EscherProperties.TEXT__TEXTRIGHT);
opt.removeEscherProperty(EscherProperties.TEXT__TEXTTOP);
opt.removeEscherProperty(EscherProperties.TEXT__TEXTBOTTOM);
opt.setEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, false, false, GROUP_SHAPE_PROPERTY_DEFAULT_VALUE));
return spContainer;
}
@Override
protected ObjRecord () {
ObjRecord obj = new ObjRecord();
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
c.setObjectType(OBJECT_TYPE_COMMENT);
c.setLocked(true);
c.setPrintable(true);
c.setAutofill(false);
c.setAutoline(true);
NoteStructureSubRecord u = new NoteStructureSubRecord();
EndSubRecord e = new EndSubRecord();
obj.addSubRecord(c);
obj.addSubRecord(u);
obj.addSubRecord(e);
return obj;
}
private static NoteRecord () {
NoteRecord note = new NoteRecord();
note.setFlags(NoteRecord.NOTE_HIDDEN);
note.setAuthor("");
return note;
}
@Override
void (int shapeId) {
if(shapeId > 65535) {
throw new IllegalArgumentException("Cannot add more than " + 65535 + " shapes");
}
super.setShapeId(shapeId);
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0);
cod.setObjectId(shapeId);
_note.setShapeId(shapeId);
}
@Override
public void (boolean visible) {
_note.setFlags(visible ? NoteRecord.NOTE_VISIBLE : NoteRecord.NOTE_HIDDEN);
setHidden(!visible);
}
@Override
public boolean () {
return _note.getFlags() == NoteRecord.NOTE_VISIBLE;
}
@Override
public CellAddress () {
return new CellAddress(getRow(), getColumn());
}
@Override
public void (CellAddress address) {
setRow(address.getRow());
setColumn(address.getColumn());
}
@Override
public void (int row, int col) {
setRow(row);
setColumn(col);
}
@Override
public int () {
return _note.getRow();
}
@Override
public void (int row) {
_note.setRow(row);
}
@Override
public int getColumn() {
return _note.getColumn();
}
@Override
public void setColumn(int col) {
_note.setColumn(col);
}
@Override
public String () {
return _note.getAuthor();
}
@Override
public void (String author) {
if (_note != null) _note.setAuthor(author);
}
protected NoteRecord () {
return _note;
}
public boolean () {
if (_note == null) return false;
if (getColumn() < 0 || getRow() < 0) return false;
return true;
}
@Override
public ClientAnchor () {
HSSFAnchor ha = super.getAnchor();
if (ha instanceof ClientAnchor) {
return (ClientAnchor) ha;
}
throw new IllegalStateException("Anchor can not be changed in "
+ ClientAnchor.class.getSimpleName());
}
@Override
public void (int shapeType) {
throw new IllegalStateException("Shape type can not be changed in "+this.getClass().getSimpleName());
}
@Override
public void (HSSFPatriarch patriarch){
super.afterRemove(patriarch);
patriarch.getBoundAggregate().removeTailRecord(getNoteRecord());
}
@Override
protected HSSFShape () {
TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
EscherContainerRecord spContainer = new EscherContainerRecord();
byte [] inSp = getEscherContainer().serialize();
spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());
ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise();
NoteRecord note = (NoteRecord) getNoteRecord().cloneViaReserialise();
return new HSSFComment(spContainer, obj, txo, note);
}
public void (int pictureIndex){
setPropertyValue(new EscherSimpleProperty( EscherProperties.FILL__PATTERNTEXTURE, false, true, pictureIndex));
setPropertyValue(new EscherSimpleProperty( EscherProperties.FILL__FILLTYPE, false, false, FILL_TYPE_PICTURE));
EscherBSERecord bse = getPatriarch().getSheet().getWorkbook().getWorkbook().getBSERecord(pictureIndex);
bse.setRef(bse.getRef() + 1);
}
public void (){
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.FILL__PATTERNTEXTURE);
if (null != property){
EscherBSERecord bse = getPatriarch().getSheet().getWorkbook().getWorkbook().getBSERecord(property.getPropertyValue());
bse.setRef(bse.getRef() - 1);
getOptRecord().removeEscherProperty(EscherProperties.FILL__PATTERNTEXTURE);
}
setPropertyValue(new EscherSimpleProperty( EscherProperties.FILL__FILLTYPE, false, false, FILL_TYPE_SOLID));
}
public int (){
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.FILL__PATTERNTEXTURE);
return property == null ? 0 : property.getPropertyValue();
}
private void (boolean value){
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.GROUPSHAPE__PRINT);
if (value){
setPropertyValue(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, false, false, property.getPropertyValue() | GROUP_SHAPE_HIDDEN_MASK));
} else {
setPropertyValue(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, false, false, property.getPropertyValue() & GROUP_SHAPE_NOT_HIDDEN_MASK));
}
}
@Override
public boolean (Object obj) {
if (!(obj instanceof HSSFComment)) {
return false;
}
HSSFComment other = (HSSFComment) obj;
return getNoteRecord().equals(other.getNoteRecord());
}
@Override
public int () {
return ((getRow()*17) + getColumn())*31;
}
}