KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > ipod > panels > CommunicationSetPanel


1 /**
2  * Copyright (C) 2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package sync4j.syncclient.ipod.panels;
19
20 import java.util.Hashtable JavaDoc;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25
26 import javax.swing.JDialog JavaDoc;
27 import javax.swing.JPanel JavaDoc;
28 import javax.swing.JButton JavaDoc;
29 import javax.swing.UIManager JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.JTextField JavaDoc;
32 import javax.swing.JPasswordField JavaDoc;
33 import javax.swing.border.*;
34 import javax.swing.SwingConstants JavaDoc;
35
36 import sync4j.syncclient.ipod.MainWindow;
37 import sync4j.syncclient.ipod.utils.*;
38
39 /**
40  * The Communication settings window.
41  *
42  * @author Luigia Fassina @ Funambol
43  * @version $Id: CommunicationSetPanel.java,v 1.4 2005/04/04 16:15:23 luigiafassina Exp $
44  */

45 public class CommunicationSetPanel extends JDialog JavaDoc
46 implements ActionListener JavaDoc, Constants JavaDoc {
47
48     // ------------------------------------------- Private Data
49
private Hashtable JavaDoc htFields = new Hashtable JavaDoc();
50     private MainWindow mainWindow ;
51     private JPanel JavaDoc jpOver ;
52     private JPanel JavaDoc jpUp ;
53     private JLabel JavaDoc jLabel1 ;
54     private JLabel JavaDoc jLabel2 ;
55     private JLabel JavaDoc jLabel3 ;
56     private JLabel JavaDoc jLabel4 ;
57     private JTextField JavaDoc jtServerURL;
58     private JTextField JavaDoc jtUsername ;
59     private JTextField JavaDoc jtDeviceId ;
60     private JPasswordField JavaDoc jpPassword;
61     private JButton JavaDoc btOk ;
62     private JButton JavaDoc btCancel;
63
64     // ------------------------------------------ Public Methods
65

66     /** Creates new form JDialog */
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     /**
78      * This method is called from within the constructor to
79      * initialize the form.
80      */

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 JavaDoc();
95         jLabel2 = new JLabel JavaDoc();
96         jLabel3 = new JLabel JavaDoc();
97         jLabel4 = new JLabel JavaDoc();
98         jpOver = new JPanel JavaDoc();
99         jpUp = new JPanel JavaDoc();
100         jtServerURL = new JTextField JavaDoc();
101         jtUsername = new JTextField JavaDoc();
102         jtDeviceId = new JTextField JavaDoc();
103         jpPassword = new JPasswordField JavaDoc();
104         btOk = new JButton JavaDoc();
105         btCancel = new JButton JavaDoc();
106
107         try {
108             UIManager.setLookAndFeel(lookAndFeel);
109         } catch(Exception JavaDoc e) {
110             e.printStackTrace();
111         }
112
113         //
114
// Set up the window.
115
//
116
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         //
135
// Internal panel for Remote Settings
136
//
137
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 JavaDoc(204,204,204), 1, true),
142                             Language.getMessage(Language.LABEL_TITLE_COMMUNICATION),
143                             1,
144                             0,
145                             font,
146                             new Color JavaDoc(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 JavaDoc 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 JavaDoc(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     /**
246      * Sets the fields with some of the values contained
247      * in the specified Hashtables.
248      */

249     private void setCommunicationConfigStored() {
250         jtServerURL.setText((String JavaDoc)htFields.get(PARAM_SYNCMLURL));
251         jtUsername.setText ((String JavaDoc)htFields.get(PARAM_USERNAME) );
252         jpPassword.setText ((String JavaDoc)htFields.get(PARAM_PASSWORD) );
253         jtDeviceId.setText ((String JavaDoc)htFields.get(PARAM_DEVICEID) );
254     }
255
256 }
257
Popular Tags