]> source.dussan.org Git - poi.git/commitdiff
added few improvements
authorEvgeniy Berlog <berlog@apache.org>
Mon, 23 Jul 2012 09:06:56 +0000 (09:06 +0000)
committerEvgeniy Berlog <berlog@apache.org>
Mon, 23 Jul 2012 09:06:56 +0000 (09:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1364547 13f79535-47bb-0310-9956-ffa450edef68

20 files changed:
src/java/org/apache/poi/hssf/model/AbstractShape.java
src/java/org/apache/poi/hssf/model/ComboboxShape.java
src/java/org/apache/poi/hssf/model/CommentShape.java
src/java/org/apache/poi/hssf/model/LineShape.java
src/java/org/apache/poi/hssf/model/PolygonShape.java
src/java/org/apache/poi/hssf/model/SimpleFilledShape.java
src/java/org/apache/poi/hssf/model/TextboxShape.java
src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java
src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java
src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
src/java/org/apache/poi/hssf/usermodel/HSSFShape.java
src/java/org/apache/poi/hssf/usermodel/HSSFShapeContainer.java
src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java
src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java
src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java
src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java
test-data/spreadsheet/drawings.xls

index 3fd8883d6339edfa32281f712bf7d514dc8ee824..3441ba9f44297e84d3cc414ba078742a0014bc2c 100644 (file)
@@ -26,6 +26,7 @@ import org.apache.poi.hssf.usermodel.*;
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
+@Deprecated
 public abstract class AbstractShape
 {
     /**
index 674fc46f0f9feb0b85162417d679164ea9009a4e..ffca90a79fa66d7575e37c5d1005fb5334e319bf 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.poi.hssf.usermodel.*;
  * 
  * @author Yegor Kozlov
  */
+@Deprecated
 public class ComboboxShape
         extends AbstractShape {
     private EscherContainerRecord spContainer;
index f739a44d72970df6e7b2546910ba69acfc485253..19e83fff66e1187d448c157d37f8bb0763062888 100644 (file)
@@ -39,6 +39,7 @@ import org.apache.poi.hssf.usermodel.HSSFShape;
  *
  * @author Yegor Kozlov
  */
+@Deprecated
 public final class CommentShape extends TextboxShape {
 
     private NoteRecord _note;
index 2480d426067ebeea77d314bba7d9861a1be7ef94..e4517e4d7ac3586e3d33310dad35de43010fac1e 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.poi.hssf.usermodel.*;
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
+@Deprecated
 public class LineShape
         extends AbstractShape
 {
index 22212c88d2a51c8c92dec019736674e7f8e04f3d..1543e2df80b85fc9d01b4897131437f4473cb4c8 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.poi.hssf.usermodel.HSSFShape;
 import org.apache.poi.hssf.usermodel.HSSFPolygon;
 import org.apache.poi.util.LittleEndian;
 
+@Deprecated
 public class PolygonShape
         extends AbstractShape
 {
index 739e1ce329258c691301259ab7e8f71424872718..1763b9d5628e693ffea10ff52242942238e53f3a 100644 (file)
@@ -25,6 +25,7 @@ import org.apache.poi.hssf.record.EndSubRecord;
 import org.apache.poi.hssf.usermodel.HSSFSimpleShape;
 import org.apache.poi.hssf.usermodel.HSSFShape;
 
+@Deprecated
 public class SimpleFilledShape
         extends AbstractShape
 {
index 1ea79d0942f40f2acf35f3c7075a358f79793612..1b2a154a1d547ca8a4f96ad4e3f6200a662ea498 100644 (file)
@@ -28,6 +28,7 @@ import org.apache.poi.hssf.usermodel.*;
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
+@Deprecated
 public class TextboxShape
         extends AbstractShape
 {
index 67fb64f227440f2f4bf5258c3be18c979661a61b..1ad05587e673938b18d7f83da8522c8611e5395a 100644 (file)
@@ -1041,63 +1041,6 @@ public class HSSFCell implements Cell {
         _sheet.getDrawingPatriarch().removeShape(comment);
     }
 
-    /**
-     * Cell comment finder.
-     * Returns cell comment for the specified sheet, row and column.
-     *
-     * @return cell comment or <code>null</code> if not found
-     */
-    protected static HSSFComment findCellComment(InternalSheet sheet, int row, int column) {
-        // TODO - optimise this code by searching backwards, find NoteRecord first, quit if not found. Find one TXO by id
-        HSSFComment comment = null;
-        Map<Integer, TextObjectRecord> noteTxo =
-                               new HashMap<Integer, TextObjectRecord>();
-        int i = 0;
-        for (Iterator<RecordBase> it = sheet.getRecords().iterator(); it.hasNext();) {
-            RecordBase rec = it.next();
-            if (rec instanceof NoteRecord) {
-                NoteRecord note = (NoteRecord) rec;
-                if (note.getRow() == row && note.getColumn() == column) {
-                    if(i < noteTxo.size()) {
-                        TextObjectRecord txo = noteTxo.get(note.getShapeId());
-                        if(txo != null){
-                            comment = new HSSFComment(note, txo);
-                            comment.setRow(note.getRow());
-                            comment.setColumn(note.getColumn());
-                            comment.setAuthor(note.getAuthor());
-                            comment.setVisible(note.getFlags() == NoteRecord.NOTE_VISIBLE);
-                            comment.setString(txo.getStr());     
-                        } else{
-                            log.log(POILogger.WARN, "Failed to match NoteRecord and TextObjectRecord, row: " + row + ", column: " + column);
-                         }
-                    } else {
-                        log.log(POILogger.WARN, "Failed to match NoteRecord and TextObjectRecord, row: " + row + ", column: " + column);
-                    }
-                    break;
-                }
-                i++;
-            } else if (rec instanceof ObjRecord) {
-                ObjRecord obj = (ObjRecord) rec;
-                SubRecord sub = obj.getSubRecords().get(0);
-                if (sub instanceof CommonObjectDataSubRecord) {
-                    CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) sub;
-                    if (cmo.getObjectType() == CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT) {
-                        //map ObjectId and corresponding TextObjectRecord,
-                        //it will be used to match NoteRecord and TextObjectRecord
-                        while (it.hasNext()) {
-                            rec = it.next();
-                            if (rec instanceof TextObjectRecord) {
-                                noteTxo.put(cmo.getObjectId(), (TextObjectRecord) rec);
-                                break;
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return comment;
-    }
-
     /**
      * @return hyperlink associated with this cell or <code>null</code> if not found
      */
index 565c89e78c96190646893e682462cfb3eeeb1e83..dfe2b76a7e543c258bee8b6fe41da7455fa56565 100644 (file)
@@ -34,7 +34,7 @@ import org.apache.poi.util.HexDump;
  *
  * @author Daniel Noll
  */
-public final class HSSFObjectData extends HSSFShape {
+public final class HSSFObjectData extends HSSFPicture {
     /**
      * Reference to the filesystem root, required for retrieving the object data.
      */
@@ -131,7 +131,7 @@ public final class HSSFObjectData extends HSSFShape {
         EscherAggregate agg = patriarch._getBoundAggregate();
         agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
         EscherBSERecord bse =
-                patriarch._sheet.getWorkbook().getWorkbook().getBSERecord(getPictureIndex());
+                patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex());
         bse.setRef(bse.getRef() + 1);
     }
 
@@ -143,24 +143,4 @@ public final class HSSFObjectData extends HSSFShape {
         ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise();
         return new HSSFObjectData(spContainer, obj, _root);
     }
-
-    public int getPictureIndex() {
-        EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.BLIP__BLIPTODISPLAY);
-        if (null == property) {
-            return -1;
-        }
-        return property.getPropertyValue();
-    }
-
-    public void setPictureIndex(int pictureIndex) {
-        setPropertyValue(new EscherSimpleProperty(EscherProperties.BLIP__BLIPTODISPLAY, false, true, pictureIndex));
-    }
-
-    @Override
-    void setShapeId(int shapeId) {
-        EscherSpRecord spRecord = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
-        spRecord.setShapeId(shapeId);
-        CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0);
-        cod.setObjectId((short) (shapeId % 1024));
-    }
 }
index 8f40651205c8c91df06df3ebedb875c3562b7d03..9240998c202daf23b0687b58dd178e81751cc3c3 100644 (file)
@@ -18,6 +18,7 @@
 package org.apache.poi.hssf.usermodel;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -48,7 +49,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
      * and building up our shapes from the records)
      */
     private EscherAggregate _boundAggregate;
-    final HSSFSheet _sheet; // TODO make private
+    private final HSSFSheet _sheet;
 
     /**
      * Creates the patriarch.
@@ -132,13 +133,6 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
         addShape(shape);
         //open existing file
         onCreate(shape);
-        EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
-        if (shape.anchor.isHorizontallyFlipped()) {
-            sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
-        }
-        if (shape.anchor.isVerticallyFlipped()) {
-            sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT);
-        }
         return shape;
     }
 
@@ -155,14 +149,6 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
         addShape(shape);
         //open existing file
         onCreate(shape);
-
-        EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
-        if (shape.anchor.isHorizontallyFlipped()) {
-            sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
-        }
-        if (shape.anchor.isVerticallyFlipped()) {
-            sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT);
-        }
         return shape;
     }
 
@@ -232,7 +218,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
      * Returns a list of all shapes contained by the patriarch.
      */
     public List<HSSFShape> getChildren() {
-        return _shapes;
+        return Collections.unmodifiableList(_shapes);
     }
 
     /**
@@ -254,6 +240,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
 
         spgrContainer.addChildRecord(spContainer);
         shape.afterInsert(this);
+        setFlipFlags(shape);
     }
 
     /**
@@ -279,6 +266,13 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
         _spgrRecord.setRectX2(x2);
     }
 
+    public void clear() {
+        ArrayList <HSSFShape> copy = new ArrayList<HSSFShape>(_shapes);
+        for (HSSFShape shape: copy){
+            removeShape(shape);
+        }
+    }
+
     int newShapeId() {
         DrawingManager2 dm = _sheet.getWorkbook().getWorkbook().getDrawingManager();
         EscherDgRecord dg =
@@ -395,4 +389,22 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
             }
         }
     }
+
+    private void setFlipFlags(HSSFShape shape){
+        EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
+        if (shape.anchor.isHorizontallyFlipped()) {
+            sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
+        }
+        if (shape.anchor.isVerticallyFlipped()) {
+            sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT);
+        }
+    }
+
+    public Iterator<HSSFShape> iterator() {
+        return _shapes.iterator();
+    }
+
+    protected HSSFSheet getSheet() {
+        return _sheet;
+    }
 }
index 6bc713366d392450d3a5668879736568aa78c9b4..7d8618ba7bac4d46fbede54ad9e584e9a1dd6198 100644 (file)
@@ -34,7 +34,7 @@ import org.apache.poi.hssf.model.InternalWorkbook;
  * @author Glen Stampoultzis
  * @author Yegor Kozlov (yegor at apache.org)
  */
-public final class HSSFPicture extends HSSFSimpleShape implements Picture {
+public class HSSFPicture extends HSSFSimpleShape implements Picture {
     public static final int PICTURE_TYPE_EMF = HSSFWorkbook.PICTURE_TYPE_EMF;                // Windows Enhanced Metafile
     public static final int PICTURE_TYPE_WMF = HSSFWorkbook.PICTURE_TYPE_WMF;                // Windows Metafile
     public static final int PICTURE_TYPE_PICT = HSSFWorkbook.PICTURE_TYPE_PICT;              // Macintosh PICT
@@ -203,7 +203,7 @@ public final class HSSFPicture extends HSSFSimpleShape implements Picture {
 
     private float getColumnWidthInPixels(int column){
 
-        int cw = _patriarch._sheet.getColumnWidth(column);
+        int cw = _patriarch.getSheet().getColumnWidth(column);
         float px = getPixelWidth(column);
 
         return cw/px;
@@ -211,18 +211,18 @@ public final class HSSFPicture extends HSSFSimpleShape implements Picture {
 
     private float getRowHeightInPixels(int i){
 
-        HSSFRow row = _patriarch._sheet.getRow(i);
+        HSSFRow row = _patriarch.getSheet().getRow(i);
         float height;
         if(row != null) height = row.getHeight();
-        else height = _patriarch._sheet.getDefaultRowHeight();
+        else height = _patriarch.getSheet().getDefaultRowHeight();
 
         return height/PX_ROW;
     }
 
     private float getPixelWidth(int column){
 
-        int def = _patriarch._sheet.getDefaultColumnWidth()*256;
-        int cw = _patriarch._sheet.getColumnWidth(column);
+        int def = _patriarch.getSheet().getDefaultColumnWidth()*256;
+        int cw = _patriarch.getSheet().getColumnWidth(column);
 
         return cw == def ? PX_DEFAULT : PX_MODIFIED;
     }
@@ -233,7 +233,7 @@ public final class HSSFPicture extends HSSFSimpleShape implements Picture {
      * @return image dimension
      */
     public Dimension getImageDimension(){
-        EscherBSERecord bse = _patriarch._sheet._book.getBSERecord(getPictureIndex());
+        EscherBSERecord bse = _patriarch.getSheet()._book.getBSERecord(getPictureIndex());
         byte[] data = bse.getBlipRecord().getPicturedata();
         int type = bse.getBlipTypeWin32();
         return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type);
@@ -245,7 +245,7 @@ public final class HSSFPicture extends HSSFSimpleShape implements Picture {
      * @return picture data for this shape
      */
     public HSSFPictureData getPictureData(){
-        InternalWorkbook iwb = _patriarch._sheet.getWorkbook().getWorkbook();
+        InternalWorkbook iwb = _patriarch.getSheet().getWorkbook().getWorkbook();
        EscherBlipRecord blipRecord = iwb.getBSERecord(getPictureIndex()).getBlipRecord();
        return new HSSFPictureData(blipRecord);
     }
@@ -255,14 +255,14 @@ public final class HSSFPicture extends HSSFSimpleShape implements Picture {
         EscherAggregate agg = patriarch._getBoundAggregate();
         agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
         EscherBSERecord bse =
-                patriarch._sheet.getWorkbook().getWorkbook().getBSERecord(getPictureIndex());
+                patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex());
         bse.setRef(bse.getRef() + 1);
     }
 
     /**
      * The color applied to the lines of this shape.
      */
-    public String getAdditionalData() {
+    public String getFileName() {
         EscherComplexProperty propFile = (EscherComplexProperty) getOptRecord().lookup(
                       EscherProperties.BLIP__BLIPFILENAME);
         try {
@@ -275,7 +275,7 @@ public final class HSSFPicture extends HSSFSimpleShape implements Picture {
         }
     }
     
-    public void setAdditionalData(String data){
+    public void setFileName(String data){
         try {
             EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.BLIP__BLIPFILENAME, true, data.getBytes("UTF-16LE"));
             setPropertyValue(prop);
index 137ead3c7527c0e65a541ad8bde1a361d52e92cc..ba7a8667065f3976c545eed15ff09cafa2f322d6 100644 (file)
@@ -20,7 +20,10 @@ package org.apache.poi.hssf.usermodel;
 import org.apache.poi.ddf.*;
 import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
 import org.apache.poi.hssf.record.ObjRecord;
+import org.apache.poi.util.LittleEndian;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.util.Iterator;
 
 /**
@@ -100,7 +103,7 @@ public abstract class HSSFShape {
         EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
         spRecord.setShapeId(shapeId);
         CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) _objRecord.getSubRecords().get(0);
-        cod.setObjectId((short) (shapeId-1024));
+        cod.setObjectId((short) (shapeId%1024));
     }
     
     int getShapeId(){
@@ -295,6 +298,53 @@ public abstract class HSSFShape {
     protected void setPropertyValue(EscherProperty property){
         _optRecord.setEscherProperty(property);
     }
+    
+    public void setFlipVertical(boolean value){
+        EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
+        if (value){
+            sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT);
+        } else {
+            sp.setFlags(sp.getFlags() & (Integer.MAX_VALUE - EscherSpRecord.FLAG_FLIPVERT));
+        }
+    }
+
+    public void setFlipHorizontal(boolean value){
+        EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
+        if (value){
+            sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
+        } else {
+            sp.setFlags(sp.getFlags() & (Integer.MAX_VALUE - EscherSpRecord.FLAG_FLIPHORIZ));
+        }
+    }
+    
+    public boolean isFlipVertical(){
+        EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
+        return (sp.getFlags() & EscherSpRecord.FLAG_FLIPVERT) != 0;
+    }
+
+    public boolean isFlipHorizontal(){
+        EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
+        return (sp.getFlags() & EscherSpRecord.FLAG_FLIPHORIZ) != 0;
+    }
+    
+    public int getRotationDegree(){
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TRANSFORM__ROTATION);
+        if (null == property){
+            return 0;
+        }
+        try {
+            LittleEndian.putInt(property.getPropertyValue(), bos);
+            return LittleEndian.getShort(bos.toByteArray(), 2);
+        } catch (IOException e) {
+            e.printStackTrace();
+            return 0;
+        }
+    }
+
+    public void setRotationDegree(short value){
+        setPropertyValue(new EscherSimpleProperty(EscherProperties.TRANSFORM__ROTATION , (value << 16)));
+    }
 
     /**
      * Count of all children and their children's children.
index 181b3d17a99e3f6c025198a27a757767109f4218..1d7748edc3d5f7af83478a5eaa1b5d74e36cd325 100644 (file)
@@ -24,12 +24,12 @@ import java.util.List;
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
-public interface HSSFShapeContainer
+public interface HSSFShapeContainer extends Iterable<HSSFShape>
 {
     /**
      * @return  Any children contained by this shape.
      */
-    List getChildren();
+    List<HSSFShape> getChildren();
 
     /**
      * add shape to the list of child records
@@ -42,4 +42,13 @@ public interface HSSFShapeContainer
      */
     void setCoordinates( int x1, int y1, int x2, int y2 );
 
+    void clear();
+    
+    public int getX1();
+
+    public int getY1();
+
+    public int getX2();
+
+    public int getY2();
 }
index 7cf6803fd00c58ef65477520bbaa17f675fde7ce..1c8ac95dfa4d2c8cef2739199c74d97268ff28a2 100644 (file)
 package org.apache.poi.hssf.usermodel;
 
 import org.apache.poi.ddf.*;
-import org.apache.poi.hssf.model.TextboxShape;
 import org.apache.poi.hssf.record.*;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Iterator;
 
@@ -32,7 +32,7 @@ import java.util.Iterator;
  * @author Glen Stampoultzis (glens at apache.org)
  */
 public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer {
-    List<HSSFShape> shapes = new ArrayList<HSSFShape>();
+    private final List<HSSFShape> shapes = new ArrayList<HSSFShape>();
     private EscherSpgrRecord _spgrRecord;
 
     public HSSFShapeGroup(EscherContainerRecord spgrContainer, ObjRecord objRecord) {
@@ -172,11 +172,6 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer {
         shapes.add(shape);
     }
 
-    public void addTextBox(TextboxShape textboxShape) {
-//        HSSFTextbox shape = new HSSFTextbox(this, textboxShape.geanchor);
-//        shapes.add(textboxShape);
-    }
-
     /**
      * Create a new simple shape under this group.
      *
@@ -258,7 +253,7 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer {
      * Return all children contained by this shape.
      */
     public List<HSSFShape> getChildren() {
-        return shapes;
+        return Collections.unmodifiableList(shapes);
     }
 
     /**
@@ -272,6 +267,13 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer {
         _spgrRecord.setRectY2(y2);
     }
 
+    public void clear() {
+        ArrayList <HSSFShape> copy = new ArrayList<HSSFShape>(shapes);
+        for (HSSFShape shape: copy){
+            removeShape(shape);
+        }
+    }
+
     /**
      * The top left x coordinate of this group.
      */
@@ -377,4 +379,8 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer {
         }
         return isRemoved;
     }
+
+    public Iterator<HSSFShape> iterator() {
+        return shapes.iterator();
+    }
 }
index 258ee011a6fb8a8bb4142f0ee32ce97db432e82f..77d23f3f1d2d8a34a7a928bfa564f6e6c3657476 100644 (file)
@@ -177,6 +177,9 @@ public class HSSFSimpleShape extends HSSFShape
         // If font is not set we must set the default one
         if (rtr.numFormattingRuns() == 0) rtr.applyFont((short) 0);
         _textObjectRecord.setStr(rtr);
+        if (string.getString() != null){
+            setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, string.getString().hashCode()));
+        }
     }
 
     @Override
index 872a195228b87d2e23a5aa163f5ecd81c3fe2db8..9f859ee3aceefe94374514ce4540ca1844f18110 100644 (file)
@@ -129,14 +129,6 @@ public class HSSFTextbox extends HSSFSimpleShape {
         return spContainer;
     }
 
-    @Override
-    public void setString(RichTextString string) {
-        HSSFRichTextString rtr = (HSSFRichTextString) string;
-        // If font is not set we must set the default one
-        if (rtr.numFormattingRuns() == 0) rtr.applyFont((short) 0);
-        getTextObjectRecord().setStr(rtr);
-    }
-
     @Override
     void afterInsert(HSSFPatriarch patriarch) {
         EscherAggregate agg = patriarch._getBoundAggregate();
index e31a6ecbf843b60d0f8e214e181fe6e0a1c18eb9..23dc0526cd3f476b5f6f322173551b60a69ea7a7 100644 (file)
@@ -136,6 +136,8 @@ public class TestDrawingShapes extends TestCase {
         rectangle.setNoFill(true);\r
         rectangle.setString(new HSSFRichTextString("teeeest"));\r
         assertEquals(rectangle.getLineStyleColor(), 1111);\r
+        assertEquals(((EscherSimpleProperty)((EscherOptRecord)rectangle.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID))\r
+                .lookup(EscherProperties.TEXT__TEXTID)).getPropertyValue(), "teeeest".hashCode());\r
         assertEquals(rectangle.isNoFill(), true);\r
         assertEquals(rectangle.getString().getString(), "teeeest");\r
 \r
@@ -225,6 +227,7 @@ public class TestDrawingShapes extends TestCase {
         assertEquals(HexDump.toHex(shape.getFillColor()), shape.getFillColor(), 0x2CE03D);\r
         assertEquals(shape.getLineWidth(), HSSFShape.LINEWIDTH_ONE_PT * 2);\r
         assertEquals(shape.getString().getString(), "POItest");\r
+        assertEquals(shape.getRotationDegree(), 27);\r
     }\r
 \r
     public void testShapeIds() {\r
@@ -536,4 +539,115 @@ public class TestDrawingShapes extends TestCase {
         assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 0);\r
         assertEquals(patriarch.getChildren().size(), 0);\r
     }\r
+\r
+    public void testShapeFlip(){\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
+        assertEquals(rectangle.isFlipVertical(), false);\r
+        assertEquals(rectangle.isFlipHorizontal(), false);\r
+\r
+        rectangle.setFlipVertical(true);\r
+        assertEquals(rectangle.isFlipVertical(), true);\r
+        rectangle.setFlipHorizontal(true);\r
+        assertEquals(rectangle.isFlipHorizontal(), true);\r
+\r
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+        sheet = wb.getSheetAt(0);\r
+        patriarch = sheet.getDrawingPatriarch();\r
+\r
+        rectangle = (HSSFSimpleShape) patriarch.getChildren().get(0);\r
+\r
+        assertEquals(rectangle.isFlipHorizontal(), true);\r
+        rectangle.setFlipHorizontal(false);\r
+        assertEquals(rectangle.isFlipHorizontal(), false);\r
+\r
+        assertEquals(rectangle.isFlipVertical(), true);\r
+        rectangle.setFlipVertical(false);\r
+        assertEquals(rectangle.isFlipVertical(), false);\r
+\r
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+        sheet = wb.getSheetAt(0);\r
+        patriarch = sheet.getDrawingPatriarch();\r
+\r
+        rectangle = (HSSFSimpleShape) patriarch.getChildren().get(0);\r
+\r
+        assertEquals(rectangle.isFlipVertical(), false);\r
+        assertEquals(rectangle.isFlipHorizontal(), false);\r
+    }\r
+\r
+    public void testRotation() {\r
+        HSSFWorkbook wb = new HSSFWorkbook();\r
+        HSSFSheet sheet = wb.createSheet();\r
+        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();\r
+\r
+        HSSFSimpleShape rectangle = patriarch.createSimpleShape(new HSSFClientAnchor(0,0,100,100, (short) 0,0,(short)5,5));\r
+        rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);\r
+\r
+        assertEquals(rectangle.getRotationDegree(), 0);\r
+        rectangle.setRotationDegree((short) 45);\r
+        assertEquals(rectangle.getRotationDegree(), 45);\r
+        rectangle.setFlipHorizontal(true);\r
+\r
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+        sheet = wb.getSheetAt(0);\r
+        patriarch = sheet.getDrawingPatriarch();\r
+        rectangle = (HSSFSimpleShape) patriarch.getChildren().get(0);\r
+        assertEquals(rectangle.getRotationDegree(), 45);\r
+        rectangle.setRotationDegree((short) 30);\r
+        assertEquals(rectangle.getRotationDegree(), 30);\r
+\r
+        patriarch.setCoordinates(0, 0, 10, 10);\r
+        rectangle.setString(new HSSFRichTextString("1234"));\r
+    }\r
+\r
+    public void testShapeContainerImplementsIterable(){\r
+        HSSFWorkbook wb = new HSSFWorkbook();\r
+        HSSFSheet sheet = wb.createSheet();\r
+        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();\r
+\r
+        patriarch.createSimpleShape(new HSSFClientAnchor());\r
+        patriarch.createSimpleShape(new HSSFClientAnchor());\r
+\r
+        int i=2;\r
+\r
+        for (HSSFShape shape: patriarch){\r
+            i--;\r
+        }\r
+        assertEquals(i, 0);\r
+    }\r
+\r
+    public void testClearShapesForPatriarch(){\r
+        HSSFWorkbook wb = new HSSFWorkbook();\r
+        HSSFSheet sheet = wb.createSheet();\r
+        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();\r
+\r
+        patriarch.createSimpleShape(new HSSFClientAnchor());\r
+        patriarch.createSimpleShape(new HSSFClientAnchor());\r
+        patriarch.createCellComment(new HSSFClientAnchor());\r
+\r
+        EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);\r
+\r
+        assertEquals(agg.getShapeToObjMapping().size(), 6);\r
+        assertEquals(agg.getTailRecords().size(), 1);\r
+        assertEquals(patriarch.getChildren().size(), 3);\r
+\r
+        patriarch.clear();\r
+\r
+        assertEquals(agg.getShapeToObjMapping().size(), 0);\r
+        assertEquals(agg.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(agg.getShapeToObjMapping().size(), 0);\r
+        assertEquals(agg.getTailRecords().size(), 0);\r
+        assertEquals(patriarch.getChildren().size(), 0);\r
+    }\r
 }\r
index 234cddccfd254e0d46f78fb68b6e4b1dd1cd2ea8..dcc611c05ab30233fcf71268be18f233bf59b258 100644 (file)
@@ -184,7 +184,7 @@ public final class TestHSSFPicture extends BaseTestPicture {
         assertEquals(1, drawing.getChildren().size());
 
         HSSFPicture picture = (HSSFPicture) drawing.getChildren().get(0);
-        assertEquals(picture.getAdditionalData(), "test");
+        assertEquals(picture.getFileName(), "test");
     }
 
     public void testSetGetProperties(){
@@ -199,15 +199,15 @@ public final class TestHSSFPicture extends BaseTestPicture {
         int idx1 = wb.addPicture(data1, Workbook.PICTURE_TYPE_JPEG);
         HSSFPicture p1 = dr.createPicture(anchor, idx1);
 
-        assertEquals(p1.getAdditionalData(), "");
-        p1.setAdditionalData("aaa");
-        assertEquals(p1.getAdditionalData(), "aaa");
+        assertEquals(p1.getFileName(), "");
+        p1.setFileName("aaa");
+        assertEquals(p1.getFileName(), "aaa");
 
         wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
         sh = wb.getSheet("Pictures");
         dr = sh.getDrawingPatriarch();
 
         p1 = (HSSFPicture) dr.getChildren().get(0);
-        assertEquals(p1.getAdditionalData(), "aaa");
+        assertEquals(p1.getFileName(), "aaa");
     }
 }
index f0ce3f28011c762d7daf27bd9b695881a3771416..d5ea732d02ae148d8a20910d05c52b886d9686ae 100644 (file)
@@ -4,6 +4,7 @@ import junit.framework.TestCase;
 import org.apache.poi.ddf.EscherContainerRecord;\r
 import org.apache.poi.ddf.EscherSpgrRecord;\r
 import org.apache.poi.hssf.HSSFTestDataSamples;\r
+import org.apache.poi.hssf.record.EscherAggregate;\r
 import org.apache.poi.hssf.record.ObjRecord;\r
 \r
 import java.lang.reflect.Field;\r
@@ -226,4 +227,36 @@ public class TestShapeGroup extends TestCase{
         }\r
         return null;\r
     }\r
+\r
+    public void testClearShapes(){\r
+        HSSFWorkbook wb = new HSSFWorkbook();\r
+        HSSFSheet sheet = wb.createSheet();\r
+        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();\r
+        HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());\r
+\r
+        group.createShape(new HSSFChildAnchor());\r
+        group.createShape(new HSSFChildAnchor());\r
+\r
+        EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);\r
+\r
+        assertEquals(agg.getShapeToObjMapping().size(), 5);\r
+        assertEquals(agg.getTailRecords().size(), 0);\r
+        assertEquals(group.getChildren().size(), 2);\r
+\r
+        group.clear();\r
+\r
+        assertEquals(agg.getShapeToObjMapping().size(), 1);\r
+        assertEquals(agg.getTailRecords().size(), 0);\r
+        assertEquals(group.getChildren().size(), 0);\r
+\r
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
+        sheet = wb.getSheetAt(0);\r
+        patriarch = sheet.getDrawingPatriarch();\r
+\r
+        group = (HSSFShapeGroup) patriarch.getChildren().get(0);\r
+\r
+        assertEquals(agg.getShapeToObjMapping().size(), 1);\r
+        assertEquals(agg.getTailRecords().size(), 0);\r
+        assertEquals(group.getChildren().size(), 0);\r
+    }\r
 }\r
index 45b9a958870d9362f8ade14e7b93e6b5d7159207..69fb3af3d19fc51bb60124e10e377bb3de9676f7 100644 (file)
Binary files a/test-data/spreadsheet/drawings.xls and b/test-data/spreadsheet/drawings.xls differ