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.JLabel;
26 import javax.swing.JPanel;
27
28 import org.xnap.XNap;
29 import org.xnap.gui.AbstractSettingsPanel;
30 import org.xnap.gui.action.EnableAction;
31 import org.xnap.gui.component.PortPanel;
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 import org.xnap.plugin.opennap.OpenNapPlugin;
37 import org.xnap.plugin.opennap.util.OpenNapPreferences;
38
39 public class OpenNapPreferencesPanel extends AbstractSettingsPanel {
40
41
42
43 private OpenNapPreferences napPrefs = OpenNapPlugin.getPreferences();
44
45 private PortPanel jpPort;
46
47 private EnableAction useAutoConnectorAction;
48 private ValidatedTextField jteMaxAutoconnectServers;
49 private EnableAction autoResumeDownloadsAction;
50 private ValidatedTextField autoResumeConnectCountTextField;
51 private EnableAction limitSearchServersAction;
52 private ValidatedTextField jteMaxSearchServers;
53
54
55
56 public OpenNapPreferencesPanel()
57 {
58 setLayout(new GridBagLayout());
59
60
61 JPanel jpConnection = new JPanel(new GridBagLayout());
62 jpConnection.setBorder
63 (GUIHelper.createDefaultBorder(XNap.tr("Local Port")));
64 GridBagHelper.add(this, jpConnection);
65
66 GridBagHelper.add(jpConnection, XNap.tr("Enable if you can receive incoming connections and set a local port."));
67 jpPort = new PortPanel(!napPrefs.getFirewalled(),
68 napPrefs.getLocalPortRange(), 20);
69
70 GridBagHelper.add(jpConnection, jpPort, false);
71
72
73 JPanel jpStartup = new JPanel(new GridBagLayout());
74 jpStartup.setBorder(GUIHelper.createDefaultBorder
75 (XNap.tr("Options")));
76 GridBagHelper.add(this, jpStartup);
77
78 jteMaxAutoconnectServers = new ValidatedTextField
79 (napPrefs.getMaxAutoconnectServers() + "", 5,
80 ValidatedTextField.NUMBERS_INT);
81 useAutoConnectorAction
82 = new EnableAction
83 (XNap.tr("On startup automatically try to connect to"),
84 new Component[] {},
85 napPrefs.getUseAutoconnector());
86 GridBagHelper.addComponent(jpStartup, new XNapCheckBox(useAutoConnectorAction));
87 GridBagHelper.addComponent(jpStartup, jteMaxAutoconnectServers);
88 GridBagHelper.addLabel(jpStartup, XNap.tr("servers"));
89
90 GridBagHelper.add(jpStartup, new JLabel());
91
92 autoResumeConnectCountTextField = new ValidatedTextField
93 (napPrefs.getAutoResumeConnectedCount() + "", 5,
94 ValidatedTextField.NUMBERS_INT);
95 autoResumeDownloadsAction
96 = new EnableAction
97 (XNap.tr("Resume downloads when connected to"),
98 new Component[] { autoResumeConnectCountTextField },
99 napPrefs.getAutoResumeDownloads());
100 GridBagHelper.addComponent
101 (jpStartup, new XNapCheckBox(autoResumeDownloadsAction));
102 GridBagHelper.addComponent
103 (jpStartup, autoResumeConnectCountTextField);
104 GridBagHelper.addLabel(jpStartup, XNap.tr("servers"));
105
106 GridBagHelper.add(jpStartup, new JLabel());
107
108
109 jteMaxSearchServers = new ValidatedTextField
110 (napPrefs.getMaxSearchServers() + "", 5,
111 ValidatedTextField.NUMBERS_INT);
112 limitSearchServersAction
113 = new EnableAction
114 (XNap.tr("Limit number of servers to search on"),
115 new Component[] { jteMaxSearchServers },
116 napPrefs.getLimitSearchServers());
117 GridBagHelper.addComponent
118 (jpStartup, new XNapCheckBox(limitSearchServersAction));
119 GridBagHelper.addComponent
120 (jpStartup, jteMaxSearchServers);
121 GridBagHelper.addLabel(jpStartup, XNap.tr("servers"));
122
123 GridBagHelper.add(jpStartup, new JLabel());
124
125 GridBagHelper.addVerticalSpacer(this);
126 GUIHelper.setMnemonics(this);
127 }
128
129
130
131 public void apply()
132 {
133 napPrefs.setFirewalled(!jpPort.isSelected());
134 napPrefs.setLocalPortRange(jpPort.getPort());
135
136 napPrefs.setUseAutoconnector(useAutoConnectorAction.isSelected());
137 napPrefs.setMaxAutoconnectServers
138 (jteMaxAutoconnectServers.getIntValue());
139 napPrefs.setAutoResumeDownloads(autoResumeDownloadsAction.isSelected());
140 napPrefs.setAutoResumeConnectedCount
141 (autoResumeConnectCountTextField.getIntValue());
142 napPrefs.setLimitSearchServers(limitSearchServersAction.isSelected());
143 napPrefs.setMaxSearchServers(jteMaxSearchServers.getIntValue());
144 }
145
146 public String getTitle()
147 {
148 return "OpenNap";
149 }
150
151
152 }