From ef017d70c17b663c17bd52773b0b09a5f67c22fe Mon Sep 17 00:00:00 2001
From: Javen O'Neal
@@ -30,9 +31,10 @@ public interface ClientAnchor {
* resize to maintain its row and column anchors (i.e. the
* object is anchored to the actual from and to row and column)
*
@@ -44,8 +46,9 @@ public interface ClientAnchor {
* If additional rows/columns are added between the from and to locations of the drawing,
* the drawing shall move its to anchors as needed to maintain this same absolute size.
*
+ * Specifies that the current drawing shall move and + * resize to maintain its row and column anchors (i.e. the + * object is anchored to the actual from and to row and column) + *
+ */ + MOVE_AND_RESIZE(0), + + /** + * Don't Move but do Resize With Anchor Cells (1) + *+ * Specifies that the current drawing shall not move with its + * row and column, but should be resized. This option is not normally + * used, but is included for completeness. + *
+ */ + DONT_MOVE_DO_RESIZE(1), + + /** + * Move With Cells but Do Not Resize (2) + *+ * Specifies that the current drawing shall move with its + * row and column (i.e. the object is anchored to the + * actual from row and column), but that the size shall remain absolute. + *
+ *+ * If additional rows/columns are added between the from and to locations of the drawing, + * the drawing shall move its to anchors as needed to maintain this same absolute size. + *
+ */ + MOVE_DONT_RESIZE(2), + + /** + * Do Not Move or Resize With Underlying Rows/Columns (3) + *+ * Specifies that the current start and end positions shall + * be maintained with respect to the distances from the + * absolute start point of the worksheet. + *
+ *+ * If additional rows/columns are added before the + * drawing, the drawing shall move its anchors as needed + * to maintain this same absolute position. + *
+ */ + DONT_MOVE_AND_RESIZE(3); + + public final short value; + AnchorType(int value) { + this.value = (short) value; + } + + public static AnchorType byId(int value) { + return values()[value]; + } + } + /** * Returns the column (0 based) of the first cell. * @@ -209,26 +276,14 @@ public interface ClientAnchor { /** * Sets the anchor type - *- * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. - *
- * @param anchorType the anchor type - * @see #MOVE_AND_RESIZE - * @see #MOVE_DONT_RESIZE - * @see #DONT_MOVE_AND_RESIZE + * @param anchorType the anchor type to set */ - public void setAnchorType( int anchorType ); + public void setAnchorType( AnchorType anchorType ); /** * Gets the anchor type - *- * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. - *
* @return the anchor type - * @see #MOVE_AND_RESIZE - * @see #MOVE_DONT_RESIZE - * @see #DONT_MOVE_AND_RESIZE */ - public int getAnchorType(); + public AnchorType getAnchorType(); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java index 14dbaff14d..8045912abf 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java @@ -28,7 +28,8 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; * @author Yegor Kozlov */ public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { - private int anchorType; + private AnchorType DEFAULT_ANCHOR_TYPE = AnchorType.MOVE_AND_RESIZE; + private AnchorType anchorType; /** * Starting anchor point @@ -44,6 +45,7 @@ public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { * Creates a new client anchor and defaults all the anchor positions to 0. */ public XSSFClientAnchor() { + anchorType = DEFAULT_ANCHOR_TYPE; cell1 = CTMarker.Factory.newInstance(); cell1.setCol(0); cell1.setColOff(0); @@ -88,6 +90,7 @@ public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { * @param cell2 ending anchor point */ protected XSSFClientAnchor(CTMarker cell1, CTMarker cell2) { + anchorType = DEFAULT_ANCHOR_TYPE; this.cell1 = cell1; this.cell2 = cell2; } @@ -214,20 +217,20 @@ public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { /** * Sets the anchor type - *- * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. + * @param anchorType the anchor type to set */ - public void setAnchorType( int anchorType ) + @Override + public void setAnchorType( AnchorType anchorType ) { this.anchorType = anchorType; } /** * Gets the anchor type - *
- * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. + * @return the anchor type */ - public int getAnchorType() + @Override + public AnchorType getAnchorType() { return anchorType; } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java index ba45cfff48..64dfc5dd00 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java @@ -34,7 +34,6 @@ 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.CellReference; import org.apache.poi.util.Internal; import org.apache.poi.util.Units; import org.apache.poi.xssf.model.CommentsTable; @@ -373,9 +372,9 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing { anchor.setFrom(ctAnchor.getFrom()); STEditAs.Enum aditAs; switch(anchor.getAnchorType()) { - case ClientAnchor.DONT_MOVE_AND_RESIZE: aditAs = STEditAs.ABSOLUTE; break; - case ClientAnchor.MOVE_AND_RESIZE: aditAs = STEditAs.TWO_CELL; break; - case ClientAnchor.MOVE_DONT_RESIZE: aditAs = STEditAs.ONE_CELL; break; + case DONT_MOVE_AND_RESIZE: aditAs = STEditAs.ABSOLUTE; break; + case MOVE_AND_RESIZE: aditAs = STEditAs.TWO_CELL; break; + case MOVE_DONT_RESIZE: aditAs = STEditAs.ONE_CELL; break; default: aditAs = STEditAs.ONE_CELL; } ctAnchor.setEditAs(aditAs); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java index 7f6db45517..edaa974a2c 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java @@ -23,7 +23,7 @@ import java.io.IOException; import java.util.List; import org.apache.poi.ss.usermodel.BaseTestPicture; -import org.apache.poi.ss.usermodel.ClientAnchor; +import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.util.LocaleUtil; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; @@ -70,9 +70,9 @@ public final class TestXSSFPicture extends BaseTestPicture { assertArrayEquals(jpegData, pictures.get(jpegIdx).getData()); XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30); - assertEquals(ClientAnchor.MOVE_AND_RESIZE, anchor.getAnchorType()); - anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE); - assertEquals(ClientAnchor.DONT_MOVE_AND_RESIZE, anchor.getAnchorType()); + assertEquals(AnchorType.MOVE_AND_RESIZE, anchor.getAnchorType()); + anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); + assertEquals(AnchorType.DONT_MOVE_AND_RESIZE, anchor.getAnchorType()); XSSFPicture shape = drawing.createPicture(anchor, jpegIdx); assertTrue(anchor.equals(shape.getAnchor())); diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java index c829159a5c..197f2f1008 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java +++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java @@ -35,6 +35,7 @@ import org.apache.poi.hssf.record.CommonObjectDataSubRecord; import org.apache.poi.hssf.record.EscherAggregate; import org.apache.poi.hssf.record.ObjRecord; import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.util.HexDump; @@ -148,8 +149,8 @@ public class TestDrawingShapes extends TestCase { HSSFPatriarch drawing = sheet.createDrawingPatriarch(); HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 50, 50, (short) 2, 2, (short) 4, 4); - anchor.setAnchorType(2); - assertEquals(anchor.getAnchorType(), 2); + anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE); + assertEquals(AnchorType.MOVE_DONT_RESIZE, anchor.getAnchorType()); HSSFSimpleShape rectangle = drawing.createSimpleShape(anchor); rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE); diff --git a/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java b/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java index 481196e775..84ef3c4115 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java +++ b/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java @@ -21,6 +21,7 @@ import junit.framework.TestCase; import org.apache.poi.ddf.*; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; /** * @author Evgeniy Berlog @@ -30,7 +31,7 @@ public class TestHSSFAnchor extends TestCase { public void testDefaultValues(){ HSSFClientAnchor clientAnchor = new HSSFClientAnchor(); - assertEquals(clientAnchor.getAnchorType(), 0); + assertEquals(clientAnchor.getAnchorType(), AnchorType.MOVE_AND_RESIZE); assertEquals(clientAnchor.getCol1(), 0); assertEquals(clientAnchor.getCol2(), 0); assertEquals(clientAnchor.getDx1(), 0); @@ -41,7 +42,7 @@ public class TestHSSFAnchor extends TestCase { assertEquals(clientAnchor.getRow2(), 0); clientAnchor = new HSSFClientAnchor(new EscherClientAnchorRecord()); - assertEquals(clientAnchor.getAnchorType(), 0); + assertEquals(clientAnchor.getAnchorType(), AnchorType.MOVE_AND_RESIZE); assertEquals(clientAnchor.getCol1(), 0); assertEquals(clientAnchor.getCol2(), 0); assertEquals(clientAnchor.getDx1(), 0); @@ -143,7 +144,7 @@ public class TestHSSFAnchor extends TestCase { HSSFPatriarch drawing = sheet.createDrawingPatriarch(); HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 200, 200, (short)2, 2, (short)15, 15); - anchor.setAnchorType(2); + anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE); HSSFSimpleShape rectangle = drawing.createSimpleShape(anchor); rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE); @@ -362,9 +363,9 @@ public class TestHSSFAnchor extends TestCase { clientAnchor2.setRow2(7); assertEquals(clientAnchor1, clientAnchor2); - clientAnchor2.setAnchorType(3); + clientAnchor2.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); assertNotSame(clientAnchor1, clientAnchor2); - clientAnchor2.setAnchorType(0); + clientAnchor2.setAnchorType(AnchorType.MOVE_AND_RESIZE); assertEquals(clientAnchor1, clientAnchor2); HSSFChildAnchor childAnchor1 = new HSSFChildAnchor(0, 1, 2, 3); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 30f6343197..d9027d2ff9 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -70,6 +70,7 @@ import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Name; @@ -2966,7 +2967,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { assertNotNull("Did not find sheet", sheet); HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch(); HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 10, 22); - anchor.setAnchorType(2); + anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE); patriarch.createPicture(anchor, pict); // Write out destination file diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java index c51ca93892..e3428cc920 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java @@ -18,6 +18,7 @@ package org.apache.poi.hssf.usermodel; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import junit.framework.AssertionFailedError; import junit.framework.TestCase; @@ -56,7 +57,7 @@ public final class TestHSSFPatriarch extends TestCase { // 3. Use patriarch HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 245, (short) 1, 1, (short) 1, 2); - anchor.setAnchorType(3); + anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png"); int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG); patr.createPicture(anchor, idx1); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java b/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java index 262b66d3a4..fea681e749 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java @@ -31,7 +31,7 @@ import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.Ole10Native; import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.apache.poi.ss.usermodel.ClientAnchor; +import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.util.LocaleUtil; import org.junit.Test; @@ -88,25 +88,25 @@ public final class TestOLE2Embeding { CreationHelper ch = wb1.getCreationHelper(); HSSFClientAnchor anchor = (HSSFClientAnchor)ch.createClientAnchor(); anchor.setAnchor((short)(2+coloffset), 1+rowoffset, 0, 0, (short)(3+coloffset), 5+rowoffset, 0, 0); - anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE); + anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); patriarch.createObjectData(anchor, pptIdx, imgPPT); anchor = (HSSFClientAnchor)ch.createClientAnchor(); anchor.setAnchor((short)(5+coloffset), 1+rowoffset, 0, 0, (short)(6+coloffset), 5+rowoffset, 0, 0); - anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE); + anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); patriarch.createObjectData(anchor, xlsIdx, imgIdx); anchor = (HSSFClientAnchor)ch.createClientAnchor(); anchor.setAnchor((short)(3+coloffset), 10+rowoffset, 0, 0, (short)(5+coloffset), 11+rowoffset, 0, 0); - anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE); + anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); patriarch.createObjectData(anchor, txtIdx, imgIdx); anchor = (HSSFClientAnchor)ch.createClientAnchor(); anchor.setAnchor((short)(1+coloffset), -2+rowoffset, 0, 0, (short)(7+coloffset), 14+rowoffset, 0, 0); - anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE); + anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); HSSFSimpleShape circle = patriarch.createSimpleShape(anchor); circle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL); -- 2.39.5