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 javax.swing.JCheckBox;
23  import javax.swing.JPanel;
24  import javax.swing.JTextField;
25  
26  import java.awt.Component;
27  import java.awt.GridBagLayout;
28  
29  import org.xnap.XNap;
30  import org.xnap.gui.AbstractSettingsPanel;
31  import org.xnap.gui.action.EnableAction;
32  import org.xnap.gui.component.*;
33  import org.xnap.gui.util.*;
34  import org.xnap.gui.component.XNapCheckBox;
35  import org.xnap.gui.util.GUIHelper;
36  import org.xnap.gui.util.GridBagHelper;
37  import org.xnap.plugin.opennap.OpenNapPlugin;
38  import org.xnap.plugin.opennap.util.OpenNapPreferences;
39  
40  public class OpenNapAdvancedPreferencesPanel extends AbstractSettingsPanel {
41  
42      //--- Data Field(s) ----
43  
44      private OpenNapPreferences napPrefs = OpenNapPlugin.getPreferences();
45  
46      private JCheckBox jcbCustomizeClientInfo;
47      private JTextField jteClient;
48  
49      private JCheckBox jcbLimitSharesPerServer;
50      private ValidatedTextField jteMaxSharesPerServer;
51      private JCheckBox jcSendWholeRepository;
52  
53      private ValidatedTextField jtMaxResults;
54      private JCheckBox jcbMaxResults;
55  
56  	private JCheckBox multiSourceCheckBox;
57  
58  	private JCheckBox utf8CheckBox;
59  
60      //--- Constructor(s) ---
61  
62      public OpenNapAdvancedPreferencesPanel()
63      {
64  		setLayout(new GridBagLayout());
65  
66  		// client info
67  		JPanel jpClientInfo = new JPanel(new GridBagLayout());
68  		jpClientInfo.setBorder(GUIHelper.createDefaultBorder(XNap.tr("Client Info")));
69  		GridBagHelper.add(this, jpClientInfo);
70          jteClient = new JTextField(napPrefs.getClientInfo(), 20);
71  		EnableAction ac 
72  			= new EnableAction(XNap.tr("Customize"), new Component[] 
73  				{ jteClient }, napPrefs.getCustomizeClientInfo());
74  		jcbCustomizeClientInfo = new XNapCheckBox(ac);
75  		GridBagHelper.addComponent(jpClientInfo, jcbCustomizeClientInfo);
76  		GridBagHelper.add(jpClientInfo, jteClient);
77  
78  		// limit number of shared files per server
79  		JPanel jpLimitShares = new JPanel(new GridBagLayout());
80  		jpLimitShares.setBorder
81  			(GUIHelper.createDefaultBorder(XNap.tr("Shares Per Server")));
82  		GridBagHelper.add(this, jpLimitShares);
83  
84          jteMaxSharesPerServer = new ValidatedTextField
85  			(napPrefs.getMaxSharesPerServer() + "", 5,
86  			 ValidatedTextField.NUMBERS_INT);
87  		ac = new EnableAction(XNap.tr("Limit Shares Per Server"), 
88  							  new Component[] { jteMaxSharesPerServer }, 
89  							  napPrefs.getLimitSharesPerServer());
90  		jcbLimitSharesPerServer = new XNapCheckBox(ac);
91  
92  		GridBagHelper.addComponent(jpLimitShares, jcbLimitSharesPerServer);
93  		GridBagHelper.add(jpLimitShares, jteMaxSharesPerServer, false);
94  
95  		jcSendWholeRepository = new JCheckBox
96  			(XNap.tr("Send whole repository on direct browse.", 1), 
97  			 napPrefs.getSendWholeRepository());
98  		GridBagHelper.add(jpLimitShares, jcSendWholeRepository);
99  			
100 		// max search results per servers
101 		JPanel jpMaxResults = new JPanel(new GridBagLayout());
102 		jpMaxResults.setBorder(GUIHelper.createDefaultBorder
103 			(XNap.tr("Maximum Search Results Per Server", 1)));
104 		GridBagHelper.add(this, jpMaxResults);
105 
106 		jtMaxResults = 
107 			new ValidatedTextField
108 				(napPrefs.getMaxSearchResultsPerServer() + "", 5, 
109 				 ValidatedTextField.NUMBERS_INT);
110 		ac = new EnableAction(XNap.tr("Limit Search Results Per Server"),
111 							  new Component[] { jtMaxResults },
112 							  napPrefs.getLimitSearchResultsPerServer());
113 		jcbMaxResults = new XNapCheckBox(ac);
114 		GridBagHelper.addComponent(jpMaxResults, jcbMaxResults);
115 		GridBagHelper.add(jpMaxResults, jtMaxResults, false);
116 
117 		// multi-source downloading
118 		JPanel multiSourcePanel = new JPanel(new GridBagLayout());
119 		GridBagHelper.add(this, multiSourcePanel);
120 
121 		multiSourcePanel.setBorder(GUIHelper.createDefaultBorder
122 			(XNap.tr("Multi Source Downloads", 1)));
123 		GridBagHelper.add(multiSourcePanel, new MultiLineLabel
124 			(XNap.tr("Please note that multi-source downloads are still in the early testing stage. Your downloads may get corrupted, XNap may get locked up or other funny things can happen. Use with caution.")));
125 		GridBagHelper.add(multiSourcePanel, new MultiLineLabel
126 			(XNap.tr("You need to restart the running transfers for the setting to take effect.")));
127 		multiSourceCheckBox = new JCheckBox
128 			(XNap.tr("Multi-source downloading"), 
129 			 napPrefs.getMultiSourceDownloading());
130 		GridBagHelper.add(multiSourcePanel, multiSourceCheckBox);
131 
132 		utf8CheckBox = new JCheckBox(XNap.tr("Use UTF-8 encoding"),
133 									 napPrefs.getUseUTF8Encoding());
134 		GridBagHelper.add(this, utf8CheckBox);
135 
136 		GridBagHelper.addVerticalSpacer(this);
137 		GUIHelper.setMnemonics(this);
138     }
139 
140     //--- Method(s) ---
141 	
142     public void apply()
143     {
144 		napPrefs.setCustomizeClientInfo(jcbCustomizeClientInfo.isSelected());
145 		napPrefs.setClientInfo(jteClient.getText().trim());
146 
147 		napPrefs.setLimitSharesPerServer(jcbLimitSharesPerServer.isSelected());
148 		napPrefs.setMaxSharesPerServer(jteMaxSharesPerServer.getIntValue());
149 		napPrefs.setSendWholeRepository(jcSendWholeRepository.isSelected());
150 
151 		napPrefs.setLimitSearchResultsPerServer(jcbMaxResults.isSelected());
152 		napPrefs.setMaxSearchResultsPerServer
153 			(jtMaxResults.getIntValue());
154 
155 		napPrefs.setMultiSourceDownloading(multiSourceCheckBox.isSelected());
156 
157 		napPrefs.setUseUTF8Encoding(utf8CheckBox.isSelected());
158     }
159 
160     public String getTitle()
161     {
162 		return XNap.tr("Advanced");
163     }
164 
165 }