View Javadoc

1   /********************************************************************************
2    * InternetCafe is a software solution that helps the management of Cybercafes 
3    * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4    * Copyright (C) 2006  Guido Angelo Ingenito
5   
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10  
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19   *******************************************************************************/
20  package ui.panel;
21  
22  import java.awt.BorderLayout;
23  import java.awt.GridLayout;
24  import java.awt.event.ActionEvent;
25  import java.awt.event.ActionListener;
26  import java.util.Date;
27  import java.util.GregorianCalendar;
28  
29  import javax.swing.JCheckBox;
30  import javax.swing.JPanel;
31  import javax.swing.JTextArea;
32  import javax.swing.border.TitledBorder;
33  
34  import ui.Messages;
35  import base.ConfigurationManager;
36  
37  import com.toedter.calendar.JTimeChooser;
38  
39  @SuppressWarnings("serial") //$NON-NLS-1$
40  public class SecurityConfigurationPanel extends JPanel {
41  
42  	private JPanel passwordProtectPanel;
43  
44  	private JCheckBox passwordProtectCheckBox;
45  
46  	private JPanel automaticPasswordProtectPanel;
47  
48  	private JTimeChooser automaticPasswordProtectTimeChooser;
49  
50  	private JCheckBox automaticPasswordProtectCheckBox;
51  	
52  	private JPanel symmetricCryptographyPanel;
53  	private JTextArea symmetricCryptographyTextArea;
54  	
55  	private JPanel asymmetricCryptographyPanel;
56  	private JTextArea asymmetricCryptographyPublicKeyTextArea;
57  	private JTextArea asymmetricCryptographyPrivateKeyTextArea;
58  	
59  
60  	public SecurityConfigurationPanel() {
61  		initialize();
62  	}
63  
64  	protected void initialize() {
65  		TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.securityconfigurationpanel.securityconfiguration")); //$NON-NLS-1$
66  		this.setBorder(titledBorder);
67  		this.setLayout(new GridLayout(3, 1));
68  		this.add(getPasswordProtectPanel(), null);
69  		this.add(getAsymmetricCryptographyPanel(), null);
70  		this.add(getSymmetricCryptographyPanel(), null);
71  	}
72  
73  	/***
74  	 * @return Returns the passwordProtectPanel.
75  	 */
76  	protected JPanel getPasswordProtectPanel() {
77  		if (passwordProtectPanel == null) {
78  			passwordProtectPanel = new JPanel();
79  			TitledBorder titledBorder = new TitledBorder(Messages.getString("common.passwordprotect")); //$NON-NLS-1$
80  			passwordProtectPanel.setBorder(titledBorder);
81  			passwordProtectPanel.setLayout(new BorderLayout());
82  			passwordProtectPanel.add(getAutomaticPasswordProtectPanel(),
83  					BorderLayout.CENTER);
84  			passwordProtectPanel.add(getPasswordProtectCheckBox(),
85  					BorderLayout.WEST);
86  
87  		}
88  		return passwordProtectPanel;
89  	}
90  
91  	/***
92  	 * @return Returns the passwordProtectCheckBox.
93  	 */
94  	protected JCheckBox getPasswordProtectCheckBox() {
95  		if (passwordProtectCheckBox == null) {
96  			passwordProtectCheckBox = new JCheckBox();
97  			passwordProtectCheckBox
98  					.setToolTipText(Messages.getString("panel.securityconfigurationpanel.message1")); //$NON-NLS-1$
99  			passwordProtectCheckBox.setSelected(ConfigurationManager
100 					.getInstance().isPasswordProtect());
101 			passwordProtectCheckBox.addActionListener(new ActionListener() {
102 				public void actionPerformed(ActionEvent arg0) {
103 					ConfigurationManager.getInstance().setPasswordProtect(
104 							passwordProtectCheckBox.isSelected());
105 				}
106 			});
107 		}
108 		return passwordProtectCheckBox;
109 	}
110 
111 	/***
112 	 * @return Returns the automaticPasswordProtectCheckBox.
113 	 */
114 	protected JCheckBox getAutomaticPasswordProtectCheckBox() {
115 		if (automaticPasswordProtectCheckBox == null) {
116 			automaticPasswordProtectCheckBox = new JCheckBox();
117 			automaticPasswordProtectCheckBox.setSelected(ConfigurationManager
118 					.getInstance().isAutomaticPasswordProtected());
119 			automaticPasswordProtectCheckBox
120 					.addActionListener(new ActionListener() {
121 						public void actionPerformed(ActionEvent arg0) {
122 							ConfigurationManager
123 									.getInstance()
124 									.setAutomaticPasswordProtect(
125 											getAutomaticPasswordProtectCheckBox()
126 													.isSelected());
127 							ConfigurationManager
128 									.getInstance()
129 									.setLogoutScheduleRate(
130 											(int) (((Date) getAutomaticPasswordProtectTimeChooser()
131 													.getValue()).getTime() / 1000));
132 
133 						}
134 
135 					});
136 
137 		}
138 		return automaticPasswordProtectCheckBox;
139 	}
140 
141 	/***
142 	 * @return Returns the automaticPasswordProtectPanel.
143 	 */
144 	protected JPanel getAutomaticPasswordProtectPanel() {
145 		if (automaticPasswordProtectPanel == null) {
146 			automaticPasswordProtectPanel = new JPanel();
147 			TitledBorder titledBorder = new TitledBorder(Messages.getString("common.automaticprotection")); //$NON-NLS-1$
148 			automaticPasswordProtectPanel.setBorder(titledBorder);
149 			automaticPasswordProtectPanel.setLayout(new BorderLayout());
150 			automaticPasswordProtectPanel.add(
151 					getAutomaticPasswordProtectTimeChooser(),
152 					BorderLayout.CENTER);
153 			automaticPasswordProtectPanel.add(
154 					getAutomaticPasswordProtectCheckBox(), BorderLayout.EAST);
155 		}
156 		return automaticPasswordProtectPanel;
157 	}
158 
159 	/***
160 	 * @return Returns the automaticPasswordProtectTimeChooser.
161 	 */
162 	protected JTimeChooser getAutomaticPasswordProtectTimeChooser() {
163 		if (automaticPasswordProtectTimeChooser == null) {
164 			automaticPasswordProtectTimeChooser = new JTimeChooser();
165 			GregorianCalendar gc = new GregorianCalendar(0, 0, 0, 0, 0,
166 					ConfigurationManager.getInstance().getLogoutScheduleRate());
167 			automaticPasswordProtectTimeChooser.setValue(gc.getTime());
168 
169 		}
170 		return automaticPasswordProtectTimeChooser;
171 	}
172 
173 	/***
174 	 * @return Returns the asymmetricCryptographyPanel.
175 	 */
176 	protected JPanel getAsymmetricCryptographyPanel() {
177 		if (asymmetricCryptographyPanel == null) {
178 			asymmetricCryptographyPanel = new JPanel();
179 			TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.securityconfigurationpanel.common.asymmetriccryptographysettings")); //$NON-NLS-1$
180 			asymmetricCryptographyPanel.setBorder(titledBorder);
181 			asymmetricCryptographyPanel.setLayout(new GridLayout(1,2));
182 			JPanel publicKeyPanel = new JPanel();
183 			publicKeyPanel.setLayout(new BorderLayout());
184 			publicKeyPanel.setBorder(new TitledBorder(Messages.getString("common.publickey"))); //$NON-NLS-1$
185 			publicKeyPanel.add(getAsymmetricCryptographyPublicKeyTextArea(),BorderLayout.CENTER);
186 			
187 			JPanel privateKeyPanel = new JPanel();
188 			privateKeyPanel.setLayout(new BorderLayout());
189 			privateKeyPanel.setBorder(new TitledBorder(Messages.getString("common.privatekey"))); //$NON-NLS-1$
190 			privateKeyPanel.add(getAsymmetricCryptographyPrivateKeyTextArea(),BorderLayout.CENTER);
191 			
192 			asymmetricCryptographyPanel.add(publicKeyPanel);
193 			asymmetricCryptographyPanel.add(privateKeyPanel);
194 
195 		}
196 		return asymmetricCryptographyPanel;
197 	}
198 
199 	/***
200 	 * @return Returns the symmetricCryptographyPanel.
201 	 */
202 	protected JPanel getSymmetricCryptographyPanel() {
203 		if (symmetricCryptographyPanel == null) {
204 			symmetricCryptographyPanel = new JPanel();
205 			TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.securityconfigurationpanel.common.symmetriccryptographysettings")); //$NON-NLS-1$
206 			symmetricCryptographyPanel.setBorder(titledBorder);
207 			symmetricCryptographyPanel.setLayout(new GridLayout(1,2));
208 			symmetricCryptographyPanel.add(getSymmetricCryptographyTextArea());
209 		}
210 		return symmetricCryptographyPanel;
211 	}
212 
213 	/***
214 	 * @return Returns the asymmetricCryptographyPrivateKeyTextArea.
215 	 */
216 	protected JTextArea getAsymmetricCryptographyPrivateKeyTextArea() {
217 		if(asymmetricCryptographyPrivateKeyTextArea == null){
218 			asymmetricCryptographyPrivateKeyTextArea = new JTextArea();
219 		}
220 		return asymmetricCryptographyPrivateKeyTextArea;
221 	}
222 
223 	/***
224 	 * @return Returns the asymmetricCryptographyPublicKeyTextArea.
225 	 */
226 	protected JTextArea getAsymmetricCryptographyPublicKeyTextArea() {
227 		if(asymmetricCryptographyPublicKeyTextArea == null){
228 			asymmetricCryptographyPublicKeyTextArea = new JTextArea();
229 		}
230 		return asymmetricCryptographyPublicKeyTextArea;
231 	}
232 
233 	/***
234 	 * @return Returns the symmetricCryptographyTextArea.
235 	 */
236 	protected JTextArea getSymmetricCryptographyTextArea() {
237 		if(symmetricCryptographyTextArea == null){
238 			symmetricCryptographyTextArea = new JTextArea();
239 		}
240 		return symmetricCryptographyTextArea;
241 	}
242 }