You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RawWindow.java 4.5KB

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