poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r1366636 - in /poi/branches/gsoc2012/src: java/org/apache/poi/ddf/ java/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/hssf/model/ testcases/org/apache/poi/hssf/usermodel/
Date Sat, 28 Jul 2012 10:21:41 GMT
Author: berlog
Date: Sat Jul 28 10:21:40 2012
New Revision: 1366636

URL: http://svn.apache.org/viewvc?rev=1366636&view=rev
Log:
added features:
-background image for comment
-wrapText for HSSFSimpleShape
-few other improvements

Modified:
    poi/branches/gsoc2012/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java
    poi/branches/gsoc2012/src/java/org/apache/poi/ddf/EscherBoolProperty.java
    poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java
    poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java
    poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
    poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java
    poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java
    poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java
    poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java
    poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFUnknownShape.java
    poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
    poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java
    poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
    poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java

Modified: poi/branches/gsoc2012/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java Sat Jul
28 10:21:40 2012
@@ -154,6 +154,15 @@ public abstract class AbstractEscherOptR
         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.
      */

Modified: poi/branches/gsoc2012/src/java/org/apache/poi/ddf/EscherBoolProperty.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/ddf/EscherBoolProperty.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/ddf/EscherBoolProperty.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/ddf/EscherBoolProperty.java Sat Jul 28 10:21:40
2012
@@ -70,7 +70,7 @@ public class EscherBoolProperty
     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();
     }

Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java Sat Jul
28 10:21:40 2012
@@ -19,7 +19,6 @@ package org.apache.poi.hssf.usermodel;
 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.
@@ -28,6 +27,9 @@ import org.apache.poi.ss.usermodel.RichT
  */
 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
@@ -77,10 +79,11 @@ public class HSSFComment extends HSSFTex
     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;
     }
 
@@ -215,7 +218,7 @@ public class HSSFComment extends HSSFTex
     }
 
     @Override
-    public HSSFShape cloneShape() {
+    protected HSSFShape cloneShape() {
         TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
         EscherContainerRecord spContainer = new EscherContainerRecord();
         byte [] inSp = getEscherContainer().serialize();
@@ -224,4 +227,26 @@ public class HSSFComment extends HSSFTex
         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();
+    }
 }

Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java Sat Jul
28 10:21:40 2012
@@ -136,7 +136,7 @@ public final class HSSFObjectData extend
     }
 
     @Override
-    public HSSFShape cloneShape() {
+    protected HSSFShape cloneShape() {
         EscherContainerRecord spContainer = new EscherContainerRecord();
         byte[] inSp = getEscherContainer().serialize();
         spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());

Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java Sat Jul
28 10:21:40 2012
@@ -87,8 +87,8 @@ public class HSSFPicture extends HSSFSim
     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;
     }
@@ -290,7 +290,7 @@ public class HSSFPicture extends HSSFSim
     }
 
     @Override
-    public HSSFShape cloneShape() {
+    protected HSSFShape cloneShape() {
         EscherContainerRecord spContainer = new EscherContainerRecord();
         byte [] inSp = getEscherContainer().serialize();
         spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());

Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java Sat Jul 28
10:21:40 2012
@@ -90,15 +90,6 @@ public abstract class HSSFShape {
 
     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);
@@ -112,15 +103,15 @@ public abstract class HSSFShape {
 
     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;
     }
 
@@ -353,5 +344,5 @@ public abstract class HSSFShape {
         return 1;
     }
 
-    public abstract HSSFShape cloneShape();
+    protected abstract HSSFShape cloneShape();
 }

Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java Sat Jul
28 10:21:40 2012
@@ -337,7 +337,7 @@ public class HSSFShapeGroup extends HSSF
     }
 
     @Override
-    public HSSFShape cloneShape() {
+    protected HSSFShape cloneShape() {
         throw new IllegalStateException("Use method cloneShape(HSSFPatriarch patriarch)");
     }
 

Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java Sat
Jul 28 10:21:40 2012
@@ -57,6 +57,10 @@ public class HSSFSimpleShape extends HSS
     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;
@@ -83,12 +87,14 @@ public class HSSFSimpleShape extends HSS
         _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(""));
@@ -194,7 +200,7 @@ public class HSSFSimpleShape extends HSS
     }
 
     @Override
-    public HSSFShape cloneShape() {
+    protected HSSFShape cloneShape() {
         TextObjectRecord txo = null;
         EscherContainerRecord spContainer = new EscherContainerRecord();
         byte [] inSp = getEscherContainer().serialize();
@@ -243,4 +249,13 @@ public class HSSFSimpleShape extends HSS
         }
         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));
+    }
 }

Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java Sat Jul
28 10:21:40 2012
@@ -230,7 +230,7 @@ public class HSSFTextbox extends HSSFSim
     }
 
     @Override
-    public HSSFShape cloneShape() {
+    protected HSSFShape cloneShape() {
         TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
         EscherContainerRecord spContainer = new EscherContainerRecord();
         byte[] inSp = getEscherContainer().serialize();

Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFUnknownShape.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFUnknownShape.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFUnknownShape.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFUnknownShape.java Sat
Jul 28 10:21:40 2012
@@ -50,7 +50,7 @@ public class HSSFUnknownShape extends HS
     }
 
     @Override
-    public HSSFShape cloneShape() {
+    protected HSSFShape cloneShape() {
         return null;
     }
 }

Modified: poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java (original)
+++ poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java Sat
Jul 28 10:21:40 2012
@@ -120,7 +120,7 @@ public class TestDrawingShapes extends T
         HSSFSheet sheet = wb.createSheet();
 
         HSSFPatriarch drawing = sheet.createDrawingPatriarch();
-        HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 200, 200, (short) 2, 2, (short)
15, 15);
+        HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 50, 50, (short) 2, 2, (short)
4, 4);
         anchor.setAnchorType(2);
         assertEquals(anchor.getAnchorType(), 2);
 
@@ -132,13 +132,16 @@ public class TestDrawingShapes extends T
         assertEquals(10000, rectangle.getLineWidth());
         rectangle.setLineStyle(10);
         assertEquals(10, rectangle.getLineStyle());
+        assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_SQUARE);
         rectangle.setLineStyleColor(1111);
         rectangle.setNoFill(true);
+        rectangle.setWrapText(HSSFSimpleShape.WRAP_NONE);
         rectangle.setString(new HSSFRichTextString("teeeest"));
         assertEquals(rectangle.getLineStyleColor(), 1111);
-        assertEquals(((EscherSimpleProperty)((EscherOptRecord)rectangle.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID))
+        assertEquals(((EscherSimpleProperty)((EscherOptRecord)HSSFTestHelper.getEscherContainer(rectangle).getChildById(EscherOptRecord.RECORD_ID))
                 .lookup(EscherProperties.TEXT__TEXTID)).getPropertyValue(), "teeeest".hashCode());
         assertEquals(rectangle.isNoFill(), true);
+        assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_NONE);
         assertEquals(rectangle.getString().getString(), "teeeest");
 
         wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
@@ -157,6 +160,7 @@ public class TestDrawingShapes extends T
         assertEquals(rectangle2.getFillColor(), 777);
         assertEquals(rectangle2.isNoFill(), true);
         assertEquals(rectangle2.getString().getString(), "teeeest");
+        assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_NONE);
 
         rectangle2.setFillColor(3333);
         rectangle2.setLineStyle(9);
@@ -167,6 +171,7 @@ public class TestDrawingShapes extends T
         rectangle2.getAnchor().setDx2(3);
         rectangle2.getAnchor().setDy1(4);
         rectangle2.getAnchor().setDy2(5);
+        rectangle.setWrapText(HSSFSimpleShape.WRAP_BY_POINTS);
         rectangle2.setString(new HSSFRichTextString("test22"));
 
         wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
@@ -175,6 +180,7 @@ public class TestDrawingShapes extends T
         assertEquals(1, drawing.getChildren().size());
         rectangle2 = (HSSFSimpleShape) drawing.getChildren().get(0);
         assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, rectangle2.getShapeType());
+        assertEquals(rectangle.getWrapText(), HSSFSimpleShape.WRAP_BY_POINTS);
         assertEquals(77, rectangle2.getLineWidth());
         assertEquals(9, rectangle2.getLineStyle());
         assertEquals(rectangle2.getLineStyleColor(), 4444);
@@ -313,7 +319,7 @@ public class TestDrawingShapes extends T
 
         HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
         EscherOptRecord opt1 = HSSFTestHelper.getOptRecord(textbox);
-        EscherOptRecord opt2 = textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID);
+        EscherOptRecord opt2 = HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID);
         assertSame(opt1, opt2);
     }
     
@@ -328,13 +334,13 @@ public class TestDrawingShapes extends T
         String opt1Str = opt.toXml();
 
         textbox.setFillColor(textbox.getFillColor());
-        assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());
+        assertEquals(opt1Str, HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID).toXml());
         textbox.setLineStyle(textbox.getLineStyle());
-        assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());
+        assertEquals(opt1Str, HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID).toXml());
         textbox.setLineWidth(textbox.getLineWidth());
-        assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());
+        assertEquals(opt1Str, HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID).toXml());
         textbox.setLineStyleColor(textbox.getLineStyleColor());
-        assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());
+        assertEquals(opt1Str, HSSFTestHelper.getEscherContainer(textbox).getChildById(EscherOptRecord.RECORD_ID).toXml());
     }
 
     public void testDgRecordNumShapes(){
@@ -370,7 +376,7 @@ public class TestDrawingShapes extends T
         shape.setString(new HSSFRichTextString("string1"));
         assertEquals(shape.getString().getString(), "string1");
 
-        assertNotNull(shape.getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
+        assertNotNull(HSSFTestHelper.getEscherContainer(shape).getChildById(EscherTextboxRecord.RECORD_ID));
         assertEquals(agg.getShapeToObjMapping().size(), 2);
 
         wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
@@ -381,9 +387,9 @@ public class TestDrawingShapes extends T
 
         shape = (HSSFSimpleShape) patriarch.getChildren().get(0);
 
-        assertNotNull(shape.getTextObjectRecord());
+        assertNotNull(HSSFTestHelper.getTextObjRecord(shape));
         assertEquals(shape.getString().getString(), "string1");
-        assertNotNull(shape.getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
+        assertNotNull(HSSFTestHelper.getEscherContainer(shape).getChildById(EscherTextboxRecord.RECORD_ID));
         assertEquals(agg.getShapeToObjMapping().size(), 2);
     }
 
@@ -396,8 +402,8 @@ public class TestDrawingShapes extends T
         HSSFTestHelper.setShapeId(combobox, 1024);
         ComboboxShape comboboxShape = new ComboboxShape(combobox, 1024);
 
-        assertTrue(Arrays.equals(comboboxShape.getSpContainer().serialize(), combobox.getEscherContainer().serialize()));
-        assertTrue(Arrays.equals(comboboxShape.getObjRecord().serialize(), combobox.getObjRecord().serialize()));
+        assertTrue(Arrays.equals(comboboxShape.getSpContainer().serialize(), HSSFTestHelper.getEscherContainer(combobox).serialize()));
+        assertTrue(Arrays.equals(comboboxShape.getObjRecord().serialize(), HSSFTestHelper.getObjRecord(combobox).serialize()));
     }
 
     public void testRemoveShapes(){

Modified: poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java (original)
+++ poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java Sat
Jul 28 10:21:40 2012
@@ -55,17 +55,17 @@ public class TestHSSFAnchor extends Test
 
         HSSFSimpleShape rectangle = (HSSFSimpleShape) drawing.getChildren().get(0);
 
-        assertEquals(rectangle.getEscherContainer().getChild(0).getRecordId(), EscherSpRecord.RECORD_ID);
-        assertEquals(rectangle.getEscherContainer().getChild(1).getRecordId(), EscherOptRecord.RECORD_ID);
-        assertEquals(rectangle.getEscherContainer().getChild(2).getRecordId(), EscherClientAnchorRecord.RECORD_ID);
-        assertEquals(rectangle.getEscherContainer().getChild(3).getRecordId(), EscherClientDataRecord.RECORD_ID);
+        assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(0).getRecordId(),
EscherSpRecord.RECORD_ID);
+        assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(1).getRecordId(),
EscherOptRecord.RECORD_ID);
+        assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(2).getRecordId(),
EscherClientAnchorRecord.RECORD_ID);
+        assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(3).getRecordId(),
EscherClientDataRecord.RECORD_ID);
 
         rectangle.setAnchor(new HSSFClientAnchor());
 
-        assertEquals(rectangle.getEscherContainer().getChild(0).getRecordId(), EscherSpRecord.RECORD_ID);
-        assertEquals(rectangle.getEscherContainer().getChild(1).getRecordId(), EscherOptRecord.RECORD_ID);
-        assertEquals("  " + HexDump.toHex(rectangle.getEscherContainer().getChild(2).getRecordId())
+ "    ", rectangle.getEscherContainer().getChild(2).getRecordId(), EscherClientAnchorRecord.RECORD_ID);
-        assertEquals(rectangle.getEscherContainer().getChild(3).getRecordId(), EscherClientDataRecord.RECORD_ID);
+        assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(0).getRecordId(),
EscherSpRecord.RECORD_ID);
+        assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(1).getRecordId(),
EscherOptRecord.RECORD_ID);
+        assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(2).getRecordId(),
EscherClientAnchorRecord.RECORD_ID);
+        assertEquals(HSSFTestHelper.getEscherContainer(rectangle).getChild(3).getRecordId(),
EscherClientDataRecord.RECORD_ID);
     }
 
     public void testCreateClientAnchorFromContainer(){
@@ -135,8 +135,8 @@ public class TestHSSFAnchor extends Test
         rectangle.setAnchor(anchor);
 
         assertNotNull(anchor.getEscherAnchor());
-        assertNotNull(rectangle.getEscherContainer());
-        assertTrue(anchor.getEscherAnchor().equals(rectangle.getEscherContainer().getChildById(EscherClientAnchorRecord.RECORD_ID)));
+        assertNotNull(HSSFTestHelper.getEscherContainer(rectangle));
+        assertTrue(anchor.getEscherAnchor().equals(HSSFTestHelper.getEscherContainer(rectangle).getChildById(EscherClientAnchorRecord.RECORD_ID)));
     }
 
     public void testClientAnchorFromEscher(){

Modified: poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
(original)
+++ poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
Sat Jul 28 10:21:40 2012
@@ -21,6 +21,8 @@ import org.apache.poi.hssf.model.Drawing
 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;
@@ -104,4 +106,16 @@ public class HSSFTestHelper {
     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();
+    }
 }

Modified: poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java?rev=1366636&r1=1366635&r2=1366636&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java (original)
+++ poi/branches/gsoc2012/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java Sat
Jul 28 10:21:40 2012
@@ -7,7 +7,7 @@ import org.apache.poi.hssf.model.Comment
 import org.apache.poi.hssf.model.HSSFTestModelHelper;
 import org.apache.poi.hssf.record.*;
 
-import java.io.IOException;
+import java.io.*;
 import java.util.Arrays;
 
 /**
@@ -91,11 +91,14 @@ public class TestComment extends TestCas
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet sh = wb.createSheet();
         HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+        int idx = wb.addPicture(new byte[]{1,2,3}, HSSFWorkbook.PICTURE_TYPE_PNG);
 
         HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
         comment.setString(new HSSFRichTextString("comment1"));
-        comment = patriarch.createCellComment(new HSSFClientAnchor());
+        comment = patriarch.createCellComment(new HSSFClientAnchor(0,0,100,100,(short)0,0,(short)10,10));
         comment.setString(new HSSFRichTextString("comment2"));
+        comment.setBackgroundImage(idx);
+        assertEquals(comment.getBackgroundImageId(), idx);
 
         assertEquals(patriarch.getChildren().size(), 2);
 
@@ -103,6 +106,11 @@ public class TestComment extends TestCas
         sh = wb.getSheetAt(0);
         patriarch = sh.getDrawingPatriarch();
 
+        comment = (HSSFComment) patriarch.getChildren().get(1);
+        assertEquals(comment.getBackgroundImageId(), idx);
+        comment.resetBackgroundImage();
+        assertEquals(comment.getBackgroundImageId(), 0);
+
         assertEquals(patriarch.getChildren().size(), 2);
         comment = patriarch.createCellComment(new HSSFClientAnchor());
         comment.setString(new HSSFRichTextString("comment3"));
@@ -111,6 +119,8 @@ public class TestComment extends TestCas
         wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
         sh = wb.getSheetAt(0);
         patriarch = sh.getDrawingPatriarch();
+        comment = (HSSFComment) patriarch.getChildren().get(1);
+        assertEquals(comment.getBackgroundImageId(), 0);
         assertEquals(patriarch.getChildren().size(), 3);
         assertEquals(((HSSFComment) patriarch.getChildren().get(0)).getString().getString(),
"comment1");
         assertEquals(((HSSFComment) patriarch.getChildren().get(1)).getString().getString(),
"comment2");



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message