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

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  * TranslatingGraphMousePlugin uses a MouseButtonOne press and
25  * drag gesture to translate the graph display in the x and y
26  * direction. The default MouseButtonOne modifier can be overridden
27  * to cause a different mouse gesture to translate the display.
28  *
29  *
30  * @author Tom Nelson
31  */
32 public class TranslatingGraphMousePlugin extends AbstractGraphMousePlugin
33     implements MouseListener, MouseMotionListener {
34  
35     /**
36      */
37     public TranslatingGraphMousePlugin() {
380        this(MouseEvent.BUTTON1_MASK);
390    }
40  
41     /**
42      * create an instance with passed modifer value
43      * @param modifiers the mouse event modifier to activate this function
44      */
45     public TranslatingGraphMousePlugin(int modifiers) {
460        super(modifiers);
470        this.cursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
480    }
49  
50     /**
51      * Check the event modifiers. Set the 'down' point for later
52      * use. If this event satisfies the modifiers, change the cursor
53      * to the system 'move cursor'
54      * @param e the event
55      */
56     public void mousePressed(MouseEvent e) {
570        VisualizationViewer vv = (VisualizationViewer)e.getSource();
580        boolean accepted = checkModifiers(e);
590        down = e.getPoint();
600        if(accepted) {
610            vv.setCursor(cursor);
62         }
630    }
64     
65     /**
66      * unset the 'down' point and change the cursoe back to the system
67      * default cursor
68      */
69     public void mouseReleased(MouseEvent e) {
700        VisualizationViewer vv = (VisualizationViewer)e.getSource();
710        down = null;
720        vv.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
730    }
74     
75     /**
76      * chack the modifiers. If accepted, translate the graph according
77      * to the dragging of the mouse pointer
78      * @param e the event
79      */
80     public void mouseDragged(MouseEvent e) {
810        VisualizationViewer vv = (VisualizationViewer)e.getSource();
820        boolean accepted = checkModifiers(e);
830        if(accepted) {
840            MutableTransformer modelTransformer = vv.getLayoutTransformer();
850            vv.setCursor(cursor);
86             try {
870                Point2D q = vv.inverseTransform(down);
880                Point2D p = vv.inverseTransform(e.getPoint());
890                float dx = (float) (p.getX()-q.getX());
900                float dy = (float) (p.getY()-q.getY());
91                 
920                modelTransformer.translate(dx, dy);
930                down.x = e.getX();
940                down.y = e.getY();
950            } catch(RuntimeException ex) {
960                System.err.println("down = "+down+", e = "+e);
970                throw ex;
980            }
99         
1000            e.consume();
101         }
1020    }
103  
104     public void mouseClicked(MouseEvent e) {
105         // TODO Auto-generated method stub
106         
1070    }
108  
109     public void mouseEntered(MouseEvent e) {
110         // TODO Auto-generated method stub
111         
1120    }
113  
114     public void mouseExited(MouseEvent e) {
115         // TODO Auto-generated method stub
116         
1170    }
118  
119     public void mouseMoved(MouseEvent e) {
120         // TODO Auto-generated method stub
121         
1220    }
123 }

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.