You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Paul L. Bogen" <pl...@kbsi.com> on 2007/05/03 18:38:03 UTC

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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Having an issue with subgraph drag and drop code.

Posted by hardc0d3r <ha...@gmail.com>.
i do not know if this will help but i saw a dragging example in javascript..
here is the link:

http://blog.codedread.com/archives/2005/12/21/how-to-enable-dragging-in-svg/

hope this helps...
-- 
View this message in context: http://www.nabble.com/batik-confusion...-tf3681701.html#a10315264
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Having an issue with subgraph drag and drop code.

Posted by "Paul L. Bogen" <pl...@kbsi.com>.
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:plbogen@kbsi.com] 
Sent: Thursday, May 03, 2007 11:38 AM
To: batik-users@xmlgraphics.apache.org
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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org