[sip-comm-dev] Re: svn commit: r6732 - trunk/src/net/java/sip/communicator: impl/protocol/jabber service/protocol service/protocol/event


#1

Hi Damien,

Just a couple of mild reminders:

- The @Override annotation on interface method implementations
generates compile errors on JDK 1.5, I guess it is allowed in JDK 1.6.
Since we target 1.5 and Mac OS X Leopard defaults to it, we should
only use it when overriding actual super method definitions and not
when implementing interfaces.

- We'd like to have Javadocs on everything including constructors,
methods implementing interfaces or overriding super definitions, the
logger field, etc. When you have the time and you feel like it, could
you please take care of them in your code?

Regards,
Lubomir

ยทยทยท

On Sat, Feb 6, 2010 at 7:21 PM, <ysaak@dev.java.net> wrote:

Author: ysaak
Date: 2010-02-06 17:21:54+0000
New Revision: 6732

Added:
trunk/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetAvatarJabberImpl.java
trunk/src/net/java/sip/communicator/service/protocol/AbstractOperationSetAvatar.java
trunk/src/net/java/sip/communicator/service/protocol/OperationSetAvatar.java
trunk/src/net/java/sip/communicator/service/protocol/event/AvatarEvent.java
trunk/src/net/java/sip/communicator/service/protocol/event/AvatarListener.java

Log:
- New operation set to change user avatar
- Implementation for XMPP

Added: trunk/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetAvatarJabberImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetAvatarJabberImpl.java?view=auto&rev=6732

--- (empty file)
+++ trunk/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetAvatarJabberImpl.java 2010-02-06 17:21:54+0000
@@ -0,0 +1,30 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.impl.protocol.jabber;
+
+import net.java.sip.communicator.service.protocol.*;
+
+/**
+ * A simple implementation of the <tt>OperationSetAvatar</tt> interface for the
+ * jabber protocol.
+ *
+ * Actually there isn't any maximum size for the jabber protocol but GoogleTalk
+ * fix it a 96x96.
+ *
+ * @author Damien Roth
+ */
+public class OperationSetAvatarJabberImpl extends
+ AbstractOperationSetAvatar<ProtocolProviderServiceJabberImpl>
+{
+
+ public OperationSetAvatarJabberImpl(
+ ProtocolProviderServiceJabberImpl parentProvider,
+ OperationSetServerStoredAccountInfo accountInfoOpSet)
+ {
+ super(parentProvider, accountInfoOpSet, 96, 96, 0);
+ }
+
+}

Added: trunk/src/net/java/sip/communicator/service/protocol/AbstractOperationSetAvatar.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/service/protocol/AbstractOperationSetAvatar.java?view=auto&rev=6732

--- (empty file)
+++ trunk/src/net/java/sip/communicator/service/protocol/AbstractOperationSetAvatar.java 2010-02-06 17:21:54+0000
@@ -0,0 +1,158 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.protocol;
+
+import java.util.*;
+
+import net.java.sip.communicator.service.protocol.ServerStoredDetails.*;
+import net.java.sip.communicator.service.protocol.event.*;
+import net.java.sip.communicator.util.Logger;
+
+/**
+ * Represents a default implementation of {@link OperationSetAvatar} in order to
+ * make it easier for implementers to provide complete solutions while focusing
+ * on implementation-specific details.
+ *
+ * @author Damien Roth
+ */
+public abstract class AbstractOperationSetAvatar<T extends ProtocolProviderService>
+ implements OperationSetAvatar
+{
+ private static Logger logger = Logger
+ .getLogger(AbstractOperationSetAvatar.class);
+
+ /**
+ * The maximum avatar width. Zero mean no maximum
+ */
+ private int maxWidth = 0;
+
+ /**
+ * The maximum avatar height. Zero mean no maximum
+ */
+ private int maxHeight = 0;
+
+ /**
+ * The maximum avatar size. Zero mean no maximum
+ */
+ private int maxSize = 0;
+
+ /**
+ * The provider that created us.
+ */
+ private T parentProvider;
+
+ private OperationSetServerStoredAccountInfo accountInfoOpSet;
+
+ /**
+ * The list of listeners interested in <tt>AvatarEvent</tt>s.
+ */
+ private List<AvatarListener> avatarListeners = new ArrayList<AvatarListener>();
+
+ protected AbstractOperationSetAvatar(T parentProvider,
+ OperationSetServerStoredAccountInfo accountInfoOpSet, int maxWidth,
+ int maxHeight, int maxSize)
+ {
+ this.parentProvider = parentProvider;
+ this.accountInfoOpSet = accountInfoOpSet;
+
+ this.maxWidth = maxWidth;
+ this.maxHeight = maxHeight;
+ this.maxSize = maxSize;
+ }
+
+ @Override
+ public int getMaxWidth()
+ {
+ return this.maxWidth;
+ }
+
+ @Override
+ public int getMaxHeight()
+ {
+ return this.maxHeight;
+ }
+
+ @Override
+ public int getMaxSize()
+ {
+ return this.maxSize;
+ }
+
+ @Override
+ public byte[] getAvatar()
+ {
+ return AccountInfoUtils.getImage(this.accountInfoOpSet);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void setAvatar(byte[] avatar)
+ {
+ ImageDetail oldDetail = null;
+ ImageDetail newDetail = new ImageDetail("avatar", avatar);
+
+ Iterator<GenericDetail> imageDetails = this.accountInfoOpSet
+ .getDetails(ServerStoredDetails.ImageDetail.class);
+ if (imageDetails.hasNext())
+ {
+ oldDetail = (ImageDetail) imageDetails.next();
+ }
+
+ try
+ {
+ if (oldDetail == null)
+ this.accountInfoOpSet.addDetail(newDetail);
+ else
+ this.accountInfoOpSet.replaceDetail(oldDetail, newDetail);
+ } catch (OperationFailedException e)
+ {
+ logger.warn("Unable to set new avatar", e);
+ }
+
+ fireAvatarChanged(avatar);
+ }
+
+ @Override
+ public void addAvatarListener(AvatarListener listener)
+ {
+ synchronized (this.avatarListeners)
+ {
+ if (!this.avatarListeners.contains(listener))
+ this.avatarListeners.add(listener);
+ }
+ }
+
+ @Override
+ public void removeAvatarListener(AvatarListener listener)
+ {
+ synchronized (this.avatarListeners)
+ {
+ if (this.avatarListeners.contains(listener))
+ this.avatarListeners.remove(listener);
+ }
+ }
+
+ /**
+ * Notifies all registered listeners of the new event.
+ *
+ * @param newAvatar
+ * the new avatar
+ */
+ protected void fireAvatarChanged(byte[] newAvatar)
+ {
+ AvatarEvent event = new AvatarEvent(this, this.parentProvider,
+ newAvatar);
+
+ Collection<AvatarListener> listeners;
+ synchronized (this.avatarListeners)
+ {
+ listeners = new ArrayList<AvatarListener>(this.avatarListeners);
+ }
+
+ for (AvatarListener l : listeners)
+ l.avatarChanged(event);
+ }
+}

Added: trunk/src/net/java/sip/communicator/service/protocol/OperationSetAvatar.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/service/protocol/OperationSetAvatar.java?view=auto&rev=6732

--- (empty file)
+++ trunk/src/net/java/sip/communicator/service/protocol/OperationSetAvatar.java 2010-02-06 17:21:54+0000
@@ -0,0 +1,77 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.protocol;
+
+import net.java.sip.communicator.service.protocol.event.AvatarListener;
+
+/**
+ * This interface is an extension of the operation set, meant to be implemented
+ * by protocols that support user avatar.
+ *
+ * @author Damien Roth
+ */
+public interface OperationSetAvatar extends OperationSet
+{
+ /**
+ * Returns the maximum width of the avatar. This method should return 0
+ * (zero) if there is no maximum width.
+ *
+ * @return the maximum width of the avatar
+ */
+ public int getMaxWidth();
+
+ /**
+ * Returns the maximum height of the avatar. This method should return 0
+ * (zero) if there is no maximum height.
+ *
+ * @return the maximum height of the avatar
+ */
+ public int getMaxHeight();
+
+ /**
+ * Returns the maximum size of the avatar. This method should return 0
+ * (zero) if there is no maximum size.
+ *
+ * @return the maximum size of the avatar
+ */
+ public int getMaxSize();
+
+ /**
+ * Defines a new avatar for this protocol
+ *
+ * @param avatar
+ * the new avatar
+ */
+ public void setAvatar(byte[] avatar);
+
+ /**
+ * Returns the current avatar of this protocol. May return null if the
+ * account has no avatar
+ *
+ * @param avatar
+ * the new avatar
+ */
+ public byte[] getAvatar();
+
+ /**
+ * Registers a listener that would receive events upon avatar changes.
+ *
+ * @param listener
+ * a AvatarListener that would receive events upon avatar
+ * changes.
+ */
+ public void addAvatarListener(AvatarListener listener);
+
+ /**
+ * Removes the specified group change listener so that it won't receive any
+ * further events.
+ *
+ * @param listener
+ * the AvatarListener to remove
+ */
+ public void removeAvatarListener(AvatarListener listener);
+}

Added: trunk/src/net/java/sip/communicator/service/protocol/event/AvatarEvent.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/service/protocol/event/AvatarEvent.java?view=auto&rev=6732

--- (empty file)
+++ trunk/src/net/java/sip/communicator/service/protocol/event/AvatarEvent.java 2010-02-06 17:21:54+0000
@@ -0,0 +1,89 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.protocol.event;
+
+import java.util.*;
+
+import net.java.sip.communicator.service.protocol.*;
+
+/**
+ * Instances of this class represent a change avatar of a protocol
+ *
+ * @author Damien Roth
+ */
+public class AvatarEvent
+ extends EventObject
+{
+ /**
+ * The new avatar
+ */
+ private byte[] newAvatar;
+
+ /**
+ * The provider that has generated the event.
+ */
+ private ProtocolProviderService sourceProvider;
+
+ /**
+ * Creates an event instance indicating that the specified protocol
+ * has changed its avatar to <tt>newAvatar</tt>.
+ *
+ * @param sourceOp the operation set that generated this event
+ * @param sourceProvider the protocol provider that the contact belongs to
+ * @param newAvatar the new avatar
+ */
+ public AvatarEvent(OperationSetAvatar sourceOp,
+ ProtocolProviderService sourceProvider, byte[] newAvatar)
+ {
+ super(sourceOp);
+ this.sourceProvider = sourceProvider;
+ this.newAvatar = newAvatar;
+ }
+
+ /**
+ * Returns the provider that the source belongs to.
+ *
+ * @return the provider that the source belongs to.
+ */
+ public ProtocolProviderService getSourceProvider()
+ {
+ return this.sourceProvider;
+ }
+
+ /**
+ * Returns the new avatar
+ * @return the new avatar
+ */
+ public byte[] getNewAvatar()
+ {
+ return this.newAvatar;
+ }
+
+ /**
+ * Returns the <tt>OperationSetAvatar</tt> instance that is the source
+ * of this event.
+ *
+ * @return the <tt>OperationSetAvatar</tt> instance that is the source
+ * of this event.
+ */
+ public OperationSetAvatar getSourceAvatarOperationSet()
+ {
+ return (OperationSetAvatar) getSource();
+ }
+
+ /**
+ * Returns a String representation of this AvatarEvent
+ *
+ * @return A a <tt>java.lang.String</tt> representation of this AvatarEvent.
+ */
+ public String toString()
+ {
+ StringBuffer buff = new StringBuffer("AvatarEvent-[ Provider=");
+ buff.append(getSourceProvider()).append("]");
+ return buff.toString();
+ }
+}

Added: trunk/src/net/java/sip/communicator/service/protocol/event/AvatarListener.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/service/protocol/event/AvatarListener.java?view=auto&rev=6732

--- (empty file)
+++ trunk/src/net/java/sip/communicator/service/protocol/event/AvatarListener.java 2010-02-06 17:21:54+0000
@@ -0,0 +1,32 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.protocol.event;
+
+import java.util.*;
+
+/**
+ * The listener interface for receiving geolocation events. The class that is
+ * interested in processing a avatar event implements this interface, and the
+ * object created with that class is registered with the avatar operation set,
+ * using its <code>addAvatarListener</code> method. When a avatar event occurs,
+ * that object's <code>avatarChanged</code> method is invoked.
+ *
+ * @see AvatarEvent
+ *
+ * @author Damien Roth
+ */
+public interface AvatarListener
+ extends EventListener
+{
+ /**
+ * Called whenever a new avatar is defined for one of the protocols that we
+ * have subscribed for.
+ *
+ * @param event the event containg the new image
+ */
+ public void avatarChanged(AvatarEvent event);
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net