aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/gui/customcontrols/FramedImage.java
blob: b9f5a309e4de3891b05a4ca563ecc68c23372efd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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);
    }
}