You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by vi...@apache.org on 2015/10/19 07:59:38 UTC
svn commit: r1709355 [4/4] - in /poi/trunk/src/ooxml:
java/org/apache/poi/xdgf/exceptions/ java/org/apache/poi/xdgf/geom/
java/org/apache/poi/xdgf/usermodel/
java/org/apache/poi/xdgf/usermodel/section/
java/org/apache/poi/xdgf/usermodel/section/geometr...
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/RelQuadBezTo.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/RelQuadBezTo.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/RelQuadBezTo.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/RelQuadBezTo.java Mon Oct 19 05:59:37 2015
@@ -25,90 +25,98 @@ import com.microsoft.schemas.office.visi
import com.microsoft.schemas.office.visio.x2012.main.RowType;
/**
- * Contains the x- and y-coordinates of the endpoint of a quadratic Bézier curve
- * relative to the shapeâs width and height and the x- and y-coordinates of the
- * control point of the curve relative shapeâs width and height.
+ * Contains the x- and y-coordinates of the endpoint of a quadratic Bezier curve
+ * relative to the shape's width and height and the x- and y-coordinates of the
+ * control point of the curve relative shape's width and height.
*/
public class RelQuadBezTo implements GeometryRow {
-
- RelQuadBezTo _master = null;
-
- // The x-coordinate of the ending vertex of a quadratic Bézier curve relative to the width of the shape.
- Double x = null;
-
- // The y-coordinate of the ending vertex of a quadratic Bézier curve relative to the height of the shape.
- Double y = null;
-
- // The x-coordinate of the curveâs control point relative to the shapeâs width; a point on the arc. The control point is best located about halfway between the beginning and ending vertices of the arc.
- Double a = null;
-
- // The y-coordinate of a curveâs control point relative to the shapeâs height.
- Double b = null;
-
- Boolean deleted = null;
-
- // TODO: support formulas
-
- public RelQuadBezTo(RowType row) {
-
- if (row.isSetDel()) deleted = row.getDel();
-
- for (CellType cell: row.getCellArray()) {
- String cellName = cell.getN();
-
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("B")) {
- b = XDGFCell.parseDoubleValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName + "' in RelQuadBezTo row");
- }
- }
- }
-
- public boolean getDel() {
- if (deleted != null)
- return deleted;
-
- if (_master != null)
- return _master.getDel();
-
- return false;
- }
-
- public Double getX() {
- return x == null ? _master.x : x;
- }
-
- public Double getY() {
- return y == null ? _master.y : y;
- }
-
- public Double getA() {
- return a == null ? _master.a : a;
- }
-
- public Double getB() {
- return b == null ? _master.b : b;
- }
-
- @Override
- public void setupMaster(GeometryRow row) {
- _master = (RelQuadBezTo) row;
- }
-
- @Override
- public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
-
- if (getDel()) return;
-
- double w = parent.getWidth();
- double h = parent.getHeight();
-
- path.quadTo(getA()*w, getB()*h, getX()*w, getY()*h);
- }
+
+ RelQuadBezTo _master = null;
+
+ // The x-coordinate of the ending vertex of a quadratic Bezier curve
+ // relative to the width of the shape.
+ Double x = null;
+
+ // The y-coordinate of the ending vertex of a quadratic Bezier curve
+ // relative to the height of the shape.
+ Double y = null;
+
+ // The x-coordinate of the curve's control point relative to the shape's
+ // width; a point on the arc. The control point is best located about
+ // halfway between the beginning and ending vertices of the arc.
+ Double a = null;
+
+ // The y-coordinate of a curve's control point relative to the shape's
+ // height.
+ Double b = null;
+
+ Boolean deleted = null;
+
+ // TODO: support formulas
+
+ public RelQuadBezTo(RowType row) {
+
+ if (row.isSetDel())
+ deleted = row.getDel();
+
+ for (CellType cell : row.getCellArray()) {
+ String cellName = cell.getN();
+
+ if (cellName.equals("X")) {
+ x = XDGFCell.parseDoubleValue(cell);
+ } else if (cellName.equals("Y")) {
+ y = XDGFCell.parseDoubleValue(cell);
+ } else if (cellName.equals("A")) {
+ a = XDGFCell.parseDoubleValue(cell);
+ } else if (cellName.equals("B")) {
+ b = XDGFCell.parseDoubleValue(cell);
+ } else {
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in RelQuadBezTo row");
+ }
+ }
+ }
+
+ public boolean getDel() {
+ if (deleted != null)
+ return deleted;
+
+ if (_master != null)
+ return _master.getDel();
+
+ return false;
+ }
+
+ public Double getX() {
+ return x == null ? _master.x : x;
+ }
+
+ public Double getY() {
+ return y == null ? _master.y : y;
+ }
+
+ public Double getA() {
+ return a == null ? _master.a : a;
+ }
+
+ public Double getB() {
+ return b == null ? _master.b : b;
+ }
+
+ @Override
+ public void setupMaster(GeometryRow row) {
+ _master = (RelQuadBezTo) row;
+ }
+
+ @Override
+ public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
+
+ if (getDel())
+ return;
+
+ double w = parent.getWidth();
+ double h = parent.getHeight();
+
+ path.quadTo(getA() * w, getB() * h, getX() * w, getY() * h);
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineKnot.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineKnot.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineKnot.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineKnot.java Mon Oct 19 05:59:37 2015
@@ -25,78 +25,82 @@ import com.microsoft.schemas.office.visi
import com.microsoft.schemas.office.visio.x2012.main.RowType;
/**
- * Contains x- and y-coordinates for a spline's control point and a spline's knot.
+ * Contains x- and y-coordinates for a spline's control point and a spline's
+ * knot.
*/
public class SplineKnot implements GeometryRow {
-
- SplineKnot _master = null;
-
- // The x-coordinate of a control point.
- Double x = null;
-
- // The y-coordinate of a control point.
- Double y = null;
-
- // One of the spline's knots (other than the last one or the first two).
- Double a = null;
-
- Boolean deleted = null;
-
- // TODO: support formulas
-
- public SplineKnot(RowType row) {
-
- if (row.isSetDel()) deleted = row.getDel();
-
- for (CellType cell: row.getCellArray()) {
- String cellName = cell.getN();
-
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName + "' in SplineKnot row");
- }
- }
- }
-
- public boolean getDel() {
- if (deleted != null)
- return deleted;
-
- if (_master != null)
- return _master.getDel();
-
- return false;
- }
-
- public Double getX() {
- return x == null ? _master.x : x;
- }
-
- public Double getY() {
- return y == null ? _master.y : y;
- }
-
- public Double getA() {
- return a == null ? _master.a : a;
- }
-
- @Override
- public void setupMaster(GeometryRow row) {
- _master = (SplineKnot) row;
- }
-
- @Override
- public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
- throw new POIXMLException("Error: Use SplineRenderer!");
- }
-
- @Override
- public String toString() {
- return "{SplineKnot x=" + getX() + " y=" + getY() + " a=" + getA() + "}";
- }
+
+ SplineKnot _master = null;
+
+ // The x-coordinate of a control point.
+ Double x = null;
+
+ // The y-coordinate of a control point.
+ Double y = null;
+
+ // One of the spline's knots (other than the last one or the first two).
+ Double a = null;
+
+ Boolean deleted = null;
+
+ // TODO: support formulas
+
+ public SplineKnot(RowType row) {
+
+ if (row.isSetDel())
+ deleted = row.getDel();
+
+ for (CellType cell : row.getCellArray()) {
+ String cellName = cell.getN();
+
+ if (cellName.equals("X")) {
+ x = XDGFCell.parseDoubleValue(cell);
+ } else if (cellName.equals("Y")) {
+ y = XDGFCell.parseDoubleValue(cell);
+ } else if (cellName.equals("A")) {
+ a = XDGFCell.parseDoubleValue(cell);
+ } else {
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in SplineKnot row");
+ }
+ }
+ }
+
+ public boolean getDel() {
+ if (deleted != null)
+ return deleted;
+
+ if (_master != null)
+ return _master.getDel();
+
+ return false;
+ }
+
+ public Double getX() {
+ return x == null ? _master.x : x;
+ }
+
+ public Double getY() {
+ return y == null ? _master.y : y;
+ }
+
+ public Double getA() {
+ return a == null ? _master.a : a;
+ }
+
+ @Override
+ public void setupMaster(GeometryRow row) {
+ _master = (SplineKnot) row;
+ }
+
+ @Override
+ public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
+ throw new POIXMLException("Error: Use SplineRenderer!");
+ }
+
+ @Override
+ public String toString() {
+ return "{SplineKnot x=" + getX() + " y=" + getY() + " a=" + getA()
+ + "}";
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineStart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineStart.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineStart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineStart.java Mon Oct 19 05:59:37 2015
@@ -28,105 +28,105 @@ import com.microsoft.schemas.office.visi
* knot, its first knot, the last knot, and the degree of the spline.
*/
public class SplineStart implements GeometryRow {
-
- SplineStart _master = null;
-
- // The x-coordinate of a spline's second control point.
- Double x = null;
-
- // The y-coordinate of a spline's second control point.
- Double y = null;
-
- // The second knot of the spline.
- Double a = null;
-
- // The first knot of a spline.
- Double b = null;
-
- // The last knot of a spline.
- Double c = null;
-
- // The degree of a spline (an integer from 1 to 25).
- Integer d = null;
-
- Boolean deleted = null;
-
- // TODO: support formulas
-
- public SplineStart(RowType row) {
-
- if (row.isSetDel()) deleted = row.getDel();
-
- for (CellType cell: row.getCellArray()) {
- String cellName = cell.getN();
-
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("B")) {
- b = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("C")) {
- c = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("D")) {
- d = XDGFCell.parseIntegerValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName + "' in SplineStart row");
- }
- }
- }
-
- public boolean getDel() {
- if (deleted != null)
- return deleted;
-
- if (_master != null)
- return _master.getDel();
-
- return false;
- }
-
- public Double getX() {
- return x == null ? _master.x : x;
- }
-
- public Double getY() {
- return y == null ? _master.y : y;
- }
-
- public Double getA() {
- return a == null ? _master.a : a;
- }
-
- public Double getB() {
- return b == null ? _master.b : b;
- }
-
- public Double getC() {
- return c == null ? _master.c : c;
- }
-
- public Integer getD() {
- return d == null ? _master.d : d;
- }
-
- @Override
- public void setupMaster(GeometryRow row) {
- _master = (SplineStart) row;
- }
-
- @Override
- public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
- throw new POIXMLException("Error: Use SplineRenderer!");
- }
-
- @Override
- public String toString() {
- return "{SplineStart x=" + getX() + " y=" + getY() +
- " a=" + getA() + " b=" + getB() +
- " c=" + getC() + " d=" + getD() +
- "}";
- }
+
+ SplineStart _master = null;
+
+ // The x-coordinate of a spline's second control point.
+ Double x = null;
+
+ // The y-coordinate of a spline's second control point.
+ Double y = null;
+
+ // The second knot of the spline.
+ Double a = null;
+
+ // The first knot of a spline.
+ Double b = null;
+
+ // The last knot of a spline.
+ Double c = null;
+
+ // The degree of a spline (an integer from 1 to 25).
+ Integer d = null;
+
+ Boolean deleted = null;
+
+ // TODO: support formulas
+
+ public SplineStart(RowType row) {
+
+ if (row.isSetDel())
+ deleted = row.getDel();
+
+ for (CellType cell : row.getCellArray()) {
+ String cellName = cell.getN();
+
+ if (cellName.equals("X")) {
+ x = XDGFCell.parseDoubleValue(cell);
+ } else if (cellName.equals("Y")) {
+ y = XDGFCell.parseDoubleValue(cell);
+ } else if (cellName.equals("A")) {
+ a = XDGFCell.parseDoubleValue(cell);
+ } else if (cellName.equals("B")) {
+ b = XDGFCell.parseDoubleValue(cell);
+ } else if (cellName.equals("C")) {
+ c = XDGFCell.parseDoubleValue(cell);
+ } else if (cellName.equals("D")) {
+ d = XDGFCell.parseIntegerValue(cell);
+ } else {
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in SplineStart row");
+ }
+ }
+ }
+
+ public boolean getDel() {
+ if (deleted != null)
+ return deleted;
+
+ if (_master != null)
+ return _master.getDel();
+
+ return false;
+ }
+
+ public Double getX() {
+ return x == null ? _master.x : x;
+ }
+
+ public Double getY() {
+ return y == null ? _master.y : y;
+ }
+
+ public Double getA() {
+ return a == null ? _master.a : a;
+ }
+
+ public Double getB() {
+ return b == null ? _master.b : b;
+ }
+
+ public Double getC() {
+ return c == null ? _master.c : c;
+ }
+
+ public Integer getD() {
+ return d == null ? _master.d : d;
+ }
+
+ @Override
+ public void setupMaster(GeometryRow row) {
+ _master = (SplineStart) row;
+ }
+
+ @Override
+ public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
+ throw new POIXMLException("Error: Use SplineRenderer!");
+ }
+
+ @Override
+ public String toString() {
+ return "{SplineStart x=" + getX() + " y=" + getY() + " a=" + getA()
+ + " b=" + getB() + " c=" + getC() + " d=" + getD() + "}";
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeDataAcceptor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeDataAcceptor.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeDataAcceptor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeDataAcceptor.java Mon Oct 19 05:59:37 2015
@@ -21,49 +21,45 @@ import org.apache.poi.xdgf.usermodel.XDG
/**
* This acceptor only allows traversal to shapes that have useful data
- * associated with them, and tries to elide details that aren't useful
- * when analyzing the content of a document.
- *
+ * associated with them, and tries to elide details that aren't useful when
+ * analyzing the content of a document.
+ *
* Useful is subjective of course, and is defined as any of:
- *
- * - Has non-empty text
- * - Is a 1d shape, such as a line
- * - User specified shapes
- * - The outline of stencil objects
- * - TODO
+ *
+ * - Has non-empty text - Is a 1d shape, such as a line - User specified shapes
+ * - The outline of stencil objects - TODO
*/
public class ShapeDataAcceptor implements ShapeVisitorAcceptor {
- @Override
- public boolean accept(XDGFShape shape) {
-
- if (shape.isDeleted())
- return false;
-
- // text is interesting
- if (shape.hasText() && shape.getTextAsString().length() != 0)
- return true;
-
- // 1d shapes are interesting, they create connections
- if (shape.isShape1D())
- return true;
-
- // User specified shapes are interesting
- if (!shape.hasMaster() && !shape.hasMasterShape())
- return true;
-
- if (shape.hasMaster() && !shape.hasMasterShape())
- return true;
-
- // include stencil content, but try to elide stencil interiors
- //if (shape.getXmlObject().isSetMaster())
- // return true;
-
- if (shape.hasMasterShape() && shape.getMasterShape().isTopmost())
- return true;
-
- return false;
- }
-
-
+ @Override
+ public boolean accept(XDGFShape shape) {
+
+ if (shape.isDeleted())
+ return false;
+
+ // text is interesting
+ if (shape.hasText() && shape.getTextAsString().length() != 0)
+ return true;
+
+ // 1d shapes are interesting, they create connections
+ if (shape.isShape1D())
+ return true;
+
+ // User specified shapes are interesting
+ if (!shape.hasMaster() && !shape.hasMasterShape())
+ return true;
+
+ if (shape.hasMaster() && !shape.hasMasterShape())
+ return true;
+
+ // include stencil content, but try to elide stencil interiors
+ // if (shape.getXmlObject().isSetMaster())
+ // return true;
+
+ if (shape.hasMasterShape() && shape.getMasterShape().isTopmost())
+ return true;
+
+ return false;
+ }
+
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeDebuggerRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeDebuggerRenderer.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeDebuggerRenderer.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeDebuggerRenderer.java Mon Oct 19 05:59:37 2015
@@ -25,46 +25,45 @@ import org.apache.poi.xdgf.usermodel.XDG
public class ShapeDebuggerRenderer extends ShapeRenderer {
- ShapeVisitorAcceptor _debugAcceptor = null;
-
- public ShapeDebuggerRenderer() {
- super();
- }
-
- public ShapeDebuggerRenderer(Graphics2D g) {
- super(g);
- }
-
- public void setDebugAcceptor(ShapeVisitorAcceptor acceptor) {
- _debugAcceptor = acceptor;
- }
-
- @Override
- protected Path2D drawPath(XDGFShape shape){
-
- Path2D path = super.drawPath(shape);
- if (_debugAcceptor == null || _debugAcceptor.accept(shape)) {
-
- // show numbers to associate shapes with ids.. doesn't always work
- Font f = _graphics.getFont();
- _graphics.scale(1, -1);
- _graphics.setFont(f.deriveFont(0.05F));
-
- String shapeId = "" + shape.getID();
- float shapeOffset = -0.1F;
-
- if (shape.hasMasterShape()) {
- shapeId += " MS:" + shape.getMasterShape().getID();
- shapeOffset -= 0.15F;
- }
-
-
- _graphics.drawString(shapeId, shapeOffset, 0);
- _graphics.setFont(f);
- _graphics.scale(1, -1);
- }
-
- return path;
- }
+ ShapeVisitorAcceptor _debugAcceptor = null;
+
+ public ShapeDebuggerRenderer() {
+ super();
+ }
+
+ public ShapeDebuggerRenderer(Graphics2D g) {
+ super(g);
+ }
+
+ public void setDebugAcceptor(ShapeVisitorAcceptor acceptor) {
+ _debugAcceptor = acceptor;
+ }
+
+ @Override
+ protected Path2D drawPath(XDGFShape shape) {
+
+ Path2D path = super.drawPath(shape);
+ if (_debugAcceptor == null || _debugAcceptor.accept(shape)) {
+
+ // show numbers to associate shapes with ids.. doesn't always work
+ Font f = _graphics.getFont();
+ _graphics.scale(1, -1);
+ _graphics.setFont(f.deriveFont(0.05F));
+
+ String shapeId = "" + shape.getID();
+ float shapeOffset = -0.1F;
+
+ if (shape.hasMasterShape()) {
+ shapeId += " MS:" + shape.getMasterShape().getID();
+ shapeOffset -= 0.15F;
+ }
+
+ _graphics.drawString(shapeId, shapeOffset, 0);
+ _graphics.setFont(f);
+ _graphics.scale(1, -1);
+ }
+
+ return path;
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeRenderer.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeRenderer.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeRenderer.java Mon Oct 19 05:59:37 2015
@@ -17,7 +17,6 @@
package org.apache.poi.xdgf.usermodel.shape;
-import java.awt.BasicStroke;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
@@ -32,62 +31,64 @@ import org.apache.poi.xdgf.usermodel.XDG
*/
public class ShapeRenderer extends ShapeVisitor {
- protected Graphics2D _graphics;
-
- public ShapeRenderer() {
- _graphics = null;
- }
-
- public ShapeRenderer(Graphics2D g) {
- _graphics = g;
- }
-
- public void setGraphics(Graphics2D g) {
- _graphics = g;
- }
-
- @Override
- public void visit(XDGFShape shape, AffineTransform globalTransform, int level) {
-
- AffineTransform savedTr = _graphics.getTransform();
- _graphics.transform(globalTransform);
-
- drawPath(shape);
- drawText(shape);
-
- // we're done, undo the transforms
- _graphics.setTransform(savedTr);
- }
-
- protected Path2D drawPath(XDGFShape shape) {
- Path2D.Double path = shape.getPath();
- if (path != null) {
-
- // setup the stroke for this line
-
- _graphics.setColor(shape.getLineColor());
- _graphics.setStroke(shape.getStroke());
- _graphics.draw(path);
- }
-
- return path;
- }
-
- protected void drawText(XDGFShape shape) {
- XDGFText text = shape.getText();
- if (text != null) {
-
- if (text.getTextContent().equals("Header"))
- text.getTextBounds();
-
- Font oldFont = _graphics.getFont();
-
- _graphics.setFont(oldFont.deriveFont(shape.getFontSize().floatValue()));
- _graphics.setColor(shape.getFontColor());
-
- text.draw(_graphics);
- _graphics.setFont(oldFont);
- }
- }
+ protected Graphics2D _graphics;
+
+ public ShapeRenderer() {
+ _graphics = null;
+ }
+
+ public ShapeRenderer(Graphics2D g) {
+ _graphics = g;
+ }
+
+ public void setGraphics(Graphics2D g) {
+ _graphics = g;
+ }
+
+ @Override
+ public void visit(XDGFShape shape, AffineTransform globalTransform,
+ int level) {
+
+ AffineTransform savedTr = _graphics.getTransform();
+ _graphics.transform(globalTransform);
+
+ drawPath(shape);
+ drawText(shape);
+
+ // we're done, undo the transforms
+ _graphics.setTransform(savedTr);
+ }
+
+ protected Path2D drawPath(XDGFShape shape) {
+ Path2D.Double path = shape.getPath();
+ if (path != null) {
+
+ // setup the stroke for this line
+
+ _graphics.setColor(shape.getLineColor());
+ _graphics.setStroke(shape.getStroke());
+ _graphics.draw(path);
+ }
+
+ return path;
+ }
+
+ protected void drawText(XDGFShape shape) {
+ XDGFText text = shape.getText();
+ if (text != null) {
+
+ if (text.getTextContent().equals("Header"))
+ text.getTextBounds();
+
+ Font oldFont = _graphics.getFont();
+
+ _graphics.setFont(oldFont.deriveFont(shape.getFontSize()
+ .floatValue()));
+ _graphics.setColor(shape.getFontColor());
+
+ text.draw(_graphics);
+ _graphics.setFont(oldFont);
+ }
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitor.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitor.java Mon Oct 19 05:59:37 2015
@@ -23,46 +23,50 @@ import org.apache.poi.xdgf.usermodel.XDG
/**
* Used to iterate through shapes
- *
+ *
* To change the behavior of a particular visitor, you can override either
* accept() or getAcceptor() [preferred]
- *
- * If accept() or visit() throw StopVisitingThisBranch, the iteration will
- * not visit subshapes of the shape.
+ *
+ * If accept() or visit() throw StopVisitingThisBranch, the iteration will not
+ * visit subshapes of the shape.
*/
-public abstract class ShapeVisitor{
+public abstract class ShapeVisitor {
+
+ ShapeVisitorAcceptor _acceptor;
+
+ public ShapeVisitor() {
+ _acceptor = getAcceptor();
+ }
+
+ // is only called on construction of the visitor, allows
+ // mixing visitors and acceptors
+ public ShapeVisitorAcceptor getAcceptor() {
+ return new ShapeVisitorAcceptor() {
+ @Override
+ public boolean accept(XDGFShape shape) {
+ return !shape.isDeleted();
+ }
+ };
+ }
+
+ public void setAcceptor(ShapeVisitorAcceptor acceptor) {
+ _acceptor = acceptor;
+ }
+
+ public boolean accept(XDGFShape shape) {
+ return _acceptor.accept(shape);
+ }
+
+ /**
+ * @param shape
+ * Current shape
+ * @param globalTransform
+ * A transform that can convert the shapes points to global
+ * coordinates
+ * @param level
+ * Level in the tree (0 is topmost, 1 is next level...
+ */
+ public abstract void visit(XDGFShape shape,
+ AffineTransform globalTransform, int level);
- ShapeVisitorAcceptor _acceptor;
-
- public ShapeVisitor() {
- _acceptor = getAcceptor();
- }
-
- // is only called on construction of the visitor, allows
- // mixing visitors and acceptors
- public ShapeVisitorAcceptor getAcceptor() {
- return new ShapeVisitorAcceptor() {
- @Override
- public boolean accept(XDGFShape shape) {
- return !shape.isDeleted();
- }
- };
- }
-
- public void setAcceptor(ShapeVisitorAcceptor acceptor) {
- _acceptor = acceptor;
- }
-
-
- public boolean accept(XDGFShape shape) {
- return _acceptor.accept(shape);
- }
-
- /**
- * @param shape Current shape
- * @param globalTransform A transform that can convert the shapes points to global coordinates
- * @param level Level in the tree (0 is topmost, 1 is next level...
- */
- public abstract void visit(XDGFShape shape, AffineTransform globalTransform, int level);
-
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitorAcceptor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitorAcceptor.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitorAcceptor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitorAcceptor.java Mon Oct 19 05:59:37 2015
@@ -21,6 +21,6 @@ import org.apache.poi.xdgf.usermodel.XDG
public interface ShapeVisitorAcceptor {
- public boolean accept(XDGFShape shape);
-
+ public boolean accept(XDGFShape shape);
+
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/StopVisiting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/StopVisiting.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/StopVisiting.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/StopVisiting.java Mon Oct 19 05:59:37 2015
@@ -19,6 +19,6 @@ package org.apache.poi.xdgf.usermodel.sh
public class StopVisiting extends RuntimeException {
- private static final long serialVersionUID = -4651207777092840750L;
+ private static final long serialVersionUID = -4651207777092840750L;
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/StopVisitingThisBranch.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/StopVisitingThisBranch.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/StopVisitingThisBranch.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/shape/exceptions/StopVisitingThisBranch.java Mon Oct 19 05:59:37 2015
@@ -19,6 +19,6 @@ package org.apache.poi.xdgf.usermodel.sh
public class StopVisitingThisBranch extends RuntimeException {
- private static final long serialVersionUID = 5262319077534717862L;
+ private static final long serialVersionUID = 5262319077534717862L;
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/HierarchyPrinter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/HierarchyPrinter.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/HierarchyPrinter.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/HierarchyPrinter.java Mon Oct 19 05:59:37 2015
@@ -32,53 +32,60 @@ import org.apache.poi.xdgf.usermodel.sha
public class HierarchyPrinter {
- public static void printHierarchy(XDGFPage page, File outDir) throws FileNotFoundException {
-
- File pageFile = new File(outDir, "page" + page.getPageNumber() + "-" + Util.sanitizeFilename(page.getName()) + ".txt");
-
- OutputStream os = new FileOutputStream(pageFile);
- PrintStream pos = new PrintStream(os);
-
- printHierarchy(page, pos);
-
- pos.close();
- }
-
- public static void printHierarchy(XDGFPage page, final PrintStream os) {
-
- page.getContent().visitShapes(new ShapeVisitor() {
-
- @Override
- public void visit(XDGFShape shape, AffineTransform globalTransform, int level) {
- for (int i = 0; i < level; i++) {
- os.append(" ");
- }
- // TODO: write text?
- os.println(shape.toString() + " [" + shape.getShapeType() + ", " + shape.getSymbolName() + "] " + shape.getMasterShape() + " " + shape.getTextAsString().trim());
- }
- });
- }
-
- public static void printHierarchy(XmlVisioDocument document, String outDirname) throws FileNotFoundException {
-
- File outDir = new File(outDirname);
-
- for (XDGFPage page: document.getPages()) {
- printHierarchy(page, outDir);
- }
- }
-
-
- public static void main(String [] args) throws Exception {
- if (args.length != 2) {
- System.err.println("Usage: in.vsdx outdir");
- System.exit(1);
- }
-
- String inFilename = args[0];
- String outDir = args[1];
-
- XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(inFilename));
- printHierarchy(doc, outDir);
- }
+ public static void printHierarchy(XDGFPage page, File outDir)
+ throws FileNotFoundException {
+
+ File pageFile = new File(outDir, "page" + page.getPageNumber() + "-"
+ + Util.sanitizeFilename(page.getName()) + ".txt");
+
+ OutputStream os = new FileOutputStream(pageFile);
+ PrintStream pos = new PrintStream(os);
+
+ printHierarchy(page, pos);
+
+ pos.close();
+ }
+
+ public static void printHierarchy(XDGFPage page, final PrintStream os) {
+
+ page.getContent().visitShapes(new ShapeVisitor() {
+
+ @Override
+ public void visit(XDGFShape shape, AffineTransform globalTransform,
+ int level) {
+ for (int i = 0; i < level; i++) {
+ os.append(" ");
+ }
+ // TODO: write text?
+ os.println(shape.toString() + " [" + shape.getShapeType()
+ + ", " + shape.getSymbolName() + "] "
+ + shape.getMasterShape() + " "
+ + shape.getTextAsString().trim());
+ }
+ });
+ }
+
+ public static void printHierarchy(XmlVisioDocument document,
+ String outDirname) throws FileNotFoundException {
+
+ File outDir = new File(outDirname);
+
+ for (XDGFPage page : document.getPages()) {
+ printHierarchy(page, outDir);
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ if (args.length != 2) {
+ System.err.println("Usage: in.vsdx outdir");
+ System.exit(1);
+ }
+
+ String inFilename = args[0];
+ String outDir = args[1];
+
+ XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(
+ inFilename));
+ printHierarchy(doc, outDir);
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/ObjectFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/ObjectFactory.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/ObjectFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/ObjectFactory.java Mon Oct 19 05:59:37 2015
@@ -27,31 +27,31 @@ import org.apache.xmlbeans.XmlObject;
public class ObjectFactory<T, X extends XmlObject> {
-
- Map<String, Constructor<? extends T>> _types = new HashMap<>();
-
- public void put(String typeName, Class<? extends T> cls, Class<?>... varargs) throws NoSuchMethodException, SecurityException {
- _types.put(typeName, cls.getDeclaredConstructor(varargs));
- }
-
- public T load(String name, Object... varargs) {
- Constructor<? extends T> constructor = _types.get(name);
- if (constructor == null) {
-
- @SuppressWarnings("unchecked")
- X xmlObject = (X) varargs[0];
-
- String typeName = xmlObject.schemaType().getName().getLocalPart();
- throw new POIXMLException("Invalid '" + typeName + "' name '" + name + "'");
- }
-
- try {
- return constructor.newInstance(varargs);
- } catch (InvocationTargetException e) {
- throw new POIXMLException(e.getCause());
- } catch (Exception e) {
- throw new POIXMLException(e);
- }
- }
-
+
+ Map<String, Constructor<? extends T>> _types = new HashMap<String, Constructor<? extends T>>();
+
+ public void put(String typeName, Class<? extends T> cls, Class<?>... varargs) throws NoSuchMethodException, SecurityException {
+ _types.put(typeName, cls.getDeclaredConstructor(varargs));
+ }
+
+ public T load(String name, Object... varargs) {
+ Constructor<? extends T> constructor = _types.get(name);
+ if (constructor == null) {
+
+ @SuppressWarnings("unchecked")
+ X xmlObject = (X) varargs[0];
+
+ String typeName = xmlObject.schemaType().getName().getLocalPart();
+ throw new POIXMLException("Invalid '" + typeName + "' name '" + name + "'");
+ }
+
+ try {
+ return constructor.newInstance(varargs);
+ } catch (InvocationTargetException e) {
+ throw new POIXMLException(e.getCause());
+ } catch (Exception e) {
+ throw new POIXMLException(e);
+ }
+ }
+
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/Util.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/Util.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/Util.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/Util.java Mon Oct 19 05:59:37 2015
@@ -18,20 +18,20 @@
package org.apache.poi.xdgf.util;
public class Util {
-
- public static int countLines(String str) {
- int lines = 1;
- int pos = 0;
- while ((pos = str.indexOf("\n", pos) + 1) != 0) {
- lines++;
- }
- return lines;
- }
-
- // this probably isn't 100% correct, so don't use it in security-sensitive
- // applications!
- // from: http://www.rgagnon.com/javadetails/java-0662.html
- public static String sanitizeFilename(String name) {
- return name.replaceAll("[:\\\\/*\"?|<>]", "_");
- }
+
+ public static int countLines(String str) {
+ int lines = 1;
+ int pos = 0;
+ while ((pos = str.indexOf("\n", pos) + 1) != 0) {
+ lines++;
+ }
+ return lines;
+ }
+
+ // this probably isn't 100% correct, so don't use it in security-sensitive
+ // applications!
+ // from: http://www.rgagnon.com/javadetails/java-0662.html
+ public static String sanitizeFilename(String name) {
+ return name.replaceAll("[:\\\\/*\"?|<>]", "_");
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/VsdxToPng.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/VsdxToPng.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/VsdxToPng.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/util/VsdxToPng.java Mon Oct 19 05:59:37 2015
@@ -20,7 +20,6 @@ package org.apache.poi.xdgf.util;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
-import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
@@ -37,82 +36,93 @@ import org.apache.poi.xdgf.usermodel.sha
public class VsdxToPng {
-
- public static void renderToPng(XDGFPage page, String outFilename, double scale, ShapeRenderer renderer) throws IOException {
- renderToPng(page, new File(outFilename), scale, renderer);
- }
-
- public static void renderToPngDir(XDGFPage page, File outDir, double scale, ShapeRenderer renderer) throws IOException {
-
- File pageFile = new File(outDir, "page" + page.getPageNumber() + "-" + Util.sanitizeFilename(page.getName()) + ".png");
- System.out.println("** Writing image to " + pageFile);
-
- renderToPng(page, pageFile, scale, renderer);
-
- }
-
- public static void renderToPng(XDGFPage page, File outFile, double scale, ShapeRenderer renderer) throws IOException {
-
- Dimension2dDouble sz = page.getPageSize();
-
- int width = (int)(scale * sz.getWidth());
- int height = (int)(scale * sz.getHeight());
-
- BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ public static void renderToPng(XDGFPage page, String outFilename,
+ double scale, ShapeRenderer renderer) throws IOException {
+ renderToPng(page, new File(outFilename), scale, renderer);
+ }
+
+ public static void renderToPngDir(XDGFPage page, File outDir, double scale,
+ ShapeRenderer renderer) throws IOException {
+
+ File pageFile = new File(outDir, "page" + page.getPageNumber() + "-"
+ + Util.sanitizeFilename(page.getName()) + ".png");
+ System.out.println("** Writing image to " + pageFile);
+
+ renderToPng(page, pageFile, scale, renderer);
+
+ }
+
+ public static void renderToPng(XDGFPage page, File outFile, double scale,
+ ShapeRenderer renderer) throws IOException {
+
+ Dimension2dDouble sz = page.getPageSize();
+
+ int width = (int) (scale * sz.getWidth());
+ int height = (int) (scale * sz.getHeight());
+
+ BufferedImage img = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_RGB);
final Graphics2D graphics = img.createGraphics();
// default rendering options
- graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
- graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+ graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
+ graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+ RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+ graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
+ RenderingHints.VALUE_FRACTIONALMETRICS_ON);
graphics.setColor(Color.black);
graphics.setBackground(Color.white);
graphics.clearRect(0, 0, width, height);
-
+
// Visio's coordinate system is flipped, so flip the image vertically
- graphics.translate(0, img.getHeight());
+ graphics.translate(0, img.getHeight());
graphics.scale(scale, -scale);
-
+
// toplevel shapes only
renderer.setGraphics(graphics);
page.getContent().visitShapes(renderer);
-
+
graphics.dispose();
-
+
FileOutputStream out = new FileOutputStream(outFile);
ImageIO.write(img, "png", out);
out.close();
- }
-
- public static void renderToPng(XmlVisioDocument document, String outDirname, double scale, ShapeRenderer renderer) throws IOException {
-
- File outDir = new File(outDirname);
-
- for (XDGFPage page: document.getPages()) {
- renderToPngDir(page, outDir, scale, renderer);
- }
- }
-
- public static void main(String [] args) throws Exception {
- if (args.length > 2) {
- System.err.println("Usage: [--debug] in.vsdx outdir");
- System.exit(1);
- }
-
- ShapeRenderer renderer = new ShapeRenderer();
-
- String inFilename = args[0];
- String pngDir = args[1];
-
- if (args[0].equals("--debug")) {
- inFilename = args[1];
- pngDir = args[2];
- renderer = new ShapeDebuggerRenderer();
- }
-
- XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(inFilename));
- renderToPng(doc, pngDir, 2000/11.0, renderer);
- }
+ }
+
+ public static void renderToPng(XmlVisioDocument document,
+ String outDirname, double scale, ShapeRenderer renderer)
+ throws IOException {
+
+ File outDir = new File(outDirname);
+
+ for (XDGFPage page : document.getPages()) {
+ renderToPngDir(page, outDir, scale, renderer);
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ if (args.length > 2) {
+ System.err.println("Usage: [--debug] in.vsdx outdir");
+ System.exit(1);
+ }
+
+ ShapeRenderer renderer = new ShapeRenderer();
+
+ String inFilename = args[0];
+ String pngDir = args[1];
+
+ if (args[0].equals("--debug")) {
+ inFilename = args[1];
+ pngDir = args[2];
+ renderer = new ShapeDebuggerRenderer();
+ }
+
+ XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(
+ inFilename));
+ renderToPng(doc, pngDir, 2000 / 11.0, renderer);
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/xml/XDGFXMLDocumentPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/xml/XDGFXMLDocumentPart.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/xml/XDGFXMLDocumentPart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/xml/XDGFXMLDocumentPart.java Mon Oct 19 05:59:37 2015
@@ -23,11 +23,12 @@ import org.apache.poi.xdgf.usermodel.XDG
public class XDGFXMLDocumentPart extends POIXMLDocumentPart {
- protected XDGFDocument _document;
-
- public XDGFXMLDocumentPart(PackagePart part, PackageRelationship rel, XDGFDocument document) {
- super(part, rel);
- _document = document;
- }
-
+ protected XDGFDocument _document;
+
+ public XDGFXMLDocumentPart(PackagePart part, PackageRelationship rel,
+ XDGFDocument document) {
+ super(part, rel);
+ _document = document;
+ }
+
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xdgf/usermodel/section/CombinedIteratorTest.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xdgf/usermodel/section/CombinedIteratorTest.java?rev=1709355&r1=1709354&r2=1709355&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xdgf/usermodel/section/CombinedIteratorTest.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xdgf/usermodel/section/CombinedIteratorTest.java Mon Oct 19 05:59:37 2015
@@ -26,134 +26,132 @@ import org.junit.Test;
public class CombinedIteratorTest {
- void testIteration(CombinedIterable<String> iterable, String... expected) {
-
- Iterator<String> iter = iterable.iterator();
-
- for (int i = 0; i < expected.length; i++) {
- Assert.assertEquals(true, iter.hasNext());
- Assert.assertEquals(expected[i], iter.next());
- }
-
- Assert.assertEquals(false, iter.hasNext());
- }
-
- @Test
- public void testNullMaster() {
-
- SortedMap<Long, String> base = new TreeMap<>();
- base.put(1L, "B1");
- base.put(2L, "B2");
- base.put(3L, "B3");
-
- testIteration(new CombinedIterable<>(base, null),
- "B1", "B2", "B3");
- }
-
- @Test
- public void testNoMatchesBaseFirst() {
-
- SortedMap<Long, String> base = new TreeMap<>();
- base.put(1L, "B1");
- base.put(2L, "B2");
- base.put(3L, "B3");
-
- SortedMap<Long, String> master = new TreeMap<>();
- master.put(4L, "M4");
- master.put(5L, "M5");
- master.put(6L, "M6");
-
- testIteration(new CombinedIterable<>(base, master),
- "B1", "B2", "B3", "M4", "M5", "M6");
- }
-
- @Test
- public void testNoMatchesMasterFirst() {
-
- SortedMap<Long, String> base = new TreeMap<>();
- base.put(4L, "B4");
- base.put(5L, "B5");
- base.put(6L, "B6");
-
- SortedMap<Long, String> master = new TreeMap<>();
- master.put(1L, "M1");
- master.put(2L, "M2");
- master.put(3L, "M3");
-
- testIteration(new CombinedIterable<>(base, master),
- "M1", "M2", "M3", "B4", "B5", "B6");
- }
-
- @Test
- public void testInterleaved1() {
-
- SortedMap<Long, String> base = new TreeMap<>();
- base.put(1L, "B1");
- base.put(3L, "B3");
- base.put(5L, "B5");
-
- SortedMap<Long, String> master = new TreeMap<>();
- master.put(2L, "M2");
- master.put(4L, "M4");
- master.put(6L, "M6");
-
- testIteration(new CombinedIterable<>(base, master),
- "B1", "M2", "B3", "M4", "B5", "M6");
- }
-
- @Test
- public void testInterleaved2() {
-
- SortedMap<Long, String> base = new TreeMap<>();
- base.put(1L, "B1");
- base.put(2L, "B2");
- base.put(5L, "B5");
- base.put(6L, "B6");
-
- SortedMap<Long, String> master = new TreeMap<>();
- master.put(3L, "M3");
- master.put(4L, "M4");
- master.put(7L, "M7");
- master.put(8L, "M8");
-
- testIteration(new CombinedIterable<>(base, master),
- "B1", "B2", "M3", "M4", "B5", "B6", "M7", "M8");
- }
-
- @Test
- public void testAllMatching() {
-
- SortedMap<Long, String> base = new TreeMap<>();
- base.put(1L, "B1");
- base.put(2L, "B2");
- base.put(3L, "B3");
-
- SortedMap<Long, String> master = new TreeMap<>();
- master.put(1L, "M1");
- master.put(2L, "M2");
- master.put(3L, "M3");
-
- testIteration(new CombinedIterable<>(base, master),
- "B1", "B2", "B3");
- }
-
- @Test
- public void testAllMatching2() {
-
- SortedMap<Long, String> base = new TreeMap<>();
- base.put(1L, "B1");
- base.put(2L, "B2");
- base.put(3L, "B3");
-
- SortedMap<Long, String> master = new TreeMap<>();
- master.put(1L, "M1");
- master.put(2L, "M2");
- master.put(3L, "M3");
- master.put(4L, "M4");
-
- testIteration(new CombinedIterable<>(base, master),
- "B1", "B2", "B3", "M4");
- }
-
-
+ void testIteration(CombinedIterable<String> iterable, String... expected) {
+
+ Iterator<String> iter = iterable.iterator();
+
+ for (int i = 0; i < expected.length; i++) {
+ Assert.assertEquals(true, iter.hasNext());
+ Assert.assertEquals(expected[i], iter.next());
+ }
+
+ Assert.assertEquals(false, iter.hasNext());
+ }
+
+ @Test
+ public void testNullMaster() {
+
+ SortedMap<Long, String> base = new TreeMap<Long, String>();
+ base.put(1L, "B1");
+ base.put(2L, "B2");
+ base.put(3L, "B3");
+
+ testIteration(new CombinedIterable<String>(base, null), "B1", "B2",
+ "B3");
+ }
+
+ @Test
+ public void testNoMatchesBaseFirst() {
+
+ SortedMap<Long, String> base = new TreeMap<Long, String>();
+ base.put(1L, "B1");
+ base.put(2L, "B2");
+ base.put(3L, "B3");
+
+ SortedMap<Long, String> master = new TreeMap<Long, String>();
+ master.put(4L, "M4");
+ master.put(5L, "M5");
+ master.put(6L, "M6");
+
+ testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
+ "B3", "M4", "M5", "M6");
+ }
+
+ @Test
+ public void testNoMatchesMasterFirst() {
+
+ SortedMap<Long, String> base = new TreeMap<Long, String>();
+ base.put(4L, "B4");
+ base.put(5L, "B5");
+ base.put(6L, "B6");
+
+ SortedMap<Long, String> master = new TreeMap<Long, String>();
+ master.put(1L, "M1");
+ master.put(2L, "M2");
+ master.put(3L, "M3");
+
+ testIteration(new CombinedIterable<String>(base, master), "M1", "M2",
+ "M3", "B4", "B5", "B6");
+ }
+
+ @Test
+ public void testInterleaved1() {
+
+ SortedMap<Long, String> base = new TreeMap<Long, String>();
+ base.put(1L, "B1");
+ base.put(3L, "B3");
+ base.put(5L, "B5");
+
+ SortedMap<Long, String> master = new TreeMap<Long, String>();
+ master.put(2L, "M2");
+ master.put(4L, "M4");
+ master.put(6L, "M6");
+
+ testIteration(new CombinedIterable<String>(base, master), "B1", "M2",
+ "B3", "M4", "B5", "M6");
+ }
+
+ @Test
+ public void testInterleaved2() {
+
+ SortedMap<Long, String> base = new TreeMap<Long, String>();
+ base.put(1L, "B1");
+ base.put(2L, "B2");
+ base.put(5L, "B5");
+ base.put(6L, "B6");
+
+ SortedMap<Long, String> master = new TreeMap<Long, String>();
+ master.put(3L, "M3");
+ master.put(4L, "M4");
+ master.put(7L, "M7");
+ master.put(8L, "M8");
+
+ testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
+ "M3", "M4", "B5", "B6", "M7", "M8");
+ }
+
+ @Test
+ public void testAllMatching() {
+
+ SortedMap<Long, String> base = new TreeMap<Long, String>();
+ base.put(1L, "B1");
+ base.put(2L, "B2");
+ base.put(3L, "B3");
+
+ SortedMap<Long, String> master = new TreeMap<Long, String>();
+ master.put(1L, "M1");
+ master.put(2L, "M2");
+ master.put(3L, "M3");
+
+ testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
+ "B3");
+ }
+
+ @Test
+ public void testAllMatching2() {
+
+ SortedMap<Long, String> base = new TreeMap<Long, String>();
+ base.put(1L, "B1");
+ base.put(2L, "B2");
+ base.put(3L, "B3");
+
+ SortedMap<Long, String> master = new TreeMap<Long, String>();
+ master.put(1L, "M1");
+ master.put(2L, "M2");
+ master.put(3L, "M3");
+ master.put(4L, "M4");
+
+ testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
+ "B3", "M4");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org