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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.RawCommandParser;
  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.input.TabCompleter;
  32. import com.dmdirc.ui.interfaces.InputWindow;
  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<InputWindow>
  39. implements DataInListener, DataOutListener {
  40. /** The server object that's being monitored. */
  41. private Server server;
  42. /**
  43. * Creates a new instance of Raw.
  44. *
  45. * @param newServer the server to monitor
  46. */
  47. public Raw(final Server newServer) {
  48. super("raw", "Raw", "(Raw log)", InputWindow.class,
  49. newServer.getConfigManager(), new RawCommandParser());
  50. this.server = newServer;
  51. WindowManager.addWindow(server, this);
  52. }
  53. /**
  54. * Registers the data callbacks for this raw window.
  55. */
  56. public void registerCallbacks() {
  57. try {
  58. server.getParser().getCallbackManager().addCallback(DataInListener.class, this);
  59. server.getParser().getCallbackManager().addCallback(DataOutListener.class, this);
  60. } catch (CallbackNotFoundException ex) {
  61. Logger.appError(ErrorLevel.HIGH, "Unable to register raw callbacks", ex);
  62. }
  63. }
  64. /** {@inheritDoc} */
  65. @Override
  66. public void windowClosing() {
  67. // 1: Make the window non-visible
  68. getFrame().setVisible(false);
  69. // 2: Remove any callbacks or listeners
  70. if (server.getParser() != null) {
  71. server.getParser().getCallbackManager().delAllCallback(this);
  72. }
  73. // 3: Trigger any actions neccessary
  74. // 4: Trigger action for the window closing
  75. // 5: Inform any parents that the window is closing
  76. server.delRaw();
  77. // 6: Remove the window from the window manager
  78. WindowManager.removeWindow(this);
  79. }
  80. /** {@inheritDoc} */
  81. @Override
  82. public void windowClosed() {
  83. // 7: Remove any references to the window and parents
  84. server = null;
  85. }
  86. /** {@inheritDoc} */
  87. @Override
  88. public void onDataIn(final Parser tParser, final String sData) {
  89. addLine("rawIn", sData);
  90. }
  91. /** {@inheritDoc} */
  92. @Override
  93. public void onDataOut(final Parser tParser, final String sData,
  94. final boolean bFromParser) {
  95. addLine("rawOut", sData);
  96. }
  97. /** {@inheritDoc} */
  98. @Override
  99. public Server getServer() {
  100. return server;
  101. }
  102. /** {@inheritDoc} */
  103. @Override
  104. public void sendLine(final String line) {
  105. if (!line.isEmpty()) {
  106. sendLine(getTranscoder().encode(line));
  107. }
  108. }
  109. /** {@inheritDoc} */
  110. @Override
  111. public int getMaxLineLength() {
  112. return server.getMaxLineLength();
  113. }
  114. /** {@inheritDoc} */
  115. @Override
  116. public TabCompleter getTabCompleter() {
  117. return server.getTabCompleter();
  118. }
  119. }