View Javadoc
1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.joscar;
21  
22  import java.awt.GridBagLayout;
23  
24  import javax.swing.*;
25  import javax.swing.JPanel;
26  import javax.swing.JTextField;
27  
28  import org.xnap.XNap;
29  import org.xnap.gui.AbstractSettingsPanel;
30  import org.xnap.gui.component.ValidatedTextField;
31  import org.xnap.gui.util.GUIHelper;
32  import org.xnap.gui.util.GridBagHelper;
33  
34  public class JOscarPreferencesPanel extends AbstractSettingsPanel
35  {
36  
37      //--- Data Field(s) ----
38  
39  	private JOscarPreferences prefs = JOscarPreferences.getInstance();
40  
41      private JTextField jteServerHost;
42      private ValidatedTextField jteServerPort;
43  
44      private JTextField jteUsername;
45  	private JTextField jtePassword;
46      private JCheckBox jcAutoConnect;
47      
48      //--- Constructor(s) ---
49  
50      public JOscarPreferencesPanel()
51      {
52  		setLayout(new GridBagLayout());
53  
54  		JPanel jpServer = new JPanel(new GridBagLayout());
55  		jpServer.setBorder(GUIHelper.createDefaultBorder(XNap.tr("Server")));
56  		GridBagHelper.add(this, jpServer);
57  
58          JLabel l = GridBagHelper.addLabel(jpServer, XNap.tr("Host"));
59          jteServerHost = new JTextField(prefs.getServerHost(), 20);
60  		l.setLabelFor(jteServerHost);
61          GridBagHelper.add(jpServer, jteServerHost, false);	
62  
63          l = GridBagHelper.addLabel(jpServer, XNap.tr("Port"));
64          jteServerPort = new ValidatedTextField(prefs.getServerPort() + "",
65  											 5,ValidatedTextField.NUMBERS_INT);
66  		l.setLabelFor(jteServerPort);
67          GridBagHelper.add(jpServer, jteServerPort, false);
68  
69  
70  		JPanel jpLogin = new JPanel(new GridBagLayout());
71  		jpLogin.setBorder(GUIHelper.createDefaultBorder(XNap.tr("Login")));
72  		GridBagHelper.add(this, jpLogin);
73  
74  		l = GridBagHelper.addLabel(jpLogin, XNap.tr("UIN"));
75          jteUsername = new JTextField(prefs.getUsername(), 20);
76  		l.setLabelFor(jteUsername);
77          GridBagHelper.add(jpLogin, jteUsername, false);	
78  
79          l = GridBagHelper.addLabel(jpLogin, XNap.tr("Password"));
80          jtePassword = new JTextField(prefs.getPassword(), 20);
81  		l.setLabelFor(jtePassword);
82          GridBagHelper.add(jpLogin, jtePassword, false);	
83  
84  
85  		jcAutoConnect  = new JCheckBox(XNap.tr("Connect on startup"), 
86  										 prefs.getAutoconnect());
87  		GridBagHelper.add(this, jcAutoConnect);
88  		
89  		GridBagHelper.addVerticalSpacer(this);
90  		GUIHelper.setMnemonics(this);
91      }
92  
93      //--- Method(s) ---
94  
95      public void apply()
96      {
97    		prefs.setServerHost(jteServerHost.getText());
98    		prefs.setServerPort(jteServerPort.getIntValue());
99  		prefs.setUsername(jteUsername.getText());
100 		prefs.setPassword(jtePassword.getText());
101 		prefs.setAutoconnect(jcAutoConnect.isSelected());
102     }
103 
104     public String getTitle()
105     {
106 		return JOscarPlugin.getInstance().getName();
107     }
108 
109 	/***
110 	 * @see xnap.gui.SettingsPanel#getDescription()
111 	 */
112 	public String getDescription() {
113 		return XNap.tr("ICQ Settings");
114 	}
115 
116 }
117