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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.InputWindow;
  30. import com.dmdirc.ui.MainFrame;
  31. import com.dmdirc.ui.ServerFrame;
  32. import java.net.URL;
  33. import javax.swing.ImageIcon;
  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 FrameContainer implements IDataIn, IDataOut {
  40. /** The server object that's being monitored. */
  41. private Server server;
  42. /** A serverframe instance used for displaying the raw data.*/
  43. private ServerFrame frame;
  44. /**
  45. * Creates a new instance of Raw.
  46. *
  47. * @param newServer the server to monitor
  48. */
  49. public Raw(final Server newServer) {
  50. this.server = newServer;
  51. final ClassLoader cldr = this.getClass().getClassLoader();
  52. final URL imageURL = cldr.getResource("com/dmdirc/res/raw.png");
  53. imageIcon = new ImageIcon(imageURL);
  54. frame = new ServerFrame(server);
  55. frame.setTitle("(Raw log)");
  56. frame.addInternalFrameListener(this);
  57. MainFrame.getMainFrame().addChild(frame);
  58. frame.getInputHandler().setTabCompleter(server.getTabCompleter());
  59. frame.setFrameIcon(imageIcon);
  60. frame.open();
  61. }
  62. /**
  63. * Registers the data callbacks for this raw window.
  64. */
  65. public void registerCallbacks() {
  66. try {
  67. server.getParser().getCallbackManager().addCallback("OnDataIn", this);
  68. server.getParser().getCallbackManager().addCallback("OnDataOut", this);
  69. } catch (CallbackNotFound ex) {
  70. Logger.error(ErrorLevel.ERROR, "Unable to register raw callbacks", ex);
  71. }
  72. }
  73. /**
  74. * Closes the raw window. Removes parser callbacks, removes the actual.
  75. * frame, and removes references to the frame and server.
  76. */
  77. public void close() {
  78. server.getParser().getCallbackManager().delCallback("OnDataIn", this);
  79. server.getParser().getCallbackManager().delCallback("OnDataOut", this);
  80. frame.setVisible(false);
  81. MainFrame.getMainFrame().delChild(frame);
  82. frame = null;
  83. server.delRaw();
  84. server = null;
  85. }
  86. /** {@inheritDoc} */
  87. public InputWindow getFrame() {
  88. return frame;
  89. }
  90. /** {@inheritDoc} */
  91. public void onDataIn(final IRCParser tParser, final String sData) {
  92. addLine("rawIn", sData);
  93. }
  94. /** {@inheritDoc} */
  95. public void onDataOut(final IRCParser tParser, final String sData,
  96. final boolean bFromParser) {
  97. addLine("rawOut", sData);
  98. }
  99. /**
  100. * Returns "Raw"...
  101. * @return A string representation of this raw object
  102. */
  103. public String toString() {
  104. return "Raw";
  105. }
  106. /**
  107. * Returns the server instance associated with this frame.
  108. *
  109. * @return the associated server connection
  110. */
  111. public Server getServer() {
  112. return server;
  113. }
  114. }