File Source: Raw.java
/*
P/P * Method: com.dmdirc.Raw__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;
24
25 import com.dmdirc.logger.ErrorLevel;
26 import com.dmdirc.logger.Logger;
27 import com.dmdirc.parser.irc.IRCParser;
28 import com.dmdirc.parser.irc.callbacks.CallbackNotFoundException;
29 import com.dmdirc.parser.irc.callbacks.interfaces.IDataIn;
30 import com.dmdirc.parser.irc.callbacks.interfaces.IDataOut;
31 import com.dmdirc.ui.WindowManager;
32 import com.dmdirc.ui.interfaces.InputWindow;
33
34 import java.io.Serializable;
35
36 /**
37 * Handles the raw window (which shows the user raw data being sent and
38 * received to/from the server).
39 * @author chris
40 */
/*
P/P * Method: Window getFrame()
*
* Preconditions:
* init'ed(this.window)
*
* Postconditions:
* return_value == this.window
* init'ed(return_value)
*/
41 public final class Raw extends WritableFrameContainer implements IDataIn,
42 IDataOut, Serializable {
43
44 /**
45 * A version number for this class. It should be changed whenever the class
46 * structure is changed (or anything else that would prevent serialized
47 * objects being unserialized with the new class).
48 */
49 private static final long serialVersionUID = 1;
50
51 /** The server object that's being monitored. */
52 private Server server;
53
54 /** An InputWindow used for displaying the raw data.*/
55 private InputWindow window;
56
57 /**
58 * Creates a new instance of Raw.
59 *
60 * @param newServer the server to monitor
61 */
62 public Raw(final Server newServer) {
/*
P/P * Method: void com.dmdirc.Raw(Server)
*
* Preconditions:
* com/dmdirc/Main.controller != null
* newServer != null
* newServer.window != null
*
* Presumptions:
* com.dmdirc.Server:getConfigManager(...)@63 != null
* com.dmdirc.ui.interfaces.InputWindow:getInputHandler(...)@70 != null
* com.dmdirc.ui.interfaces.UIController:getInputWindow(...)@67 != null
* init'ed(com/dmdirc/FrameContainer.java.awt.Color.BLACK)
*
* Postconditions:
* this.changer == &new FrameContainer$IconChanger(FrameContainer#2)
* this.config != null
* this.icon == &"raw"
* this.listeners == &new ListenerList(FrameContainer#1)
* this.notification == com/dmdirc/FrameContainer.java.awt.Color.BLACK
* init'ed(this.notification)
* this.server == newServer
* this.server != null
* this.window != null
* new FrameContainer$IconChanger(FrameContainer#2) num objects == 1
* ...
*/
63 super("raw", newServer.getConfigManager());
64
65 this.server = newServer;
66
67 window = Main.getUI().getInputWindow(this, newServer.getFrame().getCommandParser());
68 WindowManager.addWindow(server.getFrame(), window);
69 window.setTitle("(Raw log)");
70 window.getInputHandler().setTabCompleter(server.getTabCompleter());
71
72 window.open();
73 }
74
75 /**
76 * Registers the data callbacks for this raw window.
77 */
78 public void registerCallbacks() {
79 try {
/*
P/P * Method: void registerCallbacks()
*
* Preconditions:
* (soft) this.server != null
* (soft) this.server.parser != null
*
* Presumptions:
* init'ed(com.dmdirc.logger.ErrorLevel.HIGH)
* com.dmdirc.parser.irc.IRCParser:getCallbackManager(...)@80 != null
* com.dmdirc.parser.irc.IRCParser:getCallbackManager(...)@81 != null
*/
80 server.getParser().getCallbackManager().addCallback("OnDataIn", this);
81 server.getParser().getCallbackManager().addCallback("OnDataOut", this);
82 } catch (CallbackNotFoundException ex) {
83 Logger.appError(ErrorLevel.HIGH, "Unable to register raw callbacks", ex);
84 }
85 }
86
87 /** {@inheritDoc} */
88 @Override
89 public void windowClosing() {
90 // 1: Make the window non-visible
/*
P/P * Method: void windowClosing()
*
* Preconditions:
* this.server != null
* this.window != null
* init'ed(this.server.parser)
*
* Presumptions:
* com.dmdirc.parser.irc.IRCParser:getCallbackManager(...)@95 != null
*
* Postconditions:
* this.server == null
* this.server.raw == null
* this.window == null
*
* Test Vectors:
* this.server.parser: Addr_Set{null}, Inverse{null}
*/
91 window.setVisible(false);
92
93 // 2: Remove any callbacks or listeners
94 if (server != null && server.getParser() != null) {
95 server.getParser().getCallbackManager().delAllCallback(this);
96 }
97
98 // 3: Trigger any actions neccessary
99 // 4: Trigger action for the window closing
100
101 // 5: Inform any parents that the window is closing
102 server.delRaw();
103
104 // 6: Remove the window from the window manager
105 WindowManager.removeWindow(window);
106
107 // 7: Remove any references to the window and parents
108 window = null;
109 server = null;
110 }
111
112 /** {@inheritDoc} */
113 @Override
114 public InputWindow getFrame() {
/*
P/P * Method: InputWindow getFrame()
*
* Preconditions:
* init'ed(this.window)
*
* Postconditions:
* return_value == this.window
* init'ed(return_value)
*/
115 return window;
116 }
117
118 /** {@inheritDoc} */
119 @Override
120 public void onDataIn(final IRCParser tParser, final String sData) {
/*
P/P * Method: void onDataIn(IRCParser, String)
*/
121 addLine("rawIn", sData);
122 }
123
124 /** {@inheritDoc} */
125 @Override
126 public void onDataOut(final IRCParser tParser, final String sData,
127 final boolean bFromParser) {
/*
P/P * Method: void onDataOut(IRCParser, String, bool)
*/
128 addLine("rawOut", sData);
129 }
130
131 /** {@inheritDoc} */
132 @Override
133 public String toString() {
/*
P/P * Method: String toString()
*
* Postconditions:
* return_value == &"Raw"
*/
134 return "Raw";
135 }
136
137 /** {@inheritDoc} */
138 @Override
139 public Server getServer() {
/*
P/P * Method: Server getServer()
*
* Preconditions:
* init'ed(this.server)
*
* Postconditions:
* return_value == this.server
* init'ed(return_value)
*/
140 return server;
141 }
142
143 /** {@inheritDoc} */
144 @Override
145 public void sendLine(final String line) {
/*
P/P * Method: void sendLine(String)
*
* Preconditions:
* this.server != null
* init'ed(this.server.parser)
* this.window != null
* (soft) this.server.myState != null
* (soft) init'ed(this.server.myState.state)
* (soft) this.server.window != null
*
* Presumptions:
* com.dmdirc.ui.interfaces.InputWindow:getTranscoder(...)@146 != null
*/
146 server.sendLine(window.getTranscoder().encode(line));
147 }
148
149 /** {@inheritDoc} */
150 @Override
151 public int getMaxLineLength() {
/*
P/P * Method: int getMaxLineLength()
*
* Preconditions:
* this.server != null
*
* Postconditions:
* return_value == 510
*/
152 return server.getMaxLineLength();
153 }
154
155 }
SofCheck Inspector Build Version : 2.17854
| Raw.java |
2009-Jun-25 01:54:24 |
| Raw.class |
2009-Sep-02 17:04:17 |