aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/gui/PopupDialogImpl.java
blob: 43117e1466eaf1ced206f2e1a59bd02c19b15f36 (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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
 * 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;

import javax.swing.*;

import net.java.sip.communicator.service.gui.*;

/**
 * Implements <code>PopupDialog</code> interface.
 *
 * @author Yana Stamcheva
 */
public class PopupDialogImpl
    extends JOptionPane
    implements PopupDialog
{
    private static final long serialVersionUID = 0L;

    /**
     * Creates an instance of <tt>PopupDialogImpl</tt>.
     */
    public PopupDialogImpl()
    {
    }

    /**
     * Implements the <tt>PopupDialog.showInputPopupDialog(Object)</tt> method.
     * Invokes the corresponding <tt>JOptionPane.showInputDialog</tt> method.
     *
     * @param mesg the object to display
     */
    public String showInputPopupDialog(Object mesg)
    {
        return showInputDialog(mesg);
    }

    /**
     * Implements the <tt>PopupDialog.showInputPopupDialog(Object, String)</tt>
     * method. Invokes the corresponding <tt>JOptionPane.showInputDialog</tt>
     * method.
     *
     * @param mesg the message to display
     * @param initialSelectionVal the value used to initialize the input
     * field.
     */
    public String showInputPopupDialog(Object mesg,
            String initialSelectionVal)
    {
        return showInputDialog(mesg, initialSelectionVal);
    }

    /**
     * Implements the
     * <tt>PopupDialog.showInputPopupDialog(Object, String, int)</tt> method.
     * Invokes the corresponding <tt>JOptionPane.showInputDialog</tt> method.
     *
     * @param mesg the message to display
     * @param mesgType the type of message to be displayed: ERROR_MESSAGE,
     * INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
     * @param title the String to display in the dialog title bar
     */
    public String showInputPopupDialog(Object mesg, String title,
        int mesgType)
    {
        return showInputDialog(null, mesg, title,
            popupDialog2JOptionPaneMessageType(mesgType));
    }

    private static int popupDialog2JOptionPaneMessageType(int type)
    {
        switch (type) {
        case PopupDialog.ERROR_MESSAGE:
            return JOptionPane.ERROR_MESSAGE;
        case PopupDialog.INFORMATION_MESSAGE:
            return JOptionPane.INFORMATION_MESSAGE;
        case PopupDialog.QUESTION_MESSAGE:
            return JOptionPane.QUESTION_MESSAGE;
        case PopupDialog.WARNING_MESSAGE:
            return JOptionPane.WARNING_MESSAGE;
        default:
            return JOptionPane.PLAIN_MESSAGE;
        }
    }

    /**
     * Implements the
     * <tt>PopupDialog.showInputPopupDialog(Object, String, int, Object[],
     * Object)</tt> method. Invokes the corresponding
     * <tt>JOptionPane.showInputDialog</tt> method.
     *
     * @param mesg the message to display
     * @param mesgType the type of message to be displayed: ERROR_MESSAGE,
     * INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
     * @param title the String to display in the dialog title bar
     * @param selectionVal an array of Objects that gives the possible
     * selections
     * @param initialSelectionVal the value used to initialize the input field
     */
    public Object showInputPopupDialog(Object mesg, String title,
        int mesgType, Object[] selectionVal, Object initialSelectionVal)
    {
        return showInputDialog(null, mesg, title,
            popupDialog2JOptionPaneMessageType(mesgType), null,
            selectionVal, initialSelectionVal);
    }

    /**
     * Implements the
     * <tt>PopupDialog.showInputPopupDialog(Object, String, int, Object[],
     * Object)</tt> method. Invokes the corresponding
     * <tt>JOptionPane.showInputDialog</tt> method.
     *
     * @param mesg the message to display
     * @param mesgType the type of message to be displayed: ERROR_MESSAGE,
     * INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
     * @param title the String to display in the dialog title bar
     * @param selectionVal an array of Objects that gives the possible
     * selections
     * @param initialSelectionVal the value used to initialize the input field
     * @param icon the icon to show in the input window.
     */
    public Object showInputPopupDialog(Object mesg, String title,
        int mesgType, Object[] selectionVal,
        Object initialSelectionVal, byte[] icon)
    {
        return showInputDialog(null, mesg, title,
            popupDialog2JOptionPaneMessageType(mesgType),
            createImageIcon(icon), selectionVal, initialSelectionVal);
    }

    private static ImageIcon createImageIcon(byte[] icon)
    {
        return (icon == null) ? null : new ImageIcon(icon);
    }

    /**
     * Implements the <tt>PopupDialog.showMessagePopupDialog(Object)</tt>
     * method. Invokes the corresponding
     * <tt>JOptionPane.showMessageDialog</tt> method.
     *
     * @param mesg the Object to display
     */
    public void showMessagePopupDialog(Object mesg)
    {
        showMessageDialog(null, mesg);
    }

    /**
     * Implements the <tt>PopupDialog.showMessagePopupDialog(Object, String,
     * int)</tt> method. Invokes the corresponding
     * <tt>JOptionPane.showMessageDialog</tt> method.
     *
     * @param mesg the Object to display
     * @param title the title string for the dialog
     * @param mesgType the type of message to be displayed: ERROR_MESSAGE,
     * INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
     */
    public void showMessagePopupDialog(Object mesg, String title,
        int mesgType)
    {
        showMessageDialog(null, mesg, title,
            popupDialog2JOptionPaneMessageType(mesgType));
    }

    /**
     * Implements the <tt>PopupDialog.showMessagePopupDialog(Object, String,
     * int)</tt> method. Invokes the corresponding
     * <tt>JOptionPane.showMessageDialog</tt> method.
     *
     * @param mesg the Object to display
     * @param title the title string for the dialog
     * @param mesgType the type of message to be displayed: ERROR_MESSAGE,
     * INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
     * @param icon the image to display in the message dialog.
     */
    public void showMessagePopupDialog(Object mesg, String title,
        int mesgType, byte[] icon)
    {
        showMessageDialog(null, mesg, title,
            popupDialog2JOptionPaneMessageType(mesgType),
            createImageIcon(icon));
    }

    /**
     * Implements the <tt>PopupDialog.showConfirmPopupDialog(Object)</tt>
     * method. Invokes the corresponding
     * <tt>JOptionPane.showConfirmDialog</tt> method.
     *
     * @param mesg the message to display
     */
    public int showConfirmPopupDialog(Object mesg)
    {
        return showConfirmDialog(null, mesg);
    }

    /**
     * Implements the <tt>PopupDialog.showConfirmPopupDialog(Object, String,
     * int)</tt> method. Invokes the corresponding
     * <tt>JOptionPane.showConfirmDialog</tt> method.
     *
     * @param mesg the Object to display
     * @param title the title string for the dialog
     * @param optType an integer designating the options available on the
     * dialog: YES_NO_OPTION, or YES_NO_CANCEL_OPTION
     */
    public int showConfirmPopupDialog(Object mesg, String title,
        int optType)
    {
        return showConfirmDialog(null, mesg, title,
            popupDialog2JOptionPaneOptionType(optType));
    }

    private static int popupDialog2JOptionPaneOptionType(int optionType)
    {
        switch (optionType) {
        case PopupDialog.OK_CANCEL_OPTION:
            return JOptionPane.OK_CANCEL_OPTION;
        case PopupDialog.YES_NO_OPTION:
            return JOptionPane.YES_NO_OPTION;
        case PopupDialog.YES_NO_CANCEL_OPTION:
            return JOptionPane.YES_NO_CANCEL_OPTION;
        default:
            return JOptionPane.DEFAULT_OPTION;
        }
    }

    /**
     * Implements the <tt>PopupDialog.showConfirmPopupDialog(Object, String,
     * int, int)</tt> method. Invokes the corresponding
     * <tt>JOptionPane.showConfirmDialog</tt> method.
     *
     * @param mesg the Object to display
     * @param title the title string for the dialog
     * @param optType an integer designating the options available on the
     * dialog: YES_NO_OPTION, or YES_NO_CANCEL_OPTION
     * @param mesgType an integer designating the kind of message this is;
     * primarily used to determine the icon from the pluggable Look and Feel:
     * ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE,
     * or PLAIN_MESSAGE
     */
    public int showConfirmPopupDialog(Object mesg, String title,
        int optType, int mesgType)
    {
        return showConfirmDialog(null, mesg, title,
            popupDialog2JOptionPaneOptionType(optType),
            popupDialog2JOptionPaneMessageType(mesgType));
    }

    /**
     * Implements the <tt>PopupDialog.showConfirmPopupDialog(Object, String,
     * int, int)</tt> method. Invokes the corresponding
     * <tt>JOptionPane.showConfirmDialog</tt> method.
     *
     * @param mesg the Object to display
     * @param title the title string for the dialog
     * @param optType an integer designating the options available on the
     * dialog: YES_NO_OPTION, or YES_NO_CANCEL_OPTION
     * @param mesgType an integer designating the kind of message this is;
     * primarily used to determine the icon from the pluggable Look and Feel:
     * ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE,
     * or PLAIN_MESSAGE
     * @param icon the icon to display in the dialog
     */
    public int showConfirmPopupDialog(Object mesg, String title,
        int optType, int mesgType, byte[] icon)
    {
        return showConfirmDialog(null, mesg, title,
            popupDialog2JOptionPaneOptionType(optType),
            popupDialog2JOptionPaneMessageType(mesgType),
            createImageIcon(icon));
    }

    /**
     * Implements the <tt>ExportedWindow.getIdentifier()</tt> method.
     */
    public WindowID getIdentifier()
    {
        return WINDOW_GENERAL_POPUP;
    }

    /**
     * Implements the <tt>ExportedWindow.isFocused()</tt> method. Returns TRUE
     * if this dialog is the focus owner, FALSE - otherwise.
     */
    public boolean isFocused()
    {
        return super.isFocusOwner();
    }

    /**
     * Implements the <tt>ExportedWindow.bringToFront()</tt> method. Brings this
     * window to front.
     */
    public void bringToFront()
    {
        this.requestFocusInWindow();
    }

    /**
     * This dialog could not be minimized.
     */
    public void minimize()
    {
    }

    /**
     * This dialog could not be maximized.
     */
    public void maximize()
    {
    }

    /**
     * The source of the window
     * @return the source of the window
     */
    public Object getSource()
    {
        return this;
    }

    /**
     * Implementation of {@link ExportedWindow#setParams(Object[])}.
     */
    public void setParams(Object[] windowParams)
    {
    }
}