[feat] display actual data pertaining to a trip
This commit is contained in:
parent
2b3175a4ba
commit
7485fc492d
1 changed files with 58 additions and 16 deletions
|
@ -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.ImagePair;
|
||||
import fr.u_paris.gla.project.itinerary.*;
|
||||
import fr.u_paris.gla.project.utils.ApiUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
|
@ -15,10 +16,9 @@ import java.net.MalformedURLException;
|
|||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class View extends JFrame {
|
||||
|
@ -88,8 +88,11 @@ public class View extends JFrame {
|
|||
|
||||
private int count = 0;
|
||||
|
||||
private Finder finder;
|
||||
|
||||
|
||||
public View(Graph graph, Finder finder, ArrayList<Stop> s) throws HeadlessException {
|
||||
this.finder = finder;
|
||||
setSize(800, 600);
|
||||
MainPanel = new JPanel();
|
||||
GridLayout MainLayout = new GridLayout(1, 2, 50, 0);
|
||||
|
@ -300,11 +303,12 @@ public class View extends JFrame {
|
|||
super.keyReleased(e);
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
|
||||
searchLocation = TextLocation.getText();
|
||||
LoadSearchResult(s, modelStops);
|
||||
System.out.println("Enter key released with text " + searchLocation);
|
||||
String cur = TextLocation.getText();
|
||||
LoadStringStops(cur);
|
||||
LoadSearchResultItinerary(searchResPath, modelItinerary);
|
||||
System.out.println("Enter key released with text " + cur);
|
||||
CardPanel.removeAll();
|
||||
CardPanel.add(NetworkPanel);
|
||||
CardPanel.add(ItineraryPanel);
|
||||
|
||||
CardPanel.repaint();
|
||||
CardPanel.revalidate();
|
||||
|
@ -316,10 +320,11 @@ public class View extends JFrame {
|
|||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CardPanel.removeAll();
|
||||
searchLocation = TextLocation.getText();
|
||||
LoadSearchResult(s, modelStops);
|
||||
System.out.println("search location clicked with text " + searchLocation);
|
||||
CardPanel.add(NetworkPanel);
|
||||
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();
|
||||
|
@ -330,10 +335,12 @@ public class View extends JFrame {
|
|||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CardPanel.removeAll();
|
||||
searchCoord = TextCoord.getText();
|
||||
LoadSearchResult(s, modelStops);
|
||||
System.out.println("search coord clicked with text " + searchCoord);
|
||||
CardPanel.add(NetworkPanel);
|
||||
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();
|
||||
|
@ -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) {
|
||||
// Clear existing rows from the table
|
||||
int cols = model.getColumnCount();
|
||||
|
@ -461,7 +497,13 @@ public class View extends JFrame {
|
|||
if (paths != null) {
|
||||
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
|
||||
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;
|
||||
last = path;
|
||||
|
|
Reference in a new issue