|
@@ -22,8 +22,9 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.ui_swing.dialogs.prefs;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.ClientModule.GlobalConfig;
|
|
26
|
+import com.dmdirc.ClientModule.UserConfig;
|
25
|
27
|
import com.dmdirc.addons.ui_swing.MainFrame;
|
26
|
|
-import com.dmdirc.addons.ui_swing.SwingController;
|
27
|
28
|
import com.dmdirc.addons.ui_swing.components.PackingTable;
|
28
|
29
|
import com.dmdirc.addons.ui_swing.components.URLProtocolPanel;
|
29
|
30
|
import com.dmdirc.addons.ui_swing.components.renderers.URIHandlerCellRenderer;
|
|
@@ -31,6 +32,9 @@ import com.dmdirc.addons.ui_swing.components.renderers.URISchemeCellRenderer;
|
31
|
32
|
import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
|
32
|
33
|
import com.dmdirc.config.prefs.PreferencesInterface;
|
33
|
34
|
import com.dmdirc.config.validators.URLProtocolValidator;
|
|
35
|
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
|
36
|
+import com.dmdirc.interfaces.config.ConfigProvider;
|
|
37
|
+import com.dmdirc.ui.IconManager;
|
34
|
38
|
|
35
|
39
|
import java.awt.Dialog.ModalityType;
|
36
|
40
|
import java.awt.Window;
|
|
@@ -62,8 +66,12 @@ public class URLConfigPanel extends JPanel implements
|
62
|
66
|
|
63
|
67
|
/** Serial version UID. */
|
64
|
68
|
private static final long serialVersionUID = 1;
|
65
|
|
- /** Swing controller. */
|
66
|
|
- private final SwingController controller;
|
|
69
|
+ /** The global configuration to read settings from. */
|
|
70
|
+ private final AggregateConfigProvider globalConfig;
|
|
71
|
+ /** The user configuration to store settings in. */
|
|
72
|
+ private final ConfigProvider userConfig;
|
|
73
|
+ /** The icon manager to use for input dialogs. */
|
|
74
|
+ private final IconManager iconManager;
|
67
|
75
|
/** Protocol list. */
|
68
|
76
|
private PackingTable table;
|
69
|
77
|
/** Table mode. */
|
|
@@ -88,17 +96,23 @@ public class URLConfigPanel extends JPanel implements
|
88
|
96
|
/**
|
89
|
97
|
* Instantiates a new URL config panel.
|
90
|
98
|
*
|
91
|
|
- * @param controller Swing controller
|
92
|
99
|
* @param parentWindow Parent window
|
|
100
|
+ * @param globalConfig The global configuration to read settings from.
|
|
101
|
+ * @param userConfig The user configuration to write settings to.
|
|
102
|
+ * @param iconManager The icon manager to use for input dialogs.
|
93
|
103
|
*/
|
94
|
104
|
@Inject
|
95
|
105
|
public URLConfigPanel(
|
96
|
|
- final SwingController controller,
|
97
|
|
- final MainFrame parentWindow) {
|
|
106
|
+ final MainFrame parentWindow,
|
|
107
|
+ @GlobalConfig final AggregateConfigProvider globalConfig,
|
|
108
|
+ @UserConfig final ConfigProvider userConfig,
|
|
109
|
+ @GlobalConfig final IconManager iconManager) {
|
98
|
110
|
super();
|
99
|
111
|
|
100
|
|
- this.controller = controller;
|
101
|
112
|
this.parentWindow = parentWindow;
|
|
113
|
+ this.globalConfig = globalConfig;
|
|
114
|
+ this.userConfig = userConfig;
|
|
115
|
+ this.iconManager = iconManager;
|
102
|
116
|
|
103
|
117
|
initComponents();
|
104
|
118
|
addListeners();
|
|
@@ -111,7 +125,7 @@ public class URLConfigPanel extends JPanel implements
|
111
|
125
|
*/
|
112
|
126
|
private void initComponents() {
|
113
|
127
|
tableScrollPane = new JScrollPane();
|
114
|
|
- model = new URLHandlerTableModel(controller.getGlobalConfig());
|
|
128
|
+ model = new URLHandlerTableModel(globalConfig);
|
115
|
129
|
table = new PackingTable(model, tableScrollPane) {
|
116
|
130
|
private static final long serialVersionUID = 1;
|
117
|
131
|
|
|
@@ -138,7 +152,7 @@ public class URLConfigPanel extends JPanel implements
|
138
|
152
|
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
139
|
153
|
table.getRowSorter().toggleSortOrder(0);
|
140
|
154
|
details = new HashMap<>();
|
141
|
|
- empty = new URLProtocolPanel(controller.getGlobalIdentity(), null, true);
|
|
155
|
+ empty = new URLProtocolPanel(userConfig, null, true);
|
142
|
156
|
activeComponent = empty;
|
143
|
157
|
add = new JButton("Add");
|
144
|
158
|
remove = new JButton("Remove");
|
|
@@ -146,14 +160,13 @@ public class URLConfigPanel extends JPanel implements
|
146
|
160
|
|
147
|
161
|
tableScrollPane.setViewportView(table);
|
148
|
162
|
|
149
|
|
- final Set<String> options = controller.getGlobalConfig().
|
150
|
|
- getOptions("protocol").keySet();
|
|
163
|
+ final Set<String> options = globalConfig.getOptions("protocol").keySet();
|
151
|
164
|
|
152
|
165
|
for (final String option : options) {
|
153
|
166
|
try {
|
154
|
167
|
final URI uri = new URI(option + "://example.test.com");
|
155
|
168
|
model.addURI(uri);
|
156
|
|
- details.put(uri, new URLProtocolPanel(controller.getGlobalIdentity(), uri, true));
|
|
169
|
+ details.put(uri, new URLProtocolPanel(userConfig, uri, true));
|
157
|
170
|
} catch (final URISyntaxException ex) {
|
158
|
171
|
//Ignore wont happen
|
159
|
172
|
}
|
|
@@ -187,8 +200,7 @@ public class URLConfigPanel extends JPanel implements
|
187
|
200
|
public void save() {
|
188
|
201
|
valueChanged(null);
|
189
|
202
|
final Map<URI, String> handlers = model.getURLHandlers();
|
190
|
|
- final Set<String> protocols = controller.getGlobalConfig().
|
191
|
|
- getOptions("protocol").keySet();
|
|
203
|
+ final Set<String> protocols = globalConfig.getOptions("protocol").keySet();
|
192
|
204
|
for (final String protocol : protocols) {
|
193
|
205
|
URI uri;
|
194
|
206
|
try {
|
|
@@ -216,17 +228,14 @@ public class URLConfigPanel extends JPanel implements
|
216
|
228
|
*/
|
217
|
229
|
private void saveHandler(final String protocol, final String handler) {
|
218
|
230
|
if (handler.isEmpty()) {
|
219
|
|
- controller.getGlobalIdentity().unsetOption("protocol",
|
220
|
|
- protocol);
|
|
231
|
+ userConfig.unsetOption("protocol", protocol);
|
221
|
232
|
} else {
|
222
|
|
- controller.getGlobalIdentity().setOption("protocol",
|
223
|
|
- protocol, handler);
|
|
233
|
+ userConfig.setOption("protocol", protocol, handler);
|
224
|
234
|
|
225
|
235
|
}
|
226
|
236
|
|
227
|
237
|
}
|
228
|
238
|
|
229
|
|
- /** {@inheritDoc} */
|
230
|
239
|
@Override
|
231
|
240
|
public void valueChanged(final ListSelectionEvent e) {
|
232
|
241
|
if (e == null || !e.getValueIsAdjusting()) {
|
|
@@ -265,9 +274,9 @@ public class URLConfigPanel extends JPanel implements
|
265
|
274
|
public void actionPerformed(final ActionEvent e) {
|
266
|
275
|
if (e.getSource() == add) {
|
267
|
276
|
new StandardInputDialog(parentWindow,
|
268
|
|
- ModalityType.MODELESS, controller.getIconManager(), "New URL handler",
|
|
277
|
+ ModalityType.MODELESS, iconManager, "New URL handler",
|
269
|
278
|
"Please enter the name of the new protocol.",
|
270
|
|
- new URLProtocolValidator(controller.getGlobalConfig())) {
|
|
279
|
+ new URLProtocolValidator(globalConfig)) {
|
271
|
280
|
/** Serial version UID. */
|
272
|
281
|
private static final long serialVersionUID = 1;
|
273
|
282
|
|
|
@@ -277,8 +286,7 @@ public class URLConfigPanel extends JPanel implements
|
277
|
286
|
try {
|
278
|
287
|
final URI uri = new URI(getText() + "://example.test.com");
|
279
|
288
|
model.addURI(uri);
|
280
|
|
- details.put(uri, new URLProtocolPanel(controller.getGlobalIdentity(), uri,
|
281
|
|
- true));
|
|
289
|
+ details.put(uri, new URLProtocolPanel(userConfig, uri, true));
|
282
|
290
|
return true;
|
283
|
291
|
} catch (final URISyntaxException ex) {
|
284
|
292
|
return false;
|
|
@@ -293,8 +301,7 @@ public class URLConfigPanel extends JPanel implements
|
293
|
301
|
}.display();
|
294
|
302
|
|
295
|
303
|
} else if (e.getSource() == remove) {
|
296
|
|
- model.removeURI(table.getRowSorter().convertRowIndexToModel(table.
|
297
|
|
- getSelectedRow()));
|
|
304
|
+ model.removeURI(table.getRowSorter().convertRowIndexToModel(table.getSelectedRow()));
|
298
|
305
|
}
|
299
|
306
|
}
|
300
|
307
|
|