Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Raw.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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;
  23. import com.dmdirc.commandparser.parsers.CommandParser;
  24. import com.dmdirc.logger.ErrorLevel;
  25. import com.dmdirc.logger.Logger;
  26. import com.dmdirc.parser.interfaces.Parser;
  27. import com.dmdirc.parser.common.CallbackNotFoundException;
  28. import com.dmdirc.parser.interfaces.callbacks.DataInListener;
  29. import com.dmdirc.parser.interfaces.callbacks.DataOutListener;
  30. import com.dmdirc.ui.WindowManager;
  31. import com.dmdirc.ui.interfaces.InputWindow;
  32. import java.io.Serializable;
  33. /**
  34. * Handles the raw window (which shows the user raw data being sent and
  35. * received to/from the server).
  36. * @author chris
  37. */
  38. public final class Raw extends WritableFrameContainer implements DataInListener,
  39. DataOutListener, Serializable {
  40. /**
  41. * A version number for this class. It should be changed whenever the class
  42. * structure is changed (or anything else that would prevent serialized
  43. * objects being unserialized with the new class).
  44. */
  45. private static final long serialVersionUID = 1;
  46. /** The server object that's being monitored. */
  47. private Server server;
  48. /** An InputWindow used for displaying the raw data.*/
  49. private InputWindow window;
  50. /**
  51. * Creates a new instance of Raw.
  52. *
  53. * @param newServer the server to monitor
  54. * @param commandParser Command parser to use
  55. */
  56. public Raw(final Server newServer, final CommandParser commandParser) {
  57. super("raw", "Raw", newServer.getConfigManager());
  58. this.server = newServer;
  59. window = Main.getUI().getInputWindow(this, commandParser);
  60. WindowManager.addWindow(server.getFrame(), window);
  61. window.setTitle("(Raw log)");
  62. window.getInputHandler().setTabCompleter(server.getTabCompleter());
  63. window.open();
  64. }
  65. /**
  66. * Registers the data callbacks for this raw window.
  67. */
  68. public void registerCallbacks() {
  69. try {
  70. server.getParser().getCallbackManager().addCallback(DataInListener.class, this);
  71. server.getParser().getCallbackManager().addCallback(DataOutListener.class, this);
  72. } catch (CallbackNotFoundException ex) {
  73. Logger.appError(ErrorLevel.HIGH, "Unable to register raw callbacks", ex);
  74. }
  75. }
  76. /** {@inheritDoc} */
  77. @Override
  78. public void windowClosing() {
  79. // 1: Make the window non-visible
  80. window.setVisible(false);
  81. // 2: Remove any callbacks or listeners
  82. if (server.getParser() != null) {
  83. server.getParser().getCallbackManager().delAllCallback(this);
  84. }
  85. // 3: Trigger any actions neccessary
  86. // 4: Trigger action for the window closing
  87. // 5: Inform any parents that the window is closing
  88. server.delRaw();
  89. // 6: Remove the window from the window manager
  90. WindowManager.removeWindow(window);
  91. // 7: Remove any references to the window and parents
  92. window = null;
  93. server = null;
  94. }
  95. /** {@inheritDoc} */
  96. @Override
  97. public InputWindow getFrame() {
  98. return window;
  99. }
  100. /** {@inheritDoc} */
  101. @Override
  102. public void onDataIn(final Parser tParser, final String sData) {
  103. addLine("rawIn", sData);
  104. }
  105. /** {@inheritDoc} */
  106. @Override
  107. public void onDataOut(final Parser tParser, final String sData,
  108. final boolean bFromParser) {
  109. addLine("rawOut", sData);
  110. }
  111. /** {@inheritDoc} */
  112. @Override
  113. public Server getServer() {
  114. return server;
  115. }
  116. /** {@inheritDoc} */
  117. @Override
  118. public void sendLine(final String line) {
  119. if (!line.isEmpty()) {
  120. server.sendLine(window.getTranscoder().encode(line));
  121. }
  122. }
  123. /** {@inheritDoc} */
  124. @Override
  125. public int getMaxLineLength() {
  126. return server.getMaxLineLength();
  127. }
  128. }