5
5
import org .graphstream .graph .implementations .SingleGraph ;
6
6
import org .graphstream .ui .swingViewer .View ;
7
7
import org .graphstream .ui .swingViewer .Viewer ;
8
+ import org .graphstream .ui .swingViewer .util .DefaultShortcutManager ;
8
9
import tudelft .ti2806 .pl3 .LoadingObservable ;
9
10
import tudelft .ti2806 .pl3 .LoadingObserver ;
10
11
import tudelft .ti2806 .pl3 .data .graph .AbstractGraphData ;
24
25
* The GraphView is responsible for adding the nodes and edges to the graph,
25
26
* keeping the nodes and edges on the right positions and applying the right
26
27
* style to the graph.
27
- *
28
+ *
28
29
* @author Sam Smulders
30
+ *
29
31
*/
30
32
public class GraphView implements Observer , tudelft .ti2806 .pl3 .View , ViewInterface , LoadingObservable {
31
33
/**
@@ -41,12 +43,12 @@ public class GraphView implements Observer, tudelft.ti2806.pl3.View, ViewInterfa
41
43
* The position on the x axis.
42
44
*/
43
45
private float zoomCenter = 1 ;
44
-
46
+
45
47
/**
46
48
* The css style sheet used drawing the graph.<br>
47
49
* Generate a new view to have the changes take effect.
48
50
*/
49
-
51
+
50
52
private List <WrapperClone > graphData ;
51
53
private Graph graph = new SingleGraph ("Graph" );
52
54
private Viewer viewer ;
@@ -103,7 +105,7 @@ public void init() {
103
105
setZoomCenter (600 );
104
106
notifyLoadingObservers (false );
105
107
}
106
-
108
+
107
109
/**
108
110
* Generates a {@link Viewer} for the graph with the given {@code zoomLevel}
109
111
* . A new Viewer should be constructed every time the graphData or
@@ -113,6 +115,16 @@ private void generateViewer() {
113
115
viewer = new Viewer (graph ,
114
116
Viewer .ThreadingModel .GRAPH_IN_ANOTHER_THREAD );
115
117
panel = viewer .addDefaultView (false );
118
+ removeDefaultKeys ();
119
+ }
120
+
121
+ /**
122
+ * Remove the default keys from the GraphStream library, since we use our own.
123
+ * There is no other way than this to do it.
124
+ */
125
+ public void removeDefaultKeys () {
126
+ DefaultShortcutManager listener = (DefaultShortcutManager )this .getPanel ().getKeyListeners ()[0 ];
127
+ listener .release ();
116
128
}
117
129
118
130
/**
@@ -125,10 +137,10 @@ private void setGraphPropertys() {
125
137
graph .addAttribute ("ui.antialias" );
126
138
graph .addAttribute ("ui.stylesheet" , "url('" + stylesheet + "')" );
127
139
}
128
-
140
+
129
141
/**
130
142
* Generates a Graph from the current graphData.
131
- *
143
+ *
132
144
* @return a graph with all nodes from the given graphData
133
145
*/
134
146
public Graph generateGraph () {
@@ -160,27 +172,27 @@ public Graph generateGraph() {
160
172
notifyLoadingObservers (false );
161
173
return graph ;
162
174
}
163
-
175
+
164
176
/**
165
177
* Adds an edge between two nodes.
166
- *
178
+ *
167
179
* @param graph
168
- * the graph to add the edge to
180
+ * the graph to add the edge to
169
181
* @param from
170
- * the node where the edge begins
182
+ * the node where the edge begins
171
183
* @param to
172
- * the node where the edge ends
184
+ * the node where the edge ends
173
185
*/
174
186
@ SuppressWarnings ("PMD.UnusedPrivateMethod" )
175
187
private static void addNormalEdge (Graph graph , Wrapper from , Wrapper to ) {
176
188
graph .addEdge (from .getId () + "-" + to .getId (), Integer .toString (from .getId ()), Integer .toString (to .getId ()), true );
177
189
}
178
-
190
+
179
191
@ Override
180
192
public Component getPanel () {
181
193
return panel ;
182
194
}
183
-
195
+
184
196
@ Override
185
197
public GraphController getController () {
186
198
return graphController ;
@@ -196,15 +208,15 @@ public void update(Observable o, Object arg) {
196
208
zoom ();
197
209
}
198
210
}
199
-
211
+
200
212
private void zoom () {
201
213
viewer .getDefaultView ().getCamera ().setViewPercent (1 / zoomLevel );
202
214
}
203
215
204
216
public float getZoomCenter () {
205
217
return zoomCenter ;
206
218
}
207
-
219
+
208
220
/**
209
221
* Moves the view to the given position on the x axis.
210
222
*
0 commit comments