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 java.awt.*;
import javax.swing.tree.*;
import fr.iutfbleau.projetIHM2022FI2.API.AbstractGroupeFactory;
import fr.iutfbleau.projetIHM2022FI2.API.Etudiant;
import fr.iutfbleau.projetIHM2022FI2.API.Groupe;
import fr.iutfbleau.projetIHM2022FI2.API.TypeGroupe;
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.View.Chargement;
import fr.iutfbleau.projetIHM2022FI2.Graphic.View.DefaultMutableTreeNodeGroupe;
@ -27,6 +25,7 @@ import fr.iutfbleau.projetIHM2022FI2.MNP.GroupeNP;
* Le Model de L'IHM
*/
public class Model{
private JPanel panGroupe;
private FenetreGroupe fenGr;
private FenetreEtudiant fenEtu;
@ -34,6 +33,7 @@ public class Model{
private JFrame fenetre;
private JTree tree;
private BD bd;
public Model(){
this.fenetre=new JFrame();
this.fenetre.setSize(1200, 720);
@ -42,12 +42,12 @@ public class Model{
this.fenetre.setLayout(new GridLayout(1,2));
this.fenetre.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.fenetre.setMinimumSize(this.fenetre.getSize());
this.fenetre.setVisible(true);
this.bd=new BD(this.fenetre);
Chargement ch=new Chargement(this.fenetre.getSize());
this.promo=this.getPromo(ch);
ch.dispose();
this.fenetre.setVisible(true);
if(this.promo==null){
this.fenGr=new FenetreGroupe(null, this);
this.fenEtu=new FenetreEtudiant(null, this);
@ -56,14 +56,7 @@ public class Model{
this.fenEtu=new FenetreEtudiant(this.promo.getPromotion(), this);
}
this.panGroupe=new JPanel(new GridLayout(2,1));
DefaultMutableTreeNodeGroupe root=new DefaultMutableTreeNodeGroupe(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());
this.initJtree(this.promo.getPromotion());
if(this.promo!=null){
this.showGroupe(this.promo.getPromotion());
}else{
@ -79,13 +72,14 @@ public class Model{
if(g!=null)
g=this.bd.refreshALL(g);
//this.initJtree(this.promo.getPromotion());
this.panGroupe.removeAll();
this.fenGr=new FenetreGroupe(g, this);
this.fenEtu=new FenetreEtudiant(g, this);
this.fenetre.getContentPane().removeAll();
this.panGroupe.add(this.tree);
this.panGroupe.add(this.fenGr);
this.panGroupe.revalidate();
this.fenetre.add(this.panGroupe);
JScrollPane scroll=new JScrollPane(this.fenEtu);
scroll.getVerticalScrollBar().setUnitIncrement(15);
@ -316,11 +310,6 @@ public class Model{
}
}
private void setTree(DefaultMutableTreeNode mut, Groupe g){
}
public boolean deleteEtu(Etudiant e){
if(this.deleteEtutoChildren(e, this.fenGr.getG())){
this.bd.deleteEtu(e, this.fenGr.getG());
@ -341,4 +330,29 @@ public class Model{
}
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;
public class DefaultMutableTreeNodeGroupe extends DefaultMutableTreeNode{
private Groupe groupe;
public DefaultMutableTreeNodeGroupe(Groupe g){
super(g.getName());
public DefaultMutableTreeNodeGroupe(Groupe g, String path){
super(path);
this.groupe=g;
}

View File

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