jview
Class ZoomCursor

java.lang.Object
  extended by java.awt.Cursor
      extended by jview.CanvasCursor
          extended by jview.CrossCursor
              extended by jview.DragCursor
                  extended by jview.ZoomCursor
All Implemented Interfaces:
MouseListener, MouseMotionListener, MouseWheelListener, Serializable, EventListener, MouseInputListener, Initializable, PropertyAware, PropertyComposed
Direct Known Subclasses:
DeleteCursor, MarkCursor, ShapeCursor

public class ZoomCursor
extends DragCursor
implements MouseWheelListener

An extension to a cross cursor that allows zooming into JShapeCanvas dedescants, if they support it via a populated JShapeCanvas#selectArea method. This cursor stores all passed zoom-stages, allowing for step-wise retracing of the zooming events. Components that want to add support for unzooming may query the cursors actions getRevertAction() for total unzoom and getRetraceAction() for a single step unzoom.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class jview.CrossCursor
CrossCursor.Draw
 
Field Summary
private static boolean DEFALLOWSHIFT
          The default zooming amount per whhel rotation.
private static boolean DEFALLOWWHEEL
          The default zooming amount per whhel rotation.
static String DEFCURSORNAME
          Default name of this cursor.
private static double DEFSHIFTFACTOR
          The default shift per drag.
private static double DEFWHEELZOOM
          The default zooming amount per whhel rotation.
static String KEY_ALLOWSHIFT
          If false, shifitng is not allowed.
static String KEY_ALLOWWHEEL
          If false, the wheel does not zoom.
static String KEY_SHIFTFACTOR
          The shifting multiplier if dragged with "shift" pressed.
static String KEY_WHEELZOOM
          The zooming amount per wheel step.
private  Action retrace
          The action for retracing one zoom step.
static String RETRACE
          The label one the unzoom-one, that steps one zoom back.
private  Action revert
          The action for reverting to the orginial, no-zoom level.
static String REVERT
          The label at the unzoom item.
private  Point2D shiftcenter
          For shifting events, this is the normalized mouse-down point.
private  Rectangle2D shiftview
          For shifting events, this is the viewport at mouse down.
private  Shelf<Rectangle2D> zoom
          A history of zooms.
 
Fields inherited from class jview.DragCursor
KEY_ANGLESIZE, KEY_SHOWANGLE, KEY_SHOWDELTAX, KEY_SHOWDELTAY, KEY_SHOWDISTANCE, KEY_SHOWSTART
 
Fields inherited from class jview.CrossCursor
cursorcolor, KEY_ALLOWDRAG, KEY_PERSISTENT, KEY_SHOWCOORDINATE, KEY_SINGLEPERSIST, KEY_XSHIFT, KEY_YSHIFT, lastcenter, lastposition, xformat, yformat
 
Fields inherited from class jview.CanvasCursor
canvas, DEFCURSORCOLOR, KEY_COORDINATES, KEY_CURSORCOLOR, KEY_CURSORNAME, KEY_CURSORSIZE, NORMALIZED, NORMALIZEDACTION, SCREEN, SCREENACTION, USER, USERACTION
 
Fields inherited from class java.awt.Cursor
CROSSHAIR_CURSOR, CUSTOM_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, N_RESIZE_CURSOR, name, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, predefined, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Constructor Summary
ZoomCursor(PropertySupplying prop)
          Creates a new zoom cursor.
 
Method Summary
protected  void dragSelect(Rectangle zoomselect, int ignore)
          This method now converts the selected screen rectangle into viewport coordinates to allow retracing.
 Map<String,Action> getActions()
          Returns all actions.
 Action getRetraceAction()
          Returns the action for retracing one zoom level.
 Action getRevertAction()
          Returns the action for reverting to the no-zoom original state.
 void init()
          Initializes the zoom cursor.
 void mouseClicked(MouseEvent me)
          Clicking with the mouse does not do anything.
 void mouseDragged(MouseEvent me)
          If mouse dragging is enabled, we draw a rectangle instead of a cursor cross.
 void mousePressed(MouseEvent me)
          If mouse shifting is allowed, we record the starting viewport.
 void mouseReleased(MouseEvent me)
          For unzooming, we record the position of the shift start and the current viewport.
 void mouseWheelMoved(MouseWheelEvent we)
          Grabs mouse wheel events.
 void setComposedProperties(PropertySupplying prop)
          Compose with a PropertySupplying as we need subclassing Cursor.
protected  double zoomFactor(MouseWheelEvent we)
          Returns the zoom factor.
 
Methods inherited from class jview.DragCursor
clearOnRepaint, mouseEntered
 
Methods inherited from class jview.CrossCursor
drawCross, drawPosition, getCoordinateLabel, getCoordinates, getCoordinatesPair, mouseExited, mouseMoved, setCoordinateFormat, setCoordinateLabel
 
Methods inherited from class jview.CanvasCursor
disableCanvas, enableCanvas, getComposedProperties, getCursorName, getCursorShape, getCustomized, getNormalizedAction, getScreenAction, getUserAction, isConsider, isMe, isWithin, repaintCanvas, setCursorName, setCursorShape
 
Methods inherited from class java.awt.Cursor
getDefaultCursor, getName, getPredefinedCursor, getSystemCustomCursor, getType, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_WHEELZOOM

public static final String KEY_WHEELZOOM
The zooming amount per wheel step.

See Also:
Constant Field Values

KEY_ALLOWWHEEL

public static final String KEY_ALLOWWHEEL
If false, the wheel does not zoom.

See Also:
Constant Field Values

KEY_SHIFTFACTOR

public static final String KEY_SHIFTFACTOR
The shifting multiplier if dragged with "shift" pressed.

See Also:
Constant Field Values

KEY_ALLOWSHIFT

public static final String KEY_ALLOWSHIFT
If false, shifitng is not allowed.

See Also:
Constant Field Values

DEFCURSORNAME

public static final String DEFCURSORNAME
Default name of this cursor.

See Also:
Constant Field Values

DEFALLOWWHEEL

private static final boolean DEFALLOWWHEEL
The default zooming amount per whhel rotation.

See Also:
Constant Field Values

DEFWHEELZOOM

private static final double DEFWHEELZOOM
The default zooming amount per whhel rotation.

See Also:
Constant Field Values

DEFALLOWSHIFT

private static final boolean DEFALLOWSHIFT
The default zooming amount per whhel rotation.

See Also:
Constant Field Values

DEFSHIFTFACTOR

private static final double DEFSHIFTFACTOR
The default shift per drag.

See Also:
Constant Field Values

REVERT

public static final String REVERT
The label at the unzoom item.

See Also:
Constant Field Values

RETRACE

public static final String RETRACE
The label one the unzoom-one, that steps one zoom back.

See Also:
Constant Field Values

zoom

private Shelf<Rectangle2D> zoom
A history of zooms.


retrace

private Action retrace
The action for retracing one zoom step.


revert

private Action revert
The action for reverting to the orginial, no-zoom level.


shiftview

private Rectangle2D shiftview
For shifting events, this is the viewport at mouse down.


shiftcenter

private Point2D shiftcenter
For shifting events, this is the normalized mouse-down point.

Constructor Detail

ZoomCursor

public ZoomCursor(PropertySupplying prop)
Creates a new zoom cursor. Dragging is always enabled, even if overruled in properties.

Method Detail

setComposedProperties

public void setComposedProperties(PropertySupplying prop)
Compose with a PropertySupplying as we need subclassing Cursor.

Specified by:
setComposedProperties in interface PropertyAware
Overrides:
setComposedProperties in class DragCursor

init

public void init()
Initializes the zoom cursor. Here, the pop-up menu and the undo-zoom list is generated.

Specified by:
init in interface Initializable
Overrides:
init in class CanvasCursor

getRetraceAction

public Action getRetraceAction()
Returns the action for retracing one zoom level.


getRevertAction

public Action getRevertAction()
Returns the action for reverting to the no-zoom original state.


getActions

public Map<String,Action> getActions()
Returns all actions. Some special, commonly used action may be retrieved also individually.

Overrides:
getActions in class CanvasCursor
Returns:
A mapping of action names to concrete actions.

mouseClicked

public void mouseClicked(MouseEvent me)
Clicking with the mouse does not do anything.

Specified by:
mouseClicked in interface MouseListener

mouseWheelMoved

public void mouseWheelMoved(MouseWheelEvent we)
Grabs mouse wheel events. If the user pulls the wheel towards him, zoom level is increased, pushing away zooms out. If during this process the shift key is pressed, only the x-axis zooms, if the ctrl key is pressed, only y is zoomed.

Specified by:
mouseWheelMoved in interface MouseWheelListener

zoomFactor

protected double zoomFactor(MouseWheelEvent we)
Returns the zoom factor.


mousePressed

public void mousePressed(MouseEvent me)
If mouse shifting is allowed, we record the starting viewport.

Specified by:
mousePressed in interface MouseListener
Overrides:
mousePressed in class DragCursor

mouseDragged

public void mouseDragged(MouseEvent me)
If mouse dragging is enabled, we draw a rectangle instead of a cursor cross.

Specified by:
mouseDragged in interface MouseMotionListener
Overrides:
mouseDragged in class DragCursor

mouseReleased

public void mouseReleased(MouseEvent me)
For unzooming, we record the position of the shift start and the current viewport.

Specified by:
mouseReleased in interface MouseListener
Overrides:
mouseReleased in class DragCursor

dragSelect

protected void dragSelect(Rectangle zoomselect,
                          int ignore)
This method now converts the selected screen rectangle into viewport coordinates to allow retracing. We store the normalized zoom in the zoom list

Specified by:
dragSelect in class DragCursor
Parameters:
zoomselect - The on-screen Rectangle of the drag, not normalized.
ignore - The extended modifiers of the mouse event on drag end.