diff options
author | Yana Stamcheva <yana@jitsi.org> | 2008-11-13 16:29:29 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2008-11-13 16:29:29 +0000 |
commit | aede2603103d99f8a29a1217c83500c88a6e7e30 (patch) | |
tree | 755a21fde1a4cf0de061226955e036ffa6aa2c47 /src/net/java/sip/communicator/impl/gui/customcontrols/FramedImage.java | |
parent | a42efbc21e10144a792d49d5feffb0f86319775e (diff) | |
download | jitsi-aede2603103d99f8a29a1217c83500c88a6e7e30.zip jitsi-aede2603103d99f8a29a1217c83500c88a6e7e30.tar.gz jitsi-aede2603103d99f8a29a1217c83500c88a6e7e30.tar.bz2 |
Updated and added some new custom components.
Diffstat (limited to 'src/net/java/sip/communicator/impl/gui/customcontrols/FramedImage.java')
-rw-r--r-- | src/net/java/sip/communicator/impl/gui/customcontrols/FramedImage.java | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/customcontrols/FramedImage.java b/src/net/java/sip/communicator/impl/gui/customcontrols/FramedImage.java new file mode 100644 index 0000000..b9f5a30 --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/customcontrols/FramedImage.java @@ -0,0 +1,108 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.gui.customcontrols; + +import java.awt.*; + +import javax.swing.*; + +import net.java.sip.communicator.impl.gui.utils.*; +import net.java.sip.communicator.util.*; + +/** + * A custom component, used to show contact images in a frame, + * where appropriate. + * + * @author Yana Stamcheva + */ +public class FramedImage + extends JComponent +{ + private ImageIcon shadowIcon; + + private ImageIcon frameIcon; + + private ImageIcon imageIcon; + + private int width; + + private int height; + + /** + * Creates a ContactPhotoLabel by specifying the width and the height of the + * label. These are used to paint the frame in the correct bounds. + * + * @param imageIcon the icon to show within the frame + * @param width the width of the label. + * @param height the height of the label. + */ + public FramedImage(ImageIcon imageIcon, int width, int height) + { + super(); + + this.width = width; + + this.height = height; + + this.setPreferredSize(new Dimension(width, height)); + + Image photoFrameImage + = ImageLoader.getImage(ImageLoader.USER_PHOTO_FRAME); + + this.frameIcon + = ImageUtils.scaleIconWithinBounds( photoFrameImage, + width, + height); + + this.shadowIcon + = ImageUtils.scaleIconWithinBounds( + ImageLoader.getImage(ImageLoader.USER_PHOTO_SHADOW), + width, + height); + + if (imageIcon != null) + { + this.setImageIcon(imageIcon); + } + } + + public FramedImage(int width, int height) + { + this(null, width, height); + } + + public ImageIcon getImageIcon() + { + return imageIcon; + } + + public void setImageIcon(ImageIcon imageIcon) + { + this.imageIcon + = ImageUtils.getScaledRoundedImage( imageIcon.getImage(), + width - 2, + height - 2); + } + + /** + * Overrides {@link JComponent#paintComponent(Graphics)}. + */ + public void paintComponent(Graphics g) + { + g.drawImage(imageIcon.getImage(), + width/2 - imageIcon.getIconWidth()/2, + height/2 - imageIcon.getIconHeight()/2, null); + + g.drawImage(frameIcon.getImage(), + width/2 - frameIcon.getIconWidth()/2, + height/2 - frameIcon.getIconHeight()/2, null); + + g.drawImage(shadowIcon.getImage(), + width/2 - shadowIcon.getIconWidth()/2, + 1, null); + } +} |