use of org.apache.poi.hssf.record.CommonObjectDataSubRecord in project poi by apache.
the class HSSFComment method createObjRecord.
@Override
protected ObjRecord createObjRecord() {
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;
}
use of org.apache.poi.hssf.record.CommonObjectDataSubRecord in project poi by apache.
the class TestHSSFSheet method autoFilter.
@Test
public void autoFilter() throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet sh = wb1.createSheet();
InternalWorkbook iwb = wb1.getWorkbook();
InternalSheet ish = sh.getSheet();
assertNull(iwb.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1));
assertNull(ish.findFirstRecordBySid(AutoFilterInfoRecord.sid));
CellRangeAddress range = CellRangeAddress.valueOf("A1:B10");
sh.setAutoFilter(range);
NameRecord name = iwb.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1);
assertNotNull(name);
// The built-in name for auto-filter must consist of a single Area3d Ptg.
Ptg[] ptg = name.getNameDefinition();
assertEquals("The built-in name for auto-filter must consist of a single Area3d Ptg", 1, ptg.length);
assertTrue("The built-in name for auto-filter must consist of a single Area3d Ptg", ptg[0] instanceof Area3DPtg);
Area3DPtg aref = (Area3DPtg) ptg[0];
assertEquals(range.getFirstColumn(), aref.getFirstColumn());
assertEquals(range.getFirstRow(), aref.getFirstRow());
assertEquals(range.getLastColumn(), aref.getLastColumn());
assertEquals(range.getLastRow(), aref.getLastRow());
// verify AutoFilterInfoRecord
AutoFilterInfoRecord afilter = (AutoFilterInfoRecord) ish.findFirstRecordBySid(AutoFilterInfoRecord.sid);
assertNotNull(afilter);
//filter covers two columns
assertEquals(2, afilter.getNumEntries());
HSSFPatriarch dr = sh.getDrawingPatriarch();
assertNotNull(dr);
HSSFSimpleShape comboBoxShape = (HSSFSimpleShape) dr.getChildren().get(0);
assertEquals(comboBoxShape.getShapeType(), HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX);
// ObjRecord will appear after serializetion
assertNull(ish.findFirstRecordBySid(ObjRecord.sid));
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
sh = wb2.getSheetAt(0);
ish = sh.getSheet();
ObjRecord objRecord = (ObjRecord) ish.findFirstRecordBySid(ObjRecord.sid);
List<SubRecord> subRecords = objRecord.getSubRecords();
assertEquals(3, subRecords.size());
assertTrue(subRecords.get(0) instanceof CommonObjectDataSubRecord);
// must be present, see Bug 51481
assertTrue(subRecords.get(1) instanceof FtCblsSubRecord);
assertTrue(subRecords.get(2) instanceof LbsDataSubRecord);
wb2.close();
}
use of org.apache.poi.hssf.record.CommonObjectDataSubRecord in project poi by apache.
the class TestCloneSheet method testCloneComment.
@Test
public void testCloneComment() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sh = wb.createSheet();
HSSFPatriarch p = sh.createDrawingPatriarch();
HSSFComment c = p.createComment(new HSSFClientAnchor(0, 0, 100, 100, (short) 0, 0, (short) 5, 5));
c.setColumn(1);
c.setRow(2);
c.setString(new HSSFRichTextString("qwertyuio"));
HSSFSheet sh2 = wb.cloneSheet(0);
HSSFPatriarch p2 = sh2.getDrawingPatriarch();
HSSFComment c2 = (HSSFComment) p2.getChildren().get(0);
assertEquals(c.getString(), c2.getString());
assertEquals(c.getRow(), c2.getRow());
assertEquals(c.getColumn(), c2.getColumn());
// The ShapeId is not equal?
// assertEquals(c.getNoteRecord().getShapeId(), c2.getNoteRecord().getShapeId());
assertArrayEquals(c2.getTextObjectRecord().serialize(), c.getTextObjectRecord().serialize());
// ShapeId is different
CommonObjectDataSubRecord subRecord = (CommonObjectDataSubRecord) c2.getObjRecord().getSubRecords().get(0);
subRecord.setObjectId(1025);
assertArrayEquals(c2.getObjRecord().serialize(), c.getObjRecord().serialize());
// ShapeId is different
c2.getNoteRecord().setShapeId(1025);
assertArrayEquals(c2.getNoteRecord().serialize(), c.getNoteRecord().serialize());
//everything except spRecord.shapeId must be the same
assertFalse(Arrays.equals(c2.getEscherContainer().serialize(), c.getEscherContainer().serialize()));
EscherSpRecord sp = (EscherSpRecord) c2.getEscherContainer().getChild(0);
sp.setShapeId(1025);
assertArrayEquals(c2.getEscherContainer().serialize(), c.getEscherContainer().serialize());
wb.close();
}
use of org.apache.poi.hssf.record.CommonObjectDataSubRecord in project poi by apache.
the class HSSFShapeFactory method createShapeTree.
/**
* build shape tree from escher container
* @param container root escher container from which escher records must be taken
* @param agg - EscherAggregate
* @param out - shape container to which shapes must be added
* @param root - node to create HSSFObjectData shapes
*/
public static void createShapeTree(EscherContainerRecord container, EscherAggregate agg, HSSFShapeContainer out, DirectoryNode root) {
if (container.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
ObjRecord obj = null;
EscherClientDataRecord clientData = ((EscherContainerRecord) container.getChild(0)).getChildById(EscherClientDataRecord.RECORD_ID);
if (null != clientData) {
obj = (ObjRecord) agg.getShapeToObjMapping().get(clientData);
}
HSSFShapeGroup group = new HSSFShapeGroup(container, obj);
List<EscherContainerRecord> children = container.getChildContainers();
// skip the first child record, it is group descriptor
for (int i = 0; i < children.size(); i++) {
EscherContainerRecord spContainer = children.get(i);
if (i != 0) {
createShapeTree(spContainer, agg, group, root);
}
}
out.addShape(group);
} else if (container.getRecordId() == EscherContainerRecord.SP_CONTAINER) {
Map<EscherRecord, Record> shapeToObj = agg.getShapeToObjMapping();
ObjRecord objRecord = null;
TextObjectRecord txtRecord = null;
for (EscherRecord record : container) {
switch(record.getRecordId()) {
case EscherClientDataRecord.RECORD_ID:
objRecord = (ObjRecord) shapeToObj.get(record);
break;
case EscherTextboxRecord.RECORD_ID:
txtRecord = (TextObjectRecord) shapeToObj.get(record);
break;
default:
break;
}
}
if (objRecord == null) {
throw new RecordFormatException("EscherClientDataRecord can't be found.");
}
if (isEmbeddedObject(objRecord)) {
HSSFObjectData objectData = new HSSFObjectData(container, objRecord, root);
out.addShape(objectData);
return;
}
CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) objRecord.getSubRecords().get(0);
final HSSFShape shape;
switch(cmo.getObjectType()) {
case CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE:
shape = new HSSFPicture(container, objRecord);
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_RECTANGLE:
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_LINE:
shape = new HSSFSimpleShape(container, objRecord);
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_COMBO_BOX:
shape = new HSSFCombobox(container, objRecord);
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING:
EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
if (optRecord == null) {
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
} else {
EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);
if (null != property) {
shape = new HSSFPolygon(container, objRecord, txtRecord);
} else {
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
}
}
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_TEXT:
shape = new HSSFTextbox(container, objRecord, txtRecord);
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT:
shape = new HSSFComment(container, objRecord, txtRecord, agg.getNoteRecordByObj(objRecord));
break;
default:
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
}
out.addShape(shape);
}
}
use of org.apache.poi.hssf.record.CommonObjectDataSubRecord in project poi by apache.
the class TestDrawingShapes method testDefaultSettingsWithEmptyContainer.
/**
* No NullPointerException should appear
*/
@Test
public void testDefaultSettingsWithEmptyContainer() {
EscherContainerRecord container = new EscherContainerRecord();
EscherOptRecord opt = new EscherOptRecord();
opt.setRecordId(EscherOptRecord.RECORD_ID);
container.addChildRecord(opt);
ObjRecord obj = new ObjRecord();
CommonObjectDataSubRecord cod = new CommonObjectDataSubRecord();
cod.setObjectType(HSSFSimpleShape.OBJECT_TYPE_PICTURE);
obj.addSubRecord(cod);
HSSFPicture picture = new HSSFPicture(container, obj);
assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);
assertEquals(picture.getFillColor(), HSSFShape.FILL__FILLCOLOR_DEFAULT);
assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_DEFAULT);
assertEquals(picture.getLineStyleColor(), HSSFShape.LINESTYLE__COLOR_DEFAULT);
assertEquals(picture.isNoFill(), HSSFShape.NO_FILL_DEFAULT);
//not set yet
assertEquals(picture.getPictureIndex(), -1);
}
Aggregations