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 Te...@apcc.com on 2005/05/23 19:52:39 UTC

Detecting mouse events external to the JSVGCanvas

Hello,

I noticed that when a mousedown event occurs "outside" the JSVGCanvas,
and the cursor is dragged "into" the canvas, that the mouseup event is not
detected by any of its event listeners. (Also  mouseReleased() is not
called.)

To work around this, I tried to check if a mouse button was in a "down"
state when
it enters the canvas:

                     public void mouseEntered(MouseEvent e) {
                           int button = e.getButton();
                           int modifier = e.getModifiers();
                           int id = e.getID();
                         System.out.println("Mouse entered: button=" +
button + " modifier" + modifier + " id=" +id);
                    }

But the values are always the same whether the mouse button is down or up.

Is there another way to detect that the user is dragging some new item onto
the canvas?
Is there another way to query the state of the mouse button at this time?
Is there a "best practice" pattern for doing this?

Thanks in advance!
Ted


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


Re: Detecting mouse events external to the JSVGCanvas

Posted by Andres Toussaint <an...@onemileup.com>.
I do not know if this is what you want to accomplish, but in order to 
be aware of a DnD (Drag and Drop) situation, as you are explaining in 
your example, both the initial and receiving components need to be able 
to communicate with each other. In Java the DnD is accomplished by 
enabling a DragListener in the initial component and a DropTarget in 
the receiver. Since JSVGCanvas extends JComponent, you can set it up as 
a DropTargetListener.

You may see java.awt.dnd.* and java.awt.datatransfer.* packages.

The way i have it is in a JTree that i have enabled as Dragable, when 
it detects a drag operation, i create a StringTransferable (since SVG 
is XML, and thus Text) with the SVG i want to drop in my canvas. The 
JSVGCanvas implements DropTargetListener, and upon succesful drop (i.e. 
the DataFlavor is accepted), I then get the drop location by converting 
the Event.getLocation() coordinates to SVG coordinate namespace. And 
then in the UpdateManager thread i add the SVG element to my DOM.

Andres.

references, in no specific order:
http://javaalmanac.com/egs/java.awt.dnd/pkg.html
http://www.rockhoppertech.com/java-drag-and-drop-faq.html
http://www.javaworld.com/javaworld/jw-03-1999/jw-03-dragndrop.html
http://java.sun.com/docs/books/tutorial/dnd/

On May 23, 2005, at 1:52 PM, Ted.Clement@apcc.com wrote:

> Hello,
>
> I noticed that when a mousedown event occurs "outside" the JSVGCanvas,
> and the cursor is dragged "into" the canvas, that the mouseup event is 
> not
> detected by any of its event listeners. (Also  mouseReleased() is not
> called.)
>
> To work around this, I tried to check if a mouse button was in a "down"
> state when
> it enters the canvas:
>
>                      public void mouseEntered(MouseEvent e) {
>                            int button = e.getButton();
>                            int modifier = e.getModifiers();
>                            int id = e.getID();
>                          System.out.println("Mouse entered: button=" +
> button + " modifier" + modifier + " id=" +id);
>                     }
>
> But the values are always the same whether the mouse button is down or 
> up.
>
> Is there another way to detect that the user is dragging some new item 
> onto
> the canvas?
> Is there another way to query the state of the mouse button at this 
> time?
> Is there a "best practice" pattern for doing this?
>
> Thanks in advance!
> Ted
>
>
> ---------------------------------------------------------------------
> 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