Hello,
I work on a Java application based upon batik. It contains a JSVGCanvas
displaying the content of a SVGDocument.
I want to select objects on JSVGCanvas in an easier way.
For example, user want to click on a path which has stroke width = 0.01
-> Currently user must zoom on path to select it.
-> I want to widen my sensitive area depending on my zoom level.
I
've downloaded batik sources and modified several classes:
org.apache.batik.gvt.StrokeShapePainter.java :
public Shape getPaintedArea()
{
if ((this.paint == null) || (this.stroke == null))
return null;
float lineWidth = ((BasicStroke)this.stroke).getLineWidth();
int endCap = ((BasicStroke)this.stroke).getEndCap();
int lineJoin = ((BasicStroke)this.stroke).getLineJoin();
float miterLimit = ((BasicStroke)this.stroke).getMiterLimit();
float[] arrayOfFloat = ((BasicStroke)this.stroke).getDashArray();
float dashPhase = ((BasicStroke)this.stroke).getDashPhase();
lineWidth +=5.0;
BasicStroke localBasicStroke = new BasicStroke(lineWidth, endCap,
lineJoin, miterLimit, arrayOfFloat, dashPhase);
if (this.strokedShape == null)
this.strokedShape = localBasicStroke.createStrokedShape(this.shape);
return this.strokedShape;
}
Here "5.0" is a constant but I want to determine it depending on my zoom level
org.apache.batik.gvt.event.AWTEventDispatcher.java:
protected void dispatchMouseEvent(MouseEvent evt) {
GraphicsNodeMouseEvent gvtevt;
Point2D p = new Point2D.Float(evt.getX(), evt.getY());
Point2D gnp = p;
if (baseTransform != null) {
gnp = baseTransform.transform(p, null);
}
double factor = -1;
try {
AffineTransform renderingTransform = baseTransform.createInverse();
factor = Math.min(5/renderingTransform.getScaleX(), 5);
} catch (NoninvertibleTransformException e) {
e.printStackTrace();
}
[...]
}
Basically, what I am trying to do is to propagate my "factor" from
"dispatchMouseEvent" to "StrokeShapePainter>getPaintedArea()", but cant find a
solution to perform this.
Does anyone have an idea on implementing this ?
Thanks in advance,
Julien