diff --git a/src/java/org/jivesoftware/spark/ui/status/StatusBar.java b/src/java/org/jivesoftware/spark/ui/status/StatusBar.java index c52ed1bf..28935170 100644 --- a/src/java/org/jivesoftware/spark/ui/status/StatusBar.java +++ b/src/java/org/jivesoftware/spark/ui/status/StatusBar.java @@ -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 statusList = new ArrayList(); 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); + } } diff --git a/src/java/org/jivesoftware/sparkimpl/profile/VCardEditor.java b/src/java/org/jivesoftware/sparkimpl/profile/VCardEditor.java index 0f48c00a..3b2f4818 100644 --- a/src/java/org/jivesoftware/sparkimpl/profile/VCardEditor.java +++ b/src/java/org/jivesoftware/sparkimpl/profile/VCardEditor.java @@ -446,6 +446,9 @@ public class VCardEditor { statusBar.setAvatar(null); } + + // Notify listenres + SparkManager.getVCardManager().notifyVCardListeners(); } catch (XMPPException e) { Log.error(e); diff --git a/src/java/org/jivesoftware/sparkimpl/profile/VCardListener.java b/src/java/org/jivesoftware/sparkimpl/profile/VCardListener.java new file mode 100644 index 00000000..7a202f44 --- /dev/null +++ b/src/java/org/jivesoftware/sparkimpl/profile/VCardListener.java @@ -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); +} diff --git a/src/java/org/jivesoftware/sparkimpl/profile/VCardManager.java b/src/java/org/jivesoftware/sparkimpl/profile/VCardManager.java index 235d299f..25d430ac 100644 --- a/src/java/org/jivesoftware/sparkimpl/profile/VCardManager.java +++ b/src/java/org/jivesoftware/sparkimpl/profile/VCardManager.java @@ -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 listeners = new ArrayList(); /** * 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 VCardListener. + * + * @param listener the listener to add. + */ + public void addVCardListener(VCardListener listener) { + listeners.add(listener); + } + + /** + * Remove VCardListener. + * + * @param listener the listener to remove. + */ + public void removeVCardListener(VCardListener listener) { + listeners.remove(listener); + } + + /** + * Notify all VCardListener implementations. + */ + protected void notifyVCardListeners() { + for (VCardListener listener : listeners) { + listener.vcardChanged(personalVCard); + } + } + }