Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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