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

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.Cursor;
15 import java.awt.event.MouseEvent;
16 import java.awt.event.MouseListener;
17 import java.awt.event.MouseMotionListener;
18 import java.awt.geom.Point2D;
19  
20 import edu.uci.ics.jung.visualization.VisualizationViewer;
21 import edu.uci.ics.jung.visualization.transform.MutableTransformer;
22  
23 /**
24  * ViewTranslatingGraphMousePlugin uses a MouseButtonOne press and
25  * drag gesture to translate the graph display in the x and y
26  * direction by changing the AffineTransform applied to the Graphics2D.
27  * The default MouseButtonOne modifier can be overridden
28  * to cause a different mouse gesture to translate the display.
29  *
30  *
31  * @author Tom Nelson
32  */
33 public class ViewTranslatingGraphMousePlugin extends AbstractGraphMousePlugin
34     implements MouseListener, MouseMotionListener {
35  
36     /**
37      */
38     public ViewTranslatingGraphMousePlugin() {
390        this(MouseEvent.BUTTON1_MASK);
400    }
41  
42     /**
43      * create an instance with passed modifer value
44      * @param modifiers the mouse event modifier to activate this function
45      */
46     public ViewTranslatingGraphMousePlugin(int modifiers) {
470        super(modifiers);
480        this.cursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
490    }
50  
51     /**
52      * Check the event modifiers. Set the 'down' point for later
53      * use. If this event satisfies the modifiers, change the cursor
54      * to the system 'move cursor'
55      * @param e the event
56      */
57     public void mousePressed(MouseEvent e) {
580        VisualizationViewer vv = (VisualizationViewer)e.getSource();
590        boolean accepted = checkModifiers(e);
600        down = e.getPoint();
610        if(accepted) {
620            vv.setCursor(cursor);
63         }
640    }
65     
66     /**
67      * unset the 'down' point and change the cursoe back to the system
68      * default cursor
69      */
70     public void mouseReleased(MouseEvent e) {
710        VisualizationViewer vv = (VisualizationViewer)e.getSource();
720        down = null;
730        vv.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
740    }
75     
76     /**
77      * chack the modifiers. If accepted, translate the graph according
78      * to the dragging of the mouse pointer
79      * @param e the event
80      */
81     public void mouseDragged(MouseEvent e) {
820        VisualizationViewer vv = (VisualizationViewer)e.getSource();
830        boolean accepted = checkModifiers(e);
840        if(accepted) {
850            MutableTransformer viewTransformer = vv.getViewTransformer();
860            vv.setCursor(cursor);
87             try {
880                Point2D q = viewTransformer.inverseTransform(down);
890                Point2D p = viewTransformer.inverseTransform(e.getPoint());
900                float dx = (float) (p.getX()-q.getX());
910                float dy = (float) (p.getY()-q.getY());
92                 
930                viewTransformer.translate(dx, dy);
940                down.x = e.getX();
950                down.y = e.getY();
960            } catch(RuntimeException ex) {
970                System.err.println("down = "+down+", e = "+e);
980                throw ex;
990            }
100         
1010            e.consume();
102         }
1030    }
104  
105     public void mouseClicked(MouseEvent e) {
106         // TODO Auto-generated method stub
107         
1080    }
109  
110     public void mouseEntered(MouseEvent e) {
111         // TODO Auto-generated method stub
112         
1130    }
114  
115     public void mouseExited(MouseEvent e) {
116         // TODO Auto-generated method stub
117         
1180    }
119  
120     public void mouseMoved(MouseEvent e) {
121         // TODO Auto-generated method stub
122         
1230    }
124 }

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.