diff options
author | Yana Stamcheva <yana@jitsi.org> | 2008-09-25 14:43:09 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2008-09-25 14:43:09 +0000 |
commit | f2535b8934cdc3b5fb1b3962f68c3bf47f49dd53 (patch) | |
tree | 5fd82d7bf1d44d318c3aa9a15ad2c7b757ab2f85 /src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java | |
parent | 9240976298c6dac348b1849c2b91fef565e23e57 (diff) | |
download | jitsi-f2535b8934cdc3b5fb1b3962f68c3bf47f49dd53.zip jitsi-f2535b8934cdc3b5fb1b3962f68c3bf47f49dd53.tar.gz jitsi-f2535b8934cdc3b5fb1b3962f68c3bf47f49dd53.tar.bz2 |
Keep avatar ratio when showing it.
Diffstat (limited to 'src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java')
-rw-r--r-- | src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java index ee75211..5d444b8 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java @@ -36,6 +36,9 @@ public class ContactListCellRenderer implements ListCellRenderer { private Logger logger = Logger.getLogger(ContactListCellRenderer.class); + + private static final int AVATAR_HEIGHT = 30; + private JLabel nameLabel = new JLabel(); private JLabel photoLabel = new JLabel(); @@ -203,33 +206,40 @@ public class ContactListCellRenderer */ private Image createRoundImage(byte[] avatarBytes) { - BufferedImage destImage - = new BufferedImage(25, 30, BufferedImage.TYPE_INT_ARGB); - - BufferedImage avatarImage; + BufferedImage destImage = null; try { InputStream in = new ByteArrayInputStream(avatarBytes); - avatarImage = ImageIO.read(in); + BufferedImage avatarImage = ImageIO.read(in); + + Image scaledImage = avatarImage.getScaledInstance( + -1, + AVATAR_HEIGHT, + Image.SCALE_SMOOTH); + + destImage + = new BufferedImage(scaledImage.getWidth(null), + AVATAR_HEIGHT, + BufferedImage.TYPE_INT_ARGB); Graphics2D g = destImage.createGraphics(); AntialiasingManager.activateAntialiasing(g); g.setColor(Color.WHITE); - g.fillRoundRect(0, 0, 25, 30, 10, 10); + g.fillRoundRect(0, 0, + scaledImage.getWidth(null), + AVATAR_HEIGHT, + 10, 10); g.setComposite(AlphaComposite.SrcIn); - g.drawImage(avatarImage - .getScaledInstance(25, 30, Image.SCALE_SMOOTH), 0, 0, null); - - return destImage; + g.drawImage(scaledImage, 0, 0, null); } catch (Exception e) { logger.error("Could not create image.", e); } - return null; + return destImage; } /** |