Files
FIprojetIHM2022/src/fr/iutfbleau/projetIHM2022FI2/MP/ETU/View/FenetreGroupe.java

133 lines
4.2 KiB
Java
Raw Normal View History

2022-12-08 11:00:41 +01:00
package fr.iutfbleau.projetIHM2022FI2.MP.ETU.View;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
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.API.Model;
import fr.iutfbleau.projetIHM2022FI2.Permanent.Controller.ObservateurChangeGroupe;
import java.util.Set;
import java.awt.Color;
/**
* Affichage d'un groupe
*
*/
public class FenetreGroupe{
// le groupe affiché
private Groupe g;
// le panel d'affichage
private JPanel pan;
// le modèle
private Model m;
// liste des sous groupes
private Set<Groupe> appartient;
/**
* Constructeur de l'affichage d'un groupe
* @param g le groupe à afficher
* @param m le model
* @param appartient la liste des sous groupes
*
*/
public FenetreGroupe(Groupe g, Model m, Set<Groupe> appartient){
super();
this.g=g;
this.appartient=appartient;
this.m=m;
this.pan=new JPanel();
this.draw();
}
/**
* permet de récupérer le groupe affiché
* @return le groupe affiché
*/
public Groupe getG() {
return this.g;
}
/**
* rafraichit l'affichage du groupe
*/
public void refresh(){
this.pan.removeAll();
this.draw();
this.pan.revalidate();
}
/**
* gère l'affichage du groupe
*/
private void draw(){
if(g!=null){
int taille=1;
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, g.getPointPoint()));
tache.add(bout);
}
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));
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());
boolean contenu=false;
for(Groupe t: this.appartient){
if(t.getId()==gr.getId()){
contenu=true;
break;
}
}
if(contenu){
b.addActionListener(new ObservateurChangeGroupe(m, gr));
}else{
b.setBackground(Color.RED);
}
sous.add(b);
}
this.pan.add(new JScrollPane(sous));
}
}
}
/**
* permet de modifier le groupe affiché
* @param g le nouveau groupe à afficher
*/
public void setG(Groupe g) {
this.g = g;
}
/**
* permet de modifier la liste des sous groupes
* @param appartient la nouvelle liste des sous groupes
*/
public void setAppartient(Set<Groupe> appartient) {
this.appartient = appartient;
}
/**
* Permet de récupérer le panel d'affichage.
* @return le panel d'affichage
*/
public JPanel getPan() {
return pan;
}
}