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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
/*
* 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.utils;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.contactlist.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.gui.event.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.skin.*;
import net.java.sip.communicator.util.swing.*;
import java.util.*;
import java.util.List;
/**
* The invite dialog is a widget that shows a list of contacts, from which the
* user could pick in order to create a conference chat or call.
*
* @author Yana Stamcheva
* @author Adam Netocny
*/
public class InviteDialog
extends SIPCommDialog
implements Skinnable,
ContactListContainer
{
private static final long serialVersionUID = 0L;
/**
* Text area where user can specify a reason for the invitation.
*/
private final JTextArea reasonArea = new JTextArea();
/**
* The button, which performs the invite.
*/
private final JButton inviteButton = new JButton(
GuiActivator.getResources().getI18NString("service.gui.INVITE"));
/**
* The button, which cancels the operation.
*/
private final JButton cancelButton = new JButton(
GuiActivator.getResources().getI18NString("service.gui.CANCEL"));
/**
* The search field.
*/
private final SearchField searchField;
/**
* The source contact list.
*/
protected ContactList srcContactList;
/**
* The destination contact list.
*/
protected ContactList destContactList;
/**
* The invite contact transfer handler.
*/
private InviteContactTransferHandler inviteContactTransferHandler;
/**
* Currently selected protocol provider.
*/
private ProtocolProviderService currentProvider;
/**
* Icon label.
*/
private final JLabel iconLabel;
/**
* Constructs an <tt>InviteDialog</tt>.
*
* @param title the title to show on the top of this dialog
*/
public InviteDialog (String title)
{
this.setModal(false);
this.setTitle(title);
TransparentPanel mainPanel
= new TransparentPanel(new BorderLayout(5, 5));
TransparentPanel northPanel
= new TransparentPanel(new BorderLayout(10, 10));
mainPanel.setPreferredSize(new Dimension(450, 350));
mainPanel.setBorder(
BorderFactory.createEmptyBorder(15, 15, 15, 15));
this.reasonArea.setBorder(BorderFactory.createTitledBorder(
GuiActivator.getResources()
.getI18NString("service.gui.INVITE_REASON")));
JTextArea infoTextArea = new JTextArea();
infoTextArea.setText(GuiActivator.getResources()
.getI18NString("service.gui.INVITE_CONTACT_MSG"));
infoTextArea.setFont(infoTextArea.getFont().deriveFont(Font.BOLD));
infoTextArea.setLineWrap(true);
infoTextArea.setOpaque(false);
infoTextArea.setWrapStyleWord(true);
infoTextArea.setEditable(false);
iconLabel = new JLabel(new ImageIcon(
ImageLoader.getImage(ImageLoader.INVITE_DIALOG_ICON)));
northPanel.add(iconLabel, BorderLayout.WEST);
northPanel.add(infoTextArea, BorderLayout.CENTER);
TransparentPanel buttonsPanel
= new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
buttonsPanel.add(inviteButton);
buttonsPanel.add(cancelButton);
inviteButton.setMnemonic(
GuiActivator.getResources().getI18nMnemonic("service.gui.INVITE"));
cancelButton.setMnemonic(
GuiActivator.getResources().getI18nMnemonic("service.gui.CANCEL"));
Component contactListComponent = createSrcContactListComponent();
ContactListSearchFilter inviteFilter
= new InviteContactListFilter(srcContactList);
srcContactList.setDefaultFilter(inviteFilter);
searchField = new SearchField(null, inviteFilter, false);
searchField.setPreferredSize(new Dimension(200, 25));
searchField.setContactList(srcContactList);
searchField.addFocusListener(new FocusAdapter()
{
/**
* Removes all other selections.
* @param e the <tt>FocusEvent</tt> that notified us
*/
public void focusGained(FocusEvent e)
{
srcContactList.removeSelection();
}
});
TransparentPanel leftPanel
= new TransparentPanel(new BorderLayout(5, 5));
leftPanel.add(searchField, BorderLayout.NORTH);
leftPanel.add(contactListComponent);
JPanel listPanel = new JPanel(new GridLayout(0, 2, 5, 5));
listPanel.setPreferredSize(new Dimension(400, 200));
listPanel.add(leftPanel);
listPanel.add(createDestContactListComponent());
listPanel.setOpaque(false);
// Add remove buttons panel.
JPanel addRemoveButtonsPanel = new JPanel(new GridLayout(0, 2, 5, 5));
addRemoveButtonsPanel.setOpaque(false);
JButton addContactButton = new JButton(
GuiActivator.getResources().getI18NString("service.gui.ADD"));
JButton removeContactButton = new JButton(
GuiActivator.getResources().getI18NString("service.gui.REMOVE"));
addRemoveButtonsPanel.add(addContactButton);
addRemoveButtonsPanel.add(removeContactButton);
addContactButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
List<UIContact> selectedContacts
= srcContactList.getSelectedContacts();
if (selectedContacts != null && selectedContacts.size() > 0)
moveContactsFromLeftToRight(selectedContacts.iterator());
}
});
removeContactButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
List<UIContact> selectedContacts
= destContactList.getSelectedContacts();
if (selectedContacts != null && selectedContacts.size() > 0)
moveContactsFromRightToLeft(selectedContacts.iterator());
}
});
TransparentPanel centerPanel = new TransparentPanel(new BorderLayout());
centerPanel.add(listPanel, BorderLayout.CENTER);
centerPanel.add(addRemoveButtonsPanel, BorderLayout.SOUTH);
TransparentPanel southPanel = new TransparentPanel(new BorderLayout());
southPanel.add(reasonArea, BorderLayout.CENTER);
southPanel.add(buttonsPanel, BorderLayout.SOUTH);
mainPanel.add(northPanel, BorderLayout.NORTH);
mainPanel.add(centerPanel, BorderLayout.CENTER);
mainPanel.add(southPanel, BorderLayout.SOUTH);
this.getContentPane().add(mainPanel);
initTransferHandler();
KeyboardFocusManager keyManager
= KeyboardFocusManager.getCurrentKeyboardFocusManager();
ContactListSearchKeyDispatcher clKeyDispatcher
= new ContactListSearchKeyDispatcher( keyManager,
searchField,
this);
clKeyDispatcher.setContactList(srcContactList);
keyManager.addKeyEventDispatcher(clKeyDispatcher);
}
/**
* Returns the reason of this invite, if the user has specified one.
*
* @return the reason of this invite
*/
public String getReason()
{
return reasonArea.getText();
}
/**
* Adds an <tt>ActionListener</tt> to the contained "Invite" button.
*
* @param l the <tt>ActionListener</tt> to add
*/
public void addInviteButtonListener(ActionListener l)
{
this.inviteButton.addActionListener(l);
}
/**
* Adds an <tt>ActionListener</tt> to the contained "Cancel" button.
*
* @param l the <tt>ActionListener</tt> to add
*/
public void addCancelButtonListener(ActionListener l)
{
this.cancelButton.addActionListener(l);
}
/**
* Closes this dialog by clicking on the "Cancel" button.
*
* @param isEscaped indicates if this <tt>close</tt> is provoked by an
* escape
*/
protected void close(boolean isEscaped)
{
this.cancelButton.doClick();
}
/**
* Sets the current provider selected for this invite dialog.
*
* @param protocolProvider the protocol provider selected for this invite
* dialog
*/
protected void setCurrentProvider(ProtocolProviderService protocolProvider)
{
this.currentProvider = protocolProvider;
inviteContactTransferHandler.setBackupProvider(currentProvider);
}
/**
* Moves contacts from the left list to the right.
*
* @param contacts an Iterator over a list of <tt>UIContact</tt>s
*/
private void moveContactsFromLeftToRight(Iterator<UIContact> contacts)
{
while (contacts.hasNext())
{
moveContactFromLeftToRight(contacts.next());
}
}
/**
* Moves the given <tt>UIContact</tt> from left list to the right.
*
* @param uiContact the contact to move
*/
private void moveContactFromLeftToRight(UIContact uiContact)
{
destContactList.addContact(
new InviteUIContact(uiContact, currentProvider), null, false, false);
}
/**
* Moves contacts from the right list to the left.
*
* @param contacts an Iterator over a list of <tt>UIContact</tt>s
*/
protected void moveContactsFromRightToLeft(Iterator<UIContact> contacts)
{
while (contacts.hasNext())
{
moveContactFromRightToLeft(contacts.next());
}
}
/**
* Moves the given <tt>UIContact</tt> from left list to the right.
*
* @param uiContact the contact to move
*/
private void moveContactFromRightToLeft(UIContact uiContact)
{
destContactList.removeContact(uiContact);
}
/**
* Reloads icon for icon label.
*/
public void loadSkin()
{
iconLabel.setIcon(new ImageIcon(
ImageLoader.getImage(ImageLoader.INVITE_DIALOG_ICON)));
}
/**
* Creates the source contact list component.
*
* @return the created contact list component
*/
private Component createSrcContactListComponent()
{
srcContactList
= GuiActivator.getUIService().createContactListComponent();
srcContactList.setDragEnabled(true);
srcContactList.setRightButtonMenuEnabled(false);
srcContactList.setContactButtonsVisible(false);
srcContactList.setMultipleSelectionEnabled(true);
srcContactList.addContactListListener(new ContactListListener()
{
public void groupSelected(ContactListEvent evt) {}
public void groupClicked(ContactListEvent evt) {}
public void contactSelected(ContactListEvent evt) {}
public void contactClicked(ContactListEvent evt)
{
if (evt.getClickCount() > 1)
moveContactFromLeftToRight(evt.getSourceContact());
}
});
// By default we set the current filter to be the presence filter.
JScrollPane contactListScrollPane = new JScrollPane();
contactListScrollPane.setOpaque(false);
contactListScrollPane.getViewport().setOpaque(false);
contactListScrollPane.getViewport().add(srcContactList.getComponent());
contactListScrollPane.getViewport().setBorder(null);
contactListScrollPane.setViewportBorder(null);
contactListScrollPane.setBorder(null);
return contactListScrollPane;
}
/**
* Creates the destination contact list component.
*
* @return the created contact list component
*/
private Component createDestContactListComponent()
{
destContactList
= GuiActivator.getUIService().createContactListComponent();
destContactList.setContactButtonsVisible(false);
destContactList.setRightButtonMenuEnabled(false);
destContactList.setMultipleSelectionEnabled(true);
destContactList.addContactListListener(new ContactListListener()
{
public void groupSelected(ContactListEvent evt) {}
public void groupClicked(ContactListEvent evt) {}
public void contactSelected(ContactListEvent evt) {}
public void contactClicked(ContactListEvent evt)
{
if (evt.getClickCount() > 1)
moveContactFromRightToLeft(evt.getSourceContact());
}
});
// By default we set the current filter to be the presence filter.
JScrollPane contactListScrollPane = new JScrollPane();
contactListScrollPane.setOpaque(false);
contactListScrollPane.getViewport().setOpaque(false);
contactListScrollPane.getViewport().add(destContactList.getComponent());
contactListScrollPane.getViewport().setBorder(null);
contactListScrollPane.setViewportBorder(null);
contactListScrollPane.setBorder(null);
return contactListScrollPane;
}
/**
* Called when the ENTER key was typed when this container was the focused
* container. Performs the appropriate actions depending on the current
* state of the contained contact list.
*/
public void enterKeyTyped()
{
List<UIContact> selectedContacts = srcContactList.getSelectedContacts();
if (selectedContacts == null)
return;
moveContactsFromLeftToRight(selectedContacts.iterator());
}
/**
* Called when the CTRL-ENTER or CMD-ENTER keys were typed when this
* container was the focused container. Performs the appropriate actions
* depending on the current state of the contained contact list.
*/
public void ctrlEnterKeyTyped() {}
/**
* Initializes the transfer handler.
*/
private void initTransferHandler()
{
inviteContactTransferHandler
= new InviteContactTransferHandler(
destContactList,
InviteContactTransferHandler.DEST_TRANSFER_HANDLER,
true);
InviteContactTransferHandler srcContactTransferHandler
= new InviteContactTransferHandler(
srcContactList,
InviteContactTransferHandler.SOURCE_TRANSFER_HANDLER,
true);
if (srcContactList.getComponent() instanceof JComponent)
((JComponent) srcContactList).setTransferHandler(
srcContactTransferHandler);
if (destContactList.getComponent() instanceof JComponent)
((JComponent) destContactList).setTransferHandler(
inviteContactTransferHandler);
}
}
|