Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DCCChatWindow.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (c) 2006-2010 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.addons.dcc;
  23. import com.dmdirc.actions.ActionManager;
  24. import com.dmdirc.addons.dcc.actions.DCCActions;
  25. import com.dmdirc.Main;
  26. /**
  27. * This class links DCC Chat objects to a window.
  28. *
  29. * @author Shane 'Dataforce' McCormack
  30. */
  31. public class DCCChatWindow extends DCCFrame implements DCCChatInterface {
  32. /** The DCCChat object we are a window for */
  33. private final DCCChat dcc;
  34. /** My Nickname */
  35. private final String nickname;
  36. /** Other Nickname */
  37. private final String otherNickname;
  38. /**
  39. * Creates a new instance of DCCChatWindow with a given DCCChat object.
  40. *
  41. * @param plugin the DCC Plugin responsible for this window
  42. * @param dcc The DCCChat object this window wraps around
  43. * @param title The title of this window
  44. * @param nick My Current Nickname
  45. * @param targetNick Nickname of target
  46. */
  47. public DCCChatWindow(final DCCPlugin plugin, final DCCChat dcc, final String title, final String nick, final String targetNick) {
  48. super(plugin, title, "dcc-chat-inactive", false);
  49. this.dcc = dcc;
  50. dcc.setHandler(this);
  51. nickname = nick;
  52. otherNickname = targetNick;
  53. myWindow = Main.getUI().getInputWindow(this, DCCCommandParser.getDCCCommandParser());
  54. plugin.addWindow(this);
  55. myWindow.setTitle(title);
  56. myWindow.open();
  57. }
  58. /**
  59. * Get the DCCChat Object associated with this window
  60. *
  61. * @return The DCCChat Object associated with this window
  62. */
  63. public DCCChat getDCC() {
  64. return dcc;
  65. }
  66. /**
  67. * Sends a line of text to this container's source.
  68. *
  69. * @param line The line to be sent
  70. */
  71. @Override
  72. public void sendLine(final String line) {
  73. if (dcc.isWriteable()) {
  74. final StringBuffer buff = new StringBuffer("DCCChatSelfMessage");
  75. ActionManager.processEvent(DCCActions.DCC_CHAT_SELFMESSAGE, buff, this, line);
  76. addLine(buff, nickname, myWindow.getTranscoder().encode(line));
  77. dcc.sendLine(line);
  78. } else {
  79. final StringBuffer buff = new StringBuffer("DCCChatError");
  80. addLine(buff, "Socket is closed.", myWindow.getTranscoder().encode(line));
  81. }
  82. }
  83. /**
  84. * Handle a received message
  85. *
  86. * @param dcc The DCCChat that this message is from
  87. * @param message The message
  88. */
  89. @Override
  90. public void handleChatMessage(final DCCChat dcc, final String message) {
  91. final StringBuffer buff = new StringBuffer("DCCChatMessage");
  92. ActionManager.processEvent(DCCActions.DCC_CHAT_MESSAGE, buff, this, otherNickname, message);
  93. addLine(buff, otherNickname, myWindow.getTranscoder().encode(message));
  94. }
  95. /**
  96. * Called when the socket is closed
  97. *
  98. * @param dcc The DCCChat that this message is from
  99. */
  100. @Override
  101. public void socketClosed(final DCCChat dcc) {
  102. final StringBuffer buff = new StringBuffer("DCCChatInfo");
  103. ActionManager.processEvent(DCCActions.DCC_CHAT_SOCKETCLOSED, buff, this);
  104. addLine(buff, "Socket closed");
  105. if (!isWindowClosing()) {
  106. setIcon("dcc-chat-inactive");
  107. }
  108. }
  109. /**
  110. * Called when the socket is opened
  111. *
  112. * @param dcc The DCCChat that this message is from
  113. */
  114. @Override
  115. public void socketOpened(final DCCChat dcc) {
  116. final StringBuffer buff = new StringBuffer("DCCChatInfo");
  117. ActionManager.processEvent(DCCActions.DCC_CHAT_SOCKETOPENED, buff, this);
  118. addLine(buff, "Socket opened");
  119. setIcon("dcc-chat-active");
  120. }
  121. /**
  122. * Closes this container (and it's associated frame).
  123. */
  124. @Override
  125. public void windowClosing() {
  126. super.windowClosing();
  127. dcc.close();
  128. }
  129. }