Browse Source

Lots of listable abstraction

master
Chris Smith 15 years ago
parent
commit
16c9bb28cc

+ 0
- 1
src/uk/co/md87/evetool/ui/ContentPanel.java View File

@@ -66,7 +66,6 @@ public class ContentPanel extends JPanel {
66 66
 
67 67
         protected AccountChar character;
68 68
 
69
-        // TODO: Add method for activation
70 69
         public boolean isReady() {
71 70
             return false;
72 71
         }

+ 62
- 4
src/uk/co/md87/evetool/ui/pages/ListablePage.java View File

@@ -24,6 +24,11 @@ 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.Collections;
28
+import java.util.List;
29
+
30
+import javax.swing.JSeparator;
31
+
27 32
 import net.miginfocom.swing.MigLayout;
28 33
 
29 34
 import uk.co.md87.evetool.AccountManager;
@@ -32,14 +37,21 @@ import uk.co.md87.evetool.ui.ContentPanel.Page;
32 37
 import uk.co.md87.evetool.ui.ContextPanel;
33 38
 import uk.co.md87.evetool.ui.MainWindow;
34 39
 import uk.co.md87.evetool.ui.components.FilterButton;
40
+import uk.co.md87.evetool.ui.components.HeaderPanel;
41
+import uk.co.md87.evetool.ui.components.ListablePanel;
42
+import uk.co.md87.evetool.ui.dialogs.listableconfig.ListableConfigDialog;
43
+import uk.co.md87.evetool.ui.listable.Listable;
44
+import uk.co.md87.evetool.ui.listable.ListableComparator;
35 45
 import uk.co.md87.evetool.ui.listable.ListableConfig;
46
+import uk.co.md87.evetool.ui.listable.ListableConfig.CompoundConfigElement;
47
+import uk.co.md87.evetool.ui.listable.ListableParser;
36 48
 
37 49
 /**
38 50
  *
39 51
  * TODO: Document ListablePage
40 52
  * @author chris
41 53
  */
42
-public class ListablePage extends Page implements ActionListener {
54
+public abstract class ListablePage<T extends Listable> extends Page implements ActionListener {
43 55
 
44 56
     /**
45 57
      * A version number for this class. It should be changed whenever the class
@@ -73,10 +85,56 @@ public class ListablePage extends Page implements ActionListener {
73 85
         updatePage();
74 86
     }
75 87
 
76
-    public void setConfig(final ListableConfig config) {}
88
+    public void setConfig(final ListableConfig config) {
89
+        this.config = config;
90
+
91
+        updatePage();
92
+    }
93
+
94
+    protected void updatePage() {
95
+        removeAll();
96
+
97
+        final List<T> list = getListables();
98
+        final ListableParser parser = new ListableParser(list.get(0).getClass());
99
+
100
+        if (config.sortOrder != null) {
101
+            Collections.sort(list, new ListableComparator(config.sortOrder, parser));
102
+        }
103
+
104
+        String lastGroup = null;
105
+        boolean first = true;
77 106
 
78
-    protected void updatePage() {}
107
+        for (T listable : list) {
108
+            if (config.group != null &&
109
+                    (!(config.group instanceof CompoundConfigElement)
110
+                    || ((CompoundConfigElement) config.group).getElements().length > 0)) {
111
+                final String thisGroup = config.group.getValue(listable, parser);
79 112
 
80
-    public void actionPerformed(final ActionEvent e) {}
113
+                if (lastGroup == null || !thisGroup.equals(lastGroup)) {
114
+                    first = true;
115
+                    lastGroup = thisGroup;
116
+                    add(new HeaderPanel(lastGroup), "growx, pushx");
117
+                }
118
+            }
119
+
120
+            if (first) {
121
+                first = false;
122
+            } else {
123
+                add(new JSeparator(), "growx, pushx");
124
+            }
125
+
126
+            add(new ListablePanel(listable, parser, config), "growx, pushx");
127
+        }
128
+
129
+        revalidate();
130
+    }
131
+
132
+    protected abstract List<T> getListables();
133
+
134
+    /** {@inheritDoc} */
135
+    @Override
136
+    public void actionPerformed(final ActionEvent e) {
137
+        new ListableConfigDialog(window, this, config, getListables().get(0)).setVisible(true);
138
+    }
81 139
 
82 140
 }

+ 5
- 58
src/uk/co/md87/evetool/ui/pages/ShipsPage.java View File

@@ -22,32 +22,23 @@
22 22
 
23 23
 package uk.co.md87.evetool.ui.pages;
24 24
 
25
-import java.awt.event.ActionEvent;
26 25
 import java.awt.event.ActionListener;
27 26
 import java.util.ArrayList;
28
-import java.util.Collections;
29
-
30 27
 import java.util.List;
31
-import javax.swing.JSeparator;
32 28
 
33 29
 import uk.co.md87.evetool.AccountManager;
34 30
 import uk.co.md87.evetool.ApiFactory;
35 31
 import uk.co.md87.evetool.api.wrappers.data.BasicShipInfo;
36 32
 import uk.co.md87.evetool.ui.MainWindow;
37
-import uk.co.md87.evetool.ui.components.HeaderPanel;
38
-import uk.co.md87.evetool.ui.components.ListablePanel;
39 33
 import uk.co.md87.evetool.ui.data.BasicShipInfoSurrogate;
40
-import uk.co.md87.evetool.ui.dialogs.listableconfig.ListableConfigDialog;
41
-import uk.co.md87.evetool.ui.listable.ListableComparator;
42 34
 import uk.co.md87.evetool.ui.listable.ListableConfig;
43
-import uk.co.md87.evetool.ui.listable.ListableParser;
44 35
 
45 36
 /**
46 37
  *
47 38
  * TODO: Document ShipsPage
48 39
  * @author chris
49 40
  */
50
-public class ShipsPage extends ListablePage implements ActionListener {
41
+public class ShipsPage extends ListablePage<BasicShipInfoSurrogate> implements ActionListener {
51 42
 
52 43
     /**
53 44
      * A version number for this class. It should be changed whenever the class
@@ -80,10 +71,9 @@ public class ShipsPage extends ListablePage implements ActionListener {
80 71
                 && character.getSheet().wasSuccessful();
81 72
     }
82 73
 
83
-    protected void updatePage() {
84
-        removeAll();
85
-
86
-        final ListableParser parser = new ListableParser(BasicShipInfoSurrogate.class);
74
+    /** {@inheritDoc} */
75
+    @Override
76
+    protected List<BasicShipInfoSurrogate> getListables() {
87 77
         final List<BasicShipInfoSurrogate> list = new ArrayList<BasicShipInfoSurrogate>();
88 78
 
89 79
         for (BasicShipInfo ship : factory.getApi().getShipList().getResult()
@@ -91,50 +81,7 @@ public class ShipsPage extends ListablePage implements ActionListener {
91 81
             list.add(new BasicShipInfoSurrogate(ship, character.getSheet().getResult()));
92 82
         }
93 83
 
94
-        if (config.sortOrder != null) {
95
-            Collections.sort(list, new ListableComparator(config.sortOrder, parser));
96
-        }
97
-
98
-        String lastGroup = null;
99
-        boolean first = true;
100
-        
101
-        for (BasicShipInfoSurrogate ship : list) {
102
-            if (config.group != null) {
103
-                final String thisGroup = config.group.getValue(ship, parser);
104
-
105
-                if (lastGroup == null || !thisGroup.equals(lastGroup)) {
106
-                    first = true;
107
-                    lastGroup = thisGroup;
108
-                    add(new HeaderPanel(lastGroup), "growx, pushx");
109
-                }
110
-            }
111
-
112
-            if (first) {
113
-                first = false;
114
-            } else {
115
-                add(new JSeparator(), "growx, pushx");
116
-            }
117
-
118
-            add(new ListablePanel(ship, parser, config),
119
-                    "growx, pushx");
120
-        }
121
-
122
-        revalidate();
123
-    }
124
-
125
-    public void setConfig(final ListableConfig config) {
126
-        this.config = config;
127
-        
128
-        updatePage();
129
-    }
130
-
131
-    /** {@inheritDoc} */
132
-    @Override
133
-    public void actionPerformed(final ActionEvent e) {
134
-        new ListableConfigDialog(window, this, config,
135
-                new BasicShipInfoSurrogate(factory.getApi().getShipList()
136
-                .getResult().getShips().values().iterator().next(),
137
-                character.getSheet().getResult())).setVisible(true);
84
+        return list;
138 85
     }
139 86
 
140 87
 }

+ 6
- 57
src/uk/co/md87/evetool/ui/pages/SkillPage.java View File

@@ -22,32 +22,24 @@
22 22
 
23 23
 package uk.co.md87.evetool.ui.pages;
24 24
 
25
-import java.awt.event.ActionEvent;
26 25
 import java.awt.event.ActionListener;
27 26
 import java.util.ArrayList;
28
-import java.util.Collections;
29 27
 import java.util.List;
30 28
 
31
-import javax.swing.JSeparator;
32
-
33 29
 import uk.co.md87.evetool.AccountManager;
34 30
 import uk.co.md87.evetool.ApiFactory;
35 31
 import uk.co.md87.evetool.api.wrappers.data.TrainedSkillInfo;
36 32
 import uk.co.md87.evetool.ui.MainWindow;
37
-import uk.co.md87.evetool.ui.components.HeaderPanel;
38
-import uk.co.md87.evetool.ui.components.ListablePanel;
39 33
 import uk.co.md87.evetool.ui.data.TrainedSkillInfoSurrogate;
40
-import uk.co.md87.evetool.ui.dialogs.listableconfig.ListableConfigDialog;
41
-import uk.co.md87.evetool.ui.listable.ListableComparator;
42 34
 import uk.co.md87.evetool.ui.listable.ListableConfig;
43
-import uk.co.md87.evetool.ui.listable.ListableParser;
44 35
 
45 36
 /**
46 37
  *
47 38
  * TODO: Document SkillPage
48 39
  * @author chris
49 40
  */
50
-public class SkillPage extends ListablePage implements ActionListener {
41
+public class SkillPage extends ListablePage<TrainedSkillInfoSurrogate>
42
+        implements ActionListener {
51 43
 
52 44
     /**
53 45
      * A version number for this class. It should be changed whenever the class
@@ -84,59 +76,16 @@ public class SkillPage extends ListablePage implements ActionListener {
84 76
                 && character.getSheet().wasSuccessful();
85 77
     }
86 78
 
87
-    protected void updatePage() {
88
-        removeAll();
89
-
90
-        final ListableParser parser = new ListableParser(TrainedSkillInfoSurrogate.class);
79
+    /** {@inheritDoc} */
80
+    @Override
81
+    protected List<TrainedSkillInfoSurrogate> getListables() {
91 82
         final List<TrainedSkillInfoSurrogate> list = new ArrayList<TrainedSkillInfoSurrogate>();
92 83
 
93 84
         for (TrainedSkillInfo skill : character.getSheet().getResult().getSkills().values()) {
94 85
             list.add(new TrainedSkillInfoSurrogate(skill));
95 86
         }
96 87
 
97
-        if (config.sortOrder != null) {
98
-            Collections.sort(list, new ListableComparator(config.sortOrder, parser));
99
-        }
100
-
101
-        String lastGroup = null;
102
-        boolean first = true;
103
-        
104
-        for (TrainedSkillInfoSurrogate skill : list) {
105
-            if (config.group != null) {
106
-                final String thisGroup = config.group.getValue(skill, parser);
107
-
108
-                if (lastGroup == null || !thisGroup.equals(lastGroup)) {
109
-                    first = true;
110
-                    lastGroup = thisGroup;
111
-                    add(new HeaderPanel(lastGroup), "growx, pushx");
112
-                }
113
-            }
114
-
115
-            if (first) {
116
-                first = false;
117
-            } else {
118
-                add(new JSeparator(), "growx, pushx");
119
-            }
120
-
121
-            add(new ListablePanel(skill, parser, config),
122
-                    "growx, pushx");
123
-        }
124
-
125
-        revalidate();
126
-    }
127
-
128
-    public void setConfig(final ListableConfig config) {
129
-        this.config = config;
130
-        
131
-        updatePage();
132
-    }
133
-
134
-    /** {@inheritDoc} */
135
-    @Override
136
-    public void actionPerformed(final ActionEvent e) {
137
-        new ListableConfigDialog(window, this, config, new TrainedSkillInfoSurrogate(
138
-                character.getSheet().getResult().getSkills().values().iterator().next()))
139
-                .setVisible(true);
88
+        return list;
140 89
     }
141 90
 
142 91
 }

Loading…
Cancel
Save