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.opennap.gui;
21  
22  import java.awt.Component;
23  import java.awt.GridBagLayout;
24  
25  import javax.swing.JLabel;
26  import javax.swing.JPanel;
27  import javax.swing.JScrollPane;
28  import javax.swing.JTextArea;
29  
30  import org.xnap.XNap;
31  import org.xnap.gui.AbstractSettingsPanel;
32  import org.xnap.gui.action.EnableAction;
33  import org.xnap.gui.component.MultiLineLabel;
34  import org.xnap.gui.component.ValidatedTextField;
35  import org.xnap.gui.component.XNapCheckBox;
36  import org.xnap.gui.util.GUIHelper;
37  import org.xnap.gui.util.GridBagHelper;
38  import org.xnap.plugin.opennap.OpenNapPlugin;
39  import org.xnap.plugin.opennap.util.OpenNapPreferences;
40  
41  public class OpenNapServerPreferencesPanel extends AbstractSettingsPanel {
42  
43      //--- Data Field(s) ----
44  
45      private OpenNapPreferences napPrefs = OpenNapPlugin.getPreferences();
46  
47  	private EnableAction autoFetchNapigatorAction;
48  	private ValidatedTextField autoFetchNapigatorIntervalTextField;
49  	private JTextArea serverListTextArea;
50  	
51      //--- Constructor(s) ---
52  
53      public OpenNapServerPreferencesPanel()
54      {
55  		setLayout(new GridBagLayout());
56  
57  		JPanel jpStartup = new JPanel(new GridBagLayout());
58  		jpStartup.setBorder(GUIHelper.createDefaultBorder
59  							(XNap.tr("Server List")));
60  		GridBagHelper.add(this, jpStartup);
61  
62  		GridBagHelper.add(jpStartup, new MultiLineLabel(XNap.tr("XNap can fetch lists of OpenNap server addresses. These lists are provided by service providers that are not affiliated with the XNap project.")));
63  		
64  		serverListTextArea = new JTextArea(napPrefs.getNapigatorURL(), 5, 40);
65  		GridBagHelper.add(jpStartup, new JScrollPane(serverListTextArea));
66  		
67          autoFetchNapigatorIntervalTextField = new ValidatedTextField
68  			(napPrefs.getAutoFetchNapigatorInterval() + "", 5, 
69  			 ValidatedTextField.NUMBERS_INT);
70  		autoFetchNapigatorAction
71  			= new EnableAction
72  				(XNap.tr("Refresh lists every"),
73  				 new Component[] { autoFetchNapigatorIntervalTextField },
74  				 napPrefs.getAutoFetchNapigator());
75  		GridBagHelper.addComponent
76  			(jpStartup, new XNapCheckBox(autoFetchNapigatorAction));
77  		GridBagHelper.addComponent
78  			(jpStartup, autoFetchNapigatorIntervalTextField);
79  		GridBagHelper.addLabel(jpStartup, XNap.tr("hours"));
80  		// XXX: workaroung to ensure left alignment
81  		GridBagHelper.add(jpStartup, new JLabel());
82  
83  		GridBagHelper.addVerticalSpacer(this);
84  		GUIHelper.setMnemonics(this);
85      }
86  
87      //--- Method(s) ---
88  
89      public void apply()
90      {
91      	napPrefs.setNapigatorURL(serverListTextArea.getText());
92  		napPrefs.setAutoFetchNapigator(autoFetchNapigatorAction.isSelected());
93  		napPrefs.setAutoFetchNapigatorInterval
94  			(autoFetchNapigatorIntervalTextField.getIntValue());
95      }
96  
97      public String getTitle()
98      {
99  		return XNap.tr("Server List");
100     }
101 
102 }