Skip to content

Commit 73e02bb

Browse files
committed
Merge pull request #50 from ProgrammingLife3/fix/removedefaultkeys
Fix/removedefaultkeys
2 parents 5878d24 + 4e1cfee commit 73e02bb

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

src/main/java/tudelft/ti2806/pl3/Application.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void makeGraph() {
116116
graphView.getController().init();
117117

118118
graphView.getPanel().addKeyListener(keys);
119-
119+
120120
this.setFocusable(true);
121121

122122
long loadTime = System.currentTimeMillis() - startTime;

src/main/java/tudelft/ti2806/pl3/visualization/GraphView.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.graphstream.graph.implementations.SingleGraph;
66
import org.graphstream.ui.swingViewer.View;
77
import org.graphstream.ui.swingViewer.Viewer;
8+
import org.graphstream.ui.swingViewer.util.DefaultShortcutManager;
89
import tudelft.ti2806.pl3.LoadingObservable;
910
import tudelft.ti2806.pl3.LoadingObserver;
1011
import tudelft.ti2806.pl3.data.graph.AbstractGraphData;
@@ -24,8 +25,9 @@
2425
* The GraphView is responsible for adding the nodes and edges to the graph,
2526
* keeping the nodes and edges on the right positions and applying the right
2627
* style to the graph.
27-
*
28+
*
2829
* @author Sam Smulders
30+
*
2931
*/
3032
public class GraphView implements Observer, tudelft.ti2806.pl3.View, ViewInterface, LoadingObservable {
3133
/**
@@ -41,12 +43,12 @@ public class GraphView implements Observer, tudelft.ti2806.pl3.View, ViewInterfa
4143
* The position on the x axis.
4244
*/
4345
private float zoomCenter = 1;
44-
46+
4547
/**
4648
* The css style sheet used drawing the graph.<br>
4749
* Generate a new view to have the changes take effect.
4850
*/
49-
51+
5052
private List<WrapperClone> graphData;
5153
private Graph graph = new SingleGraph("Graph");
5254
private Viewer viewer;
@@ -103,7 +105,7 @@ public void init() {
103105
setZoomCenter(600);
104106
notifyLoadingObservers(false);
105107
}
106-
108+
107109
/**
108110
* Generates a {@link Viewer} for the graph with the given {@code zoomLevel}
109111
* . A new Viewer should be constructed every time the graphData or
@@ -113,6 +115,16 @@ private void generateViewer() {
113115
viewer = new Viewer(graph,
114116
Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
115117
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();
116128
}
117129

118130
/**
@@ -125,10 +137,10 @@ private void setGraphPropertys() {
125137
graph.addAttribute("ui.antialias");
126138
graph.addAttribute("ui.stylesheet", "url('" + stylesheet + "')");
127139
}
128-
140+
129141
/**
130142
* Generates a Graph from the current graphData.
131-
*
143+
*
132144
* @return a graph with all nodes from the given graphData
133145
*/
134146
public Graph generateGraph() {
@@ -160,27 +172,27 @@ public Graph generateGraph() {
160172
notifyLoadingObservers(false);
161173
return graph;
162174
}
163-
175+
164176
/**
165177
* Adds an edge between two nodes.
166-
*
178+
*
167179
* @param graph
168-
* the graph to add the edge to
180+
* the graph to add the edge to
169181
* @param from
170-
* the node where the edge begins
182+
* the node where the edge begins
171183
* @param to
172-
* the node where the edge ends
184+
* the node where the edge ends
173185
*/
174186
@SuppressWarnings("PMD.UnusedPrivateMethod")
175187
private static void addNormalEdge(Graph graph, Wrapper from, Wrapper to) {
176188
graph.addEdge(from.getId() + "-" + to.getId(), Integer.toString(from.getId()), Integer.toString(to.getId()), true);
177189
}
178-
190+
179191
@Override
180192
public Component getPanel() {
181193
return panel;
182194
}
183-
195+
184196
@Override
185197
public GraphController getController() {
186198
return graphController;
@@ -196,15 +208,15 @@ public void update(Observable o, Object arg) {
196208
zoom();
197209
}
198210
}
199-
211+
200212
private void zoom() {
201213
viewer.getDefaultView().getCamera().setViewPercent(1 / zoomLevel);
202214
}
203215

204216
public float getZoomCenter() {
205217
return zoomCenter;
206218
}
207-
219+
208220
/**
209221
* Moves the view to the given position on the x axis.
210222
*

0 commit comments

Comments
 (0)