Browse Source

Listable sorting

master
Chris Smith 15 years ago
parent
commit
c01ae46de1

+ 55
- 0
src/uk/co/md87/evetool/ui/listable/ListableComparator.java View File

@@ -0,0 +1,55 @@
1
+/*
2
+ * Copyright (c) 2009 Chris Smith
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.co.md87.evetool.ui.listable;
24
+
25
+import java.util.Comparator;
26
+import uk.co.md87.evetool.ui.listable.ListableConfig.ConfigElement;
27
+
28
+/**
29
+ *
30
+ * TODO: Document ListableComparator
31
+ * @author chris
32
+ */
33
+public class ListableComparator implements Comparator<Object> {
34
+
35
+    private final ListableConfig.ConfigElement[] order;
36
+    private final ListableParser parser;
37
+
38
+    public ListableComparator(ConfigElement[] order, ListableParser parser) {
39
+        this.order = order;
40
+        this.parser = parser;
41
+    }
42
+
43
+    public int compare(final Object o1, final Object o2) {
44
+        for (ConfigElement element : order) {
45
+            final int res = element.getValue(o1, parser).compareTo(element.getValue(o2, parser));
46
+
47
+            if (res != 0) {
48
+                return res;
49
+            }
50
+        }
51
+
52
+        return 0;
53
+    }
54
+
55
+}

+ 1
- 1
src/uk/co/md87/evetool/ui/listable/ListableConfig.java View File

@@ -29,7 +29,7 @@ package uk.co.md87.evetool.ui.listable;
29 29
 public class ListableConfig {
30 30
 
31 31
     public ConfigElement topLeft, topRight, bottomLeft, bottomRight;
32
-    public String[] sortOrder;
32
+    public ConfigElement[] sortOrder;
33 33
     public ConfigElement group;
34 34
 
35 35
     public static interface ConfigElement {

+ 21
- 8
src/uk/co/md87/evetool/ui/pages/SkillPage.java View File

@@ -24,8 +24,10 @@ package uk.co.md87.evetool.ui.pages;
24 24
 
25 25
 import java.awt.event.ActionEvent;
26 26
 import java.awt.event.ActionListener;
27
+import java.util.ArrayList;
27 28
 import java.util.Collections;
28 29
 
30
+import java.util.List;
29 31
 import javax.swing.JSeparator;
30 32
 
31 33
 import net.miginfocom.swing.MigLayout;
@@ -43,6 +45,7 @@ import uk.co.md87.evetool.ui.components.ListablePanel;
43 45
 import uk.co.md87.evetool.ui.data.TrainedSkillInfoSurrogate;
44 46
 import uk.co.md87.evetool.ui.dialogs.listableconfig.ListableConfigDialog;
45 47
 import uk.co.md87.evetool.ui.listable.Listable;
48
+import uk.co.md87.evetool.ui.listable.ListableComparator;
46 49
 import uk.co.md87.evetool.ui.listable.ListableConfig;
47 50
 import uk.co.md87.evetool.ui.listable.ListableParser;
48 51
 
@@ -81,6 +84,12 @@ public class SkillPage extends Page implements ActionListener {
81 84
         config.bottomLeft = new ListableConfig.BasicConfigElement("group name");
82 85
         config.bottomRight = new ListableConfig.BasicConfigElement("time to next level");
83 86
         config.group = new ListableConfig.BasicConfigElement("group name");
87
+
88
+        config.sortOrder = new ListableConfig.ConfigElement[]{
89
+            new ListableConfig.BasicConfigElement("group name"),
90
+            new ListableConfig.BasicConfigElement("current level"),
91
+            new ListableConfig.BasicConfigElement("trained skillpoints"),
92
+        };
84 93
     }
85 94
 
86 95
     /** {@inheritDoc} */
@@ -99,19 +108,23 @@ public class SkillPage extends Page implements ActionListener {
99 108
 
100 109
         removeAll();
101 110
 
102
-        Collections.sort(character.getSheet().getResult().getSkills(),
103
-                new TrainingTimeComparator(true));
104
-
105 111
         final ListableParser parser = new ListableParser(TrainedSkillInfoSurrogate.class);
112
+        final List<TrainedSkillInfoSurrogate> list = new ArrayList<TrainedSkillInfoSurrogate>();
113
+
114
+        for (TrainedSkillInfo skill : character.getSheet().getResult().getSkills()) {
115
+            list.add(new TrainedSkillInfoSurrogate(skill));
116
+        }
117
+
118
+        if (config.sortOrder != null) {
119
+            Collections.sort(list, new ListableComparator(config.sortOrder, parser));
120
+        }
106 121
 
107 122
         String lastGroup = null;
108 123
         boolean first = true;
109 124
         
110
-        for (TrainedSkillInfo skill : character.getSheet().getResult().getSkills()) {
111
-            final Listable wrapper = new TrainedSkillInfoSurrogate(skill);
112
-
125
+        for (TrainedSkillInfoSurrogate skill : list) {
113 126
             if (config.group != null) {
114
-                final String thisGroup = config.group.getValue(wrapper, parser);
127
+                final String thisGroup = config.group.getValue(skill, parser);
115 128
 
116 129
                 if (lastGroup == null || !thisGroup.equals(lastGroup)) {
117 130
                     first = true;
@@ -126,7 +139,7 @@ public class SkillPage extends Page implements ActionListener {
126 139
                 add(new JSeparator(), "growx, pushx");
127 140
             }
128 141
 
129
-            add(new ListablePanel(wrapper, parser, config),
142
+            add(new ListablePanel(skill, parser, config),
130 143
                     "growx, pushx");
131 144
         }
132 145
     }

Loading…
Cancel
Save