You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by tk...@apache.org on 2001/09/13 16:22:45 UTC
cvs commit: xml-batik/sources/org/apache/batik/gvt CompositeShapePainter.java FillShapePainter.java MarkerShapePainter.java ShapePainter.java StrokeShapePainter.java
tkormann 01/09/13 07:22:45
Modified: sources/org/apache/batik/gvt CompositeShapePainter.java
FillShapePainter.java MarkerShapePainter.java
ShapePainter.java StrokeShapePainter.java
Log:
Still some javadoc and source code cleanup.
Lazy computation of the CompositeGraphicsNode that is used to display markers.
In case of multiple markers (start + middle + end), the CompositeGraphicsNode is
built once instead of 3 times.
Revision Changes Path
1.7 +26 -17 xml-batik/sources/org/apache/batik/gvt/CompositeShapePainter.java
Index: CompositeShapePainter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/CompositeShapePainter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CompositeShapePainter.java 2001/03/16 18:31:48 1.6
+++ CompositeShapePainter.java 2001/09/13 14:22:45 1.7
@@ -20,39 +20,45 @@
* A shape painter which consists of multiple shape painters.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: CompositeShapePainter.java,v 1.6 2001/03/16 18:31:48 tkormann Exp $
+ * @version $Id: CompositeShapePainter.java,v 1.7 2001/09/13 14:22:45 tkormann Exp $
*/
public class CompositeShapePainter implements ShapePainter {
+
/**
* The shape associated with this painter
*/
protected Shape shape;
- /** The enclosed <tt>ShapePainter</tt>s of this composite shape painter. */
+ /**
+ * The enclosed <tt>ShapePainter</tt>s of this composite shape painter.
+ */
protected ShapePainter [] painters;
- /** The number of shape painter. */
+
+ /**
+ * The number of shape painter.
+ */
protected int count;
/**
* Constructs a new empty <tt>CompositeShapePainter</tt>.
*/
public CompositeShapePainter(Shape shape) {
- if(shape == null){
+ if (shape == null) {
throw new IllegalArgumentException();
}
-
this.shape = shape;
}
/**
- * Adds the specified shape painter.
+ * Adds the specified shape painter to the shape painter..
+ *
* @param shapePainter the shape painter to add
*/
public void addShapePainter(ShapePainter shapePainter) {
if (shapePainter == null) {
return;
}
- if(this.shape != shapePainter.getShape()){
+ if (this.shape != shapePainter.getShape()) {
shapePainter.setShape(shape);
}
if (painters == null) {
@@ -67,12 +73,11 @@
}
/**
- * Paints the specified shape using the specified Graphics2D and context.
+ * Paints the specified shape using the specified Graphics2D.
+ *
* @param g2d the Graphics2D to use
- * @param ctx the render context to use
*/
- public void paint(Graphics2D g2d,
- GraphicsNodeRenderContext ctx) {
+ public void paint(Graphics2D g2d, GraphicsNodeRenderContext ctx) {
if (painters != null) {
for (int i=0; i < count; ++i) {
painters[i].paint(g2d, ctx);
@@ -81,7 +86,7 @@
}
/**
- * Returns the area painted by this painter
+ * Returns the area painted by this shape painter.
*/
public Shape getPaintedArea(GraphicsNodeRenderContext rc){
// <!> FIX ME: Use of GeneralPath is a work around Area problems.
@@ -98,13 +103,17 @@
return null;
}
}
-
+
/**
- * Sets the Shape this painter is associated with.
+ * Sets the Shape this shape painter is associated with.
+ *
* @param shape new shape this painter should be associated with.
- * should not be null.
+ * Should not be null.
*/
public void setShape(Shape shape){
+ if (shape == null) {
+ throw new IllegalArgumentException();
+ }
if (painters != null) {
for (int i=0; i < count; ++i) {
painters[i].setShape(shape);
@@ -114,9 +123,9 @@
}
/**
- * Gets the Shape this painter is associated with.
+ * Gets the Shape this shape painter is associated with.
*
- * @return shape associated with this Painter.
+ * @return shape associated with this painter
*/
public Shape getShape(){
return shape;
1.5 +22 -16 xml-batik/sources/org/apache/batik/gvt/FillShapePainter.java
Index: FillShapePainter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/FillShapePainter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FillShapePainter.java 2001/02/06 01:56:38 1.4
+++ FillShapePainter.java 2001/09/13 14:22:45 1.5
@@ -16,25 +16,32 @@
* A shape painter that can be used to fill a shape.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: FillShapePainter.java,v 1.4 2001/02/06 01:56:38 vhardy Exp $
+ * @version $Id: FillShapePainter.java,v 1.5 2001/09/13 14:22:45 tkormann Exp $
*/
public class FillShapePainter implements ShapePainter {
- /** The Shape to be painted */
+
+ /**
+ * The Shape to be painted.
+ */
protected Shape shape;
- /** The paint attribute used to fill the shape. */
+ /**
+ * The paint attribute used to fill the shape.
+ */
protected Paint paint;
/**
* Constructs a new <tt>FillShapePainter</tt> that can be used to fill
* a <tt>Shape</tt>.
*
- * @param shape Shape to be painted by this painter. Should not be null
+ * @param shape Shape to be painted by this painter
+ * Should not be null.
*/
public FillShapePainter(Shape shape) {
- if(shape == null){
+ if (shape == null) {
throw new IllegalArgumentException();
}
+ this.shape = shape;
}
/**
@@ -47,14 +54,11 @@
}
/**
- * Paints the specified shape using the specified Graphics2D and context.
+ * Paints the specified shape using the specified Graphics2D.
*
- * @param shape the shape to paint
* @param g2d the Graphics2D to use
- * @param ctx the render context to use
*/
- public void paint(Graphics2D g2d,
- GraphicsNodeRenderContext ctx) {
+ public void paint(Graphics2D g2d, GraphicsNodeRenderContext ctx) {
if (paint != null) {
g2d.setPaint(paint);
g2d.fill(shape);
@@ -62,25 +66,27 @@
}
/**
- * Returns the area painted by this painter for a given input shape
- *
- * @param shape the shape to paint
+ * Returns the area painted by this shape painter.
*/
public Shape getPaintedArea(GraphicsNodeRenderContext rc){
return shape;
}
/**
- * Sets the Shape this painter is associated with.
+ * Sets the Shape this shape painter is associated with.
+ *
* @param shape new shape this painter should be associated with.
- * should not be null.
+ * Should not be null.
*/
public void setShape(Shape shape){
+ if (shape == null) {
+ throw new IllegalArgumentException();
+ }
this.shape = shape;
}
/**
- * Gets the Shape this painter is associated with.
+ * Gets the Shape this shape painter is associated with.
*
* @return shape associated with this Painter.
*/
1.3 +256 -221 xml-batik/sources/org/apache/batik/gvt/MarkerShapePainter.java
Index: MarkerShapePainter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/MarkerShapePainter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MarkerShapePainter.java 2001/03/05 22:07:01 1.2
+++ MarkerShapePainter.java 2001/09/13 14:22:45 1.3
@@ -10,6 +10,7 @@
import java.awt.Shape;
import java.awt.Graphics2D;
+
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
@@ -22,57 +23,51 @@
* A shape painter that can be used to paint markers on a shape.
*
* @author <a href="vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: MarkerShapePainter.java,v 1.2 2001/03/05 22:07:01 vhardy Exp $
+ * @version $Id: MarkerShapePainter.java,v 1.3 2001/09/13 14:22:45 tkormann Exp $
*/
public class MarkerShapePainter implements ShapePainter {
- /** The Shape to be painted */
- protected Shape shape;
- /**
- * Constructs a new <tt>FillShapePainter</tt> that can be used to fill
- * a <tt>Shape</tt>.
- *
- * @param shape Shape to be painted by this painter. Should not be null
+ /**
+ * The Shape to be painted.
*/
- public MarkerShapePainter(Shape shape) {
- if(shape == null){
- throw new IllegalArgumentException();
- }
-
- this.shape = shape;
- }
+ protected Shape shape;
/**
* Start Marker
*/
- private Marker startMarker;
+ protected Marker startMarker;
/**
- * Start Marker Proxy
+ * Middle Marker
*/
- private ProxyGraphicsNode startMarkerProxy;
+ protected Marker middleMarker;
/**
- * Middle Marker
+ * End Marker
*/
- private Marker middleMarker;
+ protected Marker endMarker;
/**
- * Middle Marker Proxy
+ * Start marker proxy.
*/
- private ProxyGraphicsNode middleMarkerProxies[];
+ private ProxyGraphicsNode startMarkerProxy;
/**
- * End Marker
+ * Middle marker proxy.
*/
- private Marker endMarker;
+ private ProxyGraphicsNode middleMarkerProxies[];
/**
- * End Marker Proxy
+ * End marker proxy.
*/
private ProxyGraphicsNode endMarkerProxy;
/**
+ * Contains the various marker proxies.
+ */
+ private CompositeGraphicsNode markerGroup;
+
+ /**
* Internal Cache: Primitive bounds
*/
private Rectangle2D dPrimitiveBounds;
@@ -82,71 +77,164 @@
*/
private Rectangle2D dGeometryBounds;
+ /**
+ * Constructs a new <tt>MarkerShapePainter</tt> that can be used to markers
+ * on top of a shape.
+ *
+ * @param shape Shape to be painted by this painter.
+ * Should not be null
+ */
+ public MarkerShapePainter(Shape shape) {
+ if (shape == null) {
+ throw new IllegalArgumentException();
+ }
+ this.shape = shape;
+ }
+
/**
- * Contains the various marker proxies
+ * Paints the specified shape using the specified Graphics2D.
+ *
+ * @param shape the shape to paint
+ * @param g2d the Graphics2D to use
*/
- private CompositeGraphicsNode markerGroup = new CompositeGraphicsNode();
+ public void paint(Graphics2D g2d, GraphicsNodeRenderContext ctx) {
+ if (markerGroup == null) {
+ buildMarkerGroup();
+ }
+ if (markerGroup.getChildren().size() > 0) {
+ markerGroup.paint(g2d, ctx);
+ }
+ }
- public void setStartMarker(Marker startMarker){
- this.startMarker = startMarker;
- this.startMarkerProxy = null;
- buildMarkerGroup();
+ /**
+ * Returns the area painted by this shape painter.
+ */
+ public Shape getPaintedArea(GraphicsNodeRenderContext rc){
+ if (markerGroup == null) {
+ buildMarkerGroup();
+ }
+ return markerGroup.getBounds(rc);
}
- public void setMiddleMarker(Marker middleMarker){
- this.middleMarker = middleMarker;
+ /**
+ * Sets the Shape this shape painter is associated with.
+ *
+ * @param shape new shape this painter should be associated with.
+ * Should not be null.
+ */
+ public void setShape(Shape shape){
+ if (shape == null) {
+ throw new IllegalArgumentException();
+ }
+ this.shape = shape;
+ this.startMarkerProxy = null;
this.middleMarkerProxies = null;
- buildMarkerGroup();
+ this.endMarkerProxy = null;
+ this.markerGroup = null;
}
- public void setEndMarker(Marker endMarker){
- this.endMarker = endMarker;
- this.endMarkerProxy = null;
- buildMarkerGroup();
+ /**
+ * Gets the Shape this shape painter is associated with.
+ *
+ * @return shape associated with this painter
+ */
+ public Shape getShape(){
+ return shape;
}
+ /**
+ * Returns the marker that shall be drawn at the first vertex of the given
+ * shape.
+ */
public Marker getStartMarker(){
return startMarker;
}
+ /**
+ * Sets the marker that shall be drawn at the first vertex of the given
+ * shape.
+ *
+ * @param startMarker the start marker
+ */
+ public void setStartMarker(Marker startMarker){
+ this.startMarker = startMarker;
+ this.startMarkerProxy = null;
+ this.markerGroup = null;
+ }
+
+ /**
+ * Returns the marker that shall be drawn at every other vertex (not the
+ * first or the last one) of the given shape.
+ */
public Marker getMiddleMarker(){
return middleMarker;
}
+ /**
+ * Sets the marker that shall be drawn at every other vertex (not the first
+ * or the last one) of the given shape.
+ *
+ * @param middleMarker the middle marker
+ */
+ public void setMiddleMarker(Marker middleMarker){
+ this.middleMarker = middleMarker;
+ this.middleMarkerProxies = null;
+ this.markerGroup = null;
+ }
+
+ /**
+ * Returns the marker that shall be drawn at the last vertex of the given
+ * shape.
+ */
public Marker getEndMarker(){
return endMarker;
}
+ /**
+ * Sets the marker that shall be drawn at the last vertex of the given
+ * shape.
+ *
+ * @param endMarker the end marker
+ */
+ public void setEndMarker(Marker endMarker){
+ this.endMarker = endMarker;
+ this.endMarkerProxy = null;
+ this.markerGroup = null;
+ }
+
+ // ---------------------------------------------------------------------
+ // Internal methods to build GraphicsNode according to the Marker
+ // ---------------------------------------------------------------------
+
/**
- * Builds a new marker group with the current set of
- * markers
+ * Builds a new marker group with the current set of markers.
*/
- private void buildMarkerGroup(){
- if(startMarker != null && startMarkerProxy == null){
+ protected void buildMarkerGroup(){
+ if (startMarker != null && startMarkerProxy == null) {
startMarkerProxy = buildStartMarkerProxy();
}
- if(middleMarker != null && middleMarkerProxies == null){
+ if (middleMarker != null && middleMarkerProxies == null) {
middleMarkerProxies = buildMiddleMarkerProxies();
}
- if(endMarker != null && endMarkerProxy == null){
+ if (endMarker != null && endMarkerProxy == null) {
endMarkerProxy = buildEndMarkerProxy();
}
CompositeGraphicsNode group = new CompositeGraphicsNode();
List children = group.getChildren();
- if(startMarkerProxy != null){
+ if (startMarkerProxy != null) {
children.add(startMarkerProxy);
}
-
- if(middleMarkerProxies != null){
+
+ if (middleMarkerProxies != null) {
for(int i=0; i<middleMarkerProxies.length; i++){
children.add(middleMarkerProxies[i]);
}
}
-
- if(endMarkerProxy != null){
+
+ if (endMarkerProxy != null) {
children.add(endMarkerProxy);
}
@@ -154,35 +242,34 @@
}
/**
- * Builds a proxy <tt>GraphicsNode</tt> for the input
- * <tt>Marker</tt> to be drawn at the start position
+ * Builds a proxy <tt>GraphicsNode</tt> for the input <tt>Marker</tt> to be
+ * drawn at the start position
*/
- public ProxyGraphicsNode buildStartMarkerProxy(){
+ protected ProxyGraphicsNode buildStartMarkerProxy() {
+
PathIterator iter = getShape().getPathIterator(null);
// Get initial point on the path
double coords[] = new double[6];
int segType = 0;
- if(iter.isDone()){
+ if (iter.isDone()) {
return null;
}
segType = iter.currentSegment(coords);
- if(segType != iter.SEG_MOVETO){
+ if (segType != iter.SEG_MOVETO) {
return null;
}
iter.next();
- Point2D markerPosition
- = new Point2D.Double(coords[0],
- coords[1]);
+ Point2D markerPosition = new Point2D.Double(coords[0], coords[1]);
// If the marker's orient property is NaN,
// the slope needs to be computed
double rotation = startMarker.getOrient();
- if(Double.isNaN(rotation)){
- if(!iter.isDone()){
+ if (Double.isNaN(rotation)) {
+ if (!iter.isDone()) {
double next[] = new double[6];
int nextSegType = 0;
nextSegType = iter.currentSegment(next);
@@ -199,40 +286,39 @@
}
// Now, compute the marker's proxy transform
- AffineTransform markerTxf =
- computeMarkerTransform(startMarker,
- markerPosition,
- rotation);
+ AffineTransform markerTxf = computeMarkerTransform(startMarker,
+ markerPosition,
+ rotation);
- ProxyGraphicsNode gn
- = new ProxyGraphicsNode();
+ ProxyGraphicsNode gn = new ProxyGraphicsNode();
gn.setSource(startMarker.getMarkerNode());
gn.setTransform(markerTxf);
-
+
return gn;
}
/**
- * Builds a proxy <tt>GraphicsNode</tt> for the input
- * <tt>Marker</tt> to be drawn at the end position
+ * Builds a proxy <tt>GraphicsNode</tt> for the input <tt>Marker</tt> to be
+ * drawn at the end position.
*/
- public ProxyGraphicsNode buildEndMarkerProxy(){
+ protected ProxyGraphicsNode buildEndMarkerProxy() {
+
PathIterator iter = getShape().getPathIterator(null);
int nPoints = 0;
// Get first point, in case the last segment on the
// path is a close
- if(iter.isDone()){
+ if (iter.isDone()) {
return null;
}
-
+
double coords[] = new double[6];
double moveTo[] = new double[2];
int segType = 0;
segType = iter.currentSegment(coords);
- if(segType != iter.SEG_MOVETO){
+ if (segType != iter.SEG_MOVETO) {
return null;
}
nPoints++;
@@ -247,7 +333,8 @@
coords[3], coords[4], coords[5] }, tmp = null;
int lastSegType = segType;
int lastButOneSegType = 0;
- while(!iter.isDone()){
+
+ while (!iter.isDone()) {
tmp = lastButOne;
lastButOne = last;
last = tmp;
@@ -255,10 +342,10 @@
lastSegType = iter.currentSegment(last);
- if(lastSegType == PathIterator.SEG_MOVETO){
+ if (lastSegType == PathIterator.SEG_MOVETO) {
moveTo[0] = last[0];
moveTo[1] = last[1];
- } else if(lastSegType == PathIterator.SEG_CLOSE){
+ } else if (lastSegType == PathIterator.SEG_CLOSE) {
lastSegType = PathIterator.SEG_LINETO;
last[0] = moveTo[0];
last[1] = moveTo[1];
@@ -268,18 +355,17 @@
nPoints++;
}
- if (nPoints < 2){
+ if (nPoints < 2) {
return null;
}
// Turn the last segment into a position
- Point2D markerPosition =
- getSegmentTerminatingPoint(last, lastSegType);
+ Point2D markerPosition = getSegmentTerminatingPoint(last, lastSegType);
// If the marker's orient property is NaN,
// the slope needs to be computed
double rotation = endMarker.getOrient();
- if(Double.isNaN(rotation)){
+ if (Double.isNaN(rotation)) {
rotation = computeRotation(lastButOne,
lastButOneSegType,
last, lastSegType,
@@ -287,13 +373,11 @@
}
// Now, compute the marker's proxy transform
- AffineTransform markerTxf =
- computeMarkerTransform(endMarker,
- markerPosition,
- rotation);
+ AffineTransform markerTxf = computeMarkerTransform(endMarker,
+ markerPosition,
+ rotation);
- ProxyGraphicsNode gn
- = new ProxyGraphicsNode();
+ ProxyGraphicsNode gn = new ProxyGraphicsNode();
gn.setSource(endMarker.getMarkerNode());
gn.setTransform(markerTxf);
@@ -302,31 +386,11 @@
}
/**
- * Extracts the terminating point, depending on the segment type.
+ * Builds a proxy <tt>GraphicsNode</tt> for the input <tt>Marker</tt> to be
+ * drawn at the middle positions
*/
- private final Point2D getSegmentTerminatingPoint(double coords[], int segType){
- switch(segType){
- case PathIterator.SEG_CUBICTO:
- return new Point2D.Double(coords[4], coords[5]);
- case PathIterator.SEG_LINETO:
- return new Point2D.Double(coords[0], coords[1]);
- case PathIterator.SEG_MOVETO:
- return new Point2D.Double(coords[0], coords[1]);
- case PathIterator.SEG_QUADTO:
- return new Point2D.Double(coords[2], coords[3]);
- case PathIterator.SEG_CLOSE:
- default:
- throw new Error();
- // Should never happen: close segments are
- // replaced with lineTo
- }
- }
+ protected ProxyGraphicsNode[] buildMiddleMarkerProxies() {
- /**
- * Builds a proxy <tt>GraphicsNode</tt> for the input
- * <tt>Marker</tt> to be drawn at the middle positions
- */
- public ProxyGraphicsNode[] buildMiddleMarkerProxies(){
PathIterator iter = getShape().getPathIterator(null);
double[] prev = new double[6];
@@ -335,33 +399,31 @@
int prevSegType = 0, curSegType = 0, nextSegType = 0;
// Get the first three points on the path
- if(iter.isDone()){
+ if (iter.isDone()) {
return null;
}
prevSegType = iter.currentSegment(prev);
-
double[] moveTo = new double[2];
- if(prevSegType != PathIterator.SEG_MOVETO){
+ if (prevSegType != PathIterator.SEG_MOVETO) {
return null;
}
moveTo[0] = prev[0];
moveTo[1] = prev[1];
-
iter.next();
- if(iter.isDone()){
+ if (iter.isDone()) {
return null;
}
-
+
curSegType = iter.currentSegment(cur);
- if(curSegType == PathIterator.SEG_MOVETO){
+ if (curSegType == PathIterator.SEG_MOVETO) {
moveTo[0] = cur[0];
moveTo[1] = cur[1];
- } else if(curSegType == PathIterator.SEG_CLOSE){
+ } else if (curSegType == PathIterator.SEG_CLOSE) {
curSegType = PathIterator.SEG_LINETO;
cur[0] = moveTo[0];
cur[1] = moveTo[1];
@@ -370,18 +432,18 @@
iter.next();
Vector proxies = new Vector();
- while(!iter.isDone()){
+ while (!iter.isDone()) {
nextSegType = iter.currentSegment(next);
- if(nextSegType == PathIterator.SEG_MOVETO){
+ if (nextSegType == PathIterator.SEG_MOVETO) {
moveTo[0] = next[0];
moveTo[1] = next[1];
- } else if(nextSegType == PathIterator.SEG_CLOSE){
+ } else if (nextSegType == PathIterator.SEG_CLOSE) {
nextSegType = PathIterator.SEG_LINETO;
next[0] = moveTo[0];
next[1] = moveTo[1];
}
-
+
proxies.addElement(createMiddleMarker(prev, prevSegType,
cur, curSegType,
next, nextSegType));
@@ -396,20 +458,21 @@
iter.next();
}
- ProxyGraphicsNode gn[]
- = new ProxyGraphicsNode[proxies.size()];
-
+ ProxyGraphicsNode [] gn = new ProxyGraphicsNode[proxies.size()];
proxies.copyInto(gn);
return gn;
}
+ /**
+ * Creates a ProxyGraphicsNode for a middle marker.
+ */
private ProxyGraphicsNode createMiddleMarker(double[] prev,
- int prevSegType,
- double[] cur,
- int curSegType,
- double[] next,
- int nextSegType){
+ int prevSegType,
+ double[] cur,
+ int curSegType,
+ double[] next,
+ int nextSegType){
// Turn the cur segment into a position
Point2D markerPosition = getSegmentTerminatingPoint(cur, curSegType);
@@ -417,20 +480,18 @@
// If the marker's orient property is NaN,
// the slope needs to be computed
double rotation = middleMarker.getOrient();
- if(Double.isNaN(rotation)){
+ if (Double.isNaN(rotation)) {
rotation = computeRotation(prev, prevSegType,
cur, curSegType,
next, nextSegType);
}
-
+
// Now, compute the marker's proxy transform
- AffineTransform markerTxf =
- computeMarkerTransform(middleMarker,
- markerPosition,
- rotation);
+ AffineTransform markerTxf = computeMarkerTransform(middleMarker,
+ markerPosition,
+ rotation);
- ProxyGraphicsNode gn
- = new ProxyGraphicsNode();
+ ProxyGraphicsNode gn = new ProxyGraphicsNode();
gn.setSource(middleMarker.getMarkerNode());
gn.setTransform(markerTxf);
@@ -438,12 +499,16 @@
return gn;
}
+ /**
+ * Returns the rotation according to the specified parameters.
+ */
private double computeRotation(double[] prev,
int prevSegType,
double[] cur,
int curSegType,
double[] next,
int nextSegType){
+
// Compute in slope, i.e., the slope of the segment
// going into the current point
double[] inSlope = computeInSlope(prev, prevSegType,
@@ -454,59 +519,59 @@
double[] outSlope = computeOutSlope(cur, curSegType,
next, nextSegType);
- if(inSlope == null){
+ if (inSlope == null) {
inSlope = outSlope;
}
- if(outSlope == null){
+ if (outSlope == null) {
outSlope = inSlope;
}
- if(inSlope == null){
+ if (inSlope == null) {
return 0;
}
-
double rotationIn = Math.atan2(inSlope[1], inSlope[0])*180./Math.PI;
double rotationOut = Math.atan2(outSlope[1], outSlope[0])*180./Math.PI;
double rotation = (rotationIn + rotationOut)/2;
-
+
return rotation;
}
/**
- * @return dx/dy for the in slope
+ * Returns dx/dy for the in slope.
*/
private double[] computeInSlope(double[] prev,
int prevSegType,
double[] cur,
int curSegType){
+
// Compute point into which the slope runs
Point2D curEndPoint = getSegmentTerminatingPoint(cur, curSegType);
- double dx = 0, dy = 0;
+ double dx = 0;
+ double dy = 0;
+
switch(curSegType){
case PathIterator.SEG_QUADTO:
- // If the current segment is a line, quad or cubic curve.
- // the slope is about equal to that of the
- // line from the last control point and the curEndPoint
+ // If the current segment is a line, quad or cubic curve. the slope
+ // is about equal to that of the line from the last control point
+ // and the curEndPoint
dx = curEndPoint.getX() - cur[0];
dy = curEndPoint.getY() - cur[1];
break;
case PathIterator.SEG_LINETO:
- //
- // This is equivalent to a line from the previous
- // segment's terminating point and the current end
- // point.
- Point2D prevEndPoint = getSegmentTerminatingPoint(prev, prevSegType);
-
+ // This is equivalent to a line from the previous segment's
+ // terminating point and the current end point.
+ Point2D prevEndPoint =
+ getSegmentTerminatingPoint(prev, prevSegType);
dx = curEndPoint.getX() - prevEndPoint.getX();
dy = curEndPoint.getY() - prevEndPoint.getY();
break;
case PathIterator.SEG_CUBICTO:
- // If the current segment is a line, quad or cubic curve.
- // the slope is about equal to that of the
- // line from the last control point and the curEndPoint
+ // If the current segment is a line, quad or cubic curve. the slope
+ // is about equal to that of the line from the last control point
+ // and the curEndPoint
dx = curEndPoint.getX() - cur[2];
dy = curEndPoint.getY() - cur[3];
break;
@@ -519,7 +584,7 @@
return null;
}
- if(dx == 0 && dy == 0){
+ if (dx == 0 && dy == 0) {
return null;
}
@@ -527,28 +592,28 @@
}
/**
- * @return dx/dy for the out slope
+ * Returns dx/dy for the out slope.
*/
private double[] computeOutSlope(double[] cur,
int curSegType,
double[] next,
int nextSegType){
+
Point2D curEndPoint = getSegmentTerminatingPoint(cur, curSegType);
double dx = 0, dy = 0;
switch(nextSegType){
case PathIterator.SEG_CLOSE:
- // Should not happen at this point, because all close
- // segments have been replaced by lineTo segments.
+ // Should not happen at this point, because all close segments have
+ // been replaced by lineTo segments.
break;
case PathIterator.SEG_CUBICTO:
case PathIterator.SEG_LINETO:
case PathIterator.SEG_QUADTO:
- // If the next segment is a line, quad or cubic curve.
- // the slope is about equal to that of the
- // line from curEndPoint and the first control
- // point
+ // If the next segment is a line, quad or cubic curve. the slope is
+ // about equal to that of the line from curEndPoint and the first
+ // control point
dx = next[0] - curEndPoint.getX();
dy = next[1] - curEndPoint.getY();
break;
@@ -558,7 +623,7 @@
return null;
}
- if(dx == 0 && dy == 0){
+ if (dx == 0 && dy == 0) {
return null;
}
@@ -566,14 +631,12 @@
}
/**
- * Computes the transform for the input marker, so that
- * it is positioned at the given position with the specified
- * rotation
- */
- private AffineTransform
- computeMarkerTransform(Marker marker,
- Point2D markerPosition,
- double rotation){
+ * Computes the transform for the input marker, so that it is positioned at
+ * the given position with the specified rotation
+ */
+ private AffineTransform computeMarkerTransform(Marker marker,
+ Point2D markerPosition,
+ double rotation) {
Point2D ref = marker.getRef();
/*AffineTransform txf =
AffineTransform.getTranslateInstance(markerPosition.getX()
@@ -581,62 +644,34 @@
markerPosition.getY()
- ref.getY());*/
AffineTransform txf = new AffineTransform();
+
+ txf.translate(markerPosition.getX() - ref.getX(),
+ markerPosition.getY() - ref.getY());
- txf.translate(markerPosition.getX()
- - ref.getX(),
- markerPosition.getY()
- - ref.getY());
-
- if(!Double.isNaN(rotation)){
- txf.rotate(rotation*Math.PI/180.,
- ref.getX(),
- ref.getY());
+ if (!Double.isNaN(rotation)) {
+ txf.rotate(rotation*Math.PI/180., ref.getX(), ref.getY());
}
return txf;
}
- /**
- * Paints the specified shape using the specified Graphics2D and context.
- *
- * @param shape the shape to paint
- * @param g2d the Graphics2D to use
- * @param ctx the render context to use
- */
-
- public void paint(Graphics2D g2d,
- GraphicsNodeRenderContext ctx) {
- if(markerGroup.getChildren().size() > 0){
- markerGroup.paint(g2d, ctx);
- }
- }
-
/**
- * Returns the area painted by this painter
- */
- public Shape getPaintedArea(GraphicsNodeRenderContext rc){
- return markerGroup.getBounds(rc);
- }
-
- /**
- * Sets the Shape this painter is associated with.
- * @param shape new shape this painter should be associated with.
- * should not be null.
- */
- public void setShape(Shape shape){
- this.shape = shape;
- this.startMarkerProxy = null;
- this.middleMarkerProxies = null;
- this.endMarkerProxy = null;
- buildMarkerGroup();
- }
-
- /**
- * Gets the Shape this painter is associated with.
- *
- * @return shape associated with this Painter.
+ * Extracts the terminating point, depending on the segment type.
*/
- public Shape getShape(){
- return shape;
+ protected Point2D getSegmentTerminatingPoint(double coords[], int segType) {
+ switch(segType){
+ case PathIterator.SEG_CUBICTO:
+ return new Point2D.Double(coords[4], coords[5]);
+ case PathIterator.SEG_LINETO:
+ return new Point2D.Double(coords[0], coords[1]);
+ case PathIterator.SEG_MOVETO:
+ return new Point2D.Double(coords[0], coords[1]);
+ case PathIterator.SEG_QUADTO:
+ return new Point2D.Double(coords[2], coords[3]);
+ case PathIterator.SEG_CLOSE:
+ default:
+ throw new Error();
+ // Should never happen: close segments are replaced with lineTo
+ }
}
}
1.6 +11 -11 xml-batik/sources/org/apache/batik/gvt/ShapePainter.java
Index: ShapePainter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/ShapePainter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ShapePainter.java 2001/02/06 01:56:39 1.5
+++ ShapePainter.java 2001/09/13 14:22:45 1.6
@@ -15,34 +15,34 @@
* Renders the shape of a <tt>ShapeNode</tt>.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: ShapePainter.java,v 1.5 2001/02/06 01:56:39 vhardy Exp $
+ * @version $Id: ShapePainter.java,v 1.6 2001/09/13 14:22:45 tkormann Exp $
*/
public interface ShapePainter {
/**
- * Paints the specified shape using the specified Graphics2D and context.
+ * Paints the specified shape using the specified Graphics2D.
+ *
* @param g2d the Graphics2D to use
- * @param ctx the render context to use
*/
void paint(Graphics2D g2d, GraphicsNodeRenderContext ctx);
/**
- * Returns the area painted by this painter
- *
+ * Returns the area painted by this shape painter.
*/
Shape getPaintedArea(GraphicsNodeRenderContext rc);
/**
- * Sets the Shape this painter is associated with.
+ * Sets the Shape this shape painter is associated with.
+ *
* @param shape new shape this painter should be associated with.
- * should not be null.
+ * Should not be null.
*/
- public void setShape(Shape shape);
+ void setShape(Shape shape);
/**
- * Gets the Shape this painter is associated with.
+ * Gets the shape this shape painter is associated with.
*
- * @return shape associated with this Painter.
+ * @return shape associated with this painter
*/
- public Shape getShape();
+ Shape getShape();
}
1.6 +23 -23 xml-batik/sources/org/apache/batik/gvt/StrokeShapePainter.java
Index: StrokeShapePainter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/StrokeShapePainter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StrokeShapePainter.java 2001/03/16 18:31:49 1.5
+++ StrokeShapePainter.java 2001/09/13 14:22:45 1.6
@@ -17,10 +17,13 @@
* A shape painter that can be used to draw the outline of a shape.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: StrokeShapePainter.java,v 1.5 2001/03/16 18:31:49 tkormann Exp $
+ * @version $Id: StrokeShapePainter.java,v 1.6 2001/09/13 14:22:45 tkormann Exp $
*/
public class StrokeShapePainter implements ShapePainter {
- /** Shape painted by this painter */
+
+ /**
+ * Shape painted by this painter.
+ */
protected Shape shape;
/**
@@ -34,16 +37,16 @@
protected Paint paint;
/**
- * Constructs a new <tt>ShapePainter</tt> that can be used to draw
- * the outline of a <tt>Shape</tt>.
+ * Constructs a new <tt>ShapePainter</tt> that can be used to draw the
+ * outline of a <tt>Shape</tt>.
*
- * @param shape shape to be painted by this painter. Should not be null.
+ * @param shape shape to be painted by this painter.
+ * Should not be null.
*/
public StrokeShapePainter(Shape shape) {
- if(shape == null){
+ if (shape == null) {
throw new IllegalArgumentException();
}
-
this.shape = shape;
}
@@ -66,15 +69,11 @@
}
/**
- * Paints the outline of the specified shape using the specified
- * Graphics2D and context.
+ * Paints the outline of the specified shape using the specified Graphics2D.
*
- * @param shape the shape to paint
- * @param g2d the Graphics2D to use
- * @param ctx the render context to use
+ * @param g2d the Graphics2D to use
*/
- public void paint(Graphics2D g2d,
- GraphicsNodeRenderContext ctx) {
+ public void paint(Graphics2D g2d, GraphicsNodeRenderContext ctx) {
if (stroke != null && paint != null) {
g2d.setPaint(paint);
g2d.setStroke(stroke);
@@ -83,12 +82,10 @@
}
/**
- * Returns the area painted by this painter for a given input shape
- *
- * @param shape the shape to paint
+ * Returns the area painted by this shape painter.
*/
public Shape getPaintedArea(GraphicsNodeRenderContext rc){
- if(paint != null && stroke != null){
+ if (paint != null && stroke != null) {
return stroke.createStrokedShape(shape);
} else {
return null;
@@ -96,21 +93,24 @@
}
/**
- * Sets the Shape this painter is associated with.
+ * Sets the Shape this shape painter is associated with.
+ *
* @param shape new shape this painter should be associated with.
- * should not be null.
+ * Should not be null.
*/
public void setShape(Shape shape){
+ if (shape == null) {
+ throw new IllegalArgumentException();
+ }
this.shape = shape;
}
/**
- * Gets the Shape this painter is associated with.
+ * Gets the Shape this shape painter is associated with.
*
- * @return shape associated with this Painter.
+ * @return shape associated with this painter.
*/
public Shape getShape(){
return shape;
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org