File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Parallel dragging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Parallel dragging" Watch "Parallel dragging" New topic
Author

Parallel dragging

Olaf Enulfson
Greenhorn

Joined: Jun 18, 2009
Posts: 23
Hello coders,


I'm experimenting with mouseListeners and I have an interesting problem (I think). I've searched the forum for similar posts but found none. Sorry if I missed any.

In my program I'm trying to move parts of shapes by dragging one of its points. I've already implemented the mousePressed() and mouseDragged() methods, and I can move single points. But I need to find out how many pixels the mouse pointer moved in X and Y and in which direction, so that I can apply the same vector to the other points.

In the mouseWheelEvent there is a method called getWheelRotation(), which returns the direction of the wheel. I need something alike for X and Y, instead of the actual new position getX() and getY() are returning.


Any thoughts? Thanks a bunch in advance,

O.
--
Sex is an emotion in motion.
-- Mae West
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Olaf Enulfson wrote:In my program I'm trying to move parts of shapes by dragging one of its points. I've already implemented the mousePressed() and mouseDragged() methods, and I can move single points. But I need to find out how many pixels the mouse pointer moved in X and Y and in which direction, so that I can apply the same vector to the other points.

One way is to simply have your Mouse input listener or mouse adapter save the location of the mouse on mousePressed method and store this in a variable local to this listener. Then it is trivial to calculate the change in x and y from this point in the mouseDragged method.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Olaf Enulfson wrote:I'm trying to move parts of shapes

Also, much will depend on the details of just what you are trying to do. If you are trying to move a complete shape, then you may wish to use the Shape interface and affinetransforms. Otherwise you could encapsulate your shape yourself, and give it a move method. For instance:

SimpleBox.java


DragBoxPanel.java
Olaf Enulfson
Greenhorn

Joined: Jun 18, 2009
Posts: 23
Pete, you are incredible.

I came up with your first suggestion too. I feel kind of bad for posting the question so soon. I should have given it more thought first.
But your second post blew me away. You're in a league of your own.

Thanks man. I appreciate it.

O.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parallel dragging