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.JComboBox;
26  import javax.swing.JPanel;
27  import javax.swing.JTextField;
28  
29  import org.xnap.XNap;
30  import org.xnap.gui.component.DefaultDialog;
31  import org.xnap.gui.util.GridBagHelper;
32  import org.xnap.plugin.opennap.OpenNapPlugin;
33  import org.xnap.plugin.opennap.net.OpenNapDownloadContainer;
34  import org.xnap.search.*;
35  
36  /***
37   * Provides a dialog for editing the properties like search text and
38   * filename of a download.  */
39  public class OpenNapDownloadContainerEditorDialog extends DefaultDialog
40  {
41      
42      //--- Data field(s) ---
43  
44      private OpenNapDownloadContainer download;
45  	private SearchFilter filter;
46  
47      private JTextField jtFilename;
48      private JTextField jtSearchText;
49      private JComboBox jcbMediaType;
50  
51      //--- Constructor(s) ---
52  	    
53      private OpenNapDownloadContainerEditorDialog
54  		(OpenNapDownloadContainer download)
55      {
56  		this.download = download;
57  		this.filter = download.getSearchFilter();
58  		if (filter == null) {
59  			filter = new DefaultSearchFilter();
60  		}
61  
62  		initialize();
63      }
64  
65      // --- Methods ---
66  
67      private void initialize()
68      {
69          setTitle(XNap.tr("Edit Download"));
70  
71  		JPanel jp = getMainPanel();
72  		jp.setLayout(new GridBagLayout());
73  
74  		// final filename
75  		GridBagHelper.addLabel(jp, XNap.tr("Filename"));
76  		jtFilename = new JTextField(download.getFilename());
77  		GridBagHelper.add(jp, jtFilename);
78  
79  		// search text
80  		GridBagHelper.addLabel(jp, XNap.tr("Search Text"));
81  		jtSearchText = new JTextField(filter.getText());
82  		GridBagHelper.add(jp, jtSearchText);
83  	
84  		// media type
85  		GridBagHelper.addLabel(jp, XNap.tr("Media Type"));
86  		jcbMediaType = new JComboBox
87  			(OpenNapPlugin.getSearchManager().getSupportedMediaTypes());
88  		jcbMediaType.setSelectedItem(filter.getMediaType());
89  		GridBagHelper.add(jp, jcbMediaType);
90  
91  		pack();
92      }
93  
94      public static void showDialog(Component c, OpenNapDownloadContainer d)
95      {
96  		OpenNapDownloadContainerEditorDialog me 
97  			= new OpenNapDownloadContainerEditorDialog(d);
98  		me.show();
99      }
100 
101     public boolean apply()
102     {
103 		download.setFilename(jtFilename.getText());
104 
105 		filter.put(SearchFilter.TEXT, jtSearchText.getText());
106 		filter.put(SearchFilter.MEDIA_TYPE, jcbMediaType.getSelectedItem());
107 		download.setSearchFilter(filter);
108 
109 		return true;
110     }
111 
112 }