]> source.dussan.org Git - poi.git/commitdiff
added modifiers for anchor type to XSSFClientAnchor
authorYegor Kozlov <yegor@apache.org>
Sat, 21 Mar 2009 16:28:26 +0000 (16:28 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 21 Mar 2009 16:28:26 +0000 (16:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@756965 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ClientAnchor.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java

index 395df7134fef4949251f5df19e613992e6d1be6b..ed635f9abd6e1f0ad12d17b8ec956de094f81fc6 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="add">added modifiers for anchor type to XSSFClientAnchor</action>
            <action dev="POI-DEVELOPERS" type="add">46772 - support built-in data formats in XSSFDataFormat</action>
            <action dev="POI-DEVELOPERS" type="fix">46719 - fixed XSSFSheet.shiftRows to correctly preserve row heights</action>
            <action dev="POI-DEVELOPERS" type="fix">46715 - preserve custom column widths across re-serialization of XSSFWorkbook</action>
index b22fd9d385558b43f72fa37dc9c2e087c42c1d1f..eb6a56f0b62d6d0e2b19cd0d495de6f8ab9c68cb 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="add">added modifiers for anchor type to XSSFClientAnchor</action>
            <action dev="POI-DEVELOPERS" type="add">46772 - support built-in data formats in XSSFDataFormat</action>
            <action dev="POI-DEVELOPERS" type="fix">46719 - fixed XSSFSheet.shiftRows to correctly preserve row heights</action>
            <action dev="POI-DEVELOPERS" type="fix">46715 - preserve custom column widths across re-serialization of XSSFWorkbook</action>
index 736f5e6ff5903b5234700cdd8bec388b1d9c0140..6a51a7288ce35f076f09f408f616523769fa03aa 100755 (executable)
@@ -23,6 +23,44 @@ package org.apache.poi.ss.usermodel;
  * @author Yegor Kozlov\r
  */\r
 public interface ClientAnchor {\r
+    /**\r
+     * Move and Resize With Anchor Cells\r
+     * <p>\r
+     * Specifies that the current drawing shall move and\r
+     * resize to maintain its row and column anchors (i.e. the\r
+     * object is anchored to the actual from and to row and column)\r
+     * </p>\r
+     */\r
+    public static final int MOVE_AND_RESIZE = 0;\r
+\r
+    /**\r
+     * Move With Cells but Do Not Resize\r
+     * <p>\r
+     * Specifies that the current drawing shall move with its\r
+     * row and column (i.e. the object is anchored to the\r
+     * actual from row and column), but that the size shall remain absolute.\r
+     * </p>\r
+     * <p>\r
+     * If additional rows/columns are added between the from and to locations of the drawing,\r
+     * the drawing shall move its to anchors as needed to maintain this same absolute size.\r
+     * </p>\r
+     */\r
+    public static final int MOVE_DONT_RESIZE = 2;\r
+\r
+    /**\r
+     * Do Not Move or Resize With Underlying Rows/Columns\r
+     * <p>\r
+     * Specifies that the current start and end positions shall\r
+     * be maintained with respect to the distances from the\r
+     * absolute start point of the worksheet.\r
+     * </p>\r
+     * <p>\r
+     * If additional rows/columns are added before the\r
+     * drawing, the drawing shall move its anchors as needed\r
+     * to maintain this same absolute position.\r
+     * </p>\r
+     */\r
+    public static final int DONT_MOVE_AND_RESIZE = 3;\r
 \r
     /**\r
      * Returns the column (0 based) of the first cell.\r
@@ -135,4 +173,30 @@ public interface ClientAnchor {
      * @param dx2 the x coordinate within the second cell\r
      */\r
     public void setDx2(int dx2);\r
+\r
+\r
+    /**\r
+     * Sets the anchor type\r
+     * <p>\r
+     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.\r
+     * </p>\r
+     * @param anchorType the anchor type\r
+     * @see #MOVE_AND_RESIZE\r
+     * @see #MOVE_DONT_RESIZE\r
+     * @see #DONT_MOVE_AND_RESIZE\r
+     */\r
+    public void setAnchorType( int anchorType );\r
+\r
+    /**\r
+     * Gets the anchor type\r
+     * <p>\r
+     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.\r
+     * </p>\r
+     * @return the anchor type\r
+     * @see #MOVE_AND_RESIZE\r
+     * @see #MOVE_DONT_RESIZE\r
+     * @see #DONT_MOVE_AND_RESIZE\r
+     */\r
+    public int getAnchorType();\r
+\r
 }\r
index 468ff8f6c3b5103bbd6d2e7e3f142f9b70e580a1..b23429fa01243fd6aa7e3eec2d10ee6e566c9f39 100755 (executable)
@@ -26,6 +26,7 @@ import org.apache.poi.ss.usermodel.ClientAnchor;
  * @author Yegor Kozlov\r
  */\r
 public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {\r
+    private int anchorType;\r
 \r
     /**\r
      * Starting anchor point\r
@@ -193,4 +194,26 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
     protected void setTo(CTMarker to){\r
         cell2 = to;\r
     }\r
+\r
+\r
+    /**\r
+     * Sets the anchor type\r
+     * <p>\r
+     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.\r
+     */\r
+    public void setAnchorType( int anchorType )\r
+    {\r
+        this.anchorType = anchorType;\r
+    }\r
+\r
+    /**\r
+     * Gets the anchor type\r
+     * <p>\r
+     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.\r
+     */\r
+    public int getAnchorType()\r
+    {\r
+        return anchorType;\r
+    }\r
+\r
 }\r
index 92be5e373ccc67ffb6d7815fea5492e8fe47a4f6..24943ba834a88bddc6802df8b9a6a9970fb9fa6e 100755 (executable)
@@ -138,7 +138,6 @@ public class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
         PackageRelationship rel = addPictureReference(pictureIndex);\r
 \r
         CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);\r
-        ctAnchor.setEditAs(STEditAs.ONE_CELL);\r
         CTPicture ctShape = ctAnchor.addNewPic();\r
         ctShape.set(XSSFPicture.prototype());\r
 \r
@@ -235,6 +234,14 @@ public class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
         ctAnchor.addNewClientData();\r
         anchor.setTo(ctAnchor.getTo());\r
         anchor.setFrom(ctAnchor.getFrom());\r
+        STEditAs.Enum aditAs;\r
+        switch(anchor.getAnchorType()) {\r
+            case ClientAnchor.DONT_MOVE_AND_RESIZE: aditAs = STEditAs.ABSOLUTE; break;\r
+            case ClientAnchor.MOVE_AND_RESIZE: aditAs = STEditAs.TWO_CELL; break;\r
+            case ClientAnchor.MOVE_DONT_RESIZE: aditAs = STEditAs.ONE_CELL; break;\r
+            default: aditAs = STEditAs.ONE_CELL;\r
+        }\r
+        ctAnchor.setEditAs(aditAs);\r
         return ctAnchor;\r
     }\r
 }\r
index eb405f1e12ea4be94c0cfdb8ccc1f90c5fa111ca..4fb3589ecc1e22fbbe888317abb1ace2f0df60b4 100755 (executable)
 package org.apache.poi.xssf.usermodel;\r
 \r
 import junit.framework.TestCase;\r
-import org.apache.poi.xssf.XSSFTestDataSamples;\r
-import org.apache.poi.POIXMLDocumentPart;\r
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;\r
+import org.apache.poi.ss.usermodel.ClientAnchor;\r
+import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;\r
+import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;\r
 \r
 import java.util.List;\r
 import java.util.Arrays;\r
-import java.io.IOException;\r
 \r
 /**\r
  * @author Yegor Kozlov\r
@@ -46,10 +45,17 @@ public class TestXSSFPicture extends TestCase {
         assertTrue(Arrays.equals(jpegData, pictures.get(jpegIdx).getData()));\r
 \r
         XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);\r
+        assertEquals(ClientAnchor.MOVE_AND_RESIZE, anchor.getAnchorType());\r
+        anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);\r
+        assertEquals(ClientAnchor.DONT_MOVE_AND_RESIZE, anchor.getAnchorType());\r
+\r
         XSSFPicture shape = drawing.createPicture(anchor, jpegIdx);\r
         assertTrue(anchor.equals(shape.getAnchor()));\r
         assertNotNull(shape.getPictureData());\r
         assertTrue(Arrays.equals(jpegData, shape.getPictureData().getData()));\r
 \r
+        CTTwoCellAnchor ctShapeHolder = drawing.getCTDrawing().getTwoCellAnchorArray(0);\r
+        // STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE\r
+        assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs());\r
     }\r
 }\r