Update for avatars.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@9079 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2007-09-07 20:26:43 +00:00
committed by derek
parent 6e13ce3615
commit 386ec6b6e3
8 changed files with 125 additions and 26 deletions

View File

@ -21,10 +21,17 @@ import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.spark.ChatManager;
import org.jivesoftware.spark.PresenceManager;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
@ -34,11 +41,6 @@ import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
/**
* Represent a single contact within the <code>ContactList</code>.
*/
@ -251,10 +253,11 @@ public class ContactItem extends JPanel {
if (!hashExists(hash)) {
updateAvatar();
}
updateContactItem();
}
}
updatePresenceIcon(presence);
}
@ -352,7 +355,7 @@ public class ContactItem extends JPanel {
RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getJID());
if (entry != null && (entry.getType() == RosterPacket.ItemType.none || entry.getType() == RosterPacket.ItemType.from)
&& RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
&& RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
// Do not move out of group.
setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION));
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
@ -460,5 +463,27 @@ public class ContactItem extends JPanel {
getNicknameLabel().setForeground(Color.red);
}
private void updateContactItem() {
LocalPreferences preferences = SettingsManager.getLocalPreferences();
boolean avatarsShowing = preferences.areAvatarsVisible();
try {
final URL url = getAvatarURL();
if (url != null) {
if (!avatarsShowing) {
setSideIcon(null);
}
else {
ImageIcon icon = new ImageIcon(url);
icon = GraphicUtils.scale(icon, 16, 19);
setSideIcon(icon);
}
}
}
catch (MalformedURLException e) {
e.printStackTrace();
}
}
}

View File

@ -66,6 +66,8 @@ public class ThemePanel extends JPanel {
private JCheckBox systemLookAndFeelBox;
private JCheckBox showAvatarsBox;
/**
* Construct UI
*/
@ -87,6 +89,8 @@ public class ThemePanel extends JPanel {
systemLookAndFeelBox = new JCheckBox();
showAvatarsBox = new JCheckBox();
contactListFontField = new JTextField();
contactListFontLabel = new JLabel();
@ -105,6 +109,7 @@ public class ThemePanel extends JPanel {
ResourceUtils.resLabel(contactListFontLabel, contactListFontField, "Contact &List font size:");
ResourceUtils.resLabel(chatRoomFontLabel, chatRoomFontField, "Chat &Room font size:");
ResourceUtils.resButton(showAvatarsBox, "Show &Avatars in Contact List");
// Build UI
buildUI();
@ -136,6 +141,8 @@ public class ThemePanel extends JPanel {
add(chatRoomFontField, new GridBagConstraints(1, 5, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));
add(contactListFontLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
add(contactListFontField, new GridBagConstraints(1, 6, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));
add(showAvatarsBox, new GridBagConstraints(0, 7, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
// Activate live one.
LocalPreferences pref = SettingsManager.getLocalPreferences();
@ -171,6 +178,8 @@ public class ThemePanel extends JPanel {
systemLookAndFeelBox.setSelected(pref.useSystemLookAndFeel());
showAvatarsBox.setSelected(pref.areAvatarsVisible());
try {
int chatRoomFontSize = pref.getChatRoomFontSize();
int contactListFontSize = pref.getContactListFontSize();
@ -326,4 +335,7 @@ public class ThemePanel extends JPanel {
return contactListFontField.getText();
}
public boolean areAvatarsVisible(){
return showAvatarsBox.isSelected();
}
}

View File

@ -86,6 +86,7 @@ public class ThemePreference implements Preference {
pref.setEmoticonPack(pack);
pref.setEmoticonsEnabled(emotEnabled);
pref.setUseSystemLookAndFeel(panel.useSystemLookAndFeel());
pref.setAvatarVisible(panel.areAvatarsVisible());
try {
String chatRoomFontSize = panel.getChatRoomFontSize();

View File

@ -20,11 +20,16 @@ import org.jivesoftware.spark.plugin.Plugin;
import org.jivesoftware.spark.ui.ContactGroup;
import org.jivesoftware.spark.ui.ContactItem;
import org.jivesoftware.spark.ui.ContactList;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.PreferenceListener;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
@ -33,6 +38,8 @@ import javax.swing.event.PopupMenuListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -44,6 +51,7 @@ public class ContactListAssistantPlugin implements Plugin {
private JMenu moveToMenu;
private JMenu copyToMenu;
private boolean avatarsShowing = false;
public void initialize() {
@ -132,6 +140,14 @@ public class ContactListAssistantPlugin implements Plugin {
return false;
}
});
updateAvatarsInContactList();
SettingsManager.addPreferenceListener(new PreferenceListener() {
public void preferencesChanged(LocalPreferences preference) {
updateAvatarsInContactList();
}
});
}
/**
@ -170,6 +186,44 @@ public class ContactListAssistantPlugin implements Plugin {
public void uninstall() {
}
private void updateContactItem(ContactItem contactItem) {
LocalPreferences preferences = SettingsManager.getLocalPreferences();
avatarsShowing = preferences.areAvatarsVisible();
try {
final URL url = contactItem.getAvatarURL();
if (url != null) {
if (!avatarsShowing) {
contactItem.setSideIcon(null);
}
else {
ImageIcon icon = new ImageIcon(url);
icon = GraphicUtils.scale(icon, 16, 19);
contactItem.setSideIcon(icon);
}
}
}
catch (MalformedURLException e) {
e.printStackTrace();
}
}
private void updateAvatarsInContactList() {
LocalPreferences preferences = SettingsManager.getLocalPreferences();
avatarsShowing = preferences.areAvatarsVisible();
final ContactList contactList = SparkManager.getContactList();
for (ContactGroup contactGroup : contactList.getContactGroups()) {
if (contactGroup.isOfflineGroup()) {
continue;
}
for (ContactItem contactItem : contactGroup.getContactItems()) {
updateContactItem(contactItem);
}
}
}
/**
* Copies or moves a new <code>ContactItem</code> into the <code>ContactGroup</code>.
*

View File

@ -10,10 +10,11 @@
package org.jivesoftware.sparkimpl.preference;
import org.jivesoftware.resource.Res;
import org.jivesoftware.spark.component.TitlePanel;
import org.jivesoftware.spark.component.renderer.JLabelIconRenderer;
import org.jivesoftware.spark.preference.Preference;
import org.jivesoftware.resource.Res;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import javax.swing.DefaultListModel;
import javax.swing.JComponent;
@ -29,8 +30,8 @@ import javax.swing.event.ListSelectionListener;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Iterator;
@ -111,6 +112,7 @@ public class PreferencesPanel extends JPanel implements ListSelectionListener {
if (currentPreference != null) {
if (currentPreference.isDataValid()) {
currentPreference.commit();
SettingsManager.fireListeners();
return true;
}
else {

View File

@ -141,9 +141,8 @@ public class VCardManager {
if (personalVCard != null) {
byte[] bytes = personalVCard.getAvatar();
if (bytes != null) {
String hash = org.jivesoftware.spark.util.StringUtils.hash(bytes);
update.setPhotoHash(hash);
jax.setPhotoHash(hash);
update.setPhotoHash(personalVCard.getAvatarHash());
jax.setPhotoHash(personalVCard.getAvatarHash());
newPresence.addExtension(update);
newPresence.addExtension(jax);
@ -587,7 +586,7 @@ public class VCardManager {
if (bytes != null) {
vcard.setAvatar(bytes);
try {
String hash = org.jivesoftware.spark.util.StringUtils.hash(bytes);
String hash = vcard.getAvatarHash();
final File avatarFile = new File(contactsDir, hash);
ImageIcon icon = new ImageIcon(bytes);
icon = VCardManager.scale(icon);

View File

@ -560,15 +560,15 @@ public class LocalPreferences {
}
public void setSSOAdv(boolean enabled) {
setBoolean("ssoAdv",enabled);
setBoolean("ssoAdv", enabled);
}
public boolean getSSOAdv() {
return getBoolean("ssoAdv",false);
return getBoolean("ssoAdv", false);
}
public void setSSOMethod(String method) {
props.setProperty("ssoMethod",method);
props.setProperty("ssoMethod", method);
}
public String getSSOMethod() {
@ -576,7 +576,7 @@ public class LocalPreferences {
}
public void setSSORealm(String realm) {
props.setProperty("ssoRealm",realm);
props.setProperty("ssoRealm", realm);
}
public String getSSORealm() {
@ -584,7 +584,7 @@ public class LocalPreferences {
}
public void setSSOKDC(String kdc) {
props.setProperty("ssoKDC",kdc);
props.setProperty("ssoKDC", kdc);
}
public String getSSOKDC() {
@ -592,11 +592,11 @@ public class LocalPreferences {
}
public boolean getDebug() {
return getBoolean("debug",false);
return getBoolean("debug", false);
}
public void setDebug(boolean debug) {
setBoolean("debug",debug);
setBoolean("debug", debug);
}
public void setDebuggerEnabled(boolean enabled) {
@ -631,14 +631,22 @@ public class LocalPreferences {
return getBoolean("perisitedChatRoomsClosable", true);
}
public void setLanguage(String language){
public void setLanguage(String language) {
props.setProperty("language", language);
}
public String getLanguage(){
public String getLanguage() {
return props.getProperty("language", "");
}
public void setAvatarVisible(boolean visible) {
setBoolean("showAvatar", visible);
}
public boolean areAvatarsVisible() {
return getBoolean("showAvatar", false);
}
private boolean getBoolean(String property, boolean defaultValue) {
return Boolean.parseBoolean(props.getProperty(property, Boolean.toString(defaultValue)));
}

View File

@ -66,8 +66,6 @@ public class SettingsManager {
catch (Exception e) {
Log.error("Error saving settings.", e);
}
fireListeners(localPreferences);
}
/**
@ -114,9 +112,9 @@ public class SettingsManager {
listeners.remove(listener);
}
private static void fireListeners(LocalPreferences pref) {
public static void fireListeners() {
for (PreferenceListener listener : listeners) {
listener.preferencesChanged(pref);
listener.preferencesChanged(localPreferences);
}
}
}