Browse Source

Listable config

master
Chris Smith 15 years ago
parent
commit
c61ccd91cf

+ 1
- 0
src/uk/co/md87/evetool/api/wrappers/data/SkillGroup.java View File

@@ -23,6 +23,7 @@
23 23
 package uk.co.md87.evetool.api.wrappers.data;
24 24
 
25 25
 import java.util.ArrayList;
26
+
26 27
 import uk.co.md87.evetool.ui.listable.Retrievable;
27 28
 
28 29
 /**

+ 5
- 0
src/uk/co/md87/evetool/api/wrappers/data/SkillInfo.java View File

@@ -70,6 +70,11 @@ public class SkillInfo {
70 70
         return name;
71 71
     }
72 72
 
73
+    @Retrievable
74
+    public int getRank() {
75
+        return rank;
76
+    }
77
+
73 78
     @Retrievable(formatWith=NumberFormatter.class)
74 79
     public int getMaxSkillpoints() {
75 80
         return getSkillpointsForLevel(5);

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

@@ -23,6 +23,7 @@
23 23
 package uk.co.md87.evetool.ui.dialogs.listableconfig;
24 24
 
25 25
 import java.awt.Dialog.ModalityType;
26
+import java.awt.Dimension;
26 27
 import java.awt.Window;
27 28
 import java.awt.event.ActionEvent;
28 29
 import java.awt.event.ActionListener;
@@ -63,8 +64,7 @@ import uk.co.md87.evetool.ui.listable.ListableParser;
63 64
  * TODO: Document ListableConfigDialog
64 65
  * @author chris
65 66
  */
66
-public class ListableConfigDialog extends JDialog implements ActionListener,
67
-        ItemListener, KeyListener {
67
+public class ListableConfigDialog extends JDialog implements ItemListener, KeyListener {
68 68
 
69 69
     /**
70 70
      * A version number for this class. It should be changed whenever the class
@@ -129,37 +129,40 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
129 129
         configPanel.removeAll();
130 130
         
131 131
         JButton addButton = new JButton("+");
132
-        addButton.addActionListener(this);
133
-
132
+        addButton.addActionListener(new ButtonActionListener("tl"));
133
+        addButton.setMaximumSize(new Dimension(35, 100));
134 134
         configPanel.add(new JLabel("Top left:", JLabel.RIGHT));
135 135
         addComponents("tl");
136
-        configPanel.add(addButton);
136
+        configPanel.add(addButton, "span, al right");
137 137
 
138 138
         addButton = new JButton("+");
139
-        addButton.addActionListener(this);
139
+        addButton.addActionListener(new ButtonActionListener("bl"));
140
+        addButton.setMaximumSize(new Dimension(35, 100));
140 141
         configPanel.add(new JLabel("Bottom left:", JLabel.RIGHT), "newline");
141 142
         addComponents("bl");
142
-        configPanel.add(addButton);
143
+        configPanel.add(addButton, "span, al right");
143 144
 
144 145
         addButton = new JButton("+");
145
-        addButton.addActionListener(this);
146
+        addButton.addActionListener(new ButtonActionListener("tr"));
147
+        addButton.setMaximumSize(new Dimension(35, 100));
146 148
         configPanel.add(new JLabel("Top right:", JLabel.RIGHT), "newline");
147 149
         addComponents("tr");
148
-        configPanel.add(addButton);
150
+        configPanel.add(addButton, "span, al right");
149 151
 
150 152
         addButton = new JButton("+");
151
-        addButton.addActionListener(this);
153
+        addButton.addActionListener(new ButtonActionListener("br"));
154
+        addButton.setMaximumSize(new Dimension(35, 100));
152 155
         configPanel.add(new JLabel("Bottom right:", JLabel.RIGHT), "newline");
153 156
         addComponents("br");
154
-        configPanel.add(addButton);
157
+        configPanel.add(addButton, "span, al right");
158
+
159
+        configPanel.revalidate();
160
+        pack();
155 161
     }
156 162
 
157 163
     protected void addComponents(final String location) {
158
-        String firstText = ", split " + components.get(location).size();
159 164
         for (JComponent component : components.get(location)) {
160
-            final int compWidth = component instanceof JComboBox ? 150 : 100;
161
-            configPanel.add(component, "growy, width " + compWidth + "!" + firstText);
162
-            firstText = "";
165
+            configPanel.add(component, "growy, width 100!");
163 166
         }
164 167
     }
165 168
 
@@ -184,27 +187,6 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
184 187
         return res;
185 188
     }
186 189
 
187
-    /** {@inheritDoc} */
188
-    @Override
189
-    public void actionPerformed(final ActionEvent e) {
190
-        if (e.getSource() instanceof JButton) {
191
-            final JPopupMenu menu = new JPopupMenu();
192
-
193
-            JMenuItem mi = new JMenuItem("New string");
194
-            mi.addActionListener(this);
195
-            menu.add(mi);
196
-
197
-            mi = new JMenuItem("New variable");
198
-            mi.addActionListener(this);
199
-            menu.add(mi);
200
-
201
-            menu.show((JComponent) e.getSource(), 0,
202
-                    ((JComponent) e.getSource()).getHeight());
203
-        } else if (e.getSource() instanceof JMenuItem) {
204
-            
205
-        }
206
-    }
207
-
208 190
     protected void rebuildConfig() {
209 191
         for (String loc : new String[]{"tl", "tr", "bl", "br"}) {
210 192
             final List<ConfigElement> elements = new ArrayList<ConfigElement>();
@@ -247,8 +229,7 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
247 229
     /** {@inheritDoc} */
248 230
     @Override
249 231
     public void keyTyped(final KeyEvent e) {
250
-        rebuildConfig();
251
-        panel.listableUpdated(sample);
232
+        // Do nothing
252 233
     }
253 234
 
254 235
     /** {@inheritDoc} */
@@ -260,7 +241,60 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
260 241
     /** {@inheritDoc} */
261 242
     @Override
262 243
     public void keyReleased(final KeyEvent e) {
263
-        // Do nothing
244
+        rebuildConfig();
245
+        panel.listableUpdated(sample);
246
+    }
247
+
248
+    private class ButtonActionListener implements ActionListener {
249
+
250
+        private final String location;
251
+
252
+        public ButtonActionListener(final String location) {
253
+            this.location = location;
254
+        }
255
+
256
+        public void actionPerformed(final ActionEvent e) {
257
+            final JPopupMenu menu = new JPopupMenu();
258
+
259
+            JMenuItem mi = new JMenuItem("New string");
260
+            mi.addActionListener(new MenuActionListener(location, true));
261
+            menu.add(mi);
262
+
263
+            mi = new JMenuItem("New variable");
264
+            mi.addActionListener(new MenuActionListener(location, false));
265
+            menu.add(mi);
266
+
267
+            menu.show((JComponent) e.getSource(), 0,
268
+                    ((JComponent) e.getSource()).getHeight());
269
+        }
270
+    }
271
+
272
+    private class MenuActionListener implements ActionListener {
273
+
274
+        private final String location;
275
+
276
+        private final boolean isString;
277
+
278
+        public MenuActionListener(final String location, final boolean isString) {
279
+            this.location = location;
280
+            this.isString = isString;
281
+        }
282
+
283
+        public void actionPerformed(final ActionEvent e) {
284
+            if (isString) {
285
+                final JTextField tf = new JTextField();
286
+                tf.addKeyListener(ListableConfigDialog.this);
287
+                components.get(location).add(tf);
288
+            } else {
289
+                final JComboBox box = new JComboBox(retrievables.toArray());
290
+                box.addItemListener(ListableConfigDialog.this);
291
+                components.get(location).add(box);
292
+            }
293
+
294
+            layoutConfigPanel();
295
+            rebuildConfig();
296
+            panel.listableUpdated(sample);
297
+        }
264 298
     }
265 299
 
266 300
 }

Loading…
Cancel
Save