Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Raw.java 4.9KB

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