Explorar el Código

Properly DI the lag display plugin.

Change-Id: I69911922402bc2e4172ab1aa76603922340abbc6
Reviewed-on: http://gerrit.dmdirc.com/3135
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8
Chris Smith hace 10 años
padre
commit
502844a369

+ 285
- 0
src/com/dmdirc/addons/lagdisplay/LagDisplayManager.java Ver fichero

@@ -0,0 +1,285 @@
1
+/*
2
+ * Copyright (c) 2006-2014 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.lagdisplay;
24
+
25
+import com.dmdirc.ClientModule.GlobalConfig;
26
+import com.dmdirc.FrameContainer;
27
+import com.dmdirc.ServerState;
28
+import com.dmdirc.actions.ActionManager;
29
+import com.dmdirc.actions.CoreActionType;
30
+import com.dmdirc.addons.lagdisplay.LagDisplayModule.LagDisplaySettingsDomain;
31
+import com.dmdirc.addons.ui_swing.MainFrame;
32
+import com.dmdirc.addons.ui_swing.SelectionListener;
33
+import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
34
+import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
35
+import com.dmdirc.interfaces.ActionListener;
36
+import com.dmdirc.interfaces.Connection;
37
+import com.dmdirc.interfaces.actions.ActionType;
38
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
39
+import com.dmdirc.interfaces.config.ConfigChangeListener;
40
+import com.dmdirc.util.collections.RollingList;
41
+
42
+import java.util.Date;
43
+import java.util.HashMap;
44
+import java.util.Map;
45
+import java.util.WeakHashMap;
46
+
47
+import javax.inject.Inject;
48
+import javax.inject.Provider;
49
+import javax.inject.Singleton;
50
+
51
+/**
52
+ * Manages the lifecycle of the lag display plugin.
53
+ */
54
+@Singleton
55
+public class LagDisplayManager implements ActionListener, ConfigChangeListener, SelectionListener {
56
+
57
+    /** Frame to listen to selection events on. */
58
+    // TODO: Selection/focus management should be behind an interface
59
+    private final MainFrame mainFrame;
60
+    /** Status bar to add panels to. */
61
+    private final SwingStatusBar statusBar;
62
+    private final Provider<LagDisplayPanel> panelProvider;
63
+    /** The settings domain to use. */
64
+    private final String domain;
65
+    /** Config to read global settings from. */
66
+    private final AggregateConfigProvider globalConfig;
67
+    /** A cache of ping times. */
68
+    private final Map<Connection, String> pings = new WeakHashMap<>();
69
+    /** Ping history. */
70
+    private final Map<Connection, RollingList<Long>> history = new HashMap<>();
71
+    /** Whether or not to show a graph in the info popup. */
72
+    private boolean showGraph = true;
73
+    /** Whether or not to show labels on that graph. */
74
+    private boolean showLabels = true;
75
+    /** The length of history to keep per-server. */
76
+    private int historySize = 100;
77
+    /** The panel currently in use. Null before {@link #load()} or after {@link #unload()}. */
78
+    private LagDisplayPanel panel;
79
+
80
+    @Inject
81
+    public LagDisplayManager(
82
+            final MainFrame mainFrame,
83
+            final SwingStatusBar statusBar,
84
+            final Provider<LagDisplayPanel> panelProvider,
85
+            @LagDisplaySettingsDomain final String domain,
86
+            @GlobalConfig final AggregateConfigProvider globalConfig) {
87
+        this.mainFrame = mainFrame;
88
+        this.statusBar = statusBar;
89
+        this.panelProvider = panelProvider;
90
+        this.domain = domain;
91
+        this.globalConfig = globalConfig;
92
+    }
93
+
94
+    public void load() {
95
+        statusBar.addComponent(panel);
96
+        mainFrame.addSelectionListener(this);
97
+
98
+        globalConfig.addChangeListener(domain, this);
99
+        readConfig();
100
+        ActionManager.getActionManager().registerListener(this,
101
+                CoreActionType.SERVER_GOTPING, CoreActionType.SERVER_NOPING,
102
+                CoreActionType.SERVER_DISCONNECTED,
103
+                CoreActionType.SERVER_PINGSENT, CoreActionType.SERVER_NUMERIC);
104
+
105
+        panel = panelProvider.get();
106
+    }
107
+
108
+    public void unload() {
109
+        mainFrame.removeSelectionListener(this);
110
+        statusBar.removeComponent(panel);
111
+        globalConfig.removeListener(this);
112
+        ActionManager.getActionManager().unregisterListener(this);
113
+
114
+        panel = null;
115
+    }
116
+
117
+    /** Reads the plugin's global configuration settings. */
118
+    private void readConfig() {
119
+        showGraph = globalConfig.getOptionBool(domain, "graph");
120
+        showLabels = globalConfig.getOptionBool(domain, "labels");
121
+        historySize = globalConfig.getOptionInt(domain, "history");
122
+    }
123
+
124
+    /**
125
+     * Retrieves the history of the specified server. If there is no history, a new list is added to
126
+     * the history map and returned.
127
+     *
128
+     * @param connection The connection whose history is being requested
129
+     *
130
+     * @return The history for the specified server
131
+     */
132
+    protected RollingList<Long> getHistory(final Connection connection) {
133
+        if (!history.containsKey(connection)) {
134
+            history.put(connection, new RollingList<Long>(historySize));
135
+        }
136
+        return history.get(connection);
137
+    }
138
+
139
+    /**
140
+     * Determines if the {@link ServerInfoDialog} should show a graph of the ping time for the
141
+     * current server.
142
+     *
143
+     * @return True if a graph should be shown, false otherwise
144
+     */
145
+    public boolean shouldShowGraph() {
146
+        return showGraph;
147
+    }
148
+
149
+    /**
150
+     * Determines if the {@link PingHistoryPanel} should show labels on selected points.
151
+     *
152
+     * @return True if labels should be shown, false otherwise
153
+     */
154
+    public boolean shouldShowLabels() {
155
+        return showLabels;
156
+    }
157
+
158
+    /** {@inheritDoc} */
159
+    @Override
160
+    public void selectionChanged(final TextFrame window) {
161
+        final FrameContainer source = window.getContainer();
162
+        if (source == null || source.getConnection() == null) {
163
+            panel.getComponent().setText("Unknown");
164
+        } else if (source.getConnection().getState() != ServerState.CONNECTED) {
165
+            panel.getComponent().setText("Not connected");
166
+        } else {
167
+            panel.getComponent().setText(getTime(source.getConnection()));
168
+        }
169
+        panel.refreshDialog();
170
+    }
171
+
172
+    /** {@inheritDoc} */
173
+    @Override
174
+    public void processEvent(final ActionType type, final StringBuffer format,
175
+            final Object... arguments) {
176
+        boolean useAlternate = false;
177
+
178
+        for (Object obj : arguments) {
179
+            if (obj instanceof FrameContainer
180
+                    && ((FrameContainer) obj).getConfigManager() != null) {
181
+                useAlternate = ((FrameContainer) obj).getConfigManager()
182
+                        .getOptionBool(domain, "usealternate");
183
+                break;
184
+            }
185
+        }
186
+
187
+        final TextFrame activeFrame = mainFrame.getActiveFrame();
188
+        final FrameContainer active = activeFrame == null ? null
189
+                : activeFrame.getContainer();
190
+        final boolean isActive = active != null
191
+                && arguments[0] instanceof Connection
192
+                && ((Connection) arguments[0]).equals(active.getConnection());
193
+
194
+        if (!useAlternate && type.equals(CoreActionType.SERVER_GOTPING)) {
195
+            final String value = formatTime(arguments[1]);
196
+
197
+            getHistory(((Connection) arguments[0])).add((Long) arguments[1]);
198
+            pings.put(((Connection) arguments[0]), value);
199
+
200
+            if (isActive) {
201
+                panel.getComponent().setText(value);
202
+            }
203
+
204
+            panel.refreshDialog();
205
+        } else if (!useAlternate && type.equals(CoreActionType.SERVER_NOPING)) {
206
+            final String value = formatTime(arguments[1]) + "+";
207
+
208
+            pings.put(((Connection) arguments[0]), value);
209
+
210
+            if (isActive) {
211
+                panel.getComponent().setText(value);
212
+            }
213
+
214
+            panel.refreshDialog();
215
+        } else if (type.equals(CoreActionType.SERVER_DISCONNECTED)) {
216
+            if (isActive) {
217
+                panel.getComponent().setText("Not connected");
218
+                pings.remove(arguments[0]);
219
+            }
220
+
221
+            panel.refreshDialog();
222
+        } else if (useAlternate && type.equals(CoreActionType.SERVER_PINGSENT)) {
223
+            ((Connection) arguments[0]).getParser().sendRawMessage("LAGCHECK_" + new Date().
224
+                    getTime());
225
+        } else if (useAlternate && type.equals(CoreActionType.SERVER_NUMERIC)
226
+                && ((Integer) arguments[1]) == 421
227
+                && ((String[]) arguments[2])[3].startsWith("LAGCHECK_")) {
228
+            try {
229
+                final long sent = Long.parseLong(((String[]) arguments[2])[3].substring(9));
230
+                final Long duration = new Date().getTime() - sent;
231
+                final String value = formatTime(duration);
232
+
233
+                pings.put((Connection) arguments[0], value);
234
+                getHistory(((Connection) arguments[0])).add(duration);
235
+
236
+                if (isActive) {
237
+                    panel.getComponent().setText(value);
238
+                }
239
+            } catch (NumberFormatException ex) {
240
+                pings.remove(arguments[0]);
241
+            }
242
+
243
+            if (format != null) {
244
+                format.delete(0, format.length());
245
+            }
246
+
247
+            panel.refreshDialog();
248
+        }
249
+    }
250
+
251
+    /**
252
+     * Retrieves the ping time for the specified connection.
253
+     *
254
+     * @param connection The connection whose ping time is being requested
255
+     *
256
+     * @return A String representation of the current lag, or "Unknown"
257
+     */
258
+    public String getTime(final Connection connection) {
259
+        return pings.get(connection) == null ? "Unknown" : pings.get(connection);
260
+    }
261
+
262
+    /**
263
+     * Formats the specified time so it's a nice size to display in the label.
264
+     *
265
+     * @param object An uncast Long representing the time to be formatted
266
+     *
267
+     * @return Formatted time string
268
+     */
269
+    protected String formatTime(final Object object) {
270
+        final Long time = (Long) object;
271
+
272
+        if (time >= 10000) {
273
+            return Math.round(time / 1000.0) + "s";
274
+        } else {
275
+            return time + "ms";
276
+        }
277
+    }
278
+
279
+    /** {@inheritDoc} */
280
+    @Override
281
+    public void configChanged(final String domain, final String key) {
282
+        readConfig();
283
+    }
284
+
285
+}

+ 14
- 6
src/com/dmdirc/addons/lagdisplay/LagDisplayModule.java Ver fichero

@@ -24,24 +24,32 @@ package com.dmdirc.addons.lagdisplay;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.injection.SwingModule;
26 26
 
27
+import javax.inject.Qualifier;
28
+
27 29
 import dagger.Module;
28 30
 import dagger.Provides;
29 31
 
30 32
 /**
31 33
  * DI module for the lag display plugin.
32 34
  */
33
-@Module(injects = {LagDisplayPanel.class}, addsTo = SwingModule.class)
35
+@Module(injects = {LagDisplayManager.class}, addsTo = SwingModule.class)
34 36
 public class LagDisplayModule {
35 37
 
36
-    private final LagDisplayPlugin plugin;
38
+    /** The domain for plugin settings. */
39
+    private final String domain;
40
+
41
+    @Qualifier
42
+    public static @interface LagDisplaySettingsDomain {
43
+    }
37 44
 
38
-    public LagDisplayModule(final LagDisplayPlugin plugin) {
39
-        this.plugin = plugin;
45
+    public LagDisplayModule(final String domain) {
46
+        this.domain = domain;
40 47
     }
41 48
 
42 49
     @Provides
43
-    public LagDisplayPlugin getPlugin() {
44
-        return plugin;
50
+    @LagDisplaySettingsDomain
51
+    public String getDomain() {
52
+        return domain;
45 53
     }
46 54
 
47 55
 }

+ 12
- 228
src/com/dmdirc/addons/lagdisplay/LagDisplayPlugin.java Ver fichero

@@ -22,263 +22,53 @@
22 22
 
23 23
 package com.dmdirc.addons.lagdisplay;
24 24
 
25
-import com.dmdirc.FrameContainer;
26
-import com.dmdirc.ServerState;
27
-import com.dmdirc.actions.ActionManager;
28
-import com.dmdirc.actions.CoreActionType;
29
-import com.dmdirc.addons.ui_swing.SelectionListener;
30
-import com.dmdirc.addons.ui_swing.SwingController;
31
-import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
32 25
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
33 26
 import com.dmdirc.config.prefs.PreferencesCategory;
34 27
 import com.dmdirc.config.prefs.PreferencesDialogModel;
35 28
 import com.dmdirc.config.prefs.PreferencesSetting;
36 29
 import com.dmdirc.config.prefs.PreferencesType;
37
-import com.dmdirc.interfaces.ActionListener;
38
-import com.dmdirc.interfaces.Connection;
39
-import com.dmdirc.interfaces.actions.ActionType;
40
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
41
-import com.dmdirc.interfaces.config.ConfigChangeListener;
42 30
 import com.dmdirc.plugins.PluginInfo;
43 31
 import com.dmdirc.plugins.implementations.BasePlugin;
44
-import com.dmdirc.util.collections.RollingList;
45
-
46
-import java.util.Date;
47
-import java.util.HashMap;
48
-import java.util.Map;
49
-import java.util.WeakHashMap;
50 32
 
51 33
 import dagger.ObjectGraph;
52 34
 
53 35
 /**
54 36
  * Displays the current server's lag in the status bar.
55 37
  */
56
-public final class LagDisplayPlugin extends BasePlugin implements
57
-        ActionListener, ConfigChangeListener, SelectionListener {
38
+public final class LagDisplayPlugin extends BasePlugin {
58 39
 
59
-    /** The panel we use in the status bar. */
60
-    private LagDisplayPanel panel;
61
-    /** A cache of ping times. */
62
-    private final Map<Connection, String> pings = new WeakHashMap<>();
63
-    /** Ping history. */
64
-    private final Map<Connection, RollingList<Long>> history = new HashMap<>();
65
-    /** Parent Swing UI. */
66
-    private final SwingController controller;
67
-    /** Whether or not to show a graph in the info popup. */
68
-    private boolean showGraph = true;
69
-    /** Whether or not to show labels on that graph. */
70
-    private boolean showLabels = true;
71
-    /** The length of history to keep per-server. */
72
-    private int historySize = 100;
73 40
     /** This plugin's plugin info. */
74 41
     private final PluginInfo pluginInfo;
75
-    /** Global config. */
76
-    private AggregateConfigProvider config;
42
+    /** The manager currently in use. */
43
+    private LagDisplayManager manager;
77 44
 
78 45
     /**
79 46
      * Creates a new LagDisplayPlugin.
80 47
      *
81
-     * @param controller The controller to add components to
82 48
      * @param pluginInfo This plugin's plugin info
83 49
      */
84
-    public LagDisplayPlugin(final SwingController controller,
85
-            final PluginInfo pluginInfo) {
86
-        super();
87
-        this.controller = controller;
50
+    public LagDisplayPlugin(final PluginInfo pluginInfo) {
88 51
         this.pluginInfo = pluginInfo;
89
-        config = controller.getGlobalConfig();
90 52
     }
91 53
 
92 54
     @Override
93 55
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
94 56
         super.load(pluginInfo, graph);
95 57
 
96
-        setObjectGraph(graph.plus(new LagDisplayModule(this)));
97
-        panel = getObjectGraph().get(LagDisplayPanel.class);
58
+        setObjectGraph(graph.plus(new LagDisplayModule(pluginInfo.getDomain())));
59
+        manager = getObjectGraph().get(LagDisplayManager.class);
98 60
     }
99 61
 
100 62
     /** {@inheritDoc} */
101 63
     @Override
102 64
     public void onLoad() {
103
-        controller.getSwingStatusBar().addComponent(panel);
104
-        controller.getMainFrame().addSelectionListener(this);
105
-        config.addChangeListener(getDomain(), this);
106
-        readConfig();
107
-        ActionManager.getActionManager().registerListener(this,
108
-                CoreActionType.SERVER_GOTPING, CoreActionType.SERVER_NOPING,
109
-                CoreActionType.SERVER_DISCONNECTED,
110
-                CoreActionType.SERVER_PINGSENT, CoreActionType.SERVER_NUMERIC);
65
+        manager.load();
111 66
     }
112 67
 
113 68
     /** {@inheritDoc} */
114 69
     @Override
115 70
     public void onUnload() {
116
-        controller.getMainFrame().removeSelectionListener(this);
117
-        controller.getSwingStatusBar().removeComponent(panel);
118
-        config.removeListener(this);
119
-        ActionManager.getActionManager().unregisterListener(this);
120
-    }
121
-
122
-    /** Reads the plugin's global configuration settings. */
123
-    private void readConfig() {
124
-        showGraph = config.getOptionBool(getDomain(), "graph");
125
-        showLabels = config.getOptionBool(getDomain(), "labels");
126
-        historySize = config.getOptionInt(getDomain(), "history");
127
-    }
128
-
129
-    /**
130
-     * Retrieves the history of the specified server. If there is no history, a new list is added to
131
-     * the history map and returned.
132
-     *
133
-     * @param connection The connection whose history is being requested
134
-     *
135
-     * @return The history for the specified server
136
-     */
137
-    protected RollingList<Long> getHistory(final Connection connection) {
138
-        if (!history.containsKey(connection)) {
139
-            history.put(connection, new RollingList<Long>(historySize));
140
-        }
141
-        return history.get(connection);
142
-    }
143
-
144
-    /**
145
-     * Determines if the {@link ServerInfoDialog} should show a graph of the ping time for the
146
-     * current server.
147
-     *
148
-     * @return True if a graph should be shown, false otherwise
149
-     */
150
-    public boolean shouldShowGraph() {
151
-        return showGraph;
152
-    }
153
-
154
-    /**
155
-     * Determines if the {@link PingHistoryPanel} should show labels on selected points.
156
-     *
157
-     * @return True if labels should be shown, false otherwise
158
-     */
159
-    public boolean shouldShowLabels() {
160
-        return showLabels;
161
-    }
162
-
163
-    /** {@inheritDoc} */
164
-    @Override
165
-    public void selectionChanged(final TextFrame window) {
166
-        final FrameContainer source = window.getContainer();
167
-        if (source == null || source.getConnection() == null) {
168
-            panel.getComponent().setText("Unknown");
169
-        } else if (source.getConnection().getState() != ServerState.CONNECTED) {
170
-            panel.getComponent().setText("Not connected");
171
-        } else {
172
-            panel.getComponent().setText(getTime(source.getConnection()));
173
-        }
174
-        panel.refreshDialog();
175
-    }
176
-
177
-    /** {@inheritDoc} */
178
-    @Override
179
-    public void processEvent(final ActionType type, final StringBuffer format,
180
-            final Object... arguments) {
181
-        boolean useAlternate = false;
182
-
183
-        for (Object obj : arguments) {
184
-            if (obj instanceof FrameContainer
185
-                    && ((FrameContainer) obj).getConfigManager() != null) {
186
-                useAlternate = ((FrameContainer) obj).getConfigManager()
187
-                        .getOptionBool(getDomain(), "usealternate");
188
-                break;
189
-            }
190
-        }
191
-
192
-        final TextFrame activeFrame = controller.getMainFrame().getActiveFrame();
193
-        final FrameContainer active = activeFrame == null ? null
194
-                : activeFrame.getContainer();
195
-        final boolean isActive = active != null
196
-                && arguments[0] instanceof Connection
197
-                && ((Connection) arguments[0]).equals(active.getConnection());
198
-
199
-        if (!useAlternate && type.equals(CoreActionType.SERVER_GOTPING)) {
200
-            final String value = formatTime(arguments[1]);
201
-
202
-            getHistory(((Connection) arguments[0])).add((Long) arguments[1]);
203
-            pings.put(((Connection) arguments[0]), value);
204
-
205
-            if (isActive) {
206
-                panel.getComponent().setText(value);
207
-            }
208
-
209
-            panel.refreshDialog();
210
-        } else if (!useAlternate && type.equals(CoreActionType.SERVER_NOPING)) {
211
-            final String value = formatTime(arguments[1]) + "+";
212
-
213
-            pings.put(((Connection) arguments[0]), value);
214
-
215
-            if (isActive) {
216
-                panel.getComponent().setText(value);
217
-            }
218
-
219
-            panel.refreshDialog();
220
-        } else if (type.equals(CoreActionType.SERVER_DISCONNECTED)) {
221
-            if (isActive) {
222
-                panel.getComponent().setText("Not connected");
223
-                pings.remove(arguments[0]);
224
-            }
225
-
226
-            panel.refreshDialog();
227
-        } else if (useAlternate && type.equals(CoreActionType.SERVER_PINGSENT)) {
228
-            ((Connection) arguments[0]).getParser().sendRawMessage("LAGCHECK_" + new Date().
229
-                    getTime());
230
-        } else if (useAlternate && type.equals(CoreActionType.SERVER_NUMERIC)
231
-                && ((Integer) arguments[1]) == 421
232
-                && ((String[]) arguments[2])[3].startsWith("LAGCHECK_")) {
233
-            try {
234
-                final long sent = Long.parseLong(((String[]) arguments[2])[3].substring(9));
235
-                final Long duration = new Date().getTime() - sent;
236
-                final String value = formatTime(duration);
237
-
238
-                pings.put((Connection) arguments[0], value);
239
-                getHistory(((Connection) arguments[0])).add(duration);
240
-
241
-                if (isActive) {
242
-                    panel.getComponent().setText(value);
243
-                }
244
-            } catch (NumberFormatException ex) {
245
-                pings.remove(arguments[0]);
246
-            }
247
-
248
-            if (format != null) {
249
-                format.delete(0, format.length());
250
-            }
251
-
252
-            panel.refreshDialog();
253
-        }
254
-    }
255
-
256
-    /**
257
-     * Retrieves the ping time for the specified connection.
258
-     *
259
-     * @param connection The connection whose ping time is being requested
260
-     *
261
-     * @return A String representation of the current lag, or "Unknown"
262
-     */
263
-    public String getTime(final Connection connection) {
264
-        return pings.get(connection) == null ? "Unknown" : pings.get(connection);
265
-    }
266
-
267
-    /**
268
-     * Formats the specified time so it's a nice size to display in the label.
269
-     *
270
-     * @param object An uncast Long representing the time to be formatted
271
-     *
272
-     * @return Formatted time string
273
-     */
274
-    protected String formatTime(final Object object) {
275
-        final Long time = (Long) object;
276
-
277
-        if (time >= 10000) {
278
-            return Math.round(time / 1000.0) + "s";
279
-        } else {
280
-            return time + "ms";
281
-        }
71
+        manager.unload();
282 72
     }
283 73
 
284 74
     /** {@inheritDoc} */
@@ -287,29 +77,23 @@ public final class LagDisplayPlugin extends BasePlugin implements
287 77
         final PreferencesCategory cat = new PluginPreferencesCategory(
288 78
                 pluginInfo, "Lag display plugin", "");
289 79
         cat.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
290
-                getDomain(), "usealternate",
80
+                pluginInfo.getDomain(), "usealternate",
291 81
                 "Alternate method", "Use an alternate method of determining "
292 82
                 + "lag which bypasses bouncers or proxies that may reply?",
293 83
                 manager.getConfigManager(), manager.getIdentity()));
294 84
         cat.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
295
-                getDomain(), "graph", "Show graph", "Show a graph of ping times "
85
+                pluginInfo.getDomain(), "graph", "Show graph", "Show a graph of ping times "
296 86
                 + "for the current server in the information popup?",
297 87
                 manager.getConfigManager(), manager.getIdentity()));
298 88
         cat.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
299
-                getDomain(), "labels", "Show labels", "Show labels on selected "
89
+                pluginInfo.getDomain(), "labels", "Show labels", "Show labels on selected "
300 90
                 + "points on the ping graph?",
301 91
                 manager.getConfigManager(), manager.getIdentity()));
302 92
         cat.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
303
-                getDomain(), "history", "Graph points", "Number of data points "
93
+                pluginInfo.getDomain(), "history", "Graph points", "Number of data points "
304 94
                 + "to plot on the graph, if enabled.",
305 95
                 manager.getConfigManager(), manager.getIdentity()));
306 96
         manager.getCategory("Plugins").addSubCategory(cat);
307 97
     }
308 98
 
309
-    /** {@inheritDoc} */
310
-    @Override
311
-    public void configChanged(final String domain, final String key) {
312
-        readConfig();
313
-    }
314
-
315 99
 }

+ 9
- 10
src/com/dmdirc/addons/lagdisplay/PingHistoryPanel.java Ver fichero

@@ -47,20 +47,20 @@ public class PingHistoryPanel extends JPanel {
47 47
      * class).
48 48
      */
49 49
     private static final long serialVersionUID = 1;
50
-    /** The plugin that this panel is for. */
51
-    protected final LagDisplayPlugin plugin;
50
+    /** The manager that this panel is for. */
51
+    protected final LagDisplayManager manager;
52 52
     /** The history that we're graphing. */
53 53
     protected final RollingList<Long> history;
54 54
     /** The maximum ping value. */
55
-    protected long maximum = 0L;
55
+    protected long maximum;
56 56
 
57 57
     /**
58 58
      * Creates a new history panel for the specified plugin.
59 59
      *
60
-     * @param plugin    The plugin that owns this panel
60
+     * @param manager   The manager that owns this panel
61 61
      * @param mainFrame Swing main frame
62 62
      */
63
-    public PingHistoryPanel(final LagDisplayPlugin plugin,
63
+    public PingHistoryPanel(final LagDisplayManager manager,
64 64
             final MainFrame mainFrame) {
65 65
         super();
66 66
 
@@ -68,9 +68,8 @@ public class PingHistoryPanel extends JPanel {
68 68
         setMaximumSize(new Dimension(Integer.MAX_VALUE, 100));
69 69
         setOpaque(false);
70 70
 
71
-        this.plugin = plugin;
72
-        history = plugin.getHistory(mainFrame.getActiveFrame().getContainer()
73
-                .getConnection());
71
+        this.manager = manager;
72
+        history = manager.getHistory(mainFrame.getActiveFrame().getContainer().getConnection());
74 73
 
75 74
         for (Long value : history.getList()) {
76 75
             maximum = Math.max(value, maximum);
@@ -115,8 +114,8 @@ public class PingHistoryPanel extends JPanel {
115 114
 
116 115
             g.drawRect((int) x - 1, (int) y - 1, 2, 2);
117 116
 
118
-            if (plugin.shouldShowLabels() && last1 > -1 && (last2 <= last1 || last1 >= value)) {
119
-                final String text = plugin.formatTime(last1);
117
+            if (manager.shouldShowLabels() && last1 > -1 && (last2 <= last1 || last1 >= value)) {
118
+                final String text = manager.formatTime(last1);
120 119
                 final Rectangle2D rect = g.getFont().getStringBounds(text,
121 120
                         ((Graphics2D) g).getFontRenderContext());
122 121
                 final int width = 10 + (int) rect.getWidth();

+ 8
- 8
src/com/dmdirc/addons/lagdisplay/ServerInfoDialog.java Ver fichero

@@ -49,8 +49,8 @@ public class ServerInfoDialog extends StatusbarPopupWindow {
49 49
      * class).
50 50
      */
51 51
     private static final long serialVersionUID = 3;
52
-    /** The lag display plugin. */
53
-    protected final LagDisplayPlugin plugin;
52
+    /** The lag display manager. */
53
+    protected final LagDisplayManager manager;
54 54
     /** Swing main frame. */
55 55
     private final MainFrame mainFrame;
56 56
     /** Server manager to retrieve servers from. */
@@ -59,19 +59,19 @@ public class ServerInfoDialog extends StatusbarPopupWindow {
59 59
     /**
60 60
      * Creates a new ServerInfoDialog.
61 61
      *
62
-     * @param plugin        The {@link LagDisplayPlugin} we're using for info
62
+     * @param manager       The {@link LagDisplayManager} we're using for info
63 63
      * @param parent        The {@link JPanel} to use for positioning
64 64
      * @param mainFrame     The frame that will own this dialog.
65 65
      * @param serverManager The manager to use to iterate servers.
66 66
      */
67 67
     public ServerInfoDialog(
68
-            final LagDisplayPlugin plugin,
68
+            final LagDisplayManager manager,
69 69
             @Unbound final StatusbarPanel parent,
70 70
             final MainFrame mainFrame,
71 71
             final ServerManager serverManager) {
72 72
         super(parent, mainFrame);
73 73
 
74
-        this.plugin = plugin;
74
+        this.manager = manager;
75 75
         this.mainFrame = mainFrame;
76 76
         this.serverManager = serverManager;
77 77
     }
@@ -84,8 +84,8 @@ public class ServerInfoDialog extends StatusbarPopupWindow {
84 84
         if (servers.isEmpty()) {
85 85
             panel.add(new JLabel("No open servers."));
86 86
         } else {
87
-            if (plugin.shouldShowGraph()) {
88
-                panel.add(new PingHistoryPanel(plugin, mainFrame), "span, grow, wrap");
87
+            if (manager.shouldShowGraph()) {
88
+                panel.add(new PingHistoryPanel(manager, mainFrame), "span, grow, wrap");
89 89
                 panel.add(new JSeparator(), "span, grow, wrap");
90 90
             }
91 91
 
@@ -94,7 +94,7 @@ public class ServerInfoDialog extends StatusbarPopupWindow {
94 94
                 panel.add(new JLabel(server.getState() == ServerState.CONNECTED
95 95
                         ? server.getNetwork() : "---", JLabel.CENTER), "grow");
96 96
                 panel.add(new JLabel(server.getState() == ServerState.CONNECTED
97
-                        ? plugin.getTime(server) : "---", JLabel.RIGHT), "grow, wrap");
97
+                        ? manager.getTime(server) : "---", JLabel.RIGHT), "grow, wrap");
98 98
             }
99 99
         }
100 100
     }

+ 0
- 13
src/com/dmdirc/addons/ui_swing/SwingController.java Ver fichero

@@ -31,7 +31,6 @@ import com.dmdirc.addons.ui_swing.commands.PopInCommand;
31 31
 import com.dmdirc.addons.ui_swing.commands.PopOutCommand;
32 32
 import com.dmdirc.addons.ui_swing.commands.ServerSettings;
33 33
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
34
-import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
35 34
 import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
36 35
 import com.dmdirc.addons.ui_swing.injection.SwingModule;
37 36
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
@@ -742,16 +741,4 @@ public class SwingController extends BaseCommandPlugin implements UIController {
742 741
         return swingManager.getMainFrame();
743 742
     }
744 743
 
745
-    /**
746
-     * Retrieves the status bar that's in use.
747
-     *
748
-     * @return The status bar that's in use.
749
-     *
750
-     * @deprecated Should be injected where needed.
751
-     */
752
-    @Deprecated
753
-    public SwingStatusBar getSwingStatusBar() {
754
-        return swingManager.getMainFrame().getStatusBar();
755
-    }
756
-
757 744
 }

Loading…
Cancelar
Guardar