Преглед на файлове

Use some dependency injection

Change-Id: I438b113d8b312b2c241d738047f6d307109dc142
Reviewed-on: http://gerrit.dmdirc.com/2049
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.7rc1
Chris Smith преди 13 години
родител
ревизия
d0409a198b

+ 8
- 6
src/com/dmdirc/addons/activewindow/ActiveWindowPlugin.java Целия файл

@@ -24,16 +24,18 @@ package com.dmdirc.addons.activewindow;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.SwingController;
26 26
 import com.dmdirc.plugins.BasePlugin;
27
-import com.dmdirc.plugins.PluginManager;
28 27
 
29 28
 /** Plugin to provide an active window command to the Swing UI. */
30 29
 public final class ActiveWindowPlugin extends BasePlugin {
31 30
 
32
-    /** Creates a new instance of this plugin. */
33
-    public ActiveWindowPlugin() {
31
+    /**
32
+     * Creates a new instance of this plugin.
33
+     *
34
+     * @param controller The controller to use to find active windows
35
+     */
36
+    public ActiveWindowPlugin(final SwingController controller) {
34 37
         super();
35
-        registerCommand(new ActiveCommand(((SwingController) PluginManager
36
-                .getPluginManager().getPluginInfoByName("ui_swing")
37
-                .getPlugin()).getMainFrame()), ActiveCommand.INFO);
38
+        registerCommand(new ActiveCommand(controller.getMainFrame()),
39
+                ActiveCommand.INFO);
38 40
     }
39 41
 }

+ 7
- 5
src/com/dmdirc/addons/dcc/DCCPlugin.java Целия файл

@@ -70,13 +70,15 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
70 70
     /** Our DCC Container window. */
71 71
     private PlaceholderContainer container;
72 72
 
73
-    /** Creates a new instance of this plugin. */
74
-    public DCCPlugin() {
73
+    /**
74
+     * Creates a new instance of this plugin.
75
+     *
76
+     * @param controller The controller to register UI implementations with
77
+     */
78
+    public DCCPlugin(final SwingController controller) {
75 79
         super();
76 80
         registerCommand(new DCCCommand(this), DCCCommand.INFO);
77
-        final SwingWindowFactory factory = ((SwingController) PluginManager
78
-                .getPluginManager().getPluginInfoByName("ui_swing").getPlugin())
79
-                .getWindowFactory();
81
+        final SwingWindowFactory factory = controller.getWindowFactory();
80 82
         factory.registerImplementation(new HashSet<String>(Arrays.asList(
81 83
                 "com.dmdirc.addons.dcc.ui.PlaceholderPanel")),
82 84
                 PlaceholderWindow.class);

+ 10
- 4
src/com/dmdirc/addons/lagdisplay/LagDisplayPlugin.java Целия файл

@@ -63,7 +63,7 @@ public final class LagDisplayPlugin extends BasePlugin implements
63 63
     private final Map<Server, RollingList<Long>> history
64 64
             = new HashMap<Server, RollingList<Long>>();
65 65
     /** Parent Swing UI. */
66
-    private SwingController controller;
66
+    private final SwingController controller;
67 67
     /** Whether or not to show a graph in the info popup. */
68 68
     private boolean showGraph = true;
69 69
     /** Whether or not to show labels on that graph. */
@@ -71,11 +71,18 @@ public final class LagDisplayPlugin extends BasePlugin implements
71 71
     /** The length of history to keep per-server. */
72 72
     private int historySize = 100;
73 73
 
74
+    /**
75
+     * Creates a new LagDisplayPlugin.
76
+     *
77
+     * @param controller The controller to add components to
78
+     */
79
+    public LagDisplayPlugin(final SwingController controller) {
80
+        this.controller = controller;
81
+    }
82
+
74 83
     /** {@inheritDoc} */
75 84
     @Override
76 85
     public void onLoad() {
77
-        controller = ((SwingController) PluginManager.getPluginManager()
78
-                .getPluginInfoByName("ui_swing").getPlugin());
79 86
         controller.getSwingStatusBar().addComponent(panel);
80 87
         controller.getMainFrame().addSelectionListener(this);
81 88
         IdentityManager.getGlobalConfig().addChangeListener(getDomain(), this);
@@ -93,7 +100,6 @@ public final class LagDisplayPlugin extends BasePlugin implements
93 100
         controller.getSwingStatusBar().removeComponent(panel);
94 101
         IdentityManager.getConfigIdentity().removeListener(this);
95 102
         ActionManager.getActionManager().unregisterListener(this);
96
-        controller = null;
97 103
     }
98 104
 
99 105
     /** Reads the plugin's global configuration settings. */

+ 10
- 5
src/com/dmdirc/addons/swingdebug/SwingDebugPlugin.java Целия файл

@@ -27,7 +27,6 @@ import com.dmdirc.addons.ui_swing.SwingController;
27 27
 import com.dmdirc.addons.ui_swing.components.CheckBoxMenuItem;
28 28
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
29 29
 import com.dmdirc.plugins.BasePlugin;
30
-import com.dmdirc.plugins.PluginManager;
31 30
 
32 31
 import java.awt.Toolkit;
33 32
 import java.awt.event.ActionEvent;
@@ -49,7 +48,7 @@ import net.miginfocom.swing.MigLayout;
49 48
 public class SwingDebugPlugin extends BasePlugin implements ActionListener {
50 49
 
51 50
     /** Swing controller. */
52
-    private SwingController controller;
51
+    private final SwingController controller;
53 52
     /** Debug menu. */
54 53
     private JMenu debugMenu;
55 54
     /** Debug EDT menu item. */
@@ -71,11 +70,18 @@ public class SwingDebugPlugin extends BasePlugin implements ActionListener {
71 70
     /** System error frame. */
72 71
     private JDialog errorFrame;
73 72
 
73
+    /**
74
+     * Creates a new SwingDebugPlugin.
75
+     *
76
+     * @param controller The controller to add debug entries to
77
+     */
78
+    public SwingDebugPlugin(final SwingController controller) {
79
+        this.controller = controller;
80
+    }
81
+
74 82
     /** {@inheritDoc} */
75 83
     @Override
76 84
     public void onLoad() {
77
-        controller = (SwingController) PluginManager.getPluginManager()
78
-                .getPluginInfoByName("ui_swing").getPlugin();
79 85
         try {
80 86
             sysout = System.out;
81 87
             syserr = System.err;
@@ -127,7 +133,6 @@ public class SwingDebugPlugin extends BasePlugin implements ActionListener {
127 133
         outFrame = null;
128 134
         errorFrame = null;
129 135
         controller.getMainFrame().getJMenuBar().remove(debugMenu);
130
-        controller = null;
131 136
     }
132 137
 
133 138
     /**

Loading…
Отказ
Запис