mirror of https://github.com/apache/poi.git
added modifiers for anchor type to XSSFClientAnchor
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@756965 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aca8d5187d
commit
a7816b7bdb
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -23,6 +23,44 @@ package org.apache.poi.ss.usermodel;
|
|||
* @author Yegor Kozlov
|
||||
*/
|
||||
public interface ClientAnchor {
|
||||
/**
|
||||
* Move and Resize With Anchor Cells
|
||||
* <p>
|
||||
* 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)
|
||||
* </p>
|
||||
*/
|
||||
public static final int MOVE_AND_RESIZE = 0;
|
||||
|
||||
/**
|
||||
* Move With Cells but Do Not Resize
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*/
|
||||
public static final int MOVE_DONT_RESIZE = 2;
|
||||
|
||||
/**
|
||||
* Do Not Move or Resize With Underlying Rows/Columns
|
||||
* <p>
|
||||
* Specifies that the current start and end positions shall
|
||||
* be maintained with respect to the distances from the
|
||||
* absolute start point of the worksheet.
|
||||
* </p>
|
||||
* <p>
|
||||
* If additional rows/columns are added before the
|
||||
* drawing, the drawing shall move its anchors as needed
|
||||
* to maintain this same absolute position.
|
||||
* </p>
|
||||
*/
|
||||
public static final int DONT_MOVE_AND_RESIZE = 3;
|
||||
|
||||
/**
|
||||
* Returns the column (0 based) of the first cell.
|
||||
|
@ -135,4 +173,30 @@ public interface ClientAnchor {
|
|||
* @param dx2 the x coordinate within the second cell
|
||||
*/
|
||||
public void setDx2(int dx2);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the anchor type
|
||||
* <p>
|
||||
* 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
|
||||
* </p>
|
||||
* @param anchorType the anchor type
|
||||
* @see #MOVE_AND_RESIZE
|
||||
* @see #MOVE_DONT_RESIZE
|
||||
* @see #DONT_MOVE_AND_RESIZE
|
||||
*/
|
||||
public void setAnchorType( int anchorType );
|
||||
|
||||
/**
|
||||
* Gets the anchor type
|
||||
* <p>
|
||||
* 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
|
||||
* </p>
|
||||
* @return the anchor type
|
||||
* @see #MOVE_AND_RESIZE
|
||||
* @see #MOVE_DONT_RESIZE
|
||||
* @see #DONT_MOVE_AND_RESIZE
|
||||
*/
|
||||
public int getAnchorType();
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.poi.ss.usermodel.ClientAnchor;
|
|||
* @author Yegor Kozlov
|
||||
*/
|
||||
public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
|
||||
private int anchorType;
|
||||
|
||||
/**
|
||||
* Starting anchor point
|
||||
|
@ -193,4 +194,26 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
|
|||
protected void setTo(CTMarker to){
|
||||
cell2 = to;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the anchor type
|
||||
* <p>
|
||||
* 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
|
||||
*/
|
||||
public void setAnchorType( int anchorType )
|
||||
{
|
||||
this.anchorType = anchorType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the anchor type
|
||||
* <p>
|
||||
* 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
|
||||
*/
|
||||
public int getAnchorType()
|
||||
{
|
||||
return anchorType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -138,7 +138,6 @@ public class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||
PackageRelationship rel = addPictureReference(pictureIndex);
|
||||
|
||||
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
|
||||
ctAnchor.setEditAs(STEditAs.ONE_CELL);
|
||||
CTPicture ctShape = ctAnchor.addNewPic();
|
||||
ctShape.set(XSSFPicture.prototype());
|
||||
|
||||
|
@ -235,6 +234,14 @@ public class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||
ctAnchor.addNewClientData();
|
||||
anchor.setTo(ctAnchor.getTo());
|
||||
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;
|
||||
default: aditAs = STEditAs.ONE_CELL;
|
||||
}
|
||||
ctAnchor.setEditAs(aditAs);
|
||||
return ctAnchor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,12 @@
|
|||
package org.apache.poi.xssf.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||
import org.apache.poi.POIXMLDocumentPart;
|
||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
|
||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
|
||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
|
@ -46,10 +45,17 @@ public class TestXSSFPicture extends TestCase {
|
|||
assertTrue(Arrays.equals(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());
|
||||
|
||||
XSSFPicture shape = drawing.createPicture(anchor, jpegIdx);
|
||||
assertTrue(anchor.equals(shape.getAnchor()));
|
||||
assertNotNull(shape.getPictureData());
|
||||
assertTrue(Arrays.equals(jpegData, shape.getPictureData().getData()));
|
||||
|
||||
CTTwoCellAnchor ctShapeHolder = drawing.getCTDrawing().getTwoCellAnchorArray(0);
|
||||
// STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE
|
||||
assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue