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

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