From ce69a218e308dbacb3c5e345a46007e55a687dd9 Mon Sep 17 00:00:00 2001 From: MAMBILA TETE jean philipp <@mambilat> Date: Mon, 29 Apr 2024 17:39:55 +0200 Subject: [PATCH 1/2] [feat] itinerary works and table display, no more jform --- .../java/fr/u_paris/gla/project/gui/View.form | 270 ------------------ .../java/fr/u_paris/gla/project/gui/View.java | 238 +++++++++++---- 2 files changed, 181 insertions(+), 327 deletions(-) delete mode 100644 src/main/java/fr/u_paris/gla/project/gui/View.form 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 deleted file mode 100644 index 928c8a8..0000000 --- a/src/main/java/fr/u_paris/gla/project/gui/View.form +++ /dev/null @@ -1,270 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 e6bc8ef..88e9738 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 @@ -8,29 +8,41 @@ 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 JPanel CardPanel; private JMenuItem Home; private JMenuItem Network; private JMenuItem Favorites; private JPanel NetworkPanel; - private JPanel FavoritesPanel; - private JTextField textField1; - private JButton searchButton; + + private JTextField TextLocation; + private JButton ButtonLocation; private JPanel HomePanel; 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 JMenuItem Itinerary; private JPanel stationsPanel; private JLabel departText; private JLabel arrText; + private JTextField TextCoord; + private JButton ButtonCoord; + private JPanel SearchCoordPanel; + private JPanel SearchLocationPanel; + private JLabel NetworkLabel; + private JLabel FavLabel; + private JMenuBar ButtonBar; private ArrayList StopList; @@ -38,7 +50,9 @@ public class View extends JFrame { private String arrivalCur; - private String searchCur; + private String searchLocation; + + private String searchCoord; private ArrayList searchRes; @@ -46,9 +60,87 @@ public class View extends JFrame { public View(ArrayList s) throws HeadlessException { - model = (DefaultTableModel) table.getModel(); - model.setColumnCount(2); - model.setColumnIdentifiers(new Object[]{"Line", "Stop"}); + MainPanel = new JPanel(); + GridLayout MainLayout = new GridLayout(1, 2, 50, 0); + MainPanel.setLayout(MainLayout); + 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(4, 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; @@ -63,79 +155,98 @@ public class View extends JFrame { Home.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - Cardpanel.removeAll(); - Cardpanel.add(HomePanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + 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); + LoadSearchResult(s, modelStops); + CardPanel.removeAll(); + CardPanel.add(NetworkPanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + CardPanel.repaint(); + CardPanel.revalidate(); } }); - Favorites.addActionListener(new ActionListener() { + Itinerary.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - Cardpanel.removeAll(); - Cardpanel.add(FavoritesPanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + LoadSearchResult(s, modelItinerary); + CardPanel.removeAll(); + CardPanel.add(ItineraryPanel); + + CardPanel.repaint(); + CardPanel.revalidate(); } }); - textField1.addKeyListener(new KeyAdapter() { + + + TextLocation.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); + searchLocation = TextLocation.getText(); + LoadSearchResult(s, modelStops); + System.out.println("Enter key released with text " + searchLocation); + CardPanel.removeAll(); + CardPanel.add(NetworkPanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + CardPanel.repaint(); + CardPanel.revalidate(); } } }); - searchButton.addActionListener(new ActionListener() { + ButtonLocation.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.removeAll(); + searchLocation = TextLocation.getText(); + LoadSearchResult(s, modelStops); + System.out.println("search location clicked with text " + searchLocation); + CardPanel.add(NetworkPanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + CardPanel.repaint(); + 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 public void mouseClicked(MouseEvent e) { super.mouseClicked(e); 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 public void mouseClicked(MouseEvent e) { super.mouseClicked(e); @@ -182,11 +293,11 @@ public class View extends JFrame { - public void showSearch(ArrayList stops) { + public void LoadSearchResult(ArrayList stops, DefaultTableModel model) { // Clear existing rows from the table - + int cols = model.getColumnCount(); model.setRowCount(0); - model.setColumnCount(2); + model.setColumnCount(cols); // Add new rows based on the search results @@ -208,26 +319,39 @@ public class View extends JFrame { System.out.println(count); - table.revalidate(); - table.repaint(); + tableStops.revalidate(); + tableStops.repaint(); + + tableItinerary.revalidate(); + tableItinerary.repaint(); + + paneStops.setViewportView(tableStops); + paneStops.revalidate(); + paneStops.repaint(); + + + paneItinerary.setViewportView(tableItinerary); + paneItinerary.revalidate(); + paneItinerary.repaint(); - mypane.setViewportView(table); - mypane.revalidate(); - mypane.repaint(); NetworkPanel.revalidate(); NetworkPanel.repaint(); + ItineraryPanel.revalidate(); + ItineraryPanel.repaint(); - this.displayTableValues(); + + this.displayTableValues(model); } - public void displayTableValues() { - TableModel mod = table.getModel(); + public void displayTableValues(TableModel mod) { + for (int row = 0; row < mod.getRowCount(); row++) { 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(";"); From 70ad25019bb6f85245f115697296064c086baca3 Mon Sep 17 00:00:00 2001 From: MAMBILA TETE jean philipp <@mambilat> Date: Mon, 29 Apr 2024 17:44:07 +0200 Subject: [PATCH 2/2] [feat] itinerary works and table display, no more jform --- src/main/java/fr/u_paris/gla/project/gui/View.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 88e9738..3db7c01 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 @@ -119,7 +119,7 @@ public class View extends JFrame { ButtonBar = new JMenuBar(); - GridLayout ButtonLayout = new GridLayout(4, 1); + GridLayout ButtonLayout = new GridLayout(3, 1); ButtonBar.setLayout(ButtonLayout); Home = new JMenuItem("Home"); ButtonBar.add(Home);