return propertyValue;
}
- public void setRgbColor(int color){
- this.propertyValue = color;
- }
-
public byte getRed()
{
return (byte) ( propertyValue & 0xFF );
return propertyValue;
}
- public void setPropertyValue(int propertyValue) {
- this.propertyValue = propertyValue;
- }
-
/**
* Returns true if one escher property is equal to another.
*/
*/
private List<Record> tailRec = new ArrayList<Record>();
+ public EscherAggregate() {
+ buildBaseTree();
+ }
+
public EscherAggregate(DrawingManager2 drawingManager) {
this.drawingManager = drawingManager;
}
public void setPatriarch(HSSFPatriarch patriarch) {
this.patriarch = patriarch;
- convertPatriarch(patriarch);
}
/**
throw new IllegalArgumentException("Can not find client data record");
}
+ private void buildBaseTree(){
+ EscherContainerRecord dgContainer = new EscherContainerRecord();
+ EscherContainerRecord spgrContainer = new EscherContainerRecord();
+ EscherContainerRecord spContainer1 = new EscherContainerRecord();
+ EscherSpgrRecord spgr = new EscherSpgrRecord();
+ EscherSpRecord sp1 = new EscherSpRecord();
+ dgContainer.setRecordId(EscherContainerRecord.DG_CONTAINER);
+ dgContainer.setOptions((short) 0x000F);
+ EscherDgRecord dg = new EscherDgRecord();
+ dg.setRecordId( EscherDgRecord.RECORD_ID );
+ short dgId = 1;
+ dg.setOptions( (short) ( dgId << 4 ) );
+ dg.setNumShapes( 1 );
+ dg.setLastMSOSPID( 1024 );
+ drawingGroupId = dg.getDrawingGroupId();
+ spgrContainer.setRecordId(EscherContainerRecord.SPGR_CONTAINER);
+ spgrContainer.setOptions((short) 0x000F);
+ spContainer1.setRecordId(EscherContainerRecord.SP_CONTAINER);
+ spContainer1.setOptions((short) 0x000F);
+ spgr.setRecordId(EscherSpgrRecord.RECORD_ID);
+ spgr.setOptions((short) 0x0001); // version
+ spgr.setRectX1(0);
+ spgr.setRectY1(0);
+ spgr.setRectX2(1023);
+ spgr.setRectY2(255);
+ sp1.setRecordId(EscherSpRecord.RECORD_ID);
+ sp1.setOptions((short) 0x0002);
+ sp1.setShapeId(1024);
+ sp1.setFlags(EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_PATRIARCH);
+ dgContainer.addChildRecord(dg);
+ dgContainer.addChildRecord(spgrContainer);
+ spgrContainer.addChildRecord(spContainer1);
+ spContainer1.addChildRecord(spgr);
+ spContainer1.addChildRecord(sp1);
+ addEscherRecord(dgContainer);
+ }
+
private void convertPatriarch(HSSFPatriarch patriarch) {
EscherContainerRecord dgContainer = new EscherContainerRecord();
EscherDgRecord dg;
import java.awt.Dimension;
import java.io.ByteArrayInputStream;
-import org.apache.poi.ddf.EscherBSERecord;
-import org.apache.poi.ddf.EscherBlipRecord;
+import org.apache.poi.ddf.*;
+import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.ss.usermodel.Picture;
import org.apache.poi.ss.util.ImageUtils;
import org.apache.poi.hssf.model.InternalWorkbook;
*/
private static final int PX_ROW = 15;
- private int _pictureIndex;
+ public HSSFPicture(EscherContainerRecord spContainer, ObjRecord objRecord) {
+ super(spContainer, objRecord);
+ }
/**
* Constructs a picture object.
public int getPictureIndex()
{
- return _pictureIndex;
+ EscherSimpleProperty property = _optRecord.lookup(EscherProperties.BLIP__BLIPTODISPLAY);
+ if (null == property){
+ return -1;
+ }
+ return property.getPropertyValue();
}
public void setPictureIndex( int pictureIndex )
{
- this._pictureIndex = pictureIndex;
+ setPropertyValue(new EscherSimpleProperty( EscherProperties.BLIP__BLIPTODISPLAY, false, true, pictureIndex));
}
/**
* @return image dimension
*/
public Dimension getImageDimension(){
- EscherBSERecord bse = _patriarch._sheet._book.getBSERecord(_pictureIndex);
+ EscherBSERecord bse = _patriarch._sheet._book.getBSERecord(getPictureIndex());
byte[] data = bse.getBlipRecord().getPicturedata();
int type = bse.getBlipTypeWin32();
return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type);
*/
public HSSFPictureData getPictureData(){
InternalWorkbook iwb = _patriarch._sheet.getWorkbook().getWorkbook();
- EscherBlipRecord blipRecord = iwb.getBSERecord(_pictureIndex).getBlipRecord();
+ EscherBlipRecord blipRecord = iwb.getBSERecord(getPictureIndex()).getBlipRecord();
return new HSSFPictureData(blipRecord);
}
}
public static final int LINEWIDTH_DEFAULT = 9525;
public static final int LINESTYLE__COLOR_DEFAULT = 0x08000040;
public static final int FILL__FILLCOLOR_DEFAULT = 0x08000009;
+ public static final boolean NO_FILL_DEFAULT = true;
public static final int LINESTYLE_SOLID = 0; // Solid (continuous) pen
public static final int LINESTYLE_DASHSYS = 1; // PS_DASH system dash style
public static final int LINESTYLE_LONGDASHDOTDOTGEL = 10; // long dash short dash short dash
public static final int LINESTYLE_NONE = -1;
+ public static final int LINESTYLE_DEFAULT = LINESTYLE_NONE;
+
// TODO - make all these fields private
HSSFShape parent;
HSSFAnchor anchor;
* @see HSSFClientAnchor
*/
public void setAnchor(HSSFAnchor anchor) {
+ int i = 0;
+ int recordId = -1;
if (parent == null) {
if (anchor instanceof HSSFChildAnchor)
throw new IllegalArgumentException("Must use client anchors for shapes directly attached to sheet.");
EscherClientAnchorRecord anch = _escherContainer.getChildById(EscherClientAnchorRecord.RECORD_ID);
if (null != anch) {
+ for (i=0; i< _escherContainer.getChildRecords().size(); i++){
+ if (_escherContainer.getChild(i).getRecordId() == EscherClientAnchorRecord.RECORD_ID){
+ if (i != _escherContainer.getChildRecords().size() -1){
+ recordId = _escherContainer.getChild(i+1).getRecordId();
+ }
+ }
+ }
_escherContainer.removeChildRecord(anch);
}
} else {
throw new IllegalArgumentException("Must use child anchors for shapes attached to groups.");
EscherChildAnchorRecord anch = _escherContainer.getChildById(EscherChildAnchorRecord.RECORD_ID);
if (null != anch) {
+ for (i=0; i< _escherContainer.getChildRecords().size(); i++){
+ if (_escherContainer.getChild(i).getRecordId() == EscherChildAnchorRecord.RECORD_ID){
+ if (i != _escherContainer.getChildRecords().size() -1){
+ recordId = _escherContainer.getChild(i+1).getRecordId();
+ }
+ }
+ }
_escherContainer.removeChildRecord(anch);
}
}
- _escherContainer.addChildRecord(anchor.getEscherAnchor());
+ if (-1 == recordId){
+ _escherContainer.addChildRecord(anchor.getEscherAnchor());
+ } else {
+ _escherContainer.addChildBefore(anchor.getEscherAnchor(), recordId);
+ }
this.anchor = anchor;
}
* The color applied to the lines of this shape.
*/
public void setLineStyleColor(int lineStyleColor) {
- EscherRGBProperty rgbProperty = _optRecord.lookup(EscherProperties.LINESTYLE__COLOR);
- if (null == rgbProperty) {
- rgbProperty = new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor);
- _optRecord.addEscherProperty(rgbProperty);
- } else {
- rgbProperty.setRgbColor(lineStyleColor);
- }
+ setPropertyValue(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor));
}
/**
*/
public void setLineStyleColor(int red, int green, int blue) {
int lineStyleColor = ((blue) << 16) | ((green) << 8) | red;
- EscherRGBProperty rgbProperty = _optRecord.lookup(EscherProperties.LINESTYLE__COLOR);
- if (null == rgbProperty) {
- rgbProperty = new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor);
- _optRecord.addEscherProperty(rgbProperty);
- } else {
- rgbProperty.setRgbColor(lineStyleColor);
- }
+ setPropertyValue(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor));
}
/**
* The color used to fill this shape.
*/
public void setFillColor(int fillColor) {
- EscherRGBProperty rgbProperty = _optRecord.lookup(EscherProperties.FILL__FILLCOLOR);
- if (null == rgbProperty) {
- rgbProperty = new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor);
- _optRecord.addEscherProperty(rgbProperty);
- } else {
- rgbProperty.setRgbColor(fillColor);
- }
+ setPropertyValue(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor));
}
/**
*/
public void setFillColor(int red, int green, int blue) {
int fillColor = ((blue) << 16) | ((green) << 8) | red;
- EscherRGBProperty rgbProperty = _optRecord.lookup(EscherProperties.FILL__FILLCOLOR);
- if (null == rgbProperty) {
- rgbProperty = new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor);
- _optRecord.addEscherProperty(rgbProperty);
- } else {
- rgbProperty.setRgbColor(fillColor);
- }
+ setPropertyValue(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor));
}
/**
*/
public int getLineWidth() {
EscherSimpleProperty property = _optRecord.lookup(EscherProperties.LINESTYLE__LINEWIDTH);
- return property.getPropertyValue();
+ return property == null ? LINEWIDTH_DEFAULT: property.getPropertyValue();
}
/**
* @see HSSFShape#LINEWIDTH_ONE_PT
*/
public void setLineWidth(int lineWidth) {
- EscherSimpleProperty property = _optRecord.lookup(EscherProperties.LINESTYLE__LINEWIDTH);
- if (null == property) {
- property = new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, lineWidth);
- _optRecord.addEscherProperty(property);
- } else {
- property.setPropertyValue(lineWidth);
- }
+ setPropertyValue(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, lineWidth));
}
/**
public int getLineStyle() {
EscherSimpleProperty property = _optRecord.lookup(EscherProperties.LINESTYLE__LINEDASHING);
if (null == property){
- return -1;
+ return LINESTYLE_DEFAULT;
}
return property.getPropertyValue();
}
* @param lineStyle One of the constants in LINESTYLE_*
*/
public void setLineStyle(int lineStyle) {
- EscherSimpleProperty property = _optRecord.lookup(EscherProperties.LINESTYLE__LINEDASHING);
- if (null == property) {
- property = new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, lineStyle);
- _optRecord.addEscherProperty(property);
- } else {
- property.setPropertyValue(lineStyle);
- }
+ setPropertyValue(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, lineStyle));
}
/**
*/
public boolean isNoFill() {
EscherBoolProperty property = _optRecord.lookup(EscherProperties.FILL__NOFILLHITTEST);
- return property.isTrue();
+ return property == null ? NO_FILL_DEFAULT : property.isTrue();
}
/**
* Sets whether this shape is filled or transparent.
*/
public void setNoFill(boolean noFill) {
- EscherBoolProperty property = _optRecord.lookup(EscherProperties.FILL__NOFILLHITTEST);
- if (null == property) {
- property = new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, noFill ? 1 : 0);
+ setPropertyValue(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, noFill ? 1 : 0));
+ }
+
+ protected void setPropertyValue(EscherProperty property){
+ if (null == _optRecord.lookup(property.getId())){
_optRecord.addEscherProperty(property);
} else {
- property.setPropertyValue(noFill ? 1 : 0);
+ int i=0;
+ for (EscherProperty prop: _optRecord.getEscherProperties()){
+ if (prop.getId() == property.getId()){
+ _optRecord.getEscherProperties().remove(i);
+ break;
+ }
+ i++;
+ }
+ _optRecord.addEscherProperty(property);
}
}
package org.apache.poi.hssf.usermodel.drawing;\r
\r
+import org.apache.poi.hssf.usermodel.HSSFPicture;\r
import org.apache.poi.hssf.usermodel.HSSFSimpleShape;\r
\r
/**\r
public enum HSSFShapeType {\r
NOT_PRIMITIVE((short)0x0, null, (short)0),\r
RECTANGLE((short)0x1, HSSFSimpleShape.class, HSSFSimpleShape.OBJECT_TYPE_RECTANGLE),\r
+ PICTURE((short)0x004B, HSSFPicture.class, HSSFSimpleShape.OBJECT_TYPE_PICTURE),\r
ROUND_RECTANGLE((short)0x2, null, null);\r
\r
private Short type;\r
import java.io.File;\r
import java.io.FilenameFilter;\r
import java.io.IOException;\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.lang.reflect.Method;\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.HashMap;\r
}\r
}\r
\r
+ public void testBuildBaseTree(){\r
+ EscherAggregate agg = new EscherAggregate();\r
+ HSSFWorkbook wb = new HSSFWorkbook();\r
+ HSSFSheet sheet = wb.createSheet();\r
+\r
+ HSSFPatriarch drawing = sheet.createDrawingPatriarch();\r
+ EscherAggregate agg1 = HSSFTestHelper.getEscherAggregate(drawing);\r
+ callConvertPatriarch(agg1);\r
+ agg1.setPatriarch(null);\r
+ \r
+ agg.setPatriarch(null);\r
+\r
+ byte[] aggS = agg.serialize();\r
+ byte []agg1S = agg1.serialize();\r
+\r
+ assertEquals(aggS.length, agg1S.length);\r
+ assertTrue(Arrays.equals(aggS, agg1S));\r
+ }\r
+\r
+ private static void callConvertPatriarch(EscherAggregate agg) {\r
+ Method method = null;\r
+ try {\r
+ method = agg.getClass().getDeclaredMethod("convertPatriarch", HSSFPatriarch.class);\r
+ method.setAccessible(true);\r
+ method.invoke(agg, agg.getPatriarch());\r
+ } catch (IllegalAccessException e) {\r
+ e.printStackTrace();\r
+ } catch (NoSuchMethodException e) {\r
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.\r
+ } catch (InvocationTargetException e) {\r
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.\r
+ }\r
+ }\r
+\r
/**\r
* when reading incomplete data ensure that the serialized bytes\r
match the source\r
import junit.framework.TestCase;\r
import org.apache.poi.ddf.*;\r
import org.apache.poi.hssf.HSSFTestDataSamples;\r
+import org.apache.poi.hssf.record.CommonObjectDataSubRecord;\r
+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.util.HexDump;\r
\r
assertEquals(true,\r
((EscherBoolProperty)opt.lookup(EscherProperties.GROUPSHAPE__PRINT)).isTrue());\r
}\r
+\r
+ public void testDefaultPictureSettings(){\r
+ HSSFPicture picture = new HSSFPicture(null, new HSSFClientAnchor());\r
+ assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);\r
+ assertEquals(picture.getFillColor(), HSSFShape.FILL__FILLCOLOR_DEFAULT);\r
+ assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_SOLID);\r
+ assertEquals(picture.getLineStyleColor(), HSSFShape.LINESTYLE__COLOR_DEFAULT);\r
+ assertEquals(picture.isNoFill(), false);\r
+ assertEquals(picture.getPictureIndex(), -1);//not set yet\r
+ }\r
+\r
+ /**\r
+ * No NullPointerException should appear\r
+ */\r
+ public void testDefaultSettingsWithEmptyContainer(){\r
+ EscherContainerRecord container = new EscherContainerRecord();\r
+ EscherOptRecord opt = new EscherOptRecord();\r
+ opt.setRecordId(EscherOptRecord.RECORD_ID);\r
+ container.addChildRecord(opt);\r
+ ObjRecord obj = new ObjRecord();\r
+ CommonObjectDataSubRecord cod = new CommonObjectDataSubRecord();\r
+ cod.setObjectType(HSSFSimpleShape.OBJECT_TYPE_PICTURE);\r
+ obj.addSubRecord(cod);\r
+ HSSFPicture picture = new HSSFPicture(container, obj);\r
+\r
+ assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);\r
+ assertEquals(picture.getFillColor(), HSSFShape.FILL__FILLCOLOR_DEFAULT);\r
+ assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_DEFAULT);\r
+ assertEquals(picture.getLineStyleColor(), HSSFShape.LINESTYLE__COLOR_DEFAULT);\r
+ assertEquals(picture.isNoFill(), HSSFShape.NO_FILL_DEFAULT);\r
+ assertEquals(picture.getPictureIndex(), -1);//not set yet\r
+ }\r
/**\r
* create a rectangle, save the workbook, read back and verify that all shape properties are there\r
*/\r
assertEquals(rectangle2.getAnchor().getDy1(), 4);\r
assertEquals(rectangle2.getAnchor().getDy2(), 5);\r
assertEquals(rectangle2.isNoFill(), false);\r
+\r
+ HSSFSimpleShape rect3 = drawing.createSimpleShape(new HSSFClientAnchor());\r
+ rect3.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);\r
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+\r
+ drawing = wb.getSheetAt(0).getDrawingPatriarch();\r
+ assertEquals(drawing.getChildren().size(), 2);\r
+ }\r
+\r
+ public void testReadExistingImage(){\r
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");\r
+ HSSFSheet sheet = wb.getSheet("pictures");\r
+ HSSFPatriarch drawing = sheet.getDrawingPatriarch();\r
+ assertEquals(1, drawing.getChildren().size());\r
+ HSSFPicture picture = (HSSFPicture) drawing.getChildren().get(0);\r
+\r
+ assertEquals(picture.getPictureIndex(), 1);\r
+ assertEquals(picture.getLineStyleColor(), HSSFShape.LINESTYLE__COLOR_DEFAULT);\r
+ assertEquals(picture.getFillColor(), 0x5DC943);\r
+ assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);\r
+ assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_DEFAULT);\r
+ assertEquals(picture.isNoFill(), true);\r
}\r
\r
\r
assertEquals(shape.getLineWidth(), HSSFShape.LINEWIDTH_ONE_PT*2);\r
}\r
}\r
+\r
+ public void testShapeIds() {\r
+ HSSFWorkbook wb = new HSSFWorkbook();\r
+ HSSFSheet sheet1 = wb.createSheet();\r
+ HSSFPatriarch patriarch1 = sheet1.createDrawingPatriarch();\r
+ for(int i = 0; i < 2; i++) {\r
+ patriarch1.createSimpleShape(new HSSFClientAnchor());\r
+ }\r
+\r
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+ sheet1 = wb.getSheetAt(0);\r
+ patriarch1 = sheet1.getDrawingPatriarch();\r
+\r
+ EscherAggregate agg1 = HSSFTestHelper.getEscherAggregate(patriarch1);\r
+ // last shape ID cached in EscherDgRecord\r
+ EscherDgRecord dg1 =\r
+ agg1.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);\r
+ assertEquals(1026, dg1.getLastMSOSPID());\r
+\r
+ // iterate over shapes and check shapeId\r
+ EscherContainerRecord spgrContainer =\r
+ agg1.getEscherContainer().getChildContainers().get(0);\r
+ // root spContainer + 2 spContainers for shapes\r
+ assertEquals(3, spgrContainer.getChildRecords().size());\r
+\r
+ EscherSpRecord sp0 =\r
+ ((EscherContainerRecord)spgrContainer.getChild(0)).getChildById(EscherSpRecord.RECORD_ID);\r
+ assertEquals(1024, sp0.getShapeId());\r
+\r
+ EscherSpRecord sp1 =\r
+ ((EscherContainerRecord)spgrContainer.getChild(1)).getChildById(EscherSpRecord.RECORD_ID);\r
+ assertEquals(1025, sp1.getShapeId());\r
+\r
+ EscherSpRecord sp2 =\r
+ ((EscherContainerRecord)spgrContainer.getChild(2)).getChildById(EscherSpRecord.RECORD_ID);\r
+ assertEquals(1026, sp2.getShapeId());\r
+ }\r
}\r
package org.apache.poi.hssf.model;\r
\r
import junit.framework.TestCase;\r
-import org.apache.poi.ddf.EscherChildAnchorRecord;\r
-import org.apache.poi.ddf.EscherClientAnchorRecord;\r
-import org.apache.poi.ddf.EscherContainerRecord;\r
+import org.apache.poi.ddf.*;\r
+import org.apache.poi.hssf.HSSFTestDataSamples;\r
import org.apache.poi.hssf.usermodel.*;\r
+import org.apache.poi.util.HexDump;\r
\r
/**\r
* @author Evgeniy Berlog\r
*/\r
public class TestHSSFAnchor extends TestCase {\r
\r
+ public void testDefaultValues(){\r
+ HSSFClientAnchor clientAnchor = new HSSFClientAnchor();\r
+ assertEquals(clientAnchor.getAnchorType(), 0);\r
+ assertEquals(clientAnchor.getCol1(), 0);\r
+ assertEquals(clientAnchor.getCol2(), 0);\r
+ assertEquals(clientAnchor.getDx1(), 0);\r
+ assertEquals(clientAnchor.getDx2(), 0);\r
+ assertEquals(clientAnchor.getDy1(), 0);\r
+ assertEquals(clientAnchor.getDy2(), 0);\r
+ assertEquals(clientAnchor.getRow1(), 0);\r
+ assertEquals(clientAnchor.getRow2(), 0);\r
+\r
+ clientAnchor = new HSSFClientAnchor(new EscherClientAnchorRecord());\r
+ assertEquals(clientAnchor.getAnchorType(), 0);\r
+ assertEquals(clientAnchor.getCol1(), 0);\r
+ assertEquals(clientAnchor.getCol2(), 0);\r
+ assertEquals(clientAnchor.getDx1(), 0);\r
+ assertEquals(clientAnchor.getDx2(), 0);\r
+ assertEquals(clientAnchor.getDy1(), 0);\r
+ assertEquals(clientAnchor.getDy2(), 0);\r
+ assertEquals(clientAnchor.getRow1(), 0);\r
+ assertEquals(clientAnchor.getRow2(), 0);\r
+\r
+ HSSFChildAnchor childAnchor = new HSSFChildAnchor();\r
+ assertEquals(childAnchor.getDx1(), 0);\r
+ assertEquals(childAnchor.getDx2(), 0);\r
+ assertEquals(childAnchor.getDy1(), 0);\r
+ assertEquals(childAnchor.getDy2(), 0);\r
+\r
+ childAnchor = new HSSFChildAnchor(new EscherChildAnchorRecord());\r
+ assertEquals(childAnchor.getDx1(), 0);\r
+ assertEquals(childAnchor.getDx2(), 0);\r
+ assertEquals(childAnchor.getDy1(), 0);\r
+ assertEquals(childAnchor.getDy2(), 0);\r
+ }\r
+\r
+ public void testCorrectOrderInSpContainer(){\r
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");\r
+ HSSFSheet sheet = wb.getSheet("pictures");\r
+ HSSFPatriarch drawing = sheet.getDrawingPatriarch();\r
+\r
+ HSSFSimpleShape rectangle = (HSSFSimpleShape) drawing.getChildren().get(0);\r
+ rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);\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
+\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
+ }\r
+\r
public void testCreateClientAnchorFromContainer(){\r
EscherContainerRecord container = new EscherContainerRecord();\r
EscherClientAnchorRecord escher = new EscherClientAnchorRecord();\r
assertEquals(anchor.getDy2(), 118);\r
assertEquals(escher.getDy2(), 118);\r
}\r
+\r
+ public void testEqualsToSelf(){\r
+ HSSFClientAnchor clientAnchor = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7);\r
+ assertEquals(clientAnchor, clientAnchor);\r
+\r
+ HSSFChildAnchor childAnchor = new HSSFChildAnchor(0, 1, 2, 3);\r
+ assertEquals(childAnchor, childAnchor);\r
+ }\r
+\r
+ public void testPassIncompatibleTypeIsFalse(){\r
+ HSSFClientAnchor clientAnchor = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7);\r
+ assertNotSame(clientAnchor, "wrongType");\r
+\r
+ HSSFChildAnchor childAnchor = new HSSFChildAnchor(0, 1, 2, 3);\r
+ assertNotSame(childAnchor, "wrongType");\r
+ }\r
+\r
+ public void testNullReferenceIsFalse() {\r
+ HSSFClientAnchor clientAnchor = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7);\r
+ assertFalse("Passing null to equals should return false", clientAnchor.equals(null));\r
+\r
+ HSSFChildAnchor childAnchor = new HSSFChildAnchor(0, 1, 2, 3);\r
+ assertFalse("Passing null to equals should return false", childAnchor.equals(null));\r
+ }\r
+\r
+ public void testEqualsIsReflexiveIsSymmetric() {\r
+ HSSFClientAnchor clientAnchor1 = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7);\r
+ HSSFClientAnchor clientAnchor2 = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7);\r
+\r
+ assertTrue(clientAnchor1.equals(clientAnchor2));\r
+ assertTrue(clientAnchor1.equals(clientAnchor2));\r
+\r
+ HSSFChildAnchor childAnchor1 = new HSSFChildAnchor(0, 1, 2, 3);\r
+ HSSFChildAnchor childAnchor2 = new HSSFChildAnchor(0, 1, 2, 3);\r
+\r
+ assertTrue(childAnchor1.equals(childAnchor2));\r
+ assertTrue(childAnchor2.equals(childAnchor1));\r
+ }\r
+\r
+ public void testEqualsValues(){\r
+ HSSFClientAnchor clientAnchor1 = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7);\r
+ HSSFClientAnchor clientAnchor2 = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7);\r
+ assertEquals(clientAnchor1, clientAnchor2);\r
+\r
+ clientAnchor2.setDx1(10);\r
+ assertNotSame(clientAnchor1, clientAnchor2);\r
+ clientAnchor2.setDx1(0);\r
+ assertEquals(clientAnchor1, clientAnchor2);\r
+\r
+ clientAnchor2.setDy1(10);\r
+ assertNotSame(clientAnchor1, clientAnchor2);\r
+ clientAnchor2.setDy1(1);\r
+ assertEquals(clientAnchor1, clientAnchor2);\r
+\r
+ clientAnchor2.setDx2(10);\r
+ assertNotSame(clientAnchor1, clientAnchor2);\r
+ clientAnchor2.setDx2(2);\r
+ assertEquals(clientAnchor1, clientAnchor2);\r
+\r
+ clientAnchor2.setDy2(10);\r
+ assertNotSame(clientAnchor1, clientAnchor2);\r
+ clientAnchor2.setDy2(3);\r
+ assertEquals(clientAnchor1, clientAnchor2);\r
+\r
+ clientAnchor2.setCol1(10);\r
+ assertNotSame(clientAnchor1, clientAnchor2);\r
+ clientAnchor2.setCol1(4);\r
+ assertEquals(clientAnchor1, clientAnchor2);\r
+\r
+ clientAnchor2.setRow1(10);\r
+ assertNotSame(clientAnchor1, clientAnchor2);\r
+ clientAnchor2.setRow1(5);\r
+ assertEquals(clientAnchor1, clientAnchor2);\r
+\r
+ clientAnchor2.setCol2(10);\r
+ assertNotSame(clientAnchor1, clientAnchor2);\r
+ clientAnchor2.setCol2(6);\r
+ assertEquals(clientAnchor1, clientAnchor2);\r
+\r
+ clientAnchor2.setRow2(10);\r
+ assertNotSame(clientAnchor1, clientAnchor2);\r
+ clientAnchor2.setRow2(7);\r
+ assertEquals(clientAnchor1, clientAnchor2);\r
+\r
+ clientAnchor2.setAnchorType(3);\r
+ assertNotSame(clientAnchor1, clientAnchor2);\r
+ clientAnchor2.setAnchorType(0);\r
+ assertEquals(clientAnchor1, clientAnchor2);\r
+\r
+ HSSFChildAnchor childAnchor1 = new HSSFChildAnchor(0, 1, 2, 3);\r
+ HSSFChildAnchor childAnchor2 = new HSSFChildAnchor(0, 1, 2, 3);\r
+\r
+ childAnchor1.setDx1(10);\r
+ assertNotSame(childAnchor1, childAnchor2);\r
+ childAnchor1.setDx1(0);\r
+ assertEquals(childAnchor1, childAnchor2);\r
+\r
+ childAnchor2.setDy1(10);\r
+ assertNotSame(childAnchor1, childAnchor2);\r
+ childAnchor2.setDy1(1);\r
+ assertEquals(childAnchor1, childAnchor2);\r
+\r
+ childAnchor2.setDx2(10);\r
+ assertNotSame(childAnchor1, childAnchor2);\r
+ childAnchor2.setDx2(2);\r
+ assertEquals(childAnchor1, childAnchor2);\r
+\r
+ childAnchor2.setDy2(10);\r
+ assertNotSame(childAnchor1, childAnchor2);\r
+ childAnchor2.setDy2(3);\r
+ assertEquals(childAnchor1, childAnchor2);\r
+ }\r
}\r