1 package org.columba.chat; 19 20 import javax.swing.event.EventListenerList ; 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 listenerList = new EventListenerList (); 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 53 public void addConnectionChangedListener(IConnectionChangedListener listener) { 54 listenerList.add(IConnectionChangedListener.class, listener); 55 } 56 57 60 public void removeConnectionChangedListener( 61 IConnectionChangedListener listener) { 62 listenerList.remove(IConnectionChangedListener.class, listener); 63 } 64 65 69 public void fireSelectionChanged(IAccount account, STATUS status) { 70 ConnectionChangedEvent e = new ConnectionChangedEvent(this, account, status); 71 Object [] listeners = listenerList.getListenerList(); 73 74 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 |