![]() |
tricky+frustrating: changing mouse handler while mouse pressed doesn't work
Hello,
I have a quite tricky problem, on that I work on for 3 days now without success. It's frustrating. *sigh* :-( I am using Piccolo, a zoomable UI framework <http://www.cs.umd.edu/hcil/jazz/download/>, to create a 2D space on which I can place different kinds of nodes, e.g., pictures. However, my problem is more general and not Piccolo based. Every node on this 2D space has its own mouse event handler attached. With the mouse event handler you can click on a node and drag it to another place. Every node has internally its unique index ID. If two nodes intersect, then the one with a higher index is displayed above a node with lower index. Currently, you can drag a node anywhere, even underneath another node with higher index. WHAT I WANT: Whenever a node of higher index comes between the dragged node and the cursor, I want to release the original node and apply all mouse events to the higher placed node. If a user would do this manually, he/she would release the mouse button and click again. However, the user is not doing this, but the machine should; the user constantly just holds the mouse button pressed. This turns out to be very difficult to handle, because the user does *not* release the mouse button. The input handler of the node directly underneath the cursor (that *should* handle the mouse events then), does not get activated. :-( Any expert here who can see how to solve this problem? Here is the code. Don't worry about the Piccolo stuff. I think it is a general Java question about mouse events and robots (I use java.awt.Robot -- is this the right approach?). I have marked the problematic part: ******** <code> ******* public void mouseDragged(PInputEvent aEvent) { // This tells other handlers that this event is now already handled now aEvent.setHandled(true); // Find the cursor position and the node position. Point2D cursorPos = aEvent.getPosition(); PBounds nodePosition = aEvent.getPickedNode().getGlobalFullBounds(); // Check if the cursor is within the node's bounds. This is // just for cases when the dragged node is slower than the cursor. if (nodePosition.contains(cursorPos.getX(), cursorPos.getY()) { // This retrieves the node directly underneath the cursor PNode nodeUnderneathCursor = aEvent.getPickedNode().getRoot() .getDefaultInputManager().getMouseOver() .getPickedNode(); // If there is a node underneath the cursor + its not the background if (! nodeUnderneathCursor.equals(aEvent.getPickedNode() ) && ! nodeUnderneathCursor.getClass().equals(PCamera.cla ss)) { // HERE IS THE PROBLEMATIC PART!! <<<<<<<<<<<<<<<<<<<<<<<<<<<< // Have in mind that there constantly comes a mouseDragged event // in from the user's pressed mouse button! try { Robot robot = new Robot(); // this should release the mouse button for the original node robot.mouseRelease(InputEvent.BUTTON1_MASK); // Tell other handlers that this one doesn't want to handle anymore aEvent.setHandled(false); // this should perform a click; the position is right on the node // that is between the cursor and the original dragged node robot.mousePress(InputEvent.BUTTON1_MASK); } catch (AWTException e) { e.printStackTrace(); } } } // Move the node to the new cursor position Dimension2D delta = aEvent.getDeltaRelativeTo(aEvent.getPickedNode()); aEvent.getPickedNode().translate(delta.getWidth(), delta.getHeight()); } ******* </code> ******* Thanks a lot for any hint! Claus |
Re: tricky+frustrating: changing mouse handler while mouse pressed doesn't work
Hi,
to summarize my previous mail: How can I completely ignore incomming mouse events (basically mouseDragged) from the "real" mouse in order to call: java.awt.Robot robot = new robot(); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.mousePress(InputEvent.BUTTON1_MASK); Any hint is appreciated! Claus |
| All times are GMT. The time now is 04:41 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.