|
@@ -26,17 +26,16 @@ import com.dmdirc.ClientModule.GlobalConfig;
|
26
|
26
|
import com.dmdirc.FrameContainer;
|
27
|
27
|
import com.dmdirc.Server;
|
28
|
28
|
import com.dmdirc.ServerState;
|
29
|
|
-import com.dmdirc.actions.ActionManager;
|
30
|
|
-import com.dmdirc.actions.CoreActionType;
|
31
|
29
|
import com.dmdirc.addons.ui_swing.SelectionListener;
|
32
|
30
|
import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
|
33
|
31
|
import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
|
34
|
32
|
import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
|
35
|
33
|
import com.dmdirc.events.ServerDisconnectedEvent;
|
|
34
|
+import com.dmdirc.events.ServerGotpingEvent;
|
|
35
|
+import com.dmdirc.events.ServerNopingEvent;
|
36
|
36
|
import com.dmdirc.events.ServerNumericEvent;
|
37
|
|
-import com.dmdirc.interfaces.ActionListener;
|
|
37
|
+import com.dmdirc.events.ServerPingsentEvent;
|
38
|
38
|
import com.dmdirc.interfaces.Connection;
|
39
|
|
-import com.dmdirc.interfaces.actions.ActionType;
|
40
|
39
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
41
|
40
|
import com.dmdirc.interfaces.config.ConfigChangeListener;
|
42
|
41
|
import com.dmdirc.plugins.PluginDomain;
|
|
@@ -58,7 +57,7 @@ import javax.inject.Singleton;
|
58
|
57
|
* Manages the lifecycle of the lag display plugin.
|
59
|
58
|
*/
|
60
|
59
|
@Singleton
|
61
|
|
-public class LagDisplayManager implements ActionListener, ConfigChangeListener, SelectionListener {
|
|
60
|
+public class LagDisplayManager implements ConfigChangeListener, SelectionListener {
|
62
|
61
|
|
63
|
62
|
/** Event bus to receive events on. */
|
64
|
63
|
private final EventBus eventBus;
|
|
@@ -106,9 +105,6 @@ public class LagDisplayManager implements ActionListener, ConfigChangeListener,
|
106
|
105
|
activeFrameManager.addSelectionListener(this);
|
107
|
106
|
globalConfig.addChangeListener(domain, this);
|
108
|
107
|
readConfig();
|
109
|
|
- ActionManager.getActionManager().registerListener(this,
|
110
|
|
- CoreActionType.SERVER_GOTPING, CoreActionType.SERVER_NOPING,
|
111
|
|
- CoreActionType.SERVER_PINGSENT);
|
112
|
108
|
eventBus.register(this);
|
113
|
109
|
}
|
114
|
110
|
|
|
@@ -116,7 +112,7 @@ public class LagDisplayManager implements ActionListener, ConfigChangeListener,
|
116
|
112
|
statusBar.removeComponent(panel);
|
117
|
113
|
activeFrameManager.removeSelectionListener(this);
|
118
|
114
|
globalConfig.removeListener(this);
|
119
|
|
- ActionManager.getActionManager().unregisterListener(this);
|
|
115
|
+ eventBus.unregister(this);
|
120
|
116
|
panel = null;
|
121
|
117
|
}
|
122
|
118
|
|
|
@@ -219,52 +215,56 @@ public class LagDisplayManager implements ActionListener, ConfigChangeListener,
|
219
|
215
|
panel.refreshDialog();
|
220
|
216
|
}
|
221
|
217
|
|
222
|
|
- @Override
|
223
|
|
- public void processEvent(final ActionType type, final StringBuffer format,
|
224
|
|
- final Object... arguments) {
|
225
|
|
- boolean useAlternate = false;
|
226
|
|
-
|
227
|
|
- for (Object obj : arguments) {
|
228
|
|
- if (obj instanceof FrameContainer
|
229
|
|
- && ((FrameContainer) obj).getConfigManager() != null) {
|
230
|
|
- useAlternate = ((FrameContainer) obj).getConfigManager()
|
231
|
|
- .getOptionBool(domain, "usealternate");
|
232
|
|
- break;
|
233
|
|
- }
|
|
218
|
+ @Subscribe
|
|
219
|
+ public void handleServerGotPing(final ServerGotpingEvent event) {
|
|
220
|
+ if (event.getConnection().getWindowModel().getConfigManager().
|
|
221
|
+ getOptionBool(domain, "usealternate")) {
|
|
222
|
+ return;
|
234
|
223
|
}
|
235
|
|
-
|
236
|
224
|
final TextFrame activeFrame = activeFrameManager.getActiveFrame();
|
237
|
|
- final FrameContainer active = activeFrame == null ? null
|
238
|
|
- : activeFrame.getContainer();
|
239
|
|
- final boolean isActive = active != null
|
240
|
|
- && arguments[0] instanceof Connection
|
241
|
|
- && ((Connection) arguments[0]).equals(active.getConnection());
|
|
225
|
+ final FrameContainer active = activeFrame == null ? null : activeFrame.getContainer();
|
|
226
|
+ final boolean isActive = active != null && event.getConnection().equals(active.
|
|
227
|
+ getConnection());
|
|
228
|
+ final String value = formatTime(event.getPing());
|
242
|
229
|
|
243
|
|
- if (!useAlternate && type.equals(CoreActionType.SERVER_GOTPING)) {
|
244
|
|
- final String value = formatTime(arguments[1]);
|
|
230
|
+ getHistory(event.getConnection()).add(event.getPing());
|
|
231
|
+ pings.put((event.getConnection()), value);
|
245
|
232
|
|
246
|
|
- getHistory(((Connection) arguments[0])).add((Long) arguments[1]);
|
247
|
|
- pings.put(((Connection) arguments[0]), value);
|
|
233
|
+ if (isActive) {
|
|
234
|
+ panel.getComponent().setText(value);
|
|
235
|
+ }
|
248
|
236
|
|
249
|
|
- if (isActive) {
|
250
|
|
- panel.getComponent().setText(value);
|
251
|
|
- }
|
|
237
|
+ panel.refreshDialog();
|
|
238
|
+ }
|
252
|
239
|
|
253
|
|
- panel.refreshDialog();
|
254
|
|
- } else if (!useAlternate && type.equals(CoreActionType.SERVER_NOPING)) {
|
255
|
|
- final String value = formatTime(arguments[1]) + "+";
|
|
240
|
+ @Subscribe
|
|
241
|
+ public void handleServerNoPing(final ServerNopingEvent event) {
|
|
242
|
+ if (event.getConnection().getWindowModel().getConfigManager().
|
|
243
|
+ getOptionBool(domain, "usealternate")) {
|
|
244
|
+ return;
|
|
245
|
+ }
|
|
246
|
+ final TextFrame activeFrame = activeFrameManager.getActiveFrame();
|
|
247
|
+ final FrameContainer active = activeFrame == null ? null : activeFrame.getContainer();
|
|
248
|
+ final boolean isActive = active != null && event.getConnection().equals(active.
|
|
249
|
+ getConnection());
|
|
250
|
+ final String value = formatTime(event.getPing()) + "+";
|
256
|
251
|
|
257
|
|
- pings.put(((Connection) arguments[0]), value);
|
|
252
|
+ pings.put(event.getConnection(), value);
|
258
|
253
|
|
259
|
|
- if (isActive) {
|
260
|
|
- panel.getComponent().setText(value);
|
261
|
|
- }
|
|
254
|
+ if (isActive) {
|
|
255
|
+ panel.getComponent().setText(value);
|
|
256
|
+ }
|
262
|
257
|
|
263
|
|
- panel.refreshDialog();
|
264
|
|
- } else if (useAlternate && type.equals(CoreActionType.SERVER_PINGSENT)) {
|
265
|
|
- ((Connection) arguments[0]).getParser().sendRawMessage("LAGCHECK_" + new Date().
|
266
|
|
- getTime());
|
|
258
|
+ panel.refreshDialog();
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+ @Subscribe
|
|
262
|
+ public void HandleServerPingSent(final ServerPingsentEvent event) {
|
|
263
|
+ if (!event.getConnection().getWindowModel().getConfigManager().
|
|
264
|
+ getOptionBool(domain, "usealternate")) {
|
|
265
|
+ return;
|
267
|
266
|
}
|
|
267
|
+ event.getConnection().getParser().sendRawMessage("LAGCHECK_" + new Date().getTime());
|
268
|
268
|
}
|
269
|
269
|
|
270
|
270
|
/**
|