mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
SPARK-1323 fixed refreshing avatar, set fixed size for avatar in statuspanel. you can upload avatas 128x128px to server.
git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@12347 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
committed by
holger.bergunde
parent
c7b4f26d6d
commit
907a297a98
@ -65,6 +65,7 @@ import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.ui.CommandPanel;
|
||||
import org.jivesoftware.spark.ui.PresenceListener;
|
||||
import org.jivesoftware.spark.util.GraphicUtils;
|
||||
import org.jivesoftware.spark.util.ImageCombiner;
|
||||
import org.jivesoftware.spark.util.ModelUtil;
|
||||
import org.jivesoftware.spark.util.StringUtils;
|
||||
import org.jivesoftware.spark.util.SwingTimerTask;
|
||||
@ -72,6 +73,7 @@ import org.jivesoftware.spark.util.SwingWorker;
|
||||
import org.jivesoftware.spark.util.TaskEngine;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkimpl.plugin.privacy.PrivacyManager;
|
||||
import org.jivesoftware.sparkimpl.plugin.privacy.PrivacyPlugin;
|
||||
import org.jivesoftware.sparkimpl.plugin.privacy.list.SparkPrivacyList;
|
||||
import org.jivesoftware.sparkimpl.profile.VCardEditor;
|
||||
import org.jivesoftware.sparkimpl.profile.VCardListener;
|
||||
@ -164,7 +166,8 @@ public class StatusBar extends JPanel implements VCardListener {
|
||||
}
|
||||
|
||||
public void setAvatar(Icon icon) {
|
||||
imageLabel.setIcon(icon);
|
||||
Image image = ImageCombiner.iconToImage(icon);
|
||||
imageLabel.setIcon(new ImageIcon(image.getScaledInstance(-1, 64, Image.SCALE_SMOOTH)));
|
||||
imageLabel.setBorder(null);
|
||||
invalidate();
|
||||
validateTree();
|
||||
@ -327,6 +330,8 @@ public class StatusBar extends JPanel implements VCardListener {
|
||||
privMenu.add(it);
|
||||
if (plist.isActive()) {
|
||||
it.setIcon(SparkRes.getImageIcon("PRIVACY_LIGHTNING"));
|
||||
} else {
|
||||
it.setIcon(null);
|
||||
}
|
||||
it.addActionListener(new ActionListener() {
|
||||
|
||||
@ -334,7 +339,9 @@ public class StatusBar extends JPanel implements VCardListener {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
try {
|
||||
PrivacyPlugin.removeiconFromContacts();
|
||||
plist.setListAsActive();
|
||||
PrivacyPlugin.scanContactList();
|
||||
} catch (XMPPException e1) {
|
||||
Log.warning("Could not activate list " + plist.getListName(), e1);
|
||||
e1.printStackTrace();
|
||||
@ -519,8 +526,7 @@ public class StatusBar extends JPanel implements VCardListener {
|
||||
try {
|
||||
ImageIcon avatarIcon = new ImageIcon(avatarBytes);
|
||||
avatarIcon = VCardManager.scale(avatarIcon);
|
||||
imageLabel.setIcon(avatarIcon);
|
||||
// imageLabel.setBorder(BorderFactory.createBevelBorder(0, Color.white, Color.lightGray));
|
||||
setAvatar(avatarIcon);
|
||||
imageLabel.invalidate();
|
||||
imageLabel.validate();
|
||||
imageLabel.repaint();
|
||||
|
||||
@ -20,10 +20,14 @@
|
||||
package org.jivesoftware.spark.util;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ImageObserver;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
@ -87,4 +91,30 @@ public class ImageCombiner {
|
||||
return image;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an Image from the specified Icon
|
||||
*
|
||||
* @param icon
|
||||
* that should be converted to an image
|
||||
* @return the new image
|
||||
*/
|
||||
public static Image iconToImage(Icon icon) {
|
||||
if (icon instanceof ImageIcon) {
|
||||
return ((ImageIcon) icon).getImage();
|
||||
} else {
|
||||
int w = icon.getIconWidth();
|
||||
int h = icon.getIconHeight();
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice gd = ge.getDefaultScreenDevice();
|
||||
GraphicsConfiguration gc = gd.getDefaultConfiguration();
|
||||
BufferedImage image = gc.createCompatibleImage(w, h);
|
||||
Graphics2D g = image.createGraphics();
|
||||
icon.paintIcon(null, g, 0, 0);
|
||||
g.dispose();
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -115,8 +115,8 @@ public class AvatarPanel extends JPanel implements ActionListener {
|
||||
*/
|
||||
public void setAvatar(ImageIcon icon) {
|
||||
avatar.setBorder(BorderFactory.createBevelBorder(0, Color.white, Color.lightGray));
|
||||
if (icon.getIconHeight() > 64 || icon.getIconWidth() > 64) {
|
||||
avatar.setIcon(new ImageIcon(icon.getImage().getScaledInstance(-1, 64, Image.SCALE_SMOOTH)));
|
||||
if (icon.getIconHeight() > 128 || icon.getIconWidth() > 128) {
|
||||
avatar.setIcon(new ImageIcon(icon.getImage().getScaledInstance(-1, 128, Image.SCALE_SMOOTH)));
|
||||
}
|
||||
else {
|
||||
avatar.setIcon(icon);
|
||||
|
||||
@ -185,7 +185,6 @@ public class VCardEditor {
|
||||
tabbedPane.addTab(Res.getString("tab.avatar"), avatarPanel);
|
||||
|
||||
// Build the UI
|
||||
_vcard = vCard;
|
||||
buildUI(vCard);
|
||||
|
||||
final JOptionPane pane;
|
||||
@ -242,7 +241,6 @@ public class VCardEditor {
|
||||
VCardManager manager = SparkManager.getVCardManager();
|
||||
VCard card = manager.reloadVCard(vCard.getJabberId());
|
||||
fillUI(card);
|
||||
saveVCard();
|
||||
}
|
||||
|
||||
}
|
||||
@ -437,7 +435,7 @@ public class VCardEditor {
|
||||
avatarBytes = GraphicUtils.getBytesFromImage(avatarFile);
|
||||
ImageIcon icon = new ImageIcon(avatarBytes);
|
||||
Image image = icon.getImage();
|
||||
image = image.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
|
||||
image = image.getScaledInstance(-1, 128, Image.SCALE_SMOOTH);
|
||||
avatarBytes = GraphicUtils.getBytesFromImage(image);
|
||||
|
||||
}
|
||||
|
||||
@ -585,9 +585,6 @@ public class VCardManager {
|
||||
number = number.replace("(", "");
|
||||
number = number.replace(")", "");
|
||||
number = number.replace(" ", "");
|
||||
if (number.startsWith("1")) {
|
||||
number = number.substring(1);
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user