瀏覽代碼

Make some plugins dependency inject the action manager

Change-Id: I4e17c971b445f71363cb434db233eca42131745c
Reviewed-on: http://gerrit.dmdirc.com/2165
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.7rc1
Chris Smith 12 年之前
父節點
當前提交
d6a7f72b50

+ 10
- 4
src/com/dmdirc/addons/identd/IdentdPlugin.java 查看文件

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.addons.identd;
24 24
 
25 25
 import com.dmdirc.Server;
26
-import com.dmdirc.actions.ActionManager;
27 26
 import com.dmdirc.actions.CoreActionType;
28 27
 import com.dmdirc.actions.interfaces.ActionType;
29 28
 import com.dmdirc.config.IdentityManager;
@@ -32,6 +31,7 @@ import com.dmdirc.config.prefs.PreferencesCategory;
32 31
 import com.dmdirc.config.prefs.PreferencesDialogModel;
33 32
 import com.dmdirc.config.prefs.PreferencesSetting;
34 33
 import com.dmdirc.config.prefs.PreferencesType;
34
+import com.dmdirc.interfaces.ActionController;
35 35
 import com.dmdirc.interfaces.ActionListener;
36 36
 import com.dmdirc.plugins.BasePlugin;
37 37
 import com.dmdirc.plugins.PluginInfo;
@@ -51,15 +51,21 @@ public class IdentdPlugin extends BasePlugin implements ActionListener {
51 51
     private IdentdServer myServer;
52 52
     /** This plugin's plugin info. */
53 53
     private final PluginInfo pluginInfo;
54
+    /** The action controller to use. */
55
+    private final ActionController actionController;
54 56
 
55 57
     /**
56 58
      * Creates a new instance of this plugin.
57 59
      *
58 60
      * @param pluginInfo This plugin's plugin info
61
+     * @param actionController The action controller to register listeners with
59 62
      */
60
-    public IdentdPlugin(final PluginInfo pluginInfo) {
63
+    public IdentdPlugin(final PluginInfo pluginInfo,
64
+            final ActionController actionController) {
61 65
         super();
66
+
62 67
         this.pluginInfo = pluginInfo;
68
+        this.actionController = actionController;
63 69
     }
64 70
 
65 71
     /**
@@ -68,7 +74,7 @@ public class IdentdPlugin extends BasePlugin implements ActionListener {
68 74
     @Override
69 75
     public void onLoad() {
70 76
         // Add action hooks
71
-        ActionManager.getActionManager().registerListener(this,
77
+        actionController.registerListener(this,
72 78
                 CoreActionType.SERVER_CONNECTED,
73 79
                 CoreActionType.SERVER_CONNECTING,
74 80
                 CoreActionType.SERVER_CONNECTERROR);
@@ -87,7 +93,7 @@ public class IdentdPlugin extends BasePlugin implements ActionListener {
87 93
     public void onUnload() {
88 94
         myServer.stopServer();
89 95
         servers.clear();
90
-        ActionManager.getActionManager().unregisterListener(this);
96
+        actionController.unregisterListener(this);
91 97
     }
92 98
 
93 99
     /**

+ 32
- 24
src/com/dmdirc/addons/logging/LoggingPlugin.java 查看文件

@@ -27,7 +27,6 @@ import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.Main;
28 28
 import com.dmdirc.Query;
29 29
 import com.dmdirc.Server;
30
-import com.dmdirc.actions.ActionManager;
31 30
 import com.dmdirc.actions.CoreActionType;
32 31
 import com.dmdirc.actions.interfaces.ActionType;
33 32
 import com.dmdirc.config.IdentityManager;
@@ -36,6 +35,7 @@ import com.dmdirc.config.prefs.PreferencesCategory;
36 35
 import com.dmdirc.config.prefs.PreferencesDialogModel;
37 36
 import com.dmdirc.config.prefs.PreferencesSetting;
38 37
 import com.dmdirc.config.prefs.PreferencesType;
38
+import com.dmdirc.interfaces.ActionController;
39 39
 import com.dmdirc.interfaces.ActionListener;
40 40
 import com.dmdirc.interfaces.ConfigChangeListener;
41 41
 import com.dmdirc.logger.ErrorLevel;
@@ -85,26 +85,8 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
85 85
     private int historyLines, backbufferLines;
86 86
     /** This plugin's plugin info. */
87 87
     private final PluginInfo pluginInfo;
88
-
89
-    /** Open File. */
90
-    protected static class OpenFile {
91
-
92
-        /** Last used time. */
93
-        public long lastUsedTime = System.currentTimeMillis();
94
-
95
-        /** Open file's writer. */
96
-        public BufferedWriter writer = null;
97
-
98
-        /**
99
-         * Creates a new open file.
100
-         *
101
-         * @param writer Writer that has file open
102
-         */
103
-        protected OpenFile(final BufferedWriter writer) {
104
-            this.writer = writer;
105
-        }
106
-
107
-    }
88
+    /** The action controller to use. */
89
+    private final ActionController actionController;
108 90
 
109 91
     /** Timer used to close idle files. */
110 92
     protected Timer idleFileTimer;
@@ -120,10 +102,15 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
120 102
      * Creates a new instance of this plugin.
121 103
      *
122 104
      * @param pluginInfo This plugin's plugin info
105
+     * @param actionController The action controller to register listeners with
123 106
      */
124
-    public LoggingPlugin(final PluginInfo pluginInfo) {
107
+    public LoggingPlugin(final PluginInfo pluginInfo,
108
+            final ActionController actionController) {
125 109
         super();
110
+
126 111
         this.pluginInfo = pluginInfo;
112
+        this.actionController = actionController;
113
+
127 114
         registerCommand(new LoggingCommand(), LoggingCommand.INFO);
128 115
     }
129 116
 
@@ -154,7 +141,7 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
154 141
 
155 142
         IdentityManager.getGlobalConfig().addChangeListener(getDomain(), this);
156 143
 
157
-        ActionManager.getActionManager().registerListener(this,
144
+        actionController.registerListener(this,
158 145
                 CoreActionType.CHANNEL_OPENED,
159 146
                 CoreActionType.CHANNEL_CLOSED,
160 147
                 CoreActionType.CHANNEL_MESSAGE,
@@ -220,7 +207,7 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
220 207
             idleFileTimer.purge();
221 208
         }
222 209
 
223
-        ActionManager.getActionManager().unregisterListener(this);
210
+        actionController.unregisterListener(this);
224 211
 
225 212
         synchronized (openFiles) {
226 213
             for (OpenFile file : openFiles.values()) {
@@ -228,6 +215,7 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
228 215
             }
229 216
             openFiles.clear();
230 217
         }
218
+
231 219
         super.onUnload();
232 220
     }
233 221
 
@@ -849,4 +837,24 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
849 837
         logDirectory = IdentityManager.getGlobalConfig().getOption(getDomain(), "general.directory");
850 838
     }
851 839
 
840
+    /** Open File. */
841
+    protected static class OpenFile {
842
+
843
+        /** Last used time. */
844
+        public long lastUsedTime = System.currentTimeMillis();
845
+
846
+        /** Open file's writer. */
847
+        public BufferedWriter writer = null;
848
+
849
+        /**
850
+         * Creates a new open file.
851
+         *
852
+         * @param writer Writer that has file open
853
+         */
854
+        protected OpenFile(final BufferedWriter writer) {
855
+            this.writer = writer;
856
+        }
857
+
858
+    }
859
+
852 860
 }

+ 13
- 5
src/com/dmdirc/addons/nowplaying/NowPlayingPlugin.java 查看文件

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.addons.nowplaying;
24 24
 
25
-import com.dmdirc.actions.ActionManager;
26 25
 import com.dmdirc.actions.CoreActionType;
27 26
 import com.dmdirc.actions.interfaces.ActionType;
28 27
 import com.dmdirc.addons.ui_swing.UIUtilities;
@@ -30,6 +29,7 @@ import com.dmdirc.config.IdentityManager;
30 29
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
31 30
 import com.dmdirc.config.prefs.PreferencesCategory;
32 31
 import com.dmdirc.config.prefs.PreferencesDialogModel;
32
+import com.dmdirc.interfaces.ActionController;
33 33
 import com.dmdirc.interfaces.ActionListener;
34 34
 import com.dmdirc.plugins.BasePlugin;
35 35
 import com.dmdirc.plugins.Plugin;
@@ -55,15 +55,22 @@ public class NowPlayingPlugin extends BasePlugin implements ActionListener  {
55 55
     private List<String> order;
56 56
     /** This plugin's plugin info. */
57 57
     private final PluginInfo pluginInfo;
58
+    /** The action controller to use. */
59
+    private final ActionController actionController;
58 60
 
59 61
     /**
60 62
      * Creates a new instance of this plugin.
61 63
      *
62 64
      * @param pluginInfo This plugin's plugin info
65
+     * @param actionController The action controller to register listeners with
63 66
      */
64
-    public NowPlayingPlugin(final PluginInfo pluginInfo) {
67
+    public NowPlayingPlugin(final PluginInfo pluginInfo,
68
+            final ActionController actionController) {
65 69
         super();
70
+
66 71
         this.pluginInfo = pluginInfo;
72
+        this.actionController = actionController;
73
+
67 74
         registerCommand(new NowPlayingCommand(this), NowPlayingCommand.INFO);
68 75
     }
69 76
 
@@ -75,8 +82,8 @@ public class NowPlayingPlugin extends BasePlugin implements ActionListener  {
75 82
 
76 83
         loadSettings();
77 84
 
78
-        ActionManager.getActionManager().registerListener(this,
79
-                CoreActionType.PLUGIN_LOADED, CoreActionType.PLUGIN_UNLOADED);
85
+        actionController.registerListener(this, CoreActionType.PLUGIN_LOADED,
86
+                CoreActionType.PLUGIN_UNLOADED);
80 87
 
81 88
         for (PluginInfo target : PluginManager.getPluginManager().getPluginInfos()) {
82 89
             if (target.isLoaded()) {
@@ -91,7 +98,8 @@ public class NowPlayingPlugin extends BasePlugin implements ActionListener  {
91 98
     public void onUnload() {
92 99
         sources.clear();
93 100
         managers.clear();
94
-        ActionManager.getActionManager().unregisterListener(this);
101
+        actionController.unregisterListener(this);
102
+
95 103
         super.onUnload();
96 104
     }
97 105
 

+ 15
- 5
src/com/dmdirc/addons/parserdebug/DebugPlugin.java 查看文件

@@ -23,9 +23,9 @@
23 23
 package com.dmdirc.addons.parserdebug;
24 24
 
25 25
 import com.dmdirc.Server;
26
-import com.dmdirc.actions.ActionManager;
27 26
 import com.dmdirc.actions.CoreActionType;
28 27
 import com.dmdirc.actions.interfaces.ActionType;
28
+import com.dmdirc.interfaces.ActionController;
29 29
 import com.dmdirc.interfaces.ActionListener;
30 30
 import com.dmdirc.parser.interfaces.Parser;
31 31
 import com.dmdirc.parser.interfaces.callbacks.DebugInfoListener;
@@ -44,24 +44,34 @@ public final class DebugPlugin extends BasePlugin implements DebugInfoListener,
44 44
     /** Map of parsers registered. */
45 45
     protected final Map<Parser, DebugWindow> registeredParsers
46 46
             = new HashMap<Parser, DebugWindow>();
47
+    /** The action controller to use. */
48
+    private final ActionController actionController;
47 49
 
48
-    /** Creates a new instance of this plugin. */
49
-    public DebugPlugin() {
50
+    /**
51
+     * Creates a new instance of this plugin.
52
+     *
53
+     * @param actionController The action controller to register listeners with
54
+     */
55
+    public DebugPlugin(final ActionController actionController) {
50 56
         super();
57
+
58
+        this.actionController = actionController;
59
+
51 60
         registerCommand(new ParserDebugCommand(this), ParserDebugCommand.INFO);
52 61
     }
53 62
 
54 63
     /** {@inheritDoc} */
55 64
     @Override
56 65
     public void onLoad() {
57
-        ActionManager.getActionManager().unregisterListener(this,
58
-                CoreActionType.SERVER_DISCONNECTED);
66
+        actionController.registerListener(this, CoreActionType.SERVER_DISCONNECTED);
59 67
         super.onLoad();
60 68
     }
61 69
 
62 70
     /** {@inheritDoc} */
63 71
     @Override
64 72
     public void onUnload() {
73
+        actionController.unregisterListener(this);
74
+
65 75
         final ArrayList<DebugWindow> windowList = new ArrayList<DebugWindow>();
66 76
         for (Parser parser : registeredParsers.keySet()) {
67 77
             try {

+ 14
- 9
src/com/dmdirc/addons/scriptplugin/ScriptPlugin.java 查看文件

@@ -23,9 +23,9 @@
23 23
 package com.dmdirc.addons.scriptplugin;
24 24
 
25 25
 import com.dmdirc.Main;
26
-import com.dmdirc.actions.ActionManager;
27 26
 import com.dmdirc.actions.CoreActionType;
28 27
 import com.dmdirc.actions.interfaces.ActionType;
28
+import com.dmdirc.interfaces.ActionController;
29 29
 import com.dmdirc.interfaces.ActionListener;
30 30
 import com.dmdirc.logger.ErrorLevel;
31 31
 import com.dmdirc.logger.Logger;
@@ -58,13 +58,19 @@ public final class ScriptPlugin extends BasePlugin implements ActionListener {
58 58
     private Map<String, ScriptEngineWrapper> scripts = new HashMap<String, ScriptEngineWrapper>();
59 59
     /** Used to store permanent variables */
60 60
     protected TypedProperties globalVariables = new TypedProperties();
61
+    /** The action controller to use. */
62
+    private final ActionController actionController;
61 63
 
62 64
     /**
63 65
      * Creates a new instance of the Script Plugin.
66
+     *
67
+     * @param actionController The action controller to register listeners with
64 68
      */
65
-    public ScriptPlugin() {
69
+    public ScriptPlugin(final ActionController actionController) {
66 70
         super();
67 71
 
72
+        this.actionController = actionController;
73
+
68 74
         // Add the JS Helper to the scriptFactory
69 75
         getScriptFactory().put("globalHelper", getJavaScriptHelper());
70 76
         getScriptFactory().put("globalVariables", getGlobalVariables());
@@ -76,8 +82,7 @@ public final class ScriptPlugin extends BasePlugin implements ActionListener {
76 82
     public void onLoad() {
77 83
         // Register the plugin_loaded action initially, this will be called
78 84
         // after this method finishes for us to register the rest.
79
-        ActionManager.getActionManager().registerListener(this,
80
-                CoreActionType.PLUGIN_LOADED);
85
+        actionController.registerListener(this, CoreActionType.PLUGIN_LOADED);
81 86
 
82 87
         // Make sure our scripts dir exists
83 88
         final File newDir = new File(scriptDir);
@@ -101,7 +106,7 @@ public final class ScriptPlugin extends BasePlugin implements ActionListener {
101 106
     /** {@inheritDoc} */
102 107
     @Override
103 108
     public void onUnload() {
104
-        ActionManager.getActionManager().unregisterListener(this);
109
+        actionController.unregisterListener(this);
105 110
 
106 111
         final File savedVariables = new File(scriptDir+"storedVariables");
107 112
         FileOutputStream fos = null;
@@ -121,11 +126,11 @@ public final class ScriptPlugin extends BasePlugin implements ActionListener {
121 126
      * This will unregister all the actions first.
122 127
      */
123 128
     private void registerAll() {
124
-        ActionManager.getActionManager().registerListener(this);
125
-        for (Map.Entry<String, List<ActionType>> entry : ActionManager
126
-                .getActionManager().getGroupedTypes().entrySet()) {
129
+        actionController.registerListener(this);
130
+        for (Map.Entry<String, List<ActionType>> entry
131
+                : actionController.getGroupedTypes().entrySet()) {
127 132
             final List<ActionType> types = entry.getValue();
128
-            ActionManager.getActionManager().registerListener(this,
133
+            actionController.registerListener(this,
129 134
                     types.toArray(new ActionType[types.size()]));
130 135
         }
131 136
     }

+ 11
- 5
src/com/dmdirc/addons/systray/SystrayPlugin.java 查看文件

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.addons.systray;
24 24
 
25
-import com.dmdirc.actions.ActionManager;
26 25
 import com.dmdirc.actions.CoreActionType;
27 26
 import com.dmdirc.actions.interfaces.ActionType;
28 27
 import com.dmdirc.addons.ui_swing.MainFrame;
@@ -33,6 +32,7 @@ import com.dmdirc.config.prefs.PreferencesCategory;
33 32
 import com.dmdirc.config.prefs.PreferencesDialogModel;
34 33
 import com.dmdirc.config.prefs.PreferencesSetting;
35 34
 import com.dmdirc.config.prefs.PreferencesType;
35
+import com.dmdirc.interfaces.ActionController;
36 36
 import com.dmdirc.plugins.BasePlugin;
37 37
 import com.dmdirc.plugins.PluginInfo;
38 38
 import com.dmdirc.plugins.PluginManager;
@@ -64,15 +64,22 @@ public final class SystrayPlugin extends BasePlugin implements ActionListener,
64 64
     private MainFrame mainFrame;
65 65
     /** This plugin's plugin info. */
66 66
     private final PluginInfo pluginInfo;
67
+    /** The action controller to use. */
68
+    private final ActionController actionController;
67 69
 
68 70
     /**
69 71
      * Creates a new system tray plugin.
70 72
      *
71 73
      * @param pluginInfo This plugin's plugin info
74
+     * @param actionController The action controller to use
72 75
      */
73
-    public SystrayPlugin(final PluginInfo pluginInfo) {
76
+    public SystrayPlugin(final PluginInfo pluginInfo,
77
+            final ActionController actionController) {
74 78
         super();
79
+
75 80
         this.pluginInfo = pluginInfo;
81
+        this.actionController = actionController;
82
+
76 83
         final MenuItem show = new MenuItem("Show/hide");
77 84
         final MenuItem quit = new MenuItem("Quit");
78 85
 
@@ -155,8 +162,7 @@ public final class SystrayPlugin extends BasePlugin implements ActionListener,
155 162
             mainFrame = ((SwingController) PluginManager.getPluginManager()
156 163
                     .getPluginInfoByName("ui_swing").getPlugin())
157 164
                     .getMainFrame();
158
-            ActionManager.getActionManager().registerListener(this,
159
-                CoreActionType.CLIENT_MINIMISED);
165
+            actionController.registerListener(this, CoreActionType.CLIENT_MINIMISED);
160 166
         } catch (AWTException ex) {
161 167
             continueLoading = false;
162 168
         }
@@ -170,7 +176,7 @@ public final class SystrayPlugin extends BasePlugin implements ActionListener,
170 176
     @Override
171 177
     public void onUnload() {
172 178
         SystemTray.getSystemTray().remove(icon);
173
-        ActionManager.getActionManager().unregisterListener(this);
179
+        actionController.unregisterListener(this);
174 180
         super.onUnload();
175 181
     }
176 182
 

+ 18
- 12
src/com/dmdirc/addons/time/TimePlugin.java 查看文件

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.time;
24 24
 
25
-import com.dmdirc.actions.ActionManager;
25
+import com.dmdirc.interfaces.ActionController;
26 26
 import com.dmdirc.plugins.BasePlugin;
27 27
 
28 28
 import java.util.Calendar;
@@ -32,7 +32,7 @@ import java.util.TimerTask;
32 32
 /**
33 33
  * Provides various time-related features.
34 34
  */
35
-public final class TimePlugin  extends BasePlugin {
35
+public final class TimePlugin extends BasePlugin {
36 36
 
37 37
     /** Have we registered our types already? */
38 38
     private static boolean registered;
@@ -40,10 +40,19 @@ public final class TimePlugin  extends BasePlugin {
40 40
     private Timer timer;
41 41
     /** The Manager to use for managing timers. */
42 42
     private TimerManager manager;
43
+    /** The action controller to use. */
44
+    private final ActionController actionController;
43 45
 
44
-    /** Creates a new instance of this plugin. */
45
-    public TimePlugin() {
46
+    /**
47
+     * Creates a new instance of this plugin.
48
+     *
49
+     * @param actionController The action controller to register listeners with
50
+     */
51
+    public TimePlugin(final ActionController actionController) {
46 52
         super();
53
+
54
+        this.actionController = actionController;
55
+
47 56
         registerCommand(new TimerCommand(manager), TimerCommand.INFO);
48 57
     }
49 58
 
@@ -51,8 +60,7 @@ public final class TimePlugin  extends BasePlugin {
51 60
     @Override
52 61
     public void onLoad() {
53 62
         if (!registered) {
54
-            ActionManager.getActionManager().registerTypes(
55
-                    TimeActionType.values());
63
+            actionController.registerTypes(TimeActionType.values());
56 64
             registered = true;
57 65
         }
58 66
 
@@ -76,16 +84,13 @@ public final class TimePlugin  extends BasePlugin {
76 84
     public void runTimer() {
77 85
         final Calendar cal = Calendar.getInstance();
78 86
 
79
-        ActionManager.getActionManager().triggerEvent(
80
-                TimeActionType.TIME_MINUTE, null, cal);
87
+        actionController.triggerEvent(TimeActionType.TIME_MINUTE, null, cal);
81 88
 
82 89
         if (cal.get(Calendar.MINUTE) == 0) {
83
-            ActionManager.getActionManager().triggerEvent(
84
-                    TimeActionType.TIME_HOUR, null, cal);
90
+            actionController.triggerEvent(TimeActionType.TIME_HOUR, null, cal);
85 91
 
86 92
             if (cal.get(Calendar.HOUR_OF_DAY) == 0) {
87
-                ActionManager.getActionManager().triggerEvent(
88
-                        TimeActionType.TIME_DAY, null, cal);
93
+                actionController.triggerEvent(TimeActionType.TIME_DAY, null, cal);
89 94
             }
90 95
         }
91 96
     }
@@ -98,6 +103,7 @@ public final class TimePlugin  extends BasePlugin {
98 103
             timer = null;
99 104
         }
100 105
         manager = null;
106
+
101 107
         super.onUnload();
102 108
     }
103 109
 

+ 2
- 1
test/com/dmdirc/addons/logging/TestLoggingPlugin.java 查看文件

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.logging;
24 24
 
25
+import com.dmdirc.interfaces.ActionController;
25 26
 import com.dmdirc.plugins.PluginInfo;
26 27
 import com.dmdirc.util.MapList;
27 28
 import static org.mockito.Mockito.*;
@@ -31,7 +32,7 @@ public class TestLoggingPlugin extends LoggingPlugin {
31 32
     public final MapList<Object, String> lines = new MapList<Object, String>();
32 33
 
33 34
     public TestLoggingPlugin() {
34
-        super(mock(PluginInfo.class));
35
+        super(mock(PluginInfo.class), mock(ActionController.class));
35 36
     }
36 37
 
37 38
     @Override

Loading…
取消
儲存