Author: jflesch
Date: 2007-07-29 17:35:00 +0000 (Sun, 29 Jul 2007)
New Revision: 14426

Modified:
   trunk/apps/Thaw/src/thaw/core/Main.java
   trunk/apps/Thaw/src/thaw/gui/SysTrayIcon.java
   trunk/apps/Thaw/src/thaw/plugins/TrayIcon.java
Log:
Improve the systray icon plugin (Warning : crash on jvm 64 bits)

Modified: trunk/apps/Thaw/src/thaw/core/Main.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Main.java     2007-07-29 16:06:25 UTC (rev 
14425)
+++ trunk/apps/Thaw/src/thaw/core/Main.java     2007-07-29 17:35:00 UTC (rev 
14426)
@@ -20,7 +20,7 @@
        _minor  = 7,
        _update = 1;
        public final static String
-       _svnBuildNumber = "@custom@";
+       _svnBuildNumber = "14418:14424M";

        public final static String
        VERSION = Main._major + "." + Main._minor + "." + Main._update + " 
r"+Main._svnBuildNumber;

Modified: trunk/apps/Thaw/src/thaw/gui/SysTrayIcon.java
===================================================================
--- trunk/apps/Thaw/src/thaw/gui/SysTrayIcon.java       2007-07-29 16:06:25 UTC 
(rev 14425)
+++ trunk/apps/Thaw/src/thaw/gui/SysTrayIcon.java       2007-07-29 17:35:00 UTC 
(rev 14426)
@@ -18,6 +18,11 @@
  * <br/>
  */
 public class SysTrayIcon {
+       public final static int MSG_ERROR   = 0;
+       public final static int MSG_INFO    = 1;
+       public final static int MSG_NONE    = 2;
+       public final static int MSG_WARNING = 3;
+
        private Object systemTray;
        private Object trayIcon;

@@ -115,6 +120,46 @@
        }


+       public void popMessage(String title, String msg, int msgTypeInt) {
+               if (!canWork())
+                       return;
+
+               try {
+                       Object type;
+
+                       String typeName;
+
+                       switch(msgTypeInt) {
+                       case(MSG_ERROR):   typeName = "ERROR";   break;
+                       case(MSG_INFO):    typeName = "INFO";    break;
+                       case(MSG_NONE):    typeName = "NONE";    break;
+                       case(MSG_WARNING): typeName = "WARNING"; break;
+                       default:
+                               Logger.warning(this, "Unknown message type: 
"+Integer.toString(msgTypeInt));
+                               return;
+                       }
+
+                       Class messageTypeClass = 
Class.forName("java.awt.TrayIcon").getClasses()[0];
+
+                       type = messageTypeClass.getMethod("valueOf", new 
Class[] {
+                               String.class
+                       }).invoke(null, new Object[] {
+                               typeName
+                       });
+
+
+                       
Class.forName("java.awt.TrayIcon").getMethod("displayMessage", new Class[] {
+                               String.class, String.class, type.getClass()
+                       }).invoke(trayIcon, new Object[] {
+                               title, msg, type
+                       });
+
+               } catch(Exception e) {
+                       Logger.warning(this, "Error while poping up a message: 
"+e.toString());
+               }
+       }
+
+
        public void setPopupMenu(PopupMenu m) {
                if (!canWork())
                        return;

Modified: trunk/apps/Thaw/src/thaw/plugins/TrayIcon.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/TrayIcon.java      2007-07-29 16:06:25 UTC 
(rev 14425)
+++ trunk/apps/Thaw/src/thaw/plugins/TrayIcon.java      2007-07-29 17:35:00 UTC 
(rev 14426)
@@ -38,7 +38,8 @@
 public class TrayIcon implements thaw.core.Plugin,
                                 MouseListener,
                                 WindowListener,
-                                ActionListener {
+                                ActionListener,
+                                thaw.core.LogListener {

        private Core core;
        private SysTrayIcon icon;
@@ -72,6 +73,8 @@

                icon.setVisible(true);

+               Logger.addLogListener(this);
+
                return true;
        }

@@ -80,6 +83,8 @@
                if (icon == null)
                        return false;

+               Logger.removeLogListener(this);
+
                core.getMainWindow().removeWindowListener(this);
                icon.removeMouseListener(this);

@@ -90,9 +95,60 @@
                        core.getMainWindow().setVisible(true);
                }

+               Logger.addLogListener(this);
+
                return true;
        }

+
+       public static boolean popMessage(thaw.core.PluginManager pluginManager,
+                                        String title,
+                                        String message) {
+               return popMessage(pluginManager, title, message, 
SysTrayIcon.MSG_NONE);
+       }
+
+       /**
+        * that's an helper to make my life easier :
+        *  it tries to find a loaded instance of this plugin, it succeed, it 
tries to
+        *   pop the message with it. Else if returns false.
+        * @param msgType see thaw.gui.SysTrayIcon
+        */
+       public static boolean popMessage(thaw.core.PluginManager pluginManager,
+                                        String title,
+                                        String message,
+                                        int msgType) {
+               TrayIcon plugin = 
(TrayIcon)pluginManager.getPlugin("thaw.plugins.TrayIcon");
+
+               if (plugin == null)
+                       return false;
+
+               return plugin.popMessage(title, message, msgType);
+       }
+
+       /**
+        * Made to be also used by other plugins
+        */
+       public boolean popMessage(String title, String message, int msgType) {
+               if (icon == null || !icon.canWork())
+                       return false;
+
+               icon.popMessage(title, message, msgType);
+
+               return true;
+       }
+
+
+       public void newLogLine(int level, Object src, String line) {
+               if (level > 1 || src == this || src == icon)
+                       return;
+
+               int msgType = ((level == 0) ? SysTrayIcon.MSG_ERROR : 
SysTrayIcon.MSG_WARNING);
+               String str = ((src != null) ? src.getClass().getName() + ": " : 
"") + line;
+
+               popMessage(Logger.PREFIXES[level], str, msgType);
+       }
+
+
        public String getNameForUser() {
                return I18n.getMessage("thaw.plugin.trayIcon.pluginName");
        }


Reply via email to