Merge branch 'gui-displayres' into 'dev'

[feat] display actual data pertaining to a trip

See merge request gla-groupe-3/projet!21
This commit is contained in:
RODRIGUEZ lucas 2024-05-03 23:31:36 +02:00
commit b3e1631c93

View file

@ -4,6 +4,7 @@ import fr.u_paris.gla.project.idfm.CSVImageProvider;
import fr.u_paris.gla.project.idfm.IDFMNetworkExtractor; import fr.u_paris.gla.project.idfm.IDFMNetworkExtractor;
import fr.u_paris.gla.project.idfm.ImagePair; import fr.u_paris.gla.project.idfm.ImagePair;
import fr.u_paris.gla.project.itinerary.*; import fr.u_paris.gla.project.itinerary.*;
import fr.u_paris.gla.project.utils.ApiUtils;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
@ -15,10 +16,9 @@ import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.time.LocalDateTime;
import java.util.Comparator; import java.util.*;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.logging.Logger; import java.util.logging.Logger;
public class View extends JFrame { public class View extends JFrame {
@ -88,8 +88,11 @@ public class View extends JFrame {
private int count = 0; private int count = 0;
private Finder finder;
public View(Graph graph, Finder finder, ArrayList<Stop> s) throws HeadlessException { public View(Graph graph, Finder finder, ArrayList<Stop> s) throws HeadlessException {
this.finder = finder;
setSize(800, 600); setSize(800, 600);
MainPanel = new JPanel(); MainPanel = new JPanel();
GridLayout MainLayout = new GridLayout(1, 2, 50, 0); GridLayout MainLayout = new GridLayout(1, 2, 50, 0);
@ -300,11 +303,12 @@ public class View extends JFrame {
super.keyReleased(e); super.keyReleased(e);
if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (e.getKeyCode() == KeyEvent.VK_ENTER) {
searchLocation = TextLocation.getText(); String cur = TextLocation.getText();
LoadSearchResult(s, modelStops); LoadStringStops(cur);
System.out.println("Enter key released with text " + searchLocation); LoadSearchResultItinerary(searchResPath, modelItinerary);
System.out.println("Enter key released with text " + cur);
CardPanel.removeAll(); CardPanel.removeAll();
CardPanel.add(NetworkPanel); CardPanel.add(ItineraryPanel);
CardPanel.repaint(); CardPanel.repaint();
CardPanel.revalidate(); CardPanel.revalidate();
@ -316,10 +320,11 @@ public class View extends JFrame {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
CardPanel.removeAll(); CardPanel.removeAll();
searchLocation = TextLocation.getText(); String cur = TextLocation.getText();
LoadSearchResult(s, modelStops); LoadStringStops(cur);
System.out.println("search location clicked with text " + searchLocation); LoadSearchResultItinerary(searchResPath, modelItinerary);
CardPanel.add(NetworkPanel); System.out.println("search location clicked with text " + cur);
CardPanel.add(ItineraryPanel);
CardPanel.repaint(); CardPanel.repaint();
CardPanel.revalidate(); CardPanel.revalidate();
@ -330,10 +335,12 @@ public class View extends JFrame {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
CardPanel.removeAll(); CardPanel.removeAll();
searchCoord = TextCoord.getText(); String cur = TextCoord.getText();
LoadSearchResult(s, modelStops); System.out.println(cur);
System.out.println("search coord clicked with text " + searchCoord); LoadStringCoords(cur);
CardPanel.add(NetworkPanel); LoadSearchResultItinerary(searchResPath, modelItinerary);
System.out.println("search coord clicked with text " + cur);
CardPanel.add(ItineraryPanel);
CardPanel.repaint(); CardPanel.repaint();
CardPanel.revalidate(); CardPanel.revalidate();
@ -414,6 +421,35 @@ 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<Path>) finder.findPath(coords[0], coords[1], coords[2], coords[3], LocalDateTime.now().toLocalTime().toSecondOfDay());
}
public void LoadStringStops(String stops){
String[] stops_array = stops.split(";");
double[] coords = new double[4];
int j = 0;
for (String stop: stops_array) {
double[] cur = ApiUtils.getGPSLocation(stop);
for (int i = 0; i < 2;i++){
coords[j] = cur[i];
++j;
}
}
searchResPath = (ArrayList<Path>) finder.findPath(coords[0], coords[1], coords[2], coords[3], LocalDateTime.now().toLocalTime().toSecondOfDay());
}
public void LoadSearchResult(ArrayList<Stop> stops, DefaultTableModel model) { public void LoadSearchResult(ArrayList<Stop> stops, DefaultTableModel model) {
// Clear existing rows from the table // Clear existing rows from the table
int cols = model.getColumnCount(); int cols = model.getColumnCount();
@ -461,7 +497,13 @@ public class View extends JFrame {
if (paths != null) { if (paths != null) {
for (Path path : paths) { for (Path path : paths) {
// Add a row to the table with Stop's line in the first column and Stop's name in the second column // 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[]{path.getLine(), path.getCurrentStop(), path.getStartTime()}); double time = path.getStartTime();
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; ++count;
last = path; last = path;