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.ItemEvent;
32 import java.awt.event.ItemListener;
33 import java.awt.event.MouseAdapter;
34 import java.awt.event.MouseEvent;
35 import java.awt.event.WindowAdapter;
36 import java.awt.event.WindowEvent;
37
38 import javax.swing.JButton;
39 import javax.swing.JCheckBox;
40 import javax.swing.JFrame;
41 import javax.swing.JLabel;
42 import javax.swing.JMenu;
43 import javax.swing.JMenuBar;
44 import javax.swing.JMenuItem;
45 import javax.swing.JOptionPane;
46 import javax.swing.JPanel;
47 import javax.swing.JPasswordField;
48 import javax.swing.JTextField;
49 import javax.swing.SwingConstants;
50
51 import org.apache.commons.logging.Log;
52 import org.apache.commons.logging.LogFactory;
53
54 import com.drazzib.netpisteur.configuration.Cobaye;
55 import com.drazzib.netpisteur.configuration.Configuration;
56 import com.drazzib.netpisteur.configuration.ListUtilisateurs;
57 import com.drazzib.netpisteur.configuration.Utilisateur;
58 import com.drazzib.netpisteur.util.Messages;
59
60 public class ConfigFrame extends JFrame {
61
62 private static Log log = LogFactory.getLog(ConfigFrame.class);
63
64 private static final long serialVersionUID = -513902715037672612L;
65
66 private JMenuBar menuBar;
67
68 private JMenu fichierMenu, aideMenu;
69
70 private JMenuItem quitterMenuItem, aProposMenuItem, manuelMenuItem;
71
72 private JPanel panelEst, panelOuest, panelSud, panelCentre, formulaire,
73 saisieTps, changeMotP;
74
75 private JTextField nomTextField, saisieHeure, saisieMin, saisieSec,
76 prenomTextField, refTextField;
77
78 private JLabel prenomLabel, refLabel, motDePLabel, sousMotDePLabel,
79 choixParam, chronoONTestLabel, dureeTestLabel, nveauTeLabel,
80 nomLabel, remplir;
81
82 private JPasswordField jPasswordField4;
83
84 private JButton ok, annuler, changeButton, option, creation;
85
86 private JCheckBox positionSourisClickCheckBox, mvtiSourisCheckBox,
87 historiquePagesCheckBox, listeLiensCheckBox, activeChronoCheckBox;
88
89
90 private static Cobaye leCobaye;
91
92
93 private static Utilisateur lUtilisateur;
94
95
96 private static int dureeH;
97
98 private static int dureeMin;
99
100 private static int dureeSec;
101
102
103
104
105 /** Creates new form Config */
106 public ConfigFrame() {
107 initComponents();
108 }
109
110
111
112
113 private void initComponents() {
114
115 this.menuBar = new JMenuBar();
116 this.fichierMenu = new JMenu();
117 this.quitterMenuItem = new JMenuItem();
118 this.aideMenu = new JMenu();
119 this.aProposMenuItem = new JMenuItem();
120 this.manuelMenuItem = new JMenuItem();
121 this.panelEst = new JPanel();
122 this.panelOuest = new JPanel();
123 this.panelSud = new JPanel();
124 this.panelCentre = new JPanel();
125 this.changeMotP = new JPanel();
126 this.changeButton = new JButton(Messages.getString("Config.CHANGE"));
127 this.formulaire = new JPanel();
128 this.nveauTeLabel = new JLabel();
129 this.nomLabel = new JLabel();
130 this.nomTextField = new JTextField();
131 this.prenomLabel = new JLabel();
132 this.prenomTextField = new JTextField();
133 this.refLabel = new JLabel();
134 this.refTextField = new JTextField();
135 this.motDePLabel = new JLabel();
136 this.jPasswordField4 = new JPasswordField();
137 this.sousMotDePLabel = new JLabel();
138 this.ok = new JButton();
139 this.annuler = new JButton();
140 this.option = new JButton();
141 this.creation = new JButton();
142 this.choixParam = new JLabel();
143 this.positionSourisClickCheckBox = new JCheckBox();
144 this.mvtiSourisCheckBox = new JCheckBox();
145 this.historiquePagesCheckBox = new JCheckBox();
146 this.listeLiensCheckBox = new JCheckBox();
147 this.chronoONTestLabel = new JLabel();
148 this.remplir = new JLabel();
149 this.activeChronoCheckBox = new JCheckBox();
150 this.dureeTestLabel = new JLabel();
151 this.saisieTps = new JPanel();
152 this.saisieHeure = new JTextField();
153 this.saisieMin = new JTextField();
154 this.saisieSec = new JTextField();
155 this.fichierMenu.setText(Messages.getString("Config.FILE"));
156
157 this.quitterMenuItem.setText(Messages.getString("Config.QUIT"));
158
159 this.fichierMenu.add(this.quitterMenuItem);
160 this.menuBar.add(this.fichierMenu);
161 this.aideMenu.setText(Messages.getString("Config.HELP"));
162
163 this.aProposMenuItem.setText(Messages.getString("Config.ABOUT"));
164
165 this.aideMenu.add(this.aProposMenuItem);
166 this.manuelMenuItem.setText(Messages.getString("Config.USER_HELP"));
167
168 this.aideMenu.add(this.manuelMenuItem);
169 this.menuBar.add(this.aideMenu);
170
171 addWindowListener(new WindowAdapter() {
172 public void windowClosing(WindowEvent evt) {
173 exitForm(evt);
174 }
175 });
176
177 getContentPane().add(this.panelEst, BorderLayout.NORTH);
178 getContentPane().add(this.panelEst, BorderLayout.EAST);
179 getContentPane().add(this.panelOuest, BorderLayout.WEST);
180 getContentPane().add(this.panelSud, BorderLayout.SOUTH);
181
182 this.formulaire.setLayout(new GridLayout(20, 2));
183
184
185
186
187 Font titre = new Font("Arial", Font.BOLD, 15);
188 Font petit = new Font("Arial", Font.ITALIC, 9);
189
190 this.nveauTeLabel.setText(Messages.getString("Config.IDENT_TESTER"));
191 this.nveauTeLabel.setFont(titre);
192
193 this.formulaire.add(this.nveauTeLabel);
194
195 this.formulaire.add(new JLabel());
196
197 this.nomLabel.setText(Messages.getString("Config.NAME"));
198
199 this.formulaire.add(this.nomLabel);
200
201 this.nomTextField.setName("nomTextField");
202 this.formulaire.add(this.nomTextField);
203
204 this.prenomLabel.setText(Messages.getString("Config.FIRST_NAME"));
205
206 this.formulaire.add(this.prenomLabel);
207
208 this.prenomTextField.setName("prenomTextField");
209 this.formulaire.add(this.prenomTextField);
210
211 this.refLabel.setText(Messages.getString("Config.REF_COBAYE"));
212
213 this.formulaire.add(this.refLabel);
214
215 this.formulaire.add(this.refTextField);
216
217 this.motDePLabel.setText(Messages.getString("Config.TESTER_PASSWORD"));
218
219 this.formulaire.add(this.motDePLabel);
220
221 this.changeMotP.setLayout(new GridLayout(1, 2));
222 this.changeButton.addMouseListener(new MouseAdapter() {
223 public void mouseReleased(MouseEvent evt) {
224 nouveauPasswordMouseReleased(evt);
225 }
226 });
227 this.changeMotP.add(this.jPasswordField4);
228 this.changeMotP.add(this.changeButton);
229 this.formulaire.add(this.changeMotP);
230
231 this.formulaire.add(this.sousMotDePLabel);
232 this.creation.setText(Messages.getString("Config.TESTER_CREATE"));
233
234 this.creation.addMouseListener(new MouseAdapter() {
235 public void mouseClicked(MouseEvent evt) {
236 creationMouseReleased(evt);
237 }
238 });
239 this.formulaire.add(this.creation);
240
241
242 JLabel titreDuree = new JLabel(Messages.getString("Config.LENGTH"));
243 titreDuree.setFont(titre);
244 this.formulaire.add(titreDuree);
245 this.formulaire.add(new JLabel());
246 this.chronoONTestLabel.setText(Messages
247 .getString("Config.CHRONO_LENGTH"));
248
249 this.formulaire.add(this.chronoONTestLabel);
250
251 if (Configuration.getHandle().isTimerActif()) {
252 this.activeChronoCheckBox.setSelected(true);
253 } else {
254 this.activeChronoCheckBox.setSelected(false);
255 }
256 this.activeChronoCheckBox.setHorizontalAlignment(SwingConstants.CENTER);
257 this.activeChronoCheckBox.addItemListener(new ItemListener() {
258 public void itemStateChanged(ItemEvent e) {
259 activeChrono(e);
260 }
261 });
262
263 this.formulaire.add(this.activeChronoCheckBox);
264
265 this.dureeTestLabel.setText(Messages.getString("Config.TEST_LENGTH"));
266
267 this.formulaire.add(this.dureeTestLabel);
268
269 this.saisieHeure.setColumns(2);
270 this.saisieMin.setColumns(2);
271 this.saisieSec.setColumns(2);
272 this.saisieTps.add(this.saisieHeure);
273 this.saisieTps.add(this.saisieMin);
274 this.saisieTps.add(this.saisieSec);
275 this.saisieHeure.setEditable(false);
276 this.saisieMin.setEditable(false);
277 this.saisieSec.setEditable(false);
278 this.formulaire.add(this.saisieTps);
279 this.formulaire.add(new JLabel());
280 this.formulaire.add(new JLabel());
281
282
283
284 JLabel titrePara = new JLabel(Messages.getString("Config.PARAM"));
285 titrePara.setFont(titre);
286 this.formulaire.add(titrePara);
287 this.formulaire.add(new JLabel());
288
289 this.choixParam.setText(Messages.getString("Config.CHOICE_PARAMS"));
290 this.formulaire.add(this.choixParam);
291
292 this.formulaire.add(new JLabel());
293 this.formulaire.add(new JLabel());
294
295
296 this.positionSourisClickCheckBox.setText(Messages
297 .getString("Config.CLICK_POSITION"));
298 this.positionSourisClickCheckBox.setSelected(Configuration.getHandle().isMesureClick());
299
300
301 this.positionSourisClickCheckBox.addItemListener(new ItemListener() {
302 public void itemStateChanged(ItemEvent e) {
303 treatClickCheckBox(e);
304 }
305 });
306 this.formulaire.add(this.positionSourisClickCheckBox);
307
308 this.formulaire.add(new JLabel());
309
310
311 this.mvtiSourisCheckBox.setText(Messages
312 .getString("Config.MOUSE_MOUVEMENT"));
313 this.mvtiSourisCheckBox.setSelected(Configuration.getHandle().isMesurePlacement());
314
315 this.mvtiSourisCheckBox.addItemListener(new ItemListener() {
316 public void itemStateChanged(ItemEvent e) {
317 treatPlacementCheckBox(e);
318 }
319 });
320 this.formulaire.add(this.mvtiSourisCheckBox);
321
322 this.formulaire.add(new JLabel());
323
324
325 this.historiquePagesCheckBox.setText(Messages
326 .getString("Config.HISTORY"));
327 this.historiquePagesCheckBox.setSelected(Configuration.getHandle().isMesureURL());
328
329 this.historiquePagesCheckBox.addItemListener(new ItemListener() {
330 public void itemStateChanged(ItemEvent e) {
331 treatUrlCheckBox(e);
332 }
333 });
334
335 this.formulaire.add(this.historiquePagesCheckBox);
336
337 this.formulaire.add(new JLabel());
338
339
340 this.listeLiensCheckBox.setText(Messages
341 .getString("Config.HISTORY_LINKS"));
342 this.listeLiensCheckBox.setSelected(Configuration.getHandle().isMesureHL());
343
344 this.listeLiensCheckBox.addItemListener(new ItemListener() {
345 public void itemStateChanged(ItemEvent e) {
346 treatHlCheckBox(e);
347 }
348 });
349
350 this.formulaire.add(this.listeLiensCheckBox);
351
352 this.formulaire.add(new JLabel());
353 this.formulaire.add(new JLabel());
354
355 this.formulaire.add(new JLabel());
356
357 this.option.setText(Messages.getString("Config.ADVANCED_OPTION"));
358
359 this.option.addMouseListener(new MouseAdapter() {
360 public void mouseClicked(MouseEvent evt) {
361 optionMouseReleased(evt);
362 }
363 });
364 this.formulaire.add(this.option);
365 this.formulaire.add(new JLabel());
366
367 this.remplir.setText(Messages.getString("Config.IDENT_FIELD"));
368 this.remplir.setFont(petit);
369 this.formulaire.add(this.remplir);
370
371 this.ok.setText(Messages.getString("Config.OK"));
372
373 this.ok.addMouseListener(new MouseAdapter() {
374 public void mouseClicked(MouseEvent evt) {
375 okMouseReleased(evt);
376 }
377 });
378 this.formulaire.add(this.ok);
379
380 this.annuler.setText(Messages.getString("Config.CANCEL"));
381
382 this.annuler.addMouseListener(new MouseAdapter() {
383 public void mouseReleased(MouseEvent evt) {
384 annulerMouseReleased(evt);
385 }
386 });
387 this.formulaire.add(this.annuler);
388
389 this.panelCentre.add(this.formulaire);
390 getContentPane().add(this.panelCentre, BorderLayout.CENTER);
391
392
393 setTitle(Messages.getString("Config.FORM_TITLE"));
394 this.setSize(540,800);
395 this.setResizable(false);
396
397 }
398
399 /**
400 * Check the timer
401 */
402 private boolean checkTimer() {
403
404 boolean bok = true;
405
406 if (Configuration.getHandle().isTimerActif()) {
407 try {
408 if (this.saisieHeure.getText().equals("")) {
409 dureeH = 0;
410 } else {
411 dureeH = Integer.parseInt(this.saisieHeure.getText());
412 }
413
414 if (this.saisieMin.getText().equals("")) {
415 dureeMin = 0;
416 } else {
417 dureeMin = Integer.parseInt(this.saisieMin.getText());
418 }
419
420 if (this.saisieSec.getText().equals("")) {
421 dureeSec = 0;
422 } else {
423 dureeSec = Integer.parseInt(this.saisieSec.getText());
424 }
425
426 if ((dureeH == 0 && dureeMin == 0 && dureeSec == 0)
427 || (dureeH < 0 || dureeH > 24)
428 || (dureeMin < 0 || dureeMin > 59)
429 || (dureeSec < 0 || dureeSec > 59)) {
430 bok = false;
431 }
432
433 }
434 catch (java.lang.NumberFormatException e) {
435 bok = false;
436 }
437 }
438 return bok;
439
440 }
441
442 /**
443 * Save the time in differents variable of configuration
444 */
445 private void saveTimer() {
446 if (Configuration.getHandle().isTimerActif()) {
447 Configuration.getHandle().setTimerHeure(dureeH);
448 Configuration.getHandle().setTimerMinute(dureeMin);
449 Configuration.getHandle().setTimerSeconde(dureeSec);
450
451 }
452 }
453
454 /**
455 * Check if the user exits
456 */
457 private boolean checkUser() {
458
459 String refCobaye;
460 String nomUtilisateur;
461 String prenomUtilisateur;
462 String motDePasseSaisie;
463
464 refCobaye = this.refTextField.getText();
465 nomUtilisateur = this.nomTextField.getText();
466 prenomUtilisateur = this.prenomTextField.getText();
467
468 motDePasseSaisie = new String(this.jPasswordField4.getPassword());
469
470 lUtilisateur = new Utilisateur(nomUtilisateur, prenomUtilisateur,
471 motDePasseSaisie, "", "");
472 leCobaye = new Cobaye(refCobaye);
473
474
475 ListUtilisateurs.readUtilisateurInfoFromDisk();
476
477 return (ListUtilisateurs.isIn(lUtilisateur));
478
479 }
480
481 /**
482 * Save the user parameters in differents variable of configuration
483 */
484 private void saveUser() {
485
486 Configuration.getHandle().setRootNom(lUtilisateur.getNom());
487 Configuration.getHandle().setRootPrenom(lUtilisateur.getPrenom());
488 Configuration.getHandle().setRootPassword(lUtilisateur.getMotDePasse());
489 Configuration.getHandle().setRootSeparator(
490 lUtilisateur.getSeparateur());
491 Configuration.getHandle().setRootPage(
492 lUtilisateur.getPage());
493 Configuration.getHandle().setCobayeName(leCobaye.getReference());
494 }
495
496 /**
497 * Open a new frame which allows to change a password
498 *
499 * @param MouseEvent
500 * evt
501 */
502 void nouveauPasswordMouseReleased(MouseEvent evt) {
503 boolean motdepasseOk = checkUser();
504
505 if (motdepasseOk == true) {
506
507 saveUser();
508 ChangePassword nouveauMot = new ChangePassword(lUtilisateur, this);
509 nouveauMot.setLocationRelativeTo(null);
510 nouveauMot.setVisible(true);
511
512 } else {
513 JOptionPane
514 .showMessageDialog(
515 null,
516 Messages.getString("Config.BAD_PASSWORD"), Messages.getString("Config.ERROR"), JOptionPane.ERROR_MESSAGE);
517 }
518
519 }
520
521 /**
522 * Print the name and the first name of the user on the frame when a new
523 * user is created
524 *
525 * @param nom
526 * the name of the user
527 * @param prenom
528 * the first name of the user
529 */
530 public void setFields(String nom, String prenom) {
531 this.nomTextField.setText(nom);
532 this.prenomTextField.setText(prenom);
533 this.jPasswordField4.setText("");
534 this.refTextField.setText("");
535 }
536
537 /**
538 * Print the name, the first name and the password of the user on the frame
539 * when the password is changed.
540 *
541 * This method use the method setFields(String, String)
542 *
543 * @param nom
544 * the name of the user
545 * @param prenom
546 * the first name of the user
547 * @param motDePasse
548 * the password of the user
549 */
550 public void setAllFields(String nom, String prenom, String motDePasse) {
551 this.nomTextField.setText(nom);
552 this.prenomTextField.setText(prenom);
553 this.jPasswordField4.setText(motDePasse);
554 this.refTextField.setText("");
555 }
556
557 /**
558 * Search if the option "Historique des pages visites" is activated
559 *
560 * @param ItemEvent
561 * evt
562 */
563 void treatHlCheckBox(java.awt.event.ItemEvent evt) {
564 if (evt.getStateChange() == ItemEvent.SELECTED) {
565 Configuration.getHandle().setMesureHL(true);
566 } else {
567 Configuration.getHandle().setMesureHL(false);
568 }
569 }
570
571 /**
572 * Search if the option "Liste des liens activs" is activated
573 *
574 * @param ItemEvent
575 * evt
576 */
577 void treatUrlCheckBox(ItemEvent evt) {
578 if (evt.getStateChange() == ItemEvent.SELECTED) {
579 Configuration.getHandle().setMesureURL(true);
580 } else {
581 Configuration.getHandle().setMesureURL(false);
582 }
583 }
584
585 /**
586 * Search if the option "Positions des clics de souris" is activated
587 *
588 * @param ItemEvent
589 * evt
590 */
591 void treatClickCheckBox(ItemEvent evt) {
592 if (evt.getStateChange() == ItemEvent.SELECTED) {
593 Configuration.getHandle().setMesureClick(true);
594 } else {
595 Configuration.getHandle().setMesureClick(false);
596 }
597 }
598
599 /**
600 * Search if the option "Mouvement de la souris" is activated
601 *
602 * @param ItemEvent
603 * evt
604 */
605 void treatPlacementCheckBox(ItemEvent evt) {
606 if (evt.getStateChange() == ItemEvent.SELECTED) {
607 Configuration.getHandle().setMesurePlacement(true);
608 } else {
609 Configuration.getHandle().setMesurePlacement(false);
610 }
611 }
612
613 /**
614 * Exit the application when the user click on "Annuler"
615 *
616 * @param MouseEvent
617 * evt
618 */
619 void annulerMouseReleased(MouseEvent evt) {
620 System.exit(0);
621 }
622
623 /**
624 * Open the option frame
625 *
626 * To open this frame, the user and the timer must be good
627 *
628 * @param MouseEvent
629 * evt
630 */
631 void optionMouseReleased(MouseEvent evt) {
632
633 boolean motdepasseOk = checkUser();
634
635 if (motdepasseOk == true) {
636
637 saveUser();
638 AdvancedOptionsFrame optionAv = new AdvancedOptionsFrame(
639 lUtilisateur);
640 optionAv.setLocationRelativeTo(null);
641 optionAv.setVisible(true);
642
643 } else {
644 JOptionPane
645 .showMessageDialog(
646 null,
647 Messages.getString("Config.BAD_PASSWORD"), Messages.getString("Config.ERROR"), JOptionPane.ERROR_MESSAGE);
648 }
649 }
650
651 void creationMouseReleased(MouseEvent evt) {
652 CreateTestorFrame creatTest = new CreateTestorFrame(this);
653 creatTest.setLocationRelativeTo(null);
654 creatTest.setVisible(true);
655 }
656
657 /**
658 * Open the beginning frame
659 *
660 * To open this frame, the user and the timer must be good
661 *
662 * @param MouseEvent
663 * evt
664 */
665 void okMouseReleased(MouseEvent evt) {
666
667 boolean motdepasseOk = checkUser();
668 boolean tempsOk = checkTimer();
669 if (motdepasseOk == true && tempsOk == true) {
670
671
672 this.saveTimer();
673 this.saveUser();
674
675 WaitSplashScreen demarrage = new WaitSplashScreen();
676 demarrage.setLocationRelativeTo(null);
677 this.dispose();
678 demarrage.setVisible(true);
679
680
681 } else {
682 if (motdepasseOk == false && tempsOk == false) {
683 JOptionPane
684 .showMessageDialog(
685 null,
686 Messages.getString("Config.BAD_PASSWORD_TIME"), Messages.getString("Config.ERROR"), JOptionPane.ERROR_MESSAGE);
687 } else {
688 if (motdepasseOk == false) {
689 JOptionPane
690 .showMessageDialog(
691 null,
692 Messages.getString("Config.BAD_PASSWORD"), Messages.getString("Config.ERROR"), JOptionPane.ERROR_MESSAGE);
693 }
694 if (tempsOk == false) {
695 JOptionPane
696 .showMessageDialog(
697 null,
698 Messages.getString("Config.BAD_TIME"), Messages.getString("Config.ERROR"), JOptionPane.ERROR_MESSAGE);
699 }
700 }
701 }
702 }
703
704 /**
705 * Check if the timer is selected
706 */
707 void activeChrono(ItemEvent e) {
708
709 if (e.getStateChange() == ItemEvent.SELECTED) {
710 Configuration.getHandle().setTimerActif(true);
711 this.saisieHeure.setEditable(true);
712 this.saisieMin.setEditable(true);
713 this.saisieSec.setEditable(true);
714 } else {
715 Configuration.getHandle().setTimerActif(false);
716 this.saisieHeure.setEditable(false);
717 this.saisieMin.setEditable(false);
718 this.saisieSec.setEditable(false);
719 }
720 }
721
722 /** Exit the Application */
723 void exitForm(WindowEvent evt) {
724 System.exit(0);
725 }
726
727 }
728