xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andres Toussaint <and...@onemileup.com>
Subject Re: Drag and drop
Date Mon, 17 May 2004 14:32:55 GMT
Hi Francesco:

I have found some possible situations:

First, on the "svgCanvas.addSVGLoadEventDispatcherListener" you are  
calling "registerListeners()", and in this method you are still calling  
the "onNewClickAction()" method.

>
>        root.addEventListener( SVGConstants.SVG_MOUSEDOWN_EVENT_TYPE ,  
> new OnNewClickAction(), false);
>

And the way you are assigning the EventTarget is the other possible  
source of problem.

The way I have it implemented is, first I will show a abstract of the  
SVG file:

<SVG ......>
      <g id="dragGroup" style="">
	<....... all the elements that will be draggable inside this group  
....>
      </g>


Then, the registerListeners() method, CALLED ONLY ONCE from the  
SVGLoadEventDispatcherListener, is like this:

     public void registerListeners() {
         // Gets an element from the loaded document.
         elt = document.getElementById("dragGroup");        
<------------------------ see the g id!!
         EventTarget t = (EventTarget)elt;

         // Adds  'mouseevent' listeners
         t.addEventListener("mousedown", new OnDownAction(), false);
         t.addEventListener("mousemove", new OnMoveAction(), false);
         t.addEventListener("mouseup", new OnUpAction(), false);
         t.addEventListener("mouseover", new OnOverAction(), false);
         t.addEventListener("click", new OnClickAction(), false);

     }


And then i simply add elements or remove them from this Element "elt"  
using:

                     elt.appendChild(someElement);
or, 		elt.removeChild(someElement);

I do not mess with trying to assign individual listener events to every  
object. The listener is assigned to the "g" element, and any child of  
the "g" element inherits the listener abilities, so you only need to  
get the target from the Event in the onMoveAction() (or any other  
overridden event method).

Hope this helps you,

Andres.

>
> public class OnMoveAction implements EventListener {
>     public void handleEvent(Event evt) {
>            DOMMouseEvent q = (DOMMouseEvent)evt;                 
> if(selected){
>             NamedNodeMap map = node.getAttributes();
>             //place it so that the mouse-pointer is in the center of  
> the object
>             SVGOMElement svgCurrentElement = (SVGOMElement)target;
>             SVGContext context = svgCurrentElement.getSVGContext();
>             Rectangle2D box2D = context.getBBox();
>             int height = (int)box2D.getX();
>             int width = (int)box2D.getY();
>                        AffineTransform AT = new AffineTransform();
>              
> AT.translate((double)(q.getClientX()-width/2),(double)(q.getClientY()- 
> height/2));
>             context.setScreenTransform( AT );
>         }
>     }
> }
> /*    public class OnMouseDownAction implements EventListener {
>        public void handleEvent(Event evt) {
>                    // Select Element to drop
>            DOMMouseEvent dme = (DOMMouseEvent)evt;
>            EventTarget nuovoTarget = dme.getTarget();
>            svgCurrentElement = (SVGOMElement)nuovoTarget;
>        }
>    }    */
>      public class OnDownAction implements EventListener {
>        public void handleEvent(Event evt) {
>            DOMMouseEvent q = (DOMMouseEvent)evt;
>            target = q.getTarget();
>            removeListeners();
>            registerListeners(target);
>            node = (Node)target;
>            selected = true;          }
>    }
>
>    public class OnUpAction implements EventListener {
>        public void handleEvent(Event evt) {               
> removeListeners(target);
>            registerListeners();
>            target = null;
>            selected = false;    }
>        }
>    }
> }
> --
> Email.it, the professional e-mail, gratis per te: http://www.email.it/f
> Sponsor:
> Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=&d=15-5
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
>



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


Mime
View raw message