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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
|
/*
* 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;
import java.awt.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.lookandfeel.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.main.account.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.main.configforms.*;
import net.java.sip.communicator.impl.gui.main.contactlist.*;
import net.java.sip.communicator.impl.gui.main.contactlist.addcontact.*;
import net.java.sip.communicator.impl.gui.main.login.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.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.*;
/**
* An implementation of the <tt>UIService</tt> that gives access to other
* bundles to this particular swing ui implementation.
*
* @author Yana Stamcheva
*/
public class UIServiceImpl
implements UIService
{
private static final Logger logger = Logger.getLogger(UIServiceImpl.class);
private PopupDialogImpl popupDialog;
private AccountRegWizardContainerImpl wizardContainer;
private Map registeredPlugins = new Hashtable();
private Vector pluginComponentListeners = new Vector();
private static final List supportedContainers = new ArrayList();
static
{
supportedContainers.add(UIService.CONTAINER_MAIN_TOOL_BAR);
supportedContainers.add(UIService.CONTAINER_CONTACT_RIGHT_BUTTON_MENU);
supportedContainers.add(UIService.CONTAINER_GROUP_RIGHT_BUTTON_MENU);
supportedContainers.add(UIService.CONTAINER_TOOLS_MENU);
supportedContainers.add(UIService.CONTAINER_CHAT_TOOL_BAR);
supportedContainers.add(UIService.CONTAINER_CALL_HISTORY);
}
private static final Hashtable exportedWindows = new Hashtable();
private MainFrame mainFrame;
private LoginManager loginManager;
private ContactListPanel contactListPanel;
private ConfigurationFrame configurationFrame;
private boolean exitOnClose = true;
/**
* Creates an instance of <tt>UIServiceImpl</tt>.
*/
public UIServiceImpl()
{}
/**
* Initializes all frames and panels and shows the gui.
*/
public void loadApplicationGui()
{
this.setDefaultThemePack();
this.mainFrame = new MainFrame();
this.loginManager = new LoginManager(mainFrame);
this.contactListPanel = mainFrame.getContactListPanel();
this.popupDialog = new PopupDialogImpl();
this.wizardContainer = new AccountRegWizardContainerImpl(mainFrame);
this.configurationFrame = new ConfigurationFrame(mainFrame);
mainFrame.setContactList(GuiActivator.getMetaContactListService());
if(ConfigurationManager.isApplicationVisible())
SwingUtilities.invokeLater(new RunApplicationGui());
SwingUtilities.invokeLater(new RunLoginGui());
this.initExportedWindows();
}
/**
* Implements addComponent in UIService interface. Stores a plugin component
* and fires a PluginComponentEvent to inform all interested listeners that
* a plugin component has been added.
*
* @param containerID The <tt>ContainerID</tt> of the plugable container.
* @param component The component to add.
*
* @see UIService#addComponent(ContainerID, Object)
*
* @throws java.lang.ClassCastException if <tt>component</tt> is not an
* instance of a java.awt.Component
* @throws java.lang.IllegalArgumentException if no component exists for
* the specified container id.
*/
public void addComponent(ContainerID containerID, Object component)
throws ClassCastException, IllegalArgumentException
{
if (!supportedContainers.contains(containerID))
{
throw new IllegalArgumentException(
"The constraint that you specified is not"
+ " supported by this UIService implementation.");
}
else if (!(component instanceof Component))
{
throw new ClassCastException(
"The specified plugin is not a valid swing or awt component.");
}
else
{
if (registeredPlugins.containsKey(containerID))
{
((Vector) registeredPlugins.get(containerID)).add(component);
}
else
{
Vector plugins = new Vector();
plugins.add(component);
registeredPlugins.put(containerID, plugins);
}
this.firePluginEvent(component, containerID,
PluginComponentEvent.PLUGIN_COMPONENT_ADDED);
}
}
/**
* Implements <code>UIService.addComponent(ContainerID, String, Object)
* </code>.
* For now this method only invokes addComponent(containerID, component).
*
* @param containerID The <tt>ContainerID</tt> of the plugable container.
* @param constraint a constraint indicating how the component should be
* added to the container.
* @param component the component we are adding.
*
* @see UIService#addComponent(ContainerID, String, Object)
* @throws java.lang.ClassCastException if <tt>component</tt> is not an
* instance of a java.awt.Component
* @throws java.lang.IllegalArgumentException if no component exists for
* the specified container id.
*/
public void addComponent(ContainerID containerID, String constraint,
Object component) throws ClassCastException, IllegalArgumentException
{
this.addComponent(containerID, component);
}
/**
* Implements <code>UIService.addComponent(ContainerID, String, Object)
* </code>.
* For now this method only invokes addComponent(containerID, component).
*
* @param containerID The <tt>ContainerID</tt> of the plugable container.
* @param component the component we are adding.
*
* @throws java.lang.ClassCastException if <tt>component</tt> is not an
* instance of a java.awt.Component
* @throws java.lang.IllegalArgumentException if no component exists for
* the specified container id.
*/
public void addComponent(ContainerID containerID,
ContactAwareComponent component) throws ClassCastException,
IllegalArgumentException
{
if (!(component instanceof Component))
{
throw new ClassCastException(
"The specified plugin is not a valid swing or awt component.");
}
this.addComponent(containerID, (Component) component);
}
/**
* Implements <code>UIService.addComponent(ContainerID, String, Object)
* </code>.
* For now this method only invokes addComponent(containerID, component).
*
* @param containerID The <tt>ContainerID</tt> of the plugable container.
* @param constraint a constraint indicating how the component should be
* added to the container.
* @param component the component we are adding.
*
* @throws java.lang.ClassCastException if <tt>component</tt> is not an
* instance of a java.awt.Component
* @throws java.lang.IllegalArgumentException if no component exists for
* the specified container id.
*/
public void addComponent(ContainerID containerID, String constraint,
ContactAwareComponent component) throws ClassCastException,
IllegalArgumentException
{
this.addComponent(containerID, constraint, component);
}
/**
* Implements <code>UISercie.getSupportedContainers</code>. Returns the
* list of supported containers by this implementation .
*
* @see UIService#getSupportedContainers()
* @return an Iterator over all supported containers.
*/
public Iterator getSupportedContainers()
{
return Collections.unmodifiableList(supportedContainers).iterator();
}
/**
* Implements getComponentsForConstraint in UIService interface.
*
* @param containerID the id of the container whose components we'll be
* retrieving.
* @see UIService#getComponentsForContainer(ContainerID)
*
* @return an iterator over all components added in the container with ID
* <tt>containerID</tt>
*
* @throws java.lang.IllegalArgumentException if containerID does not
* correspond to a container used in this implementation.
*/
public Iterator getComponentsForContainer(ContainerID containerID)
throws IllegalArgumentException
{
if (!supportedContainers.contains(containerID))
throw new IllegalArgumentException(
"The container that you specified is not "
+ "supported by this UIService implementation.");
Vector plugins = new Vector();
Object o = registeredPlugins.get(containerID);
if (o != null)
{
plugins = (Vector) o;
}
return plugins.iterator();
}
/**
* Not yet implemented.
*
* @param containerID the ID of the container whose constraints we'll be
* retrieving.
*
* @see UIService#getConstraintsForContainer(ContainerID)
*
* @return Iterator an <tt>Iterator</tt> for all constraintes supported by
* the container corresponding to containerID.
*/
public Iterator getConstraintsForContainer(ContainerID containerID)
{
return null;
}
/**
* Creates the corresponding PluginComponentEvent and notifies all
* <tt>ContainerPluginListener</tt>s that a plugin component is added or
* removed from the container.
*
* @param pluginComponent the plugin component that is added to the
* container.
* @param containerID the containerID that corresponds to the container
* where the component is added.
* @param eventID one of the PLUGIN_COMPONENT_XXX static fields indicating
* the nature of the event.
*/
private void firePluginEvent(Object pluginComponent,
ContainerID containerID, int eventID)
{
PluginComponentEvent evt = new PluginComponentEvent(pluginComponent,
containerID, eventID);
logger.trace("Will dispatch the following plugin component event: "
+ evt);
synchronized (pluginComponentListeners)
{
Iterator listeners = this.pluginComponentListeners.iterator();
while (listeners.hasNext())
{
PluginComponentListener l = (PluginComponentListener) listeners
.next();
switch (evt.getEventID())
{
case PluginComponentEvent.PLUGIN_COMPONENT_ADDED:
l.pluginComponentAdded(evt);
break;
case PluginComponentEvent.PLUGIN_COMPONENT_REMOVED:
l.pluginComponentRemoved(evt);
break;
default:
logger.error("Unknown event type " + evt.getEventID());
}
}
}
}
/**
* Implements <code>isVisible</code> in the UIService interface. Checks if
* the main application window is visible.
*
* @return <code>true</code> if main application window is visible,
* <code>false</code> otherwise
* @see UIService#isVisible()
*/
public boolean isVisible()
{
if (mainFrame.isVisible())
{
if (mainFrame.getExtendedState() == JFrame.ICONIFIED)
return false;
else
return true;
}
else
return false;
}
/**
* Implements <code>setVisible</code> in the UIService interface. Shows or
* hides the main application window depending on the parameter
* <code>visible</code>.
*
* @param isVisible true if we are to show the main application frame and
* false otherwise.
*
* @see UIService#setVisible(boolean)
*/
public void setVisible(boolean isVisible)
{
this.mainFrame.setVisible(isVisible);
if(isVisible)
this.mainFrame.toFront();
}
/**
* Implements <code>minimize</code> in the UIService interface. Minimizes
* the main application window.
*
* @see UIService#minimize()
*/
public void minimize()
{
this.mainFrame.setExtendedState(JFrame.ICONIFIED);
}
/**
* Implements <code>maximize</code> in the UIService interface. Maximizes
* the main application window.
*
* @see UIService#maximize()
*/
public void maximize()
{
this.mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
/**
* Implements <code>restore</code> in the UIService interface. Restores
* the main application window.
*
* @see UIService#restore()
*/
public void restore()
{
if (mainFrame.isVisible())
{
if (mainFrame.getState() == JFrame.ICONIFIED)
mainFrame.setState(JFrame.NORMAL);
mainFrame.toFront();
}
else
mainFrame.setVisible(true);
}
/**
* Implements <code>resize</code> in the UIService interface. Resizes the
* main application window.
*
* @param height the new height of tha main application frame.
* @param width the new width of the main application window.
*
* @see UIService#resize(int, int)
*/
public void resize(int width, int height)
{
this.mainFrame.setSize(width, height);
}
/**
* Implements <code>move</code> in the UIService interface. Moves the main
* application window to the point with coordinates - x, y.
*
* @param x the value of X where the main application frame is to be placed.
* @param y the value of Y where the main application frame is to be placed.
*
* @see UIService#move(int, int)
*/
public void move(int x, int y)
{
this.mainFrame.setLocation(x, y);
}
/**
* Implements the <code>UIService.setExitOnMainWindowClose</code>. Sets a
* boolean property, which indicates whether the application should be
* exited when the main application window is closed.
*
* @param exitOnClose specifies if closing the main application window
* should also be exiting the application.
*/
public void setExitOnMainWindowClose(boolean exitOnClose)
{
this.exitOnClose = exitOnClose;
if (exitOnClose)
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
else
mainFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
/**
* Implements the <code>UIService.getExitOnMainWindowClose</code>.
* Returns the boolean property, which indicates whether the application
* should be exited when the main application window is closed.
*
* @return determines whether the UI impl would exit the application when
* the main application window is closed.
*/
public boolean getExitOnMainWindowClose()
{
return this.exitOnClose;
}
/**
* Adds all <tt>ExportedWindow</tt>s to the list of application windows,
* which could be used from other bundles. Once registered in the
* <tt>UIService</tt> this window could be obtained through the
* <tt>getExportedWindow(WindowID)</tt> method and could be shown,
* hidden, resized, moved, etc.
*/
public void initExportedWindows()
{
AboutWindow aboutWindow = new AboutWindow(mainFrame);
AddContactWizard addContactWizard = new AddContactWizard(mainFrame);
exportedWindows.put(aboutWindow.getIdentifier(), aboutWindow);
exportedWindows.put(configurationFrame.getIdentifier(), configurationFrame);
exportedWindows.put(addContactWizard.getIdentifier(), addContactWizard);
}
/**
* Registers the given <tt>ExportedWindow</tt> to the list of windows that
* could be accessed from other bundles.
*
* @param window the window to be exported
*/
public void registerExportedWindow(ExportedWindow window)
{
exportedWindows.put(window.getIdentifier(), window);
}
/**
* Sets the contact list service to this UI Service implementation.
* @param contactList the MetaContactList service
*/
public void setContactList(MetaContactListService contactList)
{
this.mainFrame.setContactList(contactList);
}
public void addPluginComponentListener(PluginComponentListener l)
{
synchronized (pluginComponentListeners)
{
pluginComponentListeners.add(l);
}
}
public void removePluginComponentListener(PluginComponentListener l)
{
synchronized (pluginComponentListeners)
{
pluginComponentListeners.remove(l);
}
}
/**
* Implements <code>getSupportedExportedWindows</code> in the UIService
* interface. Returns an iterator over a set of all windows exported by
* this implementation.
*
* @return an Iterator over all windows exported by this implementation of
* the UI service.
*
* @see UIService#getSupportedExportedWindows()
*/
public Iterator getSupportedExportedWindows()
{
return Collections.unmodifiableMap(exportedWindows).keySet().iterator();
}
/**
* Implements the <code>getExportedWindow</code> in the UIService
* interface. Returns the window corresponding to the given
* <tt>WindowID</tt>.
*
* @param windowID the id of the window we'd like to retrieve.
*
* @return a reference to the <tt>ExportedWindow</tt> instance corresponding
* to <tt>windowID</tt>.
* @see UIService#getExportedWindow(WindowID)
*/
public ExportedWindow getExportedWindow(WindowID windowID)
{
if (exportedWindows.containsKey(windowID))
{
return (ExportedWindow) exportedWindows.get(windowID);
}
return null;
}
/**
* Implements the <code>UIService.isExportedWindowSupported</code> method.
* Checks if there's an exported component for the given
* <tt>WindowID</tt>.
*
* @param windowID the id of the window that we're making the query for.
*
* @return true if a window with the corresponding windowID is exported by
* the UI service implementation and false otherwise.
*
* @see UIService#isExportedWindowSupported(WindowID)
*/
public boolean isExportedWindowSupported(WindowID windowID)
{
return exportedWindows.containsKey(windowID);
}
/**
* Implements <code>getPopupDialog</code> in the UIService interface.
* Returns a <tt>PopupDialog</tt> that could be used to show simple
* messages, warnings, errors, etc.
*
* @return a <tt>PopupDialog</tt> that could be used to show simple
* messages, warnings, errors, etc.
*
* @see UIService#getPopupDialog()
*/
public PopupDialog getPopupDialog()
{
return this.popupDialog;
}
/**
* Implements <code>getChat</code> in the UIService interface. If a
* chat for the given contact exists already - returns it, otherwise
* creates a new one.
*
* @param contact the contact that we'd like to retrieve a chat window for.
*
* @return a Chat corresponding to the specified contact.
*
* @see UIService#getChat(Contact)
*/
public Chat getChat(Contact contact)
{
MetaContact metaContact = mainFrame.getContactList()
.findMetaContactByContact(contact);
ChatWindowManager chatWindowManager = mainFrame.getChatWindowManager();
ChatPanel chatPanel = chatWindowManager.getContactChat(metaContact);
return chatPanel;
}
/**
* Returns the selected <tt>Chat</tt>.
*
* @return the selected <tt>Chat</tt>.
*/
public Chat getCurrentChat()
{
ChatWindowManager chatWindowManager = mainFrame.getChatWindowManager();
return chatWindowManager.getSelectedChat();
}
/**
* Implements the <code>UIService.isContainerSupported</code> method.
* Checks if the plugable container with the given ContainerID is supported
* by this implementation.
*
* @param containderID the id of the container that we're making the query
* for.
*
* @return true if the container with the specified id is exported by the
* implementation of the UI service and false otherwise.
*
* @see UIService#isContainerSupported(ContainerID)
*/
public boolean isContainerSupported(ContainerID containderID)
{
return supportedContainers.contains(containderID);
}
/**
* Implements the <code>UIService.getAccountRegWizardContainer</code>
* method. Returns the current implementation of the
* <tt>AccountRegistrationWizardContainer</tt>.
*
* @see UIService#getAccountRegWizardContainer()
*
* @return a reference to the currently valid instance of
* <tt>AccountRegistrationWizardContainer</tt>.
*/
public AccountRegistrationWizardContainer getAccountRegWizardContainer()
{
return this.wizardContainer;
}
/**
* Implements the <code>UIService.getConfigurationWindow</code>. Returns
* the current implementation of the <tt>ConfigurationWindow</tt>
* interface.
*
* @see UIService#getConfigurationWindow()
*
* @return a reference to the currently valid instance of
* <tt>ConfigurationWindow</tt>.
*/
public ConfigurationWindow getConfigurationWindow()
{
return this.configurationFrame;
}
public ExportedWindow getAuthenticationWindow(
ProtocolProviderService protocolProvider,
String realm, UserCredentials userCredentials)
{
return new AuthenticationWindow(mainFrame, protocolProvider,
realm, userCredentials);
}
/**
* Returns the LoginManager.
* @return the LoginManager
*/
public LoginManager getLoginManager()
{
return loginManager;
}
/**
* Returns the <tt>MainFrame</tt>. This is the class defining the main
* application window.
*
* @return the <tt>MainFrame</tt>
*/
public MainFrame getMainFrame()
{
return mainFrame;
}
/**
* The <tt>RunLogin</tt> implements the Runnable interface and is used to
* shows the login windows in a seperate thread.
*/
private class RunLoginGui implements Runnable {
public void run() {
loginManager.runLogin(mainFrame);
}
}
/**
* The <tt>RunApplication</tt> implements the Runnable interface and is used to
* shows the main application window in a separate thread.
*/
private class RunApplicationGui implements Runnable {
public void run() {
mainFrame.setVisible(true);
}
}
/**
* Sets the look&feel and the theme.
*/
private void setDefaultThemePack() {
SIPCommLookAndFeel lf = new SIPCommLookAndFeel();
SIPCommLookAndFeel.setCurrentTheme(new SIPCommDefaultTheme());
// we need to set the UIDefaults class loader so that it may access
// resources packed inside OSGI bundles
UIManager.put("ClassLoader", getClass().getClassLoader());
try {
UIManager.setLookAndFeel(lf);
} catch (UnsupportedLookAndFeelException e) {
logger.error("The provided Look & Feel is not supported.", e);
}
}
}
|