Browse Source

Daggerify the active window plugin.

Change-Id: I94cf8f9c82b031da084ecf76b5b7bd6cd4b5c293
Reviewed-on: http://gerrit.dmdirc.com/2859
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8
Chris Smith 10 years ago
parent
commit
0e6034b960

+ 3
- 0
src/com/dmdirc/addons/activewindow/ActiveCommand.java View File

@@ -36,6 +36,8 @@ import com.dmdirc.interfaces.CommandController;
36 36
 import com.dmdirc.ui.input.AdditionalTabTargets;
37 37
 import com.dmdirc.ui.input.TabCompleter;
38 38
 
39
+import javax.inject.Inject;
40
+
39 41
 /**
40 42
  * Executes another command as if it were executed in the active window.
41 43
  */
@@ -55,6 +57,7 @@ public class ActiveCommand extends Command implements IntelligentCommand {
55 57
      * @param controller The controller to use for command information.
56 58
      * @param mainFrame Parent MainFrame
57 59
      */
60
+    @Inject
58 61
     public ActiveCommand(final CommandController controller, final MainFrame mainFrame) {
59 62
         super(controller);
60 63
 

+ 68
- 0
src/com/dmdirc/addons/activewindow/ActiveWindowManager.java View File

@@ -0,0 +1,68 @@
1
+/*
2
+ * Copyright (c) 2006-2013 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.activewindow;
24
+
25
+import com.dmdirc.messages.MessageSinkManager;
26
+
27
+import javax.inject.Inject;
28
+
29
+/**
30
+ * Manages the active window sink.
31
+ */
32
+public class ActiveWindowManager {
33
+
34
+    /** The message sink to register and unregister. */
35
+    private final ActiveWindowMessageSink sink;
36
+
37
+    /** The manager to add and remove the sink from. */
38
+    private final MessageSinkManager sinkManager;
39
+
40
+    /**
41
+     * Creates a new instance of {@link ActiveWindowManager}.
42
+     *
43
+     * @param sinkManager The manager to add and remove sinks from.
44
+     * @param sink The sink to be added and removed.
45
+     */
46
+    @Inject
47
+    public ActiveWindowManager(
48
+            final MessageSinkManager sinkManager,
49
+            final ActiveWindowMessageSink sink) {
50
+        this.sink = sink;
51
+        this.sinkManager = sinkManager;
52
+    }
53
+
54
+    /**
55
+     * Registers the sink with the manager.
56
+     */
57
+    public void register() {
58
+        sinkManager.addSink(sink);
59
+    }
60
+
61
+    /**
62
+     * Unregisters the sink from the manager.
63
+     */
64
+    public void unregister() {
65
+        sinkManager.removeSink(sink);
66
+    }
67
+
68
+}

+ 3
- 0
src/com/dmdirc/addons/activewindow/ActiveWindowMessageSink.java View File

@@ -31,6 +31,8 @@ import com.dmdirc.messages.MessageSinkManager;
31 31
 import java.util.Date;
32 32
 import java.util.regex.Pattern;
33 33
 
34
+import javax.inject.Inject;
35
+
34 36
 /**
35 37
  * A message sink which passes messages onto the active swing window.
36 38
  */
@@ -47,6 +49,7 @@ public class ActiveWindowMessageSink implements MessageSink {
47 49
      *
48 50
      * @param mainFrame The mainframe to use to retrieve active windows
49 51
      */
52
+    @Inject
50 53
     public ActiveWindowMessageSink(final MainFrame mainFrame) {
51 54
         this.mainFrame = mainFrame;
52 55
     }

+ 35
- 0
src/com/dmdirc/addons/activewindow/ActiveWindowModule.java View File

@@ -0,0 +1,35 @@
1
+/*
2
+ * Copyright (c) 2006-2013 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.activewindow;
24
+
25
+import com.dmdirc.addons.ui_swing.SwingModule;
26
+
27
+import dagger.Module;
28
+
29
+/**
30
+ * DI module for the active window plugin.
31
+ */
32
+@Module(injects={ActiveWindowManager.class, ActiveCommand.class}, addsTo = SwingModule.class)
33
+public class ActiveWindowModule {
34
+
35
+}

+ 15
- 29
src/com/dmdirc/addons/activewindow/ActiveWindowPlugin.java View File

@@ -22,54 +22,40 @@
22 22
 
23 23
 package com.dmdirc.addons.activewindow;
24 24
 
25
-import com.dmdirc.addons.ui_swing.SwingController;
26
-import com.dmdirc.interfaces.CommandController;
27
-import com.dmdirc.messages.MessageSinkManager;
25
+import com.dmdirc.plugins.PluginInfo;
28 26
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
29 27
 
28
+import dagger.ObjectGraph;
29
+
30 30
 /** Plugin to provide an active window command to the Swing UI. */
31 31
 public class ActiveWindowPlugin extends BaseCommandPlugin {
32 32
 
33
-    /** The message sink to register and unregister. */
34
-    private final ActiveWindowMessageSink sink;
35
-
36
-    /** The manager to add and remove the sink from. */
37
-    private final MessageSinkManager sinkManager;
33
+    /** Manager to use for the active window sink. */
34
+    private ActiveWindowManager activeWindowManager;
38 35
 
39
-    /**
40
-     * Creates a new instance of this plugin.
41
-     *
42
-     * @param controller The controller to use to find active windows
43
-     * @param commandController Command controller to register commands
44
-     * @param sinkManager The manager to add sinks to
45
-     */
46
-    public ActiveWindowPlugin(
47
-            final SwingController controller,
48
-            final CommandController commandController,
49
-            final MessageSinkManager sinkManager) {
50
-        super(commandController);
51
-
52
-        this.sinkManager = sinkManager;
36
+    /** {@inheritDoc} */
37
+    @Override
38
+    public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
39
+        super.load(pluginInfo, graph);
53 40
 
54
-        sink = new ActiveWindowMessageSink(controller.getMainFrame());
41
+        setObjectGraph(graph.plus(new ActiveWindowModule()));
42
+        registerCommand(ActiveCommand.class, ActiveCommand.INFO);
55 43
 
56
-        registerCommand(new ActiveCommand(commandController, controller.getMainFrame()),
57
-                ActiveCommand.INFO);
44
+        activeWindowManager = getObjectGraph().get(ActiveWindowManager.class);
58 45
     }
59 46
 
60 47
     /** {@inheritDoc} */
61 48
     @Override
62 49
     public void onLoad() {
63 50
         super.onLoad();
64
-
65
-        sinkManager.addSink(sink);
51
+        activeWindowManager.register();
66 52
     }
67 53
 
68 54
     /** {@inheritDoc} */
69 55
     @Override
70 56
     public void onUnload() {
71 57
         super.onUnload();
72
-
73
-        sinkManager.removeSink(sink);
58
+        activeWindowManager.unregister();
74 59
     }
60
+
75 61
 }

Loading…
Cancel
Save