|
@@ -24,6 +24,8 @@ package com.dmdirc.addons.ui_swing.dialogs.prefs;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.ClientModule.GlobalConfig;
|
26
|
26
|
import com.dmdirc.ClientModule.UserConfig;
|
|
27
|
+import com.dmdirc.addons.ui_swing.components.GenericTableModel;
|
|
28
|
+import com.dmdirc.addons.ui_swing.components.IconManager;
|
27
|
29
|
import com.dmdirc.addons.ui_swing.components.PackingTable;
|
28
|
30
|
import com.dmdirc.addons.ui_swing.components.URLProtocolPanel;
|
29
|
31
|
import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
|
|
@@ -32,7 +34,6 @@ import com.dmdirc.config.prefs.PreferencesInterface;
|
32
|
34
|
import com.dmdirc.config.validators.URLProtocolValidator;
|
33
|
35
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
34
|
36
|
import com.dmdirc.interfaces.config.ConfigProvider;
|
35
|
|
-import com.dmdirc.addons.ui_swing.components.IconManager;
|
36
|
37
|
|
37
|
38
|
import java.awt.Dialog.ModalityType;
|
38
|
39
|
import java.awt.Window;
|
|
@@ -40,6 +41,7 @@ import java.awt.event.ActionEvent;
|
40
|
41
|
import java.awt.event.ActionListener;
|
41
|
42
|
import java.net.URI;
|
42
|
43
|
import java.net.URISyntaxException;
|
|
44
|
+import java.util.Collection;
|
43
|
45
|
import java.util.HashMap;
|
44
|
46
|
import java.util.Map;
|
45
|
47
|
import java.util.Map.Entry;
|
|
@@ -52,7 +54,6 @@ import javax.swing.JScrollPane;
|
52
|
54
|
import javax.swing.ListSelectionModel;
|
53
|
55
|
import javax.swing.event.ListSelectionEvent;
|
54
|
56
|
import javax.swing.event.ListSelectionListener;
|
55
|
|
-import javax.swing.table.TableCellRenderer;
|
56
|
57
|
|
57
|
58
|
import net.miginfocom.swing.MigLayout;
|
58
|
59
|
|
|
@@ -73,7 +74,7 @@ public class URLConfigPanel extends JPanel implements
|
73
|
74
|
/** Protocol list. */
|
74
|
75
|
private PackingTable table;
|
75
|
76
|
/** Table mode. */
|
76
|
|
- private URLHandlerTableModel model;
|
|
77
|
+ private GenericTableModel<URLHandlerHolder> model;
|
77
|
78
|
/** Table scrollpane. */
|
78
|
79
|
private JScrollPane tableScrollPane;
|
79
|
80
|
/** Protocol config panel. */
|
|
@@ -122,23 +123,10 @@ public class URLConfigPanel extends JPanel implements
|
122
|
123
|
*/
|
123
|
124
|
private void initComponents() {
|
124
|
125
|
tableScrollPane = new JScrollPane();
|
125
|
|
- model = new URLHandlerTableModel(globalConfig);
|
126
|
|
- table = new PackingTable(model, tableScrollPane) {
|
127
|
|
- private static final long serialVersionUID = 1;
|
128
|
|
-
|
129
|
|
- @Override
|
130
|
|
- public TableCellRenderer getCellRenderer(final int row,
|
131
|
|
- final int column) {
|
132
|
|
- switch (column) {
|
133
|
|
- case 0:
|
134
|
|
- return new URISchemeCellRenderer();
|
135
|
|
- case 1:
|
136
|
|
- return new URIHandlerCellRenderer();
|
137
|
|
- default:
|
138
|
|
- return super.getCellRenderer(row, column);
|
139
|
|
- }
|
140
|
|
- }
|
141
|
|
- };
|
|
126
|
+ model = new GenericTableModel<>(URLHandlerHolder.class, "getUri", "getHandler");
|
|
127
|
+ table = new PackingTable(model, tableScrollPane);
|
|
128
|
+ table.setDefaultRenderer(URISchemeCellRenderer.class, new URISchemeCellRenderer());
|
|
129
|
+ table.setDefaultRenderer(URIHandlerCellRenderer.class, new URIHandlerCellRenderer());
|
142
|
130
|
table.setAutoCreateRowSorter(true);
|
143
|
131
|
table.setAutoCreateColumnsFromModel(true);
|
144
|
132
|
table.setColumnSelectionAllowed(false);
|
|
@@ -161,7 +149,7 @@ public class URLConfigPanel extends JPanel implements
|
161
|
149
|
for (final String option : options) {
|
162
|
150
|
try {
|
163
|
151
|
final URI uri = new URI(option + "://example.test.com");
|
164
|
|
- model.addURI(uri);
|
|
152
|
+ model.addValue(new URLHandlerHolder(uri, getURLHandler(uri)));
|
165
|
153
|
details.put(uri, new URLProtocolPanel(globalConfig, userConfig, uri, true));
|
166
|
154
|
} catch (final URISyntaxException ex) {
|
167
|
155
|
//Ignore wont happen
|
|
@@ -169,6 +157,14 @@ public class URLConfigPanel extends JPanel implements
|
169
|
157
|
}
|
170
|
158
|
}
|
171
|
159
|
|
|
160
|
+ private String getURLHandler(final URI uri) {
|
|
161
|
+ if (globalConfig.hasOptionString("protocol", uri.getScheme())) {
|
|
162
|
+ return globalConfig.getOption("protocol", uri.getScheme());
|
|
163
|
+ } else {
|
|
164
|
+ return "";
|
|
165
|
+ }
|
|
166
|
+ }
|
|
167
|
+
|
172
|
168
|
/**
|
173
|
169
|
* Adds listeners.
|
174
|
170
|
*/
|
|
@@ -194,7 +190,9 @@ public class URLConfigPanel extends JPanel implements
|
194
|
190
|
@Override
|
195
|
191
|
public void save() {
|
196
|
192
|
valueChanged(null);
|
197
|
|
- final Map<URI, String> handlers = model.getURLHandlers();
|
|
193
|
+ final Collection<URLHandlerHolder> elements = model.elements();
|
|
194
|
+ final Map<URI, String> handlers = new HashMap<>();
|
|
195
|
+ elements.forEach(u -> handlers.put(u.getUri(), u.getHandler()));
|
198
|
196
|
final Set<String> protocols = globalConfig.getOptions("protocol").keySet();
|
199
|
197
|
for (final String protocol : protocols) {
|
200
|
198
|
URI uri;
|
|
@@ -237,7 +235,7 @@ public class URLConfigPanel extends JPanel implements
|
237
|
235
|
setVisible(false);
|
238
|
236
|
if (selectedRow != -1 && selectedRow < model.getRowCount()) {
|
239
|
237
|
final URLProtocolPanel panel = details.get(model.getValueAt(selectedRow, 0));
|
240
|
|
- model.setValueAt(panel.getSelection(), selectedRow, 1);
|
|
238
|
+ model.getValue(selectedRow).setHandler(panel.getSelection());
|
241
|
239
|
}
|
242
|
240
|
if (table.getSelectedRow() == -1) {
|
243
|
241
|
activeComponent = empty;
|
|
@@ -246,8 +244,8 @@ public class URLConfigPanel extends JPanel implements
|
246
|
244
|
remove.setEnabled(false);
|
247
|
245
|
selectedRow = -1;
|
248
|
246
|
} else {
|
249
|
|
- activeComponent = details.get(model.getValueAt(table.getRowSorter().
|
250
|
|
- convertRowIndexToModel(table.getSelectedRow()), 0));
|
|
247
|
+ activeComponent = details.get(model.getValue(table.getRowSorter().
|
|
248
|
+ convertRowIndexToModel(table.getSelectedRow())).getUri());
|
251
|
249
|
layoutComponents();
|
252
|
250
|
add.setEnabled(true);
|
253
|
251
|
remove.setEnabled(true);
|
|
@@ -267,14 +265,15 @@ public class URLConfigPanel extends JPanel implements
|
267
|
265
|
new URLProtocolValidator(globalConfig), this::saveAddNewURLHandler).display();
|
268
|
266
|
|
269
|
267
|
} else if (e.getSource() == remove) {
|
270
|
|
- model.removeURI(table.getRowSorter().convertRowIndexToModel(table.getSelectedRow()));
|
|
268
|
+ model.removeValue(model.getValue(table.getRowSorter().convertRowIndexToModel(
|
|
269
|
+ table.getSelectedRow())));
|
271
|
270
|
}
|
272
|
271
|
}
|
273
|
272
|
|
274
|
273
|
private boolean saveAddNewURLHandler(final String text) {
|
275
|
274
|
try {
|
276
|
275
|
final URI uri = new URI(text + "://example.test.com");
|
277
|
|
- model.addURI(uri);
|
|
276
|
+ model.addValue(new URLHandlerHolder(uri, getURLHandler(uri)));
|
278
|
277
|
details.put(uri, new URLProtocolPanel(globalConfig, userConfig, uri, true));
|
279
|
278
|
return true;
|
280
|
279
|
} catch (final URISyntaxException ex) {
|