1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
| package modèle.config;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import modèle.Initialisation;
import modèle.Var;
import vue.Main_35;
import vue.MyWindow;
public class Fenetre_config extends JFrame {
//---- MES DECLARATIONS -----------------
// Mes objets "Panels"
private JPanel contentpane = new JPanel(); // ContentPane
private String id = "";
//-----CONSTRUCTEUR -----//
public Fenetre_config (String string) {
super ();
this.setTitle("configuration de : " + string);
this.isAlwaysOnTop();
this.setSize( new Dimension (500,600));
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.setVisible(true);
contentpane.setLayout(null);
this.setContentPane(contentpane);
this.id = string;
// Aiguillage du contenu selon le choix de l'item
if (id == "éditeur") {
contentpane.add(creer_panel(1, "Couleur du fond : ", Var.clr1_fond_G1));
contentpane.add(creer_panel(2, "Couleur des emplacements : ", Var.clr1_recept));
}
else if (id == "composant") {
contentpane.add(creer_panel(1, "Couleur du composant : ", Var.fond1_Composant));
}
else if (id == "fil") {
contentpane.add(creer_panel(1, "couleur du numéro de fil :", Var.clr1_num_de_fil));
}
this.repaint();
}// FIN DU CONSTRUCTEUR
private JPanel creer_panel(int i, String str_1, Color color1) {
// mon objet label "titre"
JLabel lbl_1 = new JLabel (str_1, SwingConstants.RIGHT);
lbl_1.setFont(new Font ("sherif", Font.BOLD, 20));
lbl_1.setForeground(Color.red);;
lbl_1.setSize(300, 50);
lbl_1.setLocation(0, 0);
// mon objet label "visuel"
JLabel lbl_2 = new JLabel();
lbl_2.setBackground(color1);
lbl_2.setOpaque(true);
lbl_2.setBorder(BorderFactory.createLineBorder(Color.black, 1));
lbl_2.setSize(70, 70);
lbl_2.setLocation(340, 20);
// mon objet "bouton_1"
JButton btn_1 = new JButton ("choisir :");
btn_1.setSize(150,40);
btn_1.setLocation(10, 50);
btn_1.setName(String.valueOf(i));
btn_1.addActionListener(new ActionListener() {
@Override // je modifie une valeur
public void actionPerformed(ActionEvent e) {
//------------------------------------------------------------------------------
if (id=="éditeur") {
// si changement du fond d'écran
if (btn_1.getName().equals("1")) {
Var.clr1_fond_G1 = JColorChooser.showDialog(null, "choisissez une couleur de fond", Var.clr1_fond_G1);
MyWindow.contentpane.setBackground(Var.clr1_fond_G1);
lbl_2.setBackground(Var.clr1_fond_G1);
}
// si changement recept
else if (btn_1.getName().equals("2")) {
Var.clr1_recept = JColorChooser.showDialog(null, "choisissez une couleur des emplacements", Var.clr1_recept);
lbl_2.setBackground(Var.clr1_recept);
}
// enregistrement de l'éditeur
enreg_éditeur();
} // fin du choix "éditeur" ================================================
//------------------------------------------------------------------------------
if (id=="composant") {
// si changement du fond de composant
if (btn_1.getName().equals("1")) {
Var.fond1_Composant = JColorChooser.showDialog(null, "choisissez une couleur de fond", Var.fond1_Composant);
lbl_2.setBackground(Var.fond1_Composant);
}
// j'enregistre la liste suite à la modif
ArrayList<Color> liste = new ArrayList<Color>();
liste.add(0, Var.fond1_Composant);
try {
Initialisation.enregistrer(Initialisation.cfg_composant_name, liste);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
} // fin du choix "composant" ================================================
//------------------------------------------------------------------------------
if (id=="fil") {
// si changement du numéro de fil
if (btn_1.getName().equals("1")) {
Var.clr1_num_de_fil = JColorChooser.showDialog(null, "choisissez une couleur de fond", Var.clr1_num_de_fil);
lbl_2.setBackground(Var.clr1_num_de_fil);
}
// j'enregistre la liste suite à la modif
ArrayList<Color> liste = new ArrayList<Color>();
liste.add(0, Var.clr1_num_de_fil);
try {
Initialisation.enregistrer(Initialisation.cfg_fil_name, liste);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
} // fin du choix "composant" ================================================
} // fin de ActionPerformed
}); // fin du listener bouton_1
JButton btn_2 = new JButton ("Ré_initialiser");
btn_2.setName(String.valueOf(i));
btn_2.setSize(btn_1.getSize());
btn_2.setLocation(170, 50);
btn_2.addActionListener(new ActionListener() {
@Override // je remet la valeur à valeur_0
public void actionPerformed(ActionEvent e) {
//------------------------------------------------------------------------------
if (id=="éditeur") {
// si re_initialisation du fond d'écran
if (btn_2.getName().equals("1")) {
Var.clr1_fond_G1 = Var.clr0_fond_G1;
MyWindow.contentpane.setBackground(Var.clr1_fond_G1);
lbl_2.setBackground(Var.clr0_fond_G1);
}
// si ré_initialisation de la couleur des recepts
else if (btn_2.getName().equals("2")) {
Var.clr1_recept = Var.clr0_recept;
lbl_2.setBackground(Var.clr1_recept);
}
// enregistrement de l'éditeur
enreg_éditeur();
} // fin de ré_init éditeur=============================================
//------------------------------------------------------------------------------
if (id=="composant") {
// si re_initialisation du composant
if (btn_2.getName().equals("1")) {
Var.fond1_Composant = Var.fond0_Composant;
lbl_2.setBackground(Var.fond0_Composant);
}
// enregistrement de l'éditeur
enreg_composant();
} // fin de ré_init éditeur=============================================
//------------------------------------------------------------------------------
if (id=="fil") {
// si re_initialisation couleur numéro de fil
if (btn_2.getName().equals("1")) {
Var.clr1_num_de_fil = Var.clr0_num_de_fil;
lbl_2.setBackground(Var.clr1_num_de_fil);
}
// enregistrement de l'éditeur
enreg_fil();
} // fin de ré_init éditeur=============================================
} // fin actionPerformed btn_2
}); // fin actionListener btn_2
// mon panel
JPanel pnl_1 = new JPanel();
pnl_1.setSize(getWidth(),100);
pnl_1.setLocation(0, (i-1)*100);
pnl_1.setLayout(null);
pnl_1.add(lbl_1);
pnl_1.add(btn_1);
pnl_1.add(btn_2);
pnl_1.add(lbl_2);
MyWindow.contentpane.repaint();
return pnl_1;
}
// enregistrement du fichier "éditeur.sys"
private void enreg_éditeur() {
ArrayList<Color> liste = new ArrayList<Color>();
liste.add(0, Var.clr1_fond_G1);
liste.add(1, Var.clr1_recept);
try {
Initialisation.enregistrer(Initialisation.cfg_éditeur_name, liste);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
} // ==========================================
// enregistrement du fichier "composant.sys"
private void enreg_composant() {
ArrayList<Color> liste = new ArrayList<Color>();
liste.add(0, Var.fond0_Composant);
try {
Initialisation.enregistrer(Initialisation.cfg_composant_name, liste);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
} // ===================================================
// enregistrement du fichier "fil.sys"
private void enreg_fil() {
ArrayList<Color> liste = new ArrayList<Color>();
liste.add(0, Var.clr1_num_de_fil);
try {
Initialisation.enregistrer(Initialisation.cfg_fil_name, liste);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
} // ===================================================
} // ============== fin de la classe Fenetre_config ================================ |
Partager