diff --git a/out/production/FIProjetIHM2022/Test/AdminView.class b/out/production/FIProjetIHM2022/Test/AdminView.class index dcbd159..f540f81 100644 Binary files a/out/production/FIProjetIHM2022/Test/AdminView.class and b/out/production/FIProjetIHM2022/Test/AdminView.class differ diff --git a/out/production/FIProjetIHM2022/Test/BFrame.class b/out/production/FIProjetIHM2022/Test/BFrame.class index 9d206d2..4d9053a 100644 Binary files a/out/production/FIProjetIHM2022/Test/BFrame.class and b/out/production/FIProjetIHM2022/Test/BFrame.class differ diff --git a/out/production/FIProjetIHM2022/Test/Controller$1.class b/out/production/FIProjetIHM2022/Test/Controller$1.class index f017eb7..9876162 100644 Binary files a/out/production/FIProjetIHM2022/Test/Controller$1.class and b/out/production/FIProjetIHM2022/Test/Controller$1.class differ diff --git a/out/production/FIProjetIHM2022/Test/Controller.class b/out/production/FIProjetIHM2022/Test/Controller.class index fade4b9..27a06e6 100644 Binary files a/out/production/FIProjetIHM2022/Test/Controller.class and b/out/production/FIProjetIHM2022/Test/Controller.class differ diff --git a/src/Test/AdminView.java b/src/Test/AdminView.java index 879b517..7b2d547 100644 --- a/src/Test/AdminView.java +++ b/src/Test/AdminView.java @@ -44,7 +44,7 @@ public class AdminView extends BFrame { settings.setPositionY(2); JButton addStudGrup = new JButton("Ajouter un etudiant dans un groupe"); addStudGrup.addActionListener(this.listener); - addStudGrup.setActionCommand("av::AddStudGrup"); + addStudGrup.setActionCommand("TODO"); this.add(addStudGrup, settings); this.openBFrame(); diff --git a/src/Test/BFrame.java b/src/Test/BFrame.java index aa697bc..df8ab8b 100644 --- a/src/Test/BFrame.java +++ b/src/Test/BFrame.java @@ -7,9 +7,7 @@ package Test; * 28/09/2022 at 20:35 * */ -import javax.swing.JFrame; -import javax.swing.SwingUtilities; -import javax.swing.ImageIcon; +import javax.swing.*; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.event.WindowEvent; @@ -21,7 +19,7 @@ import java.awt.event.WindowEvent; */ public class BFrame extends JFrame { - private final String title; + private String title; private int location_x = 1; private int location_y = 1; private int width = 500; @@ -100,6 +98,30 @@ public class BFrame extends JFrame { initBFrame(layout, layout_row, layout_col); } + /** + * Pour creer une fenetre modal + * + * @param title Le titre de la fenetre + * @param loca_x La localisation en x de la fenetre + * @param loca_y La localisation en y de la fenetre + * @param size_x La longueur de la fenetre + * @param size_y La largeur de la fenetre + * @param daron La fenetre qui va etre bloquer + * @param content Contenu de la fenetre + * */ + public BFrame(String title, int loca_x, int loca_y, int size_x, int size_y, BFrame daron, JPanel content) { + JDialog frame = new JDialog(daron, title, true); + frame.setLocation(loca_x, loca_y); + frame.setSize(size_x, size_y); + frame.getContentPane().add(content); + + JScrollPane scrollPane = new JScrollPane(); + frame.getContentPane().add(scrollPane); + scrollPane.setViewportView(content); + + frame.setVisible(true); + } + /** * Initialiser la fenetre sans Layout par def. */ diff --git a/src/Test/Controller.java b/src/Test/Controller.java index 4cae8a9..09ce7f5 100644 --- a/src/Test/Controller.java +++ b/src/Test/Controller.java @@ -6,17 +6,27 @@ import API.Groupe; import javax.swing.JTable; import javax.swing.JScrollPane; import javax.swing.JOptionPane; +import javax.swing.event.ListSelectionEvent; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableModel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Objects; -public class Controller implements ActionListener { +//test +import javax.swing.JDialog; +import javax.swing.JPanel; +import java.awt.GridLayout; + +public class Controller implements ActionListener, ListSelectionListener { private final BDatabase db; private final ProfView pv; private final AdminView av; private final ArrayList e; private final ArrayList g; + private JTable currentJTableUse; public Controller(ArrayList e, ArrayList g) { this.e = e; @@ -28,6 +38,58 @@ public class Controller implements ActionListener { System.out.println("[+] Demarrage de la vue Administrateur -> " + av); } + /** + * Pour creer une JTable + * @param data Les donnees + * @param title Les titres + * */ + private JTable createJTable(Object[][] data, String[] title) { + return new JTable(data, title) { + public boolean editCellAt(int row, int column, java.util.EventObject e) { + return false; + } + }; + } + + /** + * Pour afficher une JTable + * @param frame La fenetre + * @param liste La JTable + * */ + private void Display(BFrame frame, JTable liste) { + liste.getTableHeader().setReorderingAllowed(false); + liste.setFillsViewportHeight(true); + + this.currentJTableUse = liste; + + JScrollPane scroll = new JScrollPane(liste); + frame.getContentPane().add(scroll); + + frame.openBFrame(); + } + + /** + * Pour afficher une JTable contenant un listener + * @param frameTitle La fenetre + * @param liste La JTable + * */ + private void DisplayWithListner(BFrame parent, String frameTitle, JTable liste) { + JPanel forModal = new JPanel(); + + ListSelectionModel lsm = liste.getSelectionModel(); + lsm.addListSelectionListener(this); + liste.getTableHeader().setReorderingAllowed(false); + liste.setFillsViewportHeight(true); + + this.currentJTableUse = liste; + + forModal.add(liste); + + // BETA + // TODO: Manque les colonnes et prends toute la surface + BFrame frame = new BFrame(frameTitle, 1, 1, 500, 500, parent, forModal); + } + @Override public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); @@ -67,7 +129,7 @@ public class Controller implements ActionListener { data[i] = info; } - Display(frame, data, titre); + Display(frame, this.createJTable(data, titre)); } else if(Objects.equals(command, "pv::GetListFiltered")) { @@ -109,7 +171,7 @@ public class Controller implements ActionListener { data_final[x] = data[x]; } - Display(frame, data_final, titre); + Display(frame, this.createJTable(data, titre)); } else if(Objects.equals(command, "pv::SearchStudentPer3Letters")) { @@ -167,67 +229,51 @@ public class Controller implements ActionListener { }; } - Display(frame, data, titre); + Display(frame, this.createJTable(data, titre)); } } } else if(Objects.equals(command, "av::MoveStudGrup")) { - BFrame frame = new BFrame( - "Deplacer un etudiant", - 1, - 1, - 500, - 500, - "GridLayout", - 1, - 1, - 2 - ); + Object[][] data = new Object[this.e.size()][2]; - String[][] data = new String[this.e.size()][3]; - - Object[] titre = { - (String) "Nom", - (String) "Prenom", - (String) "Groupe", - (String) "Action" + String[] titre = { + "Nom", + "Prenom", + "Groupe" }; for(int i = 0; i <= this.e.size()-1; i++) { Object[] info = { - (String) this.e.get(i).getNom(), - (String) this.e.get(i).getPrenom(), - (String) String.valueOf(this.e.get(i).getGroupe()), - (String) "Deplacer" + this.e.get(i).getNom(), + this.e.get(i).getPrenom(), + String.valueOf(this.e.get(i).getGroupe()), }; data[i] = info; } - Display(frame, data, titre); + DisplayWithListner(this.av, "Deplacer un etudiant", this.createJTable(data, titre)); } } - /** - * Pour afficher le JTable - * @param frame La fenetre - * @param data Les donnees des colonnes du tableau - * @param titre Les titres des colonnes - * */ - private void Display(BFrame frame, Object[][] data, Object[] titre) { - JTable liste = new JTable(data, titre) { - public boolean editCellAt(int row, int column, java.util.EventObject e) { - return false; + @Override + public void valueChanged(ListSelectionEvent e) { + int[] cell; + Object value; + if (!e.getValueIsAdjusting()) + { + cell = this.currentJTableUse.getSelectedRows(); + if (cell.length > 0) + { + for (int i=0; i < 3; i++) { + TableModel tm = this.currentJTableUse.getModel(); + value = tm.getValueAt(cell[0],i); + System.out.print(value + " "); + } + + System.out.println(); } - }; - - liste.getTableHeader().setReorderingAllowed(false); - liste.setFillsViewportHeight(true); - - JScrollPane scroll = new JScrollPane(liste); - frame.getContentPane().add(scroll); - - frame.openBFrame(); + } } } \ No newline at end of file