org.proteinshader.gui.listeners
Class CanvasMouseListener

java.lang.Object
  extended by javax.swing.event.MouseInputAdapter
      extended by org.proteinshader.gui.listeners.CanvasMouseListener
All Implemented Interfaces:
MouseListener, MouseMotionListener, MouseWheelListener, EventListener, MouseInputListener

public class CanvasMouseListener
extends MouseInputAdapter
implements MouseWheelListener

Converts mouse movements across the canvas to image rotations or camera movements.

On Mac OS X computers that might have only a single mouse button, the single mouse button is the equivalent of the left button (button 1) on a typical Windows or Linux mouse, while the combination of the Macintosh Command key with the single mouse button is the equivalent of the right mouse button (button 3). On mice that do not have a middle button (button 2), the combination of the shift key and the left button (button 1) is used.

IMAGE_ROTATE_XY:

Windows/Linux - left mouse click
Macintosh OS X - mouse click
vertical mouse drag - results in rotation about x-axis of protein.
horizontal mouse drag - results in rotation about y-axis of protein.


IMAGE_ROTATE_Z:

Windows/Linux - shift key and right mouse click
Macintosh OS X - command key, shift key, and mouse click.
horizontal mouse drag - results in rotation about z-axis of protein.


CAMERA_PAN_XY:

Windows/Linux - right mouse click.
Maintosh OS X - command key and mouse click.
vertical mouse drag - results in camera panning in y direction.
horizontal mouse drag - results in camera panning in x direction.


CAMERA_ZOOM_Z:

Windows/Linux - shift key and left mouse click (or middle mouse click).
Maintosh OS X - shift key and mouse click.
horizontal mouse drag - results in rotation about z-axis of protein.


Nested Class Summary
static class CanvasMouseListener.Mode
          The mode controls image rotation and camera movements.
 
Field Summary
static int B1_MASK
          Abbreviated version of mouse button 1 mask for class InputEvent.
static int B2_MASK
          Abbreviated version of mouse button 2 mask for class InputEvent.
static int B3_MASK
          Abbreviated version of mouse button 3 mask for class InputEvent.
static int CAMERA_XY_SCALE
          The camera xy scale factor is used to slow down camera movement in the xy-plane.
static int CAMERA_ZOOM_SCALE
          The camera zoom factor is used to slow down camera movement in the z-axis (for mouse dragging).
static int WHEEL_SCALE_FACTOR
          When the mouse wheel is used for zooming, this scaling factory will determine how many angstroms the camera moves in or out for each wheel click.
 
Constructor Summary
CanvasMouseListener(Renderer renderer)
          Constructs a CanvasMouseListener.
 
Method Summary
 void mouseDragged(MouseEvent e)
          Rotates the model and redraws the canvas in response to the mouse being dragged across the canvas.
 void mousePressed(MouseEvent e)
          Remembers xy-coordinates where mouse was clicked.
 void mouseWheelMoved(MouseWheelEvent e)
          Zooms the camera in or out based on the number of wheel clicks.
 void moveCameraZ(int deltaHeight)
          Uses the mouse movement in the vertical direction to zoom the camera in or out.
 
Methods inherited from class javax.swing.event.MouseInputAdapter
mouseClicked, mouseEntered, mouseExited, mouseMoved, mouseReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAMERA_XY_SCALE

public static final int CAMERA_XY_SCALE
The camera xy scale factor is used to slow down camera movement in the xy-plane.

See Also:
Constant Field Values

CAMERA_ZOOM_SCALE

public static final int CAMERA_ZOOM_SCALE
The camera zoom factor is used to slow down camera movement in the z-axis (for mouse dragging).

See Also:
Constant Field Values

WHEEL_SCALE_FACTOR

public static final int WHEEL_SCALE_FACTOR
When the mouse wheel is used for zooming, this scaling factory will determine how many angstroms the camera moves in or out for each wheel click.

See Also:
Constant Field Values

B1_MASK

public static final int B1_MASK
Abbreviated version of mouse button 1 mask for class InputEvent.

See Also:
Constant Field Values

B2_MASK

public static final int B2_MASK
Abbreviated version of mouse button 2 mask for class InputEvent.

See Also:
Constant Field Values

B3_MASK

public static final int B3_MASK
Abbreviated version of mouse button 3 mask for class InputEvent.

See Also:
Constant Field Values
Constructor Detail

CanvasMouseListener

public CanvasMouseListener(Renderer renderer)
Constructs a CanvasMouseListener. This listener needs the address of the Renderer so that it can change the angle of rotation about the x, y, or z-axis, or change the xyz-coordinates of the camera.

Parameters:
renderer - the Renderer for the canvas of the main GUI.
Method Detail

mousePressed

public void mousePressed(MouseEvent e)
Remembers xy-coordinates where mouse was clicked.

Specified by:
mousePressed in interface MouseListener
Overrides:
mousePressed in class MouseInputAdapter
Parameters:
e - the mouse event triggered when a button is pressed.

mouseDragged

public void mouseDragged(MouseEvent e)
Rotates the model and redraws the canvas in response to the mouse being dragged across the canvas.

ROTATION: Clicking on the canvas and dragging the mouse horizonally will rotate the molecule about its y-axis, while dragging the mouse vertically will rotate the molecule about its x-axis.

Specified by:
mouseDragged in interface MouseMotionListener
Overrides:
mouseDragged in class MouseInputAdapter
Parameters:
e - the mouse event.

mouseWheelMoved

public void mouseWheelMoved(MouseWheelEvent e)
Zooms the camera in or out based on the number of wheel clicks.

Specified by:
mouseWheelMoved in interface MouseWheelListener

moveCameraZ

public void moveCameraZ(int deltaHeight)
Uses the mouse movement in the vertical direction to zoom the camera in or out.

The amount to move the camera in the z-direction is divided by a CAMERA_ZOOM_SCALE factor to slow it down.

Parameters:
deltaHeight - the mouse movement in the vertical direction.


Copyright © 2007-2008