102 lines
3.9 KiB
Java
102 lines
3.9 KiB
Java
package fr.iutfbleau.projetIHM2022FI2.ROOT.View;
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JScrollPane;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.Font;
|
|
import java.awt.GridLayout;
|
|
import fr.iutfbleau.projetIHM2022FI2.API.Groupe;
|
|
import fr.iutfbleau.projetIHM2022FI2.API.TypeGroupe;
|
|
import fr.iutfbleau.projetIHM2022FI2.Permanent.Controller.ObservateurChangeGroupe;
|
|
import fr.iutfbleau.projetIHM2022FI2.ROOT.Controller.ObservateurModifGroupe;
|
|
import fr.iutfbleau.projetIHM2022FI2.API.Model;
|
|
|
|
|
|
public class FenetreGroupe{
|
|
private Groupe g;
|
|
private JPanel pan;
|
|
private Model m;
|
|
public FenetreGroupe(Groupe g, Model m){
|
|
super();
|
|
this.g=g;
|
|
this.m=m;
|
|
this.pan=new JPanel();
|
|
this.draw();
|
|
}
|
|
public Groupe getG() {
|
|
return this.g;
|
|
}
|
|
public void refresh(){
|
|
this.pan.removeAll();
|
|
this.draw();
|
|
this.pan.revalidate();
|
|
}
|
|
private void draw(){
|
|
if(g!=null){
|
|
int taille=5;
|
|
if(g.getType()==TypeGroupe.PARTITION || g.getType()==TypeGroupe.ROOT)
|
|
taille--;
|
|
if(g.getSousGroupes().size()>0)
|
|
this.pan.setLayout(new GridLayout(7, 1));
|
|
else{this.pan.setLayout(new GridLayout(6, 1));}
|
|
JPanel tache=new JPanel(new GridLayout(1,taille));
|
|
if(g.getType()!=TypeGroupe.ROOT){
|
|
JButton bout=new JButton(g.getPointPoint().getName());
|
|
bout.addActionListener(new ObservateurChangeGroupe(m, this.g.getPointPoint()));
|
|
tache.add(bout);
|
|
}
|
|
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));
|
|
supprimer.setBackground(Color.RED);
|
|
tache.add(supprimer);
|
|
if(g.getType()!=TypeGroupe.PARTITION){
|
|
JButton creer=new JButton("new Groupe");
|
|
creer.addActionListener(new ObservateurModifGroupe(m, g));
|
|
tache.add(creer);
|
|
}
|
|
this.pan.add(tache);
|
|
JLabel titre=new JLabel("Groupe : "+g.getName(), JLabel.CENTER);
|
|
titre.setFont(new Font(Font.SERIF, Font.BOLD, titre.getFont().getSize()+10));
|
|
this.pan.add(titre);
|
|
this.pan.add(new JLabel("min= "+String.valueOf(g.getMin())+"\t || \t max= "+String.valueOf(g.getMax()),JLabel.CENTER));
|
|
JButton refresh= new JButton("Resfresh");
|
|
refresh.addActionListener(new ObservateurChangeGroupe(m, g));
|
|
refresh.setBackground(Color.BLACK);
|
|
refresh.setForeground(Color.WHITE);
|
|
this.pan.add(refresh);
|
|
this.pan.add(new JLabel("Type: "+g.getType().name()+"\t || \t id="+String.valueOf(g.getId()), JLabel.CENTER));
|
|
this.pan.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.pan.add(new JScrollPane(sous));
|
|
}
|
|
}else{
|
|
JButton creer=new JButton("créer une promo");
|
|
creer.addActionListener(new ObservateurModifGroupe(m, g));
|
|
this.pan.add(creer);
|
|
}
|
|
}
|
|
|
|
public void setG(Groupe g) {
|
|
this.g = g;
|
|
}
|
|
|
|
public JPanel getPan() {
|
|
return pan;
|
|
}
|
|
}
|