From d86c11fc15b27c30f7a74b0aebac4144eca75ffd Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Thu, 23 Aug 2007 17:10:09 +0000 Subject: [PATCH] fix systray envelope icon notifications --- .../communicator/impl/gui/GuiActivator.java | 25 ++++++++- .../impl/gui/main/chat/ChatPanel.java | 4 +- .../impl/gui/main/chat/ChatWindow.java | 23 ++++---- .../impl/gui/main/chat/ChatWindowManager.java | 50 ++++++++++-------- .../gui/main/contactlist/ContactList.java | 8 +++ .../main/contactlist/ContactListModel.java | 29 ++++++++++ .../main/contactlist/ContactListPanel.java | 6 ++- .../resources/common/systrayEnvelopeIcon.png | Bin 0 -> 822 bytes .../impl/gui/resources/common/systrayIcon.png | Bin 0 -> 792 bytes .../impl/gui/swing.ui.manifest.mf | 1 + .../impl/gui/utils/ImageLoader.java | 11 ++++ .../impl/gui/utils/images.properties | 5 +- .../systray/jdic/SystrayServiceJdicImpl.java | 26 ++++----- .../service/systray/SystrayService.java | 7 +++ 14 files changed, 147 insertions(+), 48 deletions(-) create mode 100644 src/net/java/sip/communicator/impl/gui/resources/common/systrayEnvelopeIcon.png create mode 100644 src/net/java/sip/communicator/impl/gui/resources/common/systrayIcon.png diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java index b80e8ac2d..0a7f18d4c 100644 --- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java +++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java @@ -18,6 +18,7 @@ import net.java.sip.communicator.service.msghistory.*; import net.java.sip.communicator.service.notification.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.systray.*; import net.java.sip.communicator.util.*; import org.osgi.framework.*; @@ -49,6 +50,8 @@ public class GuiActivator implements BundleActivator private static BrowserLauncherService browserLauncherService; private static NotificationService notificationService; + + private static SystrayService systrayService; private static Map providerFactoriesMap = new Hashtable(); @@ -271,10 +274,30 @@ public static BrowserLauncherService getBrowserLauncher() { * Returns the current implementation of the UIService. * @return the current implementation of the UIService */ - public static UIServiceImpl getUIService() { + public static UIServiceImpl getUIService() + { return uiService; } + /** + * Returns the SystrayService obtained from the bundle context. + * + * @return the SystrayService obtained from the bundle context + */ + public static SystrayService getSystrayService() + { + if (systrayService == null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(SystrayService.class.getName()); + + systrayService = (SystrayService) bundleContext + .getService(serviceReference); + } + + return systrayService; + } + /** * Returns the NotificationService obtained from the bundle context. * diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java index 869f5ab73..97c4177bb 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java @@ -551,7 +551,9 @@ public void propertyChange(PropertyChangeEvent evt) .getContactListPanel().getContactList(); ContactListModel clistModel = (ContactListModel) clist.getModel(); - + + // Remove the envelope from the contact when the chat has + // gained the focus. if(clistModel.isContactActive(selectedMetaContact)) { clistModel.removeActiveContact(selectedMetaContact); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java index 54dae30fb..011195ce1 100755 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java @@ -569,39 +569,44 @@ protected void close(boolean isEscaped) { ChatPanel chatPanel = getCurrentChatPanel(); - if(isEscaped) { + if(isEscaped) + { ChatRightButtonMenu chatRightMenu = getCurrentChatPanel() .getChatConversationPanel().getRightButtonMenu(); WritePanelRightButtonMenu writePanelRightMenu = getCurrentChatPanel() .getChatWritePanel().getRightButtonMenu(); - SIPCommMenu selectedMenu = menusPanel.getMainMenuBar().getSelectedMenu(); + SIPCommMenu selectedMenu + = menusPanel.getMainMenuBar().getSelectedMenu(); //SIPCommMenu contactMenu = getCurrentChatPanel() // .getProtoContactSelectorBox().getMenu(); MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); - if (chatRightMenu.isVisible()) { + if (chatRightMenu.isVisible()) + { chatRightMenu.setVisible(false); } - else if (writePanelRightMenu.isVisible()) { - + else if (writePanelRightMenu.isVisible()) + { writePanelRightMenu.setVisible(false); } else if (selectedMenu != null //|| contactMenu.isPopupMenuVisible() - || menusPanel.getMainToolBar().hasSelectedMenus()) { - + || menusPanel.getMainToolBar().hasSelectedMenus()) + { menuSelectionManager.clearSelectedPath(); } - else { + else + { mainFrame.getChatWindowManager().closeChat(chatPanel); } } - else { + else + { mainFrame.getChatWindowManager().closeWindow(); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java index 1f271a10b..e0f9a6e60 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java @@ -15,6 +15,7 @@ import net.java.sip.communicator.impl.gui.i18n.*; import net.java.sip.communicator.impl.gui.main.*; import net.java.sip.communicator.impl.gui.main.chat.conference.*; +import net.java.sip.communicator.impl.gui.main.contactlist.*; import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.protocol.*; @@ -248,13 +249,7 @@ public void closeWindow() if (answer == JOptionPane.OK_OPTION) { - chatWindow.removeAllChats(); - chatWindow.dispose(); - - synchronized (chats) - { - chats.clear(); - } + this.disposeChatWindow(); } } else if (System.currentTimeMillis() - chatWindow @@ -269,24 +264,12 @@ else if (System.currentTimeMillis() - chatWindow if (answer == JOptionPane.OK_OPTION) { - chatWindow.removeAllChats(); - chatWindow.dispose(); - - synchronized (chats) - { - chats.clear(); - } + this.disposeChatWindow(); } } else { - chatWindow.removeAllChats(); - chatWindow.dispose(); - - synchronized (chats) - { - chats.clear(); - } + this.disposeChatWindow(); } } } @@ -647,4 +630,29 @@ private ChatPanel getChat(Object key) return (ChatPanel) chats.get(key); } } + + /** + * Disposes the chat window. + */ + private void disposeChatWindow() + { + chatWindow.removeAllChats(); + chatWindow.dispose(); + + synchronized (chats) + { + chats.clear(); + } + + ContactList clist + = chatWindow.getMainFrame() + .getContactListPanel().getContactList(); + ContactListModel clistModel + = (ContactListModel) clist.getModel(); + + // Remove the envelope from the all active contacts in the contact list. + clistModel.removeAllActiveContacts(); + + clist.refreshAll(); + } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java index daeb66e1c..7e62fdfe4 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java @@ -1210,6 +1210,14 @@ public void refreshContact(MetaContact contact) } } } + + /** + * Refreshes the whole contact list. + */ + public void refreshAll() + { + this.modifyGroup(contactList.getRoot()); + } /** * Adds the given contact to the contact list. diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java index 485187adf..35dff5718 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java @@ -15,6 +15,7 @@ import javax.swing.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.protocol.*; @@ -601,6 +602,13 @@ public void addActiveContact(MetaContact metaContact) { synchronized (activeContacts) { + if(activeContacts.size() == 0) + { + GuiActivator.getSystrayService().setSystrayIcon( + ImageLoader.getImageInBytes( + ImageLoader.SYSTRAY_ENVELOPE_ICON)); + } + this.activeContacts.add(metaContact); } } @@ -615,6 +623,27 @@ public void removeActiveContact(MetaContact metaContact) synchronized (activeContacts) { this.activeContacts.remove(metaContact); + + if(activeContacts.size() == 0) + GuiActivator.getSystrayService().setSystrayIcon( + ImageLoader.getImageInBytes(ImageLoader.SYSTRAY_ICON)); + } + } + + /** + * Removes all contacts from the list of active contacts. + */ + public void removeAllActiveContacts() + { + synchronized (activeContacts) + { + if(activeContacts.size() > 0) + { + this.activeContacts.removeAllElements(); + + GuiActivator.getSystrayService().setSystrayIcon( + ImageLoader.getImageInBytes(ImageLoader.SYSTRAY_ICON)); + } } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java index 632f70c7b..c5f9393ac 100755 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java @@ -14,6 +14,7 @@ import javax.swing.*; import javax.swing.Timer; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.i18n.*; import net.java.sip.communicator.impl.gui.main.*; import net.java.sip.communicator.impl.gui.main.chat.*; @@ -214,12 +215,13 @@ public void messageReceived(MessageReceivedEvent evt) if(metaContact != null) { - // Show an envelope on the sender contact in the contact list. + // Show an envelope on the sender contact in the contact list and + // in the systray. ContactListModel clistModel = (ContactListModel) contactList.getModel(); clistModel.addActiveContact(metaContact); - contactList.refreshContact(metaContact); + contactList.refreshContact(metaContact); // Obtain the corresponding chat panel. ChatPanel chatPanel = chatWindowManager.getContactChat( diff --git a/src/net/java/sip/communicator/impl/gui/resources/common/systrayEnvelopeIcon.png b/src/net/java/sip/communicator/impl/gui/resources/common/systrayEnvelopeIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..fb014f1a953f7fce6c09cfc07adad6bc3e3efe43 GIT binary patch literal 822 zcmV-61Ihe}P)FNE0If000McNliru*9aF76dv~0>y`ij0>eo} zK~y-)t(4hs%uy7_Kfm9-zopA`YD_~)E!{$^A(ASB*teh}5lh4p5nlNhyjc^$15rGP zB_f$bM0h}>qD@GIh)kOhF{4K3XK07c^tX7hjM1s3?Ke5eP0qQWdvcbm9J=t(V-QNG zdeIGYK)=c$)%Wo=$z*c)!K3p(VcN0b1E2~*wBNT9Ux8#o$n zMF@#BG}dq5M_xhUf0gHRvYV^tj$+$3(Qqq)(#mf&?zW;-)YRiR4!1(*QLr&|@lS@E z=H|7txUNe@Z9UyqG`o4eB0mdOZJ{gnmg`r}AaF5t`A1XSK0=pHk+9ygaP?MvzM}q9 zA%)7giB&9JyN%AsYc8KZPP(^ez)Zg+6I?udjCib*5@g4oy*zGf;X(6l zjvUzky%)u-XxzZm=`#^RWG{tK2FO^?4m5PZ-1&=Wm_3(AZ4VGaFui^jQfj%k?U#ps z1IwHj3|+Ed;o`r}vz9AkO{kcfU?}R>JfZ2tyJG!H@xO|9#SogF0SCv{&~m>SDO3U@ z1A~HEaf_Dw%>>8QWx!>%b3lPRckki3_MpH*>IBEvQC2f21J?9B%BL+s@mKS-qmy|J zlPNAL8d6!ZKKhbifC7;kGPEDK(C4GBb`ry(uYO?WL1o*EcK`qY07*qoM6N<$f@!RQ Ag#Z8m literal 0 HcmV?d00001 diff --git a/src/net/java/sip/communicator/impl/gui/resources/common/systrayIcon.png b/src/net/java/sip/communicator/impl/gui/resources/common/systrayIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..85bc142a44f41c6cbd521f9b15dd2e999be35bd7 GIT binary patch literal 792 zcmV+z1LypSP)U_2Hl=*m)b zc&he^yFnAlMUp9nijn7|;H0%DT(x({8|%8x%v_q1VW4Mz5z98$?B6l0DH$$D(%ii; z#>IY_4NXPY)cwPe%K|x*LJ)F&?dH;5VSHq(`{vM!E zf`=0wIKpS>iF9&fU>=V;VVkS@c!}f!Q!@#y`Zk2N!#s+ce90SystrayPopupMessageEvent + * has occured + * + * @param sourceObject the source of this event + */ private void firePopupMessageEvent(Object sourceObject) { SystrayPopupMessageEvent evt @@ -329,16 +333,12 @@ private void firePopupMessageEvent(Object sourceObject) } } - public void chatFocusGained(ChatFocusEvent event) - { - Chat chat = event.getChat(); - - chat.removeChatFocusListener(this); - - this.trayIcon.setIcon(logoIcon); - } - - public void chatFocusLost(ChatFocusEvent event) + /** + * Sets a new systray icon. + * @param image the icon to set. + */ + public void setSystrayIcon(byte[] image) { + this.trayIcon.setIcon(new ImageIcon(image)); } } diff --git a/src/net/java/sip/communicator/service/systray/SystrayService.java b/src/net/java/sip/communicator/service/systray/SystrayService.java index 544b654fa..f00c2d00d 100644 --- a/src/net/java/sip/communicator/service/systray/SystrayService.java +++ b/src/net/java/sip/communicator/service/systray/SystrayService.java @@ -62,4 +62,11 @@ public void showPopupMessage(String title, * @param listener the listener to remove */ public void removePopupMessageListener(SystrayPopupMessageListener listener); + + /** + * Sets a new icon to the systray. + * + * @param image the image to set + */ + public void setSystrayIcon(byte[] image); }