Files
FIprojetIHM2022/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/Graphic/View/FenetreGroupe.java

90 lines
3.5 KiB
Java
Raw Normal View History

package fr.iutfbleau.projetIHM2022FI2.Graphic.View;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
2022-11-14 22:57:17 +01:00
import javax.swing.JScrollPane;
import java.awt.Font;
import java.awt.GridLayout;
import fr.iutfbleau.projetIHM2022FI2.API.Groupe;
import fr.iutfbleau.projetIHM2022FI2.API.TypeGroupe;
import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.ObservateurChangeGroupe;
import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.ObservateurModifGroupe;
2022-11-15 15:08:13 +01:00
import fr.iutfbleau.projetIHM2022FI2.Graphic.Model.Model;
public class FenetreGroupe extends JPanel{
private Groupe g;
private Model m;
public FenetreGroupe(Groupe g, Model m){
2022-11-13 15:46:15 +01:00
super();
this.g=g;
this.m=m;
this.draw();
}
public Groupe getG() {
return this.g;
}
public void refresh(){
this.removeAll();
this.draw();
this.revalidate();
}
private void draw(){
2022-11-13 15:46:15 +01:00
if(g!=null){
2022-11-14 22:57:17 +01:00
int taille=5;
if(g.getType()==TypeGroupe.PARTITION || g.getType()==TypeGroupe.ROOT)
taille--;
if(g.getSousGroupes().size()>0)
this.setLayout(new GridLayout(8, 1));
else{this.setLayout(new GridLayout(7, 1));}
JPanel tache=new JPanel(new GridLayout(1,taille));
if(g.getType()!=TypeGroupe.ROOT){
2022-11-16 14:59:56 +01:00
JButton bout=new JButton(g.getPointPoint().getName());
2022-11-14 22:57:17 +01:00
bout.addActionListener(new ObservateurChangeGroupe(m, this.g.getPointPoint()));
tache.add(bout);
2022-11-13 15:46:15 +01:00
}
2022-11-14 22:57:17 +01:00
JButton renomer=new JButton("rename");
renomer.addActionListener(new ObservateurModifGroupe(m, g));
tache.add(renomer);
JButton ajouter=new JButton("add");
ajouter.addActionListener(new ObservateurModifGroupe(m, g));
tache.add(ajouter);
JButton supprimer=new JButton("supr");
supprimer.addActionListener(new ObservateurModifGroupe(m, g));
2022-11-14 22:57:17 +01:00
tache.add(supprimer);
if(g.getType()!=TypeGroupe.PARTITION){
2022-11-14 22:57:17 +01:00
JButton creer=new JButton("new Groupe");
creer.addActionListener(new ObservateurModifGroupe(m, g));
2022-11-14 22:57:17 +01:00
tache.add(creer);
}
2022-11-14 22:57:17 +01:00
this.add(tache);
JLabel titre=new JLabel("Group : "+g.getName(), JLabel.CENTER);
titre.setFont(new Font(Font.SERIF, Font.BOLD, titre.getFont().getSize()+10));
this.add(titre);
this.add(new JLabel("id= "+String.valueOf(g.getId()),JLabel.CENTER));
this.add(new JLabel("min= "+String.valueOf(g.getMin()),JLabel.CENTER));
this.add(new JLabel("max= "+String.valueOf(g.getMax()),JLabel.CENTER));
this.add(new JLabel(g.getType().name(), JLabel.CENTER));
this.add(new JLabel("Sous groupe:",JLabel.CENTER));
if(g.getSousGroupes().size()>0){
JPanel sous=new JPanel(new GridLayout(g.getSousGroupes().size(), 1));
for(Groupe gr: g.getSousGroupes()){
JButton b=new JButton(gr.getName());
b.addActionListener(new ObservateurChangeGroupe(m, gr));
sous.add(b);
}
this.add(new JScrollPane(sous));
}
2022-11-13 15:46:15 +01:00
}else{
2022-11-15 15:08:13 +01:00
JButton creer=new JButton("créer une promo");
creer.addActionListener(new ObservateurModifGroupe(m, g));
this.add(creer);
}
}
2022-11-15 15:08:13 +01:00
public void setG(Groupe g) {
this.g = g;
}
}