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 package com.drazzib.netpisteur.ui;
28
29 import java.awt.BorderLayout;
30 import java.awt.Font;
31 import java.awt.GridLayout;
32 import java.awt.event.MouseAdapter;
33 import java.awt.event.MouseEvent;
34
35 import javax.swing.JButton;
36 import javax.swing.JFrame;
37 import javax.swing.JLabel;
38 import javax.swing.JOptionPane;
39 import javax.swing.JPanel;
40 import javax.swing.JPasswordField;
41 import javax.swing.SwingConstants;
42
43 import com.drazzib.netpisteur.configuration.ListUtilisateurs;
44 import com.drazzib.netpisteur.configuration.Utilisateur;
45 import com.drazzib.netpisteur.util.Messages;
46
47 /**
48 * This class open a frame wich allows to change the password of a specific user
49 */
50 public class ChangePassword extends JFrame {
51
52 /**
53 *
54 */
55 private static final long serialVersionUID = -300107571327655316L;
56
57 private JPanel panelAll, panelNorth, panelWest, panelEast, panelSouth,
58 panelCenter, passwordPanel, titrePanel, boutonPanel;
59
60 private JLabel gestMotDePassseLabel, gestMotDePassseLabel2,
61 nouveauPasswordLabel, confirmePasswordLabel;
62
63 private JPasswordField nouveauPasswordField, confirmePasswordField;
64
65 private JButton passwordOkBouton, passwordAnnulerBouton;
66
67
68
69 private String name;
70
71 private String firstname;
72
73 private String password;
74
75 private ConfigFrame myConfig;
76
77
78
79
80 /**
81 * Creates new form Config
82 *
83 * @param user
84 * the name of user
85 * @param myconf
86 * the firstname of the user
87 */
88 public ChangePassword(Utilisateur user, ConfigFrame myconf) {
89 this.name = user.getNom();
90 this.firstname = user.getPrenom();
91 this.password = user.getMotDePasse();
92 this.myConfig = myconf;
93 initComponents();
94 }
95
96
97
98
99 private void initComponents() {
100
101 this.panelAll = new JPanel(new BorderLayout());
102 this.panelNorth = new JPanel();
103 this.panelWest = new JPanel();
104 this.panelEast = new JPanel();
105 this.panelSouth = new JPanel();
106 this.panelCenter = new JPanel(new BorderLayout());
107 this.passwordPanel = new JPanel();
108 this.titrePanel = new JPanel();
109 this.boutonPanel = new JPanel();
110 this.gestMotDePassseLabel = new JLabel();
111 this.gestMotDePassseLabel2 = new JLabel();
112 this.nouveauPasswordLabel = new JLabel(Messages
113 .getString("ChangeMotDePasse.NEW_PASSWORD"));
114 this.confirmePasswordLabel = new JLabel(Messages
115 .getString("ChangeMotDePasse.CONFIRM_PASSWORD"));
116 this.nouveauPasswordField = new JPasswordField();
117 this.confirmePasswordField = new JPasswordField();
118 this.passwordOkBouton = new JButton();
119 this.passwordAnnulerBouton = new JButton();
120
121
122 Font titre = new Font("Arial", Font.BOLD, 15);
123
124
125 this.passwordPanel.setLayout(new GridLayout(6, 1));
126 this.titrePanel.setLayout(new GridLayout(2, 1));
127 this.boutonPanel.setLayout(new GridLayout(1, 2));
128
129 this.gestMotDePassseLabel.setText(Messages
130 .getString("ChangeMotDePasse.MOD_PASSWORD"));
131 this.gestMotDePassseLabel2
132 .setText(Messages.getString("ChangeMotDePasse.OF") + this.firstname + " " + this.name);
133 this.gestMotDePassseLabel.setHorizontalAlignment(SwingConstants.CENTER);
134 this.gestMotDePassseLabel2
135 .setHorizontalAlignment(SwingConstants.CENTER);
136 this.gestMotDePassseLabel.setFont(titre);
137 this.gestMotDePassseLabel2.setFont(titre);
138
139
140
141 this.titrePanel.add(this.gestMotDePassseLabel);
142 this.titrePanel.add(this.gestMotDePassseLabel2);
143
144 this.passwordPanel.add(new JLabel());
145 this.passwordPanel.add(this.nouveauPasswordLabel);
146 this.passwordPanel.add(this.nouveauPasswordField);
147 this.passwordPanel.add(this.confirmePasswordLabel);
148 this.passwordPanel.add(this.confirmePasswordField);
149 this.passwordPanel.add(new JLabel());
150
151 this.passwordOkBouton
152 .setText(Messages.getString("ChangeMotDePasse.OK"));
153
154 this.passwordOkBouton.addMouseListener(new MouseAdapter() {
155 public void mouseReleased(MouseEvent evt) {
156 passwordOkBoutonMouseReleased(evt);
157 }
158 });
159
160 this.boutonPanel.add(this.passwordOkBouton);
161
162 this.passwordAnnulerBouton.setText(Messages
163 .getString("ChangeMotDePasse.CANCEL"));
164
165 this.passwordAnnulerBouton.addMouseListener(new MouseAdapter() {
166 public void mouseReleased(MouseEvent evt) {
167 passwordAnnulerBoutonMouseReleased(evt);
168 }
169 });
170
171 this.boutonPanel.add(this.passwordAnnulerBouton);
172 this.panelCenter.add(this.titrePanel, BorderLayout.NORTH);
173 this.panelCenter.add(this.passwordPanel, BorderLayout.CENTER);
174 this.panelCenter.add(this.boutonPanel, BorderLayout.SOUTH);
175
176 this.panelAll.add(this.panelNorth, BorderLayout.NORTH);
177 this.panelAll.add(this.panelWest, BorderLayout.WEST);
178 this.panelAll.add(this.panelEast, BorderLayout.EAST);
179 this.panelAll.add(this.panelSouth, BorderLayout.SOUTH);
180 this.panelAll.add(this.panelCenter, BorderLayout.CENTER);
181 getContentPane().add(this.panelAll);
182
183 this.setLocationRelativeTo(null);
184 pack();
185
186 }
187
188 /**
189 * Allows to close the frame when the button cancel is pushed
190 *
191 * @param MouseEvent
192 * evt
193 */
194 void passwordAnnulerBoutonMouseReleased(java.awt.event.MouseEvent evt) {
195 this.dispose();
196 }
197
198 /**
199 * Allows to close the frame and save the new password when the button ok is
200 * pushed
201 *
202 * @param MouseEvent
203 * evt
204 */
205 void passwordOkBoutonMouseReleased(java.awt.event.MouseEvent evt) {
206
207 Utilisateur lUtilisateur;
208
209 String nouveauMotDePasseSaisie;
210 String confirmeMotDePasseSaisie;
211
212 lUtilisateur = new Utilisateur(this.name, this.firstname,
213 this.password, "", "");
214 nouveauMotDePasseSaisie = new String(this.nouveauPasswordField
215 .getPassword());
216 confirmeMotDePasseSaisie = new String(this.confirmePasswordField
217 .getPassword());
218
219
220 ListUtilisateurs.readUtilisateurInfoFromDisk();
221
222 boolean nouveaumotOk = (nouveauMotDePasseSaisie
223 .equals(confirmeMotDePasseSaisie));
224 boolean nonnull = !(nouveauMotDePasseSaisie.equals(""));
225
226 if (nouveaumotOk == true && nonnull == true) {
227
228 ListUtilisateurs.changePasswd(lUtilisateur, nouveauMotDePasseSaisie);
229 JOptionPane
230 .showMessageDialog(
231 null,
232 Messages.getString("ChangeMotDePasse.CHANGE_OK"), Messages.getString("ChangeMotDePasse.CHANGE_OK_TITLE"), JOptionPane.INFORMATION_MESSAGE);
233 this.myConfig.setAllFields(this.name, this.firstname,
234 nouveauMotDePasseSaisie);
235 dispose();
236
237 } else {
238 JOptionPane
239 .showMessageDialog(
240 null,
241 Messages.getString("ChangeMotDePasse.CHANGE_NOK"), Messages.getString("ChangeMotDePasse.CHANGE_NOK_TITLE"), JOptionPane.ERROR_MESSAGE);
242
243 }
244 }
245
246 }