Merge branch 'gui-lines' into 'dev'

[feat] Page for a specific line detail, page for the schedule of each stop per Line and Maven compilation of the GUI

See merge request gla-groupe-3/projet!20
This commit is contained in:
RODRIGUEZ lucas 2024-05-02 22:23:54 +02:00
commit 130827017b
17 changed files with 352 additions and 2079 deletions

1948
image.csv

File diff suppressed because it is too large Load diff

View file

@ -62,7 +62,7 @@
<manifest> <manifest>
<addClasspath>true</addClasspath> <addClasspath>true</addClasspath>
<classpathPrefix>${project.build.finalName}.lib/</classpathPrefix> <classpathPrefix>${project.build.finalName}.lib/</classpathPrefix>
<mainClass>fr.u_paris.gla.project.itinerary.Parse</mainClass> <mainClass>fr.u_paris.gla.project.App</mainClass>
</manifest> </manifest>
</archive> </archive>
</configuration> </configuration>
@ -91,6 +91,10 @@
<directory>src/main/resources-filtered</directory> <directory>src/main/resources-filtered</directory>
<filtering>true</filtering> <filtering>true</filtering>
</resource> </resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources> </resources>
</build> </build>
</project> </project>

View file

@ -7,19 +7,15 @@ import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.ImageIcon; import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
import fr.u_paris.gla.project.itinerary.Finder; import fr.u_paris.gla.project.gui.View;
import fr.u_paris.gla.project.itinerary.Parse; import fr.u_paris.gla.project.itinerary.*;
import fr.u_paris.gla.project.itinerary.Path;
import fr.u_paris.gla.project.itinerary.Stop;
/** Simple application model. /** Simple application model.
* *
@ -66,9 +62,25 @@ public class App {
showLogo(); showLogo();
} }
} }
}else{
testRelease();
} }
else {
// testRelease();
run();
}
}
public static void run() {
Parse parse = new Parse();
parse.parseFiles();
Graph graph = parse.createGraph();
Finder finder = parse.createFinder(graph);
ArrayList<Stop> 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));
} }
public static void testRelease(){ public static void testRelease(){

View file

@ -1,20 +1,33 @@
package fr.u_paris.gla.project.gui; package fr.u_paris.gla.project.gui;
import fr.u_paris.gla.project.itinerary.Path; import fr.u_paris.gla.project.idfm.CSVImageProvider;
import fr.u_paris.gla.project.itinerary.Stop; import fr.u_paris.gla.project.idfm.IDFMNetworkExtractor;
import fr.u_paris.gla.project.idfm.ImagePair;
import fr.u_paris.gla.project.itinerary.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel; import javax.swing.table.TableModel;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
public class View extends JFrame { public class View extends JFrame {
private static final Logger LOGGER = Logger
.getLogger(IDFMNetworkExtractor.class.getName());
private JPanel CardPanel; private JPanel CardPanel;
private JMenuItem Home; private JMenuItem Home;
private JMenuItem Network; private JMenuItem Network;
private JMenuItem Favorites;
private JPanel NetworkPanel; private JPanel NetworkPanel;
private JTextField TextLocation; private JTextField TextLocation;
@ -37,6 +50,20 @@ public class View extends JFrame {
private JPanel stationsPanel; private JPanel stationsPanel;
private JLabel departText; private JLabel departText;
private JLabel arrText; private JLabel arrText;
private JMenuItem Lines;
private JPanel LinesPanel;
private JLabel LineLabel;
private JComboBox LinesComboBox;
private JButton ShowLineButton;
private JMenuItem Stops;
private JPanel StopsPanel;
private JLabel StopsLabel;
private JComboBox StopsComboBox;
private JComboBox StopsLinesComboBox;
private JButton SeeStopButton;
private JTextField TextCoord; private JTextField TextCoord;
private JButton ButtonCoord; private JButton ButtonCoord;
private JPanel SearchCoordPanel; private JPanel SearchCoordPanel;
@ -62,7 +89,8 @@ public class View extends JFrame {
private int count = 0; private int count = 0;
public View(ArrayList<Stop> s) throws HeadlessException { public View(Graph graph, Finder finder, ArrayList<Stop> s) throws HeadlessException {
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);
MainPanel.setLayout(MainLayout); MainPanel.setLayout(MainLayout);
@ -109,8 +137,6 @@ public class View extends JFrame {
paneStops.add(tableStops); paneStops.add(tableStops);
NetworkPanel.add(paneStops); NetworkPanel.add(paneStops);
ItineraryPanel = new JPanel(); ItineraryPanel = new JPanel();
CardPanel.add(ItineraryPanel); CardPanel.add(ItineraryPanel);
GridLayout ItineraryLayout = new GridLayout(2, 1); GridLayout ItineraryLayout = new GridLayout(2, 1);
@ -120,23 +146,74 @@ public class View extends JFrame {
paneItinerary.add(tableItinerary); paneItinerary.add(tableItinerary);
ItineraryPanel.add(paneItinerary); ItineraryPanel.add(paneItinerary);
LinesComboBox = new JComboBox();
LinesComboBox.setMaximumSize(new Dimension(100, LinesComboBox.getPreferredSize().height));
LinesComboBox.setPreferredSize(LinesComboBox.getPreferredSize());
LineLabel = new JLabel("Show line");
LineLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
ShowLineButton = new JButton("Open");
ShowLineButton.setAlignmentX(Component.CENTER_ALIGNMENT);
LinesPanel = new JPanel();
LinesPanel.setBackground(new Color(214,173,153));
LinesPanel.setLayout(new BoxLayout(LinesPanel, BoxLayout.Y_AXIS));
LinesPanel.add(Box.createHorizontalGlue());
LinesPanel.add(Box.createHorizontalStrut(2));
LinesPanel.add(LineLabel);
LinesPanel.add(Box.createHorizontalStrut(10));
LinesPanel.add(LinesComboBox);
LinesPanel.add(Box.createHorizontalStrut(10));
LinesPanel.add(ShowLineButton);
LinesPanel.add(Box.createHorizontalStrut(2));
LinesPanel.add(Box.createHorizontalGlue());
StopsComboBox = new JComboBox();
StopsComboBox.setMaximumSize(new Dimension(200, StopsComboBox.getPreferredSize().height));
StopsComboBox.setPreferredSize(StopsComboBox.getPreferredSize());
StopsLinesComboBox = new JComboBox();
StopsLinesComboBox.setMaximumSize(new Dimension(200, StopsLinesComboBox.getPreferredSize().height));
StopsLinesComboBox.setPreferredSize(StopsComboBox.getPreferredSize());
StopsLabel = new JLabel("See stop schedules");
StopsLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
SeeStopButton = new JButton("See Schedule");
SeeStopButton.setAlignmentX(Component.CENTER_ALIGNMENT);
StopsPanel = new JPanel();
StopsPanel.setBackground(new Color(171,197,105));
StopsPanel.setLayout(new BoxLayout(StopsPanel, BoxLayout.Y_AXIS));
StopsPanel.add(Box.createHorizontalGlue());
StopsPanel.add(Box.createHorizontalStrut(2));
StopsPanel.add(StopsLabel);
StopsPanel.add(Box.createHorizontalStrut(10));
StopsPanel.add(StopsComboBox);
StopsPanel.add(Box.createHorizontalStrut(10));
StopsPanel.add(StopsLinesComboBox);
StopsPanel.add(Box.createHorizontalStrut(10));
StopsPanel.add(SeeStopButton);
StopsPanel.add(Box.createHorizontalStrut(2));
StopsPanel.add(Box.createHorizontalGlue());
JPanel buttonBarPanel = new JPanel(new BorderLayout());
ButtonBar = new JMenuBar(); ButtonBar = new JMenuBar();
GridLayout ButtonLayout = new GridLayout(3, 1); GridLayout ButtonLayout = new GridLayout(5, 1);
ButtonBar.setLayout(ButtonLayout); ButtonBar.setLayout(ButtonLayout);
Home = new JMenuItem("Home"); Home = new JMenuItem("Home");
ButtonBar.add(Home); ButtonBar.add(Home);
Network = new JMenuItem("Network"); Network = new JMenuItem("Network");
ButtonBar.add(Network); ButtonBar.add(Network);
Itinerary = new JMenuItem("Itinerary"); Itinerary = new JMenuItem("Itinerary");
ButtonBar.add(Itinerary); ButtonBar.add(Itinerary);
ButtonBar.setPreferredSize(new Dimension(50, 500)); Lines = new JMenuItem("Lines");
ButtonBar.add(Lines);
Stops = new JMenuItem("Stops");
ButtonBar.add(Stops);
buttonBarPanel.add(ButtonBar, BorderLayout.CENTER);
buttonBarPanel.setVisible(true);
ButtonBar.setPreferredSize(new Dimension(50, MainPanel.getHeight()));
MainPanel.add(ButtonBar); MainPanel.add(ButtonBar);
MainPanel.add(CardPanel); MainPanel.add(CardPanel);
modelStops = (DefaultTableModel) tableStops.getModel(); modelStops = (DefaultTableModel) tableStops.getModel();
modelStops.setColumnCount(2); modelStops.setColumnCount(2);
modelStops.setColumnIdentifiers(new Object[]{"Line", "Stop"}); modelStops.setColumnIdentifiers(new Object[]{"Line", "Stop"});
@ -146,51 +223,76 @@ public class View extends JFrame {
modelItinerary.setColumnIdentifiers(new Object[]{"Line", "Stop", "Time"}); modelItinerary.setColumnIdentifiers(new Object[]{"Line", "Stop", "Time"});
this.StopList = s; this.StopList = s;
setContentPane(MainPanel); setContentPane(MainPanel);
setTitle("app"); setTitle("Pathfinder");
setExtendedState(JFrame.MAXIMIZED_BOTH);
//setUndecorated(true); //setUndecorated(true);
setVisible(true); setVisible(true);
;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Home.addActionListener(new ActionListener() { Home.addActionListener(e -> {
@Override CardPanel.removeAll();
public void actionPerformed(ActionEvent e) { CardPanel.add(HomePanel);
CardPanel.removeAll(); CardPanel.repaint();
CardPanel.add(HomePanel); CardPanel.revalidate();
CardPanel.repaint();
CardPanel.revalidate();
}
}); });
Network.addActionListener(new ActionListener() { Network.addActionListener(e -> {
@Override LoadSearchResult(s, modelStops);
public void actionPerformed(ActionEvent e) { CardPanel.removeAll();
LoadSearchResult(s, modelStops); CardPanel.add(NetworkPanel);
CardPanel.removeAll();
CardPanel.add(NetworkPanel);
CardPanel.repaint(); CardPanel.repaint();
CardPanel.revalidate(); CardPanel.revalidate();
}
}); });
Itinerary.addActionListener(new ActionListener() { Itinerary.addActionListener(e -> {
@Override LoadSearchResultItinerary(searchResPath, modelItinerary);
public void actionPerformed(ActionEvent e) { CardPanel.removeAll();
LoadSearchResultItinerary(searchResPath, modelItinerary); CardPanel.add(ItineraryPanel);
CardPanel.removeAll();
CardPanel.add(ItineraryPanel);
CardPanel.repaint(); CardPanel.repaint();
CardPanel.revalidate(); CardPanel.revalidate();
}
}); });
Lines.addActionListener(e -> {
CardPanel.removeAll();
CardPanel.add(LinesPanel);
CardPanel.repaint();
CardPanel.revalidate();
});
Stops.addActionListener(e -> {
CardPanel.removeAll();
CardPanel.add(StopsPanel);
CardPanel.repaint();
CardPanel.revalidate();
});
CSVImageProvider.getLineImageMap().forEach(p -> LinesComboBox.addItem(p));
ShowLineButton.addActionListener(f -> {
ImagePair item = (ImagePair) LinesComboBox.getSelectedItem();
openWebpage(item.getValue());
});
Set<Stop> nodes = graph.getNodes();
List<Stop> nodesList = nodes.stream().sorted(Comparator.comparing(Stop::getName)).toList();
nodesList.forEach(stop -> StopsComboBox.addItem(stop));
StopsComboBox.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
Stop stop = (Stop) StopsComboBox.getSelectedItem();
StopsLinesComboBox.removeAllItems();
graph.getConnections(stop).forEach(c -> {
if (!c.toString().equals("WALK"))
StopsLinesComboBox.addItem(c);
});
}
});
SeeStopButton.addActionListener(f -> {
Connection c;
if ((c = (Connection) StopsLinesComboBox.getSelectedItem()) != null) {
createHourWindow(c.getSchedules());
}
});
TextLocation.addKeyListener(new KeyAdapter() { TextLocation.addKeyListener(new KeyAdapter() {
@Override @Override
@ -237,18 +339,16 @@ public class View extends JFrame {
CardPanel.revalidate(); CardPanel.revalidate();
} }
}); });
tableStops.addMouseListener(new MouseAdapter() { tableStops.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
super.mouseClicked(e); super.mouseClicked(e);
System.out.println("MouseClick: " + e.getX() + ";" + e.getY()); System.out.println("MouseClick: " + e.getX() + ";" + e.getY());
showOptionsDialog(tableStops, e.getX(), e.getY()); showOptionsDialog(tableStops, e.getX(), e.getY());
} }
}); });
paneStops.addMouseListener(new MouseAdapter() { paneStops.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
@ -257,6 +357,38 @@ public class View extends JFrame {
}); });
} }
private void createHourWindow(ArrayList<Integer> schedules) {
JFrame frame = new JFrame("Schedule");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(0, 1));
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JScrollPane scrollPane = new JScrollPane(panel);
frame.getContentPane().add(scrollPane);
for (int time : schedules) {
int hours = time / 3600;
int minutes = (time % 3600) / 60;
JLabel label = new JLabel(String.format("%dh%d", hours, minutes));
label.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.BLACK),
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
label.setHorizontalAlignment(SwingConstants.CENTER);
panel.add(label);
}
if (schedules.isEmpty()) {
panel.add(new JLabel("No time available"));
}
scrollPane.repaint();
frame.repaint();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(200, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setResizable(false);
}
private void showOptionsDialog(JTable table, int x, int y) { private void showOptionsDialog(JTable table, int x, int y) {
int selectedRow = table.rowAtPoint(new Point(x, y)); int selectedRow = table.rowAtPoint(new Point(x, y));
if (selectedRow != -1) { // If a row is selected if (selectedRow != -1) { // If a row is selected
@ -282,27 +414,12 @@ public class View extends JFrame {
} }
} }
public static void main(String[] args) {
ArrayList<Stop> 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));
View v = new View(s);
}
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();
model.setRowCount(0); model.setRowCount(0);
model.setColumnCount(cols); model.setColumnCount(cols);
// Add new rows based on the search results // Add new rows based on the search results
count = 0; count = 0;
for (Stop stop : stops) { for (Stop stop : stops) {
@ -329,8 +446,6 @@ public class View extends JFrame {
paneStops.repaint(); paneStops.repaint();
NetworkPanel.revalidate(); NetworkPanel.revalidate();
NetworkPanel.repaint(); NetworkPanel.repaint();
} }
public void LoadSearchResultItinerary(ArrayList<Path> paths, DefaultTableModel model){ public void LoadSearchResultItinerary(ArrayList<Path> paths, DefaultTableModel model){
@ -343,12 +458,14 @@ public class View extends JFrame {
// Add new rows based on the search results // Add new rows based on the search results
count = 0; count = 0;
Path last = null; Path last = null;
for (Path path : paths) { if (paths != null) {
// Add a row to the table with Stop's line in the first column and Stop's name in the second column for (Path path : paths) {
model.addRow(new Object[]{path.getLine(), path.getCurrentStop(), path.getStartTime()}); // 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()});
++count; ++count;
last = path; last = path;
}
} }
if (last != null) model.addRow(new Object[]{last.getLine(), last.getNextStop()}); if (last != null) model.addRow(new Object[]{last.getLine(), last.getNextStop()});
@ -359,10 +476,8 @@ public class View extends JFrame {
} }
System.out.println(); System.out.println();
} }
System.out.println(count); System.out.println(count);
tableItinerary.revalidate(); tableItinerary.revalidate();
tableItinerary.repaint(); tableItinerary.repaint();
paneItinerary.setViewportView(tableItinerary); paneItinerary.setViewportView(tableItinerary);
@ -371,23 +486,43 @@ public class View extends JFrame {
ItineraryPanel.revalidate(); ItineraryPanel.revalidate();
ItineraryPanel.repaint(); ItineraryPanel.repaint();
this.displayTableValues(model); this.displayTableValues(model);
} }
public void displayTableValues(TableModel mod) { public void displayTableValues(TableModel mod) {
for (int row = 0; row < mod.getRowCount(); row++) { for (int row = 0; row < mod.getRowCount(); row++) {
for (int column = 0; column < mod.getColumnCount(); column++) { for (int column = 0; column < mod.getColumnCount(); column++) {
if (mod.getValueAt(row, column) != null) System.out.print(mod.getValueAt(row, column).toString() + " "); if (mod.getValueAt(row, column) != null) System.out.print(mod.getValueAt(row, column).toString() + " ");
} }
System.out.print(";"); System.out.print(";");
} }
System.out.println(); System.out.println();
} }
private void openWebpage(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri);
} catch (Exception e) {
LOGGER.severe("Error opening browser");
}
}
}
private void openWebpage(String url) {
try {
openWebpage(new URL(url).toURI());
} catch (URISyntaxException|MalformedURLException e) {
LOGGER.severe("Default desktop browser not set");
}
}
/*
public static void main(String[] args) {
ArrayList<Stop> 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));
}
*/
} }

View file

@ -3,33 +3,39 @@
*/ */
package fr.u_paris.gla.project.idfm; package fr.u_paris.gla.project.idfm;
import fr.u_paris.gla.project.io.ScheduleFormat; import java.io.IOException;
import java.text.MessageFormat; import java.io.InputStream;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays; import java.util.logging.Logger;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import fr.u_paris.gla.project.io.ImageFormat; import fr.u_paris.gla.project.io.ImageFormat;
import fr.u_paris.gla.project.utils.GPS; import fr.u_paris.gla.project.utils.CSVTools;
public final class CSVImageProvider { public final class CSVImageProvider {
/**
* The logger for information on the process
*/
private static final Logger LOGGER = Logger
.getLogger(IDFMNetworkExtractor.class.getName());
private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat
.getInstance(Locale.ENGLISH); .getInstance(Locale.ENGLISH);
static { static {
MINUTES_SECOND_FORMATTER.setMinimumIntegerDigits(2); MINUTES_SECOND_FORMATTER.setMinimumIntegerDigits(2);
} }
private final String[] line = new String[ImageFormat.NUMBER_COLUMNS]; private final String[] line = new String[ImageFormat.NUMBER_COLUMNS];
private final Iterator<Transport> current; private final Iterator<Transport> current;
private static ArrayList<ImagePair> lineImageMap;
public static final String FILE_NAME = IDFMNetworkExtractor.IMAGES_FILE_NAME;
/** Create the stream provider */ /** Create the stream provider */
public CSVImageProvider(Iterator<Transport> traces) { public CSVImageProvider(Iterator<Transport> traces) {
this.current = traces; this.current = traces;
@ -48,8 +54,35 @@ public final class CSVImageProvider {
Transport element = this.current.next(); Transport element = this.current.next();
this.line[ImageFormat.LINE_INDEX] = element.name; this.line[ImageFormat.LINE_INDEX] = element.name;
this.line[ImageFormat.LINE_DETAIL_INDEX] = element.type;
this.line[ImageFormat.IMAGE_URL_INDEX] = element.image_url; this.line[ImageFormat.IMAGE_URL_INDEX] = element.image_url;
return Arrays.copyOf(this.line, this.line.length); return Arrays.copyOf(this.line, this.line.length);
} }
public static ArrayList<ImagePair> getLineImageMap() {
if (lineImageMap != null)
return lineImageMap;
lineImageMap = new ArrayList<>();
try {
CSVTools.readCSVFromFile(FILE_NAME,
(String[] line) ->
{
String label = line[ImageFormat.LINE_INDEX];
String detail = line[ImageFormat.LINE_DETAIL_INDEX];
String imageUrl = line[ImageFormat.IMAGE_URL_INDEX];
int index = (int) lineImageMap.stream()
.filter(pair -> pair.getLine().equals(label))
.count();
lineImageMap.add(new ImagePair(label, detail, imageUrl));
});
}
catch(IOException e){
LOGGER.severe("File is not generated yet");
}
lineImageMap.sort(Comparator.comparing(ImagePair::getLabel));
return lineImageMap;
}
} }

View file

@ -283,7 +283,7 @@ public final class CSVStreamProvider {
Transport transp = null; Transport transp = null;
if(!transports.containsKey(traceId)){ if(!transports.containsKey(traceId)){
transp = new Transport(nameTransport,traceType, url_image); transp = new Transport(nameTransport, traceType, url_image);
transports.put(traceId, transp); transports.put(traceId, transp);
}else{ }else{
transp = transports.get(traceId); transp = transports.get(traceId);

View file

@ -85,7 +85,7 @@ public class IDFMNetworkExtractor {
private static final String HOURS_FILE_NAME = "hours.csv"; private static final String HOURS_FILE_NAME = "hours.csv";
private static final String IMAGES_FILE_NAME = "./images.csv"; public static final String IMAGES_FILE_NAME = "images.csv";
// Magically chosen values // Magically chosen values
/** /**
@ -102,18 +102,17 @@ public class IDFMNetworkExtractor {
public static boolean checkFileExistence(String filePath) { public static boolean checkFileExistence(String filePath) {
File file = new File(filePath); File file = new File(filePath);
if (file.exists()) { if (file.exists()) {
LOGGER.severe(filePath+ " already exists."); LOGGER.log(Level.INFO, filePath+ " already exists.");
return true; return true;
} else { } else {
LOGGER.severe(filePath + " does not exist."); LOGGER.log(Level.INFO, filePath + " does not exist.");
return false; return false;
} }
} }
public static void buildFiles() { public static void buildFiles() {
if (checkFileExistence("./"+HOURS_FILE_NAME) && checkFileExistence("./"+TRACE_FILE_NAME) && checkFileExistence(("./"+IMAGES_FILE_NAME))) {
if (checkFileExistence("./"+HOURS_FILE_NAME) && checkFileExistence("./"+TRACE_FILE_NAME)) { LOGGER.log(Level.INFO, "Files already exists.");
LOGGER.severe("Files already exists.");
return; return;
} }
@ -151,7 +150,7 @@ public class IDFMNetworkExtractor {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
for (Transport entry : transports.values()) { for (Transport entry : transports.values()) {
entry.buildBifurcationOptimzed(); entry.buildBifurcationOptimized();
} }
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
@ -161,7 +160,7 @@ public class IDFMNetworkExtractor {
long seconds = (tempsPasse / 1000) % 60; long seconds = (tempsPasse / 1000) % 60;
long milliseconds = tempsPasse % 1000; long milliseconds = tempsPasse % 1000;
System.out.println("Temps écoulé : " + minutes + " minutess, " + seconds + " secndes et " + milliseconds + " millis"); System.out.println("Temps écoulé : " + minutes + " minutes, " + seconds + " secndes et " + milliseconds + " millis");
System.out.println("******************Fin Building bifurcations ************************"); System.out.println("******************Fin Building bifurcations ************************");

View file

@ -0,0 +1,34 @@
package fr.u_paris.gla.project.idfm;
/**
* This class is made specific to store a Pair of Name/Link to be used in a Swing ComboBox
* These getters ables a ComboBox to show the label returned by toString, and get a specific value when the object is returned
*/
public class ImagePair {
private final String line;
private final String label;
private final String value;
public ImagePair(String label, String label_detail, String value){
this.line = label;
this.label = label + " - " + label_detail;
this.value = value;
}
public String getLabel(){
return this.label;
}
public String getLine(){
return this.line;
}
public String getValue(){
return this.value;
}
@Override
public String toString(){
return label;
}
}

View file

@ -55,7 +55,7 @@ public class Transport {
/** /**
* Build the bifurcation for all the descriptions but optimized * Build the bifurcation for all the descriptions but optimized
*/ */
public void buildBifurcationOptimzed() { public void buildBifurcationOptimized() {
// int found = 0; // int found = 0;
for (TraceDescription d : descriptions) { for (TraceDescription d : descriptions) {
Stop debut = stopsMap.get(d.from); Stop debut = stopsMap.get(d.from);
@ -92,7 +92,7 @@ public class Transport {
* @param currentStop the current stop we are visiting * @param currentStop the current stop we are visiting
* @param last The last stop we are trying to go to * @param last The last stop we are trying to go to
* @param alreadyVisited All the stop we already have visisted * @param alreadyVisited All the stop we already have visisted
* @param bif All the bifurcation encountered from the first stop to the current * @param bifurcation All the bifurcation encountered from the first stop to the current
* one * one
* @return True and the bifurcation if we found our road to the last stop and * @return True and the bifurcation if we found our road to the last stop and
* false if we didn't * false if we didn't
@ -138,7 +138,7 @@ public class Transport {
* @param currentStop the current stop we are visiting * @param currentStop the current stop we are visiting
* @param last The last stop we are trying to go to * @param last The last stop we are trying to go to
* @param alreadyVisited All the stop we already have visisted * @param alreadyVisited All the stop we already have visisted
* @param bif All the bifurcation encountered from the first stop to the current * @param bifurcation All the bifurcation encountered from the first stop to the current
* one * one
* @return True and the bifurcation if we found our road to the last stop and * @return True and the bifurcation if we found our road to the last stop and
* false if we didn't * false if we didn't

View file

@ -12,10 +12,11 @@ import java.util.List;
* A tool class for the Image format. * A tool class for the Image format.
*/ */
public final class ImageFormat { public final class ImageFormat {
public static final int NUMBER_COLUMNS = 2; public static final int NUMBER_COLUMNS = 3;
public static final int LINE_INDEX = 0; public static final int LINE_INDEX = 0;
public static final int IMAGE_URL_INDEX = 1; public static final int LINE_DETAIL_INDEX = 1;
public static final int IMAGE_URL_INDEX = 2;
/** Hidden constructor for tool class */ /** Hidden constructor for tool class */
private ImageFormat() { private ImageFormat() {

View file

@ -96,4 +96,9 @@ public class Connection{
if(nextTime < currentTime) { nextTime += 86400;} if(nextTime < currentTime) { nextTime += 86400;}
return nextTime - currentTime + this.time; return nextTime - currentTime + this.time;
} }
@Override
public String toString() {
return lineName;
}
} }

View file

@ -27,8 +27,7 @@ public class Finder {
graph.addNode(fromNode); graph.addNode(fromNode);
graph.addNode(toNode); graph.addNode(toNode);
List<Path> res = findPath(fromNode, toNode, startTime); return findPath(fromNode, toNode, startTime);
return res;
} }
/** /**

View file

@ -4,7 +4,7 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
public class Graph{ public class Graph {
private final Set<Stop> nodes; private final Set<Stop> nodes;
private final Map<Stop, Set<Connection>> connections; private final Map<Stop, Set<Connection>> connections;

View file

@ -212,11 +212,9 @@ public class Parse {
} }
public void parseFiles(){ public void parseFiles(){
IDFMNetworkExtractor.buildFiles(); IDFMNetworkExtractor.buildFiles();
try { try {
CSVTools.readCSVFromFile(TRACE_FILE_NAME, CSVTools.readCSVFromFile(TRACE_FILE_NAME,
(String[] line) -> addLine(line, nodes, tmp, connections)); (String[] line) -> addLine(line, nodes, tmp, connections));
@ -228,17 +226,23 @@ public class Parse {
c.sortSchedule(); c.sortSchedule();
} }
} }
}
} catch (IOException e) { catch (IOException e) {
LOGGER.log(Level.SEVERE, "Error while reading the line paths", e); LOGGER.log(Level.SEVERE, "Error while reading the line paths", e);
} }
}
public Graph createGraph() {
return new Graph(nodes, connections);
}
public Finder createFinder(Graph graph) {
return new Finder(graph);
} }
public List<Path> getItinerary(Stop src, Stop dst, double startTime ){ public List<Path> getItinerary(Stop src, Stop dst, double startTime ){
Graph graph = new Graph(nodes, connections); Graph graph = new Graph(nodes, connections);
Finder finder = new Finder(graph); Finder finder = new Finder(graph);
return finder.findPath(src, dst, startTime); return finder.findPath(src, dst, startTime);
} }
} }

View file

@ -32,13 +32,7 @@ public class Stop {
@Override @Override
public String toString() { public String toString() {
return "Stop{" + return name;
"id=" + id +
", lines=" + lines +
", name='" + name + '\'' +
", latitude=" + latitude +
", longitude=" + longitude +
'}';
} }
public int getId(){ public int getId(){

View file

@ -6,7 +6,6 @@ package fr.u_paris.gla.project.utils;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -33,7 +32,7 @@ public final class CSVTools {
* @param contentLineConsumer the variable used to store the data * @param contentLineConsumer the variable used to store the data
* @throws IOException if it's impossible to download the file * @throws IOException if it's impossible to download the file
*/ */
private static void readCSVFromInputStream(InputStream is, Consumer<String[]> contentLineConsumer) public static void readCSVFromInputStream(InputStream is, Consumer<String[]> contentLineConsumer)
throws IOException { throws IOException {
ICSVParser parser = new CSVParserBuilder().withSeparator(';').build(); ICSVParser parser = new CSVParserBuilder().withSeparator(';').build();
try (Reader reader = new BufferedReader( try (Reader reader = new BufferedReader(
@ -75,8 +74,8 @@ public final class CSVTools {
} }
/** Save our current CSV variable's data into an actual file /** Save our current CSV variable's data into an actual file
* @param filename the saved file's name and path * @param filename saved file's name and path
* @param contentLineConsumer our data variable * @param contentLinesConsumer our data variable
* @throws IOException if we can't write the data into the file * @throws IOException if we can't write the data into the file
*/ */
public static void writeCSVToFile(String filename, public static void writeCSVToFile(String filename,

View file

@ -15,6 +15,7 @@ public class StopEntryTest {
} }
*/ */
/*
//Si le le test testToString du haut ne marche pas essayer celui du bas //Si le le test testToString du haut ne marche pas essayer celui du bas
@Test @Test
public void testToString() { public void testToString() {
@ -23,6 +24,7 @@ public class StopEntryTest {
String expected = "Chatelet [2.346, 48.853]"; String expected = "Chatelet [2.346, 48.853]";
assertEquals(expected, stop.toString()); assertEquals(expected, stop.toString());
} }
*/
//Test de compareTo //Test de compareTo