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.event.MouseAdapter;
32 import java.awt.event.MouseEvent;
33 import java.awt.event.WindowAdapter;
34 import java.awt.event.WindowEvent;
35
36 import javax.swing.ImageIcon;
37 import javax.swing.JButton;
38 import javax.swing.JFrame;
39 import javax.swing.JLabel;
40 import javax.swing.JOptionPane;
41 import javax.swing.JPanel;
42 import javax.swing.JPasswordField;
43 import javax.swing.SwingConstants;
44 import javax.swing.WindowConstants;
45
46 import com.drazzib.netpisteur.configuration.Configuration;
47 import com.drazzib.netpisteur.util.Messages;
48
49 /**
50 * @author equipe Netpisteur
51 */
52 public class ClosingFrame extends JFrame {
53
54 /**
55 *
56 */
57 private static final long serialVersionUID = 111982095829414480L;
58
59 private JPanel panelAll, panelNorth, panelWest, panelEast, panelSouth,
60 panelMot, titrePanel, panelCenter, fermeturePanel, boutonPanel;
61
62 private JLabel titreLabel, image, contenu;
63
64 private JButton fermetureOkBouton, fermetureAnnulerBouton;
65
66 private JPasswordField motDePasse;
67
68
69
70
71 private MainFrame main;
72
73
74
75
76 /** Creates new form FermetureWindow */
77 public ClosingFrame(MainFrame mainW) {
78 this.main = mainW;
79 setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
80 initComponents();
81 }
82
83
84
85
86 private void initComponents() {
87
88 this.panelAll = new JPanel(new BorderLayout());
89 this.panelNorth = new JPanel();
90 this.panelWest = new JPanel();
91 this.panelEast = new JPanel();
92 this.panelSouth = new JPanel();
93 this.panelCenter = new JPanel(new BorderLayout());
94 this.panelMot = new JPanel();
95 this.fermeturePanel = new JPanel();
96 this.boutonPanel = new JPanel();
97 this.titrePanel = new JPanel();
98 this.titreLabel = new JLabel();
99 this.image = new JLabel();
100 this.contenu = new JLabel();
101 this.fermetureOkBouton = new JButton();
102 this.fermetureAnnulerBouton = new JButton();
103 this.motDePasse = new JPasswordField();
104
105
106 Font titre = new Font("Arial", Font.BOLD, 15);
107
108
109 this.panelMot.setLayout(new java.awt.GridLayout(1, 3));
110 this.titrePanel.setLayout(new java.awt.GridLayout(1, 2));
111 this.fermeturePanel.setLayout(new java.awt.GridLayout(5, 1));
112 this.boutonPanel.setLayout(new java.awt.GridLayout(1, 4));
113
114 this.titreLabel.setText(Messages.getString("FermetureWindow.CLOSING"));
115 this.titreLabel.setHorizontalAlignment(SwingConstants.RIGHT);
116 this.titreLabel.setFont(titre);
117
118 this.image.setIcon(new ImageIcon(getClass().getResource(
119 "/com/drazzib/netpisteur/resources/logo.png")));
120 this.titrePanel.add(this.titreLabel);
121 this.titrePanel.add(this.image);
122
123 this.fermeturePanel.add(new JLabel());
124
125 this.contenu
126 .setText(Messages.getString("FermetureWindow.PASSWORD") + Configuration.getHandle().getRootPrenom() + " "
127 + Configuration.getHandle().getRootNom());
128 this.contenu.setHorizontalAlignment(SwingConstants.CENTER);
129 this.fermeturePanel.add(this.contenu);
130
131 this.fermeturePanel.add(new JLabel());
132
133 this.panelMot.add(new JLabel());
134 this.panelMot.add(this.motDePasse);
135 this.panelMot.add(new JLabel());
136
137 this.fermeturePanel.add(this.panelMot);
138
139 this.fermeturePanel.add(new JLabel());
140 this.fermetureOkBouton
141 .setText(Messages.getString("FermetureWindow.OK"));
142
143 this.fermetureOkBouton.addMouseListener(new MouseAdapter() {
144 public void mouseReleased(MouseEvent evt) {
145 fermetureOkBoutonMouseReleased(evt);
146 }
147 });
148
149 this.fermetureAnnulerBouton.setText(Messages
150 .getString("FermetureWindow.CANCEL"));
151
152 this.fermetureAnnulerBouton.addMouseListener(new MouseAdapter() {
153 public void mouseReleased(MouseEvent evt) {
154 exitForm();
155 }
156 });
157
158 this.addWindowListener(new WindowAdapter() {
159 public void windowClosing(WindowEvent evt) {
160 exitForm();
161 }
162 });
163
164 this.boutonPanel.add(new JLabel());
165 this.boutonPanel.add(this.fermetureOkBouton);
166 this.boutonPanel.add(this.fermetureAnnulerBouton);
167 this.boutonPanel.add(new JLabel());
168
169 this.panelCenter.add(this.titrePanel, BorderLayout.NORTH);
170 this.panelCenter.add(this.fermeturePanel, BorderLayout.CENTER);
171 this.panelCenter.add(this.boutonPanel, BorderLayout.SOUTH);
172
173 this.panelAll.add(this.panelNorth, BorderLayout.NORTH);
174 this.panelAll.add(this.panelWest, BorderLayout.WEST);
175 this.panelAll.add(this.panelEast, BorderLayout.EAST);
176 this.panelAll.add(this.panelSouth, BorderLayout.SOUTH);
177 this.panelAll.add(this.panelCenter, BorderLayout.CENTER);
178 getContentPane().add(this.panelAll);
179
180 this.setLocationRelativeTo(null);
181 pack();
182
183 }
184
185 void fermetureOkBoutonMouseReleased(MouseEvent evt) {
186
187 String motDePasseSaisie = new String(this.motDePasse.getPassword());
188
189 if (motDePasseSaisie
190 .equals(Configuration.getHandle().getRootPassword())) {
191 this.main.saveDatas();
192 } else {
193
194 JOptionPane
195 .showMessageDialog(
196 null,
197 Messages
198 .getString("FermetureWindow.WRONG_PASSWORD"),
199 Messages.getString("FermetureWindow.ERROR"), JOptionPane.ERROR_MESSAGE);
200 }
201 }
202
203 /** Exit the Application */
204 void exitForm() {
205 this.dispose();
206 }
207
208 }
209