Merge branch 'gui' into 'dev'
branche GUI (Stops) See merge request gla-groupe-3/projet!15
This commit is contained in:
commit
0a95f54fb0
3 changed files with 510 additions and 1 deletions
270
src/main/java/fr/u_paris/gla/project/gui/View.form
Normal file
270
src/main/java/fr/u_paris/gla/project/gui/View.form
Normal file
|
@ -0,0 +1,270 @@
|
|||
<?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>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="67039" class="javax.swing.JMenuBar" layout-manager="GridLayoutManager" row-count="9" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
239
src/main/java/fr/u_paris/gla/project/gui/View.java
Normal file
239
src/main/java/fr/u_paris/gla/project/gui/View.java
Normal file
|
@ -0,0 +1,239 @@
|
|||
package fr.u_paris.gla.project.gui;
|
||||
|
||||
import fr.u_paris.gla.project.itinerary.Stop;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class View extends JFrame {
|
||||
private JPanel Cardpanel;
|
||||
private JMenuItem Home;
|
||||
private JMenuItem Network;
|
||||
private JMenuItem Favorites;
|
||||
private JPanel NetworkPanel;
|
||||
private JPanel FavoritesPanel;
|
||||
private JTextField textField1;
|
||||
private JButton searchButton;
|
||||
private JPanel HomePanel;
|
||||
private JPanel MainPanel;
|
||||
private DefaultTableModel model;
|
||||
|
||||
private JTable table;
|
||||
|
||||
private JScrollPane mypane;
|
||||
private JPanel ItineraryPanel;
|
||||
private JMenuItem Itinerary;
|
||||
private JPanel stationsPanel;
|
||||
private JLabel departText;
|
||||
private JLabel arrText;
|
||||
|
||||
private ArrayList<Stop> StopList;
|
||||
|
||||
private String departureCur;
|
||||
|
||||
private String arrivalCur;
|
||||
|
||||
private String searchCur;
|
||||
|
||||
private ArrayList<Stop> searchRes;
|
||||
|
||||
private int count = 0;
|
||||
|
||||
|
||||
public View(ArrayList<Stop> s) throws HeadlessException {
|
||||
model = (DefaultTableModel) table.getModel();
|
||||
model.setColumnCount(2);
|
||||
model.setColumnIdentifiers(new Object[]{"Line", "Stop"});
|
||||
this.StopList = s;
|
||||
|
||||
|
||||
setContentPane(MainPanel);
|
||||
setTitle("app");
|
||||
setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||
//setUndecorated(true);
|
||||
setVisible(true);
|
||||
;
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Home.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Cardpanel.removeAll();
|
||||
Cardpanel.add(HomePanel);
|
||||
Cardpanel.repaint();
|
||||
Cardpanel.revalidate();
|
||||
}
|
||||
});
|
||||
|
||||
Network.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
showSearch(s);
|
||||
Cardpanel.removeAll();
|
||||
Cardpanel.add(NetworkPanel);
|
||||
|
||||
Cardpanel.repaint();
|
||||
Cardpanel.revalidate();
|
||||
}
|
||||
});
|
||||
|
||||
Favorites.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Cardpanel.removeAll();
|
||||
Cardpanel.add(FavoritesPanel);
|
||||
Cardpanel.repaint();
|
||||
Cardpanel.revalidate();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
textField1.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
super.keyReleased(e);
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
|
||||
searchCur = textField1.getText();
|
||||
showSearch(s);
|
||||
System.out.println("Enter key released with text " + searchCur);
|
||||
Cardpanel.removeAll();
|
||||
Cardpanel.add(NetworkPanel);
|
||||
|
||||
Cardpanel.repaint();
|
||||
Cardpanel.revalidate();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
searchButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Cardpanel.removeAll();
|
||||
searchCur = textField1.getText();
|
||||
showSearch(s);
|
||||
System.out.println("search button clicked with text " + searchCur);
|
||||
Cardpanel.add(NetworkPanel);
|
||||
|
||||
Cardpanel.repaint();
|
||||
Cardpanel.revalidate();
|
||||
}
|
||||
});
|
||||
table.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
super.mouseClicked(e);
|
||||
System.out.println("MouseClick: " + e.getX() + ";" + e.getY());
|
||||
showOptionsDialog(table, e.getX(), e.getY());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mypane.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
super.mouseClicked(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showOptionsDialog(JTable table, int x, int y) {
|
||||
int selectedRow = table.rowAtPoint(new Point(x, y));
|
||||
if (selectedRow != -1) { // If a row is selected
|
||||
|
||||
String stationSel = (String) table.getValueAt(selectedRow, 1);
|
||||
|
||||
// Options to set Departure, Arrival, or Cancel
|
||||
Object[] options = {"Departure", "Arrival", "Cancel"};
|
||||
int choice = JOptionPane.showOptionDialog(null, "What action would you like to perform for " + stationSel + "?", "Action Selection",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
|
||||
|
||||
// Handling the choice
|
||||
if (choice == 0) {
|
||||
this.departureCur = stationSel;
|
||||
this.departText.setText("Departure: " + stationSel);
|
||||
} else if (choice == 1) {
|
||||
this.arrivalCur = stationSel;
|
||||
this.arrText.setText("Arrival: " + stationSel);
|
||||
} else {
|
||||
System.out.println("rien");
|
||||
}
|
||||
System.out.println("Départ: " + this.departureCur + "; Arrivée: " + this.arrivalCur);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 showSearch(ArrayList<Stop> stops) {
|
||||
// Clear existing rows from the table
|
||||
|
||||
model.setRowCount(0);
|
||||
model.setColumnCount(2);
|
||||
|
||||
|
||||
// Add new rows based on the search results
|
||||
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);
|
||||
|
||||
table.revalidate();
|
||||
table.repaint();
|
||||
|
||||
mypane.setViewportView(table);
|
||||
mypane.revalidate();
|
||||
mypane.repaint();
|
||||
|
||||
NetworkPanel.revalidate();
|
||||
NetworkPanel.repaint();
|
||||
|
||||
|
||||
this.displayTableValues();
|
||||
|
||||
}
|
||||
|
||||
public void displayTableValues() {
|
||||
TableModel mod = table.getModel();
|
||||
for (int row = 0; row < mod.getRowCount(); row++) {
|
||||
for (int column = 0; column < mod.getColumnCount(); column++) {
|
||||
System.out.print(mod.getValueAt(row, column).toString() + " ");
|
||||
}
|
||||
System.out.print(";");
|
||||
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue