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.gift.gui;
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.FilePanel;
31  import org.xnap.gui.component.ValidatedTextField;
32  import org.xnap.gui.util.GUIHelper;
33  import org.xnap.gui.util.GridBagHelper;
34  import org.xnap.plugin.gift.GiFTPlugin;
35  import org.xnap.plugin.gift.util.GiFTPreferences;
36  
37  public class GiFTPreferencesPanel extends AbstractSettingsPanel
38  {
39  
40      //--- Data Field(s) ----
41  
42  
43  	private static GiFTPreferences prefs = GiFTPreferences.getInstance();
44  
45  	private FilePanel fpGiftDaemon;
46  	private ValidatedTextField jteHttpPort;
47      private JTextField jteGiftHost;
48      private ValidatedTextField jteGiftPort;
49  	private JCheckBox jcbStartEngine;
50  	private JCheckBox jcbAutoConnect;
51  
52      
53      //--- Constructor(s) ---
54  
55      public GiFTPreferencesPanel()
56      {
57  		setLayout(new GridBagLayout());
58  
59  		JPanel jpCommand = new JPanel(new GridBagLayout());
60  		jpCommand.setBorder(GUIHelper.createDefaultBorder(XNap.tr("Daemon Command")));
61  		GridBagHelper.add(this, jpCommand);
62  
63  		fpGiftDaemon = new FilePanel(prefs.getGiftDaemon(), 20);
64  		GridBagHelper.add(jpCommand, fpGiftDaemon);
65  
66  		jcbStartEngine = new JCheckBox(XNap.tr("Launch giFT on Startup"),
67  									   prefs.getStartDaemon());
68  		GridBagHelper.add(jpCommand, jcbStartEngine);
69  
70  		JPanel jpDaemon = new JPanel(new GridBagLayout());
71  		jpDaemon.setBorder(GUIHelper.createDefaultBorder(XNap.tr("Daemon")));
72  		GridBagHelper.add(this, jpDaemon);
73  
74          JLabel l = GridBagHelper.addLabel(jpDaemon, XNap.tr("Host"));
75          jteGiftHost = new JTextField(prefs.getGiftHost(), 20);
76  		l.setLabelFor(jteGiftHost);
77          GridBagHelper.add(jpDaemon, jteGiftHost, false);	
78  
79          l = GridBagHelper.addLabel(jpDaemon, XNap.tr("Port"));
80          jteGiftPort = new ValidatedTextField(prefs.getDaemonPort() + "",
81  											 5,ValidatedTextField.NUMBERS_INT);
82  		l.setLabelFor(jteGiftPort);
83          GridBagHelper.add(jpDaemon, jteGiftPort, false);
84  
85  		l = GridBagHelper.addLabel(jpDaemon, XNap.tr("HTTP Port"));
86  		jteHttpPort = new ValidatedTextField(prefs.getHttpPort() + "",
87  											 5,ValidatedTextField.NUMBERS_INT);
88  		l.setLabelFor(jteHttpPort);
89  		GridBagHelper.add(jpDaemon, jteHttpPort, false);
90  
91  		jcbAutoConnect = new JCheckBox
92  			(XNap.tr("Connect to giFT on Startup", 1), prefs.getAutoconnect());
93  		GridBagHelper.add(jpDaemon, jcbAutoConnect);
94  
95  		GridBagHelper.addVerticalSpacer(this);
96  		GUIHelper.setMnemonics(this);
97      }
98  
99      //--- Method(s) ---
100 
101     public void apply()
102     {
103 		prefs.setGiftDaemon(fpGiftDaemon.getFilename());
104 		prefs.setGiftHost(jteGiftHost.getText());
105 		prefs.setDaemonPort(jteGiftPort.getIntValue());
106 		prefs.setHttpPort(jteHttpPort.getIntValue());
107 		prefs.setAutoconnect(jcbAutoConnect.isSelected());
108 		prefs.setStartDaemon(jcbStartEngine.isSelected());
109 
110     }
111 
112     public String getTitle()
113     {
114 		return GiFTPlugin.getInstance().getInfo().getName();
115     }
116 
117 	/***
118 	 * @see xnap.gui.SettingsPanel#getDescription()
119 	 */
120 	public String getDescription() 
121 	{
122 		return XNap.tr("giFT settings");
123 	}
124 
125 }
126 
127