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.GridBagLayout;
23
24 import javax.swing.DefaultComboBoxModel;
25 import javax.swing.JComboBox;
26 import javax.swing.JComponent;
27 import javax.swing.JPanel;
28
29 import org.xnap.XNap;
30 import org.xnap.gui.SearchOptionsPanel;
31 import org.xnap.gui.component.RangeBox;
32 import org.xnap.gui.util.GUIHelper;
33 import org.xnap.gui.util.GridBagHelper;
34 import org.xnap.plugin.opennap.net.OpenNapServer;
35 import org.xnap.search.SearchFilter;
36
37 /***
38 *
39 */
40 public class OpenNapSearchOptionsPanel extends JPanel
41 implements SearchOptionsPanel {
42
43
44
45 private RangeBox rbBitrate;
46 private DefaultComboBoxModel cbmServers;
47 private JComboBox jcbServers;
48
49
50
51 public OpenNapSearchOptionsPanel()
52 {
53 setLayout(new GridBagLayout());
54 setBorder(GUIHelper.createDefaultBorder(XNap.tr("OpenNap")));
55
56 GridBagHelper.addLabel(this, XNap.tr("Server"));
57 cbmServers = new DefaultComboBoxModel();
58 cbmServers.addElement(XNap.tr("All"));
59 jcbServers = new JComboBox(cbmServers);
60 GridBagHelper.add(this, jcbServers);
61
62 GridBagHelper.addLabel(this, XNap.tr("Bitrate"));
63 rbBitrate = new RangeBox();
64 GridBagHelper.add(this, rbBitrate);
65 }
66
67
68
69 /***
70 * @see xnap.gui.SearchOptionsPanel#getComponent()
71 */
72 public JComponent getComponent()
73 {
74 return this;
75 }
76
77 /***
78 * @see xnap.gui.SearchOptionsPanel#setOptions(xnap.search.SearchFilter)
79 */
80 public void setOptions(SearchFilter filter)
81 {
82 if (cbmServers.getSelectedItem() instanceof OpenNapServer) {
83 filter.put("nap.server", cbmServers.getSelectedItem());
84 }
85
86 filter.put("nap.minBitrate",
87 (rbBitrate.getMinValue() != -1)
88 ? new Long(rbBitrate.getMinValue())
89 : null);
90 filter.put("nap.maxBitrate",
91 (rbBitrate.getMaxValue() != -1)
92 ? new Long(rbBitrate.getMaxValue())
93 : null);
94
95 }
96
97 /***
98 * @see xnap.gui.SearchOptionsPanel#setSearchFilter(xnap.search.SearchFilter)
99 */
100 public void setSearchFilter(SearchFilter filter)
101 {
102 Integer min = (Integer)filter.get("nap.minBitrate");
103 Integer max = (Integer)filter.get("nap.minBitrate");
104 rbBitrate.setValues((min != null) ? min.intValue() : -1,
105 (max != null) ? max.intValue() : -1);
106
107 OpenNapServer s = (OpenNapServer)filter.get("nap.server");
108 if (s != null) {
109 jcbServers.setSelectedItem(s);
110 }
111 else {
112
113 jcbServers.setSelectedIndex(0);
114 }
115 }
116
117 }