1 18 package sync4j.syncclient.ipod.panels; 19 20 import java.util.Hashtable ; 21 22 import java.awt.Color ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 26 import javax.swing.JDialog ; 27 import javax.swing.JPanel ; 28 import javax.swing.JButton ; 29 import javax.swing.UIManager ; 30 import javax.swing.JLabel ; 31 import javax.swing.JTextField ; 32 import javax.swing.JPasswordField ; 33 import javax.swing.border.*; 34 import javax.swing.SwingConstants ; 35 36 import sync4j.syncclient.ipod.MainWindow; 37 import sync4j.syncclient.ipod.utils.*; 38 39 45 public class CommunicationSetPanel extends JDialog 46 implements ActionListener , Constants { 47 48 private Hashtable htFields = new Hashtable (); 50 private MainWindow mainWindow ; 51 private JPanel jpOver ; 52 private JPanel jpUp ; 53 private JLabel jLabel1 ; 54 private JLabel jLabel2 ; 55 private JLabel jLabel3 ; 56 private JLabel jLabel4 ; 57 private JTextField jtServerURL; 58 private JTextField jtUsername ; 59 private JTextField jtDeviceId ; 60 private JPasswordField jpPassword; 61 private JButton btOk ; 62 private JButton btCancel; 63 64 66 67 public CommunicationSetPanel(MainWindow mainWindow, boolean modal) { 68 super(mainWindow, modal); 69 this.mainWindow = mainWindow; 70 71 htFields = mainWindow.getSyncmlValues(); 72 73 initComponents(); 74 setCommunicationConfigStored(); 75 } 76 77 81 private void initComponents() { 82 int xlab = 18 ; 83 int wlab = 90 ; 84 int hlab = 21 ; 85 int xtext = 130; 86 int wtext = 222; 87 int htext = 21 ; 88 int ybt = 147; 89 int wbt = 88 ; 90 int hbt = 24 ; 91 int y = 26 ; 92 int dy = 24 ; 93 94 jLabel1 = new JLabel (); 95 jLabel2 = new JLabel (); 96 jLabel3 = new JLabel (); 97 jLabel4 = new JLabel (); 98 jpOver = new JPanel (); 99 jpUp = new JPanel (); 100 jtServerURL = new JTextField (); 101 jtUsername = new JTextField (); 102 jtDeviceId = new JTextField (); 103 jpPassword = new JPasswordField (); 104 btOk = new JButton (); 105 btCancel = new JButton (); 106 107 try { 108 UIManager.setLookAndFeel(lookAndFeel); 109 } catch(Exception e) { 110 e.printStackTrace(); 111 } 112 113 getContentPane().setLayout(null); 117 118 setTitle(Language.getMessage(Language.LABEL_TITLE_COMMUNICATION)); 119 setBackground(Color.WHITE); 120 setForeground(Color.WHITE); 121 setFont(font); 122 setName("commSetDialog"); 123 setResizable(false); 124 setSize(400,214); 125 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 126 setLocationRelativeTo(null); 127 128 jpOver.setLayout(null); 129 jpOver.setBackground(Color.WHITE); 130 jpOver.setForeground(Color.WHITE); 131 jpOver.setBounds(0, 0, 400, 214); 132 getContentPane().add(jpOver); 133 134 jpUp.setLayout(null); 138 jpUp.setBounds(8, 12, 371, 132); 139 jpUp.setBackground(Color.WHITE); 140 jpUp.setBorder(new TitledBorder( 141 new LineBorder(new Color (204,204,204), 1, true), 142 Language.getMessage(Language.LABEL_TITLE_COMMUNICATION), 143 1, 144 0, 145 font, 146 new Color (0,51,204)) 147 ); 148 jpUp.setName("commSet"); 149 150 jLabel1.setText(Language.getMessage(Language.LABEL_COMM_SERVERURL)); 151 jLabel1.setFont(font); 152 jLabel1.setBounds(xlab, y, wlab, hlab); 153 jLabel1.setVerticalAlignment(SwingConstants.CENTER); 154 jpUp.add(jLabel1); 155 156 jtServerURL.setText(""); 157 jtServerURL.setFont(font); 158 jtServerURL.setBounds(xtext, 26, wtext, htext); 159 jtServerURL.requestFocusInWindow(); 160 jpUp.add(jtServerURL); 161 162 y += dy; 163 164 jLabel2.setText(Language.getMessage(Language.LABEL_COMM_USERNAME)); 165 jLabel2.setFont(font); 166 jLabel2.setBounds(xlab, y, wlab, hlab); 167 jLabel2.setVerticalAlignment(SwingConstants.CENTER); 168 jpUp.add(jLabel2); 169 170 jtUsername.setText(""); 171 jtUsername.setFont(font); 172 jtUsername.setBounds(xtext, 50, wtext, htext); 173 jpUp.add(jtUsername); 174 175 y += dy; 176 177 jLabel3.setText(Language.getMessage(Language.LABEL_COMM_PASSWORD)); 178 jLabel3.setBounds(xlab, y, wlab, hlab); 179 jLabel3.setFont(font); 180 jLabel3.setVerticalAlignment(SwingConstants.CENTER); 181 jpUp.add(jLabel3); 182 183 jpPassword.setText(""); 184 jpPassword.setFont(font); 185 jpPassword.setBounds(xtext, 74, wtext, htext); 186 jpUp.add(jpPassword); 187 188 y += dy; 189 190 jLabel4.setText(Language.getMessage(Language.LABEL_COMM_DEVICEID)); 191 jLabel4.setBounds(xlab, y, wlab, hlab); 192 jLabel4.setFont(font); 193 jLabel4.setVerticalAlignment(SwingConstants.CENTER); 194 jpUp.add(jLabel4); 195 196 jtDeviceId.setText(""); 197 jtDeviceId.setFont(font); 198 jtDeviceId.setBounds(xtext, 98, wtext, htext); 199 jtDeviceId.setEditable(false); 200 jpUp.add(jtDeviceId); 201 202 jpOver.add(jpUp); 203 204 btOk.setText(Language.getMessage(Language.BT_OK)); 205 btOk.setActionCommand("OK"); 206 btOk.setName("btOk"); 207 btOk.setFont(font); 208 btOk.setBounds(198, ybt, wbt, hbt); 209 btOk.addActionListener(this); 210 211 jpOver.add(btOk); 212 213 btCancel.setText(Language.getMessage(Language.BT_CANCEL)); 214 btCancel.setActionCommand("CANCEL"); 215 btCancel.setName("btCancel"); 216 btCancel.setBounds(292, ybt, wbt, hbt); 217 btCancel.setFont(font); 218 btCancel.addActionListener(this); 219 jpOver.add(btCancel); 220 221 jtServerURL.setNextFocusableComponent(jtUsername); 222 jtUsername.setNextFocusableComponent(jpPassword) ; 223 jpPassword.setNextFocusableComponent(jtDeviceId) ; 224 jtDeviceId.setNextFocusableComponent(btOk) ; 225 btOk.setNextFocusableComponent(btCancel) ; 226 btCancel.setNextFocusableComponent(jtServerURL) ; 227 } 228 229 public void actionPerformed(ActionEvent evt) { 230 if (evt.getActionCommand().equals("OK")) { 231 htFields.put(PARAM_SYNCMLURL, jtServerURL.getText()); 232 htFields.put(PARAM_USERNAME , jtUsername.getText()); 233 htFields.put(PARAM_PASSWORD , new String (jpPassword.getPassword())); 234 htFields.put(PARAM_DEVICEID , jtDeviceId.getText()); 235 236 mainWindow.writeCommunicationSettings(htFields); 237 removeAll(); 238 setVisible(false); 239 } else if (evt.getActionCommand().equals("CANCEL")) { 240 removeAll(); 241 setVisible(false); 242 } 243 } 244 245 249 private void setCommunicationConfigStored() { 250 jtServerURL.setText((String )htFields.get(PARAM_SYNCMLURL)); 251 jtUsername.setText ((String )htFields.get(PARAM_USERNAME) ); 252 jpPassword.setText ((String )htFields.get(PARAM_PASSWORD) ); 253 jtDeviceId.setText ((String )htFields.get(PARAM_DEVICEID) ); 254 } 255 256 } 257 | Popular Tags |