Line | Hits | Source |
---|---|---|
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() { | |
39 | 0 | this(MouseEvent.BUTTON1_MASK); |
40 | 0 | } |
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) { | |
47 | 0 | super(modifiers); |
48 | 0 | this.cursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); |
49 | 0 | } |
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) { | |
58 | 0 | VisualizationViewer vv = (VisualizationViewer)e.getSource(); |
59 | 0 | boolean accepted = checkModifiers(e); |
60 | 0 | down = e.getPoint(); |
61 | 0 | if(accepted) { |
62 | 0 | vv.setCursor(cursor); |
63 | } | |
64 | 0 | } |
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) { | |
71 | 0 | VisualizationViewer vv = (VisualizationViewer)e.getSource(); |
72 | 0 | down = null; |
73 | 0 | vv.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
74 | 0 | } |
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) { | |
82 | 0 | VisualizationViewer vv = (VisualizationViewer)e.getSource(); |
83 | 0 | boolean accepted = checkModifiers(e); |
84 | 0 | if(accepted) { |
85 | 0 | MutableTransformer viewTransformer = vv.getViewTransformer(); |
86 | 0 | vv.setCursor(cursor); |
87 | try { | |
88 | 0 | Point2D q = viewTransformer.inverseTransform(down); |
89 | 0 | Point2D p = viewTransformer.inverseTransform(e.getPoint()); |
90 | 0 | float dx = (float) (p.getX()-q.getX()); |
91 | 0 | float dy = (float) (p.getY()-q.getY()); |
92 | ||
93 | 0 | viewTransformer.translate(dx, dy); |
94 | 0 | down.x = e.getX(); |
95 | 0 | down.y = e.getY(); |
96 | 0 | } catch(RuntimeException ex) { |
97 | 0 | System.err.println("down = "+down+", e = "+e); |
98 | 0 | throw ex; |
99 | 0 | } |
100 | ||
101 | 0 | e.consume(); |
102 | } | |
103 | 0 | } |
104 | ||
105 | public void mouseClicked(MouseEvent e) { | |
106 | // TODO Auto-generated method stub | |
107 | ||
108 | 0 | } |
109 | ||
110 | public void mouseEntered(MouseEvent e) { | |
111 | // TODO Auto-generated method stub | |
112 | ||
113 | 0 | } |
114 | ||
115 | public void mouseExited(MouseEvent e) { | |
116 | // TODO Auto-generated method stub | |
117 | ||
118 | 0 | } |
119 | ||
120 | public void mouseMoved(MouseEvent e) { | |
121 | // TODO Auto-generated method stub | |
122 | ||
123 | 0 | } |
124 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |