View Javadoc

1   /*
2    * This file is part of NetPisteur.
3    * 
4    * Copyright 2001-2002 : Olivier CORNEC, David BOUANCHEAU, Loic LOPEZ,
5    *                       Gaetan BOUDARD, Mael LE LANNOU, Julien ROBINEAU
6    * 
7    * Copyright 2002-2003 : Olivier BRIENS, Simon DEZE, Florence FRIGOULT,
8    *                       Olivier JOURNEAULT, Francois MARTINIER, Damien RAUDE-MORVAN
9    * 
10   * Copyright 2004-2007 : Damien RAUDE-MORVAN
11   * 
12   * NetPisteur is free software; you can redistribute it and/or modify
13   * it under the terms of the GNU General Public License as published by
14   * the Free Software Foundation; either version 2 of the License, or
15   * (at your option) any later version.
16   *
17   * NetPisteur is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   * GNU General Public License for more details.
21   *
22   * You should have received a copy of the GNU General Public License
23   * along with NetPisteur; if not, write to the Free Software
24   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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  	// attribute
70  
71  	private MainFrame main;
72  
73  	// //////////////////////////////
74  	// constructor
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  	} // FermetureWindow()
82  
83  	// //////////////////////////////
84  	// operations
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 		// Cration de la police des titres
106 		Font titre = new Font("Arial", Font.BOLD, 15); //$NON-NLS-1$
107 
108 		// Mot de passe
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")); //$NON-NLS-1$
115 		this.titreLabel.setHorizontalAlignment(SwingConstants.RIGHT);
116 		this.titreLabel.setFont(titre);
117 		// titreLabel.setName("motPas1");
118 		this.image.setIcon(new ImageIcon(getClass().getResource(
119 				"/com/drazzib/netpisteur/resources/logo.png"))); //$NON-NLS-1$
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() + " " //$NON-NLS-1$ //$NON-NLS-2$
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")); //$NON-NLS-1$
142 		// fermetureOkBouton.setName("ok");
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")); //$NON-NLS-1$
151 		// fermetureAnnulerBouton.setName("annuler");
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 	} // initComponents()
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"), //$NON-NLS-1$
199 							Messages.getString("FermetureWindow.ERROR"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
200 		}
201 	} // fermetureOkBoutonMouseReleased()
202 
203 	/** Exit the Application */
204 	void exitForm() {
205 		this.dispose();
206 	} // exitForm()
207 
208 } // class FermetureWindow
209