Coverage details for edu.uci.ics.jung.visualization.control.ScalingGraphMousePlugin

LineHitsSource
1 /*
2  * Copyright (c) 2005, the JUNG Project and the Regents of the University
3  * of California
4  * All rights reserved.
5  *
6  * This software is open-source under the BSD license; see either
7  * "license.txt" or
8  * http://jung.sourceforge.net/license.txt for a description.
9  * Created on Mar 8, 2005
10  *
11  */
12 package edu.uci.ics.jung.visualization.control;
13  
14 import java.awt.event.MouseEvent;
15 import java.awt.event.MouseWheelEvent;
16 import java.awt.event.MouseWheelListener;
17 import java.awt.geom.Point2D;
18  
19 import edu.uci.ics.jung.visualization.VisualizationViewer;
20  
21 /**
22  * ScalingGraphMouse applies a scaling transformation to the graph layout.
23  * The Vertices get closer or farther apart, but do not themselves change
24  * size. ScalingGraphMouse uses MouseWheelEvents to apply the scaling.
25  *
26  * @author Tom Nelson
27  */
28 public class ScalingGraphMousePlugin extends AbstractGraphMousePlugin
29     implements MouseWheelListener {
30  
31     /**
32      * the amount to zoom in by
33      */
340    protected float in = 1.1f;
35     /**
36      * the amount to zoom out by
37      */
380    protected float out = 1/1.1f;
39     
40     /**
41      * whether to center the zoom at the current mouse position
42      */
430    protected boolean zoomAtMouse = true;
44     
45     /**
46      * controls scaling operations
47      */
48     protected ScalingControl scaler;
49     
50     public ScalingGraphMousePlugin(ScalingControl scaler, int modifiers) {
510        this(scaler, modifiers, 1.1f, 1/1.1f);
520    }
53     
54     public ScalingGraphMousePlugin(ScalingControl scaler, int modifiers, float in, float out) {
550        super(modifiers);
560        this.scaler = scaler;
570        this.in = in;
580        this.out = out;
590    }
60    /**
61      * @param zoomAtMouse The zoomAtMouse to set.
62      */
63     public void setZoomAtMouse(boolean zoomAtMouse) {
640        this.zoomAtMouse = zoomAtMouse;
650    }
66     
67     public boolean checkModifiers(MouseEvent e) {
680        return e.getModifiers() == modifiers || (e.getModifiers() & modifiers) != 0;
69     }
70  
71     /**
72      * zoom the display in or out, depending on the direction of the
73      * mouse wheel motion.
74      */
75     public void mouseWheelMoved(MouseWheelEvent e) {
760        boolean accepted = checkModifiers(e);
770        if(accepted == true) {
780            VisualizationViewer vv = (VisualizationViewer)e.getSource();
790            Point2D mouse = e.getPoint();
800            Point2D center = vv.getCenter();
810            int amount = e.getWheelRotation();
820            if(zoomAtMouse) {
830                if(amount > 0) {
840                    scaler.scale(vv, in, mouse);
850                } else if(amount < 0) {
860                    scaler.scale(vv, out, mouse);
87                 }
88             } else {
890                if(amount > 0) {
900                    scaler.scale(vv, in, center);
910                } else if(amount < 0) {
920                    scaler.scale(vv, out, center);
93                 }
94             }
950            e.consume();
960            vv.repaint();
97         }
980    }
99     /**
100      * @return Returns the zoom in value.
101      */
102     public float getIn() {
1030        return in;
104     }
105     /**
106      * @param in The zoom in value to set.
107      */
108     public void setIn(float in) {
1090        this.in = in;
1100    }
111     /**
112      * @return Returns the zoom out value.
113      */
114     public float getOut() {
1150        return out;
116     }
117     /**
118      * @param out The zoom out value to set.
119      */
120     public void setOut(float out) {
1210        this.out = out;
1220    }
123  
124     public ScalingControl getScaler() {
1250        return scaler;
126     }
127  
128     public void setScaler(ScalingControl scaler) {
1290        this.scaler = scaler;
1300    }
131 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.