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.

FakeInputWindow.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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.redirect;
  23. import com.dmdirc.MessageTarget;
  24. import com.dmdirc.WritableFrameContainer;
  25. import com.dmdirc.commandparser.parsers.CommandParser;
  26. import com.dmdirc.config.ConfigManager;
  27. import com.dmdirc.ui.input.InputHandler;
  28. import com.dmdirc.ui.interfaces.InputWindow;
  29. import com.dmdirc.ui.messages.Formatter;
  30. import com.dmdirc.util.StringTranscoder;
  31. import java.beans.PropertyVetoException;
  32. import java.nio.charset.Charset;
  33. /**
  34. * Implements a fake input window, which sends echoed text to the specified
  35. * chat window instead.
  36. *
  37. * @author Chris
  38. */
  39. public class FakeInputWindow implements InputWindow {
  40. /** The target for this window. */
  41. private final MessageTarget target;
  42. /**
  43. * Creates a new instance of FakeInputWindow.
  44. *
  45. * @param target The message target that output gets sent to
  46. */
  47. public FakeInputWindow(final MessageTarget target) {
  48. this.target = target;
  49. }
  50. /** {@inheritDoc} */
  51. @Override
  52. public CommandParser getCommandParser() {
  53. return target.getFrame().getCommandParser();
  54. }
  55. /** {@inheritDoc} */
  56. @Override
  57. public InputHandler getInputHandler() {
  58. return target.getFrame().getInputHandler();
  59. }
  60. /** {@inheritDoc} */
  61. @Override
  62. public void setAwayIndicator(final boolean isAway) {
  63. // Do nothing
  64. }
  65. /** {@inheritDoc} */
  66. @Override
  67. public void addLine(final String messageType, final Object... args) {
  68. target.sendLine(Formatter.formatMessage(getConfigManager(), messageType, args));
  69. }
  70. /** {@inheritDoc} */
  71. @Override
  72. public void addLine(final StringBuffer messageType, final Object... args) {
  73. addLine(messageType.toString(), args);
  74. }
  75. /** {@inheritDoc} */
  76. @Override
  77. public void addLine(final String line, final boolean timestamp) {
  78. target.sendLine(line);
  79. }
  80. /** {@inheritDoc} */
  81. @Override
  82. public void clear() {
  83. // Do nothing
  84. }
  85. /** {@inheritDoc} */
  86. @Override
  87. public ConfigManager getConfigManager() {
  88. return target.getFrame().getConfigManager();
  89. }
  90. /** {@inheritDoc} */
  91. @Override
  92. public WritableFrameContainer getContainer() {
  93. return target;
  94. }
  95. /** {@inheritDoc} */
  96. @Override
  97. public boolean isVisible() {
  98. return false;
  99. }
  100. /** {@inheritDoc} */
  101. @Override
  102. public void setVisible(final boolean isVisible) {
  103. // Do nothing
  104. }
  105. /** {@inheritDoc} */
  106. @Override
  107. public String getTitle() {
  108. return "Fake window";
  109. }
  110. /** {@inheritDoc} */
  111. @Override
  112. public boolean isMaximum() {
  113. return false;
  114. }
  115. /** {@inheritDoc} */
  116. @Override
  117. public void setTitle(final String title) {
  118. // Do nothing
  119. }
  120. /** {@inheritDoc} */
  121. @Override
  122. public void open() {
  123. // Do nothing
  124. }
  125. /** {@inheritDoc} */
  126. @Override
  127. public StringTranscoder getTranscoder() {
  128. return new StringTranscoder(Charset.defaultCharset());
  129. }
  130. /** {@inheritDoc} */
  131. @Override
  132. public void close() {
  133. /// Do nothing
  134. }
  135. /** {@inheritDoc} */
  136. @Override
  137. public void restore() {
  138. // Do nothing
  139. }
  140. /** {@inheritDoc} */
  141. @Override
  142. public void maximise() {
  143. // Do nothing
  144. }
  145. /** {@inheritDoc} */
  146. @Override
  147. public void toggleMaximise() {
  148. // Do nothing
  149. }
  150. /** {@inheritDoc} */
  151. @Override
  152. public void minimise() {
  153. // Do nothing
  154. }
  155. /** {@inheritDoc} */
  156. @Override
  157. public void activateFrame() {
  158. // Do nothing
  159. }
  160. }