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.

DCCFrame.java 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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.Main;
  24. import com.dmdirc.Server;
  25. import com.dmdirc.WritableFrameContainer;
  26. import com.dmdirc.addons.ui_swing.components.frames.InputTextFrame;
  27. import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
  28. import com.dmdirc.addons.ui_swing.SwingController;
  29. import com.dmdirc.addons.ui_swing.UIUtilities;
  30. import com.dmdirc.commandparser.PopupType;
  31. import com.dmdirc.commandparser.parsers.CommandParser;
  32. import com.dmdirc.commandparser.parsers.GlobalCommandParser;
  33. import com.dmdirc.config.IdentityManager;
  34. import com.dmdirc.ui.WindowManager;
  35. import com.dmdirc.ui.interfaces.InputWindow;
  36. import com.dmdirc.util.ReturnableThread;
  37. import java.awt.Container;
  38. import javax.swing.JPopupMenu;
  39. /**
  40. * This class links DCC objects to a window.
  41. *
  42. * @author Shane 'Dataforce' McCormack
  43. */
  44. public abstract class DCCFrame extends WritableFrameContainer {
  45. /**
  46. * Empty Frame.
  47. */
  48. private class EmptyFrame extends InputTextFrame {
  49. /** A version number for this class. */
  50. private static final long serialVersionUID = 200711271;
  51. /**
  52. * Creates a new instance of EmptyFrame.
  53. *
  54. * @param owner The frame container that owns this frame
  55. */
  56. public EmptyFrame(final WritableFrameContainer owner) {
  57. super(owner, (SwingController) Main.getUI());
  58. setTextPane(null);
  59. pack();
  60. }
  61. /**
  62. * Retrieves the command Parser for this input window.
  63. *
  64. * @return This window's command parser
  65. */
  66. @Override
  67. public final CommandParser getCommandParser() {
  68. return GlobalCommandParser.getGlobalCommandParser();
  69. }
  70. /** {@inheritDoc} */
  71. @Override
  72. public PopupType getNicknamePopupType() {
  73. return null;
  74. }
  75. /** {@inheritDoc} */
  76. @Override
  77. public PopupType getChannelPopupType() {
  78. return null;
  79. }
  80. /** {@inheritDoc} */
  81. @Override
  82. public PopupType getHyperlinkPopupType() {
  83. return null;
  84. }
  85. /** {@inheritDoc} */
  86. @Override
  87. public PopupType getNormalPopupType() {
  88. return null;
  89. }
  90. /** {@inheritDoc} */
  91. @Override
  92. public void addCustomPopupItems(final JPopupMenu popupMenu) {
  93. //Add no custom popup items
  94. }
  95. }
  96. /** The Window we're using. */
  97. protected InputWindow myWindow = null;
  98. /** The dcc plugin that owns this frame */
  99. protected final DCCPlugin plugin;
  100. /** The Window we're using. */
  101. private boolean windowClosing = false;
  102. /**
  103. * Creates a new instance of DCCFrame with an empty window.
  104. *
  105. * @param plugin The DCCPlugin that owns this frame
  106. * @param title The title of this window
  107. * @param icon The icon to use
  108. */
  109. public DCCFrame(final DCCPlugin plugin, final String title, final String icon) {
  110. this(plugin, title, icon, true);
  111. }
  112. /**
  113. * Creates a new instance of DCCFrame.
  114. *
  115. * @param plugin The DCCPlugin that owns this frame
  116. * @param title The title of this window
  117. * @param defaultWindow Create default (empty) window. (non-default = chat frame)
  118. * @param icon The icon to use
  119. */
  120. public DCCFrame(final DCCPlugin plugin, final String title, final String icon, final boolean defaultWindow) {
  121. super(icon, title, IdentityManager.getGlobalConfig());
  122. this.plugin = plugin;
  123. if (defaultWindow) {
  124. myWindow = UIUtilities.invokeAndWait(new ReturnableThread<EmptyFrame>() {
  125. /** {@inheritDoc} */
  126. @Override
  127. public void run() {
  128. final EmptyFrame frame = new EmptyFrame(DCCFrame.this);
  129. frame.setTitle(title);
  130. setObject(frame);
  131. }
  132. });
  133. }
  134. }
  135. /**
  136. * Sends a line of text to this container's source.
  137. *
  138. * @param line The line to be sent
  139. */
  140. @Override
  141. public void sendLine(final String line) {
  142. }
  143. /**
  144. * Returns the maximum length that a line passed to sendLine() should be,
  145. * in order to prevent it being truncated or causing protocol violations.
  146. *
  147. * @return The maximum line length for this container
  148. */
  149. @Override
  150. public int getMaxLineLength() {
  151. return 512;
  152. }
  153. /**
  154. * Returns the internal frame associated with this object.
  155. *
  156. * @return The internal frame associated with this object
  157. */
  158. @Override
  159. public InputWindow getFrame() {
  160. return myWindow;
  161. }
  162. /**
  163. * Returns the content pane of the internal frame associated with this object.
  164. *
  165. * @return The content pane of the internal frame associated with this object
  166. */
  167. public Container getContentPane() {
  168. return ((TextFrame) getFrame()).getContentPane();
  169. }
  170. /**
  171. * Returns the server instance associated with this container.
  172. *
  173. * @return the associated server connection
  174. */
  175. @Override
  176. public Server getServer() {
  177. return null;
  178. }
  179. /**
  180. * Is the window closing?
  181. *
  182. * @return True if windowClosing has been called.
  183. */
  184. public final boolean isWindowClosing() {
  185. return windowClosing;
  186. }
  187. /** {@inheritDoc} */
  188. @Override
  189. public void windowClosing() {
  190. windowClosing = true;
  191. // 1: Make the window non-visible
  192. myWindow.setVisible(false);
  193. // 2: Remove any callbacks or listeners
  194. // 3: Trigger any actions neccessary
  195. // 4: Trigger action for the window closing
  196. // 5: Inform any parents that the window is closing
  197. plugin.delWindow(this);
  198. // 6: Remove the window from the window manager
  199. WindowManager.removeWindow(myWindow);
  200. // 7: Remove any references to the window and parents
  201. myWindow = null; // NOPMD
  202. }
  203. }