This commit is contained in:
martins 2022-11-17 14:45:42 +01:00
parent 3a2dffd61f
commit 3c518bd6d1
3 changed files with 41 additions and 22 deletions

View File

@ -7,13 +7,11 @@ import java.sql.ResultSet;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import javax.swing.tree.*;
import fr.iutfbleau.projetIHM2022FI2.API.AbstractGroupeFactory; import fr.iutfbleau.projetIHM2022FI2.API.AbstractGroupeFactory;
import fr.iutfbleau.projetIHM2022FI2.API.Etudiant; import fr.iutfbleau.projetIHM2022FI2.API.Etudiant;
import fr.iutfbleau.projetIHM2022FI2.API.Groupe; import fr.iutfbleau.projetIHM2022FI2.API.Groupe;
import fr.iutfbleau.projetIHM2022FI2.API.TypeGroupe; import fr.iutfbleau.projetIHM2022FI2.API.TypeGroupe;
import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.ObservateurFenetre; import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.ObservateurFenetre;
import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.TreeSelectionListenerGroupe;
import fr.iutfbleau.projetIHM2022FI2.Graphic.Util.BD; import fr.iutfbleau.projetIHM2022FI2.Graphic.Util.BD;
import fr.iutfbleau.projetIHM2022FI2.Graphic.View.Chargement; import fr.iutfbleau.projetIHM2022FI2.Graphic.View.Chargement;
import fr.iutfbleau.projetIHM2022FI2.Graphic.View.DefaultMutableTreeNodeGroupe; import fr.iutfbleau.projetIHM2022FI2.Graphic.View.DefaultMutableTreeNodeGroupe;
@ -27,6 +25,7 @@ import fr.iutfbleau.projetIHM2022FI2.MNP.GroupeNP;
* Le Model de L'IHM * Le Model de L'IHM
*/ */
public class Model{ public class Model{
private JPanel panGroupe; private JPanel panGroupe;
private FenetreGroupe fenGr; private FenetreGroupe fenGr;
private FenetreEtudiant fenEtu; private FenetreEtudiant fenEtu;
@ -34,6 +33,7 @@ public class Model{
private JFrame fenetre; private JFrame fenetre;
private JTree tree; private JTree tree;
private BD bd; private BD bd;
public Model(){ public Model(){
this.fenetre=new JFrame(); this.fenetre=new JFrame();
this.fenetre.setSize(1200, 720); this.fenetre.setSize(1200, 720);
@ -42,12 +42,12 @@ public class Model{
this.fenetre.setLayout(new GridLayout(1,2)); this.fenetre.setLayout(new GridLayout(1,2));
this.fenetre.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); this.fenetre.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.fenetre.setMinimumSize(this.fenetre.getSize()); this.fenetre.setMinimumSize(this.fenetre.getSize());
this.fenetre.setVisible(true);
this.bd=new BD(this.fenetre); this.bd=new BD(this.fenetre);
Chargement ch=new Chargement(this.fenetre.getSize()); Chargement ch=new Chargement(this.fenetre.getSize());
this.promo=this.getPromo(ch); this.promo=this.getPromo(ch);
ch.dispose(); ch.dispose();
this.fenetre.setVisible(true);
if(this.promo==null){ if(this.promo==null){
this.fenGr=new FenetreGroupe(null, this); this.fenGr=new FenetreGroupe(null, this);
this.fenEtu=new FenetreEtudiant(null, this); this.fenEtu=new FenetreEtudiant(null, this);
@ -56,14 +56,7 @@ public class Model{
this.fenEtu=new FenetreEtudiant(this.promo.getPromotion(), this); this.fenEtu=new FenetreEtudiant(this.promo.getPromotion(), this);
} }
this.panGroupe=new JPanel(new GridLayout(2,1)); this.panGroupe=new JPanel(new GridLayout(2,1));
DefaultMutableTreeNodeGroupe root=new DefaultMutableTreeNodeGroupe(this.promo.getPromotion()); this.initJtree(this.promo.getPromotion());
this.tree=new JTreeGroupe(this, root);
this.tree.setEditable(true);
this.tree.setShowsRootHandles(true);
this.tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
this.tree.addTreeSelectionListener(new TreeSelectionListenerGroupe());
if(this.promo!=null){ if(this.promo!=null){
this.showGroupe(this.promo.getPromotion()); this.showGroupe(this.promo.getPromotion());
}else{ }else{
@ -78,14 +71,15 @@ public class Model{
public void showGroupe(Groupe g){ public void showGroupe(Groupe g){
if(g!=null) if(g!=null)
g=this.bd.refreshALL(g); g=this.bd.refreshALL(g);
//this.initJtree(this.promo.getPromotion());
this.panGroupe.removeAll(); this.panGroupe.removeAll();
this.fenGr=new FenetreGroupe(g, this); this.fenGr=new FenetreGroupe(g, this);
this.fenEtu=new FenetreEtudiant(g, this); this.fenEtu=new FenetreEtudiant(g, this);
this.fenetre.getContentPane().removeAll(); this.fenetre.getContentPane().removeAll();
this.panGroupe.add(this.tree); this.panGroupe.add(this.tree);
this.panGroupe.add(this.fenGr); this.panGroupe.add(this.fenGr);
this.panGroupe.revalidate();
this.fenetre.add(this.panGroupe); this.fenetre.add(this.panGroupe);
JScrollPane scroll=new JScrollPane(this.fenEtu); JScrollPane scroll=new JScrollPane(this.fenEtu);
scroll.getVerticalScrollBar().setUnitIncrement(15); scroll.getVerticalScrollBar().setUnitIncrement(15);
@ -316,11 +310,6 @@ public class Model{
} }
} }
private void setTree(DefaultMutableTreeNode mut, Groupe g){
}
public boolean deleteEtu(Etudiant e){ public boolean deleteEtu(Etudiant e){
if(this.deleteEtutoChildren(e, this.fenGr.getG())){ if(this.deleteEtutoChildren(e, this.fenGr.getG())){
this.bd.deleteEtu(e, this.fenGr.getG()); this.bd.deleteEtu(e, this.fenGr.getG());
@ -341,4 +330,29 @@ public class Model{
} }
return true; return true;
} }
private void initJtree(Groupe g){
DefaultMutableTreeNodeGroupe mut;
if(g!=null){
mut=new DefaultMutableTreeNodeGroupe(g, g.getName());
for(Groupe sous:g.getSousGroupes()){
this.treeRecursif(sous, mut);
}
}else{
mut=new DefaultMutableTreeNodeGroupe(g, null);
}
this.tree=new JTreeGroupe(this, mut);
}
private void treeRecursif(Groupe g, DefaultMutableTreeNodeGroupe m){
DefaultMutableTreeNodeGroupe mut=new DefaultMutableTreeNodeGroupe(g, g.getName());
m.add(mut);
for(Groupe sous: g.getSousGroupes()){
this.treeRecursif(sous, mut);
}
}
private void refreshTree(Groupe g){
}
} }

View File

@ -5,8 +5,8 @@ import javax.swing.tree.DefaultMutableTreeNode;
import fr.iutfbleau.projetIHM2022FI2.API.Groupe; import fr.iutfbleau.projetIHM2022FI2.API.Groupe;
public class DefaultMutableTreeNodeGroupe extends DefaultMutableTreeNode{ public class DefaultMutableTreeNodeGroupe extends DefaultMutableTreeNode{
private Groupe groupe; private Groupe groupe;
public DefaultMutableTreeNodeGroupe(Groupe g){ public DefaultMutableTreeNodeGroupe(Groupe g, String path){
super(g.getName()); super(path);
this.groupe=g; this.groupe=g;
} }

View File

@ -1,7 +1,6 @@
package fr.iutfbleau.projetIHM2022FI2.Graphic.View; package fr.iutfbleau.projetIHM2022FI2.Graphic.View;
import javax.swing.JTree; import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeSelectionModel;
import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener; import javax.swing.event.TreeSelectionListener;
import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.TreeSelectionEventGroupe; import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.TreeSelectionEventGroupe;
@ -13,6 +12,12 @@ public class JTreeGroupe extends JTree{
public JTreeGroupe(Model m, DefaultMutableTreeNodeGroupe mut){ public JTreeGroupe(Model m, DefaultMutableTreeNodeGroupe mut){
super(mut); super(mut);
this.model=m; this.model=m;
this.setEditable(true);
this.setShowsRootHandles(true);
this.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
this.addTreeSelectionListener(new TreeSelectionListenerGroupe());
this.setRowHeight(15);
} }
@Override @Override
protected void fireValueChanged(TreeSelectionEvent e) { protected void fireValueChanged(TreeSelectionEvent e) {