diff options
author | Yana Stamcheva <yana@jitsi.org> | 2007-09-12 16:08:26 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2007-09-12 16:08:26 +0000 |
commit | cd5de841642ce7da4088c1c8fa61f99616570c46 (patch) | |
tree | dab406767551732b6400cb76be2be53daca24d04 /src | |
parent | 612b6f61810ab3f91acaa2540eaef351b344a9c9 (diff) | |
download | jitsi-cd5de841642ce7da4088c1c8fa61f99616570c46.zip jitsi-cd5de841642ce7da4088c1c8fa61f99616570c46.tar.gz jitsi-cd5de841642ce7da4088c1c8fa61f99616570c46.tar.bz2 |
Systray fixes:
- Status menus fixed
- Presence listener added to the systray in order to update status icons when the status is changed.
- Status icons fixed for protocols not supporting presence
Diffstat (limited to 'src')
8 files changed, 321 insertions, 153 deletions
diff --git a/src/net/java/sip/communicator/impl/systray/jdic/LightGrayFilter.java b/src/net/java/sip/communicator/impl/systray/jdic/LightGrayFilter.java new file mode 100644 index 0000000..3c72127 --- /dev/null +++ b/src/net/java/sip/communicator/impl/systray/jdic/LightGrayFilter.java @@ -0,0 +1,46 @@ +/* + * 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.systray.jdic; + +import java.awt.*; +import java.awt.image.*; +import javax.swing.*; + +/** + * An image filter that "disables" an image by turning + * it into a grayscale image, and brightening the pixels + * in the image. Used by buttons to create an image for + * a disabled button. Creates a more brighter image than + * the javax.swing.GrayFilter. + * + * @author Yana Stamcheva + */ +public class LightGrayFilter extends GrayFilter { + + /** + * Creates an instance of a LightGrayFilter. + * @param b a boolean -- true if the pixels should be brightened + * @param p an int in the range 0..100 that determines the percentage + * of gray, where 100 is the darkest gray, and 0 is the lightest + */ + public LightGrayFilter(boolean b, int p) { + super(b, p); + } + + /** + * Creates a disabled image. + * @param i The source image. + * @return A disabled image based on the source image. + */ + public static Image createDisabledImage(Image i) { + LightGrayFilter filter = new LightGrayFilter(true, 65); + ImageProducer prod = new FilteredImageSource(i.getSource(), filter); + Image grayImage = Toolkit.getDefaultToolkit().createImage(prod); + + return grayImage; + } +} diff --git a/src/net/java/sip/communicator/impl/systray/jdic/ProviderRegistration.java b/src/net/java/sip/communicator/impl/systray/jdic/ProviderRegistration.java index 6fb1c0b..c80656d 100644 --- a/src/net/java/sip/communicator/impl/systray/jdic/ProviderRegistration.java +++ b/src/net/java/sip/communicator/impl/systray/jdic/ProviderRegistration.java @@ -33,7 +33,8 @@ public class ProviderRegistration /** * The logger for this class. */ - private Logger logger = Logger.getLogger(ProviderRegistration.class.getName()); + private Logger logger + = Logger.getLogger(ProviderRegistration.class.getName()); /** * Creates an instance of <tt>ProviderRegistration</tt>. @@ -102,6 +103,4 @@ public class ProviderRegistration return userCredentials; } - - } diff --git a/src/net/java/sip/communicator/impl/systray/jdic/ProviderUnRegistration.java b/src/net/java/sip/communicator/impl/systray/jdic/ProviderUnRegistration.java index 373a483..0d41e12 100644 --- a/src/net/java/sip/communicator/impl/systray/jdic/ProviderUnRegistration.java +++ b/src/net/java/sip/communicator/impl/systray/jdic/ProviderUnRegistration.java @@ -28,8 +28,9 @@ public class ProviderUnRegistration /** * The logger for this class. */ - private Logger logger = Logger.getLogger(ProviderUnRegistration.class.getName()); - + private Logger logger + = Logger.getLogger(ProviderUnRegistration.class.getName()); + /** * Creates an instance of <tt>ProviderUnRegistration</tt>. * @param protocolProvider the provider we want to unregister diff --git a/src/net/java/sip/communicator/impl/systray/jdic/StatusSelector.java b/src/net/java/sip/communicator/impl/systray/jdic/StatusSelector.java index 3796743..a3a49d4 100644 --- a/src/net/java/sip/communicator/impl/systray/jdic/StatusSelector.java +++ b/src/net/java/sip/communicator/impl/systray/jdic/StatusSelector.java @@ -50,17 +50,18 @@ public class StatusSelector /** * Creates an instance of StatusSelector * - * @param tray a reference of the parent <tt>Systray</tt> - * @param pro the protocol provider - * @param pre the presence status + * @param jdicSystray a reference of the parent <tt>Systray</tt> + * @param provider the protocol provider + * @param presence the presence status */ - public StatusSelector(SystrayServiceJdicImpl tray, - ProtocolProviderService pro, OperationSetPresence pre) + public StatusSelector( SystrayServiceJdicImpl jdicSystray, + ProtocolProviderService provider, + OperationSetPresence presence) { - this.parentSystray = tray; - this.provider = pro; - this.presence = pre; + this.parentSystray = jdicSystray; + this.provider = provider; + this.presence = presence; /* the parent item */ @@ -83,7 +84,6 @@ public class StatusSelector this.add(item); } - } /** @@ -145,7 +145,19 @@ public class StatusSelector } } } - + + /** + * Stops the timer that manages the connecting animated icon. + */ + public void updateStatus(PresenceStatus presenceStatus) + { + logger.trace("Systray update status for provider: " + + provider.getAccountID().getAccountAddress() + + ". The new status will be: " + presenceStatus.getStatusName()); + + this.setIcon(new ImageIcon(presenceStatus.getStatusIcon())); + } + /** * This class allow to use a thread to change the presence status. */ @@ -157,7 +169,7 @@ public class StatusSelector { this.status = status; } - + public void run() { try { @@ -179,23 +191,30 @@ public class StatusSelector if (e1.getErrorCode() == OperationFailedException.GENERAL_ERROR) { - + logger.error( + "General error occured while " + + "publishing presence status.", + e1); } else if (e1.getErrorCode() == OperationFailedException .NETWORK_FAILURE) { - + logger.error( + "Network failure occured while " + + "publishing presence status.", + e1); } else if (e1.getErrorCode() == OperationFailedException .PROVIDER_NOT_REGISTERED) { - + logger.error( + "Protocol provider must be" + + "registered in order to change status.", + e1); } - logger.error("Error - changing status", e1); } } } - } diff --git a/src/net/java/sip/communicator/impl/systray/jdic/StatusSimpleSelector.java b/src/net/java/sip/communicator/impl/systray/jdic/StatusSimpleSelector.java index 4901e3b..1a6908d 100644 --- a/src/net/java/sip/communicator/impl/systray/jdic/StatusSimpleSelector.java +++ b/src/net/java/sip/communicator/impl/systray/jdic/StatusSimpleSelector.java @@ -48,51 +48,54 @@ public class StatusSimpleSelector * The menu item for the online status */ private JMenuItem onlineItem = new JMenuItem( - Resources.getString("onlineStatus"), - new ImageIcon(Resources.getImage("sipLogo"))); + Resources.getString("onlineStatus")); /** * The menu item for the offline status */ private JMenuItem offlineItem = new JMenuItem( - Resources.getString("offlineStatus"), - new ImageIcon(Resources.getImage("sipLogoOffline"))); + Resources.getString("offlineStatus")); /** * Creates an instance of <tt>StatusSimpleSelector</tt> * - * @param tray a reference of the parent <tt>Systray</tt> - * @param pro the protocol provider + * @param jdicSystray a reference of the parent <tt>Systray</tt> + * @param protocolProvider the protocol provider */ - public StatusSimpleSelector(SystrayServiceJdicImpl tray,ProtocolProviderService pro) + public StatusSimpleSelector(SystrayServiceJdicImpl jdicSystray, + ProtocolProviderService protocolProvider) { - - this.provider = pro; - this.parentSystray = tray; - + + this.provider = protocolProvider; + this.parentSystray = jdicSystray; + /* the parent item */ - + ImageIcon icon; - + if(provider.isRegistered()) { - icon = new ImageIcon(Resources.getImage("sipLogo")); + System.out.println("EHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOoo"); + icon = new ImageIcon(protocolProvider.getProtocolIcon() + .getIcon(ProtocolIcon.ICON_SIZE_16x16)); } else { - icon = new ImageIcon(Resources.getImage("sipLogoOffline")); + icon = new ImageIcon(LightGrayFilter.createDisabledImage( + new ImageIcon(protocolProvider.getProtocolIcon() + .getIcon(ProtocolIcon.ICON_SIZE_16x16)).getImage())); } - + this.setText(provider.getAccountID().getUserID()); this.setIcon(icon); - + /* the menu itself */ - + this.onlineItem.addActionListener(this); this.offlineItem.addActionListener(this); - + this.onlineItem.setName("online"); this.offlineItem.setName("offline"); - + this.add(onlineItem); this.add(offlineItem); } @@ -126,4 +129,16 @@ public class StatusSimpleSelector } } } + + /** + * Stops the timer that manages the connecting animated icon. + */ + public void updateStatus(PresenceStatus presenceStatus) + { + logger.trace("Systray update status for provider: " + + provider.getAccountID().getAccountAddress() + + ". The new status will be: " + presenceStatus.getStatusName()); + + this.setIcon(new ImageIcon(presenceStatus.getStatusIcon())); + } } diff --git a/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java b/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java index 4c0b3fe..a89e316 100644 --- a/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java +++ b/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java @@ -7,14 +7,18 @@ package net.java.sip.communicator.impl.systray.jdic; - import java.awt.*; +import java.beans.*; import java.util.*; import javax.swing.*; import net.java.sip.communicator.impl.systray.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.protocol.event.*; +import net.java.sip.communicator.util.*; + +import org.osgi.framework.*; /** * The <tt>StatusSubMenu</tt> provides a menu which allow @@ -26,15 +30,20 @@ import net.java.sip.communicator.service.protocol.*; */ public class StatusSubMenu -extends JMenu -//implements ActionListener + extends JMenu { - /** * A reference of <tt>Systray</tt> */ private SystrayServiceJdicImpl parentSystray; - + + /** + * Contains all accounts and corresponding menus. + */ + private Hashtable accountSelectors = new Hashtable(); + + private Logger logger = Logger.getLogger(StatusSubMenu.class); + /** * Creates an instance of <tt>StatusSubMenu</tt>. * @param tray a reference of the parent <tt>Systray</tt> @@ -49,46 +58,163 @@ extends JMenu new ImageIcon(Resources.getImage("statusMenuIcon"))); /* makes the menu look better */ - this.setPreferredSize(new Dimension(28, 24)); - - update(); - + this.setPreferredSize(new java.awt.Dimension(28, 24)); + + this.init(); } - + /** - * Updates the Menu by retrieving provider informations + * Adds the account corresponding to the given protocol provider to this + * menu. + * + * @param protocolProvider the protocol provider corresponding to the + * account to add */ - public void update() - { - this.removeAll(); - - Iterator it=parentSystray.getProtocolProviders(); - - while(it.hasNext()){ - ProtocolProviderService provider = - (ProtocolProviderService) it.next(); - - Map supportedOperationSets - = provider.getSupportedOperationSets(); - - OperationSetPresence presence = (OperationSetPresence) - supportedOperationSets.get(OperationSetPresence.class.getName()); - - if (presence == null) - { - StatusSimpleSelector s = - new StatusSimpleSelector(parentSystray,provider); - - this.add(s); - } - else - { - StatusSelector s = - new StatusSelector(parentSystray,provider,presence); - - this.add(s); + private void addAccount(ProtocolProviderService protocolProvider) + { + OperationSetPresence presence = (OperationSetPresence) + protocolProvider.getOperationSet(OperationSetPresence.class); + + if (presence == null) + { + StatusSimpleSelector simpleSelector = + new StatusSimpleSelector(parentSystray, protocolProvider); + + this.accountSelectors.put( protocolProvider.getAccountID(), + simpleSelector); + this.add(simpleSelector); + } + else + { + StatusSelector statusSelector = + new StatusSelector( parentSystray, + protocolProvider, + presence); + + this.accountSelectors.put( protocolProvider.getAccountID(), + statusSelector); + this.add(statusSelector); + + presence.addProviderPresenceStatusListener( + new SystrayProviderPresenceStatusListener()); + } + } + + /** + * Removes the account corresponding to the given protocol provider from + * this menu. + * + * @param protocolProvider the protocol provider corresponding to the + * account to remove. + */ + private void removeAccount(ProtocolProviderService protocolProvider) + { + Component c = (Component) this.accountSelectors + .get(protocolProvider.getAccountID()); + + this.remove(c); + } + + /** + * We fill the protocolProviderTable with all + * running protocol providers at the start of + * the bundle. + */ + private void init() + { + SystrayActivator.bundleContext + .addServiceListener(new ProtocolProviderServiceListener()); + + ServiceReference[] protocolProviderRefs = null; + try + { + protocolProviderRefs + = SystrayActivator.bundleContext.getServiceReferences( + ProtocolProviderService.class.getName(),null); + } + catch (InvalidSyntaxException ex) + { + // this shouldn't happen since we're providing no parameter string + // but let's log just in case. + logger .error("Error while retrieving service refs", ex); + return; + } + + // in case we found any + if (protocolProviderRefs != null) + { + + for (int i = 0; i < protocolProviderRefs.length; i++) + { + ProtocolProviderService provider + = (ProtocolProviderService) SystrayActivator.bundleContext + .getService(protocolProviderRefs[i]); + + this.addAccount(provider); } } } - + + /** + * Listens for <tt>ServiceEvent</tt>s indicating that a + * <tt>ProtocolProviderService</tt> has been registered and completes the + * account status menu. + */ + private class ProtocolProviderServiceListener implements ServiceListener + { + /** + * When a service is registered or unregistered, we update + * the provider tables and add/remove listeners (if it supports + * BasicInstantMessenging implementation) + * + * @param event ServiceEvent + */ + public void serviceChanged(ServiceEvent event) + { + Object service = SystrayActivator.bundleContext + .getService( event.getServiceReference()); + + if (! (service instanceof ProtocolProviderService)) + return; + + ProtocolProviderService provider = (ProtocolProviderService)service; + + if (event.getType() == ServiceEvent.REGISTERED) + addAccount(provider); + + if (event.getType() == ServiceEvent.UNREGISTERING) + removeAccount(provider); + } + } + + /** + * Listens for all providerStatusChanged and providerStatusMessageChanged + * events in order to refresh the account status panel, when a status is + * changed. + */ + private class SystrayProviderPresenceStatusListener + implements ProviderPresenceStatusListener + { + /** + * Fired when an account has changed its status. We update the icon + * in the menu. + */ + public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt) + { + ProtocolProviderService pps = evt.getProvider(); + + StatusSelector selectorBox + = (StatusSelector) accountSelectors.get(pps.getAccountID()); + + if(selectorBox == null) + return; + + selectorBox.updateStatus(evt.getNewStatus()); + } + + public void providerStatusMessageChanged(PropertyChangeEvent evt) + { + } + } + }
\ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/systray/jdic/SystrayServiceJdicImpl.java b/src/net/java/sip/communicator/impl/systray/jdic/SystrayServiceJdicImpl.java index b656d22..89a3439 100644 --- a/src/net/java/sip/communicator/impl/systray/jdic/SystrayServiceJdicImpl.java +++ b/src/net/java/sip/communicator/impl/systray/jdic/SystrayServiceJdicImpl.java @@ -16,12 +16,12 @@ import net.java.sip.communicator.impl.systray.*; import net.java.sip.communicator.service.configuration.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; import net.java.sip.communicator.service.systray.*; import net.java.sip.communicator.service.systray.event.*; import net.java.sip.communicator.util.*; import org.jdesktop.jdic.tray.*; +import org.osgi.framework.*; /** * The <tt>Systray</tt> provides a Icon and the associated <tt>TrayMenu</tt> @@ -49,11 +49,6 @@ public class SystrayServiceJdicImpl private TrayMenu menu; /** - * The list of all providers. - */ - private Map protocolProviderTable = new LinkedHashMap(); - - /** * The list of all added popup message listeners. */ private Vector popupMessageListeners = new Vector(); @@ -158,29 +153,16 @@ public class SystrayServiceJdicImpl } /** - * Returns a set of all protocol providers. - * - * @return a set of all protocol providers. - */ - public Iterator getProtocolProviders() - { - return this.protocolProviderTable.values().iterator(); - } - /** - * Display in a balloon the newly received message - * @param evt the event containing the message - */ - public void messageReceived(MessageReceivedEvent evt) - { - - } - - /** * Saves the last status for all accounts. This information is used - * on loging. Each time user logs in he's logged with the same status + * on logging. Each time user logs in he's logged with the same status * as he was the last time before closing the application. + * + * @param protocolProvider the protocol provider for which we save the + * last selected status + * @param statusName the status name to save */ - public void saveStatusInformation(ProtocolProviderService protocolProvider, + public void saveStatusInformation( + ProtocolProviderService protocolProvider, String statusName) { ConfigurationService configService @@ -234,11 +216,16 @@ public class SystrayServiceJdicImpl /** * Implements the <tt>SystratService.showPopupMessage</tt> method. Shows - * a popup message, above the systray icon, which has the given title, + * a pop up message, above the Systray icon, which has the given title, * message content and message type. + * + * @param title the title of the message + * @param messageContent the content text + * @param messageType the type of the message */ - public void showPopupMessage(String title, String messageContent, - int messageType) + public void showPopupMessage( String title, + String messageContent, + int messageType) { int trayMsgType = TrayIcon.NONE_MESSAGE_TYPE; @@ -258,6 +245,8 @@ public class SystrayServiceJdicImpl /** * Implements the <tt>SystrayService.addPopupMessageListener</tt> method. + * + * @param listener the listener to add */ public void addPopupMessageListener(SystrayPopupMessageListener listener) { @@ -269,6 +258,8 @@ public class SystrayServiceJdicImpl /** * Implements the <tt>SystrayService.removePopupMessageListener</tt> method. + * + * @param listener the listener to remove */ public void removePopupMessageListener(SystrayPopupMessageListener listener) { @@ -280,7 +271,7 @@ public class SystrayServiceJdicImpl /** * Notifies all interested listeners that a <tt>SystrayPopupMessageEvent</tt> - * has occured + * has occured. * * @param sourceObject the source of this event */ @@ -307,7 +298,8 @@ public class SystrayServiceJdicImpl } /** - * Sets a new systray icon. + * Sets a new Systray icon. + * * @param image the icon to set. */ public void setSystrayIcon(byte[] image) diff --git a/src/net/java/sip/communicator/impl/systray/jdic/TrayMenu.java b/src/net/java/sip/communicator/impl/systray/jdic/TrayMenu.java index 783bf95..e46baa7 100644 --- a/src/net/java/sip/communicator/impl/systray/jdic/TrayMenu.java +++ b/src/net/java/sip/communicator/impl/systray/jdic/TrayMenu.java @@ -10,7 +10,6 @@ package net.java.sip.communicator.impl.systray.jdic; import java.awt.event.*; import javax.swing.*; -import javax.swing.event.*; import net.java.sip.communicator.impl.systray.*; import net.java.sip.communicator.service.gui.*; @@ -19,15 +18,14 @@ import net.java.sip.communicator.util.*; import org.osgi.framework.*; /** - * The <tt>Traymenu</tt> is the menu that appears when the user right-click - * on the systray icon + * The <tt>TrayMenu</tt> is the menu that appears when the user right-click + * on the Systray icon. * * @author Nicolas Chamouard */ public class TrayMenu extends JPopupMenu - implements ActionListener, - PopupMenuListener + implements ActionListener { /** * The logger for this class. @@ -51,7 +49,7 @@ public class TrayMenu Resources.getString("addContact"), new ImageIcon(Resources.getImage("addContactIcon"))); - private StatusSubMenu setStatusMenu; + private StatusSubMenu statusMenu; /** * The configuration window called by the menu item "settings" @@ -66,25 +64,23 @@ public class TrayMenu public TrayMenu(SystrayServiceJdicImpl tray) { parentSystray = tray; - - setStatusMenu = new StatusSubMenu(tray); - + + statusMenu = new StatusSubMenu(tray); + this.add(settingsItem); this.add(addContactMenuItem); this.addSeparator(); - this.add(setStatusMenu); + this.add(statusMenu); this.addSeparator(); this.add(closeItem); - + this.settingsItem.setName("settings"); this.closeItem.setName("close"); this.addContactMenuItem.setName("addContact"); - + this.settingsItem.addActionListener(this); this.closeItem.addActionListener(this); this.addContactMenuItem.addActionListener(this); - - this.addPopupMenuListener(this); } /** @@ -130,30 +126,4 @@ public class TrayMenu Resources.getString("failedToLoadAddContactDialog")); } } - - /** - * Currently unused - * @param evt ignored - */ - public void popupMenuCanceled(PopupMenuEvent evt) - { - } - - /** - * Currently unused - * @param evt ignored - */ - public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) - { - } - - /** - * Fill the menu with items when it is displayed - * @param evt ignored - */ - public void popupMenuWillBecomeVisible(PopupMenuEvent evt) - { - setStatusMenu.update(); - } - }
\ No newline at end of file |