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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2006-2007 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.logger.ErrorLevel;
  24. import com.dmdirc.logger.Logger;
  25. import com.dmdirc.parser.IRCParser;
  26. import com.dmdirc.parser.callbacks.CallbackNotFound;
  27. import com.dmdirc.parser.callbacks.interfaces.IDataIn;
  28. import com.dmdirc.parser.callbacks.interfaces.IDataOut;
  29. import com.dmdirc.ui.CustomInputFrame;
  30. import com.dmdirc.ui.MainFrame;
  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 IDataIn,
  39. IDataOut, 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. /** A serverframe instance used for displaying the raw data.*/
  49. private CustomInputFrame frame;
  50. /**
  51. * Creates a new instance of Raw.
  52. *
  53. * @param newServer the server to monitor
  54. */
  55. public Raw(final Server newServer) {
  56. super();
  57. this.server = newServer;
  58. icon = IconManager.getIcon("raw");
  59. frame = new CustomInputFrame(this, newServer.getFrame().getCommandParser());
  60. frame.setTitle("(Raw log)");
  61. MainFrame.getMainFrame().addChild(frame);
  62. frame.getInputHandler().setTabCompleter(server.getTabCompleter());
  63. frame.setFrameIcon(icon);
  64. frame.open();
  65. }
  66. /**
  67. * Registers the data callbacks for this raw window.
  68. */
  69. public void registerCallbacks() {
  70. try {
  71. server.getParser().getCallbackManager().addCallback("OnDataIn", this);
  72. server.getParser().getCallbackManager().addCallback("OnDataOut", this);
  73. } catch (CallbackNotFound ex) {
  74. Logger.appError(ErrorLevel.HIGH, "Unable to register raw callbacks", ex);
  75. }
  76. }
  77. /**
  78. * Closes the raw window. Removes parser callbacks, removes the actual.
  79. * frame, and removes references to the frame and server.
  80. */
  81. public void close() {
  82. server.getParser().getCallbackManager().delCallback("OnDataIn", this);
  83. server.getParser().getCallbackManager().delCallback("OnDataOut", this);
  84. frame.setVisible(false);
  85. MainFrame.getMainFrame().delChild(frame);
  86. frame = null;
  87. server.delRaw();
  88. server = null;
  89. }
  90. /** {@inheritDoc} */
  91. public InputWindow getFrame() {
  92. return frame;
  93. }
  94. /** {@inheritDoc} */
  95. public void onDataIn(final IRCParser tParser, final String sData) {
  96. frame.addLine("rawIn", sData);
  97. }
  98. /** {@inheritDoc} */
  99. public void onDataOut(final IRCParser tParser, final String sData,
  100. final boolean bFromParser) {
  101. frame.addLine("rawOut", sData);
  102. }
  103. /**
  104. * Returns "Raw"...
  105. * @return A string representation of this raw object
  106. */
  107. public String toString() {
  108. return "Raw";
  109. }
  110. /**
  111. * Returns the server instance associated with this frame.
  112. *
  113. * @return the associated server connection
  114. */
  115. public Server getServer() {
  116. return server;
  117. }
  118. /** {@inheritDoc} */
  119. public void sendLine(final String line) {
  120. server.sendLine(line);
  121. }
  122. /** {@inheritDoc} */
  123. public int getMaxLineLength() {
  124. return server.getMaxLineLength();
  125. }
  126. }