ObjRecord obj = new ObjRecord();
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
c.setObjectType(HSSFTextbox.OBJECT_TYPE_TEXT);
- c.setLocked( true );
- c.setPrintable( true );
- c.setAutofill( true );
- c.setAutoline( true );
+ c.setLocked(true);
+ c.setPrintable(true);
+ c.setAutofill(true);
+ c.setAutoline(true);
EndSubRecord e = new EndSubRecord();
- obj.addSubRecord( c );
- obj.addSubRecord( e );
- return obj; }
+ obj.addSubRecord(c);
+ obj.addSubRecord(e);
+ return obj;
+ }
@Override
protected EscherContainerRecord createSpContainer() {
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTBOTTOM, 0));
opt.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID));
- opt.setEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
+ opt.setEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
opt.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT));
opt.setEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT));
opt.setEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT));
opt.setEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, NO_FILLHITTEST_FALSE));
- opt.setEscherProperty(new EscherBoolProperty( EscherProperties.GROUPSHAPE__PRINT, 0x080000));
+ opt.setEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000));
EscherRecord anchor = getAnchor().getEscherAnchor();
clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
}
@Override
- void afterInsert(HSSFPatriarch patriarch){
+ void afterInsert(HSSFPatriarch patriarch) {
EscherAggregate agg = patriarch._getBoundAggregate();
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID), getTextObjectRecord());
*/
public int getMarginLeft() {
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TEXT__TEXTLEFT);
- return property == null ? 0: property.getPropertyValue();
+ return property == null ? 0 : property.getPropertyValue();
}
/**
*/
public int getMarginRight() {
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TEXT__TEXTRIGHT);
- return property == null ? 0: property.getPropertyValue();
+ return property == null ? 0 : property.getPropertyValue();
}
/**
*/
public int getMarginTop() {
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TEXT__TEXTTOP);
- return property == null ? 0: property.getPropertyValue();
+ return property == null ? 0 : property.getPropertyValue();
}
/**
*/
public int getMarginBottom() {
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TEXT__TEXTBOTTOM);
- return property == null ? 0: property.getPropertyValue();
+ return property == null ? 0 : property.getPropertyValue();
}
/**
@Override
public void setShapeType(int shapeType) {
- throw new IllegalStateException("Shape type can not be changed in "+this.getClass().getSimpleName());
+ throw new IllegalStateException("Shape type can not be changed in " + this.getClass().getSimpleName());
}
@Override
public HSSFShape cloneShape() {
TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
EscherContainerRecord spContainer = new EscherContainerRecord();
- byte [] inSp = getEscherContainer().serialize();
+ byte[] inSp = getEscherContainer().serialize();
spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());
ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise();
return new HSSFTextbox(spContainer, obj, txo);
}
+
+ @Override
+ protected void afterRemove(HSSFPatriarch patriarch) {
+ patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
+ patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
+ }
}
import org.apache.poi.hssf.record.EscherAggregate;\r
import org.apache.poi.hssf.record.ObjRecord;\r
import org.apache.poi.hssf.usermodel.*;\r
+import org.apache.poi.ss.usermodel.Workbook;\r
import org.apache.poi.util.HexDump;\r
\r
import java.io.IOException;\r
assertTrue(Arrays.equals(comboboxShape.getSpContainer().serialize(), combobox.getEscherContainer().serialize()));\r
assertTrue(Arrays.equals(comboboxShape.getObjRecord().serialize(), combobox.getObjRecord().serialize()));\r
}\r
+\r
+ public void testRemoveShapes(){\r
+ HSSFWorkbook wb = new HSSFWorkbook();\r
+ HSSFSheet sheet = wb.createSheet();\r
+ HSSFPatriarch patriarch = sheet.createDrawingPatriarch();\r
+\r
+ HSSFSimpleShape rectangle = patriarch.createSimpleShape(new HSSFClientAnchor());\r
+ rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);\r
+\r
+ int idx = wb.addPicture(new byte[]{1,2,3}, Workbook.PICTURE_TYPE_JPEG);\r
+ patriarch.createPicture(new HSSFClientAnchor(), idx);\r
+\r
+ patriarch.createCellComment(new HSSFClientAnchor());\r
+\r
+ HSSFPolygon polygon = patriarch.createPolygon(new HSSFClientAnchor());\r
+ polygon.setPoints(new int[]{1,2}, new int[]{2,3});\r
+\r
+ patriarch.createTextbox(new HSSFClientAnchor());\r
+\r
+ HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());\r
+ group.createTextbox(new HSSFChildAnchor());\r
+ group.createPicture(new HSSFChildAnchor(), idx);\r
+\r
+ assertEquals(patriarch.getChildren().size(), 6);\r
+ assertEquals(group.getChildren().size(), 2);\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 12);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 1);\r
+\r
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+ sheet = wb.getSheetAt(0);\r
+ patriarch = sheet.getDrawingPatriarch();\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 12);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 1);\r
+\r
+ assertEquals(patriarch.getChildren().size(), 6);\r
+\r
+ group = (HSSFShapeGroup) patriarch.getChildren().get(5);\r
+ group.removeShape(group.getChildren().get(0));\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 10);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 1);\r
+\r
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+ sheet = wb.getSheetAt(0);\r
+ patriarch = sheet.getDrawingPatriarch();\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 10);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 1);\r
+\r
+ group = (HSSFShapeGroup) patriarch.getChildren().get(5);\r
+ patriarch.removeShape(group);\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 8);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 1);\r
+\r
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+ sheet = wb.getSheetAt(0);\r
+ patriarch = sheet.getDrawingPatriarch();\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 8);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 1);\r
+ assertEquals(patriarch.getChildren().size(), 5);\r
+\r
+ HSSFShape shape = patriarch.getChildren().get(0);\r
+ patriarch.removeShape(shape);\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 6);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 1);\r
+ assertEquals(patriarch.getChildren().size(), 4);\r
+\r
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+ sheet = wb.getSheetAt(0);\r
+ patriarch = sheet.getDrawingPatriarch();\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 6);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 1);\r
+ assertEquals(patriarch.getChildren().size(), 4);\r
+\r
+ HSSFPicture picture = (HSSFPicture) patriarch.getChildren().get(0);\r
+ patriarch.removeShape(picture);\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 5);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 1);\r
+ assertEquals(patriarch.getChildren().size(), 3);\r
+\r
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+ sheet = wb.getSheetAt(0);\r
+ patriarch = sheet.getDrawingPatriarch();\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 5);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 1);\r
+ assertEquals(patriarch.getChildren().size(), 3);\r
+\r
+ HSSFComment comment = (HSSFComment) patriarch.getChildren().get(0);\r
+ patriarch.removeShape(comment);\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 3);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 0);\r
+ assertEquals(patriarch.getChildren().size(), 2);\r
+\r
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+ sheet = wb.getSheetAt(0);\r
+ patriarch = sheet.getDrawingPatriarch();\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 3);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 0);\r
+ assertEquals(patriarch.getChildren().size(), 2);\r
+\r
+ polygon = (HSSFPolygon) patriarch.getChildren().get(0);\r
+ patriarch.removeShape(polygon);\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 2);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 0);\r
+ assertEquals(patriarch.getChildren().size(), 1);\r
+\r
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+ sheet = wb.getSheetAt(0);\r
+ patriarch = sheet.getDrawingPatriarch();\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 2);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 0);\r
+ assertEquals(patriarch.getChildren().size(), 1);\r
+\r
+ HSSFTextbox textbox = (HSSFTextbox) patriarch.getChildren().get(0);\r
+ patriarch.removeShape(textbox);\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 0);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 0);\r
+ assertEquals(patriarch.getChildren().size(), 0);\r
+\r
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+ sheet = wb.getSheetAt(0);\r
+ patriarch = sheet.getDrawingPatriarch();\r
+\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getShapeToObjMapping().size(), 0);\r
+ assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 0);\r
+ assertEquals(patriarch.getChildren().size(), 0);\r
+ }\r
}\r