KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > chat > Connection


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.chat;
19
20 import javax.swing.event.EventListenerList JavaDoc;
21
22 import org.columba.chat.config.api.IAccount;
23 import org.columba.chat.conn.api.ConnectionChangedEvent;
24 import org.columba.chat.conn.api.IConnection;
25 import org.columba.chat.conn.api.IConnectionChangedListener;
26 import org.jivesoftware.smack.XMPPConnection;
27
28 public class Connection implements IConnection {
29
30     private STATUS status;
31
32     private EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
33
34     public static XMPPConnection XMPPConnection;
35
36     public Connection() {
37         super();
38     }
39
40     public STATUS getStatus() {
41         return status;
42     }
43
44     public void setStatus(STATUS status) {
45         this.status = status;
46
47         fireSelectionChanged(MainInterface.config.getAccount(), status);
48     }
49
50     /**
51      * Adds a listener.
52      */

53     public void addConnectionChangedListener(IConnectionChangedListener listener) {
54         listenerList.add(IConnectionChangedListener.class, listener);
55     }
56
57     /**
58      * Removes a previously registered listener.
59      */

60     public void removeConnectionChangedListener(
61             IConnectionChangedListener listener) {
62         listenerList.remove(IConnectionChangedListener.class, listener);
63     }
64
65     /**
66      * Propagates an event to all registered listeners notifying them that the
67      * connection status has changed
68      */

69     public void fireSelectionChanged(IAccount account, STATUS status) {
70         ConnectionChangedEvent e = new ConnectionChangedEvent(this, account, status);
71         // Guaranteed to return a non-null array
72
Object JavaDoc[] listeners = listenerList.getListenerList();
73
74         // Process the listeners last to first, notifying
75
// those that are interested in this event
76
for (int i = listeners.length - 2; i >= 0; i -= 2) {
77             if (listeners[i] == IConnectionChangedListener.class) {
78                 ((IConnectionChangedListener) listeners[i + 1])
79                         .connectionChanged(e);
80             }
81         }
82     }
83
84 }
85
Popular Tags