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.

Raw.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2006-2011 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.ServerCommandParser;
  24. import com.dmdirc.logger.ErrorLevel;
  25. import com.dmdirc.logger.Logger;
  26. import com.dmdirc.parser.common.CallbackNotFoundException;
  27. import com.dmdirc.parser.interfaces.Parser;
  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. import java.util.Date;
  34. /**
  35. * Handles the raw window (which shows the user raw data being sent and
  36. * received to/from the server).
  37. * @author chris
  38. */
  39. public final class Raw extends WritableFrameContainer<InputWindow>
  40. implements DataInListener, DataOutListener {
  41. /** The server object that's being monitored. */
  42. private Server server;
  43. /**
  44. * Creates a new instance of Raw.
  45. *
  46. * @param newServer the server to monitor
  47. */
  48. public Raw(final Server newServer) {
  49. super("raw", "Raw", "(Raw log)", InputWindow.class,
  50. newServer.getConfigManager(), new ServerCommandParser());
  51. this.server = newServer;
  52. getCommandParser().setOwner(server);
  53. WindowManager.addWindow(server, this);
  54. }
  55. /**
  56. * Registers the data callbacks for this raw window.
  57. */
  58. public void registerCallbacks() {
  59. try {
  60. server.getParser().getCallbackManager().addCallback(DataInListener.class, this);
  61. server.getParser().getCallbackManager().addCallback(DataOutListener.class, this);
  62. } catch (CallbackNotFoundException ex) {
  63. Logger.appError(ErrorLevel.HIGH, "Unable to register raw callbacks", ex);
  64. }
  65. }
  66. /** {@inheritDoc} */
  67. @Override
  68. public void windowClosing() {
  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. }
  78. /** {@inheritDoc} */
  79. @Override
  80. public void windowClosed() {
  81. // 7: Remove any references to the window and parents
  82. server = null;
  83. }
  84. /** {@inheritDoc} */
  85. @Override
  86. public void onDataIn(final Parser parser, final Date date, final String data) {
  87. addLine("rawIn", data);
  88. }
  89. /** {@inheritDoc} */
  90. @Override
  91. public void onDataOut(final Parser parser, final Date date, final String data,
  92. final boolean fromParser) {
  93. addLine("rawOut", data);
  94. }
  95. /** {@inheritDoc} */
  96. @Override
  97. public Server getServer() {
  98. return server;
  99. }
  100. /** {@inheritDoc} */
  101. @Override
  102. public void sendLine(final String line) {
  103. if (!line.isEmpty()) {
  104. sendLine(getTranscoder().encode(line));
  105. }
  106. }
  107. /** {@inheritDoc} */
  108. @Override
  109. public int getMaxLineLength() {
  110. return server.getMaxLineLength();
  111. }
  112. /** {@inheritDoc} */
  113. @Override
  114. public TabCompleter getTabCompleter() {
  115. return server.getTabCompleter();
  116. }
  117. }