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.JComboBox; 29 import javax.swing.JPanel; 30 import javax.swing.border.TitledBorder; 31 32 import org.apache.log4j.Logger; 33 34 import base.jdbs.ConfigurationManager; 35 import base.jdbs.NetworkConnectionType; 36 37 /*** 38 * @author skunk 39 * 40 */ 41 @SuppressWarnings("serial") 42 public class NetworkConfigurationPanel extends JPanel { 43 44 private static final transient Logger logger = Logger 45 .getLogger(NetworkConfigurationPanel.class.getName()); 46 47 /*** 48 * This is the panel where will be shown the default replication level for 49 * each created backup artifact.* 50 */ 51 private JPanel replicationLevelPanel; 52 53 private JComboBox replicationLevelComboBox; 54 55 /*** 56 * This is the defalut number of upload slots to be grant to other jdbs 57 * users.* 58 */ 59 private JPanel uploadSlotPanel; 60 61 private JComboBox uploadSlotComboBox; 62 63 /*** This is the default number of download slots to be grant to the peer.* */ 64 private JPanel downloadSlotPanel; 65 66 private JComboBox downloadSlotComboBox; 67 68 /*** This is the peer connection type, one between LAN T1, T2, 56Kb etc...* */ 69 private JPanel connectionTypePanel; 70 71 private JComboBox connectionTypeComboBox; 72 73 public NetworkConfigurationPanel() { 74 initialize(); 75 } 76 77 protected void initialize() { 78 this.setBorder(new TitledBorder("Network Configuration Paramenters")); 79 this.setLayout(new GridLayout(4, 1)); 80 this.add(this.getReplicationLevelPanel()); 81 this.add(this.getUploadSlotPanel()); 82 this.add(this.getDownloadSlotPanel()); 83 this.add(this.getConnectionTypePanel()); 84 } 85 86 /*** 87 * @return the downloadSlotComboBox 88 */ 89 protected JComboBox getDownloadSlotComboBox() { 90 if (this.downloadSlotComboBox == null) { 91 this.downloadSlotComboBox = new JComboBox(); 92 for (int i = 0; i < 10; i++) 93 this.downloadSlotComboBox.addItem(i); 94 } 95 return downloadSlotComboBox; 96 } 97 98 /*** 99 * @return the downloadSlotPanel 100 */ 101 protected JPanel getDownloadSlotPanel() { 102 if (this.downloadSlotPanel == null) { 103 this.downloadSlotPanel = new JPanel(); 104 this.downloadSlotPanel.setBorder(new TitledBorder( 105 "Download Slots (0 = infinite)")); 106 this.downloadSlotPanel.setLayout(new BorderLayout()); 107 this.downloadSlotPanel.add(this.getDownloadSlotComboBox()); 108 } 109 return downloadSlotPanel; 110 } 111 112 /*** 113 * @return the replicationLevelComboBox 114 */ 115 protected JComboBox getReplicationLevelComboBox() { 116 if (this.replicationLevelComboBox == null) { 117 this.replicationLevelComboBox = new JComboBox(); 118 for (int i = 0; i < 10; i++) 119 this.replicationLevelComboBox.addItem(i); 120 this.replicationLevelComboBox.setSelectedItem(5); 121 } 122 return replicationLevelComboBox; 123 } 124 125 /*** 126 * @return the replicationLevelPanel 127 */ 128 protected JPanel getReplicationLevelPanel() { 129 if (this.replicationLevelPanel == null) { 130 this.replicationLevelPanel = new JPanel(); 131 this.replicationLevelPanel.setBorder(new TitledBorder( 132 "Replication Level")); 133 this.replicationLevelPanel.setLayout(new BorderLayout()); 134 this.replicationLevelPanel.add(this.getReplicationLevelComboBox()); 135 } 136 return replicationLevelPanel; 137 } 138 139 /*** 140 * @return the uploadSlotComboBox 141 */ 142 protected JComboBox getUploadSlotComboBox() { 143 if (this.uploadSlotComboBox == null) { 144 this.uploadSlotComboBox = new JComboBox(); 145 for (int i = 0; i < 10; i++) 146 this.uploadSlotComboBox.addItem(i); 147 } 148 return uploadSlotComboBox; 149 } 150 151 /*** 152 * @return the uploadSlotPanel 153 */ 154 protected JPanel getUploadSlotPanel() { 155 if (this.uploadSlotPanel == null) { 156 this.uploadSlotPanel = new JPanel(); 157 this.uploadSlotPanel.setBorder(new TitledBorder( 158 "Upload Slots (0 = infinite)")); 159 this.uploadSlotPanel.setLayout(new BorderLayout()); 160 this.uploadSlotPanel.add(this.getUploadSlotComboBox()); 161 } 162 return uploadSlotPanel; 163 } 164 165 /*** 166 * @return Returns the connectionTypeComboBox. 167 */ 168 protected JComboBox getConnectionTypeComboBox() { 169 if (this.connectionTypeComboBox == null) { 170 this.connectionTypeComboBox = new JComboBox(); 171 for (int i = 0; i < NetworkConnectionType.type.length; i++) { 172 this.connectionTypeComboBox 173 .addItem(NetworkConnectionType.type[i]); 174 } 175 this.connectionTypeComboBox.setSelectedItem(NetworkConnectionType 176 .fromConnectionTypeToString(ConfigurationManager 177 .getInstance().getNetworkConnectionType())); 178 this.connectionTypeComboBox.addActionListener(new ActionListener() { 179 180 public void actionPerformed(ActionEvent arg0) { 181 ConfigurationManager 182 .getInstance() 183 .setNetworkConnectionType( 184 NetworkConnectionType 185 .fromStringToConnectionType(connectionTypeComboBox 186 .getSelectedItem() 187 .toString())); 188 } 189 }); 190 } 191 return connectionTypeComboBox; 192 } 193 194 /*** 195 * @return Returns the connectionTypePanel. 196 */ 197 protected JPanel getConnectionTypePanel() { 198 if (this.connectionTypePanel == null) { 199 this.connectionTypePanel = new JPanel(); 200 this.connectionTypePanel.setBorder(new TitledBorder( 201 "Connection Type")); 202 this.connectionTypePanel.setLayout(new BorderLayout()); 203 this.connectionTypePanel.add(this.getConnectionTypeComboBox(), 204 BorderLayout.CENTER); 205 } 206 return connectionTypePanel; 207 } 208 }