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 package com.drazzib.netpisteur.ui;
27
28 import java.awt.BorderLayout;
29 import java.awt.Font;
30 import java.awt.GridLayout;
31 import java.awt.event.MouseAdapter;
32 import java.awt.event.MouseEvent;
33
34 import javax.swing.JButton;
35 import javax.swing.JFrame;
36 import javax.swing.JLabel;
37 import javax.swing.JOptionPane;
38 import javax.swing.JPanel;
39 import javax.swing.JPasswordField;
40 import javax.swing.JTextField;
41
42 import com.drazzib.netpisteur.configuration.ListUtilisateurs;
43 import com.drazzib.netpisteur.configuration.Utilisateur;
44 import com.drazzib.netpisteur.util.Messages;
45
46 public class CreateTestorFrame extends JFrame {
47
48 private static final long serialVersionUID = -1634246603370843049L;
49
50 private JPanel panelAll, panelNorth, panelWest, panelEast, panelSouth,
51 panelCenter, creationPanel, boutonPanel, createPanel;
52
53 private JLabel createLabel, createNomLabel, createPrenomLabel,
54 createPasswdLabel, expliCreateLabel, confirmeMotDePasseSaisieLabel;
55
56 private JPasswordField confirmeMotDePasseSaisieText, createPasswdField;
57
58 private JTextField createNomTextField, createPrenomTextField;
59
60 private JButton okBouton, annulerBouton;
61
62 private ConfigFrame myConfig;
63
64 /** Creates new form Config */
65 public CreateTestorFrame(ConfigFrame pConfig) {
66 this.myConfig = pConfig;
67 initComponents();
68 }
69
70
71
72
73 private void initComponents() {
74
75
76 this.panelAll = new JPanel(new BorderLayout());
77 this.panelNorth = new JPanel();
78 this.panelWest = new JPanel();
79 this.panelEast = new JPanel();
80 this.panelSouth = new JPanel();
81 this.panelCenter = new JPanel(new BorderLayout());
82
83
84 this.boutonPanel = new JPanel();
85
86 this.creationPanel = new JPanel();
87
88
89 this.createPanel = new JPanel(new GridLayout(5, 2));
90
91
92 this.createLabel = new JLabel();
93 this.expliCreateLabel = new JLabel();
94 this.createNomLabel = new JLabel();
95 this.createPrenomLabel = new JLabel();
96 this.createPasswdLabel = new JLabel();
97 this.confirmeMotDePasseSaisieLabel = new JLabel();
98 this.confirmeMotDePasseSaisieText = new JPasswordField();
99
100 this.createNomTextField = new JTextField();
101 this.createPrenomTextField = new JTextField();
102 this.createPasswdField = new JPasswordField();
103
104
105 Font titre = new Font("Arial", Font.BOLD, 15);
106
107
108
109
110 this.creationPanel.setLayout(new GridLayout(7, 2));
111 this.boutonPanel.setLayout(new GridLayout(1, 2));
112
113
114 this.createLabel.setText(Messages
115 .getString("CreationTesteur.CREATE_TESTER"));
116 this.createLabel.setFont(titre);
117
118 this.creationPanel.add(this.createLabel);
119
120 this.creationPanel.add(new JLabel());
121
122 this.creationPanel.add(this.expliCreateLabel);
123 this.creationPanel.add(new JLabel());
124
125 this.createNomLabel.setText(Messages.getString("CreationTesteur.NAME"));
126
127 this.createPrenomLabel.setText(Messages
128 .getString("CreationTesteur.FIRST_NAME"));
129
130 this.createPasswdLabel.setText(Messages
131 .getString("CreationTesteur.PASSWORD"));
132
133
134 this.confirmeMotDePasseSaisieLabel.setText(Messages
135 .getString("CreationTesteur.CONFIRM_PASSWORD"));
136
137
138 this.creationPanel.add(this.createNomLabel);
139 this.creationPanel.add(this.createNomTextField);
140 this.creationPanel.add(this.createPrenomLabel);
141 this.creationPanel.add(this.createPrenomTextField);
142 this.creationPanel.add(this.createPasswdLabel);
143 this.creationPanel.add(this.createPasswdField);
144 this.creationPanel.add(this.confirmeMotDePasseSaisieLabel);
145 this.creationPanel.add(this.confirmeMotDePasseSaisieText);
146
147 this.creationPanel.add(this.createPanel);
148 this.creationPanel.add(new JLabel());
149
150
151
152
153 this.boutonPanel = new JPanel();
154
155 this.okBouton = new JButton();
156 this.annulerBouton = new JButton();
157
158
159 this.okBouton.setText(Messages.getString("CreationTesteur.OK"));
160
161 this.okBouton.addMouseListener(new MouseAdapter() {
162 public void mouseReleased(MouseEvent evt) {
163 okBoutonMouseReleased(evt);
164 }
165 });
166
167
168
169 this.annulerBouton
170 .setText(Messages.getString("CreationTesteur.CANCEL"));
171
172 this.annulerBouton.addMouseListener(new MouseAdapter() {
173 public void mouseReleased(MouseEvent evt) {
174 annulerBoutonMouseReleased(evt);
175
176 }
177 });
178
179
180
181 this.boutonPanel.add(this.okBouton);
182 this.boutonPanel.add(this.annulerBouton);
183
184
185
186
187 setTitle(Messages.getString("CreationTesteur.CREATE_TESTER_TITLE"));
188
189
190 this.panelCenter.add(this.creationPanel, BorderLayout.CENTER);
191 this.panelCenter.add(this.boutonPanel, BorderLayout.SOUTH);
192 this.panelAll.add(this.panelNorth, BorderLayout.NORTH);
193 this.panelAll.add(this.panelWest, BorderLayout.WEST);
194 this.panelAll.add(this.panelEast, BorderLayout.EAST);
195 this.panelAll.add(this.panelSouth, BorderLayout.SOUTH);
196 this.panelAll.add(this.panelCenter, BorderLayout.CENTER);
197 getContentPane().add(this.panelAll);
198
199 pack();
200
201 }
202
203
204
205
206 void annulerBoutonMouseReleased(java.awt.event.MouseEvent evt) {
207 this.dispose();
208
209 }
210
211 /**
212 * Lorsque l'on appui sur le bouton ok, la frame se ferme en enregistrant
213 * les nouveaux parametres Des vrification sont faites pour valider
214 * l'action : vrification que les cases ne sont pas vide vrification que
215 * le testeur n'existe pas dj
216 *
217 */
218 void okBoutonMouseReleased(MouseEvent evt) {
219 Utilisateur lUtilisateur;
220 String nomUtilisateur;
221 String prenomUtilisateur;
222 String motDePasseSaisie;
223
224 nomUtilisateur = this.createNomTextField.getText();
225 prenomUtilisateur = this.createPrenomTextField.getText();
226 motDePasseSaisie = new String(this.createPasswdField.getPassword());
227 lUtilisateur = new Utilisateur(nomUtilisateur, prenomUtilisateur,
228 motDePasseSaisie, " ", " ");
229
230 if (nomUtilisateur.equals("") || prenomUtilisateur.equals("")) {
231 JOptionPane
232 .showMessageDialog(
233 null,
234 Messages
235 .getString("CreationTesteur.ENTER_ALL_PARAMETERS"), Messages.getString("CreationTesteur.ERROR"),
236 JOptionPane.ERROR_MESSAGE);
237
238 } else {
239 if (motDePasseSaisie.equals("")) {
240 JOptionPane
241 .showMessageDialog(
242 null,
243 Messages
244 .getString("CreationTesteur.ENTER_PASSWORD"),
245 Messages.getString("CreationTesteur.ERROR"), JOptionPane.ERROR_MESSAGE);
246
247 } else {
248 if (checkPasswords() == false) {
249 JOptionPane
250 .showMessageDialog(
251 null,
252 Messages
253 .getString("CreationTesteur.ENTER_CONFIRM_PASSWORD"), Messages.getString("CreationTesteur.ERROR"),
254 JOptionPane.ERROR_MESSAGE);
255 } else {
256 if (checkUserExist() == true) {
257 JOptionPane
258 .showMessageDialog(
259 null,
260 Messages
261 .getString("CreationTesteur.SAME_USER"), Messages.getString("CreationTesteur.ERROR"),
262 JOptionPane.ERROR_MESSAGE);
263 } else {
264
265 JOptionPane
266 .showMessageDialog(
267 null,
268 Messages
269 .getString("CreationTesteur.OK_ADD_USER"), Messages.getString("CreationTesteur.ADD"),
270 JOptionPane.INFORMATION_MESSAGE);
271 ListUtilisateurs.add(lUtilisateur);
272
273 this.myConfig.setFields(this.createNomTextField
274 .getText(), this.createPrenomTextField
275 .getText());
276 dispose();
277
278 }
279 }
280 }
281 }
282 }
283
284 /**
285 * Methode qui verifie que le mot de passe saisie est le meme dans la zone
286 * de saisie de confirmation
287 *
288 * @return ret //retourn true si les deux mots de passes sont correctes
289 */
290 private boolean checkPasswords() {
291
292 boolean ret = false;
293 String motDePasse = new String(this.createPasswdField.getPassword());
294 String confirmeMotDePasseSaisie = new String(
295 this.confirmeMotDePasseSaisieText.getPassword());
296
297 if (confirmeMotDePasseSaisie.equals(motDePasse)) {
298 ret = true;
299 } else {
300 ret = false;
301 }
302 return ret;
303 }
304
305 /**
306 * Methode qui permet de verifier que le testeur n'existe pas dja
307 *
308 * return ret // retourne vrai si le testeur existe deja
309 */
310 private boolean checkUserExist() {
311 boolean ret;
312 Utilisateur lUtilisateur;
313 String nomUtilisateur;
314 String prenomUtilisateur;
315 String motDePasseSaisie;
316
317 nomUtilisateur = this.createNomTextField.getText();
318 prenomUtilisateur = this.createPrenomTextField.getText();
319 motDePasseSaisie = new String(this.createPasswdField.getPassword());
320 lUtilisateur = new Utilisateur(nomUtilisateur, prenomUtilisateur,
321 motDePasseSaisie, " ", " ");
322
323 ListUtilisateurs.readUtilisateurInfoFromDisk();
324
325
326 ret = ListUtilisateurs.isIn(lUtilisateur);
327
328 return ret;
329
330 }
331
332 }