y.view
Class Graph2DViewMouseWheelZoomListener

java.lang.Object
  extended by y.view.Graph2DViewMouseWheelZoomListener
All Implemented Interfaces:
MouseWheelListener, EventListener

public class Graph2DViewMouseWheelZoomListener
extends Object
implements MouseWheelListener

This class can be registered with the Graph2DView's canvas component (Graph2DView.getCanvasComponent()) as a MouseWheelListener. It will thereby add mouse wheel scrolling capabilities to the Graph2DView. E.g.:

  // get the view instance
  Graph2DView view = getView();
  // create the listener
  Graph2DViewMouseWheelZoomListener mwzl = new Graph2DViewMouseWheelZoomListener();
  // register it with the view's internal canvas component
  view.getCanvasComponent().addMouseWheelListener(mwzl);
 

Note that this class can only be used with J2SE 1.4 or higher.

 
Your browser does not support SVG content.

Constructor Summary
Graph2DViewMouseWheelZoomListener()
          Creates a new Graph2DViewMouseWheelZoomListener If it receives MouseWheelListener events that come from the canvas component of a Graph2DView (see Graph2DView.getCanvasComponent()), it will zoom into or out of the Graph2DView.
 
Method Summary
protected  void adjustWorldRect(Graph2DView view)
          Adjusts the world rectangle that defines the accessible area of the given view after its zoom and clip has been changed.
protected  double calcZoom(double zoom, int amount)
          Calculates the new zoom level to be assigned to the canvas.
 double getMaximumZoom()
          Gets the maximum zoom level of Graph2DView that will be assigned when scrolling the mouse wheel.
 double getMinimumZoom()
          Returns the minimum zoom level of Graph2DView that will be assigned when scrolling the mouse wheel.
protected  boolean isCenterZoomEvent(MouseWheelEvent mwe)
          Determines whether for the current event center zooming should be used.
 boolean isCenterZooming()
          Returns the property centerZooming.
 boolean isDownInZooming()
          Returns property downInZooming.
 void mouseWheelMoved(MouseWheelEvent e)
           
 void setCenterZooming(boolean centerZooming)
          Sets the property centerZooming.
 void setDownInZooming(boolean downIn)
          Sets property downInZooming.
 void setMaximumZoom(double maximumZoom)
          Sets the maximum zoom level of Graph2DView that will be assigned when scrolling the mouse wheel.
 void setMinimumZoom(double minimumZoom)
          Sets the minimum zoom level of Graph2DView that will be assigned when scrolling the mouse wheel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graph2DViewMouseWheelZoomListener

public Graph2DViewMouseWheelZoomListener()
Creates a new Graph2DViewMouseWheelZoomListener If it receives MouseWheelListener events that come from the canvas component of a Graph2DView (see Graph2DView.getCanvasComponent()), it will zoom into or out of the Graph2DView.

Method Detail

mouseWheelMoved

public void mouseWheelMoved(MouseWheelEvent e)
Specified by:
mouseWheelMoved in interface MouseWheelListener

calcZoom

protected double calcZoom(double zoom,
                          int amount)
Calculates the new zoom level to be assigned to the canvas. Subclasses may override this method to implement customized behavior.

Parameters:
zoom - the current zoom level set on the canvas.
amount - the amount of scroll wheel rotation or units to scroll.

adjustWorldRect

protected void adjustWorldRect(Graph2DView view)
Adjusts the world rectangle that defines the accessible area of the given view after its zoom and clip has been changed. By default, the world rectangle will be adjusted to the size of the graph's bounding box.


isCenterZoomEvent

protected boolean isCenterZoomEvent(MouseWheelEvent mwe)
Determines whether for the current event center zooming should be used. This implementation will return false if isCenterZooming() returns false or the Event.CTRL_MASK flag is set in mwe's modifiers.

Parameters:
mwe - the current MouseWheelEvent
Returns:
true if center zooming should be used

isCenterZooming

public boolean isCenterZooming()
Returns the property centerZooming. If enabled, this class will zoom to the center of the canvas when the mouse wheel is used. Otherwise it will take the position of the mouse into account, keeping that world coordinate position the same during zooming. The default is true.

Returns:
whether to enable simple center zooming

setCenterZooming

public void setCenterZooming(boolean centerZooming)
Sets the property centerZooming. If enabled, this class will zoom to the center of the canvas when the mouse wheel is used. Otherwise it will take the position of the mouse into account, keeping that world coordinate position the same during zooming.

Parameters:
centerZooming - whether to enable simple center zooming

getMaximumZoom

public double getMaximumZoom()
Gets the maximum zoom level of Graph2DView that will be assigned when scrolling the mouse wheel. By default, this value is set to Double.MAX_VALUE.


setMaximumZoom

public void setMaximumZoom(double maximumZoom)
Sets the maximum zoom level of Graph2DView that will be assigned when scrolling the mouse wheel. By default, this value is set to Double.MAX_VALUE.


getMinimumZoom

public double getMinimumZoom()
Returns the minimum zoom level of Graph2DView that will be assigned when scrolling the mouse wheel.


setMinimumZoom

public void setMinimumZoom(double minimumZoom)
Sets the minimum zoom level of Graph2DView that will be assigned when scrolling the mouse wheel. By default, this value is set to Double.MIN_VALUE.


isDownInZooming

public boolean isDownInZooming()
Returns property downInZooming.

Returns:
property downInZooming.
See Also:
setDownInZooming(boolean)

setDownInZooming

public void setDownInZooming(boolean downIn)
Sets property downInZooming. If set to true scrolling down (using the mouse wheel) will be translated into a zoom in action and scrolling up will be translated into a zoom out action. By default, this property is set to false, i.e. scrolling down triggers zoom out behavior and scrolling up zoom in behavior.

Parameters:
downIn - if true, scrolling down will zoom in; otherwise scrolling down will zoom out.

© Copyright 2000-2008,
yWorks GmbH.
All rights reserved.