aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-11-17 13:00:09 +0000
committerPJ Fanning <fanningpj@apache.org>2021-11-17 13:00:09 +0000
commitfd1b5c87cf7ec8aad5905c844dcba1e95f9bbc17 (patch)
treea39cfac83a1972f64561b4f10285cec613218e19
parent8bde66c3e6224dcb0ec8210d41e459e671306765 (diff)
downloadpoi-fd1b5c87cf7ec8aad5905c844dcba1e95f9bbc17.tar.gz
poi-fd1b5c87cf7ec8aad5905c844dcba1e95f9bbc17.zip
try to make comments table more extensible
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895104 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java36
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java24
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java5
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java7
-rw-r--r--poi/src/main/java9/module-info.classbin3385 -> 3421 bytes
5 files changed, 46 insertions, 26 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
index 016eb2c3b8..876339f2fa 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
@@ -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 POIXMLDocumentPart implements Comments {
}
/**
+ * 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.
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
index ee953ba50c..99a0bed281 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
@@ -42,7 +42,6 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper;
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 POIXMLDocumentPart implements Drawing<XSS
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);
}
/**
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index 67f86991fa..e716283ef1 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -570,13 +570,14 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
}
/**
- * 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) {
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
index 59aa229853..2adda36768 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
@@ -49,6 +49,7 @@ import com.microsoft.schemas.vml.STStrokeJoinStyle;
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 extends POIXMLDocumentPart {
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();
diff --git a/poi/src/main/java9/module-info.class b/poi/src/main/java9/module-info.class
index a27868cdf4..7ca4ecd882 100644
--- a/poi/src/main/java9/module-info.class
+++ b/poi/src/main/java9/module-info.class
Binary files differ