Преглед изворни кода

Remove the remaining WindowManager singleton refs.

Add a GlobalWindowManager to keep state and references, rather than
use static methods on GlobalWindow.

Minor tidying.

Change-Id: I65b84082f0a07cdc9e4c05263f6c5c77282e9b04
Reviewed-on: http://gerrit.dmdirc.com/2818
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8rc1
Chris Smith пре 10 година
родитељ
комит
2fcdd341d6

+ 5
- 12
src/com/dmdirc/ClientModule.java Прегледај датотеку

@@ -187,14 +187,17 @@ public class ClientModule {
187 187
      * Gets the message sink manager for the client.
188 188
      *
189 189
      * @param statusBarManager The status bar manager to use for status bar sinks.
190
+     * @param windowManager The window manager to use for sinks that iterate windows.
190 191
      * @return The message sink manager the client should use.
191 192
      */
192 193
     @Provides
193 194
     @Singleton
194
-    public MessageSinkManager getMessageSinkManager(final StatusBarManager statusBarManager) {
195
+    public MessageSinkManager getMessageSinkManager(
196
+            final StatusBarManager statusBarManager,
197
+            final WindowManager windowManager) {
195 198
         final MessageSinkManager messageSinkManager = new MessageSinkManager();
196 199
         MessageSinkManager.setManager(messageSinkManager);
197
-        messageSinkManager.loadDefaultSinks(statusBarManager);
200
+        messageSinkManager.loadDefaultSinks(statusBarManager, windowManager);
198 201
         return messageSinkManager;
199 202
     }
200 203
 
@@ -367,16 +370,6 @@ public class ClientModule {
367 370
         return manager;
368 371
     }
369 372
 
370
-    /**
371
-     * Gets a window manager.
372
-     *
373
-     * @return A singleton window manager.
374
-     */
375
-    @Provides
376
-    public WindowManager getWindowManager() {
377
-        return new WindowManager();
378
-    }
379
-
380 373
     /**
381 374
      * Gets a preferences manager.
382 375
      *

+ 64
- 34
src/com/dmdirc/GlobalWindow.java Прегледај датотеку

@@ -27,9 +27,10 @@ import com.dmdirc.commandparser.CommandManager;
27 27
 import com.dmdirc.commandparser.CommandType;
28 28
 import com.dmdirc.commandparser.parsers.CommandParser;
29 29
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
30
-import com.dmdirc.config.IdentityManager;
30
+import com.dmdirc.interfaces.CommandController;
31 31
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32 32
 import com.dmdirc.interfaces.config.ConfigChangeListener;
33
+import com.dmdirc.interfaces.config.IdentityController;
33 34
 import com.dmdirc.ui.WindowManager;
34 35
 import com.dmdirc.ui.core.components.WindowComponent;
35 36
 import com.dmdirc.ui.input.TabCompleter;
@@ -37,6 +38,10 @@ import com.dmdirc.ui.input.TabCompletionType;
37 38
 
38 39
 import java.util.Arrays;
39 40
 
41
+import javax.inject.Inject;
42
+import javax.inject.Provider;
43
+import javax.inject.Singleton;
44
+
40 45
 import lombok.Getter;
41 46
 
42 47
 /**
@@ -109,43 +114,68 @@ public class GlobalWindow extends WritableFrameContainer {
109 114
         return -1;
110 115
     }
111 116
 
112
-    /**
113
-     * Initialises the global window if it's enabled in the config.
114
-     */
115
-    public static void init() {
116
-        IdentityManager.getIdentityManager().getGlobalConfiguration()
117
-                .addChangeListener("general", "showglobalwindow",
118
-                new ConfigChangeListener() {
119
-
120
-            @Override
121
-            public void configChanged(final String domain, final String key) {
122
-                updateWindowState();
123
-            }
124
-        });
117
+    /** Handles the state of the global window. */
118
+    @Singleton
119
+    public static class GlobalWindowManager implements ConfigChangeListener {
120
+
121
+        /** The global configuration to read settings from. */
122
+        private final AggregateConfigProvider globalConfig;
123
+        /** The provider to use to retrieve a command controller. */
124
+        private final Provider<CommandController> commandControllerProvider;
125
+        /** The provider to use to retrieve a window manager. */
126
+        private final Provider<WindowManager> windowManagerProvider;
127
+
128
+        /**
129
+         * Creates a new instance of {@link GlobalWindowManager}.
130
+         *
131
+         * @param identityController Controller to retrieve global configuration from.
132
+         * @param commandControllerProvider The provider to use to retrieve a command controller.
133
+         * @param windowManagerProvider The provider to use to retrieve a window manager.
134
+         */
135
+        @Inject
136
+        public GlobalWindowManager(
137
+                final IdentityController identityController,
138
+                final Provider<CommandController> commandControllerProvider,
139
+                final Provider<WindowManager> windowManagerProvider) {
140
+            this.globalConfig = identityController.getGlobalConfiguration();
141
+            this.commandControllerProvider = commandControllerProvider;
142
+            this.windowManagerProvider = windowManagerProvider;
143
+        }
125 144
 
126
-        updateWindowState();
127
-    }
145
+        /** {@inheritDoc} */
146
+        @Override
147
+        public void configChanged(final String domain, final String key) {
148
+            updateWindowState();
149
+        }
128 150
 
129
-    /**
130
-     * Updates the state of the global window in line with the
131
-     * general.showglobalwindow config setting.
132
-     */
133
-    protected static void updateWindowState() {
134
-        final AggregateConfigProvider configManager = IdentityManager.getIdentityManager()
135
-                .getGlobalConfiguration();
136
-
137
-        synchronized (GlobalWindow.class) {
138
-            if (configManager.getOptionBool("general", "showglobalwindow")) {
139
-                if (globalWindow == null) {
140
-                    globalWindow = new GlobalWindow(configManager,
141
-                            new GlobalCommandParser(configManager,
142
-                                    CommandManager.getCommandManager()), WindowManager.getWindowManager());
143
-                }
144
-            } else {
145
-                if (globalWindow != null) {
146
-                    globalWindow.close();
151
+        /**
152
+         * Initialises the global window if it's enabled in the config.
153
+         */
154
+        public void init() {
155
+            globalConfig.addChangeListener("general", "showglobalwindow", this);
156
+            updateWindowState();
157
+        }
158
+
159
+        /**
160
+         * Updates the state of the global window in line with the
161
+         * general.showglobalwindow config setting.
162
+         */
163
+        protected void updateWindowState() {
164
+            synchronized (GlobalWindow.class) {
165
+                if (globalConfig.getOptionBool("general", "showglobalwindow")) {
166
+                    if (globalWindow == null) {
167
+                        globalWindow = new GlobalWindow(globalConfig,
168
+                                new GlobalCommandParser(globalConfig, commandControllerProvider.get()),
169
+                                windowManagerProvider.get());
170
+                    }
171
+                } else {
172
+                    if (globalWindow != null) {
173
+                        globalWindow.close();
174
+                    }
147 175
                 }
148 176
             }
149 177
         }
178
+
150 179
     }
180
+
151 181
 }

+ 8
- 4
src/com/dmdirc/Main.java Прегледај датотеку

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
+import com.dmdirc.GlobalWindow.GlobalWindowManager;
25 26
 import com.dmdirc.actions.ActionManager;
26 27
 import com.dmdirc.actions.CoreActionType;
27 28
 import com.dmdirc.commandline.CommandLineParser;
@@ -84,6 +85,9 @@ public class Main {
84 85
     /** The command manager to use. */
85 86
     private final CommandManager commandManager;
86 87
 
88
+    /** The global window manager to use. */
89
+    private final GlobalWindowManager globalWindowManager;
90
+
87 91
     /** The commands to load into the command manager. */
88 92
     private final Set<CommandDetails> commands;
89 93
 
@@ -98,9 +102,9 @@ public class Main {
98 102
      * @param commandManager The command manager the client will use.
99 103
      * @param messageSinkManager Unused for now - TODO: remove me when it's injected somewhere sensible.
100 104
      * @param themeManager Unused for now - TODO: remove me when it's injected somewhere sensible.
101
-     * @param aliasWrapper Alias wrapper to provide to the actions manager.
102 105
      * @param corePluginExtractor Extractor to use for core plugins.
103 106
      * @param urlBuilder URL builder to use as a singleton.
107
+     * @param globalWindowManager Global window manager to use.
104 108
      * @param commands The commands to be loaded into the command manager.
105 109
      */
106 110
     @Inject
@@ -115,6 +119,7 @@ public class Main {
115 119
             final ThemeManager themeManager,
116 120
             final CorePluginExtractor corePluginExtractor,
117 121
             final URLBuilder urlBuilder,
122
+            final GlobalWindowManager globalWindowManager,
118 123
             final Set<CommandDetails> commands) {
119 124
         this.identityManager = identityManager;
120 125
         this.serverManager = serverManager;
@@ -123,6 +128,7 @@ public class Main {
123 128
         this.pluginManager = pluginManager;
124 129
         this.corePluginExtractor = corePluginExtractor;
125 130
         this.commandManager = commandManager;
131
+        this.globalWindowManager = globalWindowManager;
126 132
         this.commands = commands;
127 133
         URLBuilder.setInstance(urlBuilder);
128 134
     }
@@ -149,8 +155,6 @@ public class Main {
149 155
 
150 156
     /**
151 157
      * Initialises the client.
152
-     *
153
-     * @param args The command line arguments
154 158
      */
155 159
     public void init() {
156 160
         for (CommandDetails command : commands) {
@@ -168,7 +172,7 @@ public class Main {
168 172
 
169 173
         commandLineParser.processArguments(serverManager);
170 174
 
171
-        GlobalWindow.init();
175
+        globalWindowManager.init();
172 176
 
173 177
         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
174 178
             /** {@inheritDoc} */

+ 3
- 3
src/com/dmdirc/commandparser/parsers/CommandParser.java Прегледај датотеку

@@ -29,12 +29,12 @@ import com.dmdirc.actions.CoreActionType;
29 29
 import com.dmdirc.commandparser.CommandArguments;
30 30
 import com.dmdirc.commandparser.CommandInfo;
31 31
 import com.dmdirc.commandparser.CommandInfoPair;
32
-import com.dmdirc.commandparser.CommandManager;
33 32
 import com.dmdirc.commandparser.CommandType;
34 33
 import com.dmdirc.commandparser.commands.Command;
35 34
 import com.dmdirc.commandparser.commands.CommandOptions;
36 35
 import com.dmdirc.commandparser.commands.ExternalCommand;
37 36
 import com.dmdirc.commandparser.commands.PreviousCommand;
37
+import com.dmdirc.interfaces.CommandController;
38 38
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
39 39
 import com.dmdirc.util.collections.RollingList;
40 40
 
@@ -70,11 +70,11 @@ public abstract class CommandParser implements Serializable {
70 70
 
71 71
     /** Command manager to use. */
72 72
     @Getter
73
-    protected final CommandManager commandManager;
73
+    protected final CommandController commandManager;
74 74
 
75 75
     /** Creates a new instance of CommandParser. */
76 76
     protected CommandParser(final AggregateConfigProvider configManager,
77
-            final CommandManager commandManager) {
77
+            final CommandController commandManager) {
78 78
         commands = new HashMap<>();
79 79
         history = new RollingList<>(configManager.getOptionInt("general", "commandhistory"));
80 80
         this.commandManager = commandManager;

+ 2
- 2
src/com/dmdirc/commandparser/parsers/GlobalCommandParser.java Прегледај датотеку

@@ -25,10 +25,10 @@ package com.dmdirc.commandparser.parsers;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.commandparser.CommandInfo;
28
-import com.dmdirc.commandparser.CommandManager;
29 28
 import com.dmdirc.commandparser.CommandType;
30 29
 import com.dmdirc.commandparser.commands.Command;
31 30
 import com.dmdirc.commandparser.commands.context.CommandContext;
31
+import com.dmdirc.interfaces.CommandController;
32 32
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
33 33
 import com.dmdirc.logger.ErrorLevel;
34 34
 import com.dmdirc.logger.Logger;
@@ -52,7 +52,7 @@ public class GlobalCommandParser extends CommandParser {
52 52
      * @param commandManager Command manager to load commands from
53 53
      */
54 54
     public GlobalCommandParser(final AggregateConfigProvider configManager,
55
-            final CommandManager commandManager) {
55
+            final CommandController commandManager) {
56 56
         super(configManager, commandManager);
57 57
     }
58 58
 

+ 5
- 2
src/com/dmdirc/messages/MessageSinkManager.java Прегледај датотеку

@@ -129,12 +129,15 @@ public class MessageSinkManager {
129 129
      * Loads the default message sinks into this manager.
130 130
      *
131 131
      * @param statusBarManager The status bar manager to give to status-bar related sinks.
132
+     * @param windowManager The window manager to give to sinks that iterate windows.
132 133
      */
133
-    public void loadDefaultSinks(final StatusBarManager statusBarManager) {
134
+    public void loadDefaultSinks(
135
+            final StatusBarManager statusBarManager,
136
+            final WindowManager windowManager) {
134 137
         addSink(new AllMessageSink());
135 138
         addSink(new ChannelMessageSink());
136 139
         addSink(new CommonChanelsMessageSink());
137
-        addSink(new CustomWindowMessageSink(WindowManager.getWindowManager()));
140
+        addSink(new CustomWindowMessageSink(windowManager));
138 141
         addSink(new ForkMessageSink());
139 142
         addSink(new FormatMessageSink());
140 143
         addSink(new GroupMessageSink());

+ 11
- 11
src/com/dmdirc/ui/WindowManager.java Прегледај датотеку

@@ -34,21 +34,29 @@ import java.util.Collections;
34 34
 import java.util.List;
35 35
 import java.util.concurrent.CopyOnWriteArrayList;
36 36
 
37
+import javax.inject.Inject;
38
+import javax.inject.Singleton;
39
+
37 40
 /**
38 41
  * The WindowManager maintains a list of all open windows, and their
39 42
  * parent/child relations.
40 43
  */
44
+@Singleton
41 45
 public class WindowManager {
42 46
 
43
-    /** Singleton instance of the WindowManager. */
44
-    private static final WindowManager INSTANCE = new WindowManager();
45
-
46 47
     /** A list of root windows. */
47 48
     private final List<FrameContainer> rootWindows = new CopyOnWriteArrayList<>();
48 49
 
49 50
     /** A list of frame listeners. */
50 51
     private final ListenerList listeners = new ListenerList();
51 52
 
53
+    /**
54
+     * Creates a new instance of {@link WindowManager}.
55
+     */
56
+    @Inject
57
+    public WindowManager() {
58
+    }
59
+
52 60
     /**
53 61
      * Registers a FrameListener with the WindowManager.
54 62
      *
@@ -343,12 +351,4 @@ public class WindowManager {
343 351
         }
344 352
     }
345 353
 
346
-    /**
347
-     * Returns a singleton instance of the WindowManager.
348
-     *
349
-     * @return A singleton WindowManager instance
350
-     */
351
-    public static WindowManager getWindowManager() {
352
-        return INSTANCE;
353
-    }
354 354
 }

+ 2
- 3
test/com/dmdirc/harness/TestCommandParser.java Прегледај датотеку

@@ -25,13 +25,12 @@ package com.dmdirc.harness;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.commandparser.CommandInfo;
28
-import com.dmdirc.commandparser.CommandManager;
29 28
 import com.dmdirc.commandparser.CommandType;
30 29
 import com.dmdirc.commandparser.commands.Command;
31 30
 import com.dmdirc.commandparser.parsers.CommandParser;
31
+import com.dmdirc.interfaces.CommandController;
32 32
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
33 33
 
34
-
35 34
 public class TestCommandParser extends CommandParser {
36 35
     private static final long serialVersionUID = 7073002401375438532L;
37 36
 
@@ -48,7 +47,7 @@ public class TestCommandParser extends CommandParser {
48 47
     public String invalidCommand;
49 48
 
50 49
     public TestCommandParser(final AggregateConfigProvider configManager,
51
-            final CommandManager commandManager) {
50
+            final CommandController commandManager) {
52 51
         super(configManager, commandManager);
53 52
         this.configManager = configManager;
54 53
     }

Loading…
Откажи
Сачувај