[sip-comm-cvs] CVS update: /sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/conference/, /sip-communicator/src/net/java/sip/communicator/impl/gu...

yanas at dev.java.net yanas at dev.java.net
Thu May 3 16:22:23 CEST 2007


User: yanas   
Date: 2007-05-03 14:22:23+0000
Added:
   sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/ChatContact.java

Modified:
   sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatPanel.java
   sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/ChatContactListPanel.java
   sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/MetaContactChatPanel.java
   sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/ChatContactPanel.java
   sip-communicator/src/net/java/sip/communicator/impl/gui/i18n/messages.properties

Log:
 multi user chat enhancements

File Changes:

Directory: /sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/conference/
=========================================================================================

File [changed]: ConferenceChatPanel.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatPanel.java?r1=1.7&r2=1.8
Delta lines:  +5 -1
-------------------
--- ConferenceChatPanel.java	2007-04-27 15:43:45+0000	1.7
+++ ConferenceChatPanel.java	2007-05-03 14:22:20+0000	1.8
@@ -54,7 +54,11 @@
 
         for (int i = 0; i < membersList.size(); i ++)
         {
-            getChatContactListPanel().addContact((Contact)membersList.get(i));
+            ChatContact chatContact
+                = new ChatContact((ChatRoomMember)membersList.get(i));
+            
+            getChatContactListPanel()
+                .addContact(chatContact);
         }
 
         this.chatRoom.addMessageListener(this);

Directory: /sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/
==============================================================================

File [added]: ChatContact.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/ChatContact.java?rev=1.1&content-type=text/vnd.viewcvs-markup
Added lines: 213
----------------
/*
 * 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.gui.main.chat;

import java.awt.*;
import java.util.*;

import javax.swing.*;

import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;

/**
 * The <tt>ChatContact</tt> is a wrapping class for the <tt>Contact</tt> and
 * <tt>ChatRoomMember</tt> interface.
 * 
 * @author Yana Stamcheva
 */
public class ChatContact
{
    private Logger logger = Logger.getLogger(ChatContact.class);
    
    private String name;
     
    private String address;
    
    private ImageIcon image;
    
    private ProtocolProviderService protocolProvider;
    
    private PresenceStatus presenceStatus;
    
    private boolean isMultiChatContact;
    
    private Object sourceContact;
    
    /**
     * Creates an instance of <tt>ChatContact</tt> by passing to it the
     * <tt>Contact</tt> for which it is created.
     * 
     * @param contact the <tt>Contact</tt> for which this <tt>ChatContact</tt>
     * is created
     */
    public ChatContact(Contact contact)
    {
        this(null, contact);
    }
    
    /**
     * Creates an instance of <tt>ChatContact</tt> by passing to it the
     * corresponding <tt>MetaContact</tt> and <tt>Contact</tt>.
     * 
     * @param metaContact the <tt>MetaContact</tt> encapsulating the given
     * <tt>Contact</tt>
     * @param contact the <tt>Contact</tt> for which this <tt>ChatContact</tt>
     * is created
     */
    public ChatContact(MetaContact metaContact, Contact contact)
    {
        this.sourceContact = contact;
        this.address = contact.getAddress();
        this.isMultiChatContact = false;
        this.protocolProvider = contact.getProtocolProvider();
        
        if(metaContact != null)
            name = metaContact.getDisplayName();
        else
            name = contact.getDisplayName();
        
    }
    
    /**
     * Creates an instance of <tt>ChatContact</tt> by passing to it the
     * <tt>ChatRoomMember</tt> for which it is created.
     * 
     * @param chatRoomMember the <tt>ChatRoomMember</tt> for which this
     * <tt>ChatContact</tt> is created.
     */
    public ChatContact(ChatRoomMember chatRoomMember)
    {
        this.sourceContact = chatRoomMember;
        this.name = chatRoomMember.getName();
        this.address = chatRoomMember.getContactAddress();
        this.isMultiChatContact = true;
        this.protocolProvider = chatRoomMember.getProtocolProvider();
    }

    /**
     * Returns the contact identifier.
     * 
     * @return the contact identifier
     */
    public String getAddress()
    {
        return address;
    }

    /**
     * Returns the contact name.
     * 
     * @return the contact name
     */  
    public String getName()
    {
        return name;
    }
    
    /**
     * Returns the current presence status for single user chat contacts and
     * null for multi user chat contacts.
     * 
     * @return the current presence status for single user chat contacts and
     * null for multi user chat contacts
     */
    public PresenceStatus getPresenceStatus()
    {
        if(!isMultiChatContact)
            return ((Contact)sourceContact).getPresenceStatus();
        
        return null;
    }
    
    /**
     * Returns the <tt>ProtocolProviderService</tt> of the contact.
     * 
     * @return the <tt>ProtocolProviderService</tt> of the contact
     */
    public ProtocolProviderService getProtocolProvider()
    {
        return protocolProvider;
    }
    
    /**
     * Returns the source contact. It could be an instance of <tt>Contact</tt>
     * or <tt>ChatRoomMember</tt> interface.
     * 
     * @return the source contact
     */
    public Object getSourceContact()
    {
        return sourceContact;
    }
    
    /**
     * Returns the avatar image corresponding to the source contact. In the case
     * of multi user chat contact returns null.
     * 
     * @return the avatar image corresponding to the source contact. In the case
     * of multi user chat contact returns null
     */
    public ImageIcon getImage()
    {
        byte[] contactImage = null;
        
        if(!(sourceContact instanceof Contact))
            return null;
        
        Contact contact = (Contact)sourceContact;
        
        MetaContact metaContact = GuiActivator.getMetaContactListService()
            .findMetaContactByContact(contact);
        
        if(metaContact != null)
        {
            Iterator i = metaContact.getContacts();
            
            while(i.hasNext())
            {
                Contact protoContact = (Contact) i.next();
                
                try
                {
                    contactImage = protoContact.getImage();
                }
                catch (Exception ex)
                {
                    logger.error("Failed to load contact photo.", ex);
                }
                
                if(contactImage != null && contactImage.length > 0)
                    break;
            }
        }
        else if(contact != null)
        {
            try
            {
                contactImage = contact.getImage();
            }
            catch (Exception ex)
            {
                logger.error("Failed to load contact photo.", ex);
            }
        }
        
        if(contactImage != null)
        {
            Image image = ImageLoader.getBytesInImage(contactImage);
            
            return new ImageIcon(image.getScaledInstance(            
                            40, 45, Image.SCALE_SMOOTH));
        }
        else
            return null;
    }
}

File [changed]: ChatContactListPanel.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/ChatContactListPanel.java?r1=1.1&r2=1.2
Delta lines:  +34 -106
----------------------
--- ChatContactListPanel.java	2007-03-12 17:38:30+0000	1.1
+++ ChatContactListPanel.java	2007-05-03 14:22:21+0000	1.2
@@ -14,8 +14,6 @@
 
 import net.java.sip.communicator.impl.gui.customcontrols.*;
 import net.java.sip.communicator.impl.gui.utils.*;
-import net.java.sip.communicator.service.contactlist.*;
-import net.java.sip.communicator.service.protocol.*;
 
 /**
  * The <tt>ChatContactListPanel</tt> is the panel added on the right of the
@@ -44,7 +42,7 @@
     
     private JPanel contactsPanel = new JPanel();
     
-    private Hashtable contacts = new Hashtable(); 
+    private Hashtable chatContacts = new Hashtable(); 
     
     private ChatPanel chatPanel;
     
@@ -62,46 +60,6 @@
         
         this.setMinimumSize(new Dimension(150, 100));
 
-        this.init();
-    }
-    
-    /**
-     * Adds a simple <tt>Contact</tt> to the list of contacts contained in the
-     * chat.
-     * 
-     * @param contact the <tt>Contact</tt> to be added
-     */
-    public void addContact(Contact contact)
-    {
-        ChatContactPanel chatContactPanel = new ChatContactPanel(
-            chatPanel, contact);
-
-        this.contactsPanel.add(chatContactPanel);
-        
-        this.contacts.put(contact, chatContactPanel);
-    }
-    
-    /**
-     * Adds a <tt>MetaContact</tt> to the list of contacts contained in the chat.
-     *  
-     * @param metaContact the <tt>MetaContact</tt> to be added
-     * @param contact the subcontact which is initially selected
-     */
-    public void addContact(MetaContact metaContact, Contact contact)
-    {
-        ChatContactPanel chatContactPanel = new ChatContactPanel(
-            chatPanel, metaContact, contact);
-
-        this.contactsPanel.add(chatContactPanel);
-        
-        this.contacts.put(metaContact, chatContactPanel);
-    }
-
-    /**
-     * Constructs the <tt>ChatContactListPanel</tt>.
-     */
-    private void init()
-    {
         this.contactsPanel.setLayout(new BoxLayout(this.contactsPanel,
                 BoxLayout.Y_AXIS));
 
@@ -118,88 +76,58 @@
     }
 
     /**
-     * Updates the status icon of the contact in this
-     * <tt>ChatContactListPanel</tt>.
-     * @param contact the <tt>Contact</tt>, which should be updated
+     * Adds a <tt>ChatContact</tt> to the list of contacts contained in the
+     * chat.
+     * 
+     * @param chatContact the <tt>ChatContact</tt> to add
      */
-    public void updateContactStatus(Contact contact)
+    public void addContact(ChatContact chatContact)
     {
-        ChatContactPanel chatContactPanel = null;
-        if(contacts.containsKey(contact))
-        {
-            chatContactPanel = (ChatContactPanel)contacts.get(contact);
-        
-            chatContactPanel.setStatusIcon(contact.getPresenceStatus());        
-        }
-    }
+        ChatContactPanel chatContactPanel = new ChatContactPanel(
+            chatPanel, chatContact);
 
-    /**
-     * Updates the status icon of the contact in this
-     * <tt>ChatContactListPanel</tt>.
-     * @param metaContact the <tt>MetaContact</tt>, which should be updated
-     */
-    public void updateContactStatus(MetaContact metaContact)
-    {
-        ChatContactPanel chatContactPanel = null;        
-        if(contacts.containsKey(metaContact))
-        {
-            chatContactPanel = (ChatContactPanel)contacts.get(metaContact);
+        this.contactsPanel.add(chatContactPanel);
         
-            chatContactPanel.setStatusIcon(
-                metaContact.getDefaultContact().getPresenceStatus());        
-        }
+        this.chatContacts.put(chatContact, chatContactPanel);
     }
 
     /**
-     * Updates the given protocol contact chat panel in the list. Disables or
-     * enable buttons, according to the functionalities supported by this
-     * contact.
+     * In the corresponding <tt>ChatContactPanel</tt> changes the name of the
+     * given <tt>Contact</tt>.
      * 
-     * @param contact the <tt>Contact</tt>, which chat contact panel to update
+     * @param chatContact the <tt>ChatContact</tt> to be renamed
      */
-    public void updateProtocolContact(Contact contact)
+    public void renameContact(ChatContact chatContact)
     {   
         ChatContactPanel chatContactPanel = null;
-        if(contacts.containsKey(contact))
+        if(chatContacts.containsKey(chatContact))
         {
-            chatContactPanel = (ChatContactPanel)contacts.get(contact);
+            chatContactPanel = (ChatContactPanel)chatContacts.get(chatContact);
         
-            chatContactPanel.updateProtocolContact(contact);
+            chatContactPanel.renameContact(chatContact.getName());
         }
     }
 
     /**
-     * In the corresponding <tt>ChatContactPanel</tt> changes the name of the
-     * given <tt>Contact</tt>.
-     * 
-     * @param contact the <tt>Contact</tt>, which has been renamed
+     * Returns the list of <tt>ChatContacts</tt> contained in this container. 
+     * @return the list of <tt>ChatContacts</tt> contained in this container
      */
-    public void renameContact(Contact contact)
+    public Enumeration getChatContacts()
     {
-        ChatContactPanel chatContactPanel = null;
-        if(contacts.containsKey(contact))
-        {
-            chatContactPanel = (ChatContactPanel)contacts.get(contact);
-        
-            chatContactPanel.renameContact(contact.getDisplayName());
-        }        
+        return chatContacts.keys();
     }
  
     /**
-     * In the corresponding <tt>ChatContactPanel</tt> changes the name of the
-     * given <tt>MetaContact</tt>.
+     * Returns the <tt>ChatContactPanel</tt> corresponding to the given
+     * <tt>ChatContact</tt>.
      * 
-     * @param contact the <tt>MetaContact</tt>, which has been renamed
+     * @param chatContact the <tt>ChatContact</tt> to search for.
+     * @return the <tt>ChatContactPanel</tt> corresponding to the given
+     * <tt>ChatContact</tt>
      */
-    public void renameContact(MetaContact contact)
-    {
-        ChatContactPanel chatContactPanel = null;
-        if(contacts.containsKey(contact))
+    public ChatContactPanel getChatContactPanel(ChatContact chatContact)
         {
-            chatContactPanel = (ChatContactPanel)contacts.get(contact);
-        
-            chatContactPanel.renameContact(contact.getDisplayName());
-        }        
+        return (ChatContactPanel) chatContacts.get(chatContact);
     }
 }
 

File [changed]: MetaContactChatPanel.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/MetaContactChatPanel.java?r1=1.3&r2=1.4
Delta lines:  +147 -15
----------------------
--- MetaContactChatPanel.java	2007-04-11 14:15:53+0000	1.3
+++ MetaContactChatPanel.java	2007-05-03 14:22:21+0000	1.4
@@ -16,7 +16,6 @@
 import net.java.sip.communicator.impl.gui.*;
 import net.java.sip.communicator.impl.gui.customcontrols.*;
 import net.java.sip.communicator.impl.gui.i18n.*;
-import net.java.sip.communicator.impl.gui.main.*;
 import net.java.sip.communicator.impl.gui.utils.*;
 import net.java.sip.communicator.service.contactlist.*;
 import net.java.sip.communicator.service.contactlist.event.*;
@@ -35,7 +34,8 @@
 public class MetaContactChatPanel
     extends ChatPanel
     implements  ContactPresenceStatusListener,
-                MetaContactListListener
+                MetaContactListListener,
+                SubscriptionListener
 {
 
     private static final Logger logger = Logger
@@ -72,8 +72,10 @@
 
         this.metaContact = metaContact;
 
+        ChatContact chatContact = new ChatContact(metaContact, protocolContact);
+        
         //Add the contact to the list of contacts contained in this panel
-        getChatContactListPanel().addContact(metaContact, protocolContact);
+        getChatContactListPanel().addContact(chatContact);
         
         //Load the history period, to initialize the firstMessageTimestamp and
         //the lastMessageTimeStamp variables. Used to disable/enable history
@@ -93,9 +95,17 @@
         {
             Contact subContact = (Contact) protocolContacts.next();
             
-            chatWindow.getMainFrame()
-                .getProtocolPresenceOpSet(subContact.getProtocolProvider())
+            Object opSet = subContact.getProtocolProvider()
+                .getOperationSet(OperationSetPersistentPresence.class);
+            
+            if(opSet != null)
+            {
+                ((OperationSetPersistentPresence)opSet)
                 .addContactPresenceStatusListener(this);
+                
+                ((OperationSetPersistentPresence)opSet)
+                    .addSubsciptionListener(this);
+            }
         }
         
         //Obtains the MetaContactListService and adds itself to it as a
@@ -275,22 +285,38 @@
     {   
         Contact sourceContact = evt.getSourceContact();
     
-        MainFrame mainFrame = getChatWindow().getMainFrame();
-        
-        MetaContact sourceMetaContact = mainFrame
-            .getContactList().findMetaContactByContact(sourceContact);
+        MetaContact sourceMetaContact = GuiActivator.getMetaContactListService()
+            .findMetaContactByContact(sourceContact);
     
         if (sourceMetaContact != null && metaContact.equals(sourceMetaContact))
         {   
+            // Update the status of the given contact in the "send via" selector
+            // box.
             contactSelectorBox.updateContactStatus(sourceContact);
             
+            // Update the status of the source meta contact in the contact details
+            // panel on the right.
+            
+            if(sourceMetaContact != null
+                    && sourceMetaContact.getDefaultContact().equals(sourceContact))
+            {
+                ChatContact chatContact
+                    = findChatContactByMetaContact(sourceMetaContact);
+            
+                ChatContactPanel chatContactPanel
+                    = getChatContactListPanel()
+                        .getChatContactPanel(chatContact);
+                
+                chatContactPanel.setStatusIcon(
+                    chatContact.getPresenceStatus());
+            }
+            
             PresenceStatus status = contactSelectorBox
                 .getSelectedProtocolContact().getPresenceStatus();
 
-            getChatContactListPanel().updateContactStatus(metaContact);
-
+            // Show a status message to the user.
             String message = getChatConversationPanel().processMessage(
-                this.metaContact.getDisplayName(),
+                sourceContact.getAddress(),
                 new Date(System.currentTimeMillis()),
                 Constants.SYSTEM_MESSAGE,
                 Messages.getI18NString("statusChangedChatMessage",
@@ -393,7 +419,10 @@
         
         if(evt.getSourceMetaContact().equals(metaContact))
         {
-            getChatContactListPanel().renameContact(evt.getSourceMetaContact());
+            ChatContact chatContact
+                = findChatContactByMetaContact(evt.getSourceMetaContact());
+            
+            getChatContactListPanel().renameContact(chatContact);
 
             getChatWindow().setTabTitle(this, newName);
 
@@ -645,8 +674,111 @@
         }
     }
 
+    /**
+     * Returns the <tt>MetaContact</tt> corresponding to the chat.
+     * 
+     * @return the <tt>MetaContact</tt> corresponding to the chat.
+     */
     public MetaContact getMetaContact()
     {
         return metaContact;
     }
+    
+    public void subscriptionCreated(SubscriptionEvent evt)
+    {}
+
+    public void subscriptionFailed(SubscriptionEvent evt)
+    {}
+
+    public void subscriptionRemoved(SubscriptionEvent evt)
+    {}
+
+    public void subscriptionMoved(SubscriptionMovedEvent evt)
+    {}
+
+    public void subscriptionResolved(SubscriptionEvent evt)
+    {}
+
+    /**
+     * Change the contact avatar image when contact details were updated.
+     */
+    public void contactModified(ContactPropertyChangeEvent evt)
+    {
+        Contact sourceContact = evt.getSourceContact();
+        
+        ChatContact chatContact = findChatContactByContact(sourceContact);
+        
+        if(chatContact != null)
+        {
+            ChatContactPanel chatContactPanel
+                = getChatContactListPanel().getChatContactPanel(chatContact);
+     
+            chatContactPanel.setContactPhoto(chatContact.getImage());
+        }
+    }
+    
+    /**
+     * Returns the <tt>ChatContact</tt> corresponding to the given
+     * <tt>MetaContact</tt>.
+     * 
+     * @param metaContact the <tt>MetaContact</tt> to search for
+     * @return the <tt>ChatContact</tt> corresponding to the given
+     * <tt>MetaContact</tt>.
+     */
+    private ChatContact findChatContactByMetaContact(MetaContact metaContact)
+    {
+        Enumeration chatContacts
+            = getChatContactListPanel().getChatContacts();
+            
+        while(chatContacts.hasMoreElements())
+        {
+            ChatContact chatContact
+                = (ChatContact) chatContacts.nextElement();
+            
+            Object chatSourceContact = chatContact.getSourceContact();
+            
+            if(chatSourceContact instanceof Contact)
+            {
+                MetaContact parentMetaContact
+                    = GuiActivator.getMetaContactListService()
+                        .findMetaContactByContact((Contact)chatSourceContact);
+                
+                if(parentMetaContact != null
+                        && parentMetaContact.equals(metaContact))
+                    return chatContact;
+            }
+        }
+        
+        return null;
+    }
+    
+    /**
+     * Returns the <tt>ChatContact</tt> corresponding to the given
+     * <tt>Contact</tt>.
+     * 
+     * @param metaContact the <tt>MetaContact</tt> to search for
+     * @return the <tt>ChatContact</tt> corresponding to the given
+     * <tt>Contact</tt>.
+     */
+    private ChatContact findChatContactByContact(Contact contact)
+    {
+        Enumeration chatContacts
+            = getChatContactListPanel().getChatContacts();
+            
+        while(chatContacts.hasMoreElements())
+        {
+            ChatContact chatContact
+                = (ChatContact) chatContacts.nextElement();
+            
+            Object chatSourceContact = chatContact.getSourceContact();
+            
+            if(chatSourceContact instanceof Contact
+                    && chatSourceContact.equals(contact))
+            {
+                return chatContact;
+            }
+        }
+        
+        return null;
+    }
 }

File [changed]: ChatContactPanel.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/gui/main/chat/ChatContactPanel.java?r1=1.2&r2=1.3
Delta lines:  +64 -144
----------------------
--- ChatContactPanel.java	2007-03-13 16:31:57+0000	1.2
+++ ChatContactPanel.java	2007-05-03 14:22:21+0000	1.3
@@ -9,7 +9,6 @@
 
 import java.awt.*;
 import java.awt.event.*;
-import java.util.*;
 
 import javax.swing.*;
 import javax.swing.border.*;
@@ -18,9 +17,7 @@
 import net.java.sip.communicator.impl.gui.customcontrols.*;
 import net.java.sip.communicator.impl.gui.i18n.*;
 import net.java.sip.communicator.impl.gui.lookandfeel.*;
-import net.java.sip.communicator.impl.gui.main.*;
 import net.java.sip.communicator.impl.gui.utils.*;
-import net.java.sip.communicator.service.contactlist.*;
 import net.java.sip.communicator.service.protocol.*;
 import net.java.sip.communicator.util.*;
 
@@ -67,58 +64,40 @@
 
     private JPanel mainPanel = new JPanel(new BorderLayout());
     
-    private Contact protocolContact;
+    private ImageIcon contactPhotoIcon;
+    
+    private ChatContact chatContact;
     
     private PresenceStatus status;
     
     private ChatPanel chatPanel;
 
-    /**
-     * Creates an instance of the <tt>ChatContactPanel</tt>.
-     * 
-     * @param chatPanel
-     * @param protocolContact
-     */
-    public ChatContactPanel(ChatPanel chatPanel, Contact protocolContact)
-    {
-        this(chatPanel, null, protocolContact);
-    }
     
     /**
      * Creates an instance of the <tt>ChatContactPanel</tt>.
      * 
      * @param chatPanel the <tt>ChatPanel</tt>, to which this
      * <tt>ChatContactPanel</tt> belongs to.
-     * @param metaContact
-     * @param protocolContact
+     * @param chatContact the chat contact
      */
-    public ChatContactPanel(ChatPanel chatPanel,
-            MetaContact metaContact, Contact protocolContact)
+    public ChatContactPanel(ChatPanel chatPanel, ChatContact contact)
     {
         super(new BorderLayout(10, 5));
 
-        this.protocolContact = protocolContact;
+        this.chatContact = contact;
         
         this.setPreferredSize(new Dimension(100, 60));
 
         this.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
 
-        this.status = protocolContact.getPresenceStatus();
+        this.status = chatContact.getPresenceStatus();
         this.chatPanel = chatPanel;
 
         this.setOpaque(false);
         this.mainPanel.setOpaque(false);
-        //this.contactNamePanel.setOpaque(false);
         this.buttonsPanel.setOpaque(false);
         
-        String chatContactName;
-
-        if(metaContact != null)
-            chatContactName = metaContact.getDisplayName();
-        else
-            chatContactName = protocolContact.getDisplayName();
-        
-        this.personNameLabel.setText(chatContactName);
+        this.personNameLabel.setText(chatContact.getName());
         this.personNameLabel.setFont(this.getFont().deriveFont(Font.BOLD));
         this.personNameLabel.setIcon(new ImageIcon(Constants
                 .getStatusIcon(status)));
@@ -150,9 +129,40 @@
         this.callButton.setEnabled(false);
         this.sendFileButton.setEnabled(false);
         
-        new LoadContactPhoto(metaContact, protocolContact).start();
+        //Load the contact photo.
+        new Thread()
+        {
+            public void run()
+            {   
+                contactPhotoIcon = chatContact.getImage();
+                
+                SwingUtilities.invokeLater(new Runnable(){
+                    public void run()
+                    {
+                        if(contactPhotoIcon != null)
+                        {
+                            personPhotoLabel.setBorder(
+                                    new SIPCommBorders.BoldRoundBorder());
+                            personPhotoLabel.setIcon(contactPhotoIcon);
+                        }
+                    }
+                });
+                
+            }
+        }.start();
+
+        ProtocolProviderService pps
+            = chatContact.getProtocolProvider();
+    
+        Object contactInfoOpSet
+            = pps.getOperationSet(OperationSetWebContactInfo.class);
         
-        this.updateProtocolContact(protocolContact);
+        if(contactInfoOpSet == null)
+            infoButton.setEnabled(false);
+        else
+            infoButton.setEnabled(true);
+        
+        this.setStatusIcon(chatContact.getPresenceStatus());
     }
 
     /**
@@ -201,52 +211,28 @@
     }
     
     /**
-     * Disables or enables the contact info button depending on the selected 
-     * protocol contact.
-     * 
-     * @param protocolContact the selected protocol contact 
-     */
-    public void updateProtocolContact(Contact protocolContact)
-    {   
-        MainFrame mainFrame = chatPanel.getChatWindow().getMainFrame();
-        
-        ProtocolProviderService pps
-            = protocolContact.getProtocolProvider();
-
-        OperationSetWebContactInfo wContactInfo
-            = mainFrame.getWebContactInfoOpSet(pps);
-        
-        if(wContactInfo == null)
-            infoButton.setEnabled(false);
-        else
-            infoButton.setEnabled(true);
-        
-        this.setStatusIcon(protocolContact.getPresenceStatus());
-    }
-    
-    /**
      * 
      */
     public void actionPerformed(ActionEvent e)
     {
         JButton button = (JButton) e.getSource();
         
-        MainFrame mainFrame = chatPanel.getChatWindow().getMainFrame();
-        
-        if(button.getName().equals("call")) {
-            
+        if(button.getName().equals("call"))
+        {
+            //TODO: Implement the call functionality
         }
         else if(button.getName().equals("info"))
         {
             ProtocolProviderService pps
-                = protocolContact.getProtocolProvider();
+                = chatContact.getProtocolProvider();
 
-            OperationSetWebContactInfo wContactInfo
-                = mainFrame.getWebContactInfoOpSet(pps);
+            Object contactInfoOpSet
+                = pps.getOperationSet(OperationSetWebContactInfo.class);
 
-            if(wContactInfo != null) {
+            if(contactInfoOpSet != null) {
                 GuiActivator.getBrowserLauncher().openURL(
-                    wContactInfo.getWebContactInfo(protocolContact)
+                    ((OperationSetWebContactInfo)contactInfoOpSet)
+                        .getWebContactInfo(chatContact.getAddress())
                         .toString());
             }            
         }
@@ -262,83 +248,17 @@
     }
     
     /**
-     * Loads contact photo in a separate thread
+     * Sets the given <tt>ImageIcon</tt> to be the photo shown on the left of
+     * the contact name.
+     * 
+     * @param contactPhoto the image to show as a contact photo
      */
-    private class LoadContactPhoto extends Thread
-    {
-        private MetaContact metaContact;
-        private Contact contact;
-        private ImageIcon contactPhoto;
-        
-        public LoadContactPhoto(MetaContact metaContact, Contact contact)
-        {
-            this.metaContact = metaContact;
-            this.contact = contact;
-        }
-
-        public LoadContactPhoto(MetaContact metaContact)
-        {
-            this.metaContact = metaContact;
-        }
-        
-        public void run()
-        {
-            byte[] image = null;
-            
-            if(metaContact != null)
-            {
-                Iterator i = metaContact.getContacts();
-                
-                while(i.hasNext())
-                {
-                    Contact protoContact = (Contact) i.next();
-                    
-                    try
-                    {
-                        image = protoContact.getImage();
-                    }
-                    catch (Exception ex)
-                    {
-                        logger.error("Failed to load contact photo.", ex);
-                    }
-                    
-                    if(image != null && image.length > 0)
-                        break;
-                }
-            }
-            else if(contact != null)
-            {
-                try
-                {
-                    image = contact.getImage();
-                }
-                catch (Exception ex)
-                {
-                    logger.error("Failed to load contact photo.", ex);
-                }
-            }
-            
-            if(image != null && image.length > 0)
+    public void setContactPhoto(ImageIcon contactPhoto)
             {
-                Image contactImage
-                    = ImageLoader.getBytesInImage(image);
-                
-                contactPhoto = new ImageIcon(
-                    contactImage.getScaledInstance(            
-                    40, 45, Image.SCALE_SMOOTH));
-            }    
-            
-            if(contactPhoto == null)
-                return;
+        contactPhotoIcon = contactPhoto;
             
-            SwingUtilities.invokeLater(new Runnable(){
-                public void run()
-                {
                     personPhotoLabel.setBorder(
                         new SIPCommBorders.BoldRoundBorder());
-                    personPhotoLabel.setIcon(contactPhoto);
-                }
-            });
-        }
+        personPhotoLabel.setIcon(contactPhotoIcon);                
     }
 }

Directory: /sip-communicator/src/net/java/sip/communicator/impl/gui/i18n/
=========================================================================

File [changed]: messages.properties
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/gui/i18n/messages.properties?r1=1.62&r2=1.63
Delta lines:  +1 -0
-------------------
--- messages.properties	2007-04-24 12:32:53+0000	1.62
+++ messages.properties	2007-05-03 14:22:21+0000	1.63
@@ -95,6 +95,7 @@
 ignore=Ignore
 insertSmiley=Insert smiley
 invalidCall=Invalid call
+join=&Join
 joinChatRoom=&Join chat room
 last=Last
 launchBrowserError=Error attempting to launch web browser.




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





More information about the commits mailing list