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  
21  package org.xnap.gui.prefs;
22  
23  import java.awt.Component;
24  import java.awt.GridBagLayout;
25  
26  import javax.swing.JCheckBox;
27  import javax.swing.*;
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.ValidatedTextField;
33  import org.xnap.gui.component.XNapCheckBox;
34  import org.xnap.gui.util.GUIHelper;
35  import org.xnap.gui.util.GridBagHelper;
36  
37  public class SearchPrefsPanel extends AbstractSettingsPanel {
38      
39      //--- Data field(s) ---
40  
41  	private JCheckBox alwaysAutoSearchCheckBox;
42      private JCheckBox jcRemoveDuplicateResults;
43      private JCheckBox jcFilterResults;
44      private ValidatedTextField jteAutoSearchInterval;
45      private EnableAction acLimitDownloadAttempts;
46      private ValidatedTextField jtfMaxAutoSearches;
47  
48      //--- Constructor(s) ---
49  
50      public SearchPrefsPanel()
51      {
52  		setLayout(new GridBagLayout());
53  
54  		// search result options
55          jcRemoveDuplicateResults = new JCheckBox
56  			(XNap.tr("Remove duplicate search results", 1), 
57  			 prefs.getRemoveDuplicateResults());
58  		GridBagHelper.add(this, jcRemoveDuplicateResults);
59  
60  		jcFilterResults = new JCheckBox
61              (XNap.tr("Double filter results", 1), prefs.getFilterResults());
62  		GridBagHelper.add(this, jcFilterResults);
63  
64  		// auto downloads
65  		JPanel jpAutoDownloads = new JPanel(new GridBagLayout());
66  		jpAutoDownloads.setBorder
67  			(GUIHelper.createDefaultBorder(XNap.tr("Automatic Search For Sources")));
68  		GridBagHelper.add(this, jpAutoDownloads);
69  
70          JLabel l = GridBagHelper.addLabel(jpAutoDownloads, 
71  										  XNap.tr("Initial search interval (at least 10 min)", 1));
72          jteAutoSearchInterval = new ValidatedTextField
73  			(prefs.getAutoDownloadSearchInterval() / 60 + "", 5, 
74  			 ValidatedTextField.NUMBERS_INT);
75  		l.setLabelFor(jteAutoSearchInterval);
76          GridBagHelper.addComponent(jpAutoDownloads, jteAutoSearchInterval);
77          GridBagHelper.addLabel(jpAutoDownloads, XNap.tr("min"));
78  		GridBagHelper.add(jpAutoDownloads, new JLabel());
79  
80  		alwaysAutoSearchCheckBox = new JCheckBox
81  			(XNap.tr("Always automatically search for more sources"),
82  			 prefs.getAlwaysAutoDownload());
83  		GridBagHelper.add(jpAutoDownloads, alwaysAutoSearchCheckBox);
84  
85          jtfMaxAutoSearches = new ValidatedTextField
86  			(prefs.getAutoDownloadMaxSearches() + "", 5, 
87  			 ValidatedTextField.NUMBERS_INT);
88  		acLimitDownloadAttempts
89  			= new EnableAction(XNap.tr("Limit Search Attempts"),
90  							   new Component[] { jtfMaxAutoSearches },
91  							   prefs.getLimitDownloadAttempts());
92  		GridBagHelper.addComponent
93  			(jpAutoDownloads, new XNapCheckBox(acLimitDownloadAttempts));
94  		GridBagHelper.add(jpAutoDownloads, jtfMaxAutoSearches, false);
95  	
96  		GridBagHelper.addVerticalSpacer(this);
97  		GUIHelper.setMnemonics(this);
98      }
99  
100     public void apply() 
101     {
102 		prefs.setRemoveDuplicateResults(jcRemoveDuplicateResults.isSelected());
103 		prefs.setFilterResults(jcFilterResults.isSelected());
104 		prefs.setAutoDownloadSearchInterval
105 			(jteAutoSearchInterval.getIntValue() * 60); 
106 		prefs.setLimitDownloadAttempts(acLimitDownloadAttempts.isSelected());
107 		prefs.setAlwaysAutoDownload(alwaysAutoSearchCheckBox.isSelected());
108 		prefs.setAutoDownloadMaxSearches(jtfMaxAutoSearches.getIntValue());
109     }
110 
111     public String getTitle()
112     {
113 		return XNap.tr("Search");
114     }
115 
116 	public String getDescription()
117 	{
118 		return XNap.tr("Search configuration.");
119 	}
120 }