sortProperties();
}
+ public void removeEscherProperty(int num){
+ for ( Iterator<EscherProperty> iterator = getEscherProperties().iterator(); iterator.hasNext(); ) {
+ EscherProperty prop = iterator.next();
+ if (prop.getPropertyNumber() == num){
+ iterator.remove();
+ }
+ }
+ }
+
/**
* Retrieve the string representation of this record.
*/
public String toXml(String tab){
StringBuilder builder = new StringBuilder();
builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
- .append("\" name=\"").append(getName()).append("\" blipId=\"")
+ .append("\" name=\"").append(getName()).append("\" simpleValue=\"").append(getPropertyValue()).append("\" blipId=\"")
.append(isBlipId()).append("\" value=\"").append(isTrue()).append("\"").append("/>\n");
return builder.toString();
}
import org.apache.poi.ddf.*;
import org.apache.poi.hssf.record.*;
import org.apache.poi.ss.usermodel.Comment;
-import org.apache.poi.ss.usermodel.RichTextString;
/**
* Represents a cell comment - a sticky note associated with a cell.
*/
public class HSSFComment extends HSSFTextbox implements Comment {
+ private final static int FILL_TYPE_SOLID = 0;
+ private final static int FILL_TYPE_PICTURE = 3;
+
/*
* TODO - make HSSFComment more consistent when created vs read from file.
* Currently HSSFComment has two main forms (corresponding to the two constructors). There
protected EscherContainerRecord createSpContainer() {
EscherContainerRecord spContainer = super.createSpContainer();
EscherOptRecord opt = spContainer.getChildById(EscherOptRecord.RECORD_ID);
- removeEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT);
- removeEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT);
- removeEscherProperty(opt, EscherProperties.TEXT__TEXTTOP);
- removeEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);
+ 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, 655362));
return spContainer;
}
}
@Override
- public HSSFShape cloneShape() {
+ protected HSSFShape cloneShape() {
TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
EscherContainerRecord spContainer = new EscherContainerRecord();
byte [] inSp = getEscherContainer().serialize();
NoteRecord note = (NoteRecord) getNoteRecord().cloneViaReserialise();
return new HSSFComment(spContainer, obj, txo, note);
}
+
+ public void setBackgroundImage(int pictureIndex){
+ setPropertyValue(new EscherSimpleProperty( EscherProperties.FILL__PATTERNTEXTURE, false, true, pictureIndex));
+ setPropertyValue(new EscherSimpleProperty( EscherProperties.FILL__FILLTYPE, false, false, FILL_TYPE_PICTURE));
+ EscherBSERecord bse = _patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(pictureIndex);
+ bse.setRef(bse.getRef() + 1);
+ }
+
+ public void resetBackgroundImage(){
+ EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.FILL__PATTERNTEXTURE);
+ if (null != property){
+ EscherBSERecord bse = _patriarch.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 getBackgroundImageId(){
+ EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.FILL__PATTERNTEXTURE);
+ return property == null ? 0 : property.getPropertyValue();
+ }
}
}
@Override
- public HSSFShape cloneShape() {
+ protected HSSFShape cloneShape() {
EscherContainerRecord spContainer = new EscherContainerRecord();
byte[] inSp = getEscherContainer().serialize();
spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());
protected EscherContainerRecord createSpContainer() {
EscherContainerRecord spContainer = super.createSpContainer();
EscherOptRecord opt = spContainer.getChildById(EscherOptRecord.RECORD_ID);
- removeEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
- removeEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
+ opt.removeEscherProperty(EscherProperties.LINESTYLE__LINEDASHING);
+ opt.removeEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH);
spContainer.removeChildRecord(spContainer.getChildById(EscherTextboxRecord.RECORD_ID));
return spContainer;
}
}
@Override
- public HSSFShape cloneShape() {
+ protected HSSFShape cloneShape() {
EscherContainerRecord spContainer = new EscherContainerRecord();
byte [] inSp = getEscherContainer().serialize();
spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());
protected abstract void afterRemove(HSSFPatriarch patriarch);
- protected void removeEscherProperty(EscherOptRecord opt, int num){
- for ( Iterator<EscherProperty> iterator = opt.getEscherProperties().iterator(); iterator.hasNext(); ) {
- EscherProperty prop = iterator.next();
- if (prop.getPropertyNumber() == num){
- iterator.remove();
- }
- }
- }
-
void setShapeId(int shapeId){
EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
spRecord.setShapeId(shapeId);
abstract void afterInsert(HSSFPatriarch patriarch);
- public EscherContainerRecord getEscherContainer() {
+ protected EscherContainerRecord getEscherContainer() {
return _escherContainer;
}
- public ObjRecord getObjRecord() {
+ protected ObjRecord getObjRecord() {
return _objRecord;
}
- public EscherOptRecord getOptRecord() {
+ protected EscherOptRecord getOptRecord() {
return _optRecord;
}
return 1;
}
- public abstract HSSFShape cloneShape();
+ protected abstract HSSFShape cloneShape();
}
}
@Override
- public HSSFShape cloneShape() {
+ protected HSSFShape cloneShape() {
throw new IllegalStateException("Use method cloneShape(HSSFPatriarch patriarch)");
}
public final static short OBJECT_TYPE_COMMENT = 25;
// public final static short OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 30;
+ public final static int WRAP_SQUARE = 0;
+ public final static int WRAP_BY_POINTS = 1;
+ public final static int WRAP_NONE = 2;
+
private static final Map <Short, Short> objTypeToShapeType = new HashMap<Short, Short>();
private TextObjectRecord _textObjectRecord;
_textObjectRecord = createTextObjRecord();
}
- public TextObjectRecord getTextObjectRecord() {
+ protected TextObjectRecord getTextObjectRecord() {
return _textObjectRecord;
}
protected TextObjectRecord createTextObjRecord(){
TextObjectRecord obj = new TextObjectRecord();
+ obj.setHorizontalTextAlignment(2);
+ obj.setVerticalTextAlignment(2);
obj.setTextLocked(true);
obj.setTextOrientation(TextObjectRecord.TEXT_ORIENTATION_NONE);
obj.setStr(new HSSFRichTextString(""));
}
@Override
- public HSSFShape cloneShape() {
+ protected HSSFShape cloneShape() {
TextObjectRecord txo = null;
EscherContainerRecord spContainer = new EscherContainerRecord();
byte [] inSp = getEscherContainer().serialize();
}
spRecord.setShapeType(objTypeToShapeType.get((short) shapeType));
}
+
+ public int getWrapText(){
+ EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TEXT__WRAPTEXT);
+ return null == property ? WRAP_SQUARE : property.getPropertyValue();
+ }
+
+ public void setWrapText(int value){
+ setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__WRAPTEXT, false, false, value));
+ }
}
}
@Override
- public HSSFShape cloneShape() {
+ protected HSSFShape cloneShape() {
TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
EscherContainerRecord spContainer = new EscherContainerRecord();
byte[] inSp = getEscherContainer().serialize();
}\r
\r
@Override\r
- public HSSFShape cloneShape() {\r
+ protected HSSFShape cloneShape() {\r
return null;\r
}\r
}\r
HSSFSheet sheet = wb.createSheet();\r
\r
HSSFPatriarch drawing = sheet.createDrawingPatriarch();\r
- HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 200, 200, (short) 2, 2, (short) 15, 15);\r
+ HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 50, 50, (short) 2, 2, (short) 4, 4);\r
anchor.setAnchorType(2);\r
assertEquals(anchor.getAnchorType(), 2);\r
\r
assertEquals(10000, rectangle.getLineWidth());\r
rectangle.setLineStyle(10);\r
assertEquals(10, rectangle.getLineStyle());\r
+ assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_SQUARE);\r
rectangle.setLineStyleColor(1111);\r
rectangle.setNoFill(true);\r
+ rectangle.setWrapText(HSSFSimpleShape.WRAP_NONE);\r
rectangle.setString(new HSSFRichTextString("teeeest"));\r
assertEquals(rectangle.getLineStyleColor(), 1111);\r
- assertEquals(((EscherSimpleProperty)((EscherOptRecord)rectangle.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID))\r
+ assertEquals(((EscherSimpleProperty)((EscherOptRecord)HSSFTestHelper.getEscherContainer(rectangle).getChildById(EscherOptRecord.RECORD_ID))\r
.lookup(EscherProperties.TEXT__TEXTID)).getPropertyValue(), "teeeest".hashCode());\r
assertEquals(rectangle.isNoFill(), true);\r
+ assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_NONE);\r
assertEquals(rectangle.getString().getString(), "teeeest");\r
\r
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
assertEquals(rectangle2.getFillColor(), 777);\r
assertEquals(rectangle2.isNoFill(), true);\r
assertEquals(rectangle2.getString().getString(), "teeeest");\r
+ assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_NONE);\r
\r
rectangle2.setFillColor(3333);\r
rectangle2.setLineStyle(9);\r
rectangle2.getAnchor().setDx2(3);\r
rectangle2.getAnchor().setDy1(4);\r
rectangle2.getAnchor().setDy2(5);\r
+ rectangle.setWrapText(HSSFSimpleShape.WRAP_BY_POINTS);\r
rectangle2.setString(new HSSFRichTextString("test22"));\r
\r
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
assertEquals(1, drawing.getChildren().size());\r
rectangle2 = (HSSFSimpleShape) drawing.getChildren().get(0);\r
assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, rectangle2.getShapeType());\r
+ assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_BY_POINTS);\r
assertEquals(77, rectangle2.getLineWidth());\r
assertEquals(9, rectangle2.getLineStyle());\r
assertEquals(rectangle2.getLineStyleColor(), 4444);\r
\r
HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());\r
EscherOptRecord opt1 = HSSFTestHelper.getOptRecord(textbox);\r
- EscherOptRecord opt2 = textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID);\r
+ EscherOptRecord opt2 = HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID);\r
assertSame(opt1, opt2);\r
}\r
\r
String opt1Str = opt.toXml();\r
\r
textbox.setFillColor(textbox.getFillColor());\r
- assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());\r
+ assertEquals(opt1Str, HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID).toXml());\r
textbox.setLineStyle(textbox.getLineStyle());\r
- assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());\r
+ assertEquals(opt1Str, HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID).toXml());\r
textbox.setLineWidth(textbox.getLineWidth());\r
- assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());\r
+ assertEquals(opt1Str, HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID).toXml());\r
textbox.setLineStyleColor(textbox.getLineStyleColor());\r
- assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());\r
+ assertEquals(opt1Str, HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID).toXml());\r
}\r
\r
public void testDgRecordNumShapes(){\r
shape.setString(new HSSFRichTextString("string1"));\r
assertEquals(shape.getString().getString(), "string1");\r
\r
- assertNotNull(shape.getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));\r
+ assertNotNull(HSSFTestHelper.getEscherContainer(shape).getChildById(EscherTextboxRecord.RECORD_ID));\r
assertEquals(agg.getShapeToObjMapping().size(), 2);\r
\r
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
\r
shape = (HSSFSimpleShape) patriarch.getChildren().get(0);\r
\r
- assertNotNull(shape.getTextObjectRecord());\r
+ assertNotNull(HSSFTestHelper.getTextObjRecord(shape));\r
assertEquals(shape.getString().getString(), "string1");\r
- assertNotNull(shape.getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));\r
+ assertNotNull(HSSFTestHelper.getEscherContainer(shape).getChildById(EscherTextboxRecord.RECORD_ID));\r
assertEquals(agg.getShapeToObjMapping().size(), 2);\r
}\r
\r
HSSFTestHelper.setShapeId(combobox, 1024);\r
ComboboxShape comboboxShape = new ComboboxShape(combobox, 1024);\r
\r
- assertTrue(Arrays.equals(comboboxShape.getSpContainer().serialize(), combobox.getEscherContainer().serialize()));\r
- assertTrue(Arrays.equals(comboboxShape.getObjRecord().serialize(), combobox.getObjRecord().serialize()));\r
+ assertTrue(Arrays.equals(comboboxShape.getSpContainer().serialize(), HSSFTestHelper.getEscherContainer(combobox).serialize()));\r
+ assertTrue(Arrays.equals(comboboxShape.getObjRecord().serialize(), HSSFTestHelper.getObjRecord(combobox).serialize()));\r
}\r
\r
public void testRemoveShapes(){\r
\r
HSSFSimpleShape rectangle = (HSSFSimpleShape) drawing.getChildren().get(0);\r
\r
- assertEquals(rectangle.getEscherContainer().getChild(0).getRecordId(), EscherSpRecord.RECORD_ID);\r
- assertEquals(rectangle.getEscherContainer().getChild(1).getRecordId(), EscherOptRecord.RECORD_ID);\r
- assertEquals(rectangle.getEscherContainer().getChild(2).getRecordId(), EscherClientAnchorRecord.RECORD_ID);\r
- assertEquals(rectangle.getEscherContainer().getChild(3).getRecordId(), EscherClientDataRecord.RECORD_ID);\r
+ assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(0).getRecordId(), EscherSpRecord.RECORD_ID);\r
+ assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(1).getRecordId(), EscherOptRecord.RECORD_ID);\r
+ assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(2).getRecordId(), EscherClientAnchorRecord.RECORD_ID);\r
+ assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(3).getRecordId(), EscherClientDataRecord.RECORD_ID);\r
\r
rectangle.setAnchor(new HSSFClientAnchor());\r
\r
- assertEquals(rectangle.getEscherContainer().getChild(0).getRecordId(), EscherSpRecord.RECORD_ID);\r
- assertEquals(rectangle.getEscherContainer().getChild(1).getRecordId(), EscherOptRecord.RECORD_ID);\r
- assertEquals(" " + HexDump.toHex(rectangle.getEscherContainer().getChild(2).getRecordId()) + " ", rectangle.getEscherContainer().getChild(2).getRecordId(), EscherClientAnchorRecord.RECORD_ID);\r
- assertEquals(rectangle.getEscherContainer().getChild(3).getRecordId(), EscherClientDataRecord.RECORD_ID);\r
+ assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(0).getRecordId(), EscherSpRecord.RECORD_ID);\r
+ assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(1).getRecordId(), EscherOptRecord.RECORD_ID);\r
+ assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(2).getRecordId(), EscherClientAnchorRecord.RECORD_ID);\r
+ assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(3).getRecordId(), EscherClientDataRecord.RECORD_ID);\r
}\r
\r
public void testCreateClientAnchorFromContainer(){\r
rectangle.setAnchor(anchor);\r
\r
assertNotNull(anchor.getEscherAnchor());\r
- assertNotNull(rectangle.getEscherContainer());\r
- assertTrue(anchor.getEscherAnchor().equals(rectangle.getEscherContainer().getChildById(EscherClientAnchorRecord.RECORD_ID)));\r
+ assertNotNull(HSSFTestHelper.getEscherContainer(rectangle));\r
+ assertTrue(anchor.getEscherAnchor().equals(HSSFTestHelper.getEscherContainer(rectangle).getChildById(EscherClientAnchorRecord.RECORD_ID)));\r
}\r
\r
public void testClientAnchorFromEscher(){\r
import org.apache.poi.hssf.model.InternalSheet;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.EscherAggregate;
+import org.apache.poi.hssf.record.ObjRecord;
+import org.apache.poi.hssf.record.TextObjectRecord;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public static void setShapeId(HSSFShape shape, int id){
shape.setShapeId(id);
}
+
+ public static EscherContainerRecord getEscherContainer(HSSFShape shape){
+ return shape.getEscherContainer();
+ }
+
+ public static TextObjectRecord getTextObjRecord(HSSFSimpleShape shape){
+ return shape.getTextObjectRecord();
+ }
+
+ public static ObjRecord getObjRecord(HSSFShape shape){
+ return shape.getObjRecord();
+ }
}
import org.apache.poi.hssf.model.HSSFTestModelHelper;\r
import org.apache.poi.hssf.record.*;\r
\r
-import java.io.IOException;\r
+import java.io.*;\r
import java.util.Arrays;\r
\r
/**\r
HSSFWorkbook wb = new HSSFWorkbook();\r
HSSFSheet sh = wb.createSheet();\r
HSSFPatriarch patriarch = sh.createDrawingPatriarch();\r
+ int idx = wb.addPicture(new byte[]{1,2,3}, HSSFWorkbook.PICTURE_TYPE_PNG);\r
\r
HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());\r
comment.setString(new HSSFRichTextString("comment1"));\r
- comment = patriarch.createCellComment(new HSSFClientAnchor());\r
+ comment = patriarch.createCellComment(new HSSFClientAnchor(0,0,100,100,(short)0,0,(short)10,10));\r
comment.setString(new HSSFRichTextString("comment2"));\r
+ comment.setBackgroundImage(idx);\r
+ assertEquals(comment.getBackgroundImageId(), idx);\r
\r
assertEquals(patriarch.getChildren().size(), 2);\r
\r
sh = wb.getSheetAt(0);\r
patriarch = sh.getDrawingPatriarch();\r
\r
+ comment = (HSSFComment) patriarch.getChildren().get(1);\r
+ assertEquals(comment.getBackgroundImageId(), idx);\r
+ comment.resetBackgroundImage();\r
+ assertEquals(comment.getBackgroundImageId(), 0);\r
+\r
assertEquals(patriarch.getChildren().size(), 2);\r
comment = patriarch.createCellComment(new HSSFClientAnchor());\r
comment.setString(new HSSFRichTextString("comment3"));\r
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
sh = wb.getSheetAt(0);\r
patriarch = sh.getDrawingPatriarch();\r
+ comment = (HSSFComment) patriarch.getChildren().get(1);\r
+ assertEquals(comment.getBackgroundImageId(), 0);\r
assertEquals(patriarch.getChildren().size(), 3);\r
assertEquals(((HSSFComment) patriarch.getChildren().get(0)).getString().getString(), "comment1");\r
assertEquals(((HSSFComment) patriarch.getChildren().get(1)).getString().getString(), "comment2");\r