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.

DebugWindow.java 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.parserdebug;
  18. import com.dmdirc.FrameContainer;
  19. import com.dmdirc.events.CommandOutputEvent;
  20. import com.dmdirc.interfaces.Connection;
  21. import com.dmdirc.events.eventbus.EventBus;
  22. import com.dmdirc.parser.interfaces.Parser;
  23. import com.dmdirc.ui.core.components.WindowComponent;
  24. import com.dmdirc.ui.messages.BackBufferFactory;
  25. import java.util.Arrays;
  26. import java.util.Optional;
  27. /**
  28. * This class is used to show the parser debug in a window
  29. */
  30. public class DebugWindow extends FrameContainer {
  31. /** The debug listener for this window. */
  32. protected final Object listener;
  33. /** The parser this window is debugging. */
  34. protected Parser parser;
  35. /** The connection we're operating on. */
  36. protected final Connection connection;
  37. /**
  38. * Creates a new instance of DebugWindow.
  39. */
  40. public DebugWindow(
  41. // TODO: Icky.
  42. final Object listener,
  43. final String title,
  44. final Parser parser,
  45. final Connection connection,
  46. final EventBus eventBus,
  47. final BackBufferFactory backBufferFactory) {
  48. super("raw", "Parser Debug", title,
  49. connection.getWindowModel().getConfigManager(), backBufferFactory,
  50. eventBus, Arrays.asList(WindowComponent.TEXTAREA.getIdentifier()));
  51. this.listener = listener;
  52. this.parser = parser;
  53. this.connection = connection;
  54. initBackBuffer();
  55. }
  56. @Override
  57. public Optional<Connection> getConnection() {
  58. return Optional.of(connection);
  59. }
  60. /**
  61. * Set the parser to null to stop us holding onto parsers when the server connection is closed.
  62. */
  63. public void unsetParser() {
  64. getEventBus().publishAsync(new CommandOutputEvent(this,
  65. "======================\n" +
  66. "Unset parser: " + parser));
  67. parser = null;
  68. }
  69. /**
  70. * Closes this container (and its associated frame).
  71. */
  72. @Override
  73. public void close() {
  74. super.close();
  75. // Remove any callbacks or listeners
  76. if (parser != null) {
  77. parser.getCallbackManager().unsubscribe(listener);
  78. }
  79. }
  80. }