|
@@ -0,0 +1,121 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2015 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.debug;
|
|
24
|
+
|
|
25
|
+import com.dmdirc.FrameContainer;
|
|
26
|
+import com.dmdirc.commandparser.CommandType;
|
|
27
|
+import com.dmdirc.commandparser.parsers.ServerCommandParser;
|
|
28
|
+import com.dmdirc.events.ServerConnectingEvent;
|
|
29
|
+import com.dmdirc.interfaces.CommandController;
|
|
30
|
+import com.dmdirc.interfaces.Connection;
|
|
31
|
+import com.dmdirc.parser.common.CallbackManager;
|
|
32
|
+import com.dmdirc.parser.interfaces.Parser;
|
|
33
|
+import com.dmdirc.parser.interfaces.callbacks.DataInListener;
|
|
34
|
+import com.dmdirc.parser.interfaces.callbacks.DataOutListener;
|
|
35
|
+import com.dmdirc.ui.core.components.WindowComponent;
|
|
36
|
+import com.dmdirc.ui.input.TabCompleterFactory;
|
|
37
|
+import com.dmdirc.ui.messages.BackBufferFactory;
|
|
38
|
+import com.dmdirc.ui.messages.sink.MessageSinkManager;
|
|
39
|
+
|
|
40
|
+import java.util.Arrays;
|
|
41
|
+import java.util.Date;
|
|
42
|
+import java.util.Optional;
|
|
43
|
+
|
|
44
|
+import net.engio.mbassy.listener.Handler;
|
|
45
|
+
|
|
46
|
+/**
|
|
47
|
+ * Shows the raw lines to and from a connection.
|
|
48
|
+ */
|
|
49
|
+public class RawWindow extends FrameContainer {
|
|
50
|
+
|
|
51
|
+ private final Connection connection;
|
|
52
|
+
|
|
53
|
+ public RawWindow(
|
|
54
|
+ final Connection connection,
|
|
55
|
+ final CommandController commandController,
|
|
56
|
+ final MessageSinkManager messageSinkManager,
|
|
57
|
+ final TabCompleterFactory tabCompleterFactory,
|
|
58
|
+ final BackBufferFactory backBufferFactory) {
|
|
59
|
+ super(connection.getWindowModel(), "raw", "Raw", "(Raw log)",
|
|
60
|
+ connection.getWindowModel().getConfigManager(),
|
|
61
|
+ backBufferFactory,
|
|
62
|
+ new ServerCommandParser(
|
|
63
|
+ connection.getWindowModel().getConfigManager(),
|
|
64
|
+ commandController,
|
|
65
|
+ connection.getWindowModel().getEventBus()),
|
|
66
|
+ tabCompleterFactory.getTabCompleter(connection.getWindowModel().getTabCompleter(),
|
|
67
|
+ connection.getWindowModel().getConfigManager(),
|
|
68
|
+ CommandType.TYPE_QUERY, CommandType.TYPE_CHAT),
|
|
69
|
+ messageSinkManager,
|
|
70
|
+ connection.getWindowModel().getEventBus(),
|
|
71
|
+ Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
|
|
72
|
+ WindowComponent.INPUTFIELD.getIdentifier()));
|
|
73
|
+ this.connection = connection;
|
|
74
|
+ initBackBuffer();
|
|
75
|
+
|
|
76
|
+ connection.getWindowModel().getEventBus().subscribe(this);
|
|
77
|
+ connection.getParser().map(Parser::getCallbackManager).ifPresent(this::addCallbacks);
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ @Override
|
|
81
|
+ public Optional<Connection> getConnection() {
|
|
82
|
+ return Optional.of(connection);
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ @Override
|
|
86
|
+ public void close() {
|
|
87
|
+ connection.getParser().map(Parser::getCallbackManager).ifPresent(this::removeCallbacks);
|
|
88
|
+ connection.getWindowModel().getEventBus().unsubscribe(this);
|
|
89
|
+ super.close();
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ @Override
|
|
93
|
+ public int getMaxLineLength() {
|
|
94
|
+ return -1;
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ @Handler
|
|
98
|
+ public void handleServerConnecting(final ServerConnectingEvent connectingEvent) {
|
|
99
|
+ connection.getParser().map(Parser::getCallbackManager).ifPresent(this::addCallbacks);
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ private void addCallbacks(final CallbackManager callbackManager) {
|
|
103
|
+ callbackManager.addCallback(DataInListener.class, this::handleDataIn);
|
|
104
|
+ callbackManager.addCallback(DataOutListener.class, this::handleDataOut);
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+ private void removeCallbacks(final CallbackManager callbackManager) {
|
|
108
|
+ callbackManager.delCallback(DataInListener.class, (DataInListener) this::handleDataIn);
|
|
109
|
+ callbackManager.delCallback(DataOutListener.class, (DataOutListener) this::handleDataOut);
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ private void handleDataIn(final Parser parser, final Date date, final String line) {
|
|
113
|
+ addLine("rawIn", date, line);
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ private void handleDataOut(final Parser parser, final Date date, final String line,
|
|
117
|
+ final boolean fromParser) {
|
|
118
|
+ addLine("rawOut", date, line);
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+}
|