diff --git a/src/main/java/fr/u_paris/gla/project/gui/View.form b/src/main/java/fr/u_paris/gla/project/gui/View.form index 703d5bc..21d3701 100644 --- a/src/main/java/fr/u_paris/gla/project/gui/View.form +++ b/src/main/java/fr/u_paris/gla/project/gui/View.form @@ -58,7 +58,7 @@ - + @@ -100,6 +100,7 @@ + @@ -109,7 +110,12 @@ - + + + + + + @@ -135,9 +141,18 @@ + + + + + + + + + - + @@ -156,13 +171,6 @@ - - - - - - - @@ -204,6 +212,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/fr/u_paris/gla/project/gui/View.java b/src/main/java/fr/u_paris/gla/project/gui/View.java index 7fc0831..d6db5f1 100644 --- a/src/main/java/fr/u_paris/gla/project/gui/View.java +++ b/src/main/java/fr/u_paris/gla/project/gui/View.java @@ -4,6 +4,7 @@ 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.ActionEvent; import java.awt.event.ActionListener; @@ -11,7 +12,7 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.util.ArrayList; -public class View extends JFrame{ +public class View extends JFrame { private JPanel Cardpanel; private JMenuItem Home; private JMenuItem Network; @@ -27,13 +28,22 @@ public class View extends JFrame{ private JTable table; private JScrollPane mypane; + private JPanel ItineraryPanel; + private JMenuItem Itinerary; private ArrayList StopList; - private Stop StopCur; + private Stop departureCur; + + private Stop arrivalCur; + + private String searchCur; private ArrayList searchRes; + private int count = 0; + + public View(ArrayList s) throws HeadlessException { this.createUIComponents(); this.StopList = s; @@ -43,7 +53,8 @@ public class View extends JFrame{ setTitle("app"); setExtendedState(JFrame.MAXIMIZED_BOTH); //setUndecorated(true); - setVisible(true);; + setVisible(true); + ; setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Home.addActionListener(new ActionListener() { @@ -59,8 +70,10 @@ public class View extends JFrame{ Network.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { + showSearch(s); Cardpanel.removeAll(); Cardpanel.add(NetworkPanel); + Cardpanel.repaint(); Cardpanel.revalidate(); } @@ -82,76 +95,103 @@ public class View extends JFrame{ public void keyReleased(KeyEvent e) { super.keyReleased(e); if (e.getKeyCode() == KeyEvent.VK_ENTER) { - System.out.println("Enter key released"); + + 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(); + } + }); } - - public static void main(String[] args) { ArrayList 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)); - System.out.println(s.toString()); View v = new View(s); - v.showSearch(s); - + } private void createUIComponents() { // TODO: place custom component creation code here - table = new JTable(); - dtm = new DefaultTableModel(0, 0); - String[] header = new String[] { "Line", "Stop" }; + dtm = new DefaultTableModel(1, 2); + + String[] header = new String[]{"Line", "Stop"}; dtm.setColumnIdentifiers(header); - table.setModel(dtm); + dtm.setValueAt("test", 0, 0); + dtm.setValueAt("test", 0, 1); + table = new JTable(dtm); + table.setPreferredScrollableViewportSize(table.getPreferredSize()); + mypane = new JScrollPane(table); } - private void showSearch(ArrayList stops) { + public void showSearch(ArrayList stops) { // Clear existing rows from the table dtm.setRowCount(0); // 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 - dtm.addRow(new Object[]{stop.getLines(), stop.getName()}); + dtm.addRow(new Object[]{stop.getLines().iterator().next(), stop.getName()}); + ++count; } - this.displayTableValues(); - dtm.fireTableDataChanged(); - table.repaint(); + + table.setModel(dtm); table.revalidate(); - Cardpanel.repaint(); - Cardpanel.revalidate(); + table.repaint(); + + mypane.setViewportView(table); + mypane.revalidate(); + mypane.repaint(); + + NetworkPanel.revalidate(); + NetworkPanel.repaint(); + + + this.displayTableValues(); } - private void displayTableValues() { - int rowCount = dtm.getRowCount(); - int columnCount = dtm.getColumnCount(); - - // Iterate over each row - for (int row = 0; row < rowCount; row++) { - // Iterate over each column - for (int col = 0; col < columnCount; col++) { - // Get the value at the current cell - Object value = dtm.getValueAt(row, col); - // Display the value - System.out.println("Value at row " + row + ", column " + col + ": " + value); + 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(); + + } }