Browse Source

More actions work

git-svn-id: http://svn.dmdirc.com/trunk@2902 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 years ago
parent
commit
2a3244ea84

+ 13
- 3
src/com/dmdirc/actions/ActionGroup.java View File

@@ -26,11 +26,19 @@ import java.util.ArrayList;
26 26
 import java.util.List;
27 27
 
28 28
 /**
29
- *
29
+ * Represents a group of actions, along with their meta-data.
30
+ * 
30 31
  * @author chris
31 32
  */
32 33
 public class ActionGroup extends ArrayList<Action> {
33 34
     
35
+    /**
36
+     * A version number for this class. It should be changed whenever the class
37
+     * structure is changed (or anything else that would prevent serialized
38
+     * objects being unserialized with the new class).
39
+     */
40
+    private static final long serialVersionUID = 1;    
41
+    
34 42
     private String name;
35 43
     
36 44
     private String description;
@@ -39,6 +47,10 @@ public class ActionGroup extends ArrayList<Action> {
39 47
     
40 48
     private final List<ActionSetting> settings = new ArrayList<ActionSetting>();
41 49
 
50
+    public ActionGroup(String name) {
51
+        this.name = name;
52
+    }
53
+
42 54
     public String getAuthor() {
43 55
         return author;
44 56
     }
@@ -66,7 +78,5 @@ public class ActionGroup extends ArrayList<Action> {
66 78
     public List<ActionSetting> getSettings() {
67 79
         return settings;
68 80
     }
69
-    
70
-    
71 81
 
72 82
 }

+ 26
- 9
src/com/dmdirc/actions/ActionManager.java View File

@@ -41,7 +41,9 @@ import com.dmdirc.util.WeakMapList;
41 41
 import java.io.File;
42 42
 import java.io.IOException;
43 43
 import java.util.ArrayList;
44
+import java.util.HashMap;
44 45
 import java.util.List;
46
+import java.util.Map;
45 47
 
46 48
 /**
47 49
  * Manages all actions for the client.
@@ -71,8 +73,8 @@ public final class ActionManager {
71 73
             = new MapList<ActionType, Action>();
72 74
     
73 75
     /** A map linking groups and a list of actions that're in them. */
74
-    private final static MapList<String, Action> groups
75
-            = new MapList<String, Action>();
76
+    private final static Map<String, ActionGroup> groups
77
+            = new HashMap<String, ActionGroup>();
76 78
     
77 79
     /** A map of the action type groups to the action types within. */
78 80
     private final static MapList<String, ActionType> actionTypeGroups
@@ -178,7 +180,7 @@ public final class ActionManager {
178 180
      *
179 181
      * @return a map of groups to action lists
180 182
      */
181
-    public static MapList<String, Action> getGroups() {
183
+    public static Map<String, ActionGroup> getGroups() {
182 184
         return groups;
183 185
     }
184 186
     
@@ -291,10 +293,25 @@ public final class ActionManager {
291 293
         if (isWrappedGroup(action.getGroup())) {
292 294
             getWrapper(action.getGroup()).registerAction(action);
293 295
         } else {
294
-            groups.add(action.getGroup(), action);
296
+            getGroup(action.getGroup()).add(action);
295 297
         }
296 298
     }
297 299
     
300
+    /**
301
+     * Retrieves the action group with the specified name. A new group is
302
+     * created if it doesn't already exist.
303
+     * 
304
+     * @param name The name of the group to retrieve
305
+     * @return The corresponding ActionGroup
306
+     */
307
+    public static ActionGroup getGroup(final String name) {
308
+        if (!groups.containsKey(name)) {
309
+            groups.put(name, new ActionGroup(name));
310
+        }
311
+        
312
+        return groups.get(name);
313
+    }
314
+    
298 315
     /**
299 316
      * Unregisters an action with the manager.
300 317
      *
@@ -305,7 +322,7 @@ public final class ActionManager {
305 322
         assert(action != null);
306 323
         
307 324
         actions.removeFromAll(action);
308
-        groups.removeFromAll(action);
325
+        getGroup(action.getGroup()).remove(action);
309 326
     }
310 327
     
311 328
     /**
@@ -407,7 +424,7 @@ public final class ActionManager {
407 424
         assert(!groups.containsKey(group));
408 425
         
409 426
         if (new File(getDirectory() + group).mkdir()) {
410
-            groups.add(group);
427
+            groups.put(group, new ActionGroup(group));
411 428
         }
412 429
     }
413 430
     
@@ -423,7 +440,7 @@ public final class ActionManager {
423 440
     public static void removeGroup(final String group) {
424 441
         assert(group != null);
425 442
         assert(!group.isEmpty());
426
-        assert(groups.containsKey(group));        
443
+        assert(groups.containsKey(group));
427 444
         
428 445
         for (Action action : new ArrayList<Action>(groups.get(group))) {
429 446
             unregisterAction(action);
@@ -474,10 +491,10 @@ public final class ActionManager {
474 491
         
475 492
         for (Action action : groups.get(oldName)) {
476 493
             action.setGroup(newName);
477
-            groups.add(newName, action);
494
+            getGroup(newName).add(action);
478 495
         }
479 496
         
480
-        groups.clear(oldName);
497
+        groups.remove(oldName);
481 498
         
482 499
         removeGroup(oldName);
483 500
     }

+ 3
- 3
src/com/dmdirc/ui/swing/dialogs/actionseditor/ActionsManagerDialog.java View File

@@ -23,17 +23,17 @@
23 23
 package com.dmdirc.ui.swing.dialogs.actionseditor;
24 24
 
25 25
 import com.dmdirc.Main;
26
-import com.dmdirc.actions.Action;
26
+import com.dmdirc.actions.ActionGroup;
27 27
 import com.dmdirc.actions.ActionManager;
28 28
 import com.dmdirc.ui.swing.MainFrame;
29 29
 import com.dmdirc.ui.swing.components.StandardDialog;
30
-import com.dmdirc.util.MapList;
31 30
 
32 31
 import java.awt.Dimension;
33 32
 import java.awt.Insets;
34 33
 import java.awt.event.ActionEvent;
35 34
 import java.awt.event.ActionListener;
36 35
 import java.util.Arrays;
36
+import java.util.Map;
37 37
 
38 38
 import javax.swing.JButton;
39 39
 import javax.swing.JDialog;
@@ -199,7 +199,7 @@ public final class ActionsManagerDialog extends StandardDialog
199 199
 
200 200
         groups.removeAll();
201 201
 
202
-        final MapList<String, Action> actionGroups = ActionManager.getGroups();
202
+        final Map<String, ActionGroup> actionGroups = ActionManager.getGroups();
203 203
 
204 204
         if (actionGroups == null) {
205 205
             return;

Loading…
Cancel
Save