Added VCardListener.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@9224 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2007-09-26 14:43:03 +00:00
committed by derek
parent df307442b5
commit 91548b3fcd
4 changed files with 77 additions and 4 deletions

View File

@ -21,10 +21,12 @@ import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.ui.PresenceListener;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.SwingTimerTask;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.TaskEngine;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.profile.VCardEditor;
import org.jivesoftware.sparkimpl.profile.VCardListener;
import org.jivesoftware.sparkimpl.profile.VCardManager;
import java.awt.Color;
@ -45,6 +47,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.TimerTask;
import javax.swing.AbstractAction;
import javax.swing.Action;
@ -60,7 +63,7 @@ import javax.swing.SwingUtilities;
import javax.swing.border.Border;
//TODO: I need to remove the presence logic from this class.
public class StatusBar extends JPanel {
public class StatusBar extends JPanel implements VCardListener {
private List<StatusItem> statusList = new ArrayList<StatusItem>();
private JLabel imageLabel = new JLabel();
@ -129,6 +132,17 @@ public class StatusBar extends JPanel {
imageLabel.setCursor(GraphicUtils.DEFAULT_CURSOR);
}
});
final TimerTask task = new SwingTimerTask() {
public void doRun() {
SparkManager.getVCardManager().addVCardListener(SparkManager.getWorkspace().getStatusBar());
}
};
TaskEngine.getInstance().schedule(task, 3000);
}
public void setAvatar(Icon icon) {
@ -529,4 +543,9 @@ public class StatusBar extends JPanel {
dim.width = 0;
return dim;
}
public void vcardChanged(VCard vcard) {
updatVCardInformation(vcard);
}
}

View File

@ -446,6 +446,9 @@ public class VCardEditor {
statusBar.setAvatar(null);
}
// Notify listenres
SparkManager.getVCardManager().notifyVCardListeners();
}
catch (XMPPException e) {
Log.error(e);

View File

@ -0,0 +1,20 @@
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.sparkimpl.profile;
import org.jivesoftware.smackx.packet.VCard;
/**
* Users will want to implement this interface to listen for changes with their VCard.
*
* @author Derek DeMoro
*/
public interface VCardListener {
void vcardChanged(VCard vcard);
}

View File

@ -53,7 +53,9 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
@ -89,6 +91,7 @@ public class VCardManager {
private File contactsDir;
private List<VCardListener> listeners = new ArrayList<VCardListener>();
/**
* Initialize VCardManager.
@ -231,7 +234,7 @@ public class VCardManager {
JMenuItem viewProfileMenu = new JMenuItem("", SparkRes.getImageIcon(SparkRes.FIND_TEXT_IMAGE));
ResourceUtils.resButton(viewProfileMenu, Res.getString("menuitem.lookup.profile"));
contactsMenu.insert(viewProfileMenu, size - 1);
contactsMenu.insert(viewProfileMenu, size > 0 ? size - 1 : 0);
viewProfileMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String jidToView = JOptionPane.showInputDialog(SparkManager.getMainWindow(), Res.getString("message.enter.jabber.id") + ":", Res.getString("title.lookup.profile"), JOptionPane.QUESTION_MESSAGE);
@ -577,10 +580,10 @@ public class VCardManager {
VCard vcard = getVCard(jid, true);
if (vcard != null) {
String hash = vcard.getAvatarHash();
if(!ModelUtil.hasLength(hash)){
if (!ModelUtil.hasLength(hash)) {
return null;
}
final File avatarFile = new File(contactsDir, hash);
try {
return avatarFile.toURL();
@ -689,4 +692,32 @@ public class VCardManager {
return null;
}
/**
* Add <code>VCardListener</code>.
*
* @param listener the listener to add.
*/
public void addVCardListener(VCardListener listener) {
listeners.add(listener);
}
/**
* Remove <code>VCardListener</code>.
*
* @param listener the listener to remove.
*/
public void removeVCardListener(VCardListener listener) {
listeners.remove(listener);
}
/**
* Notify all <code>VCardListener</code> implementations.
*/
protected void notifyVCardListeners() {
for (VCardListener listener : listeners) {
listener.vcardChanged(personalVCard);
}
}
}