aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/gui/main/GeneralDialPanel.java
blob: b14fffc41c37c3a59167afeb4ec4c21f133d47f7 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
 * Jitsi, 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.main;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

import javax.swing.*;

import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.call.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.skin.*;

import org.jitsi.service.resources.*;
import org.jitsi.util.*;

/**
 * The <tt>DialPanel</tt> is the panel that contains the buttons to dial a
 * phone number.
 *
 * @author Yana Stamcheva
 * @author Adam Netocny
 * @author Lyubomir Marinov
 */
public class GeneralDialPanel
    extends TransparentPanel
    implements MouseListener,
               Skinnable
{
    /**
     * The parent dial pad dialog.
     */
    private final GeneralDialPadDialog dialPadDialog;

    /**
     * The dial panel.
     */
    private final JPanel dialPadPanel =
        new TransparentPanel(new GridLayout(4, 3,
            GuiActivator.getResources()
                .getSettingsInt("impl.gui.DIAL_PAD_HORIZONTAL_GAP"),
            GuiActivator.getResources()
                .getSettingsInt("impl.gui.DIAL_PAD_VERTICAL_GAP")));

    /**
     * Handles DTMFs.
     */
    private final DTMFHandler dtmfHandler;

    /**
     * Creates an instance of <tt>DialPanel</tt> for a specific call, by
     * specifying the parent <tt>CallManager</tt> and the
     * <tt>CallPeer</tt>.
     *
     * @param dtmfHandler handles DTMFs.
     */
    public GeneralDialPanel(GeneralDialPadDialog dialPadDialog,
                            DTMFHandler dtmfHandler)
    {
        this.dialPadDialog = dialPadDialog;
        this.dtmfHandler = dtmfHandler;

        this.init();
    }

    /**
     * Initializes a new dial button which is to be used on Mac OS X.
     *
     * @param imageID
     * @param rolloverImageID
     * @param pressedImageImageID
     * @param name
     * @return the newly-initialized dial button
     */
    private JButton createDialButton( ImageID imageID,
                                      ImageID rolloverImageID,
                                      ImageID pressedImageImageID,
                                      String name)
    {
        JButton button
            = new SIPCommButton(
                    ImageLoader.getImage(imageID),
                    ImageLoader.getImage(rolloverImageID),
                    ImageLoader.getImage(pressedImageImageID),
                    null,
                    null,
                    null);

        button.setAlignmentY(JButton.LEFT_ALIGNMENT);
        button.setOpaque(false);
        button.setName(name);
        button.addMouseListener(this);
        return button;
    }

    /**
     * Initializes this panel by adding all dial buttons to it.
     */
    public void init()
    {
        this.dialPadPanel.setOpaque(false);

        this.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));

        loadSkin();

        this.add(dialPadPanel, BorderLayout.CENTER);
    }

    /**
     * Reloads dial buttons.
     */
    @Override
    public void loadSkin()
    {
        dialPadPanel.removeAll();

        for (DTMFHandler.DTMFToneInfo info : DTMFHandler.AVAILABLE_TONES)
        {
            // We only add buttons with images.
            if (info.imageID == null)
                continue;

            JComponent c
                = OSUtils.IS_MAC
                    ? createDialButton(
                            info.macImageID,
                            info.macImageRolloverID,
                            info.macImageRolloverID,
                            info.tone.getValue())
                    : createDialButton(
                            info.imageID,
                            info.imageIDPressed,
                            info.imageIDRollover,
                            info.tone.getValue());

            dialPadPanel.add(c);
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {}

    @Override
    public void mouseEntered(MouseEvent e) {}

    @Override
    public void mouseExited(MouseEvent e) {}

    /**
     * Handles the <tt>MouseEvent</tt> triggered when user presses one of the
     * dial buttons.
     * @param e the event
     */
    @Override
    public void mousePressed(MouseEvent e)
    {
        JButton button = (JButton) e.getSource();

        dialPadDialog.dialButtonPressed(button.getName());
        dtmfHandler.startSendingDtmfTone(button.getName());
    }

    /**
     * Handles the <tt>MouseEvent</tt> triggered when user releases one of the
     * dial buttons.
     * @param e the event
     */
    @Override
    public void mouseReleased(MouseEvent e)
    {
        dtmfHandler.stopSendingDtmfTone();
    }

    /**
     * Paints the main background image to the background of this dial panel.
     *
     * @param g the <tt>Graphics</tt> object used for painting
     */
    @Override
    public void paintComponent(Graphics g)
    {
        // do the superclass behavior first
        super.paintComponent(g);

        Graphics2D g2 = (Graphics2D) g;

        BufferedImage bgImage
            = ImageLoader.getImage(ImageLoader.MAIN_WINDOW_BACKGROUND);

        // paint the image
        if (bgImage != null)
        {
            ResourceManagementService r = GuiActivator.getResources();
            boolean isTextureBackground
                = Boolean.parseBoolean(
                        r.getSettingsString(
                                "impl.gui.IS_CONTACT_LIST_TEXTURE_BG_ENABLED"));
            int width = getWidth();
            int height = getHeight();

            if (isTextureBackground)
            {
                Rectangle rect
                    = new Rectangle(0, 0,
                            bgImage.getWidth(null),
                            bgImage.getHeight(null));
                TexturePaint texture = new TexturePaint(bgImage, rect);

                g2.setPaint(texture);
                g2.fillRect(0, 0, width, height);
            }
            else
            {
                g.setColor(new Color(r.getColor("contactListBackground")));
                // Paint the background with the chosen color.
                g.fillRect(0, 0, width, height);
                g2.drawImage(
                        bgImage,
                        width - bgImage.getWidth(),
                        height - bgImage.getHeight(),
                        this);
            }
        }
    }
}