Search this API

y.view
Class Graph2DViewMouseWheelZoomListener

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

public class Graph2DViewMouseWheelZoomListener
extends java.lang.Object
implements java.awt.event.MouseWheelListener

Zooms a Graph2DView's view port in response to mouse wheel events.

Instances of this class should be registered as a listener for mouse wheel events using method addToCanvas(Graph2DView).

See Also:
Graph2DViewMouseWheelScrollListener
 
Your browser does not support SVG content.

Field Summary
protected  java.awt.event.MouseWheelEvent lastMouseWheelEvent
          Stores last mouse event received via mouseWheelMoved(MouseWheelEvent)
 
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
 void addToCanvas(Graph2DView view)
          Adds this listener to the set of listeners that are notified of mouse wheel events for the specified view.
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.
 java.awt.Color getZoomIndicatorColor()
          Returns the base color of the zoom indicator.
protected  boolean isCenterZoomEvent(java.awt.event.MouseWheelEvent mwe)
          Determines whether for the current event center zooming should be used.
 boolean isCenterZooming()
          Returns the property centerZooming.
 boolean isDownInZooming()
          Returns property downInZooming.
 boolean isLimitMinimumZoomByContentSize()
          Returns whether or not the minimum zoom level shall be bound by the maximum zoom level that will still allow to fit the complete graph into the view.
 boolean isZoomIndicatorShowing()
          Returns whether or not the view shall display an animated zoom indicator at the mouse position whenever the zoom level gets changed by this class.
 void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
           
protected  void paintZoomIndicator(java.awt.Graphics2D gfx, int x, int y, int width, int height, double time, java.awt.event.MouseWheelEvent ev)
          Paints the zoom indicator inside the given bounds.
 void removeFromCanvas(Graph2DView view)
          Removes this listener from the set of listeners that are notified of mouse wheel events for the specified view.
 void setCenterZooming(boolean centerZooming)
          Sets the property centerZooming.
 void setDownInZooming(boolean downIn)
          Sets property downInZooming.
 void setLimitMinimumZoomByContentSize(boolean limitMinimumZoomByContentSize)
          Sets whether or not the minimum zoom level shall be bound by the maximum zoom level that will still allow to fit the complete graph into the view.
 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.
 void setZoomIndicatorColor(java.awt.Color zoomIndicatorColor)
          Sets the base color of the zoom indicator.
 void setZoomIndicatorShowing(boolean zoomIndicatorShowing)
          Whether or not the view shall display an animated zoom indicator at the mouse position whenever the zoom level gets changed by this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastMouseWheelEvent

protected java.awt.event.MouseWheelEvent lastMouseWheelEvent
Stores last mouse event received via mouseWheelMoved(MouseWheelEvent)

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

addToCanvas

public void addToCanvas(Graph2DView view)
Adds this listener to the set of listeners that are notified of mouse wheel events for the specified view. Invoking this method is equivalent to:
view.getCanvasComponent().addMouseWheelListener(this);

Parameters:
view - the Graph2DView instance whose mouse wheel events should be handled by this listener.
See Also:
removeFromCanvas(Graph2DView)

removeFromCanvas

public void removeFromCanvas(Graph2DView view)
Removes this listener from the set of listeners that are notified of mouse wheel events for the specified view. Invoking this method is equivalent to:
view.getCanvasComponent().removeMouseWheelListener(this);

Parameters:
view - the Graph2DView instance whose mouse wheel events were handled by this listener.
See Also:
addToCanvas(Graph2DView)

setLimitMinimumZoomByContentSize

public void setLimitMinimumZoomByContentSize(boolean limitMinimumZoomByContentSize)
Sets whether or not the minimum zoom level shall be bound by the maximum zoom level that will still allow to fit the complete graph into the view. By default this feature is disabled.


isLimitMinimumZoomByContentSize

public boolean isLimitMinimumZoomByContentSize()
Returns whether or not the minimum zoom level shall be bound by the maximum zoom level that will still allow to fit the complete graph into the view. By default this feature is disabled.


mouseWheelMoved

public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
Specified by:
mouseWheelMoved in interface java.awt.event.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(java.awt.event.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.

setZoomIndicatorShowing

public void setZoomIndicatorShowing(boolean zoomIndicatorShowing)
Whether or not the view shall display an animated zoom indicator at the mouse position whenever the zoom level gets changed by this class. By default this feature is disabled.


isZoomIndicatorShowing

public boolean isZoomIndicatorShowing()
Returns whether or not the view shall display an animated zoom indicator at the mouse position whenever the zoom level gets changed by this class. By default this feature is disabled.


paintZoomIndicator

protected void paintZoomIndicator(java.awt.Graphics2D gfx,
                                  int x,
                                  int y,
                                  int width,
                                  int height,
                                  double time,
                                  java.awt.event.MouseWheelEvent ev)
Paints the zoom indicator inside the given bounds. The given bounds are measured in view coordinate space. The default implementation makes use of the color returned by getZoomIndicatorColor().

Parameters:
time - a value between 0.0 and 1.0 that indicates what frame of the zoom indicator animation needs to be painted.
See Also:
AnimationObject

setZoomIndicatorColor

public void setZoomIndicatorColor(java.awt.Color zoomIndicatorColor)
Sets the base color of the zoom indicator.


getZoomIndicatorColor

public java.awt.Color getZoomIndicatorColor()
Returns the base color of the zoom indicator.


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