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