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.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.DMDircMBassador;
  24. import com.dmdirc.FrameContainer;
  25. import com.dmdirc.interfaces.Connection;
  26. import com.dmdirc.parser.interfaces.Parser;
  27. import com.dmdirc.parser.interfaces.callbacks.DebugInfoListener;
  28. import com.dmdirc.ui.core.components.WindowComponent;
  29. import com.dmdirc.ui.messages.BackBufferFactory;
  30. import java.util.Arrays;
  31. import java.util.Date;
  32. import java.util.Optional;
  33. /**
  34. * This class is used to show the parser debug in a window
  35. */
  36. public class DebugWindow extends FrameContainer {
  37. /** The debug listener for this window. */
  38. protected final DebugInfoListener listener;
  39. /** The parser this window is debugging. */
  40. protected Parser parser;
  41. /** The connection we're operating on. */
  42. protected final Connection connection;
  43. /**
  44. * Creates a new instance of DebugWindow.
  45. */
  46. public DebugWindow(
  47. final DebugInfoListener listener,
  48. final String title,
  49. final Parser parser,
  50. final Connection connection,
  51. final DMDircMBassador eventBus,
  52. final BackBufferFactory backBufferFactory) {
  53. super(connection.getWindowModel(), "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. addLine("======================", new Date());
  70. addLine("Unset parser: " + parser, new Date());
  71. parser = null;
  72. }
  73. /**
  74. * Closes this container (and its associated frame).
  75. */
  76. @Override
  77. public void close() {
  78. super.close();
  79. // Remove any callbacks or listeners
  80. if (parser != null) {
  81. parser.getCallbackManager().delCallback(DebugInfoListener.class, listener);
  82. }
  83. }
  84. }