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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 uk.org.ownage.dmdirc;
  23. import java.net.URL;
  24. import javax.swing.ImageIcon;
  25. import uk.org.ownage.dmdirc.commandparser.CommandWindow;
  26. import uk.org.ownage.dmdirc.parser.IRCParser;
  27. import uk.org.ownage.dmdirc.parser.callbacks.interfaces.IDataIn;
  28. import uk.org.ownage.dmdirc.parser.callbacks.interfaces.IDataOut;
  29. import uk.org.ownage.dmdirc.ui.MainFrame;
  30. import uk.org.ownage.dmdirc.ui.ServerFrame;
  31. /**
  32. * Handles the raw window (which shows the user raw data being sent and
  33. * received to/from the server).
  34. * @author chris
  35. */
  36. public final class Raw extends FrameContainer implements IDataIn, IDataOut {
  37. /**
  38. * The server object that's being monitored.
  39. */
  40. private Server server;
  41. /**
  42. * A serverframe instance used for displaying the raw data.
  43. */
  44. private ServerFrame frame;
  45. /**
  46. * Creates a new instance of Raw.
  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("uk/org/ownage/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.setTabCompleter(server.getTabCompleter());
  59. frame.setFrameIcon(imageIcon);
  60. frame.open();
  61. }
  62. /**
  63. * Closes the raw window. Removes parser callbacks, removes the actual.
  64. * frame, and removes references to the frame and server.
  65. */
  66. public void close() {
  67. server.getParser().getCallbackManager().delCallback("OnDataIn", this);
  68. server.getParser().getCallbackManager().delCallback("OnDataOut", this);
  69. frame.setVisible(false);
  70. MainFrame.getMainFrame().delChild(frame);
  71. frame = null;
  72. server.delRaw();
  73. server = null;
  74. }
  75. /**
  76. * Returns the internal frame belonging to this object.
  77. * @return This object's internal frame
  78. */
  79. public CommandWindow getFrame() {
  80. return frame;
  81. }
  82. /**
  83. * Called when the parser receives a line of data. The data is simply
  84. * logged to the raw window.
  85. * @param parser A reference to the IRC parser
  86. * @param data The data that was received
  87. */
  88. public void onDataIn(final IRCParser parser, final String data) {
  89. addLine("rawIn", data);
  90. }
  91. /**
  92. * Called when the parser receives a line of data. The data is simply
  93. * logged to the raw window.
  94. * @param parser A reference to the IRC parser
  95. * @param data The data that was received
  96. * @param fromParser true if sent from parser, false otherwise
  97. */
  98. public void onDataOut(final IRCParser parser, final String data,
  99. final boolean fromParser) {
  100. addLine("rawOut", data);
  101. }
  102. /**
  103. * Returns "Raw"...
  104. * @return A string representation of this raw object
  105. */
  106. public String toString() {
  107. return "Raw";
  108. }
  109. /**
  110. * Returns the server instance associated with this frame.
  111. *
  112. * @return the associated server connection
  113. */
  114. public Server getServer() {
  115. return server;
  116. }
  117. }