I extend the MouseInputAdapter and use a mousePressed() event to call a method in my Renderer called ‘startZoom()’ where it stores a global point signifying the first point of the starting of the zoom:
public void mousePressed( MouseEvent e ) {
if (SwingUtilities.isMiddleMouseButton(e)) {
renderer.startZoom(e.getPoint());
}
}
public void startZoom( Point MousePt ) {
mousePoint.x = MousePt.x;
mousePoint.y = MousePt.y;
}
Next I have a mouseDragged() method in my mouse handler that calls the zoom() method of my renderer to calculate the deltas between the first point and the current point being dragged so that I can use this delta value for calculating the zoom
public void mouseDragged( MouseEvent e ) {
if (SwingUtilities.isMiddleMouseButton(e)) {
renderer.zoom(e.getPoint() );
}
}
public void zoom( Point MousePt ) {
// calculate the delta point
Point delta = new Point();
delta.x = MousePt.x - mousePoint.x;
delta.y = MousePt.y - mousePoint.y;
// set the new mouse point to the old mouse point
mousePoint.x = MousePt.x;
mousePoint.y = MousePt.y;
}
and in my display() method I use the delta point to apply it either to a rotation or a zoom or whatever…this part is up to you on how to implement it.