Browse Source

Make the ActionManager into a singleton

CLIENT-84

Change-Id: I3a874129485b94635edd932399a218347a209ea5
Reviewed-on: http://gerrit.dmdirc.com/1785
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.6.5rc1
Chris Smith 13 years ago
parent
commit
6ea269d2a4
1 changed files with 432 additions and 60 deletions
  1. 432
    60
      src/com/dmdirc/actions/ActionManager.java

+ 432
- 60
src/com/dmdirc/actions/ActionManager.java View File

51
  */
51
  */
52
 public final class ActionManager {
52
 public final class ActionManager {
53
 
53
 
54
+    /** A singleton instance of the ActionManager. */
55
+    private static final ActionManager INSTANCE = new ActionManager();
56
+
54
     /** A list of registered action types. */
57
     /** A list of registered action types. */
55
-    private static final List<ActionType> ACTION_TYPES
58
+    private final List<ActionType> types
56
             = new ArrayList<ActionType>();
59
             = new ArrayList<ActionType>();
57
 
60
 
58
     /** A list of registered action components. */
61
     /** A list of registered action components. */
59
-    private static final List<ActionComponent> ACTION_COMPONENTS
62
+    private final List<ActionComponent> components
60
             = new ArrayList<ActionComponent>();
63
             = new ArrayList<ActionComponent>();
61
 
64
 
62
     /** A list of registered action comparisons. */
65
     /** A list of registered action comparisons. */
63
-    private static final List<ActionComparison> ACTION_COMPARISON
66
+    private final List<ActionComparison> comparisons
64
             = new ArrayList<ActionComparison>();
67
             = new ArrayList<ActionComparison>();
65
 
68
 
66
     /** A map linking types and a list of actions that're registered for them. */
69
     /** A map linking types and a list of actions that're registered for them. */
67
-    private static final MapList<ActionType, Action> ACTIONS
70
+    private final MapList<ActionType, Action> actions
68
             = new MapList<ActionType, Action>();
71
             = new MapList<ActionType, Action>();
69
 
72
 
70
     /** A map linking groups and a list of actions that're in them. */
73
     /** A map linking groups and a list of actions that're in them. */
71
-    private static final Map<String, ActionGroup> GROUPS
74
+    private final Map<String, ActionGroup> groups
72
             = new HashMap<String, ActionGroup>();
75
             = new HashMap<String, ActionGroup>();
73
 
76
 
74
     /** A map of objects to synchronise on for concurrency groups. */
77
     /** A map of objects to synchronise on for concurrency groups. */
75
-    private static final Map<String, Object> LOCKS
78
+    private final Map<String, Object> locks
76
             = new HashMap<String, Object>();
79
             = new HashMap<String, Object>();
77
 
80
 
78
     /** A map of the action type groups to the action types within. */
81
     /** A map of the action type groups to the action types within. */
79
-    private static final MapList<String, ActionType> ACTIONTYPE_GROUPS
82
+    private final MapList<String, ActionType> typeGroups
80
             = new MapList<String, ActionType>();
83
             = new MapList<String, ActionType>();
81
 
84
 
82
     /** The listeners that we have registered. */
85
     /** The listeners that we have registered. */
83
-    private static final MapList<ActionType, ActionListener> LISTENERS
86
+    private final MapList<ActionType, ActionListener> listeners
84
             = new MapList<ActionType, ActionListener>();
87
             = new MapList<ActionType, ActionListener>();
85
 
88
 
86
     /** Indicates whether or not user actions should be killed (not processed). */
89
     /** Indicates whether or not user actions should be killed (not processed). */
87
-    private static boolean killSwitch
90
+    private boolean killSwitch
88
             = IdentityManager.getGlobalConfig().getOptionBool("actions", "killswitch");
91
             = IdentityManager.getGlobalConfig().getOptionBool("actions", "killswitch");
89
 
92
 
90
     /** Creates a new instance of ActionManager. */
93
     /** Creates a new instance of ActionManager. */
92
         // Shouldn't be instansiated
95
         // Shouldn't be instansiated
93
     }
96
     }
94
 
97
 
98
+    /**
99
+     * Returns a singleton instance of the Action Manager.
100
+     *
101
+     * @return A singleton ActionManager instance
102
+     */
103
+    public static ActionManager getActionManager() {
104
+        return INSTANCE;
105
+    }
106
+
95
     /**
107
     /**
96
      * Initialises the action manager.
108
      * Initialises the action manager.
109
+     * @deprecated Use {@link #getActionManager()} and non-static methods
97
      */
110
      */
111
+    @Deprecated
98
     public static void init() {
112
     public static void init() {
113
+        INSTANCE.initialise();
114
+    }
115
+
116
+    /**
117
+     * Initialises the action manager.
118
+     */
119
+    public void initialise() {
99
         registerActionTypes(CoreActionType.values());
120
         registerActionTypes(CoreActionType.values());
100
         registerActionComparisons(CoreActionComparison.values());
121
         registerActionComparisons(CoreActionComparison.values());
101
         registerActionComponents(CoreActionComponent.values());
122
         registerActionComponents(CoreActionComponent.values());
129
 
150
 
130
     /**
151
     /**
131
      * Saves all actions.
152
      * Saves all actions.
153
+     * @deprecated Use {@link #getActionManager()} and non-static methods
132
      */
154
      */
155
+    @Deprecated
133
     public static void saveActions() {
156
     public static void saveActions() {
134
-        for (ActionGroup group : GROUPS.values()) {
157
+        INSTANCE.saveAllActions();
158
+    }
159
+
160
+    /**
161
+     * Saves all actions.
162
+     */
163
+    public void saveAllActions() {
164
+        for (ActionGroup group : groups.values()) {
135
             for (Action action : group) {
165
             for (Action action : group) {
136
                 action.save();
166
                 action.save();
137
             }
167
             }
143
      *
173
      *
144
      * @param name The name of the setting to be registered
174
      * @param name The name of the setting to be registered
145
      * @param value The default value for the setting
175
      * @param value The default value for the setting
176
+     * @deprecated Use {@link #getActionManager()} and non-static methods
146
      */
177
      */
178
+    @Deprecated
147
     public static void registerDefault(final String name, final String value) {
179
     public static void registerDefault(final String name, final String value) {
180
+        INSTANCE.registerSetting(name, value);
181
+    }
182
+
183
+    /**
184
+     * Registers the specified default setting for actions.
185
+     *
186
+     * @param name The name of the setting to be registered
187
+     * @param value The default value for the setting
188
+     */
189
+    public void registerSetting(final String name, final String value) {
148
         IdentityManager.getAddonIdentity().setOption("actions", name, value);
190
         IdentityManager.getAddonIdentity().setOption("actions", name, value);
149
     }
191
     }
150
 
192
 
152
      * Registers the specified group of actions with the manager.
194
      * Registers the specified group of actions with the manager.
153
      *
195
      *
154
      * @param group The group of actions to be registered
196
      * @param group The group of actions to be registered
197
+     * @deprecated Use {@link #getActionManager()} and non-static methods
155
      */
198
      */
199
+    @Deprecated
156
     public static void registerGroup(final ActionGroup group) {
200
     public static void registerGroup(final ActionGroup group) {
157
-        GROUPS.put(group.getName(), group);
201
+        INSTANCE.addGroup(group);
202
+    }
203
+
204
+    /**
205
+     * Registers the specified group of actions with the manager.
206
+     *
207
+     * @param group The group of actions to be registered
208
+     */
209
+    public void addGroup(final ActionGroup group) {
210
+        groups.put(group.getName(), group);
158
     }
211
     }
159
 
212
 
160
     /**
213
     /**
161
      * Registers a set of actiontypes with the manager.
214
      * Registers a set of actiontypes with the manager.
162
      *
215
      *
163
      * @param types An array of ActionTypes to be registered
216
      * @param types An array of ActionTypes to be registered
217
+     * @deprecated Use {@link #getActionManager()} and non-static methods
164
      */
218
      */
219
+    @Deprecated
165
     @Precondition("None of the specified ActionTypes are null")
220
     @Precondition("None of the specified ActionTypes are null")
166
     public static void registerActionTypes(final ActionType[] types) {
221
     public static void registerActionTypes(final ActionType[] types) {
167
-        for (ActionType type : types) {
222
+        INSTANCE.registerTypes(types);
223
+    }
224
+
225
+    /**
226
+     * Registers a set of actiontypes with the manager.
227
+     *
228
+     * @param newTypes An array of ActionTypes to be registered
229
+     */
230
+    @Precondition("None of the specified ActionTypes are null")
231
+    public void registerTypes(final ActionType[] newTypes) {
232
+        for (ActionType type : newTypes) {
168
             Logger.assertTrue(type != null);
233
             Logger.assertTrue(type != null);
169
 
234
 
170
-            if(!ACTION_TYPES.contains(type)) {
171
-                ACTION_TYPES.add(type);
172
-                ACTIONTYPE_GROUPS.add(type.getType().getGroup(), type);
235
+            if(!types.contains(type)) {
236
+                types.add(type);
237
+                typeGroups.add(type.getType().getGroup(), type);
173
             }
238
             }
174
         }
239
         }
175
     }
240
     }
178
      * Registers a set of action components with the manager.
243
      * Registers a set of action components with the manager.
179
      *
244
      *
180
      * @param comps An array of ActionComponents to be registered
245
      * @param comps An array of ActionComponents to be registered
246
+     * @deprecated Use {@link #getActionManager()} and non-static methods
181
      */
247
      */
248
+    @Deprecated
182
     @Precondition("None of the specified ActionComponents are null")
249
     @Precondition("None of the specified ActionComponents are null")
183
     public static void registerActionComponents(final ActionComponent[] comps) {
250
     public static void registerActionComponents(final ActionComponent[] comps) {
251
+        INSTANCE.registerComponents(comps);
252
+    }
253
+
254
+    /**
255
+     * Registers a set of action components with the manager.
256
+     *
257
+     * @param comps An array of ActionComponents to be registered
258
+     */
259
+    @Precondition("None of the specified ActionComponents are null")
260
+    public void registerComponents(final ActionComponent[] comps) {
184
         for (ActionComponent comp : comps) {
261
         for (ActionComponent comp : comps) {
185
             Logger.assertTrue(comp != null);
262
             Logger.assertTrue(comp != null);
186
 
263
 
187
-            ACTION_COMPONENTS.add(comp);
264
+            components.add(comp);
188
         }
265
         }
189
     }
266
     }
190
 
267
 
192
      * Registers a set of action comparisons with the manager.
269
      * Registers a set of action comparisons with the manager.
193
      *
270
      *
194
      * @param comps An array of ActionComparisons to be registered
271
      * @param comps An array of ActionComparisons to be registered
272
+     * @deprecated Use {@link #getActionManager()} and non-static methods
195
      */
273
      */
274
+    @Deprecated
196
     @Precondition("None of the specified ActionComparisons are null")
275
     @Precondition("None of the specified ActionComparisons are null")
197
     public static void registerActionComparisons(final ActionComparison[] comps) {
276
     public static void registerActionComparisons(final ActionComparison[] comps) {
277
+        INSTANCE.registerComparisons(comps);
278
+    }
279
+
280
+    /**
281
+     * Registers a set of action comparisons with the manager.
282
+     *
283
+     * @param comps An array of ActionComparisons to be registered
284
+     */
285
+    @Precondition("None of the specified ActionComparisons are null")
286
+    public void registerComparisons(final ActionComparison[] comps) {
198
         for (ActionComparison comp : comps) {
287
         for (ActionComparison comp : comps) {
199
             Logger.assertTrue(comp != null);
288
             Logger.assertTrue(comp != null);
200
 
289
 
201
-            ACTION_COMPARISON.add(comp);
290
+            comparisons.add(comp);
202
         }
291
         }
203
     }
292
     }
204
 
293
 
206
      * Returns a map of groups to action lists.
295
      * Returns a map of groups to action lists.
207
      *
296
      *
208
      * @return a map of groups to action lists
297
      * @return a map of groups to action lists
298
+     * @deprecated Use {@link #getActionManager()} and non-static methods
209
      */
299
      */
300
+    @Deprecated
210
     public static Map<String, ActionGroup> getGroups() {
301
     public static Map<String, ActionGroup> getGroups() {
211
-        return GROUPS;
302
+        return INSTANCE.getGroupsMap();
303
+    }
304
+
305
+    /**
306
+     * Returns a map of groups to action lists.
307
+     *
308
+     * @return a map of groups to action lists
309
+     */
310
+    public Map<String, ActionGroup> getGroupsMap() {
311
+        return groups;
212
     }
312
     }
213
 
313
 
214
     /**
314
     /**
215
      * Returns a map of type groups to types.
315
      * Returns a map of type groups to types.
216
      *
316
      *
217
      * @return A map of type groups to types
317
      * @return A map of type groups to types
318
+     * @deprecated Use {@link #getActionManager()} and non-static methods
218
      */
319
      */
320
+    @Deprecated
219
     public static MapList<String, ActionType> getTypeGroups() {
321
     public static MapList<String, ActionType> getTypeGroups() {
220
-        return ACTIONTYPE_GROUPS;
322
+        return INSTANCE.getGroupedTypes();
323
+    }
324
+
325
+    /**
326
+     * Returns a map of type groups to types.
327
+     *
328
+     * @return A map of type groups to types
329
+     */
330
+    public MapList<String, ActionType> getGroupedTypes() {
331
+        return typeGroups;
221
     }
332
     }
222
 
333
 
223
     /**
334
     /**
224
      * Loads actions from the user's directory.
335
      * Loads actions from the user's directory.
336
+     * @deprecated Use {@link #getActionManager()} and non-static methods
225
      */
337
      */
338
+    @Deprecated
226
     public static void loadActions() {
339
     public static void loadActions() {
227
-        ACTIONS.clear();
340
+        INSTANCE.loadUserActions();
341
+    }
342
+
343
+    /**
344
+     * Loads actions from the user's directory.
345
+     */
346
+    public void loadUserActions() {
347
+        actions.clear();
228
 
348
 
229
-        for (ActionGroup group : GROUPS.values()) {
349
+        for (ActionGroup group : groups.values()) {
230
             group.clear();
350
             group.clear();
231
         }
351
         }
232
 
352
 
258
     /**
378
     /**
259
      * Creates new ActionGroupComponents for each action group.
379
      * Creates new ActionGroupComponents for each action group.
260
      */
380
      */
261
-    private static void registerComponents() {
262
-        for (ActionGroup group : GROUPS.values()) {
381
+    private void registerComponents() {
382
+        for (ActionGroup group : groups.values()) {
263
             new ActionGroupComponent(group);
383
             new ActionGroupComponent(group);
264
         }
384
         }
265
     }
385
     }
270
      * @param dir The directory to scan.
390
      * @param dir The directory to scan.
271
      */
391
      */
272
     @Precondition("The specified File is not null and represents a directory")
392
     @Precondition("The specified File is not null and represents a directory")
273
-    private static void loadActions(final File dir) {
393
+    private void loadActions(final File dir) {
274
         Logger.assertTrue(dir != null);
394
         Logger.assertTrue(dir != null);
275
         Logger.assertTrue(dir.isDirectory());
395
         Logger.assertTrue(dir.isDirectory());
276
 
396
 
277
-        if (!GROUPS.containsKey(dir.getName())) {
278
-            GROUPS.put(dir.getName(), new ActionGroup(dir.getName()));
397
+        if (!groups.containsKey(dir.getName())) {
398
+            groups.put(dir.getName(), new ActionGroup(dir.getName()));
279
         }
399
         }
280
 
400
 
281
         for (File file : dir.listFiles()) {
401
         for (File file : dir.listFiles()) {
287
      * Registers an action with the manager.
407
      * Registers an action with the manager.
288
      *
408
      *
289
      * @param action The action to be registered
409
      * @param action The action to be registered
410
+     * @deprecated Use {@link #getActionManager()} and non-static methods
290
      */
411
      */
412
+    @Deprecated
291
     @Precondition("The specified action is not null")
413
     @Precondition("The specified action is not null")
292
     public static void registerAction(final Action action) {
414
     public static void registerAction(final Action action) {
415
+        INSTANCE.addAction(action);
416
+    }
417
+
418
+    /**
419
+     * Registers an action with the manager.
420
+     *
421
+     * @param action The action to be registered
422
+     */
423
+    @Precondition("The specified action is not null")
424
+    public void addAction(final Action action) {
293
         Logger.assertTrue(action != null);
425
         Logger.assertTrue(action != null);
294
 
426
 
295
         for (ActionType trigger : action.getTriggers()) {
427
         for (ActionType trigger : action.getTriggers()) {
296
-            ACTIONS.add(trigger, action);
428
+            actions.add(trigger, action);
297
         }
429
         }
298
 
430
 
299
         getGroup(action.getGroup()).add(action);
431
         getGroup(action.getGroup()).add(action);
305
      *
437
      *
306
      * @param name The name of the group to retrieve
438
      * @param name The name of the group to retrieve
307
      * @return The corresponding ActionGroup
439
      * @return The corresponding ActionGroup
440
+     * @deprecated Use {@link #getActionManager()} and non-static methods
308
      */
441
      */
442
+    @Deprecated
309
     public static ActionGroup getGroup(final String name) {
443
     public static ActionGroup getGroup(final String name) {
310
-        if (!GROUPS.containsKey(name)) {
311
-            GROUPS.put(name, new ActionGroup(name));
444
+        return INSTANCE.getOrCreateGroup(name);
445
+    }
446
+
447
+    /**
448
+     * Retrieves the action group with the specified name. A new group is
449
+     * created if it doesn't already exist.
450
+     *
451
+     * @param name The name of the group to retrieve
452
+     * @return The corresponding ActionGroup
453
+     */
454
+    public ActionGroup getOrCreateGroup(final String name) {
455
+        if (!groups.containsKey(name)) {
456
+            groups.put(name, new ActionGroup(name));
312
         }
457
         }
313
 
458
 
314
-        return GROUPS.get(name);
459
+        return groups.get(name);
315
     }
460
     }
316
 
461
 
317
     /**
462
     /**
318
      * Unregisters an action with the manager.
463
      * Unregisters an action with the manager.
319
      *
464
      *
320
      * @param action The action to be unregistered
465
      * @param action The action to be unregistered
466
+     * @deprecated Use {@link #getActionManager()} and non-static methods
321
      */
467
      */
468
+    @Deprecated
322
     @Precondition("The specified action is not null")
469
     @Precondition("The specified action is not null")
323
     public static void unregisterAction(final Action action) {
470
     public static void unregisterAction(final Action action) {
471
+        INSTANCE.removeAction(action);
472
+    }
473
+
474
+    /**
475
+     * Unregisters an action with the manager.
476
+     *
477
+     * @param action The action to be unregistered
478
+     */
479
+    @Precondition("The specified action is not null")
480
+    public void removeAction(final Action action) {
324
         Logger.assertTrue(action != null);
481
         Logger.assertTrue(action != null);
325
 
482
 
326
-        ACTIONS.removeFromAll(action);
483
+        actions.removeFromAll(action);
327
         getGroup(action.getGroup()).remove(action);
484
         getGroup(action.getGroup()).remove(action);
328
     }
485
     }
329
 
486
 
332
      * triggers change.
489
      * triggers change.
333
      *
490
      *
334
      * @param action The action to be reregistered
491
      * @param action The action to be reregistered
492
+     * @deprecated Use {@link #getActionManager()} and non-static methods
335
      */
493
      */
494
+    @Deprecated
336
     public static void reregisterAction(final Action action) {
495
     public static void reregisterAction(final Action action) {
337
         unregisterAction(action);
496
         unregisterAction(action);
338
         registerAction(action);
497
         registerAction(action);
363
      * @param arguments The arguments for the event
522
      * @param arguments The arguments for the event
364
      * @return True if the event should be processed, or false if an action
523
      * @return True if the event should be processed, or false if an action
365
      * listener has requested the event be skipped.
524
      * listener has requested the event be skipped.
525
+     * @deprecated Use {@link #getActionManager()} and non-static methods
366
      */
526
      */
527
+    @Deprecated
367
     @Precondition({
528
     @Precondition({
368
         "The specified ActionType is not null",
529
         "The specified ActionType is not null",
369
         "The specified ActionType has a valid ActionMetaType",
530
         "The specified ActionType has a valid ActionMetaType",
371
     })
532
     })
372
     public static boolean processEvent(final ActionType type,
533
     public static boolean processEvent(final ActionType type,
373
             final StringBuffer format, final Object ... arguments) {
534
             final StringBuffer format, final Object ... arguments) {
535
+        return INSTANCE.triggerEvent(type, format, arguments);
536
+    }
537
+
538
+    /**
539
+     * Processes an event of the specified type.
540
+     *
541
+     * @param type The type of the event to process
542
+     * @param format The format of the message that's going to be displayed for
543
+     * the event. Actions may change this format.
544
+     * @param arguments The arguments for the event
545
+     * @return True if the event should be processed, or false if an action
546
+     * listener has requested the event be skipped.
547
+     */
548
+    @Precondition({
549
+        "The specified ActionType is not null",
550
+        "The specified ActionType has a valid ActionMetaType",
551
+        "The length of the arguments array equals the arity of the ActionType's ActionMetaType"
552
+    })
553
+    public boolean triggerEvent(final ActionType type,
554
+            final StringBuffer format, final Object ... arguments) {
374
         Logger.assertTrue(type != null);
555
         Logger.assertTrue(type != null);
375
         Logger.assertTrue(type.getType() != null);
556
         Logger.assertTrue(type.getType() != null);
376
         Logger.assertTrue(type.getType().getArity() == arguments.length);
557
         Logger.assertTrue(type.getType().getArity() == arguments.length);
377
 
558
 
378
         boolean res = false;
559
         boolean res = false;
379
 
560
 
380
-        if (LISTENERS.containsKey(type)) {
561
+        if (listeners.containsKey(type)) {
381
             for (ActionListener listener
562
             for (ActionListener listener
382
-                    : new ArrayList<ActionListener>(LISTENERS.get(type))) {
563
+                    : new ArrayList<ActionListener>(listeners.get(type))) {
383
                 try {
564
                 try {
384
                     listener.processEvent(type, format, arguments);
565
                     listener.processEvent(type, format, arguments);
385
                 } catch (Exception e) {
566
                 } catch (Exception e) {
406
      * @return True if the event should be skipped, or false if it can continue
587
      * @return True if the event should be skipped, or false if it can continue
407
      */
588
      */
408
     @Precondition("The specified ActionType is not null")
589
     @Precondition("The specified ActionType is not null")
409
-    private static boolean triggerActions(final ActionType type,
590
+    private boolean triggerActions(final ActionType type,
410
             final StringBuffer format, final Object ... arguments) {
591
             final StringBuffer format, final Object ... arguments) {
411
         Logger.assertTrue(type != null);
592
         Logger.assertTrue(type != null);
412
 
593
 
413
         boolean res = false;
594
         boolean res = false;
414
 
595
 
415
-        if (ACTIONS.containsKey(type)) {
416
-            for (Action action : new ArrayList<Action>(ACTIONS.get(type))) {
596
+        if (actions.containsKey(type)) {
597
+            for (Action action : new ArrayList<Action>(actions.get(type))) {
417
                 try {
598
                 try {
418
                     if (action.getConcurrencyGroup() == null) {
599
                     if (action.getConcurrencyGroup() == null) {
419
                         res |= action.trigger(format, arguments);
600
                         res |= action.trigger(format, arguments);
420
                     } else {
601
                     } else {
421
-                        synchronized (LOCKS) {
422
-                            if (!LOCKS.containsKey(action.getConcurrencyGroup())) {
423
-                                LOCKS.put(action.getConcurrencyGroup(), new Object());
602
+                        synchronized (locks) {
603
+                            if (!locks.containsKey(action.getConcurrencyGroup())) {
604
+                                locks.put(action.getConcurrencyGroup(), new Object());
424
                             }
605
                             }
425
                         }
606
                         }
426
 
607
 
427
-                        synchronized (LOCKS.get(action.getConcurrencyGroup())) {
608
+                        synchronized (locks.get(action.getConcurrencyGroup())) {
428
                             res |= action.trigger(format, arguments);
609
                             res |= action.trigger(format, arguments);
429
                         }
610
                         }
430
                     }
611
                     }
456
      * @param group The group to be created
637
      * @param group The group to be created
457
      *
638
      *
458
      * @return The newly created group
639
      * @return The newly created group
640
+     * @deprecated Use {@link #getActionManager()} and non-static methods
459
      */
641
      */
642
+    @Deprecated
460
     @Precondition({
643
     @Precondition({
461
         "The specified group is non-null and not empty",
644
         "The specified group is non-null and not empty",
462
         "The specified group is not an existing group"
645
         "The specified group is not an existing group"
463
     })
646
     })
464
     public static ActionGroup makeGroup(final String group) {
647
     public static ActionGroup makeGroup(final String group) {
648
+        return INSTANCE.createGroup(group);
649
+    }
650
+
651
+    /**
652
+     * Creates a new group with the specified name.
653
+     *
654
+     * @param group The group to be created
655
+     *
656
+     * @return The newly created group
657
+     */
658
+    @Precondition({
659
+        "The specified group is non-null and not empty",
660
+        "The specified group is not an existing group"
661
+    })
662
+    public ActionGroup createGroup(final String group) {
465
         Logger.assertTrue(group != null);
663
         Logger.assertTrue(group != null);
466
         Logger.assertTrue(!group.isEmpty());
664
         Logger.assertTrue(!group.isEmpty());
467
-        Logger.assertTrue(!GROUPS.containsKey(group));
665
+        Logger.assertTrue(!groups.containsKey(group));
468
 
666
 
469
         final File file = new File(getDirectory() + group);
667
         final File file = new File(getDirectory() + group);
470
         if (file.isDirectory() || file.mkdir()) {
668
         if (file.isDirectory() || file.mkdir()) {
471
             final ActionGroup actionGroup = new ActionGroup(group);
669
             final ActionGroup actionGroup = new ActionGroup(group);
472
-            GROUPS.put(group, actionGroup);
670
+            groups.put(group, actionGroup);
473
             return actionGroup;
671
             return actionGroup;
474
         } else {
672
         } else {
475
             throw new IllegalArgumentException("Unable to create action group directory"
673
             throw new IllegalArgumentException("Unable to create action group directory"
481
      * Removes the group with the specified name.
679
      * Removes the group with the specified name.
482
      *
680
      *
483
      * @param group The group to be removed
681
      * @param group The group to be removed
682
+     * @deprecated Use {@link #getActionManager()} and non-static methods
484
      */
683
      */
684
+    @Deprecated
485
     @Precondition({
685
     @Precondition({
486
         "The specified group is non-null and not empty",
686
         "The specified group is non-null and not empty",
487
         "The specified group is an existing group"
687
         "The specified group is an existing group"
488
     })
688
     })
489
     public static void removeGroup(final String group) {
689
     public static void removeGroup(final String group) {
690
+        INSTANCE.deleteGroup(group);
691
+    }
692
+
693
+    /**
694
+     * Removes the group with the specified name.
695
+     *
696
+     * @param group The group to be removed
697
+     */
698
+    @Precondition({
699
+        "The specified group is non-null and not empty",
700
+        "The specified group is an existing group"
701
+    })
702
+    public void deleteGroup(final String group) {
490
         Logger.assertTrue(group != null);
703
         Logger.assertTrue(group != null);
491
         Logger.assertTrue(!group.isEmpty());
704
         Logger.assertTrue(!group.isEmpty());
492
-        Logger.assertTrue(GROUPS.containsKey(group));
705
+        Logger.assertTrue(groups.containsKey(group));
493
 
706
 
494
-        for (Action action : GROUPS.get(group).getActions()) {
707
+        for (Action action : groups.get(group).getActions()) {
495
             unregisterAction(action);
708
             unregisterAction(action);
496
         }
709
         }
497
 
710
 
513
             return;
726
             return;
514
         }
727
         }
515
 
728
 
516
-        GROUPS.remove(group);
729
+        groups.remove(group);
517
     }
730
     }
518
 
731
 
519
     /**
732
     /**
521
      *
734
      *
522
      * @param oldName The old name of the group
735
      * @param oldName The old name of the group
523
      * @param newName The new name of the group
736
      * @param newName The new name of the group
737
+     * @deprecated Use {@link #getActionManager()} and non-static methods
524
      */
738
      */
739
+    @Deprecated
525
     @Precondition({
740
     @Precondition({
526
         "The old name is non-null and not empty",
741
         "The old name is non-null and not empty",
527
         "The old name is an existing group",
742
         "The old name is an existing group",
530
         "The old name does not equal the new name"
745
         "The old name does not equal the new name"
531
     })
746
     })
532
     public static void renameGroup(final String oldName, final String newName) {
747
     public static void renameGroup(final String oldName, final String newName) {
748
+        INSTANCE.changeGroupName(oldName, newName);
749
+    }
750
+
751
+    /**
752
+     * Renames the specified group.
753
+     *
754
+     * @param oldName The old name of the group
755
+     * @param newName The new name of the group
756
+     */
757
+    @Precondition({
758
+        "The old name is non-null and not empty",
759
+        "The old name is an existing group",
760
+        "The new name is non-null and not empty",
761
+        "The new name is not an existing group",
762
+        "The old name does not equal the new name"
763
+    })
764
+    public void changeGroupName(final String oldName, final String newName) {
533
         Logger.assertTrue(oldName != null);
765
         Logger.assertTrue(oldName != null);
534
         Logger.assertTrue(!oldName.isEmpty());
766
         Logger.assertTrue(!oldName.isEmpty());
535
         Logger.assertTrue(newName != null);
767
         Logger.assertTrue(newName != null);
536
         Logger.assertTrue(!newName.isEmpty());
768
         Logger.assertTrue(!newName.isEmpty());
537
-        Logger.assertTrue(GROUPS.containsKey(oldName));
538
-        Logger.assertTrue(!GROUPS.containsKey(newName));
769
+        Logger.assertTrue(groups.containsKey(oldName));
770
+        Logger.assertTrue(!groups.containsKey(newName));
539
         Logger.assertTrue(!newName.equals(oldName));
771
         Logger.assertTrue(!newName.equals(oldName));
540
 
772
 
541
         makeGroup(newName);
773
         makeGroup(newName);
542
 
774
 
543
-        for (Action action : GROUPS.get(oldName).getActions()) {
775
+        for (Action action : groups.get(oldName).getActions()) {
544
             action.setGroup(newName);
776
             action.setGroup(newName);
545
             getGroup(oldName).remove(action);
777
             getGroup(oldName).remove(action);
546
             getGroup(newName).add(action);
778
             getGroup(newName).add(action);
554
      * doesn't match a valid registered action comparison.
786
      * doesn't match a valid registered action comparison.
555
      *
787
      *
556
      * @param type The name of the action comparison to try and find
788
      * @param type The name of the action comparison to try and find
557
-     * @return The actioncomparison with the specified name, or null on failure
789
+     * @return The type with the specified name, or null on failure
790
+     * @deprecated Use {@link #getActionManager()} and non-static methods
558
      */
791
      */
792
+    @Deprecated
559
     public static ActionType getActionType(final String type) {
793
     public static ActionType getActionType(final String type) {
794
+        return INSTANCE.getType(type);
795
+    }
796
+
797
+    /**
798
+     * Returns the action comparison specified by the given string, or null if it
799
+     * doesn't match a valid registered action comparison.
800
+     *
801
+     * @param type The name of the action comparison to try and find
802
+     * @return The type with the specified name, or null on failure
803
+     */
804
+    public ActionType getType(final String type) {
560
         if (type == null || type.isEmpty()) {
805
         if (type == null || type.isEmpty()) {
561
             return null;
806
             return null;
562
         }
807
         }
563
 
808
 
564
-        for (ActionType target : ACTION_TYPES) {
809
+        for (ActionType target : types) {
565
             if (target.name().equals(type)) {
810
             if (target.name().equals(type)) {
566
                 return target;
811
                 return target;
567
             }
812
             }
576
      *
821
      *
577
      * @param type The type to be checked against
822
      * @param type The type to be checked against
578
      * @return A list of compatible action types
823
      * @return A list of compatible action types
824
+     * @deprecated Use {@link #getActionManager()} and non-static methods
579
      */
825
      */
826
+    @Deprecated
580
     @Precondition("The specified type is not null")
827
     @Precondition("The specified type is not null")
581
     public static List<ActionType> getCompatibleTypes(final ActionType type) {
828
     public static List<ActionType> getCompatibleTypes(final ActionType type) {
829
+        return INSTANCE.findCompatibleTypes(type);
830
+    }
831
+
832
+    /**
833
+     * Returns a list of action types that are compatible with the one
834
+     * specified.
835
+     *
836
+     * @param type The type to be checked against
837
+     * @return A list of compatible action types
838
+     */
839
+    @Precondition("The specified type is not null")
840
+    public List<ActionType> findCompatibleTypes(final ActionType type) {
582
         Logger.assertTrue(type != null);
841
         Logger.assertTrue(type != null);
583
 
842
 
584
         final List<ActionType> res = new ArrayList<ActionType>();
843
         final List<ActionType> res = new ArrayList<ActionType>();
585
-        for (ActionType target : ACTION_TYPES) {
844
+        for (ActionType target : types) {
586
             if (!target.equals(type) && target.getType().equals(type.getType())) {
845
             if (!target.equals(type) && target.getType().equals(type.getType())) {
587
                 res.add(target);
846
                 res.add(target);
588
             }
847
             }
597
      *
856
      *
598
      * @param target The class to be tested
857
      * @param target The class to be tested
599
      * @return A list of compatible action components
858
      * @return A list of compatible action components
859
+     * @deprecated Use {@link #getActionManager()} and non-static methods
600
      */
860
      */
861
+    @Deprecated
601
     @Precondition("The specified target is not null")
862
     @Precondition("The specified target is not null")
602
     public static List<ActionComponent> getCompatibleComponents(final Class<?> target) {
863
     public static List<ActionComponent> getCompatibleComponents(final Class<?> target) {
864
+        return INSTANCE.findCompatibleComponents(target);
865
+    }
866
+
867
+    /**
868
+     * Returns a list of action components that are compatible with the
869
+     * specified class.
870
+     *
871
+     * @param target The class to be tested
872
+     * @return A list of compatible action components
873
+     */
874
+    @Precondition("The specified target is not null")
875
+    public List<ActionComponent> findCompatibleComponents(final Class<?> target) {
603
         Logger.assertTrue(target != null);
876
         Logger.assertTrue(target != null);
604
 
877
 
605
         final List<ActionComponent> res = new ArrayList<ActionComponent>();
878
         final List<ActionComponent> res = new ArrayList<ActionComponent>();
606
-        for (ActionComponent subject : ACTION_COMPONENTS) {
879
+        for (ActionComponent subject : components) {
607
             if (subject.appliesTo().equals(target)) {
880
             if (subject.appliesTo().equals(target)) {
608
                 res.add(subject);
881
                 res.add(subject);
609
             }
882
             }
618
      *
891
      *
619
      * @param target The class to be tested
892
      * @param target The class to be tested
620
      * @return A list of compatible action comparisons
893
      * @return A list of compatible action comparisons
894
+     * @deprecated Use {@link #getActionManager()} and non-static methods
621
      */
895
      */
896
+    @Deprecated
622
     @Precondition("The specified target is not null")
897
     @Precondition("The specified target is not null")
623
     public static List<ActionComparison> getCompatibleComparisons(final Class<?> target) {
898
     public static List<ActionComparison> getCompatibleComparisons(final Class<?> target) {
899
+        return INSTANCE.findCompatibleComparisons(target);
900
+    }
901
+
902
+    /**
903
+     * Returns a list of action comparisons that are compatible with the
904
+     * specified class.
905
+     *
906
+     * @param target The class to be tested
907
+     * @return A list of compatible action comparisons
908
+     */
909
+    @Precondition("The specified target is not null")
910
+    public List<ActionComparison> findCompatibleComparisons(final Class<?> target) {
624
         Logger.assertTrue(target != null);
911
         Logger.assertTrue(target != null);
625
 
912
 
626
         final List<ActionComparison> res = new ArrayList<ActionComparison>();
913
         final List<ActionComparison> res = new ArrayList<ActionComparison>();
627
-        for (ActionComparison subject : ACTION_COMPARISON) {
914
+        for (ActionComparison subject : comparisons) {
628
             if (subject.appliesTo().equals(target)) {
915
             if (subject.appliesTo().equals(target)) {
629
                 res.add(subject);
916
                 res.add(subject);
630
             }
917
             }
637
      * Returns a list of all the action types registered by this manager.
924
      * Returns a list of all the action types registered by this manager.
638
      *
925
      *
639
      * @return A list of registered action types
926
      * @return A list of registered action types
927
+     * @deprecated Use {@link #getActionManager()} and non-static methods
640
      */
928
      */
929
+    @Deprecated
641
     public static List<ActionType> getTypes() {
930
     public static List<ActionType> getTypes() {
642
-        return ACTION_TYPES;
931
+        return INSTANCE.getAllTypes();
932
+    }
933
+
934
+    /**
935
+     * Returns a list of all the action types registered by this manager.
936
+     *
937
+     * @return A list of registered action types
938
+     */
939
+    public List<ActionType> getAllTypes() {
940
+        return types;
643
     }
941
     }
644
 
942
 
645
     /**
943
     /**
646
      * Returns a list of all the action types registered by this manager.
944
      * Returns a list of all the action types registered by this manager.
647
      *
945
      *
648
      * @return A list of registered action comparisons
946
      * @return A list of registered action comparisons
947
+     * @deprecated Use {@link #getActionManager()} and non-static methods
649
      */
948
      */
949
+    @Deprecated
650
     public static List<ActionComparison> getComparisons() {
950
     public static List<ActionComparison> getComparisons() {
651
-        return ACTION_COMPARISON;
951
+        return INSTANCE.getAllComparisons();
952
+    }
953
+
954
+    /**
955
+     * Returns a list of all the action types registered by this manager.
956
+     *
957
+     * @return A list of registered action comparisons
958
+     */
959
+    public List<ActionComparison> getAllComparisons() {
960
+        return comparisons;
652
     }
961
     }
653
 
962
 
654
     /**
963
     /**
657
      *
966
      *
658
      * @param type The name of the action component to try and find
967
      * @param type The name of the action component to try and find
659
      * @return The actioncomponent with the specified name, or null on failure
968
      * @return The actioncomponent with the specified name, or null on failure
969
+     * @deprecated Use {@link #getActionManager()} and non-static methods
660
      */
970
      */
971
+    @Deprecated
661
     @Precondition("The specified type is non-null and not empty")
972
     @Precondition("The specified type is non-null and not empty")
662
     public static ActionComponent getActionComponent(final String type) {
973
     public static ActionComponent getActionComponent(final String type) {
974
+        return INSTANCE.getComponent(type);
975
+    }
976
+
977
+    /**
978
+     * Returns the action component specified by the given string, or null if it
979
+     * doesn't match a valid registered action component.
980
+     *
981
+     * @param type The name of the action component to try and find
982
+     * @return The actioncomponent with the specified name, or null on failure
983
+     */
984
+    @Precondition("The specified type is non-null and not empty")
985
+    public ActionComponent getComponent(final String type) {
663
         Logger.assertTrue(type != null);
986
         Logger.assertTrue(type != null);
664
         Logger.assertTrue(!type.isEmpty());
987
         Logger.assertTrue(!type.isEmpty());
665
 
988
 
666
-        for (ActionComponent target : ACTION_COMPONENTS) {
989
+        for (ActionComponent target : components) {
667
             if (target.name().equals(type)) {
990
             if (target.name().equals(type)) {
668
                 return target;
991
                 return target;
669
             }
992
             }
678
      *
1001
      *
679
      * @param type The name of the action type to try and find
1002
      * @param type The name of the action type to try and find
680
      * @return The actiontype with the specified name, or null on failure
1003
      * @return The actiontype with the specified name, or null on failure
1004
+     * @deprecated Use {@link #getActionManager()} and non-static methods
681
      */
1005
      */
1006
+    @Deprecated
682
     @Precondition("The specified type is non-null and not empty")
1007
     @Precondition("The specified type is non-null and not empty")
683
     public static ActionComparison getActionComparison(final String type) {
1008
     public static ActionComparison getActionComparison(final String type) {
1009
+        return INSTANCE.getComparison(type);
1010
+    }
1011
+
1012
+    /**
1013
+     * Returns the action type specified by the given string, or null if it
1014
+     * doesn't match a valid registered action type.
1015
+     *
1016
+     * @param type The name of the action type to try and find
1017
+     * @return The actiontype with the specified name, or null on failure
1018
+     */
1019
+    @Precondition("The specified type is non-null and not empty")
1020
+    public ActionComparison getComparison(final String type) {
684
         Logger.assertTrue(type != null);
1021
         Logger.assertTrue(type != null);
685
         Logger.assertTrue(!type.isEmpty());
1022
         Logger.assertTrue(!type.isEmpty());
686
 
1023
 
687
-        for (ActionComparison target : ACTION_COMPARISON) {
1024
+        for (ActionComparison target : comparisons) {
688
             if (target.name().equals(type)) {
1025
             if (target.name().equals(type)) {
689
                 return target;
1026
                 return target;
690
             }
1027
             }
714
      *
1051
      *
715
      * @param types The action types that are to be listened for
1052
      * @param types The action types that are to be listened for
716
      * @param listener The listener to be added
1053
      * @param listener The listener to be added
1054
+     * @deprecated Use {@link #getActionManager()} and non-static methods
717
      */
1055
      */
1056
+    @Deprecated
718
     public static void addListener(final ActionListener listener, final ActionType ... types) {
1057
     public static void addListener(final ActionListener listener, final ActionType ... types) {
1058
+        INSTANCE.registerListener(listener, types);
1059
+    }
1060
+
1061
+    /**
1062
+     * Adds a new listener for the specified action type.
1063
+     *
1064
+     * @param types The action types that are to be listened for
1065
+     * @param listener The listener to be added
1066
+     */
1067
+    public void registerListener(final ActionListener listener, final ActionType ... types) {
719
         for (ActionType type : types) {
1068
         for (ActionType type : types) {
720
-            LISTENERS.add(type, listener);
1069
+            listeners.add(type, listener);
721
         }
1070
         }
722
     }
1071
     }
723
 
1072
 
726
      *
1075
      *
727
      * @param types The action types that were being listened for
1076
      * @param types The action types that were being listened for
728
      * @param listener The listener to be removed
1077
      * @param listener The listener to be removed
1078
+     * @deprecated Use {@link #getActionManager()} and non-static methods
729
      */
1079
      */
1080
+    @Deprecated
730
     public static void removeListener(final ActionListener listener, final ActionType ... types) {
1081
     public static void removeListener(final ActionListener listener, final ActionType ... types) {
1082
+        INSTANCE.unregisterListener(listener, types);
1083
+    }
1084
+
1085
+    /**
1086
+     * Removes a listener for the specified action type.
1087
+     *
1088
+     * @param types The action types that were being listened for
1089
+     * @param listener The listener to be removed
1090
+     */
1091
+    public void unregisterListener(final ActionListener listener, final ActionType ... types) {
731
         for (ActionType type : types) {
1092
         for (ActionType type : types) {
732
-            LISTENERS.remove(type, listener);
1093
+            listeners.remove(type, listener);
733
         }
1094
         }
734
     }
1095
     }
735
 
1096
 
737
      * Removes a listener for all action types.
1098
      * Removes a listener for all action types.
738
      *
1099
      *
739
      * @param listener The listener to be removed
1100
      * @param listener The listener to be removed
1101
+     * @deprecated Use {@link #getActionManager()} and non-static methods
740
      */
1102
      */
1103
+    @Deprecated
741
     public static void removeListener(final ActionListener listener) {
1104
     public static void removeListener(final ActionListener listener) {
742
-        LISTENERS.removeFromAll(listener);
1105
+        INSTANCE.unregisterListener(listener);
1106
+    }
1107
+
1108
+    /**
1109
+     * Removes a listener for all action types.
1110
+     *
1111
+     * @param listener The listener to be removed
1112
+     */
1113
+    public void unregisterListener(final ActionListener listener) {
1114
+        listeners.removeFromAll(listener);
743
     }
1115
     }
744
 }
1116
 }

Loading…
Cancel
Save