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

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  
18 import edu.uci.ics.jung.visualization.VisualizationViewer;
19 import edu.uci.ics.jung.visualization.transform.LensTransformer;
20 import edu.uci.ics.jung.visualization.transform.MutableTransformer;
21  
22 /**
23  * HyperbolicMagnificationGraphMousePlugin changes the magnification
24  * within the Hyperbolic projection of the HyperbolicTransformer.
25  *
26  * @author Tom Nelson
27  */
28 public class LensMagnificationGraphMousePlugin extends AbstractGraphMousePlugin
29     implements MouseWheelListener {
30  
310    protected float floor = .5f;
32     
330    protected float ceiling = .9f;
34     
350    protected float delta = .02f;
36     
37     /**
38      * create an instance with default zoom in/out values
39      */
40     public LensMagnificationGraphMousePlugin() {
410        this(MouseEvent.CTRL_MASK);
420    }
43     
44     /**
45      * create an instance with passed modifiers
46      * @param modifiers
47      */
48     public LensMagnificationGraphMousePlugin(float floor, float ceiling, float delta) {
490        this(MouseEvent.CTRL_MASK, floor, ceiling, delta);
500    }
51     
52     public LensMagnificationGraphMousePlugin(int modifiers) {
530        this(modifiers, .5f, .9f, .02f);
540    }
55     public LensMagnificationGraphMousePlugin(int modifiers, float floor, float ceiling, float delta) {
560        super(modifiers);
570        this.floor = floor;
580        this.ceiling = ceiling;
590        this.delta = delta;
600    }
61     /**
62      * override to check equality with a mask
63      */
64     public boolean checkModifiers(MouseEvent e) {
650        return (e.getModifiers() & modifiers) != 0;
66     }
67  
68     private void changeMagnification(MutableTransformer transformer, float delta) {
690        if(transformer instanceof LensTransformer) {
700            LensTransformer ht = (LensTransformer)transformer;
710            float magnification = ht.getMagnification() + delta;
720            magnification = Math.max(floor, magnification);
730            magnification = Math.min(magnification, ceiling);
740            ht.setMagnification(magnification);
75         }
760    }
77     /**
78      * zoom the display in or out, depending on the direction of the
79      * mouse wheel motion.
80      */
81     public void mouseWheelMoved(MouseWheelEvent e) {
820        boolean accepted = checkModifiers(e);
830        float delta = this.delta;
840        if(accepted == true) {
850            VisualizationViewer vv = (VisualizationViewer)e.getSource();
860            MutableTransformer modelTransformer = vv.getLayoutTransformer();
870            MutableTransformer viewTransformer = vv.getViewTransformer();
880            int amount = e.getWheelRotation();
890            if(amount < 0) {
900                delta = -delta;
91             }
920            changeMagnification(modelTransformer, delta);
930            changeMagnification(viewTransformer, delta);
940            vv.repaint();
950            e.consume();
96         }
970    }
98 }

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.