Merge dev into branch

This commit is contained in:
Lucas 2024-05-01 12:07:01 +02:00
commit 586692fffb
11 changed files with 345 additions and 595 deletions

View file

@ -7,6 +7,7 @@ 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.List;
import java.util.Properties; import java.util.Properties;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
@ -15,6 +16,11 @@ import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.WindowConstants; import javax.swing.WindowConstants;
import fr.u_paris.gla.project.itinerary.Finder;
import fr.u_paris.gla.project.itinerary.Parse;
import fr.u_paris.gla.project.itinerary.Path;
import fr.u_paris.gla.project.itinerary.Stop;
/** Simple application model. /** Simple application model.
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
@ -60,9 +66,31 @@ public class App {
showLogo(); showLogo();
} }
} }
}else{
testRelease();
} }
} }
public static void testRelease(){
Parse parse = new Parse();
parse.parseFiles();
Stop source = parse.getTmp().get("Porte d'Ivry").get(0);
Stop destination = parse.getTmp().get("Châtelet").get(0);
System.out.println("Itinéraire de Porte d'Ivry à Châtelet");
List<Path> result = parse.getItinerary(source, destination, 43200);
for(Path element : result){
System.out.println(element.getCurrentStop());
}
System.out.println("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
System.out.println("Itinéraire de Porte d'Ivry à Châtelet");
source = parse.getTmp().get("Saint-Jacques").get(0);
destination = parse.getTmp().get("Porte d'Ivry").get(0);
result = parse.getItinerary(source, destination, 43200);
for(Path element : result){
System.out.println(element.getCurrentStop());
}
}
/** @param out the output stream */ /** @param out the output stream */
public static void printAppInfos(PrintStream out) { public static void printAppInfos(PrintStream out) {
Properties props = readApplicationProperties(); Properties props = readApplicationProperties();

View file

@ -1,324 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="fr.u_paris.gla.project.gui.View">
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="853" height="600"/>
</constraints>
<properties>
<background color="-12828863"/>
<focusCycleRoot value="true"/>
</properties>
<border type="none"/>
<children>
<grid id="15a59" binding="Cardpanel" layout-manager="CardLayout" hgap="0" vgap="0" show="24ba7">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-720907"/>
<doubleBuffered value="true"/>
<enabled value="true"/>
<foreground color="-12495218"/>
</properties>
<border type="none"/>
<children>
<grid id="24ba7" binding="HomePanel" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<card name="Card1"/>
</constraints>
<properties>
<background color="-8683389"/>
<enabled value="false"/>
<foreground color="-10699971"/>
</properties>
<border type="none"/>
<children>
<component id="3cb9b" class="javax.swing.JTextField" binding="textField1" default-binding="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="1" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="a2307" class="javax.swing.JButton" binding="searchButton" default-binding="true">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<label value="Search"/>
<text value="Search"/>
<verifyInputWhenFocusTarget value="false"/>
</properties>
</component>
<component id="177f" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Search stop"/>
</properties>
</component>
<vspacer id="8b80">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="b3e57">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<hspacer id="5107e">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="f414">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
<grid id="184ef" binding="NetworkPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<card name="Card2"/>
</constraints>
<properties>
<background color="-2708071"/>
<doubleBuffered value="true"/>
<enabled value="true"/>
</properties>
<border type="none"/>
<children>
<component id="89720" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="4" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="44153"/>
<text value="Network"/>
</properties>
</component>
<grid id="7f3c9" binding="stationsPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="35d9e" class="javax.swing.JLabel" binding="departText">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Departure:"/>
</properties>
</component>
<vspacer id="f3812">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="33aa0" class="javax.swing.JLabel" binding="arrText">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Arrival:"/>
</properties>
</component>
</children>
</grid>
<scrollpane id="44153" binding="mypane">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2046e" class="javax.swing.JTable" binding="table">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
<grid id="dfb19" binding="FavoritesPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<card name="Card3"/>
</constraints>
<properties>
<background color="-5520023"/>
<doubleBuffered value="true"/>
<enabled value="true"/>
</properties>
<border type="none"/>
<children>
<component id="131d5" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Favorites"/>
</properties>
</component>
</children>
</grid>
<grid id="30e2e" binding="ItineraryPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<card name="Card4"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="5ab99" binding="LinesPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<card name="Card5"/>
</constraints>
<properties>
<background color="-406200"/>
</properties>
<border type="none"/>
<children>
<component id="32efa" class="javax.swing.JLabel" binding="lineLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font size="20" style="1"/>
<text value="Show line"/>
</properties>
</component>
<component id="4836e" class="javax.swing.JComboBox" binding="linesComboBox">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="200" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<component id="2aedb" class="javax.swing.JButton" binding="showLineButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="1" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="78" height="30"/>
</grid>
</constraints>
<properties>
<text value="Open"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="67039" class="javax.swing.JMenuBar" layout-manager="GridLayoutManager" row-count="11" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="10ffa" class="javax.swing.JMenuItem" binding="Home">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="102" height="20"/>
</grid>
</constraints>
<properties>
<hideActionText value="false"/>
<text value="Home"/>
</properties>
</component>
<component id="43d5e" class="javax.swing.JMenuItem" binding="Network">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="102" height="20"/>
</grid>
</constraints>
<properties>
<text value="Network"/>
</properties>
</component>
<component id="9da5d" class="javax.swing.JMenuItem" binding="Favorites">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="102" height="20"/>
</grid>
</constraints>
<properties>
<text value="Favorites"/>
</properties>
</component>
<vspacer id="402a8">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<preferred-size width="102" height="14"/>
</grid>
</constraints>
</vspacer>
<vspacer id="15816">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<preferred-size width="102" height="14"/>
</grid>
</constraints>
</vspacer>
<vspacer id="dae0c">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<preferred-size width="102" height="14"/>
</grid>
</constraints>
</vspacer>
<component id="664f9" class="javax.swing.JMenuItem" binding="Itinerary">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="102" height="20"/>
</grid>
</constraints>
<properties>
<text value="Itinerary"/>
</properties>
</component>
<vspacer id="936ed">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="c45a6">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="b44bf" class="javax.swing.JMenuItem" binding="Lines">
<constraints>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="102" height="20"/>
</grid>
</constraints>
<properties>
<text value="Lines"/>
</properties>
</component>
<vspacer id="1e08c">
<constraints>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</children>
</grid>
</form>

View file

@ -3,6 +3,7 @@ package fr.u_paris.gla.project.gui;
import fr.u_paris.gla.project.idfm.CSVImageProvider; 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.Path;
import fr.u_paris.gla.project.itinerary.Stop; import fr.u_paris.gla.project.itinerary.Stop;
import javax.swing.*; import javax.swing.*;
@ -21,50 +22,146 @@ public class View extends JFrame {
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
.getLogger(IDFMNetworkExtractor.class.getName()); .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 JMenuItem Favorites;
private JPanel NetworkPanel; private JPanel NetworkPanel;
private JPanel FavoritesPanel;
private JTextField textField1; private JTextField TextLocation;
private JButton searchButton; private JButton ButtonLocation;
private JPanel HomePanel; private JPanel HomePanel;
private JPanel MainPanel; private JPanel MainPanel;
private DefaultTableModel model; private DefaultTableModel modelStops;
private JTable table; private JTable tableStops;
private JScrollPane mypane; private JTable tableItinerary;
private DefaultTableModel modelItinerary;
private JScrollPane paneStops;
private JScrollPane paneItinerary;
private JPanel ItineraryPanel; private JPanel ItineraryPanel;
private JMenuItem Itinerary; private JMenuItem Itinerary;
private JPanel stationsPanel; private JPanel stationsPanel;
private JLabel departText; private JLabel departText;
private JLabel arrText; private JLabel arrText;
private JMenuItem Lines; private JMenuItem Lines;
private JPanel LinesPanel; private JPanel LinesPanel;
private JLabel lineLabel; private JLabel lineLabel;
private JComboBox linesComboBox; private JComboBox linesComboBox;
private JButton showLineButton; private JButton showLineButton;
private JTextField TextCoord;
private JButton ButtonCoord;
private JPanel SearchCoordPanel;
private JPanel SearchLocationPanel;
private JLabel NetworkLabel;
private JLabel FavLabel;
private JMenuBar ButtonBar;
private ArrayList<Stop> StopList; private ArrayList<Stop> StopList;
private String departureCur; private String departureCur;
private String arrivalCur; private String arrivalCur;
private String searchCur; private String searchLocation;
private String searchCoord;
private ArrayList<Stop> searchRes; private ArrayList<Stop> searchRes;
private ArrayList<Path> searchResPath;
private int count = 0; private int count = 0;
public View(ArrayList<Stop> s) throws HeadlessException { public View(ArrayList<Stop> s) throws HeadlessException {
table = new JTable(); MainPanel = new JPanel();
model = (DefaultTableModel) table.getModel(); GridLayout MainLayout = new GridLayout(1, 2, 50, 0);
model.setColumnCount(2); MainPanel.setLayout(MainLayout);
model.setColumnIdentifiers(new Object[]{"Line", "Stop"}); CardLayout CardLay = new CardLayout();
CardPanel = new JPanel(CardLay);
HomePanel = new JPanel();
CardPanel.add(HomePanel);
SearchCoordPanel = new JPanel();
SearchLocationPanel = new JPanel();
GridLayout SearchLayout = new GridLayout(1, 2);
HomePanel.setLayout(SearchLayout);
HomePanel.add(SearchCoordPanel);
HomePanel.add(SearchLocationPanel);
GridLayout SearchCoordLayout = new GridLayout(2, 1);
GridLayout SearchLocationLayout = new GridLayout(2, 1);
SearchCoordPanel.setLayout(SearchCoordLayout);
SearchLocationPanel.setLayout(SearchLocationLayout);
TextCoord = new JTextField();
ButtonCoord = new JButton("Look for coords");
SearchCoordPanel.add(TextCoord);
SearchCoordPanel.add(ButtonCoord);
TextLocation = new JTextField();
ButtonLocation = new JButton("Look for string");
SearchLocationPanel.add(TextLocation);
SearchLocationPanel.add(ButtonLocation);
NetworkPanel = new JPanel();
CardPanel.add(NetworkPanel);
GridLayout NetworkLayout = new GridLayout(3, 1);
NetworkPanel.setLayout(NetworkLayout);
NetworkLabel = new JLabel("Network");
NetworkPanel.add(NetworkLabel);
stationsPanel = new JPanel();
NetworkPanel.add(stationsPanel);
GridLayout StationsLayout = new GridLayout(2, 1);
departText = new JLabel("Départ: ");
arrText = new JLabel("Arivée: ");
stationsPanel.setLayout(StationsLayout);
stationsPanel.add(departText);
stationsPanel.add(arrText);
paneStops = new JScrollPane();
tableStops = new JTable();
paneStops.add(tableStops);
NetworkPanel.add(paneStops);
ItineraryPanel = new JPanel();
CardPanel.add(ItineraryPanel);
GridLayout ItineraryLayout = new GridLayout(2, 1);
ItineraryPanel.setLayout(ItineraryLayout);
paneItinerary = new JScrollPane();
tableItinerary = new JTable();
paneItinerary.add(tableItinerary);
ItineraryPanel.add(paneItinerary);
ButtonBar = new JMenuBar();
GridLayout ButtonLayout = new GridLayout(3, 1);
ButtonBar.setLayout(ButtonLayout);
Home = new JMenuItem("Home");
ButtonBar.add(Home);
Network = new JMenuItem("Network");
ButtonBar.add(Network);
Itinerary = new JMenuItem("Itinerary");
ButtonBar.add(Itinerary);
ButtonBar.setPreferredSize(new Dimension(50, 500));
MainPanel.add(ButtonBar);
MainPanel.add(CardPanel);
modelStops = (DefaultTableModel) tableStops.getModel();
modelStops.setColumnCount(2);
modelStops.setColumnIdentifiers(new Object[]{"Line", "Stop"});
modelItinerary = (DefaultTableModel) tableItinerary.getModel();
modelItinerary.setColumnCount(3);
modelItinerary.setColumnIdentifiers(new Object[]{"Line", "Stop", "Time"});
this.StopList = s; this.StopList = s;
setContentPane(MainPanel); setContentPane(MainPanel);
@ -77,40 +174,42 @@ public class View extends JFrame {
Home.addActionListener(new ActionListener() { Home.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Cardpanel.removeAll(); CardPanel.removeAll();
Cardpanel.add(HomePanel); CardPanel.add(HomePanel);
Cardpanel.repaint(); CardPanel.repaint();
Cardpanel.revalidate(); CardPanel.revalidate();
} }
}); });
Network.addActionListener(new ActionListener() { Network.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
showSearch(s); LoadSearchResult(s, modelStops);
Cardpanel.removeAll(); CardPanel.removeAll();
Cardpanel.add(NetworkPanel); CardPanel.add(NetworkPanel);
Cardpanel.repaint(); CardPanel.repaint();
Cardpanel.revalidate(); CardPanel.revalidate();
} }
}); });
Favorites.addActionListener(new ActionListener() { Itinerary.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Cardpanel.removeAll(); LoadSearchResultItinerary(searchResPath, modelItinerary);
Cardpanel.add(FavoritesPanel); CardPanel.removeAll();
Cardpanel.repaint(); CardPanel.add(ItineraryPanel);
Cardpanel.revalidate();
CardPanel.repaint();
CardPanel.revalidate();
} }
}); });
Lines.addActionListener(e -> { Lines.addActionListener(e -> {
Cardpanel.removeAll(); CardPanel.removeAll();
Cardpanel.add(LinesPanel); CardPanel.add(LinesPanel);
Cardpanel.repaint(); CardPanel.repaint();
Cardpanel.revalidate(); CardPanel.revalidate();
}); });
CSVImageProvider.getLineImageMap().forEach(p -> linesComboBox.addItem(p)); CSVImageProvider.getLineImageMap().forEach(p -> linesComboBox.addItem(p));
@ -119,49 +218,66 @@ public class View extends JFrame {
openWebpage(item.getValue()); openWebpage(item.getValue());
}); });
textField1.addKeyListener(new KeyAdapter() {
TextLocation.addKeyListener(new KeyAdapter() {
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
super.keyReleased(e); super.keyReleased(e);
if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (e.getKeyCode() == KeyEvent.VK_ENTER) {
searchCur = textField1.getText(); searchLocation = TextLocation.getText();
showSearch(s); LoadSearchResult(s, modelStops);
System.out.println("Enter key released with text " + searchCur); System.out.println("Enter key released with text " + searchLocation);
Cardpanel.removeAll(); CardPanel.removeAll();
Cardpanel.add(NetworkPanel); CardPanel.add(NetworkPanel);
Cardpanel.repaint(); CardPanel.repaint();
Cardpanel.revalidate(); CardPanel.revalidate();
} }
} }
}); });
searchButton.addActionListener(new ActionListener() { ButtonLocation.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Cardpanel.removeAll(); CardPanel.removeAll();
searchCur = textField1.getText(); searchLocation = TextLocation.getText();
showSearch(s); LoadSearchResult(s, modelStops);
System.out.println("search button clicked with text " + searchCur); System.out.println("search location clicked with text " + searchLocation);
Cardpanel.add(NetworkPanel); CardPanel.add(NetworkPanel);
Cardpanel.repaint(); CardPanel.repaint();
Cardpanel.revalidate(); CardPanel.revalidate();
} }
}); });
table.addMouseListener(new MouseAdapter() {
ButtonCoord.addActionListener(new ActionListener() {
@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);
CardPanel.repaint();
CardPanel.revalidate();
}
});
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(table, e.getX(), e.getY()); showOptionsDialog(tableStops, e.getX(), e.getY());
} }
}); });
mypane.addMouseListener(new MouseAdapter() {
paneStops.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
super.mouseClicked(e); super.mouseClicked(e);
@ -203,15 +319,11 @@ public class View extends JFrame {
View v = new View(s); View v = new View(s);
} }
public void LoadSearchResult(ArrayList<Stop> stops, DefaultTableModel model) {
public void showSearch(ArrayList<Stop> stops) {
// Clear existing rows from the table // Clear existing rows from the table
int cols = model.getColumnCount();
model.setRowCount(0); model.setRowCount(0);
model.setColumnCount(2); model.setColumnCount(cols);
// Add new rows based on the search results // Add new rows based on the search results
count = 0; count = 0;
@ -232,32 +344,61 @@ public class View extends JFrame {
System.out.println(count); System.out.println(count);
table.revalidate(); tableStops.revalidate();
table.repaint(); tableStops.repaint();
paneStops.setViewportView(tableStops);
mypane.setViewportView(table); paneStops.revalidate();
mypane.revalidate(); paneStops.repaint();
mypane.repaint();
NetworkPanel.revalidate(); NetworkPanel.revalidate();
NetworkPanel.repaint(); NetworkPanel.repaint();
this.displayTableValues();
} }
public void displayTableValues() { public void LoadSearchResultItinerary(ArrayList<Path> paths, DefaultTableModel model){
TableModel mod = table.getModel(); // Clear existing rows from the table
int cols = model.getColumnCount();
model.setRowCount(0);
model.setColumnCount(cols);
// Add new rows based on the search results
count = 0;
Path last = 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()});
++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);
tableItinerary.revalidate();
tableItinerary.repaint();
paneItinerary.setViewportView(tableItinerary);
paneItinerary.revalidate();
paneItinerary.repaint();
ItineraryPanel.revalidate();
ItineraryPanel.repaint();
this.displayTableValues(model);
}
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++) {
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) { private void openWebpage(URI uri) {

View file

@ -21,6 +21,8 @@ public class CSVSchedulesProvider {
put("Subway", new int[]{4, 2, 6,3,3,4}); put("Subway", new int[]{4, 2, 6,3,3,4});
}}; }};
// Time between 2 passages for the transports with a new type we don't know yet // Time between 2 passages for the transports with a new type we don't know yet
private static int DEFAULT_TIMING = 6; private static int DEFAULT_TIMING = 6;
private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat

View file

@ -23,6 +23,23 @@ import fr.u_paris.gla.project.utils.GPS;
* CSV Stream Provider class * CSV Stream Provider class
*/ */
public final class CSVStreamProvider { public final class CSVStreamProvider {
private static final HashMap<String, Double> two_acceleration_distance_by_type = new HashMap<String, Double>(){{
put("Bus", 0.1);
put("Funicular", 0.1);
put("Tram", 0.1);
put("Rail", 0.2);
put("Subway", 0.1);
}};
private static final HashMap<String, Double> max_speed_by_type = new HashMap<String, Double>(){{
put("Bus", 10.0);
put("Funicular", 5.0);
put("Tram", 20.0);
put("Rail", 50.0);
put("Subway", 30.0);
}};
/** /**
* Formatter from numbers into GPS Coordinates * Formatter from numbers into GPS Coordinates
*/ */
@ -201,7 +218,7 @@ public final class CSVStreamProvider {
this.line[NetworkFormat.DISTANCE_INDEX] = NumberFormat.getInstance(Locale.ENGLISH) this.line[NetworkFormat.DISTANCE_INDEX] = NumberFormat.getInstance(Locale.ENGLISH)
.format(distance); .format(distance);
this.line[NetworkFormat.DURATION_INDEX] = formatTime( this.line[NetworkFormat.DURATION_INDEX] = formatTime(
(long) Math.ceil(distanceToTime(distance) * SECONDS_IN_HOURS)); (long) Math.ceil(distanceToTime(distance,this.traceType) * SECONDS_IN_HOURS));
int bifurcation = this.lineSegments.get(this.start).size() - 1; int bifurcation = this.lineSegments.get(this.start).size() - 1;
this.line[NetworkFormat.VARIANT_INDEX] = Integer this.line[NetworkFormat.VARIANT_INDEX] = Integer
.toString(bifurcation); .toString(bifurcation);
@ -231,6 +248,18 @@ public final class CSVStreamProvider {
MINUTES_SECOND_FORMATTER.format(time / SECONDS_IN_MINUTES), MINUTES_SECOND_FORMATTER.format(time % SECONDS_IN_MINUTES)); MINUTES_SECOND_FORMATTER.format(time / SECONDS_IN_MINUTES), MINUTES_SECOND_FORMATTER.format(time % SECONDS_IN_MINUTES));
} }
// /** A tool method to give a delay to go through a certain distance.
// * <p>
// * This is a model with an linear acceleration and deceleration periods and a
// * constant speed in between.
// *
// * @param distance the distance (in km)
// * @return the duration of the trip (in hours) */
// private static double distanceToTime(double distance) {
// return Math.max(0, distance - TWO_ACCELERATION_DISTANCE) / MAX_SPEED
// + Math.pow(Math.min(distance, TWO_ACCELERATION_DISTANCE) / MAX_SPEED, 2);
// }
/** A tool method to give a delay to go through a certain distance. /** A tool method to give a delay to go through a certain distance.
* <p> * <p>
* This is a model with an linear acceleration and deceleration periods and a * This is a model with an linear acceleration and deceleration periods and a
@ -238,9 +267,11 @@ public final class CSVStreamProvider {
* *
* @param distance the distance (in km) * @param distance the distance (in km)
* @return the duration of the trip (in hours) */ * @return the duration of the trip (in hours) */
private static double distanceToTime(double distance) { private static double distanceToTime(double distance, String type) {
return Math.max(0, distance - TWO_ACCELERATION_DISTANCE) / MAX_SPEED Double max_speed = max_speed_by_type.get(type);
+ Math.pow(Math.min(distance, TWO_ACCELERATION_DISTANCE) / MAX_SPEED, 2); Double two_acc_distance = two_acceleration_distance_by_type.get(type);
return Math.max(0, distance - two_acc_distance) / max_speed
+ Math.pow(Math.min(distance, two_acc_distance) / max_speed, 2);
} }
private void fillTransports(int bif) { private void fillTransports(int bif) {

View file

@ -18,6 +18,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
* Code of an extractor for the data from IDF mobilite. * Code of an extractor for the data from IDF mobilite.
* *
@ -98,142 +99,6 @@ public class IDFMNetworkExtractor {
// Well named constants // Well named constants
private static final double QUARTER_KILOMETER = .25; private static final double QUARTER_KILOMETER = .25;
/**
* Main entry point for the extractor of IDF mobilité data into a network as
* defined by this application.
*
* @param args the arguments (expected one for the destination file)
*/
public static void main(String[] args) {
if (args.length != 2) {
LOGGER.severe("Invalid command line. Missing target files.");
return;
}
Map<String, TraceEntry> traces = new HashMap<>();
try {
CSVTools.readCSVFromFile(TRACE_FILE_DOWNLOADED_NAME,
(String[] line) -> addLine(line, traces));
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Error while reading the line paths", e);
}
List<StopEntry> stops = new ArrayList<>(traces.size() * GUESS_STOPS_BY_LINE);
try {
CSVTools.readCSVFromFile(STOPS_FILE_DOWNLOADED_NAME,
(String[] line) -> addStop(line, traces, stops));
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Error while reading the stops", e);
}
cleanTraces(traces);
Map<String, Transport> transports = new HashMap<>();
CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator(), transports);
// Write into args[0]
try {
CSVTools.writeCSVToFile(args[0], Stream.iterate(provider.next(),
t -> provider.hasNext(), t -> provider.next()));
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e,
() -> MessageFormat.format("Could not write in file {0}", args[0]));
}
/*CSVStreamSchedulesProvider providerschedules = new CSVStreamSchedulesProvider(traces.values().iterator());
// TraceEntry tmp = traces.values().iterator().next();
// tmp.getTerminus()
// .forEach(m -> LOGGER.log(Level.INFO, m));
// Write into args[1]
try {
CSVTools.writeCSVToFile(args[1], Stream.iterate(providerschedules.next(),
t -> providerschedules.hasNext(), t -> providerschedules.next()));
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e,
() -> MessageFormat.format("Could not write in file {0}", args[1]));
}*/
// System.out.println("****** END ******");
// System.out.println(transports.size());
// System.out.println(transports.get("IDFM:C01371").name);
// System.out.println(transports.get("IDFM:C02060").name);
// Transport ligne_1 = transports.get("IDFM:C01371");
// Transport ligne_7 = transports.get("IDFM:C01377");
// Transport rerd = transports.get("IDFM:C01728");
// Transport b54b = transports.get("IDFM:C00940");
// System.out.println("****** AFFICHAGE LIGNE ******");
// Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche");
// System.out.println(maisonBlanche.name);
// for (BifStop nextEntry : maisonBlanche.connected.values()) {
// System.out.println(nextEntry.bifurc+ nextEntry.stop.name);
// }
// System.out.println("****** AFFICHAGE LIGNE ******");
// Stop corientin = ligne_7.stopsMap.get("Corentin Cariou");
// System.out.println(corientin.name);
// for (BifStop nextEntry : corientin.connected.values()) {
// System.out.println(nextEntry.bifurc+ nextEntry.stop.name);
// }
// System.out.println("***************************");
// System.out.println("****** AFFICHAGE Description ******");
// System.out.println(traces.get("IDFM:C01377").descriptions);
// System.out.println("****** AFFICHAGE Description False ******");
// System.out.println(ligne_7.descriptions);
// System.out.println("****************** Build la path ***********************");
// System.out.println(ligne_7.type);
// System.out.println(rerd.type);
// ligne_7.buildBifurcation();
// rerd.buildBifurcation();
// System.out.println("******************Derniere description ***********************");
// System.out.println(ligne_7.descriptions);
// System.out.println("******************Description 54B ************************");
// b54b.buildBifurcation();
// System.out.println(b54b.descriptions);
System.out.println("******************Building bifurcations ************************");
long startTime = System.currentTimeMillis();
for (Transport entry : transports.values()) {
entry.buildBifurcationOptimzed();
}
long endTime = System.currentTimeMillis();
long tempsPasse = endTime - startTime;
long minutes = (tempsPasse / 1000) / 60;
long seconds = (tempsPasse / 1000) % 60;
long milliseconds = tempsPasse % 1000;
System.out.println("Temps écoulé : " + minutes + " minutess, " + seconds + " secndes et " + milliseconds + " millis");
System.out.println("******************Fin Building bifurcations ************************");
CSVSchedulesProvider providerschedules = new CSVSchedulesProvider(transports.values().iterator());
try {
CSVTools.writeCSVToFile(args[1], Stream.iterate(providerschedules.next(),
t -> providerschedules.hasNext(), t -> providerschedules.next()));
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e,
() -> MessageFormat.format("Could not write in file {0}", args[1]));
}
CSVImageProvider providerimage = new CSVImageProvider(transports.values().iterator());
String imageCSV = "image.csv";
try {
CSVTools.writeCSVToFile(imageCSV, Stream.iterate(providerimage.next(),
t -> providerimage.hasNext(), t -> providerimage.next()));
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e,
() -> MessageFormat.format("Could not write in file {0}", imageCSV));
}
}
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()) {
@ -245,7 +110,7 @@ public class IDFMNetworkExtractor {
} }
} }
public static void builFiles() { public static void buildFiles() {
if (checkFileExistence("./"+HOURS_FILE_NAME) && checkFileExistence("./"+TRACE_FILE_NAME)) { if (checkFileExistence("./"+HOURS_FILE_NAME) && checkFileExistence("./"+TRACE_FILE_NAME)) {
LOGGER.severe("Files already exists."); LOGGER.severe("Files already exists.");

View file

@ -1,23 +1,43 @@
package fr.u_paris.gla.project.itinerary; package fr.u_paris.gla.project.itinerary;
import fr.u_paris.gla.project.utils.GPS;
import java.util.*; import java.util.*;
public class Finder { public class Finder {
private Graph graph; private Graph graph;
public Finder(Graph graph) { public Finder(Graph graph) {
this.graph = graph; this.graph = graph;
} }
public List<Path> findPath(double from_x, double from_y, double to_x, double to_y, double startTime) {
Stop fromNode = new Stop("", "tmp_from", from_x, from_y);
Stop toNode = new Stop("", "tmp_to", to_x, to_y);
for (Stop node : graph.getNodes()) {
double from_dst = GPS.distance(from_x, from_y, node.getLatitude(), node.getLongitude());
double to_dst = GPS.distance(to_x, to_y, node.getLatitude(), node.getLongitude());
Connection from_c = new Connection(node, "", from_dst, (int) ((from_dst * 1000) / Parse.WALK_SPEED));
Connection to_c = new Connection(toNode, "", to_dst, (int) ((to_dst * 1000) / Parse.WALK_SPEED));
graph.addConnection(fromNode, from_c);
graph.addConnection(node, to_c);
}
graph.addNode(fromNode);
graph.addNode(toNode);
List<Path> res = findPath(fromNode, toNode, startTime);
return res;
}
/** /**
* return a path from startNode to goalNode using A* algorithm * return a path from startNode to goalNode using A* algorithm
* @param startNode * @param startNode
* @param goalNode * @param goalNode
*/ */
public List<Path> findPath(Stop startNode, Stop goalNode, double startTime) { public List<Path> findPath(Stop startNode, Stop goalNode, double startTime) {
PriorityQueue<Stop> openSet = new PriorityQueue<>(Comparator.comparingDouble(Stop::getF));
PriorityQueue<Stop> openSet = new PriorityQueue<>(Comparator.comparingDouble(GraphNode::getF));
HashSet<Stop> closedSet = new HashSet<>(); HashSet<Stop> closedSet = new HashSet<>();
HashMap<Stop, Path> cameFrom = new HashMap<>(); HashMap<Stop, Path> cameFrom = new HashMap<>();
HashMap<Stop, Double> gScore = new HashMap<>(); HashMap<Stop, Double> gScore = new HashMap<>();
@ -111,6 +131,5 @@ public class Finder {
node.setF(newF); node.setF(newF);
openSet.add(node); openSet.add(node);
} }
} }

View file

@ -1,6 +1,6 @@
package fr.u_paris.gla.project.itinerary; package fr.u_paris.gla.project.itinerary;
import java.util.HashMap; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -25,4 +25,25 @@ public class Graph{
public Map<Stop, Set<Connection>> getConnections() { public Map<Stop, Set<Connection>> getConnections() {
return connections; return connections;
} }
public void addNode(Stop s) {
nodes.add(s);
}
public void addConnection(Stop stop, Connection con) {
Set<Connection> currentConnections = connections.get(stop);
if (currentConnections == null) {
HashSet<Connection> set = new HashSet<>();
set.add(con);
connections.put(stop, set);
}
else {
currentConnections.add(con);
}
}
public void removeNode(Stop s) {
nodes.remove(s);
connections.remove(s);
}
} }

View file

@ -1,14 +0,0 @@
package fr.u_paris.gla.project.itinerary;
import java.util.List;
import java.util.Set;
public interface GraphNode {
int getId();
double getHeuristicCost(Stop goalNode);
Set<Stop> getNeighbors();
double getCost(Stop neighbor);
double getF();
void setF(double value);
}

View file

@ -9,7 +9,7 @@ import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
public class ItineraryCalculator { public class Parse {
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
.getLogger(IDFMNetworkExtractor.class.getName()); .getLogger(IDFMNetworkExtractor.class.getName());
@ -42,7 +42,11 @@ public class ItineraryCalculator {
private static final int STOP_TIME = 30; private static final int STOP_TIME = 30;
//Walking speed in m/s //Walking speed in m/s
private static final double WALK_SPEED = 1.; public static final double WALK_SPEED = 1.;
private HashSet<Stop> nodes = new HashSet<>();
private HashMap<Stop, Set<Connection>> connections = new HashMap<>();
private HashMap<String, ArrayList<Stop>> tmp = new HashMap<>();
/** /**
* Returns the coordinates from a String to a double array: * Returns the coordinates from a String to a double array:
@ -55,6 +59,9 @@ public class ItineraryCalculator {
return new double[] {Double.parseDouble(stringCoords[0]), Double.parseDouble(stringCoords[1])}; return new double[] {Double.parseDouble(stringCoords[0]), Double.parseDouble(stringCoords[1])};
} }
public HashMap<String, ArrayList<Stop>> getTmp(){
return tmp;
}
/** /**
* Searchs for a stop with the same name and GPS coordinates in the graph, and creates it if non existant * Searchs for a stop with the same name and GPS coordinates in the graph, and creates it if non existant
* @param nodes a graph of the stops * @param nodes a graph of the stops
@ -204,17 +211,12 @@ public class ItineraryCalculator {
} }
} }
public static void main(String[] args){ public void parseFiles(){
if (args.length != 0) {
LOGGER.severe("Invalid command line. Target file names are in the main file for now."); IDFMNetworkExtractor.buildFiles();
return;
}
//IDFMNetworkExtractor.builFiles();
try { try {
HashSet<Stop> nodes = new HashSet<>();
HashMap<Stop, Set<Connection>> connections = new HashMap<>();
HashMap<String, ArrayList<Stop>> tmp = new HashMap<>();
CSVTools.readCSVFromFile(TRACE_FILE_NAME, CSVTools.readCSVFromFile(TRACE_FILE_NAME,
(String[] line) -> addLine(line, nodes, tmp, connections)); (String[] line) -> addLine(line, nodes, tmp, connections));
@ -227,32 +229,16 @@ public class ItineraryCalculator {
} }
} }
Stop porteivry = tmp.get("Porte d'Ivry").get(0);
Stop repu = tmp.get("République").get(0);
Graph graph = new Graph(nodes, connections);
int cpt = 0;
for (Map.Entry<Stop, Set<Connection>> entry : graph.getConnections().entrySet()) {
if (entry.getValue() == null) cpt +=1;
}
Stop garenord = tmp.get("Gare du Nord").get(0);
Stop chatelet = tmp.get("Châtelet").get(0);
//System.out.println(graph.getConnections(garenord));
//System.out.println(cpt);
//System.out.println(graph.getConnections(porteivry));
Finder finder = new Finder(graph);
List<Path> res = finder.findPath(porteivry, chatelet, 43200);
for (Path element : res) {
System.out.println(element.getCurrentStop());
}
} 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 List<Path> getItinerary(Stop src, Stop dst, double startTime ){
Graph graph = new Graph(nodes, connections);
Finder finder = new Finder(graph);
return finder.findPath(src, dst, startTime);
} }
} }

View file

@ -3,7 +3,7 @@ package fr.u_paris.gla.project.itinerary;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class Stop implements GraphNode { public class Stop {
// The total number of stops // The total number of stops
private static int counter = 0; private static int counter = 0;
@ -41,27 +41,22 @@ public class Stop implements GraphNode {
'}'; '}';
} }
@Override
public int getId(){ public int getId(){
return id; return id;
} }
@Override
public double getHeuristicCost(Stop goalNode) { public double getHeuristicCost(Stop goalNode) {
return 0; return 0;
} }
@Override
public Set<Stop> getNeighbors() { public Set<Stop> getNeighbors() {
return null; return null;
} }
@Override
public double getCost(Stop neighbor) { public double getCost(Stop neighbor) {
return 0; return 0;
} }
@Override
public double getF() { public double getF() {
return f; return f;
} }