Browse Source

Use edit button image in LCD

master
Chris Smith 15 years ago
parent
commit
b628a264f8

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

@@ -31,6 +31,7 @@ import java.awt.event.ItemEvent;
31 31
 import java.awt.event.ItemListener;
32 32
 import java.awt.event.KeyEvent;
33 33
 import java.awt.event.KeyListener;
34
+import java.io.IOException;
34 35
 import java.util.ArrayList;
35 36
 import java.util.Collections;
36 37
 import java.util.HashMap;
@@ -38,7 +39,11 @@ import java.util.List;
38 39
 import java.util.Map;
39 40
 import java.util.Set;
40 41
 
42
+import java.util.logging.Level;
43
+import java.util.logging.Logger;
44
+import javax.imageio.ImageIO;
41 45
 import javax.swing.BorderFactory;
46
+import javax.swing.ImageIcon;
42 47
 import javax.swing.JButton;
43 48
 import javax.swing.JComboBox;
44 49
 import javax.swing.JComponent;
@@ -92,6 +97,20 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
92 97
 
93 98
     private final SkillPage page;
94 99
 
100
+    private static ImageIcon editInactiveIcon, editActiveIcon;
101
+
102
+    static {
103
+        try {
104
+            editInactiveIcon = new ImageIcon(ImageIO.read(ListableConfigDialog
105
+                    .class.getResource("/uk/co/md87/evetool/ui/res/edit-inactive.png")));
106
+            editActiveIcon = new ImageIcon(ImageIO.read(ListableConfigDialog
107
+                    .class.getResource("/uk/co/md87/evetool/ui/res/edit.png")));
108
+        } catch (IOException ex) {
109
+            Logger.getLogger(ListableConfigDialog.class.getName())
110
+                    .log(Level.WARNING, "Unable to load images", ex);
111
+        }
112
+    }
113
+
95 114
     public ListableConfigDialog(final Window window, final SkillPage page,
96 115
             final ListableConfig config, final Listable sample) {
97 116
         super(window, "Display Configuration", ModalityType.APPLICATION_MODAL);
@@ -152,20 +171,25 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
152 171
     protected void layoutConfigPanel() {
153 172
         configPanel.removeAll();
154 173
         
155
-        JButton addButton;
174
+        JButton editButton;
156 175
 
157 176
         final List<String> keyset = new ArrayList<String>(components.keySet());
158 177
         Collections.sort(keyset);
159 178
 
160 179
         for (int i = 0; i < keyset.size(); i++) {
161 180
             final String key = keyset.get(i);
181
+
182
+            editButton = new JButton(editInactiveIcon);
183
+            editButton.setRolloverIcon(editActiveIcon);
184
+            editButton.setBorder(BorderFactory.createEmptyBorder());
185
+            editButton.setOpaque(false);
186
+            editButton.setContentAreaFilled(false);
187
+            editButton.setMaximumSize(new Dimension(20, 20));
162 188
             
163
-            addButton = new JButton("+");
164
-            addButton.addActionListener(new ButtonActionListener(key));
165
-            addButton.setMaximumSize(new Dimension(35, 100));
189
+            editButton.addActionListener(new ButtonActionListener(key));
166 190
             configPanel.add(new JLabel(getText(key), JLabel.RIGHT));
167 191
             addComponents(key);
168
-            configPanel.add(addButton, "span, al right");
192
+            configPanel.add(editButton, "span, al right, gapleft 10");
169 193
 
170 194
             if (key.length() > 2 && i < keyset.size() - 1
171 195
                     && !keyset.get(i + 1).startsWith(key.substring(0, 4))) {
@@ -305,6 +329,8 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
305 329
             this.location = location;
306 330
         }
307 331
 
332
+        /** {@inheritDoc} */
333
+        @Override
308 334
         public void actionPerformed(final ActionEvent e) {
309 335
             final JPopupMenu menu = new JPopupMenu();
310 336
 
@@ -316,11 +342,46 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
316 342
             mi.addActionListener(new MenuActionListener(location, false));
317 343
             menu.add(mi);
318 344
 
345
+            if (!components.get(location).isEmpty()) {
346
+                menu.add(new JSeparator());
347
+            }
348
+
349
+            for (JComponent component : components.get(location)) {
350
+                final String text = component instanceof JTextField ?
351
+                    ((JTextField) component).getText() :
352
+                    String.valueOf(((JComboBox) component).getSelectedItem());
353
+                mi = new JMenuItem("Remove '" + text + "'");
354
+                mi.addActionListener(new MenuRemoveActionListener(location, component));
355
+                menu.add(mi);
356
+            }
357
+
319 358
             menu.show((JComponent) e.getSource(), 0,
320 359
                     ((JComponent) e.getSource()).getHeight());
321 360
         }
322 361
     }
323 362
 
363
+    private class MenuRemoveActionListener implements ActionListener {
364
+
365
+        private final String location;
366
+
367
+        private final JComponent component;
368
+
369
+        public MenuRemoveActionListener(String location, JComponent component) {
370
+            this.location = location;
371
+            this.component = component;
372
+        }
373
+
374
+        /** {@inheritDoc} */
375
+        @Override
376
+        public void actionPerformed(ActionEvent e) {
377
+            components.get(location).remove(component);
378
+            layoutConfigPanel();
379
+            rebuildConfig();
380
+            panel.listableUpdated(sample);
381
+        }
382
+
383
+    }
384
+
324 385
     private class MenuActionListener implements ActionListener {
325 386
 
326 387
         private final String location;
@@ -332,6 +393,8 @@ public class ListableConfigDialog extends JDialog implements ActionListener,
332 393
             this.isString = isString;
333 394
         }
334 395
 
396
+        /** {@inheritDoc} */
397
+        @Override
335 398
         public void actionPerformed(final ActionEvent e) {
336 399
             if (isString) {
337 400
                 final JTextField tf = new JTextField();

Loading…
Cancel
Save