You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/11/17 13:00:09 UTC

svn commit: r1895104 - in /poi/trunk: poi-ooxml/src/main/java/org/apache/poi/xssf/model/ poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/ poi/src/main/java9/

Author: fanningpj
Date: Wed Nov 17 13:00:09 2021
New Revision: 1895104

URL: http://svn.apache.org/viewvc?rev=1895104&view=rev
Log:
try to make comments table more extensible

Modified:
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
    poi/trunk/poi/src/main/java9/module-info.class

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java?rev=1895104&r1=1895103&r2=1895104&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java Wed Nov 17 13:00:09 2021
@@ -25,11 +25,16 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
+import com.microsoft.schemas.vml.CTShape;
 import org.apache.poi.ooxml.POIXMLDocumentPart;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.ss.util.CellAddress;
 import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
 import org.apache.poi.xssf.usermodel.XSSFComment;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFVMLDrawing;
 import org.apache.xmlbeans.XmlException;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
@@ -169,6 +174,37 @@ public class CommentsTable extends POIXM
     }
 
     /**
+     * Create a new comment and add to the CommentTable.
+     * @param sheet sheet to add comment to
+     * @param clientAnchor the anchor for this comment
+     * @return new XSSFComment
+     * @since POI 5.2.0
+     */
+    public XSSFComment createNewComment(XSSFSheet sheet, XSSFClientAnchor clientAnchor) {
+        XSSFVMLDrawing vml = sheet.getVMLDrawing(true);
+        com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape();
+        if (clientAnchor.isSet()) {
+            // convert offsets from emus to pixels since we get a
+            // DrawingML-anchor
+            // but create a VML Drawing
+            int dx1Pixels = clientAnchor.getDx1() / Units.EMU_PER_PIXEL;
+            int dy1Pixels = clientAnchor.getDy1() / Units.EMU_PER_PIXEL;
+            int dx2Pixels = clientAnchor.getDx2() / Units.EMU_PER_PIXEL;
+            int dy2Pixels = clientAnchor.getDy2() / Units.EMU_PER_PIXEL;
+            String position = clientAnchor.getCol1() + ", " + dx1Pixels + ", " + clientAnchor.getRow1() + ", " + dy1Pixels + ", " +
+                    clientAnchor.getCol2() + ", " + dx2Pixels + ", " + clientAnchor.getRow2() + ", " + dy2Pixels;
+            vmlShape.getClientDataArray(0).setAnchorArray(0, position);
+        }
+        CellAddress ref = new CellAddress(clientAnchor.getRow1(), clientAnchor.getCol1());
+
+        if (findCellComment(ref) != null) {
+            throw new IllegalArgumentException("Multiple cell comments in one cell are not allowed, cell: " + ref);
+        }
+
+        return new XSSFComment(this, newComment(ref), vmlShape);
+    }
+
+    /**
      * Refresh Map<CellAddress, CTComment> commentRefs cache,
      * Calls that use the commentRefs cache will perform in O(1)
      * time rather than O(n) lookup time for List<CTComment> comments.

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java?rev=1895104&r1=1895103&r2=1895104&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java Wed Nov 17 13:00:09 2021
@@ -42,7 +42,6 @@ import org.apache.poi.openxml4j.opc.Pack
 import org.apache.poi.openxml4j.opc.TargetMode;
 import org.apache.poi.ss.usermodel.ClientAnchor;
 import org.apache.poi.ss.usermodel.Drawing;
-import org.apache.poi.ss.util.CellAddress;
 import org.apache.poi.ss.util.ImageUtils;
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.Units;
@@ -384,29 +383,8 @@ public final class XSSFDrawing extends P
         XSSFClientAnchor ca = (XSSFClientAnchor) anchor;
         XSSFSheet sheet = getSheet();
 
-        // create comments and vmlDrawing parts if they don't exist
         CommentsTable comments = sheet.getCommentsTable(true);
-        XSSFVMLDrawing vml = sheet.getVMLDrawing(true);
-        com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape();
-        if (ca.isSet()) {
-            // convert offsets from emus to pixels since we get a
-            // DrawingML-anchor
-            // but create a VML Drawing
-            int dx1Pixels = ca.getDx1() / Units.EMU_PER_PIXEL;
-            int dy1Pixels = ca.getDy1() / Units.EMU_PER_PIXEL;
-            int dx2Pixels = ca.getDx2() / Units.EMU_PER_PIXEL;
-            int dy2Pixels = ca.getDy2() / Units.EMU_PER_PIXEL;
-            String position = ca.getCol1() + ", " + dx1Pixels + ", " + ca.getRow1() + ", " + dy1Pixels + ", " + ca
-                .getCol2() + ", " + dx2Pixels + ", " + ca.getRow2() + ", " + dy2Pixels;
-            vmlShape.getClientDataArray(0).setAnchorArray(0, position);
-        }
-        CellAddress ref = new CellAddress(ca.getRow1(), ca.getCol1());
-
-        if (comments.findCellComment(ref) != null) {
-            throw new IllegalArgumentException("Multiple cell comments in one cell are not allowed, cell: " + ref);
-        }
-
-        return new XSSFComment(comments, comments.newComment(ref), vmlShape);
+        return comments.createNewComment(getSheet(), ca);
     }
 
     /**

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1895104&r1=1895103&r2=1895104&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Wed Nov 17 13:00:09 2021
@@ -570,13 +570,14 @@ public class XSSFSheet extends POIXMLDoc
     }
 
     /**
-     * Get VML drawing for this sheet (aka 'legacy' drawing)
+     * Get VML drawing for this sheet (aka 'legacy' drawing). This method is for internal POI use only.
      *
      * @param autoCreate if true, then a new VML drawing part is created
      *
      * @return the VML drawing of {@code null} if the drawing was not found and autoCreate=false
      */
-    protected XSSFVMLDrawing getVMLDrawing(boolean autoCreate) {
+    @Internal
+    public XSSFVMLDrawing getVMLDrawing(boolean autoCreate) {
         XSSFVMLDrawing drawing = null;
         CTLegacyDrawing ctDrawing = getCTLegacyDrawing();
         if(ctDrawing == null) {

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java?rev=1895104&r1=1895103&r2=1895104&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java Wed Nov 17 13:00:09 2021
@@ -49,6 +49,7 @@ import com.microsoft.schemas.vml.STStrok
 import org.apache.poi.ooxml.POIXMLDocumentPart;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.schemas.vmldrawing.XmlDocument;
+import org.apache.poi.util.Internal;
 import org.apache.poi.util.ReplacingInputStream;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlException;
@@ -236,7 +237,11 @@ public final class XSSFVMLDrawing extend
         grpCur.dispose();
     }
 
-    protected CTShape newCommentShape(){
+    /**
+     * This method is for internal POI use only.
+     */
+    @Internal
+    public CTShape newCommentShape() {
         CTGroup grp = CTGroup.Factory.newInstance();
 
         CTShape shape = grp.addNewShape();

Modified: poi/trunk/poi/src/main/java9/module-info.class
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java9/module-info.class?rev=1895104&r1=1895103&r2=1895104&view=diff
==============================================================================
Binary files - no diff available.



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