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 28 import javax.swing.JButton; 29 import javax.swing.JCheckBox; 30 import javax.swing.JLabel; 31 import javax.swing.JPanel; 32 import javax.swing.JTextField; 33 import javax.swing.border.TitledBorder; 34 35 import org.apache.log4j.Logger; 36 37 import ui.util.GeneralUtil; 38 import base.jdbs.ConfigurationManager; 39 import base.jdbs.ui.dialog.RepositorySetupDialog; 40 41 @SuppressWarnings("serial") 42 public class RepositoryConfigurationPanel extends JPanel { 43 44 private static final transient Logger logger = Logger.getLogger(RepositoryConfigurationPanel.class.getName()); 45 46 private JPanel locationPanel; 47 private JTextField locationTextField; 48 49 private JPanel declaredAvailableSpacePanel; 50 private JTextField declaredAvailableSpaceTextField; 51 52 private JPanel autoBackupExpirationPanel; 53 private JCheckBox autoBackupExpirationCheckBox; 54 55 private JPanel buttonPanel; 56 private JButton changeButton; 57 58 public RepositoryConfigurationPanel(){ 59 this.setBorder(new TitledBorder("Repository Configuration Parameters")); 60 this.setLayout(new BorderLayout()); 61 JPanel leftPanel = new JPanel(); 62 leftPanel.setLayout(new GridLayout(2,1)); 63 leftPanel.add(this.getLocationPanel()); 64 leftPanel.add(this.getDeclaredAvailableSpacePanel()); 65 this.add(leftPanel,BorderLayout.CENTER); 66 JPanel southPanel = new JPanel(); 67 southPanel.setLayout(new BorderLayout()); 68 southPanel.add(this.getButtonPanel(),BorderLayout.NORTH); 69 southPanel.add(this.getAutoBackupExpirationPanel(),BorderLayout.SOUTH); 70 this.add(southPanel,BorderLayout.SOUTH); 71 } 72 73 /*** 74 * @return the declaredAvailableSpacePanel 75 */ 76 protected JPanel getDeclaredAvailableSpacePanel() { 77 if(this.declaredAvailableSpacePanel == null){ 78 this.declaredAvailableSpacePanel = new JPanel(); 79 this.declaredAvailableSpacePanel.setBorder(new TitledBorder("Declared Available Space")); 80 this.declaredAvailableSpacePanel.setLayout(new BorderLayout()); 81 this.declaredAvailableSpacePanel.add(this.getDeclaredAvailableSpaceTextField(),BorderLayout.CENTER); 82 } 83 return declaredAvailableSpacePanel; 84 } 85 /*** 86 * @return the declaredAvailableSpaceTextField 87 */ 88 protected JTextField getDeclaredAvailableSpaceTextField() { 89 if(this.declaredAvailableSpaceTextField == null){ 90 this.declaredAvailableSpaceTextField = new JTextField(); 91 this.declaredAvailableSpaceTextField.setEditable(false); 92 this.declaredAvailableSpaceTextField.setText(""+ConfigurationManager.getInstance().getRepository().getDeclaredAvailableSpace()); 93 } 94 return declaredAvailableSpaceTextField; 95 } 96 97 /*** 98 * @return the locationPanel 99 */ 100 protected JPanel getLocationPanel() { 101 if(this.locationPanel == null){ 102 this.locationPanel = new JPanel(); 103 this.locationPanel.setBorder(new TitledBorder("Location")); 104 this.locationPanel.setLayout(new BorderLayout()); 105 this.locationPanel.add(this.getLocationTextField(),BorderLayout.CENTER); 106 } 107 return locationPanel; 108 } 109 /*** 110 * @return the locationTextField 111 */ 112 protected JTextField getLocationTextField() { 113 if(this.locationTextField == null){ 114 this.locationTextField = new JTextField(); 115 this.locationTextField.setEditable(false); 116 this.locationTextField.setText(ConfigurationManager.getInstance().getRepository().getLocation().getAbsolutePath()); 117 } 118 return locationTextField; 119 } 120 121 /*** 122 * @return Returns the buttonPanel. 123 */ 124 protected JPanel getButtonPanel() { 125 if(this.buttonPanel == null){ 126 this.buttonPanel = new JPanel(); 127 this.buttonPanel.setLayout(new GridLayout(1,3)); 128 this.buttonPanel.add(new JLabel()); 129 this.buttonPanel.add(this.getChangeButton()); 130 this.buttonPanel.add(new JLabel()); 131 } 132 return buttonPanel; 133 } 134 135 /*** 136 * @return Returns the changeButton. 137 */ 138 protected JButton getChangeButton() { 139 if(this.changeButton == null){ 140 this.changeButton = new JButton("Setup"); 141 this.changeButton.addActionListener(new ActionListener(){ 142 143 public void actionPerformed(ActionEvent arg0) { 144 RepositorySetupDialog repositorySetupDialog = new RepositorySetupDialog(); 145 repositorySetupDialog.setModal(true); 146 GeneralUtil.centerComponent(repositorySetupDialog); 147 repositorySetupDialog.setVisible(true); 148 } 149 150 }); 151 } 152 return changeButton; 153 } 154 155 /*** 156 * @return Returns the autoBackupExpirationCheckBox. 157 */ 158 protected JCheckBox getAutoBackupExpirationCheckBox() { 159 if(this.autoBackupExpirationCheckBox == null){ 160 this.autoBackupExpirationCheckBox = new JCheckBox(); 161 } 162 return autoBackupExpirationCheckBox; 163 } 164 165 /*** 166 * @return Returns the autoBackupExpirationPanel. 167 */ 168 protected JPanel getAutoBackupExpirationPanel() { 169 if(this.autoBackupExpirationPanel == null){ 170 this.autoBackupExpirationPanel = new JPanel(); 171 this.autoBackupExpirationPanel.setBorder(new TitledBorder("Automatically Purge Expired Backups")); 172 this.autoBackupExpirationPanel.setLayout(new BorderLayout()); 173 this.autoBackupExpirationPanel.add(this.getAutoBackupExpirationCheckBox(),BorderLayout.CENTER); 174 } 175 return autoBackupExpirationPanel; 176 } 177 178 }