All Downloads are FREE. Search and download functionalities are using the official Maven repository.

prefuse.controls.WheelZoomControl Maven / Gradle / Ivy

Go to download

Prefuse is a set of software tools for creating rich interactive data visualizations in the Java programming language.

The newest version!
package prefuse.controls;

import java.awt.Point;
import java.awt.event.MouseWheelEvent;

import prefuse.Display;
import prefuse.visual.VisualItem;

/**
 * Zooms the display using the mouse scroll wheel, changing the scale of the
 * viewable region.
 *
 * @author Kevin Krumwiede
 * @author bobruney
 * @author mathis ahrens
 * @author jeffrey heer
 */
public class WheelZoomControl extends AbstractZoomControl {
    
    private Point m_point = new Point();
    private final boolean inverted;
    private final boolean atPointer;
    
    /**
     * Creates a new WheelZoomControl.  If inverted is true,
     * scrolling the mouse wheel toward you will make the graph appear
     * smaller.  If atPointer is true, zooming will be centered on
     * the mouse pointer instead of the center of the display.
     * 
     * @param inverted true if the scroll direction should be inverted
     * @param atPointer true if zooming should be centered on the mouse pointer
     */
    public WheelZoomControl(boolean inverted, boolean atPointer) {
    	this.inverted = inverted;
    	this.atPointer = atPointer;
    }
    
    /**
     * Creates a new WheelZoomControl with the default zoom direction
     * and zooming on the center of the display.
     */
    public WheelZoomControl() {
    	this(false, false);
    }
    
    /**
     * @see prefuse.controls.Control#itemWheelMoved(prefuse.visual.VisualItem, java.awt.event.MouseWheelEvent)
     */
    public void itemWheelMoved(VisualItem item, MouseWheelEvent e) {
        if ( m_zoomOverItem )
            mouseWheelMoved(e);
    }
    
    /**
     * @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)
     */
    public void mouseWheelMoved(MouseWheelEvent e) {
        Display display = (Display)e.getComponent();
        if(atPointer) m_point = e.getPoint();
        else {
        	m_point.x = display.getWidth()/2;
        	m_point.y = display.getHeight()/2;
        }
        if(inverted) zoom(display, m_point, 1 - 0.1f * e.getWheelRotation(), false);
        else zoom(display, m_point, 1 + 0.1f * e.getWheelRotation(), false);
    }
    
} // end of class WheelZoomControl




© 2015 - 2025 Weber Informatics LLC | Privacy Policy