From 237edea766d62a2b3427b4f2eb8e1386b8b4e6e7 Mon Sep 17 00:00:00 2001 From: Mikael Capelle Date: Tue, 20 Feb 2018 11:41:18 +0100 Subject: [PATCH] Update MainWindow to allow choice of mode for SP. --- src/main/org/insa/base/MainWindow.java | 37 +++++++++++--------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/main/org/insa/base/MainWindow.java b/src/main/org/insa/base/MainWindow.java index f296fde..d9e9cc9 100644 --- a/src/main/org/insa/base/MainWindow.java +++ b/src/main/org/insa/base/MainWindow.java @@ -8,11 +8,9 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.geom.NoninvertibleTransformException; -import java.awt.geom.Point2D; import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -144,22 +142,11 @@ public class MainWindow extends JFrame { return; } - System.out.println("MOUSE CLICKED: " + evt.getPoint() + " -> " + lonlat); + Node node = graph.findClosestNode(lonlat); - ArrayList nodes = graph.getNodes(); - Node node = null; - double minDis = Double.POSITIVE_INFINITY; - for (int n = 0 ; n < nodes.size(); ++n) { - double dis = lonlat.distanceTo(nodes.get(n).getPoint()); - if (dis < minDis) { - node = nodes.get(n); - minDis = dis; - } - } new GraphDrawing(drawing).drawPoint(node.getPoint(), 10, Color.BLUE); points.add(node); if (points.size() == nTargetPoints) { - System.out.println("CALLABLE!"); callable.call(points); this.disable(); } @@ -487,13 +474,21 @@ public class MainWindow extends JFrame { bellmanItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - clickAdapter.enable(2, new CallableWithNodes() { - @Override - public void call(ArrayList nodes) { - launchShortestPathThread(new BellmanFordAlgorithm( - new ShortestPathInstance(graph, nodes.get(0), nodes.get(1), Mode.TIME))); - } - }); + int idx = JOptionPane.showOptionDialog(MainWindow.this, + "Which mode do you want?", "Mode selection", + JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, + null, Mode.values(), Mode.LENGTH); + + if (idx != -1) { + Mode mode = Mode.values()[idx]; + clickAdapter.enable(2, new CallableWithNodes() { + @Override + public void call(ArrayList nodes) { + launchShortestPathThread(new BellmanFordAlgorithm( + new ShortestPathInstance(graph, nodes.get(0), nodes.get(1), mode))); + } + }); + } } }); graphItems.add(wccItem);