File Source: DCCChatWindow.java
/*
P/P * Method: com.dmdirc.addons.dcc.DCCChatWindow__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 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
23 package com.dmdirc.addons.dcc;
24
25 import com.dmdirc.actions.ActionManager;
26 import com.dmdirc.addons.dcc.actions.DCCActions;
27 import com.dmdirc.Main;
28 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29
30 /**
31 * This class links DCC Chat objects to a window.
32 *
33 * @author Shane 'Dataforce' McCormack
34 */
35 public class DCCChatWindow extends DCCFrame implements DCCChatInterface {
36 /** The DCCChat object we are a window for */
37 private final DCCChat dcc;
38
39 /** My Nickname */
40 private final String nickname;
41
42 /** Other Nickname */
43 private final String otherNickname;
44
45 /**
46 * Creates a new instance of DCCChatWindow with a given DCCChat object.
47 *
48 * @param plugin the DCC Plugin responsible for this window
49 * @param dcc The DCCChat object this window wraps around
50 * @param title The title of this window
51 * @param nick My Current Nickname
52 * @param targetNick Nickname of target
53 */
54 public DCCChatWindow(final DCCPlugin plugin, final DCCChat dcc, final String title, final String nick, final String targetNick) {
/*
P/P * Method: void com.dmdirc.addons.dcc.DCCChatWindow(DCCPlugin, DCCChat, String, String, String)
*
* Preconditions:
* com/dmdirc/Main.controller != null
* dcc != null
* init'ed(plugin.container)
* plugin != null
* (soft) plugin.childFrames != null
*
* Presumptions:
* com.dmdirc.config.IdentityManager:getGlobalConfig(...)@138 init'ed
* com.dmdirc.ui.interfaces.UIController:getInputWindow(...)@61 != null
* (soft) init'ed(com/dmdirc/FrameContainer.java.awt.Color.BLACK)
*
* Postconditions:
* dcc.handler == this
* dcc.handler != null
* plugin.container == One-of{old plugin.container, &new DCCPlugin$3(createContainer#1)}
* plugin.container != null
* this.changer == &new FrameContainer$IconChanger(FrameContainer#2)
* this.config != null
* this.dcc == dcc
* this.dcc != null
* this.icon == &"dcc-chat-inactive"
* this.listeners == &new ListenerList(FrameContainer#1)
* ...
*/
55 super(plugin, title, "dcc-chat-inactive", false);
56 this.dcc = dcc;
57 dcc.setHandler(this);
58 nickname = nick;
59 otherNickname = targetNick;
60
61 myWindow = Main.getUI().getInputWindow(this, GlobalCommandParser.getGlobalCommandParser());
62 plugin.addWindow(this);
63
64 myWindow.setTitle(title);
65 myWindow.open();
66 }
67
68 /**
69 * Get the DCCChat Object associated with this window
70 *
71 * @return The DCCChat Object associated with this window
72 */
73 public DCCChat getDCC() {
/*
P/P * Method: DCCChat getDCC()
*
* Postconditions:
* return_value == this.dcc
* init'ed(return_value)
*/
74 return dcc;
75 }
76
77 /**
78 * Sends a line of text to this container's source.
79 *
80 * @param line The line to be sent
81 */
82 @Override
83 public void sendLine(final String line) {
/*
P/P * Method: void sendLine(String)
*
* Preconditions:
* this.dcc != null
* init'ed(this.dcc.out)
* this.myWindow != null
* (soft) com.dmdirc.addons.dcc.actions.DCCActions__static_init.new DCCActions(DCCActions__static_init#4).type != null
* (soft) init'ed(com/dmdirc/actions/ActionManager.killSwitch)
* (soft) init'ed(com/dmdirc/ServerManager.me)
*
* Presumptions:
* com.dmdirc.ui.interfaces.InputWindow:getTranscoder(...)@87 != null
* com.dmdirc.ui.interfaces.InputWindow:getTranscoder(...)@91 != null
*
* Postconditions:
* com/dmdirc/ServerManager.me == old com/dmdirc/ServerManager.me
* new ArrayList(ServerManager#1) num objects == 0, if init'ed
* new ServerManager(getServerManager#1) num objects == 0, if init'ed
* new ServerManager(getServerManager#1).servers == null
*
* Test Vectors:
* this.dcc.out: Addr_Set{null}, Inverse{null}
*/
84 if (dcc.isWriteable()) {
85 final StringBuffer buff = new StringBuffer("DCCChatSelfMessage");
86 ActionManager.processEvent(DCCActions.DCC_CHAT_SELFMESSAGE, buff, this, line);
87 addLine(buff, nickname, myWindow.getTranscoder().encode(line));
88 dcc.sendLine(line);
89 } else {
90 final StringBuffer buff = new StringBuffer("DCCChatError");
91 addLine(buff, "Socket is closed.", myWindow.getTranscoder().encode(line));
92 }
93 }
94
95 /**
96 * Handle a received message
97 *
98 * @param dcc The DCCChat that this message is from
99 * @param message The message
100 */
101 @Override
102 public void handleChatMessage(final DCCChat dcc, final String message) {
/*
P/P * Method: void handleChatMessage(DCCChat, String)
*
* Preconditions:
* init'ed(com/dmdirc/actions/ActionManager.killSwitch)
* this.myWindow != null
* (soft) com.dmdirc.addons.dcc.actions.DCCActions__static_init.new DCCActions(DCCActions__static_init#3).type != null
* (soft) init'ed(com/dmdirc/ServerManager.me)
*
* Presumptions:
* com.dmdirc.ui.interfaces.InputWindow:getTranscoder(...)@105 != null
*
* Postconditions:
* com/dmdirc/ServerManager.me == old com/dmdirc/ServerManager.me
* new ArrayList(ServerManager#1) num objects == undefined
* new ArrayList(ServerManager#1) num objects == 0, if init'ed
* new ServerManager(getServerManager#1) num objects == new ArrayList(ServerManager#1) num objects
* new ServerManager(getServerManager#1).servers == undefined
* new ServerManager(getServerManager#1).servers == null
*/
103 final StringBuffer buff = new StringBuffer("DCCChatMessage");
104 ActionManager.processEvent(DCCActions.DCC_CHAT_MESSAGE, buff, this, otherNickname, message);
105 addLine(buff, otherNickname, myWindow.getTranscoder().encode(message));
106 }
107
108 /**
109 * Called when the socket is closed
110 *
111 * @param dcc The DCCChat that this message is from
112 */
113 @Override
114 public void socketClosed(final DCCChat dcc) {
/*
P/P * Method: void socketClosed(DCCChat)
*
* Preconditions:
* init'ed(com/dmdirc/actions/ActionManager.killSwitch)
* init'ed(this.windowClosing)
* (soft) com.dmdirc.addons.dcc.actions.DCCActions__static_init.new DCCActions(DCCActions__static_init#5).type != null
* (soft) init'ed(com/dmdirc/ServerManager.me)
* (soft) this.config != null
* (soft) this.listeners != null
*
* Postconditions:
* com/dmdirc/ServerManager.me == old com/dmdirc/ServerManager.me
* this.icon == One-of{old this.icon, &"dcc-chat-inactive"}
* new ArrayList(ServerManager#1) num objects == undefined
* new ArrayList(ServerManager#1) num objects == 0, if init'ed
* new ServerManager(getServerManager#1) num objects == new ArrayList(ServerManager#1) num objects
* new ServerManager(getServerManager#1).servers == undefined
* new ServerManager(getServerManager#1).servers == null
*
* Test Vectors:
* this.windowClosing: {1}, {0}
*/
115 final StringBuffer buff = new StringBuffer("DCCChatInfo");
116 ActionManager.processEvent(DCCActions.DCC_CHAT_SOCKETCLOSED, buff, this);
117 addLine(buff, "Socket closed");
118 if (!isWindowClosing()) {
119 setIcon("dcc-chat-inactive");
120 }
121 }
122
123 /**
124 * Called when the socket is opened
125 *
126 * @param dcc The DCCChat that this message is from
127 */
128 @Override
129 public void socketOpened(final DCCChat dcc) {
/*
P/P * Method: void socketOpened(DCCChat)
*
* Preconditions:
* init'ed(com/dmdirc/actions/ActionManager.killSwitch)
* this.config != null
* this.listeners != null
* (soft) com.dmdirc.addons.dcc.actions.DCCActions__static_init.new DCCActions(DCCActions__static_init#6).type != null
* (soft) init'ed(com/dmdirc/ServerManager.me)
*
* Postconditions:
* com/dmdirc/ServerManager.me == old com/dmdirc/ServerManager.me
* this.icon == &"dcc-chat-active"
* new ArrayList(ServerManager#1) num objects == undefined
* new ArrayList(ServerManager#1) num objects == 0, if init'ed
* new ServerManager(getServerManager#1) num objects == new ArrayList(ServerManager#1) num objects
* new ServerManager(getServerManager#1).servers == undefined
* new ServerManager(getServerManager#1).servers == null
*/
130 final StringBuffer buff = new StringBuffer("DCCChatInfo");
131 ActionManager.processEvent(DCCActions.DCC_CHAT_SOCKETOPENED, buff, this);
132 addLine(buff, "Socket opened");
133 setIcon("dcc-chat-active");
134 }
135
136 /**
137 * Closes this container (and it's associated frame).
138 */
139 @Override
140 public void windowClosing() {
/*
P/P * Method: void windowClosing()
*
* Preconditions:
* this.myWindow != null
* init'ed(this.plugin.container)
* this.dcc != null
* this.dcc.serverSocketSem != null
* this.plugin != null
* (soft) init'ed(this.dcc.serverSocket)
* (soft) init'ed(this.dcc.socket)
* (soft) this.dcc.serverListeningSem != null
* (soft) this.plugin.childFrames != null
*
* Postconditions:
* possibly_updated(this.dcc.in)
* possibly_updated(this.dcc.out)
* this.dcc.serverSocket == null
* this.dcc.socket == null
* this.myWindow == null
* this.plugin.container == One-of{old this.plugin.container, null}
* init'ed(this.plugin.container)
* this.windowClosing == 1
*/
141 super.windowClosing();
142 dcc.close();
143 }
144 }
SofCheck Inspector Build Version : 2.17854
| DCCChatWindow.java |
2009-Jun-25 01:54:24 |
| DCCChatWindow.class |
2009-Sep-02 17:04:17 |