瀏覽代碼

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
      * Gets the message sink manager for the client.
187
      * Gets the message sink manager for the client.
188
      *
188
      *
189
      * @param statusBarManager The status bar manager to use for status bar sinks.
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
      * @return The message sink manager the client should use.
191
      * @return The message sink manager the client should use.
191
      */
192
      */
192
     @Provides
193
     @Provides
193
     @Singleton
194
     @Singleton
194
-    public MessageSinkManager getMessageSinkManager(final StatusBarManager statusBarManager) {
195
+    public MessageSinkManager getMessageSinkManager(
196
+            final StatusBarManager statusBarManager,
197
+            final WindowManager windowManager) {
195
         final MessageSinkManager messageSinkManager = new MessageSinkManager();
198
         final MessageSinkManager messageSinkManager = new MessageSinkManager();
196
         MessageSinkManager.setManager(messageSinkManager);
199
         MessageSinkManager.setManager(messageSinkManager);
197
-        messageSinkManager.loadDefaultSinks(statusBarManager);
200
+        messageSinkManager.loadDefaultSinks(statusBarManager, windowManager);
198
         return messageSinkManager;
201
         return messageSinkManager;
199
     }
202
     }
200
 
203
 
367
         return manager;
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
      * Gets a preferences manager.
374
      * Gets a preferences manager.
382
      *
375
      *

+ 64
- 34
src/com/dmdirc/GlobalWindow.java 查看文件

27
 import com.dmdirc.commandparser.CommandType;
27
 import com.dmdirc.commandparser.CommandType;
28
 import com.dmdirc.commandparser.parsers.CommandParser;
28
 import com.dmdirc.commandparser.parsers.CommandParser;
29
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
30
-import com.dmdirc.config.IdentityManager;
30
+import com.dmdirc.interfaces.CommandController;
31
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
31
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
 import com.dmdirc.interfaces.config.ConfigChangeListener;
32
 import com.dmdirc.interfaces.config.ConfigChangeListener;
33
+import com.dmdirc.interfaces.config.IdentityController;
33
 import com.dmdirc.ui.WindowManager;
34
 import com.dmdirc.ui.WindowManager;
34
 import com.dmdirc.ui.core.components.WindowComponent;
35
 import com.dmdirc.ui.core.components.WindowComponent;
35
 import com.dmdirc.ui.input.TabCompleter;
36
 import com.dmdirc.ui.input.TabCompleter;
37
 
38
 
38
 import java.util.Arrays;
39
 import java.util.Arrays;
39
 
40
 
41
+import javax.inject.Inject;
42
+import javax.inject.Provider;
43
+import javax.inject.Singleton;
44
+
40
 import lombok.Getter;
45
 import lombok.Getter;
41
 
46
 
42
 /**
47
 /**
109
         return -1;
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
 
22
 
23
 package com.dmdirc;
23
 package com.dmdirc;
24
 
24
 
25
+import com.dmdirc.GlobalWindow.GlobalWindowManager;
25
 import com.dmdirc.actions.ActionManager;
26
 import com.dmdirc.actions.ActionManager;
26
 import com.dmdirc.actions.CoreActionType;
27
 import com.dmdirc.actions.CoreActionType;
27
 import com.dmdirc.commandline.CommandLineParser;
28
 import com.dmdirc.commandline.CommandLineParser;
84
     /** The command manager to use. */
85
     /** The command manager to use. */
85
     private final CommandManager commandManager;
86
     private final CommandManager commandManager;
86
 
87
 
88
+    /** The global window manager to use. */
89
+    private final GlobalWindowManager globalWindowManager;
90
+
87
     /** The commands to load into the command manager. */
91
     /** The commands to load into the command manager. */
88
     private final Set<CommandDetails> commands;
92
     private final Set<CommandDetails> commands;
89
 
93
 
98
      * @param commandManager The command manager the client will use.
102
      * @param commandManager The command manager the client will use.
99
      * @param messageSinkManager Unused for now - TODO: remove me when it's injected somewhere sensible.
103
      * @param messageSinkManager Unused for now - TODO: remove me when it's injected somewhere sensible.
100
      * @param themeManager Unused for now - TODO: remove me when it's injected somewhere sensible.
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
      * @param corePluginExtractor Extractor to use for core plugins.
105
      * @param corePluginExtractor Extractor to use for core plugins.
103
      * @param urlBuilder URL builder to use as a singleton.
106
      * @param urlBuilder URL builder to use as a singleton.
107
+     * @param globalWindowManager Global window manager to use.
104
      * @param commands The commands to be loaded into the command manager.
108
      * @param commands The commands to be loaded into the command manager.
105
      */
109
      */
106
     @Inject
110
     @Inject
115
             final ThemeManager themeManager,
119
             final ThemeManager themeManager,
116
             final CorePluginExtractor corePluginExtractor,
120
             final CorePluginExtractor corePluginExtractor,
117
             final URLBuilder urlBuilder,
121
             final URLBuilder urlBuilder,
122
+            final GlobalWindowManager globalWindowManager,
118
             final Set<CommandDetails> commands) {
123
             final Set<CommandDetails> commands) {
119
         this.identityManager = identityManager;
124
         this.identityManager = identityManager;
120
         this.serverManager = serverManager;
125
         this.serverManager = serverManager;
123
         this.pluginManager = pluginManager;
128
         this.pluginManager = pluginManager;
124
         this.corePluginExtractor = corePluginExtractor;
129
         this.corePluginExtractor = corePluginExtractor;
125
         this.commandManager = commandManager;
130
         this.commandManager = commandManager;
131
+        this.globalWindowManager = globalWindowManager;
126
         this.commands = commands;
132
         this.commands = commands;
127
         URLBuilder.setInstance(urlBuilder);
133
         URLBuilder.setInstance(urlBuilder);
128
     }
134
     }
149
 
155
 
150
     /**
156
     /**
151
      * Initialises the client.
157
      * Initialises the client.
152
-     *
153
-     * @param args The command line arguments
154
      */
158
      */
155
     public void init() {
159
     public void init() {
156
         for (CommandDetails command : commands) {
160
         for (CommandDetails command : commands) {
168
 
172
 
169
         commandLineParser.processArguments(serverManager);
173
         commandLineParser.processArguments(serverManager);
170
 
174
 
171
-        GlobalWindow.init();
175
+        globalWindowManager.init();
172
 
176
 
173
         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
177
         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
174
             /** {@inheritDoc} */
178
             /** {@inheritDoc} */

+ 3
- 3
src/com/dmdirc/commandparser/parsers/CommandParser.java 查看文件

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

+ 2
- 2
src/com/dmdirc/commandparser/parsers/GlobalCommandParser.java 查看文件

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

+ 5
- 2
src/com/dmdirc/messages/MessageSinkManager.java 查看文件

129
      * Loads the default message sinks into this manager.
129
      * Loads the default message sinks into this manager.
130
      *
130
      *
131
      * @param statusBarManager The status bar manager to give to status-bar related sinks.
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
         addSink(new AllMessageSink());
137
         addSink(new AllMessageSink());
135
         addSink(new ChannelMessageSink());
138
         addSink(new ChannelMessageSink());
136
         addSink(new CommonChanelsMessageSink());
139
         addSink(new CommonChanelsMessageSink());
137
-        addSink(new CustomWindowMessageSink(WindowManager.getWindowManager()));
140
+        addSink(new CustomWindowMessageSink(windowManager));
138
         addSink(new ForkMessageSink());
141
         addSink(new ForkMessageSink());
139
         addSink(new FormatMessageSink());
142
         addSink(new FormatMessageSink());
140
         addSink(new GroupMessageSink());
143
         addSink(new GroupMessageSink());

+ 11
- 11
src/com/dmdirc/ui/WindowManager.java 查看文件

34
 import java.util.List;
34
 import java.util.List;
35
 import java.util.concurrent.CopyOnWriteArrayList;
35
 import java.util.concurrent.CopyOnWriteArrayList;
36
 
36
 
37
+import javax.inject.Inject;
38
+import javax.inject.Singleton;
39
+
37
 /**
40
 /**
38
  * The WindowManager maintains a list of all open windows, and their
41
  * The WindowManager maintains a list of all open windows, and their
39
  * parent/child relations.
42
  * parent/child relations.
40
  */
43
  */
44
+@Singleton
41
 public class WindowManager {
45
 public class WindowManager {
42
 
46
 
43
-    /** Singleton instance of the WindowManager. */
44
-    private static final WindowManager INSTANCE = new WindowManager();
45
-
46
     /** A list of root windows. */
47
     /** A list of root windows. */
47
     private final List<FrameContainer> rootWindows = new CopyOnWriteArrayList<>();
48
     private final List<FrameContainer> rootWindows = new CopyOnWriteArrayList<>();
48
 
49
 
49
     /** A list of frame listeners. */
50
     /** A list of frame listeners. */
50
     private final ListenerList listeners = new ListenerList();
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
      * Registers a FrameListener with the WindowManager.
61
      * Registers a FrameListener with the WindowManager.
54
      *
62
      *
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
 import com.dmdirc.FrameContainer;
25
 import com.dmdirc.FrameContainer;
26
 import com.dmdirc.commandparser.CommandArguments;
26
 import com.dmdirc.commandparser.CommandArguments;
27
 import com.dmdirc.commandparser.CommandInfo;
27
 import com.dmdirc.commandparser.CommandInfo;
28
-import com.dmdirc.commandparser.CommandManager;
29
 import com.dmdirc.commandparser.CommandType;
28
 import com.dmdirc.commandparser.CommandType;
30
 import com.dmdirc.commandparser.commands.Command;
29
 import com.dmdirc.commandparser.commands.Command;
31
 import com.dmdirc.commandparser.parsers.CommandParser;
30
 import com.dmdirc.commandparser.parsers.CommandParser;
31
+import com.dmdirc.interfaces.CommandController;
32
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
33
 
33
 
34
-
35
 public class TestCommandParser extends CommandParser {
34
 public class TestCommandParser extends CommandParser {
36
     private static final long serialVersionUID = 7073002401375438532L;
35
     private static final long serialVersionUID = 7073002401375438532L;
37
 
36
 
48
     public String invalidCommand;
47
     public String invalidCommand;
49
 
48
 
50
     public TestCommandParser(final AggregateConfigProvider configManager,
49
     public TestCommandParser(final AggregateConfigProvider configManager,
51
-            final CommandManager commandManager) {
50
+            final CommandController commandManager) {
52
         super(configManager, commandManager);
51
         super(configManager, commandManager);
53
         this.configManager = configManager;
52
         this.configManager = configManager;
54
     }
53
     }

Loading…
取消
儲存