Browse Source

Listable config dialogs

master
Chris Smith 15 years ago
parent
commit
fae126695b

+ 47
- 14
src/uk/co/md87/evetool/ui/dialogs/listableconfig/ListableConfigDialog.java View File

@@ -52,6 +52,7 @@ import javax.swing.JTextField;
52 52
 
53 53
 import net.miginfocom.swing.MigLayout;
54 54
 
55
+import uk.co.md87.evetool.ui.ContentPanel.Page;
55 56
 import uk.co.md87.evetool.ui.components.ListablePanel;
56 57
 import uk.co.md87.evetool.ui.listable.Listable;
57 58
 import uk.co.md87.evetool.ui.listable.ListableConfig;
@@ -60,13 +61,15 @@ import uk.co.md87.evetool.ui.listable.ListableConfig.CompoundConfigElement;
60 61
 import uk.co.md87.evetool.ui.listable.ListableConfig.ConfigElement;
61 62
 import uk.co.md87.evetool.ui.listable.ListableConfig.LiteralConfigElement;
62 63
 import uk.co.md87.evetool.ui.listable.ListableParser;
64
+import uk.co.md87.evetool.ui.pages.SkillPage;
63 65
 
64 66
 /**
65 67
  *
66 68
  * TODO: Document ListableConfigDialog
67 69
  * @author chris
68 70
  */
69
-public class ListableConfigDialog extends JDialog implements ItemListener, KeyListener {
71
+public class ListableConfigDialog extends JDialog implements ActionListener,
72
+        ItemListener, KeyListener {
70 73
 
71 74
     /**
72 75
      * A version number for this class. It should be changed whenever the class
@@ -83,16 +86,21 @@ public class ListableConfigDialog extends JDialog implements ItemListener, KeyLi
83 86
     private final Map<String, List<JComponent>> components
84 87
             = new HashMap<String, List<JComponent>>();
85 88
 
89
+    private volatile boolean complete = false;
90
+
86 91
     private final JPanel configPanel, previewPanel;
87 92
     private final ListablePanel panel;
88 93
 
89
-    public ListableConfigDialog(final Window owner, final ListableConfig config,
90
-            final Listable sample) {
91
-        super(owner, "Display Configuration", ModalityType.APPLICATION_MODAL);
94
+    private final SkillPage page;
95
+
96
+    public ListableConfigDialog(final Window window, final SkillPage page,
97
+            final ListableConfig config, final Listable sample) {
98
+        super(window, "Display Configuration", ModalityType.APPLICATION_MODAL);
92 99
 
93 100
         setLayout(new MigLayout("wrap 1, fill", "[fill]", "[|fill|fill]"));
94 101
 
95
-        this.config = config;
102
+        this.page = page;
103
+        this.config = config.clone();
96 104
         this.sample = sample;
97 105
         this.parser = new ListableParser(sample.getClass());
98 106
         
@@ -101,22 +109,30 @@ public class ListableConfigDialog extends JDialog implements ItemListener, KeyLi
101 109
         this.configPanel = new JPanel(new MigLayout("fill", "[fill]"));
102 110
         this.previewPanel = new JPanel(new MigLayout("fill", "[fill]", "[fill]"));
103 111
 
104
-        configPanel.setBorder(BorderFactory.createTitledBorder("Information"));
112
+        configPanel.setBorder(BorderFactory.createTitledBorder("Configuration"));
105 113
         previewPanel.setBorder(BorderFactory.createTitledBorder("Preview"));
106 114
 
107 115
         this.panel = new ListablePanel(sample, parser, config);
108 116
         
109 117
         previewPanel.add(panel);
110 118
 
119
+        final JButton cancelButton = new JButton("Cancel");
120
+        final JButton okButton = new JButton("OK");
121
+
122
+        cancelButton.addActionListener(this);
123
+        okButton.addActionListener(this);
124
+
111 125
         add(configPanel);
112 126
         add(previewPanel);
127
+        add(cancelButton, "split");
128
+        add(okButton, "split");
113 129
 
114 130
         initConfigPanel();
115 131
         layoutConfigPanel();
116 132
 
117 133
         pack();
118 134
 
119
-        setLocationRelativeTo(owner);
135
+        setLocationRelativeTo(window);
120 136
         setResizable(false);
121 137
     }
122 138
 
@@ -130,6 +146,8 @@ public class ListableConfigDialog extends JDialog implements ItemListener, KeyLi
130 146
         for (int i = 0; i < config.sortOrder.length; i++) {
131 147
             components.put("+sort_" + i, getComponents(config.sortOrder[i]));
132 148
         }
149
+
150
+        complete = true;
133 151
     }
134 152
 
135 153
     protected void layoutConfigPanel() {
@@ -208,13 +226,11 @@ public class ListableConfigDialog extends JDialog implements ItemListener, KeyLi
208 226
     }
209 227
 
210 228
     protected void rebuildConfig() {
211
-        for (String loc : new String[]{"tl", "tr", "bl", "br"}) {
229
+        config.sortOrder = new ConfigElement[components.size() - 5];
230
+        
231
+        for (String loc : components.keySet()) {
212 232
             final List<ConfigElement> elements = new ArrayList<ConfigElement>();
213 233
 
214
-            if (!components.containsKey(loc)) {
215
-                continue;
216
-            }
217
-
218 234
             for (JComponent component : components.get(loc)) {
219 235
                 if (component instanceof JTextField) {
220 236
                     elements.add(new LiteralConfigElement(((JTextField) component).getText()));
@@ -235,6 +251,11 @@ public class ListableConfigDialog extends JDialog implements ItemListener, KeyLi
235 251
                 config.bottomRight = res;
236 252
             } else if (loc.equals("bl")) {
237 253
                 config.bottomLeft = res;
254
+            } else if (loc.equals("+group")) {
255
+                config.group = res;
256
+            } else if (loc.startsWith("+sort_")) {
257
+                final int line = Integer.parseInt(loc.substring(6));
258
+                config.sortOrder[line] = res;
238 259
             }
239 260
         }
240 261
     }
@@ -242,8 +263,10 @@ public class ListableConfigDialog extends JDialog implements ItemListener, KeyLi
242 263
     /** {@inheritDoc} */
243 264
     @Override
244 265
     public void itemStateChanged(final ItemEvent e) {
245
-        rebuildConfig();
246
-        panel.listableUpdated(sample);
266
+        if (complete) {
267
+            rebuildConfig();
268
+            panel.listableUpdated(sample);
269
+        }
247 270
     }
248 271
 
249 272
     /** {@inheritDoc} */
@@ -265,6 +288,16 @@ public class ListableConfigDialog extends JDialog implements ItemListener, KeyLi
265 288
         panel.listableUpdated(sample);
266 289
     }
267 290
 
291
+    /** {@inheritDoc} */
292
+    @Override
293
+    public void actionPerformed(final ActionEvent e) {
294
+        if (((JButton) e.getSource()).getText().equals("OK")) {
295
+            page.setConfig(config);
296
+        }
297
+
298
+        dispose();
299
+    }
300
+
268 301
     private class ButtonActionListener implements ActionListener {
269 302
 
270 303
         private final String location;

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

@@ -22,11 +22,14 @@
22 22
 
23 23
 package uk.co.md87.evetool.ui.listable;
24 24
 
25
+import java.util.Arrays;
26
+
25 27
 /**
26 28
  *
29
+ * TODO: Document ListableConfig
27 30
  * @author chris
28 31
  */
29
-public class ListableConfig {
32
+public class ListableConfig implements Cloneable {
30 33
 
31 34
     public ConfigElement topLeft, topRight, bottomLeft, bottomRight;
32 35
     public ConfigElement[] sortOrder;
@@ -95,4 +98,19 @@ public class ListableConfig {
95 98
         }
96 99
     }
97 100
 
101
+    /** {@inheritDoc} */
102
+    @Override
103
+    public ListableConfig clone() {
104
+        final ListableConfig clone = new ListableConfig();
105
+
106
+        clone.bottomLeft = bottomLeft;
107
+        clone.bottomRight = bottomRight;
108
+        clone.topLeft = topLeft;
109
+        clone.topRight = topRight;
110
+        clone.group = group;
111
+        clone.sortOrder = Arrays.copyOf(sortOrder, sortOrder.length);
112
+
113
+        return clone;
114
+    }
115
+
98 116
 }

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

@@ -64,7 +64,7 @@ public class SkillPage extends Page implements ActionListener {
64 64
     private final MainWindow window;
65 65
     private final ApiFactory factory;
66 66
 
67
-    private final ListableConfig config;
67
+    private ListableConfig config;
68 68
 
69 69
     public SkillPage(final MainWindow window, final AccountManager manager,
70 70
             final ApiFactory factory) {
@@ -103,7 +103,12 @@ public class SkillPage extends Page implements ActionListener {
103 103
         final FilterButton button = new FilterButton();
104 104
         button.addActionListener(this);
105 105
         context.add(button, "growy, al right");
106
+        
107
+        updatePage();
108
+    }
106 109
 
110
+
111
+    protected void updatePage() {
107 112
         removeAll();
108 113
 
109 114
         final ListableParser parser = new ListableParser(TrainedSkillInfoSurrogate.class);
@@ -140,12 +145,20 @@ public class SkillPage extends Page implements ActionListener {
140 145
             add(new ListablePanel(skill, parser, config),
141 146
                     "growx, pushx");
142 147
         }
148
+
149
+        revalidate();
150
+    }
151
+
152
+    public void setConfig(final ListableConfig config) {
153
+        this.config = config;
154
+        
155
+        updatePage();
143 156
     }
144 157
 
145 158
     /** {@inheritDoc} */
146 159
     @Override
147 160
     public void actionPerformed(final ActionEvent e) {
148
-        new ListableConfigDialog(window, config, new TrainedSkillInfoSurrogate(
161
+        new ListableConfigDialog(window, this, config, new TrainedSkillInfoSurrogate(
149 162
                 character.getSheet().getResult().getSkills().get(0))).setVisible(true);
150 163
     }
151 164
 

Loading…
Cancel
Save