From 3bc079999287ddeba5842166f36440de1de6170b Mon Sep 17 00:00:00 2001 From: "pro.boooooo" Date: Thu, 1 Dec 2022 18:59:34 +0100 Subject: [PATCH] $ --- src/Test/AdminView.java | 4 ++ src/Test/BDatabase.java | 25 ++++---- src/Test/BFrame.java | 2 +- src/Test/Controller.java | 60 +++++------------- src/Test/MainMenu.java | 88 +++++++++++++------------- src/Test/ProfView.java | 6 +- src/Test/StudentView.java | 125 +++++++++++++++++++++++++++++++++++++ src/Test/TestTexteMNP.java | 5 +- 8 files changed, 209 insertions(+), 106 deletions(-) create mode 100644 src/Test/StudentView.java diff --git a/src/Test/AdminView.java b/src/Test/AdminView.java index 58d5a61..92f41cd 100644 --- a/src/Test/AdminView.java +++ b/src/Test/AdminView.java @@ -2,6 +2,8 @@ package Test; import API.Etudiant; import API.Groupe; + +import java.awt.*; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JLabel; @@ -15,6 +17,8 @@ public class AdminView extends JPanel { public AdminView(ArrayList e, ArrayList g, Controller listener) { super(); + this.setLayout(new GridBagLayout()); + this.listener = listener; this.g = g; this.e = e; diff --git a/src/Test/BDatabase.java b/src/Test/BDatabase.java index 970687a..9b093b5 100644 --- a/src/Test/BDatabase.java +++ b/src/Test/BDatabase.java @@ -219,6 +219,19 @@ public class BDatabase { return listGroupe; } + /** + * + * Recuperer le nombre de membre d'un groupe + * + * @param groupe_id le groupes + * @return le nombre de membre + * */ + public int getMemberCount(int groupe_id) { + ArrayList forCount = this.fetchAll( + "SELECT nom FROM fi_eleves WHERE groupe=" + groupe_id); + + return forCount.size(); + } /** * Recuperer l'hote courant. @@ -251,16 +264,4 @@ public class BDatabase { public String toString() { return this.db_host + "\n" + this.db_name + "\n" + this.db_user + "\n"; } - /*** - * Recupere le nombre d'etudiant par groupe - * @return - */ - /*public ArrayList getNbrEtuGroupes() { - ArrayList NGroupe = new ArrayList<>(); - ArrayList groupeNB = this.fetchAll("SELECT COUNT(DISTINCT groupe) FROM fi_eleves;"); - for(int i = 0; i <= NGroupe.Goupe(groupeNB); i++) { - ArrayList grpnb = this.fetchAll("Select count(id) from fi_eleves where groupe="+i+";"); - - } - }*/ } \ No newline at end of file diff --git a/src/Test/BFrame.java b/src/Test/BFrame.java index 9569844..4d10cf0 100644 --- a/src/Test/BFrame.java +++ b/src/Test/BFrame.java @@ -108,7 +108,7 @@ public class BFrame extends JFrame { * @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) { + public BFrame(String title, int loca_x, int loca_y, int size_x, int size_y, JFrame daron, JPanel content) { JDialog frame = new JDialog(daron, title, true); frame.setLocation(loca_x, loca_y); frame.setSize(size_x, size_y); diff --git a/src/Test/Controller.java b/src/Test/Controller.java index 0a146f4..d2de5e7 100644 --- a/src/Test/Controller.java +++ b/src/Test/Controller.java @@ -18,11 +18,11 @@ import java.util.Objects; public class Controller implements ActionListener, ListSelectionListener { private final BDatabase db; - private ProfView pv = null; - private AdminView av = null; + private ProfView pv; + private AdminView av; + private StudentView sv; private BFrame currentModal; - - private MainMenu parent; + private JFrame parent; private ArrayList e; private ArrayList g; @@ -32,17 +32,15 @@ public class Controller implements ActionListener, ListSelectionListener { private ArrayList tmpStud; - public Controller(BDatabase db, MainMenu frame) { + public Controller(BDatabase db) { this.db = db; this.e = this.db.getEtuList(); this.g = this.db.getGroupeList(); - parent = frame; - // Les 3 fenetres s'ouvriront en meme temps (Pour le contexte du projet) - //this.pv = new ProfView(this.e, this.g, this); - //System.out.println("[+] Demarrage de la vue professeur -> " + this.pv); - //this.av = new AdminView(this.e, this.g, this); - //System.out.println("[+] Demarrage de la vue Administrateur -> " + this.av); + this.sv = new StudentView(this.e, this.g, this); + this.pv = new ProfView(this.e, this.g, this); + this.av = new AdminView(this.e, this.g, this); + this.parent = new MainMenu(this); } /** @@ -58,7 +56,6 @@ public class Controller implements ActionListener, ListSelectionListener { }; } - /** * Pour afficher une JTable sans listener * @@ -283,7 +280,7 @@ public class Controller implements ActionListener, ListSelectionListener { } else if(Objects.equals(command, "av::AddStudGrup")) { - ArrayList> data = new ArrayList(); + ArrayList> data = new ArrayList<>(); String[] titre = { "Nom", @@ -433,41 +430,16 @@ public class Controller implements ActionListener, ListSelectionListener { } } - - public JTable initTable() { - Object[][] data = new Object[this.e.size()][3]; - String[] title = { - "Nom", - "Prenom", - "Groupe", - }; - - for(int i = 0; i <= this.e.size()-1; i++) { - Object[] info = { - this.e.get(i).getNom(), - this.e.get(i).getPrenom(), - String.valueOf(this.e.get(i).getGroupe()), - "[DEPLACER]" - }; - - data[i] = info; - } - - return createJTable(data, title); + public ProfView getProfView() { + return this.pv; } - - public void setAv (AdminView av) { - if (this.av == null) { - this.av = av; - } + public StudentView getStudentView() { + return this.sv; } - - public void setPv (ProfView pv) { - if (this.pv == null) { - this.pv = pv; - } + public AdminView getAdminView() { + return this.av; } diff --git a/src/Test/MainMenu.java b/src/Test/MainMenu.java index ee32625..319bfb9 100644 --- a/src/Test/MainMenu.java +++ b/src/Test/MainMenu.java @@ -6,65 +6,58 @@ import java.awt.event.ActionEvent; public class MainMenu extends JFrame { private final static Dimension MINIMUM_SIZE = new Dimension(960, 540); - private CardLayout cards = new CardLayout(); + private CardLayout cards; + private AdminView av; + private StudentView sv; private ProfView pv; - private JTable table; + private BLayout settings; - private JButton[] buttonTab = { - new JButton("Admin"), - new JButton("Prof"), - new JButton("Student") - }; + private final Controller listener; + private JButton[] buttonTab; - public MainMenu() { + public MainMenu(Controller listener) { super(); + + this.av = listener.getAdminView(); + this.pv = listener.getProfView(); + this.sv = listener.getStudentView(); + + this.cards = new CardLayout(); + + this.listener = listener; + + this.buttonTab = new JButton[] { + new JButton("Admin"), + new JButton("Prof"), + new JButton("Student") + }; + this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setExtendedState(MAXIMIZED_BOTH); this.setMinimumSize(MINIMUM_SIZE); - init(); + this.init(); this.setVisible(true); } private void init() { - BDatabase db = new BDatabase(); - Controller listener = new Controller(db, this); - - this.av = new AdminView(listener.getEtudiants(), listener.getGroupes(), listener); - this.pv = new ProfView(listener.getEtudiants(), listener.getGroupes(), listener); - - listener.setAv(av); - listener.setPv(pv); - - this.table = listener.initTable(); - - this.setLayout(cards); + this.setLayout(this.cards); this.add(first()); - this.add(cardWithTable(adminView())); - //this.add(cardWithTable(profView())); + this.add(adminView()); + this.add(profView()); + this.add(studentView()); - cards.first(this.getContentPane()); - } - - - private JPanel cardWithTable(JPanel sidePanel) { - JPanel panel = new JPanel(); - JTable tempTable = this.table; - - panel.setLayout(new GridLayout(1, 2)); - panel.add(sidePanel); - panel.add(tempTable); - - return panel; + this.cards.first(this.getContentPane()); } private JPanel first() { - JPanel mainPanel = new JPanel(), centerPanel = new JPanel(); + JPanel mainPanel = new JPanel(); + JPanel centerPanel = new JPanel(); Dimension buttonDimension = new Dimension(300, 50); mainPanel.setLayout(new BorderLayout()); @@ -90,18 +83,22 @@ public class MainMenu extends JFrame { private JPanel adminView() { - JPanel mainPanel = new JPanel(); - mainPanel.add(av); + JPanel mainPanel = new JPanel(new GridBagLayout()); + mainPanel.add(this.av, this.settings); return mainPanel; } - private JPanel profView() { - JPanel mainPanel = new JPanel(); - mainPanel.add(pv); + JPanel mainPanel = new JPanel(new GridBagLayout()); + mainPanel.add(this.pv, this.settings); return mainPanel; } + private JPanel studentView() { + JPanel mainPanel = new JPanel(new GridBagLayout()); + mainPanel.add(this.sv, this.settings); + return mainPanel; + } private void action(ActionEvent e) { JButton origin = (JButton) e.getSource(); @@ -113,8 +110,13 @@ public class MainMenu extends JFrame { } else if (origin.getText() == "Prof") { cards.next(this.getContentPane()); cards.next(this.getContentPane()); + } else if (origin.getText() == "Student") { + cards.next(this.getContentPane()); + cards.next(this.getContentPane()); + cards.next(this.getContentPane()); + } - } else { + else { JOptionPane.showMessageDialog(null, "En travaux"); } } diff --git a/src/Test/ProfView.java b/src/Test/ProfView.java index 2d8118a..c3f0718 100644 --- a/src/Test/ProfView.java +++ b/src/Test/ProfView.java @@ -8,9 +8,7 @@ import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; -import java.awt.Dimension; -import java.awt.Insets; -import java.awt.GridBagConstraints; +import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.util.ArrayList; @@ -25,6 +23,8 @@ public class ProfView extends JPanel { public ProfView(ArrayList e, ArrayList g, Controller listener) { super(); + this.setLayout(new GridBagLayout()); + this.listener = listener; this.e = e; this.g = g; diff --git a/src/Test/StudentView.java b/src/Test/StudentView.java new file mode 100644 index 0000000..d78fe98 --- /dev/null +++ b/src/Test/StudentView.java @@ -0,0 +1,125 @@ +package Test; + +import API.Etudiant; +import API.Groupe; +import javax.swing.JComboBox; +import javax.swing.JTextField; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import java.awt.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.ArrayList; + +public class StudentView extends JPanel { + private final ArrayList e; + private final ArrayList g; + private final Controller listener; + private JComboBox groupeOption; + private JTextField text; + + public StudentView(ArrayList e, ArrayList g, Controller listener) { + super(); + + this.setLayout(new GridBagLayout()); + + this.listener = listener; + this.e = e; + this.g = g; + + this.Display(); + } + + public String getComboSelection() { + return (String) this.groupeOption.getSelectedItem(); + } + + public String getSearchStud() { + return this.text.getText(); + } + + public int getComboSelectionIndex() { + return this.groupeOption.getSelectedIndex(); + } + + public void Display() { + BLayout settings = new BLayout(); + settings.setPositionX(0); + settings.setPositionY(6); + + settings.setPositionY(0); + JButton studList = new JButton("Voir la liste des etudiants"); + studList.setActionCommand("pv::GetStudList"); + studList.addActionListener(this.listener); + this.add(studList, settings); + + settings.setPositionY(1); + this.add(new JLabel(" "), settings); + + settings.setPositionY(2); + JLabel gs = new JLabel("Afficher les etudiants se trouvant dans le groupe :"); + this.add(gs, settings); + + settings.setPositionY(3); + settings.setPadding(new Insets(0, 0, 0, 50)); + String[] groupeList = new String[this.g.size()]; + + for(int i = 0; i <= this.g.size()-1; i++) { + groupeList[i] = this.g.get(i).getName(); + } + + this.groupeOption = new JComboBox<>(groupeList); + this.groupeOption.setPreferredSize(new Dimension(110, 30)); + this.add(groupeOption, settings); + + settings.setPositionY(3); + settings.setPadding(new Insets(0, 0, 0, 0)); + settings.setAnchor(GridBagConstraints.EAST); + JButton confirm = new JButton("Rechercher"); + confirm.setActionCommand("pv::GetListFiltered"); + confirm.addActionListener(this.listener); + this.add(confirm, settings); + + settings.setAnchor(GridBagConstraints.CENTER); + + settings.setPositionY(4); + this.add(new JLabel(" "), settings); + + settings.setPositionY(5); + JLabel pf = new JLabel("Rechercher un etudiant : "); + this.add(pf, settings); + + settings.setPositionY(6); + settings.setPadding(new Insets(0, 0, 0, 50)); + this.text = new JTextField(); + this.text.setPreferredSize(new Dimension(110, 30)); + text.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent e) { + if (text.getText().length() >= 3 ) + e.consume(); + } + }); + this.add(this.text, settings); + + settings.setPositionY(6); + settings.setPadding(new Insets(0, 0, 0, 0)); + settings.setAnchor(GridBagConstraints.EAST); + JButton searchTLetters = new JButton("Rechercher"); + searchTLetters.addActionListener(this.listener); + searchTLetters.setActionCommand("pv::SearchStudentPer3Letters"); + this.add(searchTLetters, settings); + settings.setAnchor(GridBagConstraints.CENTER); + + settings.setPositionY(7); + this.add(new JLabel(" "), settings); + + settings.setPositionY(8); + JButton changGrp = new JButton("Changer de groupe"); + changGrp.addActionListener(this.listener); + this.add(changGrp, settings); + + this.repaint(); + } +} diff --git a/src/Test/TestTexteMNP.java b/src/Test/TestTexteMNP.java index 2188658..ff6ca8e 100644 --- a/src/Test/TestTexteMNP.java +++ b/src/Test/TestTexteMNP.java @@ -8,12 +8,11 @@ public class TestTexteMNP { /** * Objet de la base de donnee contenant des methodes utile a notre developpement * */ - //BDatabase db = new BDatabase(); + BDatabase db = new BDatabase(); /** * Demarrage de l'appli * */ - //Controller listener = new Controller(db); - new MainMenu(); + Controller listener = new Controller(db); } }