package prefuse.controls;_x000D_
_x000D_
import java.awt.Cursor;_x000D_
import java.awt.event.MouseEvent;_x000D_
import java.awt.geom.Point2D;_x000D_
_x000D_
import prefuse.Display;_x000D_
import prefuse.util.ui.UILib;_x000D_
import prefuse.visual.VisualItem;_x000D_
_x000D_
_x000D_
/**_x000D_
 * Zooms the display, changing the scale of the viewable region. By default,_x000D_
 * zooming is achieved by pressing the right mouse button on the background_x000D_
 * of the visualization and dragging the mouse up or down. Moving the mouse up_x000D_
 * zooms out the display around the spot the mouse was originally pressed._x000D_
 * Moving the mouse down similarly zooms in the display, making items_x000D_
 * larger._x000D_
 *_x000D_
 * @author <a href="http://jheer.org">jeffrey heer</a>_x000D_
 */_x000D_
public class ZoomControl extends AbstractZoomControl {_x000D_
    _x000D_
    private int yLast;_x000D_
    private Point2D down = new Point2D.Float();_x000D_
    private int button = RIGHT_MOUSE_BUTTON; _x000D_
    _x000D_
    /**_x000D_
     * Create a new zoom control._x000D_
     */_x000D_
    public ZoomControl() {_x000D_
        // do nothing_x000D_
    }_x000D_
    _x000D_
    /**_x000D_
     * Create a new zoom control._x000D_
     * @param mouseButton the mouse button that should initiate a zoom. One of_x000D_
     * {@link Control#LEFT_MOUSE_BUTTON}, {@link Control#MIDDLE_MOUSE_BUTTON},_x000D_
     * or {@link Control#RIGHT_MOUSE_BUTTON}._x000D_
     */_x000D_
    public ZoomControl(int mouseButton) {_x000D_
        button = mouseButton;_x000D_
    }_x000D_
    _x000D_
    /**_x000D_
     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void mousePressed(MouseEvent e) {_x000D_
        if ( UILib.isButtonPressed(e, button) ) {_x000D_
            Display display = (Display)e.getComponent();_x000D_
            if (display.isTranformInProgress()) {_x000D_
                yLast = -1;_x000D_
                System.err.println("can't move");_x000D_
                return;_x000D_
            }_x000D_
            display.setCursor(_x000D_
                Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));_x000D_
            display.getAbsoluteCoordinate(e.getPoint(), down);_x000D_
            yLast = e.getY();_x000D_
        }_x000D_
    }_x000D_
    _x000D_
    /**_x000D_
     * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void mouseDragged(MouseEvent e) {_x000D_
        if ( UILib.isButtonPressed(e, button) ) {_x000D_
            Display display = (Display)e.getComponent();_x000D_
            if (display.isTranformInProgress() || yLast == -1) {_x000D_
                yLast = -1;_x000D_
                return;_x000D_
            }_x000D_
            _x000D_
            int y = e.getY();_x000D_
            int dy = y-yLast;_x000D_
            double zoom = 1 + ((double)dy) / 100;_x000D_
            _x000D_
            int status = zoom(display, down, zoom, true);_x000D_
            int cursor = Cursor.N_RESIZE_CURSOR;_x000D_
            if ( status == NO_ZOOM )_x000D_
                cursor = Cursor.WAIT_CURSOR;_x000D_
            display.setCursor(Cursor.getPredefinedCursor(cursor));_x000D_
            _x000D_
            yLast = y;_x000D_
        }_x000D_
    }_x000D_
_x000D_
    /**_x000D_
     * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void mouseReleased(MouseEvent e) {_x000D_
        if ( UILib.isButtonPressed(e, button) ) {_x000D_
            e.getComponent().setCursor(Cursor.getDefaultCursor());_x000D_
        }_x000D_
    }_x000D_
    _x000D_
    /**_x000D_
     * @see prefuse.controls.Control#itemPressed(prefuse.visual.VisualItem, java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void itemPressed(VisualItem item, MouseEvent e) {_x000D_
        if ( m_zoomOverItem )_x000D_
            mousePressed(e);_x000D_
    }_x000D_
_x000D_
    /**_x000D_
     * @see prefuse.controls.Control#itemDragged(prefuse.visual.VisualItem, java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void itemDragged(VisualItem item, MouseEvent e) {_x000D_
        if ( m_zoomOverItem )_x000D_
            mouseDragged(e);_x000D_
    }_x000D_
    _x000D_
    /**_x000D_
     * @see prefuse.controls.Control#itemReleased(prefuse.visual.VisualItem, java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void itemReleased(VisualItem item, MouseEvent e) {_x000D_
        if ( m_zoomOverItem )_x000D_
            mouseReleased(e);_x000D_
    }_x000D_
    _x000D_
} // end of class ZoomControl_x000D_

/**_x000D_
     * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)_x000D_
     */
package prefuse.controls;_x000D_
_x000D_
import java.awt.Cursor;_x000D_
import java.awt.event.MouseEvent;_x000D_
import java.awt.geom.Point2D;_x000D_
_x000D_
import prefuse.Display;_x000D_
import prefuse.util.ui.UILib;_x000D_
import prefuse.visual.VisualItem;_x000D_
_x000D_
_x000D_
/**_x000D_
 * Zooms the display, changing the scale of the viewable region. By default,_x000D_
 * zooming is achieved by pressing the right mouse button on the background_x000D_
 * of the visualization and dragging the mouse up or down. Moving the mouse up_x000D_
 * zooms out the display around the spot the mouse was originally pressed._x000D_
 * Moving the mouse down similarly zooms in the display, making items_x000D_
 * larger._x000D_
 *_x000D_
 * @author <a href="http://jheer.org">jeffrey heer</a>_x000D_
 */_x000D_
public class ZoomControl extends AbstractZoomControl {_x000D_
    _x000D_
    private int yLast;_x000D_
    private Point2D down = new Point2D.Float();_x000D_
    private int button = RIGHT_MOUSE_BUTTON; _x000D_
    _x000D_
    /**_x000D_
     * Create a new zoom control._x000D_
     */_x000D_
    public ZoomControl() {_x000D_
        // do nothing_x000D_
    }_x000D_
    _x000D_
    /**_x000D_
     * Create a new zoom control._x000D_
     * @param mouseButton the mouse button that should initiate a zoom. One of_x000D_
     * {@link Control#LEFT_MOUSE_BUTTON}, {@link Control#MIDDLE_MOUSE_BUTTON},_x000D_
     * or {@link Control#RIGHT_MOUSE_BUTTON}._x000D_
     */_x000D_
    public ZoomControl(int mouseButton) {_x000D_
        button = mouseButton;_x000D_
    }_x000D_
    _x000D_
    /**_x000D_
     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void mousePressed(MouseEvent e) {_x000D_
        if ( UILib.isButtonPressed(e, button) ) {_x000D_
            Display display = (Display)e.getComponent();_x000D_
            if (display.isTranformInProgress()) {_x000D_
                yLast = -1;_x000D_
                System.err.println("can't move");_x000D_
                return;_x000D_
            }_x000D_
            display.setCursor(_x000D_
                Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));_x000D_
            display.getAbsoluteCoordinate(e.getPoint(), down);_x000D_
            yLast = e.getY();_x000D_
        }_x000D_
    }_x000D_
    _x000D_
    /**_x000D_
     * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)_x000D_
<SUF>*/_x000D_
    public void mouseDragged(MouseEvent e) {_x000D_
        if ( UILib.isButtonPressed(e, button) ) {_x000D_
            Display display = (Display)e.getComponent();_x000D_
            if (display.isTranformInProgress() || yLast == -1) {_x000D_
                yLast = -1;_x000D_
                return;_x000D_
            }_x000D_
            _x000D_
            int y = e.getY();_x000D_
            int dy = y-yLast;_x000D_
            double zoom = 1 + ((double)dy) / 100;_x000D_
            _x000D_
            int status = zoom(display, down, zoom, true);_x000D_
            int cursor = Cursor.N_RESIZE_CURSOR;_x000D_
            if ( status == NO_ZOOM )_x000D_
                cursor = Cursor.WAIT_CURSOR;_x000D_
            display.setCursor(Cursor.getPredefinedCursor(cursor));_x000D_
            _x000D_
            yLast = y;_x000D_
        }_x000D_
    }_x000D_
_x000D_
    /**_x000D_
     * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void mouseReleased(MouseEvent e) {_x000D_
        if ( UILib.isButtonPressed(e, button) ) {_x000D_
            e.getComponent().setCursor(Cursor.getDefaultCursor());_x000D_
        }_x000D_
    }_x000D_
    _x000D_
    /**_x000D_
     * @see prefuse.controls.Control#itemPressed(prefuse.visual.VisualItem, java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void itemPressed(VisualItem item, MouseEvent e) {_x000D_
        if ( m_zoomOverItem )_x000D_
            mousePressed(e);_x000D_
    }_x000D_
_x000D_
    /**_x000D_
     * @see prefuse.controls.Control#itemDragged(prefuse.visual.VisualItem, java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void itemDragged(VisualItem item, MouseEvent e) {_x000D_
        if ( m_zoomOverItem )_x000D_
            mouseDragged(e);_x000D_
    }_x000D_
    _x000D_
    /**_x000D_
     * @see prefuse.controls.Control#itemReleased(prefuse.visual.VisualItem, java.awt.event.MouseEvent)_x000D_
     */_x000D_
    public void itemReleased(VisualItem item, MouseEvent e) {_x000D_
        if ( m_zoomOverItem )_x000D_
            mouseReleased(e);_x000D_
    }_x000D_
    _x000D_
} // end of class ZoomControl_x000D_
