Oh, here is my translate function:
void translate(Node n, float x, float y) {
if(!(n instanceof SVGOMGElement))
{
NodeList nodes = n.getChildNodes();
for(int i=0; i < nodes.getLength(); i++)
translate(nodes.item(i),x,y);
}
else
{
SVGOMGElement svgG = ((SVGOMGElement) n);
SVGAnimatedTransformList atl =
svgG.getTransform();
SVGOMTransform trans = new SVGOMTransform();
trans.setTranslate(x, y);
atl.getBaseVal().appendItem(trans);
}
}
-----Original Message-----
From: Paul L. Bogen [mailto:[EMAIL PROTECTED]
Sent: Thursday, May 03, 2007 11:38 AM
To: [email protected]
Subject: Having an issue with subgraph drag and drop code.
I am creating dragging code for a subtree of the svg (g element
primarily).
The problem I'm having is that it is not translating the clicked on
element correctly.
So eventually the subtree is no longer underneath the mouse so it does
not get the mouseup event.
Any ideas how to correct this?
Here is my eventhandler:
public class OnMouseAction implements EventListener {
private boolean down;
private SVGOMPoint initialDragPoint;
private SVGOMPoint initialLocation;
public void handleEvent(Event evt) {
if(evt instanceof org.w3c.dom.events.MouseEvent)
{
org.w3c.dom.events.MouseEvent mevt =
(org.w3c.dom.events.MouseEvent) evt;
EventTarget et = evt.getCurrentTarget();
SVGLocatable elt = (SVGLocatable) et;
if (elt != null) {
String type = evt.getType();
if(type.equals("mousedown")) {
System.out.print("D");
this.down = true;
SVGOMPoint pt = new
SVGOMPoint(mevt.getClientX(), mevt.getClientY());
SVGMatrix mat =
elt.getScreenCTM();
mat = mat.inverse();
// screen -> elem
this.initialDragPoint =
(SVGOMPoint)pt.matrixTransform(mat);
this.initialLocation =
new SVGOMPoint(elt.getBBox().getX(),elt.getBBox().getY());
} else
if(type.equals("mousemove")) {
DOMMouseEvent elEvt =
(DOMMouseEvent)evt;
if(this.down &&
elEvt.getButton() == 1)
{
System.out.print("M");
//Cast the event
onto a Batik Mouse event,
//so we can get
ccordinates
int nowToX =
elEvt.getClientX();
int nowToY =
elEvt.getClientY();
//convert it to
a point for use with the Matrix
SVGOMPoint pt =
new SVGOMPoint(nowToX, nowToY);
//Get the items
screen coordinates, and apply the transformation
// elem ->
screen
SVGMatrix mat =
elt.getScreenCTM();
mat =
mat.inverse(); // screen -> elem
SVGOMPoint
dragpt = (SVGOMPoint)pt.matrixTransform(mat);
float finalX =
dragpt.getX() -
(this.initialDragPoint.getX() - this.initialLocation.getX());
float finalY =
dragpt.getY() -
(this.initialDragPoint.getY() - this.initialLocation.getY());
translate(((Node) elt), finalX, finalY);
SVGTechnologyDemo.this.canvas.getUpdateManager().forceRepaint();
}
} else
if(type.equals("mouseup")) {
System.out.println("U");
this.down = false;
} else {
System.out.println("X");
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]