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 21 package base.jdbs.ui.panel; 22 23 import java.awt.BorderLayout; 24 import java.awt.GridLayout; 25 import java.awt.event.ActionEvent; 26 import java.awt.event.ActionListener; 27 import java.beans.PropertyChangeEvent; 28 import java.beans.PropertyChangeListener; 29 30 import javax.swing.JComboBox; 31 import javax.swing.JPanel; 32 import javax.swing.JScrollPane; 33 import javax.swing.JTextArea; 34 import javax.swing.JTextField; 35 import javax.swing.border.TitledBorder; 36 37 import org.apache.log4j.Logger; 38 39 import base.jdbs.Backup; 40 import base.jdbs.ConfigurationManager; 41 import base.jdbs.SecurityLevel; 42 43 import com.toedter.calendar.JDateChooser; 44 45 /*** 46 * @author skunk 47 * 48 */ 49 @SuppressWarnings("serial") 50 public class BackupPanel extends JPanel { 51 52 private static final transient Logger logger = Logger 53 .getLogger(BackupPanel.class.getName()); 54 55 private JPanel guIdPanel; 56 57 private JPanel namePanel; 58 59 private JPanel descriptionPanel; 60 61 private JPanel creationDatePanel; 62 63 private JPanel expirationDatePanel; 64 65 private JPanel securityLevelPanel; 66 67 private JPanel filePanel; 68 69 private JTextField guIdTextField; 70 71 private JTextField nameTextField; 72 73 private JScrollPane descriptionScrollPane; 74 75 private JTextArea descriptionTextArea; 76 77 private JDateChooser creationDateChooser; 78 79 private JDateChooser expirationDateChooser; 80 81 private JComboBox securityLevelComboBox; 82 83 private final Backup backup; 84 85 public BackupPanel(Backup backup) { 86 this.backup = backup; 87 initialize(); 88 } 89 90 protected void initialize() { 91 this.setLayout(new GridLayout(2, 1)); 92 JPanel topPanel = new JPanel(); 93 topPanel.setLayout(new GridLayout(3, 2)); 94 95 topPanel.add(this.getGuIdPanel()); 96 topPanel.add(this.getNamePanel()); 97 topPanel.add(this.getDescriptionPanel()); 98 topPanel.add(this.getSecurityLevelPanel()); 99 topPanel.add(this.getCreationDatePanel()); 100 topPanel.add(this.getExpirationDatePanel()); 101 102 JPanel bottomPanel = new JPanel(); 103 bottomPanel.setLayout(new BorderLayout()); 104 bottomPanel.add(this.getFilePanel()); 105 106 this.add(topPanel); 107 this.add(bottomPanel); 108 109 } 110 111 /*** 112 * @return Returns the creationDatePanel. 113 */ 114 protected JPanel getCreationDatePanel() { 115 if (this.creationDatePanel == null) { 116 this.creationDatePanel = new JPanel(); 117 this.creationDatePanel.setBorder(new TitledBorder("Creation Date")); 118 this.creationDatePanel.setLayout(new BorderLayout()); 119 this.creationDatePanel.add(this.getCreationDateChooser(), 120 BorderLayout.CENTER); 121 } 122 return creationDatePanel; 123 } 124 125 /*** 126 * @return Returns the descriptionPanel. 127 */ 128 protected JPanel getDescriptionPanel() { 129 if (this.descriptionPanel == null) { 130 this.descriptionPanel = new JPanel(); 131 this.descriptionPanel.setBorder(new TitledBorder("Description")); 132 this.descriptionPanel.setLayout(new BorderLayout()); 133 this.descriptionPanel.add(this.getDescriptionScrollPane(), 134 BorderLayout.CENTER); 135 } 136 return descriptionPanel; 137 } 138 139 /*** 140 * @return Returns the expirationDatePanel. 141 */ 142 protected JPanel getExpirationDatePanel() { 143 if (this.expirationDatePanel == null) { 144 this.expirationDatePanel = new JPanel(); 145 this.expirationDatePanel.setBorder(new TitledBorder( 146 "Expiration Date")); 147 this.expirationDatePanel.setLayout(new BorderLayout()); 148 this.expirationDatePanel.add(this.getExpirationDateChooser(), 149 BorderLayout.CENTER); 150 } 151 return expirationDatePanel; 152 } 153 154 /*** 155 * @return Returns the guIdPanel. 156 */ 157 protected JPanel getGuIdPanel() { 158 if (this.guIdPanel == null) { 159 this.guIdPanel = new JPanel(); 160 this.guIdPanel.setBorder(new TitledBorder( 161 "Global Unique Identifier")); 162 this.guIdPanel.setLayout(new BorderLayout()); 163 this.guIdPanel.add(this.getGuIdTextField(), BorderLayout.CENTER); 164 } 165 return guIdPanel; 166 } 167 168 /*** 169 * @return Returns the namePanel. 170 */ 171 protected JPanel getNamePanel() { 172 if (this.namePanel == null) { 173 this.namePanel = new JPanel(); 174 this.namePanel.setBorder(new TitledBorder("Name")); 175 this.namePanel.setLayout(new BorderLayout()); 176 this.namePanel.add(this.getNameTextField(), BorderLayout.CENTER); 177 } 178 return namePanel; 179 } 180 181 /*** 182 * @return Returns the securityLevelPanel. 183 */ 184 protected JPanel getSecurityLevelPanel() { 185 if (this.securityLevelPanel == null) { 186 this.securityLevelPanel = new JPanel(); 187 this.securityLevelPanel 188 .setBorder(new TitledBorder("Security Level")); 189 this.securityLevelPanel.setLayout(new BorderLayout()); 190 this.securityLevelPanel.add(this.getSecurityLevelComboBox(), 191 BorderLayout.CENTER); 192 } 193 return securityLevelPanel; 194 } 195 196 /*** 197 * @return Returns the creationDateChooser. 198 */ 199 protected JDateChooser getCreationDateChooser() { 200 if (this.creationDateChooser == null) { 201 this.creationDateChooser = new JDateChooser(); 202 this.creationDateChooser.setDate(backup.getCreationDate()); 203 this.creationDateChooser.addPropertyChangeListener( 204 "creationDateChanged", new PropertyChangeListener() { 205 206 public void propertyChange(PropertyChangeEvent arg0) { 207 logger.debug("creationDateChooser propertyChange:" 208 + arg0); 209 backup.setCreationDate(creationDateChooser 210 .getDate()); 211 212 } 213 }); 214 } 215 return creationDateChooser; 216 } 217 218 /*** 219 * @return Returns the descriptionTextArea. 220 */ 221 protected JTextArea getDescriptionTextArea() { 222 if (this.descriptionTextArea == null) { 223 this.descriptionTextArea = new JTextArea(backup.getDescription()); 224 this.descriptionTextArea.addPropertyChangeListener( 225 "descriptionChanged", new PropertyChangeListener() { 226 227 public void propertyChange(PropertyChangeEvent arg0) { 228 logger.debug("descriptionTextArea propertyChange:" 229 + arg0); 230 backup 231 .setDescription(descriptionTextArea 232 .getText()); 233 234 } 235 }); 236 } 237 return descriptionTextArea; 238 } 239 240 /*** 241 * @return Returns the expirationDateChooser. 242 */ 243 protected JDateChooser getExpirationDateChooser() { 244 if (this.expirationDateChooser == null) { 245 this.expirationDateChooser = new JDateChooser(); 246 this.expirationDateChooser.setDate(backup.getExpirationDate()); 247 this.expirationDateChooser.addPropertyChangeListener( 248 "expirationDateChanged", new PropertyChangeListener() { 249 250 public void propertyChange(PropertyChangeEvent arg0) { 251 logger 252 .debug("expirationDateChooser propertyChange:" 253 + arg0); 254 backup.setExpirationDate(expirationDateChooser 255 .getDate()); 256 257 } 258 }); 259 } 260 return expirationDateChooser; 261 } 262 263 /*** 264 * @return Returns the guIdTextField. 265 */ 266 protected JTextField getGuIdTextField() { 267 if (this.guIdTextField == null) { 268 this.guIdTextField = new JTextField(backup.getGuId()); 269 this.guIdTextField.setEditable(false); 270 this.guIdTextField.setEnabled(false); 271 } 272 return guIdTextField; 273 } 274 275 /*** 276 * @return Returns the nameTextField. 277 */ 278 protected JTextField getNameTextField() { 279 if (this.nameTextField == null) { 280 this.nameTextField = new JTextField(backup.getName()); 281 this.nameTextField.addActionListener(new ActionListener() { 282 public void actionPerformed(ActionEvent arg0) { 283 logger.debug("nameTextField actionPerformed"); 284 backup.setName(nameTextField.getText()); 285 } 286 }); 287 } 288 return nameTextField; 289 } 290 291 /*** 292 * @return Returns the securityLevelComboBox. 293 */ 294 protected JComboBox getSecurityLevelComboBox() { 295 if (this.securityLevelComboBox == null) { 296 this.securityLevelComboBox = new JComboBox(); 297 for (int i = 0; i < SecurityLevel.level.length; i++) { 298 this.securityLevelComboBox.addItem(SecurityLevel.level[i]); 299 if (ConfigurationManager.getInstance() 300 .getDefaultBackupSecurityLevel().toString() 301 .equalsIgnoreCase(SecurityLevel.level[i])) 302 this.securityLevelComboBox 303 .setSelectedItem(SecurityLevel.level[i]); 304 } 305 this.securityLevelComboBox.addActionListener(new ActionListener() { 306 public void actionPerformed(ActionEvent arg0) { 307 logger.debug("securityLevelComboBox actionPerformed"); 308 backup.setSecurityLevel(SecurityLevel 309 .fromStringToSecurityLevel(securityLevelComboBox 310 .getSelectedItem().toString())); 311 312 } 313 }); 314 } 315 return securityLevelComboBox; 316 } 317 318 /*** 319 * @return Returns the descriptionScrollPane. 320 */ 321 protected JScrollPane getDescriptionScrollPane() { 322 if (this.descriptionScrollPane == null) { 323 this.descriptionScrollPane = new JScrollPane(this 324 .getDescriptionTextArea()); 325 } 326 return descriptionScrollPane; 327 } 328 329 /*** 330 * @return Returns the filePanel. 331 */ 332 protected JPanel getFilePanel() { 333 if (this.filePanel == null) { 334 this.filePanel = new TabledFilePanel(backup); 335 } 336 return filePanel; 337 } 338 339 }