Browse Source

* Added Channel.close(), Raw.close() and Server.close()

* Added Server.disconnect()
* Added MainFrame.delChild()
* Implemented ServerManager.disconnectAll() and added ServerManager.closeAll()
* Raw's parser callbacks are now normal methods not AICs

git-svn-id: http://svn.dmdirc.com/trunk@192 00569f92-eb28-0410-84fd-f71c24880f
tags/0.1
Chris Smith 17 years ago
parent
commit
7f6fe4f903

+ 16
- 0
src/uk/org/ownage/dmdirc/Channel.java View File

@@ -155,5 +155,21 @@ public class Channel implements IRCParser.IChannelMessage,
155 155
     public Server getServer() {
156 156
         return server;
157 157
     }
158
+
159
+    void close() {
160
+        server.getParser().delChannelMessage(this);
161
+        server.getParser().delChannelTopic(this);
162
+        server.getParser().delChannelGotNames(this);
163
+        server.getParser().delChannelJoin(this);
164
+        server.getParser().delChannelPart(this);
165
+        server.getParser().delChannelQuit(this);
166
+        server.getParser().delChannelKick(this);
167
+        server.getParser().delChannelAction(this);
168
+        
169
+        frame.setVisible(false);
170
+        MainFrame.getMainFrame().delChild(frame);
171
+        frame = null;
172
+        server = null;
173
+    }
158 174
     
159 175
 }

+ 20
- 11
src/uk/org/ownage/dmdirc/Raw.java View File

@@ -31,7 +31,7 @@ import uk.org.ownage.dmdirc.ui.ServerFrame;
31 31
  * received to/from the server)
32 32
  * @author chris
33 33
  */
34
-public class Raw {
34
+public class Raw implements IRCParser.IDataIn, IRCParser.IDataOut {
35 35
     
36 36
     /**
37 37
      * The server object that's being monitored
@@ -54,17 +54,26 @@ public class Raw {
54 54
         
55 55
         MainFrame.getMainFrame().addChild(frame);
56 56
         
57
-        server.getParser().addDataIn(new IRCParser.IDataIn() {
58
-            public void onDataIn(IRCParser tParser, String sData) {
59
-                Raw.this.frame.addLine("<<< "+sData);
60
-            }
61
-        });
57
+        server.getParser().addDataIn(this);
58
+        server.getParser().addDataOut(this);
59
+    }
60
+
61
+    void close() {
62
+        server.getParser().delDataIn(this);
63
+        server.getParser().delDataOut(this);
62 64
         
63
-        server.getParser().addDataOut(new IRCParser.IDataOut() {
64
-            public void onDataOut(IRCParser tparser, String sData, boolean fromParser) {
65
-                Raw.this.frame.addLine(">>> "+sData);
66
-            }
67
-        });
65
+        frame.setVisible(false);
66
+        MainFrame.getMainFrame().delChild(frame);
67
+        frame = null;
68
+        server = null;
69
+    }
70
+
71
+    public void onDataIn(IRCParser tParser, String sData) {
72
+        frame.addLine("<<< "+sData);
73
+    }
74
+
75
+    public void onDataOut(IRCParser tParser, String sData, boolean bFromParser) {
76
+        frame.addLine(">>> "+sData);
68 77
     }
69 78
     
70 79
 }

+ 41
- 16
src/uk/org/ownage/dmdirc/Server.java View File

@@ -57,6 +57,8 @@ public class Server implements IRCParser.IChannelSelfJoin, IRCParser.IErrorInfo
57 57
      */
58 58
     private IRCParser parser;
59 59
     
60
+    private Raw raw;
61
+    
60 62
     /**
61 63
      * Creates a new instance of Server
62 64
      * @param server The hostname/ip of the server to connect to
@@ -73,15 +75,15 @@ public class Server implements IRCParser.IChannelSelfJoin, IRCParser.IErrorInfo
73 75
         MainFrame.getMainFrame().addChild(frame);
74 76
         
75 77
         frame.addLine("Connecting to "+server+":"+port);
76
-              
78
+        
77 79
         parser = new IRCParser(new ServerInfo(server, port, password));
78 80
         
79 81
         parser.addChannelSelfJoin(this);
80 82
         parser.addErrorInfo(this);
81
-                
82
-        Raw raw = new Raw(this);
83
-              
84
-        try {           
83
+        
84
+        raw = new Raw(this);
85
+        
86
+        try {
85 87
             Thread thread = new Thread(parser);
86 88
             thread.start();
87 89
         } catch (Exception ex) {
@@ -89,14 +91,6 @@ public class Server implements IRCParser.IChannelSelfJoin, IRCParser.IErrorInfo
89 91
         }
90 92
     }
91 93
     
92
-    /**
93
-     * Called on destruction, the server unregisters itself with the ServerManager
94
-     * @throws java.lang.Throwable ...
95
-     */
96
-    protected void finalize() throws Throwable {
97
-        ServerManager.getServerManager().unregisterServer(this);
98
-    }
99
-    
100 94
     /**
101 95
      * Retrieves the parser used for this connection
102 96
      * @return IRCParser this connection's parser
@@ -108,15 +102,46 @@ public class Server implements IRCParser.IChannelSelfJoin, IRCParser.IErrorInfo
108 102
     public void addLine(String line) {
109 103
         frame.addLine(line);
110 104
     }
111
-
105
+    
106
+    public void close(String reason) {
107
+        // Unregister parser callbacks
108
+        parser.delChannelSelfJoin(this);
109
+        parser.delErrorInfo(this);        
110
+        // Disconnect from the server
111
+        disconnect(reason);
112
+        // Unregister ourselves with the server manager
113
+        ServerManager.getServerManager().unregisterServer(this);
114
+        // Close all channel windows
115
+        closeChannels();
116
+        // Close the raw window
117
+        raw.close();
118
+        // Close our own window
119
+        frame.setVisible(false);
120
+        MainFrame.getMainFrame().delChild(frame);
121
+        frame = null;
122
+        // Ditch the parser
123
+        parser = null;
124
+    }
125
+    
126
+    public void disconnect(String reason) {
127
+        parser.quit(reason);
128
+    }
129
+    
130
+    private void closeChannels() {
131
+        for (Channel channel : channels.values()) {
132
+            channel.close();
133
+            channels.remove(channel);
134
+        }
135
+    }
136
+    
112 137
     private void addChannel(ChannelInfo chan) {
113 138
         channels.put(chan.getName(), new Channel(this, chan));
114 139
     }
115
-
140
+    
116 141
     public void onChannelSelfJoin(IRCParser tParser, ChannelInfo cChannel) {
117 142
         addChannel(cChannel);
118 143
     }
119
-
144
+    
120 145
     public void onErrorInfo(IRCParser tParser, ParserError errorInfo) {
121 146
         ErrorLevel errorLevel;
122 147
         if (errorInfo.isFatal()) {

+ 13
- 1
src/uk/org/ownage/dmdirc/ServerManager.java View File

@@ -78,9 +78,21 @@ public class ServerManager {
78 78
      * @param message The quit message to send to the IRC servers
79 79
      */
80 80
     public void disconnectAll(String message) {
81
-        throw new UnsupportedOperationException("Not implemented yet");
81
+        for (Server server : servers) {
82
+            server.disconnect(message);
83
+        }
82 84
     }
83 85
     
86
+    /**
87
+     * Closes all servers with the specified quit message
88
+     * @param message The quit message to send to the IRC servers
89
+     */
90
+    public void closeAll(String message) {
91
+        for (Server server : servers) {
92
+            server.close(message);
93
+        }
94
+    }    
95
+    
84 96
     /**
85 97
      * Returns the number of servers that are registered with the manager
86 98
      * @return number of registered servers

+ 5
- 0
src/uk/org/ownage/dmdirc/ui/MainFrame.java View File

@@ -89,6 +89,10 @@ public class MainFrame extends javax.swing.JFrame {
89 89
         desktopPane.add(frame);
90 90
     }
91 91
     
92
+    public void delChild(JInternalFrame frame) {
93
+        desktopPane.remove(frame);
94
+    }    
95
+    
92 96
     /**
93 97
      * Returns the JInternalFrame that is currently active
94 98
      * @return The active JInternalFrame
@@ -171,6 +175,7 @@ public class MainFrame extends javax.swing.JFrame {
171 175
         );
172 176
         pack();
173 177
     }// </editor-fold>//GEN-END:initComponents
178
+
174 179
     
175 180
     // Variables declaration - do not modify//GEN-BEGIN:variables
176 181
     private javax.swing.JDesktopPane desktopPane;

Loading…
Cancel
Save