1
2
3
4
5
6
7
8
9
10
11 package edu.uci.ics.jung.visualization.control;
12
13 import java.awt.Component;
14 import java.awt.Cursor;
15 import java.awt.event.InputEvent;
16 import java.awt.event.KeyAdapter;
17 import java.awt.event.KeyEvent;
18
19
20
21
22
23
24
25
26 public class ModalLensGraphMouse extends AbstractModalGraphMouse implements
27 ModalGraphMouse {
28
29
30
31
32 protected LensMagnificationGraphMousePlugin magnificationPlugin;
33
34 public ModalLensGraphMouse() {
35 this(1.1f, 1/1.1f);
36 }
37
38 public ModalLensGraphMouse(float in, float out) {
39 this(in, out, new LensMagnificationGraphMousePlugin());
40 }
41
42 public ModalLensGraphMouse(LensMagnificationGraphMousePlugin magnificationPlugin) {
43 this(1.1f, 1/1.1f, magnificationPlugin);
44 }
45
46 public ModalLensGraphMouse(float in, float out, LensMagnificationGraphMousePlugin magnificationPlugin) {
47 super(in,out);
48 this.in = in;
49 this.out = out;
50 this.magnificationPlugin = magnificationPlugin;
51 loadPlugins();
52 setModeKeyListener(new ModeKeyAdapter(this));
53 }
54
55 protected void loadPlugins() {
56 pickingPlugin = new PickingGraphMousePlugin();
57 animatedPickingPlugin = new AnimatedPickingGraphMousePlugin();
58 translatingPlugin = new LensTranslatingGraphMousePlugin(InputEvent.BUTTON1_MASK);
59 scalingPlugin = new ScalingGraphMousePlugin(new CrossoverScalingControl(), 0, in, out);
60 rotatingPlugin = new RotatingGraphMousePlugin();
61 shearingPlugin = new ShearingGraphMousePlugin();
62
63 add(magnificationPlugin);
64 add(scalingPlugin);
65
66 setMode(Mode.TRANSFORMING);
67 }
68 public static class ModeKeyAdapter extends KeyAdapter {
69 private char t = 't';
70 private char p = 'p';
71 protected ModalGraphMouse graphMouse;
72
73 public ModeKeyAdapter(ModalGraphMouse graphMouse) {
74 this.graphMouse = graphMouse;
75 }
76
77 public ModeKeyAdapter(char t, char p, ModalGraphMouse graphMouse) {
78 this.t = t;
79 this.p = p;
80 this.graphMouse = graphMouse;
81 }
82
83 public void keyTyped(KeyEvent event) {
84 char keyChar = event.getKeyChar();
85 if(keyChar == t) {
86 ((Component)event.getSource()).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
87 graphMouse.setMode(Mode.TRANSFORMING);
88 } else if(keyChar == p) {
89 ((Component)event.getSource()).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
90 graphMouse.setMode(Mode.PICKING);
91 }
92 }
93 }
94
95 }