Newer
Older
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
package edu.mermet.tp8.fenetres;
import edu.mermet.tp8.*;
import utilisateur.InfoUtilisateur;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.nio.file.*;
import java.util.*;
import javax.swing.*;
/**
*
* @author Paul LEVRAGUE
*/
public class FrameConfiguration extends AbstractFenetre
{
private static final String[] NOM_BOUTONS = new String[] {"Conversion Celsius/Farenheit", "Saisie de texte", "Diaporama", "Boutons"};
private static final int NB_MENUS = 4;
private Application app;
private ButtonGroup[] tabButtonGroup;
public FrameConfiguration(Action monAction, Application app)
{
super(app, monAction, "Configuration des menus");
this.app = app;
//setModal(true);
JPanel pnlRadioButton = new JPanel();
pnlRadioButton.setLayout(new BoxLayout(pnlRadioButton, BoxLayout.PAGE_AXIS));
//Création des radioButtons en fonction des préférences de l'utilisateurs s'il les a définies
InfoUtilisateur info = InfoUtilisateur.getInstance();
tabButtonGroup = new ButtonGroup[NB_MENUS];
for (int i=0; i<NB_MENUS; i++)
{
JPanel pnlFlow = new JPanel(new FlowLayout());
String btnChoisi = info.getDonnee(NOM_BOUTONS[i]);
JRadioButton autoButton = new JRadioButton("Auto");
autoButton.setActionCommand("Auto");
if (btnChoisi.equals("Auto")) autoButton.setSelected(true);
JRadioButton afficheButton = new JRadioButton("Affiché");
afficheButton.setActionCommand("Affiché");
if (btnChoisi.equals("Affiché")) afficheButton.setSelected(true);
JRadioButton cacheButton = new JRadioButton("Caché");
cacheButton.setActionCommand("Caché");
if (btnChoisi.equals("Caché")) cacheButton.setSelected(true);
tabButtonGroup[i] = new ButtonGroup();
tabButtonGroup[i].add(autoButton);
tabButtonGroup[i].add(afficheButton);
tabButtonGroup[i].add(cacheButton);
pnlFlow.add(new JLabel(NOM_BOUTONS[i]));
pnlFlow.add(autoButton);
pnlFlow.add(afficheButton);
pnlFlow.add(cacheButton);
pnlRadioButton.add(pnlFlow);
}
JPanel pnlBtnBas = new JPanel(new FlowLayout());
JButton btnValider = new JButton("Valider");
JButton btnAnnuler = new JButton("Annuler");
btnValider.addActionListener(new ActionListenerValider());
btnAnnuler.addActionListener(new ActionListenerAnnuler());
pnlBtnBas.add(btnValider);
pnlBtnBas.add(btnAnnuler);
JPanel pnlBorder = new JPanel(new BorderLayout());
pnlBorder.add(pnlRadioButton);
pnlBorder.add(pnlBtnBas, BorderLayout.SOUTH);
add(pnlBorder);
this.setLocationRelativeTo(null);
pack();
}
public void cacherFenetre()
{
app.enableConfiguration(true);
setVisible(false);
}
public class ActionListenerValider implements ActionListener
{
@Override
public void actionPerformed(ActionEvent ae)
{
InfoUtilisateur info = InfoUtilisateur.getInstance();
for (int i=0; i<NB_MENUS; i++)
info.sauvegarde(NOM_BOUTONS[i], tabButtonGroup[i].getSelection().getActionCommand());
cacherFenetre();
app.majApplicationsAffichees();
}
}
public class ActionListenerAnnuler implements ActionListener
{
@Override
public void actionPerformed(ActionEvent ae)
{
cacherFenetre();
}
}
}