|
@@ -19,12 +19,11 @@
|
19
|
19
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
20
|
* SOFTWARE.
|
21
|
21
|
*/
|
|
22
|
+
|
22
|
23
|
package com.dmdirc.addons.ui_swing.components.addonbrowser;
|
23
|
24
|
|
24
|
25
|
import com.dmdirc.Main;
|
25
|
26
|
import com.dmdirc.addons.ui_swing.MainFrame;
|
26
|
|
-import com.dmdirc.addons.ui_swing.UIUtilities;
|
27
|
|
-import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
|
28
|
27
|
import com.dmdirc.util.ConfigFile;
|
29
|
28
|
import com.dmdirc.util.InvalidConfigFileException;
|
30
|
29
|
|
|
@@ -32,25 +31,18 @@ import java.awt.event.ActionEvent;
|
32
|
31
|
import java.awt.event.ActionListener;
|
33
|
32
|
import java.io.File;
|
34
|
33
|
import java.io.IOException;
|
35
|
|
-import java.util.ArrayList;
|
36
|
|
-import java.util.Collections;
|
37
|
|
-import java.util.Comparator;
|
38
|
|
-import java.util.List;
|
39
|
34
|
import java.util.Map;
|
40
|
35
|
|
41
|
36
|
import javax.swing.BorderFactory;
|
42
|
37
|
import javax.swing.ButtonGroup;
|
43
|
|
-import javax.swing.DefaultListModel;
|
44
|
38
|
import javax.swing.JCheckBox;
|
45
|
39
|
import javax.swing.JDialog;
|
46
|
|
-import javax.swing.JLabel;
|
47
|
40
|
import javax.swing.JPanel;
|
48
|
41
|
import javax.swing.JRadioButton;
|
49
|
42
|
import javax.swing.JScrollPane;
|
50
|
|
-import javax.swing.JTable;
|
51
|
43
|
import javax.swing.JTextField;
|
52
|
44
|
|
53
|
|
-import javax.swing.table.DefaultTableModel;
|
|
45
|
+import javax.swing.SwingUtilities;
|
54
|
46
|
import net.miginfocom.swing.MigLayout;
|
55
|
47
|
|
56
|
48
|
/**
|
|
@@ -58,8 +50,7 @@ import net.miginfocom.swing.MigLayout;
|
58
|
50
|
*
|
59
|
51
|
* @author chris
|
60
|
52
|
*/
|
61
|
|
-public class BrowserWindow extends JDialog implements ActionListener,
|
62
|
|
- Comparator<AddonInfo> {
|
|
53
|
+public class BrowserWindow extends JDialog implements ActionListener {
|
63
|
54
|
|
64
|
55
|
/**
|
65
|
56
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -82,12 +73,14 @@ public class BrowserWindow extends JDialog implements ActionListener,
|
82
|
73
|
/** The installed checkbox. */
|
83
|
74
|
private final JCheckBox installedBox = new JCheckBox("Installed", true);
|
84
|
75
|
/** The not installed checkbox. */
|
85
|
|
- private final JCheckBox notinstalledBox = new JCheckBox("Not installed", true);
|
|
76
|
+ private final JCheckBox notinstalledBox = new JCheckBox("Not installed",
|
|
77
|
+ true);
|
86
|
78
|
/** The panel used to list addons. */
|
87
|
79
|
private final AddonTable list = new AddonTable();
|
88
|
80
|
/** The scrollpane for the list panel. */
|
89
|
81
|
private final JScrollPane scrollPane = new JScrollPane(list,
|
90
|
|
- JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
|
82
|
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
|
|
83
|
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
91
|
84
|
/** The sort by name button. */
|
92
|
85
|
private final JRadioButton nameButton = new JRadioButton("Name", true);
|
93
|
86
|
/** The sort by rating button. */
|
|
@@ -96,15 +89,19 @@ public class BrowserWindow extends JDialog implements ActionListener,
|
96
|
89
|
private final JRadioButton dateButton = new JRadioButton("Date", false);
|
97
|
90
|
/** The sort by status button. */
|
98
|
91
|
private final JRadioButton statusButton = new JRadioButton("Status", false);
|
99
|
|
- /** All known addon infos. */
|
100
|
|
- private final List<AddonInfo> infos = new ArrayList<AddonInfo>();
|
|
92
|
+ /** Row sorter. */
|
|
93
|
+ private final AddonSorter sorter;
|
|
94
|
+ /** Addon filter. */
|
|
95
|
+ private final AddonFilter filter;
|
101
|
96
|
|
102
|
97
|
/**
|
103
|
98
|
* Creates and displays a new browser window.
|
104
|
99
|
*/
|
105
|
100
|
public BrowserWindow() {
|
106
|
|
- super((MainFrame) Main.getUI().getMainWindow(), "DMDirc Addon Browser", false);
|
107
|
|
- setIconImage(((MainFrame) Main.getUI().getMainWindow()).getIcon().getImage());
|
|
101
|
+ super((MainFrame) Main.getUI().getMainWindow(), "DMDirc Addon Browser",
|
|
102
|
+ false);
|
|
103
|
+ setIconImage(((MainFrame) Main.getUI().getMainWindow()).getIcon().
|
|
104
|
+ getImage());
|
108
|
105
|
setResizable(false);
|
109
|
106
|
setLayout(new MigLayout("fill, wmin 650, hmin 600"));
|
110
|
107
|
scrollPane.getVerticalScrollBar().setUnitIncrement(15);
|
|
@@ -144,6 +141,16 @@ public class BrowserWindow extends JDialog implements ActionListener,
|
144
|
141
|
|
145
|
142
|
initListeners();
|
146
|
143
|
|
|
144
|
+ filter = new AddonFilter(verifiedBox.getModel(),
|
|
145
|
+ unverifiedBox.getModel(), installedBox.getModel(),
|
|
146
|
+ notinstalledBox.getModel(), pluginsBox.getModel(), themesBox.
|
|
147
|
+ getModel(), actionsBox.getModel(),
|
|
148
|
+ searchBox);
|
|
149
|
+ sorter = new AddonSorter(list.getModel(), dateButton.getModel(),
|
|
150
|
+ nameButton.getModel(), ratingButton.getModel(),
|
|
151
|
+ statusButton.getModel(), filter);
|
|
152
|
+ list.setRowSorter(sorter);
|
|
153
|
+
|
147
|
154
|
try {
|
148
|
155
|
loadData();
|
149
|
156
|
} catch (IOException ex) {
|
|
@@ -170,17 +177,17 @@ public class BrowserWindow extends JDialog implements ActionListener,
|
170
|
177
|
themesBox.addActionListener(this);
|
171
|
178
|
actionsBox.addActionListener(this);
|
172
|
179
|
|
173
|
|
- nameButton.addActionListener(this);
|
174
|
|
- ratingButton.addActionListener(this);
|
175
|
|
- dateButton.addActionListener(this);
|
176
|
|
- statusButton.addActionListener(this);
|
177
|
|
-
|
178
|
180
|
verifiedBox.addActionListener(this);
|
179
|
181
|
unverifiedBox.addActionListener(this);
|
180
|
182
|
installedBox.addActionListener(this);
|
181
|
183
|
notinstalledBox.addActionListener(this);
|
182
|
184
|
|
183
|
185
|
searchBox.addActionListener(this);
|
|
186
|
+
|
|
187
|
+ nameButton.addActionListener(this);
|
|
188
|
+ ratingButton.addActionListener(this);
|
|
189
|
+ dateButton.addActionListener(this);
|
|
190
|
+ statusButton.addActionListener(this);
|
184
|
191
|
}
|
185
|
192
|
|
186
|
193
|
/**
|
|
@@ -190,92 +197,30 @@ public class BrowserWindow extends JDialog implements ActionListener,
|
190
|
197
|
* @throws InvalidConfigFileException If the file is corrupt somehow
|
191
|
198
|
*/
|
192
|
199
|
private void loadData() throws IOException, InvalidConfigFileException {
|
193
|
|
- ConfigFile data = new ConfigFile(Main.getConfigDir() + File.separator + "addons.feed");
|
|
200
|
+ ConfigFile data = new ConfigFile(Main.getConfigDir() + File.separator +
|
|
201
|
+ "addons.feed");
|
194
|
202
|
data.read();
|
195
|
|
- int i = 0;
|
196
|
203
|
|
197
|
204
|
for (Map<String, String> entry : data.getKeyDomains().values()) {
|
198
|
205
|
final AddonInfo info = new AddonInfo(entry);
|
199
|
|
- infos.add(info);
|
|
206
|
+ list.getModel().addRow(new Object[]{new AddonInfoLabel(info),});
|
200
|
207
|
}
|
201
|
|
-
|
202
|
|
- sortAndFilter();
|
203
|
208
|
}
|
204
|
209
|
|
205
|
210
|
/**
|
206
|
|
- * Sorts and filters the list of addons according to the currently selected
|
207
|
|
- * options.
|
208
|
|
- */
|
209
|
|
- private void sortAndFilter() {
|
210
|
|
- list.getModel().setRowCount(0);
|
211
|
|
- list.add(new JLabel("Sorting list.", JLabel.CENTER), "grow, pushy");
|
212
|
|
-
|
213
|
|
- new LoggingSwingWorker() {
|
214
|
|
-
|
215
|
|
- final List<AddonInfo> newInfos = new ArrayList<AddonInfo>();
|
216
|
|
-
|
217
|
|
- /* {@inheritDoc} */
|
218
|
|
- @Override
|
219
|
|
- protected Object doInBackground() {
|
220
|
|
- for (AddonInfo info : infos) {
|
221
|
|
- if ((!verifiedBox.isSelected() && info.isVerified()) ||
|
222
|
|
- (!unverifiedBox.isSelected() && !info.isVerified()) ||
|
223
|
|
- (!installedBox.isSelected() && info.isInstalled()) ||
|
224
|
|
- (!notinstalledBox.isSelected() &&
|
225
|
|
- !info.isInstalled()) || (!pluginsBox.isSelected() &&
|
226
|
|
- info.getType() == AddonType.TYPE_PLUGIN) ||
|
227
|
|
- (!themesBox.isSelected() && info.getType() ==
|
228
|
|
- AddonType.TYPE_THEME) ||
|
229
|
|
- (!actionsBox.isSelected() && info.getType() ==
|
230
|
|
- AddonType.TYPE_ACTION_PACK) || (!searchBox.getText().
|
231
|
|
- isEmpty() && !info.matches(searchBox.getText()))) {
|
232
|
|
- continue;
|
233
|
|
- }
|
234
|
|
-
|
235
|
|
- newInfos.add(info);
|
236
|
|
- }
|
237
|
|
-
|
238
|
|
- Collections.sort(newInfos, BrowserWindow.this);
|
239
|
|
- return newInfos;
|
240
|
|
- }
|
241
|
|
-
|
242
|
|
- /* {@inheritDoc} */
|
243
|
|
- @Override
|
244
|
|
- protected void done() {
|
245
|
|
- super.done();
|
246
|
|
-
|
247
|
|
- list.getModel().setRowCount(0);
|
248
|
|
- for (AddonInfo info : newInfos) {
|
249
|
|
- list.getModel().addRow(new Object[] {new AddonInfoLabel(info), });
|
250
|
|
- }
|
251
|
|
- UIUtilities.resetScrollPane(scrollPane);
|
252
|
|
- }
|
253
|
|
- }.execute();
|
254
|
|
- }
|
255
|
|
-
|
256
|
|
- /**
|
257
|
211
|
* {@inheritDoc}
|
258
|
|
- *
|
|
212
|
+ *
|
259
|
213
|
* @param e Action event
|
260
|
214
|
*/
|
261
|
215
|
@Override
|
262
|
216
|
public void actionPerformed(final ActionEvent e) {
|
263
|
|
- sortAndFilter();
|
264
|
|
- }
|
|
217
|
+ SwingUtilities.invokeLater(new Runnable() {
|
265
|
218
|
|
266
|
|
- /** {@inheritDoc} */
|
267
|
|
- @Override
|
268
|
|
- public int compare(final AddonInfo o1, final AddonInfo o2) {
|
269
|
|
- if (dateButton.isSelected()) {
|
270
|
|
- return o1.getId() - o2.getId();
|
271
|
|
- } else if (nameButton.isSelected()) {
|
272
|
|
- return o1.getTitle().compareTo(o2.getTitle());
|
273
|
|
- } else if (ratingButton.isSelected()) {
|
274
|
|
- return o1.getRating() - o2.getRating();
|
275
|
|
- } else if (statusButton.isSelected()) {
|
276
|
|
- return (o1.isVerified() ? 1 : 0) - (o2.isVerified() ? 1 : 0);
|
277
|
|
- } else {
|
278
|
|
- return 0;
|
279
|
|
- }
|
|
219
|
+ /** {@inheritDoc} */
|
|
220
|
+ @Override
|
|
221
|
+ public void run() {
|
|
222
|
+ sorter.sort();
|
|
223
|
+ }
|
|
224
|
+ });
|
280
|
225
|
}
|
281
|
226
|
}
|