From 0c20cd68402c90697d106e6a1e06182220f58b88 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sun, 5 May 2024 12:32:44 +0200 Subject: [PATCH] [fix] Fix crash with empty string, remove some prints --- .../java/fr/u_paris/gla/project/gui/View.java | 79 ++++--------------- 1 file changed, 14 insertions(+), 65 deletions(-) diff --git a/src/main/java/fr/u_paris/gla/project/gui/View.java b/src/main/java/fr/u_paris/gla/project/gui/View.java index 6ed68bf..0c89a9a 100644 --- a/src/main/java/fr/u_paris/gla/project/gui/View.java +++ b/src/main/java/fr/u_paris/gla/project/gui/View.java @@ -290,6 +290,7 @@ public class View extends JFrame { }); } }); + SeeStopButton.addActionListener(f -> { Connection c; if ((c = (Connection) StopsLinesComboBox.getSelectedItem()) != null) { @@ -316,35 +317,28 @@ public class View extends JFrame { } }); - ButtonLocation.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + ButtonLocation.addActionListener(e -> { + String cur = TextLocation.getText(); + if (!cur.isEmpty()) { CardPanel.removeAll(); - String cur = TextLocation.getText(); LoadStringStops(cur); LoadSearchResultItinerary(searchResPath, modelItinerary); - System.out.println("search location clicked with text " + cur); CardPanel.add(ItineraryPanel); - - CardPanel.repaint(); - CardPanel.revalidate(); } + CardPanel.repaint(); + CardPanel.revalidate(); }); - ButtonCoord.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + ButtonCoord.addActionListener(e -> { + String cur = TextCoord.getText(); + if (!cur.isEmpty()) { CardPanel.removeAll(); - String cur = TextCoord.getText(); - System.out.println(cur); LoadStringCoords(cur); LoadSearchResultItinerary(searchResPath, modelItinerary); - System.out.println("search coord clicked with text " + cur); CardPanel.add(ItineraryPanel); - - CardPanel.repaint(); - CardPanel.revalidate(); } + CardPanel.repaint(); + CardPanel.revalidate(); }); tableStops.addMouseListener(new MouseAdapter() { @@ -422,16 +416,13 @@ public class View extends JFrame { } public void LoadStringCoords(String stops){ - System.out.println(stops); stops = stops.replaceAll("[()]", "").replaceAll(";", ","); String[] stops_array = stops.split(","); double[] coords = new double[4]; - System.out.println(Arrays.toString(stops_array)); for (int i = 0; i < 4; i++){ coords[i] = Double.parseDouble(stops_array[i]); } searchResPath = (ArrayList) finder.findPath(coords[0], coords[1], coords[2], coords[3], LocalDateTime.now().toLocalTime().toSecondOfDay()); - } public void LoadStringStops(String stops){ @@ -443,7 +434,7 @@ public class View extends JFrame { for (int i = 0; i < 2;i++){ coords[j] = cur[i]; ++j; - } + } } searchResPath = (ArrayList) finder.findPath(coords[0], coords[1], coords[2], coords[3], LocalDateTime.now().toLocalTime().toSecondOfDay()); } @@ -460,21 +451,10 @@ public class View extends JFrame { count = 0; for (Stop stop : stops) { // Add a row to the table with Stop's line in the first column and Stop's name in the second column - model.addRow(new Object[]{String.join(",", stop.getLines()), stop.getName()}); ++count; } - System.out.println(stops.toString()); - for (int i = 0; i < model.getRowCount(); i++) { - for (int j = 0; j < model.getColumnCount(); j++) { - System.out.print("valeur at coord " + i +";" + j +": " + model.getValueAt(i, j) + "\t"); - } - System.out.println(); - } - - System.out.println(count); - tableStops.revalidate(); tableStops.repaint(); paneStops.setViewportView(tableStops); @@ -490,7 +470,6 @@ public class View extends JFrame { model.setRowCount(0); model.setColumnCount(cols); - // Add new rows based on the search results count = 0; Path last = null; @@ -501,24 +480,14 @@ public class View extends JFrame { int hours = (int) (time / 3600); int minutes = (int) ((time % 3600) / 60); - - model.addRow(new Object[]{path.getLine(), path.getCurrentStop(), String.format("%02d:%02d", hours, minutes)}); ++count; last = path; } } - if (last != null) model.addRow(new Object[]{last.getLine(), last.getNextStop()}); - - System.out.println(paths); - for (int i = 0; i < model.getRowCount(); i++) { - for (int j = 0; j < model.getColumnCount(); j++) { - System.out.print("valeur at coord " + i +";" + j +": " + model.getValueAt(i, j) + "\t"); - } - System.out.println(); - } - System.out.println(count); + if (last != null) + model.addRow(new Object[]{last.getLine(), last.getNextStop()}); tableItinerary.revalidate(); tableItinerary.repaint(); @@ -527,17 +496,6 @@ public class View extends JFrame { paneItinerary.repaint(); ItineraryPanel.revalidate(); ItineraryPanel.repaint(); - this.displayTableValues(model); - } - - public void displayTableValues(TableModel mod) { - for (int row = 0; row < mod.getRowCount(); row++) { - for (int column = 0; column < mod.getColumnCount(); column++) { - if (mod.getValueAt(row, column) != null) System.out.print(mod.getValueAt(row, column).toString() + " "); - } - System.out.print(";"); - } - System.out.println(); } private void openWebpage(URI uri) { @@ -558,13 +516,4 @@ public class View extends JFrame { LOGGER.severe("Default desktop browser not set"); } } - - /* - public static void main(String[] args) { - ArrayList s = new ArrayList<>(); - s.add(new Stop("M8", "Balard", 1.0315897, 3.0265513)); - s.add(new Stop("M14", "Gare de Lyon", 2.4658452681, 3.0265513)); - SwingUtilities.invokeLater(() -> new View(graph, finder, s)); - } - */ }