Browse Source

Listable grouping

master
Chris Smith 15 years ago
parent
commit
32a4a53132

+ 63
- 0
src/uk/co/md87/evetool/ui/components/HeaderPanel.java View File

@@ -0,0 +1,63 @@
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.components;
24
+
25
+import java.awt.Font;
26
+
27
+import javax.swing.BorderFactory;
28
+import javax.swing.JLabel;
29
+import javax.swing.JPanel;
30
+import javax.swing.border.BevelBorder;
31
+
32
+import net.miginfocom.swing.MigLayout;
33
+
34
+/**
35
+ * Displays a header for grouped listables.
36
+ *
37
+ * @author chris
38
+ */
39
+public class HeaderPanel extends JPanel {
40
+
41
+    /**
42
+     * A version number for this class. It should be changed whenever the class
43
+     * structure is changed (or anything else that would prevent serialized
44
+     * objects being unserialized with the new class).
45
+     */
46
+    private static final long serialVersionUID = 10;
47
+
48
+    /**
49
+     * Creates a new header panel with the specified text.
50
+     *
51
+     * @param text The text to be displayed
52
+     */
53
+    public HeaderPanel(final String text) {
54
+        super(new MigLayout("fillx"));
55
+
56
+        final JLabel header = new JLabel(text);
57
+        header.setFont(header.getFont().deriveFont(14f).deriveFont(Font.BOLD));
58
+        setBorder(BorderFactory.createCompoundBorder(
59
+                BorderFactory.createBevelBorder(BevelBorder.RAISED),
60
+                BorderFactory.createEmptyBorder(0, 5, 0, 5)));
61
+        add(header, "growx");
62
+    }
63
+}

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

@@ -30,7 +30,7 @@ public class ListableConfig {
30 30
 
31 31
     public ConfigElement topLeft, topRight, bottomLeft, bottomRight;
32 32
     public String[] sortOrder;
33
-    public String group;
33
+    public ConfigElement group;
34 34
 
35 35
     public static interface ConfigElement {
36 36
 

+ 19
- 2
src/uk/co/md87/evetool/ui/pages/SkillPage.java View File

@@ -38,9 +38,11 @@ import uk.co.md87.evetool.ui.ContentPanel.Page;
38 38
 import uk.co.md87.evetool.ui.ContextPanel;
39 39
 import uk.co.md87.evetool.ui.MainWindow;
40 40
 import uk.co.md87.evetool.ui.components.FilterButton;
41
+import uk.co.md87.evetool.ui.components.HeaderPanel;
41 42
 import uk.co.md87.evetool.ui.components.ListablePanel;
42 43
 import uk.co.md87.evetool.ui.data.TrainedSkillInfoSurrogate;
43 44
 import uk.co.md87.evetool.ui.dialogs.listableconfig.ListableConfigDialog;
45
+import uk.co.md87.evetool.ui.listable.Listable;
44 46
 import uk.co.md87.evetool.ui.listable.ListableConfig;
45 47
 import uk.co.md87.evetool.ui.listable.ListableParser;
46 48
 
@@ -78,6 +80,7 @@ public class SkillPage extends Page implements ActionListener {
78 80
                 new ListableConfig.BasicConfigElement("max skillpoints"));
79 81
         config.bottomLeft = new ListableConfig.BasicConfigElement("group name");
80 82
         config.bottomRight = new ListableConfig.BasicConfigElement("time to next level");
83
+        config.group = new ListableConfig.BasicConfigElement("group name");
81 84
     }
82 85
 
83 86
     /** {@inheritDoc} */
@@ -100,16 +103,30 @@ public class SkillPage extends Page implements ActionListener {
100 103
                 new TrainingTimeComparator(true));
101 104
 
102 105
         final ListableParser parser = new ListableParser(TrainedSkillInfoSurrogate.class);
103
-        
106
+
107
+        String lastGroup = null;
104 108
         boolean first = true;
109
+        
105 110
         for (TrainedSkillInfo skill : character.getSheet().getResult().getSkills()) {
111
+            final Listable wrapper = new TrainedSkillInfoSurrogate(skill);
112
+
113
+            if (config.group != null) {
114
+                final String thisGroup = config.group.getValue(wrapper, parser);
115
+
116
+                if (lastGroup == null || !thisGroup.equals(lastGroup)) {
117
+                    first = true;
118
+                    lastGroup = thisGroup;
119
+                    add(new HeaderPanel(lastGroup), "growx, pushx");
120
+                }
121
+            }
122
+
106 123
             if (first) {
107 124
                 first = false;
108 125
             } else {
109 126
                 add(new JSeparator(), "growx, pushx");
110 127
             }
111 128
 
112
-            add(new ListablePanel(new TrainedSkillInfoSurrogate(skill), parser, config),
129
+            add(new ListablePanel(wrapper, parser, config),
113 130
                     "growx, pushx");
114 131
         }
115 132
     }

Loading…
Cancel
Save