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