diff options
author | Yana Stamcheva <yana@jitsi.org> | 2013-01-29 21:56:43 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2013-01-29 21:56:43 +0000 |
commit | f50c63f264321462d3c3ef800ecceb7b87936599 (patch) | |
tree | 8f30a826253432190f20c593e1dc216c880b7821 /src/net/java/sip/communicator/util | |
parent | 0048d0bdd75a1e796a418f346868cc9bd49725ef (diff) | |
download | jitsi-f50c63f264321462d3c3ef800ecceb7b87936599.zip jitsi-f50c63f264321462d3c3ef800ecceb7b87936599.tar.gz jitsi-f50c63f264321462d3c3ef800ecceb7b87936599.tar.bz2 |
Moves CallRenderer and CallPeerRenderer interfaces to service gui. Moves the CallPeerAdapter class to the utility package.
Diffstat (limited to 'src/net/java/sip/communicator/util')
-rw-r--r-- | src/net/java/sip/communicator/util/call/CallPeerAdapter.java | 205 | ||||
-rw-r--r-- | src/net/java/sip/communicator/util/util.manifest.mf | 4 |
2 files changed, 208 insertions, 1 deletions
diff --git a/src/net/java/sip/communicator/util/call/CallPeerAdapter.java b/src/net/java/sip/communicator/util/call/CallPeerAdapter.java new file mode 100644 index 0000000..1aad340 --- /dev/null +++ b/src/net/java/sip/communicator/util/call/CallPeerAdapter.java @@ -0,0 +1,205 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.util.call; + +import java.beans.*; + +import net.java.sip.communicator.service.gui.call.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.protocol.event.*; + +import org.jitsi.service.protocol.event.*; + +/** + * <tt>CallPeerAdapter</tt> implements common <tt>CallPeer</tt> related + * listeners in order to facilitate the task of implementing + * <tt>CallPeerRenderer</tt>. + * + * @author Yana Stamcheva + * @author Lyubomir Marinov + */ +public class CallPeerAdapter + extends net.java.sip.communicator.service.protocol.event.CallPeerAdapter + implements CallPeerSecurityListener, + PropertyChangeListener +{ + /** + * The <tt>CallPeer</tt> which is depicted by {@link #renderer}. + */ + private final CallPeer peer; + + /** + * The <tt>CallPeerRenderer</tt> which is facilitated by this instance. + */ + private final CallPeerRenderer renderer; + + /** + * Initializes a new <tt>CallPeerAdapter</tt> instance which is to listen to + * a specific <tt>CallPeer</tt> on behalf of a specific + * <tt>CallPeerRenderer</tt>. The new instance adds itself to the specified + * <tt>CallPeer</tt> as a listener for each of the implemented listener + * types. + * + * @param peer the <tt>CallPeer</tt> which the new instance is to listen to + * on behalf of the specified <tt>renderer</tt> + * @param renderer the <tt>CallPeerRenderer</tt> which is to be facilitated + * by the new instance + */ + public CallPeerAdapter(CallPeer peer, CallPeerRenderer renderer) + { + this.peer = peer; + this.renderer = renderer; + + this.peer.addCallPeerListener(this); + this.peer.addCallPeerSecurityListener(this); + this.peer.addPropertyChangeListener(this); + } + + /** + * Removes the listeners implemented by this instance from the associated + * <tt>CallPeer</tt> and prepares it for garbage collection. + */ + public void dispose() + { + peer.removeCallPeerListener(this); + peer.removeCallPeerSecurityListener(this); + peer.removePropertyChangeListener(this); + } + + /** + * {@inheritDoc} + */ + @Override + public void peerDisplayNameChanged(CallPeerChangeEvent ev) + { + if (peer.equals(ev.getSourceCallPeer())) + renderer.setPeerName((String) ev.getNewValue()); + } + + /** + * {@inheritDoc} + */ + @Override + public void peerImageChanged(CallPeerChangeEvent ev) + { + if (peer.equals(ev.getSourceCallPeer())) + renderer.setPeerImage((byte[]) ev.getNewValue()); + } + + /** + * {@inheritDoc} + */ + @Override + public void peerStateChanged(CallPeerChangeEvent ev) + { + CallPeer sourcePeer = ev.getSourceCallPeer(); + + if (!sourcePeer.equals(peer)) + return; + + CallPeerState newState = (CallPeerState) ev.getNewValue(); + CallPeerState oldState = (CallPeerState) ev.getOldValue(); + + String newStateString = sourcePeer.getState().getLocalizedStateString(); + + if (newState == CallPeerState.CONNECTED) + { + if (!CallPeerState.isOnHold(oldState)) + { + if (!renderer.getCallRenderer().isCallTimerStarted()) + renderer.getCallRenderer().startCallTimer(); + } + else + { + renderer.setOnHold(false); + renderer.getCallRenderer().updateHoldButtonState(); + } + } + else if (newState == CallPeerState.DISCONNECTED) + { + // The call peer should be already removed from the call + // see CallPeerRemoved + } + else if (newState == CallPeerState.FAILED) + { + // The call peer should be already removed from the call + // see CallPeerRemoved + } + else if (CallPeerState.isOnHold(newState)) + { + renderer.setOnHold(true); + renderer.getCallRenderer().updateHoldButtonState(); + } + + renderer.setPeerState(oldState, newState, newStateString); + + String reasonString = ev.getReasonString(); + if (reasonString != null) + renderer.setErrorReason(reasonString); + } + + /** + * {@inheritDoc} + */ + public void propertyChange(PropertyChangeEvent ev) + { + String propertyName = ev.getPropertyName(); + + if (propertyName.equals(CallPeer.MUTE_PROPERTY_NAME)) + { + boolean mute = (Boolean) ev.getNewValue(); + + renderer.setMute(mute); + } + } + + /** + * {@inheritDoc} + * + * <tt>CallPeerAdapter</tt> does nothing. + */ + public void securityMessageRecieved(CallPeerSecurityMessageEvent ev) + { + } + + /** + * {@inheritDoc} + */ + public void securityNegotiationStarted( + CallPeerSecurityNegotiationStartedEvent ev) + { + if (peer.equals(ev.getSource())) + renderer.securityNegotiationStarted(ev); + } + + /** + * {@inheritDoc} + */ + public void securityOff(CallPeerSecurityOffEvent ev) + { + if (peer.equals(ev.getSource())) + renderer.securityOff(ev); + } + + /** + * {@inheritDoc} + */ + public void securityOn(CallPeerSecurityOnEvent ev) + { + if (peer.equals(ev.getSource())) + renderer.securityOn(ev); + } + + /** + * {@inheritDoc} + */ + public void securityTimeout(CallPeerSecurityTimeoutEvent ev) + { + if (peer.equals(ev.getSource())) + renderer.securityTimeout(ev); + } +}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/util/util.manifest.mf b/src/net/java/sip/communicator/util/util.manifest.mf index 11b391a..f55306f 100644 --- a/src/net/java/sip/communicator/util/util.manifest.mf +++ b/src/net/java/sip/communicator/util/util.manifest.mf @@ -30,6 +30,7 @@ Import-Package: com.sun.awt, javax.xml.transform.stream, net.java.sip.communicator.util, net.java.sip.communicator.service.gui, + net.java.sip.communicator.service.gui.call, net.java.sip.communicator.service.resources, net.java.sip.communicator.service.keybindings, net.java.sip.communicator.service.msghistory, @@ -59,4 +60,5 @@ Export-Package: net.java.sip.communicator.util, net.java.sip.communicator.util.launchutils, net.java.sip.communicator.util.skin, net.java.sip.communicator.util.xml, - net.java.sip.communicator.util.account
\ No newline at end of file + net.java.sip.communicator.util.account, + net.java.sip.communicator.util.call
\ No newline at end of file |