|
@@ -0,0 +1,165 @@
|
|
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.pages;
|
|
24
|
+
|
|
25
|
+import java.awt.event.ActionEvent;
|
|
26
|
+import java.awt.event.ActionListener;
|
|
27
|
+import java.util.ArrayList;
|
|
28
|
+import java.util.Collections;
|
|
29
|
+
|
|
30
|
+import java.util.List;
|
|
31
|
+import javax.swing.JSeparator;
|
|
32
|
+
|
|
33
|
+import net.miginfocom.swing.MigLayout;
|
|
34
|
+
|
|
35
|
+import uk.co.md87.evetool.AccountManager;
|
|
36
|
+import uk.co.md87.evetool.ApiFactory;
|
|
37
|
+import uk.co.md87.evetool.api.wrappers.data.BasicShipInfo;
|
|
38
|
+import uk.co.md87.evetool.api.wrappers.data.TrainedSkillInfo;
|
|
39
|
+import uk.co.md87.evetool.ui.ContextPanel;
|
|
40
|
+import uk.co.md87.evetool.ui.MainWindow;
|
|
41
|
+import uk.co.md87.evetool.ui.components.FilterButton;
|
|
42
|
+import uk.co.md87.evetool.ui.components.HeaderPanel;
|
|
43
|
+import uk.co.md87.evetool.ui.components.ListablePanel;
|
|
44
|
+import uk.co.md87.evetool.ui.data.BasicShipInfoSurrogate;
|
|
45
|
+import uk.co.md87.evetool.ui.data.TrainedSkillInfoSurrogate;
|
|
46
|
+import uk.co.md87.evetool.ui.dialogs.listableconfig.ListableConfigDialog;
|
|
47
|
+import uk.co.md87.evetool.ui.listable.ListableComparator;
|
|
48
|
+import uk.co.md87.evetool.ui.listable.ListableConfig;
|
|
49
|
+import uk.co.md87.evetool.ui.listable.ListableParser;
|
|
50
|
+
|
|
51
|
+/**
|
|
52
|
+ *
|
|
53
|
+ * TODO: Document ShipsPage
|
|
54
|
+ * @author chris
|
|
55
|
+ */
|
|
56
|
+public class ShipsPage extends ListablePage implements ActionListener {
|
|
57
|
+
|
|
58
|
+ /**
|
|
59
|
+ * A version number for this class. It should be changed whenever the class
|
|
60
|
+ * structure is changed (or anything else that would prevent serialized
|
|
61
|
+ * objects being unserialized with the new class).
|
|
62
|
+ */
|
|
63
|
+ private static final long serialVersionUID = 10;
|
|
64
|
+
|
|
65
|
+ private final MainWindow window;
|
|
66
|
+ private final ApiFactory factory;
|
|
67
|
+
|
|
68
|
+ private ListableConfig config;
|
|
69
|
+
|
|
70
|
+ public ShipsPage(final MainWindow window, final AccountManager manager,
|
|
71
|
+ final ApiFactory factory) {
|
|
72
|
+ this.window = window;
|
|
73
|
+ this.factory = factory;
|
|
74
|
+
|
|
75
|
+ setLayout(new MigLayout("fillx, wrap 1"));
|
|
76
|
+
|
|
77
|
+ config = new ListableConfig();
|
|
78
|
+ config.topLeft = new ListableConfig.BasicConfigElement("name");
|
|
79
|
+ config.topRight = new ListableConfig.CompoundConfigElement();
|
|
80
|
+ config.bottomLeft = new ListableConfig.BasicConfigElement("can fly");
|
|
81
|
+ config.bottomRight = new ListableConfig.CompoundConfigElement();
|
|
82
|
+ config.group = new ListableConfig.BasicConfigElement("group name");
|
|
83
|
+
|
|
84
|
+ config.sortOrder = new ListableConfig.ConfigElement[]{
|
|
85
|
+ new ListableConfig.BasicConfigElement("group name"),
|
|
86
|
+ new ListableConfig.BasicConfigElement("name"),
|
|
87
|
+ };
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ /** {@inheritDoc} */
|
|
91
|
+ @Override
|
|
92
|
+ public boolean isReady() {
|
|
93
|
+ return character != null && character.getSheet() != null
|
|
94
|
+ && character.getSheet().wasSuccessful();
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ /** {@inheritDoc} */
|
|
98
|
+ @Override
|
|
99
|
+ public void activated(final ContextPanel context) {
|
|
100
|
+ final FilterButton button = new FilterButton();
|
|
101
|
+ button.addActionListener(this);
|
|
102
|
+ context.add(button, "growy, al right");
|
|
103
|
+
|
|
104
|
+ updatePage();
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+ protected void updatePage() {
|
|
109
|
+ removeAll();
|
|
110
|
+
|
|
111
|
+ final ListableParser parser = new ListableParser(BasicShipInfoSurrogate.class);
|
|
112
|
+ final List<BasicShipInfoSurrogate> list = new ArrayList<BasicShipInfoSurrogate>();
|
|
113
|
+
|
|
114
|
+ for (BasicShipInfo ship : factory.getApi().getShipList().getResult()
|
|
115
|
+ .getShips().values()) {
|
|
116
|
+ list.add(new BasicShipInfoSurrogate(ship, character.getSheet().getResult()));
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ if (config.sortOrder != null) {
|
|
120
|
+ Collections.sort(list, new ListableComparator(config.sortOrder, parser));
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ String lastGroup = null;
|
|
124
|
+ boolean first = true;
|
|
125
|
+
|
|
126
|
+ for (BasicShipInfoSurrogate ship : list) {
|
|
127
|
+ if (config.group != null) {
|
|
128
|
+ final String thisGroup = config.group.getValue(ship, parser);
|
|
129
|
+
|
|
130
|
+ if (lastGroup == null || !thisGroup.equals(lastGroup)) {
|
|
131
|
+ first = true;
|
|
132
|
+ lastGroup = thisGroup;
|
|
133
|
+ add(new HeaderPanel(lastGroup), "growx, pushx");
|
|
134
|
+ }
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ if (first) {
|
|
138
|
+ first = false;
|
|
139
|
+ } else {
|
|
140
|
+ add(new JSeparator(), "growx, pushx");
|
|
141
|
+ }
|
|
142
|
+
|
|
143
|
+ add(new ListablePanel(ship, parser, config),
|
|
144
|
+ "growx, pushx");
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ revalidate();
|
|
148
|
+ }
|
|
149
|
+
|
|
150
|
+ public void setConfig(final ListableConfig config) {
|
|
151
|
+ this.config = config;
|
|
152
|
+
|
|
153
|
+ updatePage();
|
|
154
|
+ }
|
|
155
|
+
|
|
156
|
+ /** {@inheritDoc} */
|
|
157
|
+ @Override
|
|
158
|
+ public void actionPerformed(final ActionEvent e) {
|
|
159
|
+ new ListableConfigDialog(window, this, config,
|
|
160
|
+ new BasicShipInfoSurrogate(factory.getApi().getShipList()
|
|
161
|
+ .getResult().getShips().values().iterator().next(),
|
|
162
|
+ character.getSheet().getResult())).setVisible(true);
|
|
163
|
+ }
|
|
164
|
+
|
|
165
|
+}
|