/* * * Component.java * * Created on 21 avril 2007, 15:47 * * Permet la création d'un composant dans l'IHM * Etend javax.swing.JPanel pour créer un panel "composant" */ package graphique; import java.awt.image.ImageObserver; import java.awt.image.ImageProducer; import java.text.AttributedCharacterIterator; import org.eclipse.swt.layout.FillLayout; import simulateur.*; import javax.swing.*; import java.awt.*; import org.eclipse.swt.*; import java.lang.Math; /** * * @author maxence */ public class Component extends javax.swing.JPanel { private GATE m_gate; //La porte private int m_nb_input; //Le nombre d'entrée du composant /** Creates a new instance of Component */ public Component(String comp,int nb_input) { super(); //Création de la porte if (comp == "and"){ m_gate = new AND_GATE(); } else if (comp == "or"){ m_gate = new OR_GATE(); } else if (comp == "nand"){ m_gate = new NAND_GATE(); } else if (comp == "not"){ m_gate = new NOT_GATE(); } else { m_gate = null; } m_nb_input = nb_input; create_panel(); doLayout(); } /** * create_panel : crée le panel pour le composant */ private void create_panel(){ //Taille du panel this.setLayout(null); setPreferredSize(new Dimension (70,40)); // this.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); this.setBackground(new Color (255,50,25)); // this.setLocation(60,60); setOpaque(true); //1) Ajout de l'image du composant //2) Ajout des entrées/sorties //On dessine des boutons pour chaque entrée / sortie //La sortie JLabel output = new JLabel(""); output.setSize(6,6); output.setBackground(new Color(255,51,51)); output.setForeground(new Color(15,15,155)); output.setOpaque(true); output.setLocation(this.getPreferredSize().width-6,java.lang.Math.round(getPreferredSize().height/2)-3); //Les entrées //Si il y a une seule entrée, on la place au milieu, sinon à 1/3 JLabel input1 = new JLabel(""); input1.setSize(6,6); input1.setBackground(new Color(255,51,51)); input1.setForeground(new Color(15,15,155)); input1.setOpaque(true); if (m_nb_input == 1){ input1.setLocation(0,java.lang.Math.round(getPreferredSize().height/2)-3); } else { //On rajoute la deuxième entrée input1.setLocation(0,java.lang.Math.round(getPreferredSize().height/3)-3); JLabel input2 = new JLabel(""); input2.setSize(6,6); input2.setBackground(new Color(255,51,51)); input2.setForeground(new Color(15,15,155)); input2.setOpaque(true); input1.setLocation(0,java.lang.Math.round(2*getPreferredSize().height/3)-3); add(input2); } //add(new JButton("prout")); add(input1); add(output); // this.add("North", new Button(" bouton haut ")); //this.add("South", new Button(" bouton bas ")); //this.add("West", new Button(" bouton gauche ")); //this.add("East", new Button(" bouton droite ")); //this.add("Center", new Button(" bouton milieu ")); } }