Переглянути джерело

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 роки тому
джерело
коміт
0e6034b960

+ 3
- 0
src/com/dmdirc/addons/activewindow/ActiveCommand.java Переглянути файл

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

+ 68
- 0
src/com/dmdirc/addons/activewindow/ActiveWindowManager.java Переглянути файл

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 Переглянути файл

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

+ 35
- 0
src/com/dmdirc/addons/activewindow/ActiveWindowModule.java Переглянути файл

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 Переглянути файл

22
 
22
 
23
 package com.dmdirc.addons.activewindow;
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
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
26
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
29
 
27
 
28
+import dagger.ObjectGraph;
29
+
30
 /** Plugin to provide an active window command to the Swing UI. */
30
 /** Plugin to provide an active window command to the Swing UI. */
31
 public class ActiveWindowPlugin extends BaseCommandPlugin {
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
     /** {@inheritDoc} */
47
     /** {@inheritDoc} */
61
     @Override
48
     @Override
62
     public void onLoad() {
49
     public void onLoad() {
63
         super.onLoad();
50
         super.onLoad();
64
-
65
-        sinkManager.addSink(sink);
51
+        activeWindowManager.register();
66
     }
52
     }
67
 
53
 
68
     /** {@inheritDoc} */
54
     /** {@inheritDoc} */
69
     @Override
55
     @Override
70
     public void onUnload() {
56
     public void onUnload() {
71
         super.onUnload();
57
         super.onUnload();
72
-
73
-        sinkManager.removeSink(sink);
58
+        activeWindowManager.unregister();
74
     }
59
     }
60
+
75
 }
61
 }

Завантаження…
Відмінити
Зберегти