]> source.dussan.org Git - poi.git/commitdiff
Patch from hishidama to add Comment.getClientAnchor(). This closes #12 from github
authorNick Burch <nick@apache.org>
Tue, 4 Nov 2014 23:55:23 +0000 (23:55 +0000)
committerNick Burch <nick@apache.org>
Tue, 4 Nov 2014 23:55:23 +0000 (23:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1636782 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFComment.java
src/java/org/apache/poi/ss/usermodel/Comment.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java

index 8b4350893c0d8240c28ea7f9bcc9297442eeefce..81de3a41d05396b1104f1c4cb8a41df036a2e50a 100644 (file)
@@ -28,6 +28,7 @@ import org.apache.poi.hssf.record.NoteRecord;
 import org.apache.poi.hssf.record.NoteStructureSubRecord;
 import org.apache.poi.hssf.record.ObjRecord;
 import org.apache.poi.hssf.record.TextObjectRecord;
+import org.apache.poi.ss.usermodel.ClientAnchor;
 import org.apache.poi.ss.usermodel.Comment;
 
 /**
@@ -231,6 +232,17 @@ public class HSSFComment extends HSSFTextbox implements Comment {
         return true;
     }
 
+    @Override
+    public ClientAnchor getClientAnchor() {
+        HSSFAnchor ha = super.getAnchor();
+        if (ha instanceof ClientAnchor) {
+            return (ClientAnchor) ha;
+        }
+
+        throw new IllegalStateException("Anchor can not be changed in "
+                + ClientAnchor.class.getSimpleName());
+    }
+
     @Override
     public void setShapeType(int shapeType) {
         throw new IllegalStateException("Shape type can not be changed in "+this.getClass().getSimpleName());
index 463f7013481fa029c1e6951a4ea65ea2afa5d8c5..356e55c7c9ca829f9b299363d0d62f2d344d2f39 100644 (file)
@@ -87,4 +87,10 @@ public interface Comment {
      */
     void setString(RichTextString string);
 
+    /**
+     * Return defines position of this anchor in the sheet.
+     *
+     * @return defines position of this anchor in the sheet
+     */
+    public ClientAnchor getClientAnchor();
 }
\ No newline at end of file
index f75b250624e58009a7ba3b203f5db322b4da658e..9d7dda22c423613411756c1edc28429a73193562 100644 (file)
 ==================================================================== */
 package org.apache.poi.xssf.usermodel;
 
+import java.math.BigInteger;
+
+import org.apache.poi.ss.usermodel.ClientAnchor;
 import org.apache.poi.ss.usermodel.Comment;
 import org.apache.poi.ss.usermodel.RichTextString;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.model.CommentsTable;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
-import schemasMicrosoftComVml.CTShape;
 
-import java.math.BigInteger;
+import schemasMicrosoftComVml.CTShape;
 
 public class XSSFComment implements Comment {
        
@@ -172,6 +174,18 @@ public class XSSFComment implements Comment {
                setString(new XSSFRichTextString(string));
        }
 
+    @Override
+    public ClientAnchor getClientAnchor() {
+        String position = _vmlShape.getClientDataArray(0).getAnchorArray(0);
+        int[] pos = new int[8];
+        int i = 0;
+        for (String s : position.split(",")) {
+            pos[i++] = Integer.parseInt(s.trim());
+        }
+        XSSFClientAnchor ca = new XSSFClientAnchor(0, 0, 0, 0, pos[0], pos[2], pos[4], pos[6]);
+        return ca;
+    }
+
     /**
      * @return the xml bean holding this comment's properties
      */
index 2ca3dbaa911cc5c099fefe403b61d6d924c7daee..23ee0ff20c4254c47f7e781d4ece6f4fdc4f0fbe 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
 
 import org.apache.poi.hssf.usermodel.HSSFRichTextString;
 import org.apache.poi.ss.usermodel.BaseTestCellComment;
+import org.apache.poi.ss.usermodel.ClientAnchor;
 import org.apache.poi.ss.usermodel.IndexedColors;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.XSSFITestDataProvider;
@@ -167,4 +168,34 @@ public final class TestXSSFComment extends BaseTestCellComment  {
         assertEquals("", comment.getAuthor());
         assertEquals(2, sheetComments.getNumberOfAuthors());
     }
+
+    public void testGetClientAnchor() {
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFSheet sheet = wb.createSheet();
+        XSSFDrawing drawing = sheet.createDrawingPatriarch();
+        XSSFComment comment;
+        ClientAnchor anchor;
+
+        comment = drawing.createCellComment(new XSSFClientAnchor(101, 102, 103, 104, 1, 2, 3, 4));
+        anchor = comment.getClientAnchor();
+        assertEquals(0, anchor.getDx1());
+        assertEquals(0, anchor.getDy1());
+        assertEquals(0, anchor.getDx2());
+        assertEquals(0, anchor.getDy2());
+        assertEquals(1, anchor.getCol1());
+        assertEquals(2, anchor.getRow1());
+        assertEquals(3, anchor.getCol2());
+        assertEquals(4, anchor.getRow2());
+
+        comment = drawing.createCellComment(new XSSFClientAnchor());
+        anchor = comment.getClientAnchor();
+        assertEquals(0, anchor.getDx1());
+        assertEquals(0, anchor.getDy1());
+        assertEquals(0, anchor.getDx2());
+        assertEquals(0, anchor.getDy2());
+        assertEquals(1, anchor.getCol1());
+        assertEquals(0, anchor.getRow1());
+        assertEquals(3, anchor.getCol2());
+        assertEquals(3, anchor.getRow2());
+    }
 }
index b49f725baaa704ab9ecc2ead6897406d229497fd..6a08fe7fa5086bc3a5583a2029ba0cdc2daf1a9c 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel;
 import org.apache.poi.hssf.HSSFITestDataProvider;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.ss.usermodel.BaseTestCellComment;
+import org.apache.poi.ss.usermodel.ClientAnchor;
 
 /**
  * Tests TestHSSFCellComment.
@@ -70,4 +71,34 @@ public final class TestHSSFComment extends BaseTestCellComment {
         comment = cell.getCellComment();
         assertEquals("c6", comment.getString().getString());
     }
+
+    public void testGetClientAnchor() {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sheet = wb.createSheet();
+        HSSFPatriarch drawing = sheet.createDrawingPatriarch();
+        HSSFComment comment;
+        ClientAnchor anchor;
+
+        comment = drawing.createCellComment(new HSSFClientAnchor(101, 102, 103, 104, (short) 1, 2, (short) 3, 4));
+        anchor = comment.getClientAnchor();
+        assertEquals(101, anchor.getDx1());
+        assertEquals(102, anchor.getDy1());
+        assertEquals(103, anchor.getDx2());
+        assertEquals(104, anchor.getDy2());
+        assertEquals(1, anchor.getCol1());
+        assertEquals(2, anchor.getRow1());
+        assertEquals(3, anchor.getCol2());
+        assertEquals(4, anchor.getRow2());
+
+        comment = drawing.createCellComment(new HSSFClientAnchor());
+        anchor = comment.getClientAnchor();
+        assertEquals(0, anchor.getDx1());
+        assertEquals(0, anchor.getDy1());
+        assertEquals(0, anchor.getDx2());
+        assertEquals(0, anchor.getDy2());
+        assertEquals(0, anchor.getCol1());
+        assertEquals(0, anchor.getRow1());
+        assertEquals(0, anchor.getCol2());
+        assertEquals(0, anchor.getRow2());
+    }
 }