1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
43
44 private OpenNapDownloadContainer download;
45 private SearchFilter filter;
46
47 private JTextField jtFilename;
48 private JTextField jtSearchText;
49 private JComboBox jcbMediaType;
50
51
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
66
67 private void initialize()
68 {
69 setTitle(XNap.tr("Edit Download"));
70
71 JPanel jp = getMainPanel();
72 jp.setLayout(new GridBagLayout());
73
74
75 GridBagHelper.addLabel(jp, XNap.tr("Filename"));
76 jtFilename = new JTextField(download.getFilename());
77 GridBagHelper.add(jp, jtFilename);
78
79
80 GridBagHelper.addLabel(jp, XNap.tr("Search Text"));
81 jtSearchText = new JTextField(filter.getText());
82 GridBagHelper.add(jp, jtSearchText);
83
84
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 }