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 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.debug;
  18. import com.dmdirc.FrameContainer;
  19. import com.dmdirc.events.ServerConnectingEvent;
  20. import com.dmdirc.interfaces.Connection;
  21. import com.dmdirc.parser.events.DataInEvent;
  22. import com.dmdirc.parser.events.DataOutEvent;
  23. import com.dmdirc.parser.interfaces.Parser;
  24. import com.dmdirc.ui.core.components.WindowComponent;
  25. import com.dmdirc.ui.messages.BackBufferFactory;
  26. import java.util.Arrays;
  27. import java.util.Optional;
  28. import net.engio.mbassy.listener.Handler;
  29. /**
  30. * Shows the raw lines to and from a connection.
  31. */
  32. public class RawWindow extends FrameContainer {
  33. private final Connection connection;
  34. public RawWindow(final Connection connection, final BackBufferFactory backBufferFactory) {
  35. super("raw", "Raw", "(Raw log)",
  36. connection.getWindowModel().getConfigManager(),
  37. backBufferFactory,
  38. connection.getWindowModel().getEventBus(),
  39. Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
  40. WindowComponent.INPUTFIELD.getIdentifier()));
  41. this.connection = connection;
  42. initBackBuffer();
  43. connection.getWindowModel().getEventBus().subscribe(this);
  44. connection.getParser().map(Parser::getCallbackManager).ifPresent(c -> c.subscribe(this));
  45. }
  46. @Override
  47. public Optional<Connection> getConnection() {
  48. return Optional.of(connection);
  49. }
  50. @Override
  51. public void close() {
  52. connection.getParser().map(Parser::getCallbackManager).ifPresent(c -> c.unsubscribe(this));
  53. connection.getWindowModel().getEventBus().unsubscribe(this);
  54. super.close();
  55. }
  56. @Handler
  57. public void handleServerConnecting(final ServerConnectingEvent connectingEvent) {
  58. if (connectingEvent.getConnection().equals(connection)) {
  59. connection.getParser()
  60. .map(Parser::getCallbackManager)
  61. .ifPresent(c -> c.subscribe(this));
  62. }
  63. }
  64. @Handler
  65. private void handleDataIn(final DataInEvent event) {
  66. getEventBus().publishAsync(new RawDataInEvent(this, event.getData()));
  67. }
  68. @Handler
  69. private void handleDataOut(final DataOutEvent event) {
  70. getEventBus().publishAsync(new RawDataOutEvent(this, event.getData()));
  71. }
  72. }