Round corners for avatars and account photo.

cusax-fix
Yana Stamcheva 17 years ago
parent 2a772b309e
commit 718254af15

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

@ -9,17 +9,19 @@
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;
import javax.swing.*;
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.protocol.*;
import net.java.sip.communicator.util.*;
/**
* The <tt>ContactListCellRenderer</tt> is the custom cell renderer used in the
@ -33,16 +35,13 @@ public class ContactListCellRenderer
extends JPanel
implements ListCellRenderer
{
private Logger logger = Logger.getLogger(ContactListCellRenderer.class);
private JLabel nameLabel = new JLabel();
private JLabel photoLabel = new JLabel();
private JPanel buttonsPanel;
private SIPCommButton extendPanelButton = new SIPCommButton(ImageLoader
.getImage(ImageLoader.MORE_INFO_ICON), ImageLoader
.getImage(ImageLoader.MORE_INFO_ICON));
private int rowTransparency
= GuiActivator.getResources()
.getSettingsInt("contactListRowTransparency");
@ -55,11 +54,6 @@ public class ContactListCellRenderer
private MainFrame mainFrame;
private int CONTACT_PROTOCOL_BUTTON_WIDTH = 20;
private Color bgColor = new Color(GuiActivator.getResources()
.getColor("contactListRowColor"), true);
/**
* Initialize the panel containing the node.
*/
@ -104,8 +98,6 @@ public Component getListCellRendererComponent(JList list, Object value,
ContactList contactList = (ContactList) list;
ContactListModel listModel = (ContactListModel) contactList.getModel();
if (value instanceof MetaContact)
{
this.setPreferredSize(new Dimension(20, 30));
@ -129,15 +121,10 @@ public Component getListCellRendererComponent(JList list, Object value,
this.setBorder(BorderFactory.createEmptyBorder(1, 5, 1, 1));
byte[] avatar = contactItem.getAvatar(true);
if (avatar != null)
if (avatar != null && avatar.length > 0)
{
ImageIcon imageIcon = new ImageIcon(avatar);
Image newImage = imageIcon.getImage()
.getScaledInstance(25, 30, Image.SCALE_SMOOTH);
imageIcon.setImage(newImage);
this.photoLabel.setIcon(imageIcon);
Image roundedAvatar = createRoundImage(avatar);
this.photoLabel.setIcon(new ImageIcon(roundedAvatar));
}
// We should set the bounds of the cell explicitely in order to
@ -208,28 +195,41 @@ else if (value instanceof MetaContactGroup)
}
/**
* Adds the protocol provider index to the given source image.
* @param sourceImage
* @param index
* @return
* Creates a rounded avatar image.
*
* @param avatarBytes The bytes of the initial avatar image.
*
* @return The rounded corner image.
*/
private Image createIndexedImage(Image sourceImage, int index)
{
BufferedImage buffImage = new BufferedImage(
22, 16, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D)buffImage.getGraphics();
AlphaComposite ac =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
AntialiasingManager.activateAntialiasing(g);
g.setColor(Color.DARK_GRAY);
g.setFont(Constants.FONT.deriveFont(Font.BOLD, 9));
g.drawImage(sourceImage, 0, 0, null);
g.setComposite(ac);
g.drawString(new Integer(index+1).toString(), 14, 8);
return buffImage;
private Image createRoundImage(byte[] avatarBytes)
{
BufferedImage destImage
= new BufferedImage(25, 30, BufferedImage.TYPE_INT_ARGB);
BufferedImage avatarImage;
try
{
InputStream in = new ByteArrayInputStream(avatarBytes);
avatarImage = ImageIO.read(in);
Graphics2D g = destImage.createGraphics();
AntialiasingManager.activateAntialiasing(g);
g.setColor(Color.WHITE);
g.fillRoundRect(0, 0, 25, 30, 10, 10);
g.setComposite(AlphaComposite.SrcIn);
g.drawImage(avatarImage
.getScaledInstance(25, 30, Image.SCALE_SMOOTH), 0, 0, null);
return destImage;
}
catch (Exception e)
{
logger.error("Could not create image.", e);
}
return null;
}
/**

@ -7,7 +7,10 @@
package net.java.sip.communicator.impl.gui.main.presence;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.*;
@ -22,10 +25,11 @@ public class AccountStatusPanel
extends JPanel
implements RegistrationStateChangeListener
{
private Logger logger = Logger.getLogger(AccountStatusPanel.class);
static final int AVATAR_ICON_HEIGHT = 45;
private static final int AVATAR_ICON_HEIGHT = 45;
static final int AVATAR_ICON_WIDTH = 40;
private static final int AVATAR_ICON_WIDTH = 40;
private JMenuBar statusMenuBar = new JMenuBar();
@ -75,10 +79,6 @@ public AccountStatusPanel(MainFrame mainFrame)
this.rightPanel.add(accountNameLabel);
this.rightPanel.add(statusMenuBar);
this.initAccountImageLabel();
this.initAccountNameLabel();
}
public void addAccount(ProtocolProviderService protocolProvider)
@ -131,16 +131,6 @@ public boolean hasSelectedMenus()
return statusComboBox.hasSelectedMenus();
}
private void initAccountImageLabel()
{
}
private void initAccountNameLabel()
{
}
public void registrationStateChanged(RegistrationStateChangeEvent evt)
{
final ProtocolProviderService protocolProvider = evt.getProvider();
@ -164,11 +154,10 @@ public void run()
if (accountImage != null)
{
accountImageLabel.setIcon( ImageUtils
.scaleIconWithinBounds(
new ImageIcon(accountImage),
AVATAR_ICON_WIDTH,
AVATAR_ICON_HEIGHT));
Image roundedImage = createRoundImage(accountImage);
accountImageLabel
.setIcon(new ImageIcon(roundedImage));
}
String firstName
@ -224,4 +213,46 @@ protected void paintComponent(Graphics g)
g.fillRoundRect(5, 5, this.getWidth() - 10, this.getHeight() - 10, 8, 8);
}
/**
* Creates a rounded avatar image.
*
* @param avatarBytes The bytes of the initial avatar image.
*
* @return The rounded corner image.
*/
private Image createRoundImage(byte[] avatarBytes)
{
BufferedImage destImage
= new BufferedImage(AVATAR_ICON_WIDTH,
AVATAR_ICON_HEIGHT,
BufferedImage.TYPE_INT_ARGB);
BufferedImage avatarImage;
try
{
InputStream in = new ByteArrayInputStream(avatarBytes);
avatarImage = ImageIO.read(in);
Graphics2D g = destImage.createGraphics();
AntialiasingManager.activateAntialiasing(g);
g.setColor(Color.WHITE);
g.fillRoundRect(0, 0, AVATAR_ICON_WIDTH, AVATAR_ICON_HEIGHT, 10, 10);
g.setComposite(AlphaComposite.SrcIn);
g.drawImage(avatarImage
.getScaledInstance( AVATAR_ICON_WIDTH,
AVATAR_ICON_HEIGHT,
Image.SCALE_SMOOTH), 0, 0, null);
return destImage;
}
catch (Exception e)
{
logger.error("Could not create image.", e);
}
return null;
}
}

Loading…
Cancel
Save