This commit is contained in:
2022-11-03 21:34:31 +01:00
parent bca98479f6
commit fcf32a2ec0
5 changed files with 112 additions and 88 deletions

View File

@@ -4,72 +4,39 @@ import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import java.util.LinkedList;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import fr.iutfbleau.projetIHM2022FI2.API.*;
import fr.iutfbleau.projetIHM2022FI2.API.Groupe;
import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.ObservateurFenetre;
public class MaFenetre extends JFrame{
private LinkedList<Groupe> tabGroupe=new LinkedList<Groupe>();
private JPanel Left;
private JPanel Right;
private PaintGroupe paint;
public MaFenetre(){
super();
this.setSize(1000,720);
this.setLocation(200,200);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.getContentPane().setBackground(new Color(230, 230, 255, 255));
this.addWindowListener(new ObservateurFenetre());
this.setLayout(new GridBagLayout());
this.Left=new JPanel();
this.setLayout(new GridLayout(1,2));
this.Left=new JPanel(new GridLayout(2,1));
this.Right=new JPanel();
this.paint=new PaintGroupe();
GridBagConstraints gc=new GridBagConstraints();
gc.gridx=1;
gc.gridy=1;
gc.anchor=GridBagConstraints.CENTER;
gc.gridheight=1;
gc.gridwidth=1;
gc.fill=GridBagConstraints.BOTH;
this.add(this.Left, gc);
gc.gridx=2;
gc.gridy=1;
gc.anchor=GridBagConstraints.CENTER;
gc.gridheight=1;
gc.gridwidth=1;
gc.fill=GridBagConstraints.BOTH;
this.add(this.Right, gc);
this.Left.setBackground(Color.RED);
this.Left.add(this.paint);
this.add(this.Left);
this.Right.setBackground(Color.BLUE);
this.add(this.Right);
}
public void addGroupe(Groupe g){
this.tabGroupe.add(g);
}
public boolean removeGroupe(Groupe g){
int i=this.tabGroupe.indexOf(g);
if(i==-1){
return false;
}else{
this.tabGroupe.remove(i);
}
return true;
}
private void GroupeDraw(){
}
private GridBagConstraints getConstraints(int index){
GridBagConstraints gc=new GridBagConstraints();
gc.gridx=1;
gc.gridy=index;
gc.anchor=GridBagConstraints.BASELINE;
gc.gridheight=1;
gc.gridwidth=1;
gc.insets=null;
gc.fill=GridBagConstraints.HORIZONTAL;
return gc;
this.paint.addGroupe(g);
}
}

View File

@@ -0,0 +1,51 @@
package fr.iutfbleau.projetIHM2022FI2.Graphic.View;
import fr.iutfbleau.projetIHM2022FI2.API.*;
import javax.swing.JComponent;
import java.awt.Graphics;
import java.util.LinkedList;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
public class PaintGroupe extends JComponent {
private LinkedList<Groupe> tabGroupe=new LinkedList<Groupe>();
public PaintGroupe(){}
@Override
protected void paintComponent(Graphics pinceau) {
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
Graphics secondPinceau = pinceau.create();
// obligatoire : si le composant n'est pas censé être transparent
if (this.isOpaque()) {
// obligatoire : on repeint toute la surface avec la couleur de fond
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
// maintenant on dessine ce que l'on veut
secondPinceau.setColor(this.getForeground());
int y=100;
for(Groupe g: this.tabGroupe){
secondPinceau.setColor(Color.BLACK);
secondPinceau.setFont(new Font(Font.SANS_SERIF, Font.BOLD, this.getWidth()/10));
FontMetrics metrics = secondPinceau.getFontMetrics(secondPinceau.getFont());
secondPinceau.drawString(g.getName().toUpperCase(), (this.getWidth()/2-metrics.stringWidth(g.getName().toUpperCase())/2), (y-metrics.getAscent()));
g.getName();
}
}
public void addGroupe(Groupe g){
this.tabGroupe.add(g);
this.repaint();
}
public boolean removeGroupe(Groupe g){
int i=this.tabGroupe.indexOf(g);
if(i==-1){
return false;
}else{
this.tabGroupe.remove(i);
}
this.repaint();
return true;
}
}