您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Raw.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  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.interfaces.CommandController;
  25. import com.dmdirc.interfaces.Connection;
  26. import com.dmdirc.logger.ErrorLevel;
  27. import com.dmdirc.logger.Logger;
  28. import com.dmdirc.messages.MessageSinkManager;
  29. import com.dmdirc.parser.common.CallbackNotFoundException;
  30. import com.dmdirc.parser.interfaces.Parser;
  31. import com.dmdirc.parser.interfaces.callbacks.DataInListener;
  32. import com.dmdirc.parser.interfaces.callbacks.DataOutListener;
  33. import com.dmdirc.ui.core.components.WindowComponent;
  34. import com.dmdirc.util.URLBuilder;
  35. import com.dmdirc.util.annotations.factory.Factory;
  36. import com.dmdirc.util.annotations.factory.Unbound;
  37. import java.util.Arrays;
  38. import java.util.Date;
  39. /**
  40. * Handles the raw window (which shows the user raw data being sent and received to/from the
  41. * server).
  42. */
  43. @Factory(inject = true, providers = true, singleton = true)
  44. public class Raw extends FrameContainer implements DataInListener, DataOutListener {
  45. /** The server object that's being monitored. */
  46. private final Server server;
  47. /**
  48. * Creates a new instance of Raw.
  49. *
  50. * @param newServer the server to monitor
  51. * @param commandController The controller to load commands from.
  52. * @param messageSinkManager The sink manager to use to despatch messages.
  53. * @param urlBuilder The URL builder to use when finding icons.
  54. */
  55. public Raw(
  56. @Unbound final Server newServer,
  57. final CommandController commandController,
  58. final MessageSinkManager messageSinkManager,
  59. final URLBuilder urlBuilder) {
  60. super("raw", "Raw", "(Raw log)", newServer.getConfigManager(), urlBuilder,
  61. new ServerCommandParser(newServer.getConfigManager(), commandController),
  62. newServer.getTabCompleter(),
  63. messageSinkManager,
  64. Arrays.asList(
  65. WindowComponent.TEXTAREA.getIdentifier(),
  66. WindowComponent.INPUTFIELD.getIdentifier()));
  67. this.server = newServer;
  68. getCommandParser().setOwner(server);
  69. }
  70. /**
  71. * Registers the data callbacks for this raw window.
  72. */
  73. public void registerCallbacks() {
  74. try {
  75. server.getParser().getCallbackManager().addCallback(DataInListener.class, this);
  76. server.getParser().getCallbackManager().addCallback(DataOutListener.class, this);
  77. } catch (CallbackNotFoundException ex) {
  78. Logger.appError(ErrorLevel.HIGH, "Unable to register raw callbacks", ex);
  79. }
  80. }
  81. @Override
  82. public void close() {
  83. super.close();
  84. // Remove any callbacks or listeners
  85. if (server.getParser() != null) {
  86. server.getParser().getCallbackManager().delAllCallback(this);
  87. }
  88. // Inform any parents that the window is closing
  89. server.delRaw();
  90. }
  91. @Override
  92. public void onDataIn(final Parser parser, final Date date, final String data) {
  93. addLine("rawIn", data);
  94. }
  95. @Override
  96. public void onDataOut(final Parser parser, final Date date, final String data,
  97. final boolean fromParser) {
  98. addLine("rawOut", data);
  99. }
  100. @Override
  101. public Connection getConnection() {
  102. return server;
  103. }
  104. @Override
  105. public void sendLine(final String line) {
  106. server.sendLine(line);
  107. }
  108. @Override
  109. public int getMaxLineLength() {
  110. return server.getMaxLineLength();
  111. }
  112. }