r2656 - in trunk/src/main: java/org/chorem/jtimer java/org/chorem/jtimer/ui/systray resources/org/chorem/jtimer/ui/systray/resources
Author: echatellier Date: 2009-09-09 10:32:30 +0200 (Wed, 09 Sep 2009) New Revision: 2656 Added: trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager.properties trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager_fr.properties Removed: trunk/src/main/java/org/chorem/jtimer/ui/systray/AWTSystray.java trunk/src/main/java/org/chorem/jtimer/ui/systray/NoSystray.java trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/AWTSystray.properties trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/AWTSystray_fr.properties Modified: trunk/src/main/java/org/chorem/jtimer/JTimer.java trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java trunk/src/main/java/org/chorem/jtimer/ui/systray/package-info.java Log: New system tray implementation. Install it with AWT event queue. Can now be hot swapped with no systray implementation. Modified: trunk/src/main/java/org/chorem/jtimer/JTimer.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/JTimer.java 2009-09-07 15:29:18 UTC (rev 2655) +++ trunk/src/main/java/org/chorem/jtimer/JTimer.java 2009-09-09 08:32:30 UTC (rev 2656) @@ -165,7 +165,7 @@ } // Systray mgr - systrayManager = SystrayManager.getSystray(this); + systrayManager = new SystrayManager(this); core.getData().addDataEventListener(systrayManager); } @@ -462,7 +462,7 @@ try { core.getData().addProject(p); } - catch(DataViolationException e) { + catch (DataViolationException e) { displayErrorMessage(e.getExceptionKey()); } } @@ -491,7 +491,7 @@ try { core.getData().editProject(project, newProjectName); } - catch(DataViolationException e) { + catch (DataViolationException e) { displayErrorMessage(e.getExceptionKey()); } } @@ -527,7 +527,7 @@ try { core.getData().addTask(selectedTask, t); } - catch(DataViolationException e) { + catch (DataViolationException e) { displayErrorMessage(e.getExceptionKey()); } } @@ -790,13 +790,18 @@ long newTodayTime = todayTime + increment; - // check if + negative increment still positive - if (newTodayTime > 0) { - core.getData().changeTaskTime(selectedTask, now, newTodayTime); - } else { - // force to 0 - core.getData().changeTaskTime(selectedTask, now, 0L); + try { + // check if + negative increment still positive + if (newTodayTime > 0) { + core.getData().changeTaskTime(selectedTask, now, newTodayTime); + } else { + // force to 0 + core.getData().changeTaskTime(selectedTask, now, 0L); + } } + catch(DataViolationException e) { + displayErrorMessage(e.getExceptionKey()); + } } } @@ -823,7 +828,13 @@ .getString("input.mergeTaskTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (confirm == JOptionPane.YES_OPTION) { - core.getData().mergeTasks(destinationTask, otherTasks); + + try { + core.getData().mergeTasks(destinationTask, otherTasks); + } + catch (DataViolationException e) { + displayErrorMessage(e.getExceptionKey()); + } } } @@ -845,7 +856,12 @@ // remove useless spaces annotation = annotation.trim(); - this.core.getData().addAnnotation(selectedTask, new Date(), annotation); + try { + core.getData().addAnnotation(selectedTask, new Date(), annotation); + } + catch (DataViolationException e) { + displayErrorMessage(e.getExceptionKey()); + } } } Deleted: trunk/src/main/java/org/chorem/jtimer/ui/systray/AWTSystray.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/systray/AWTSystray.java 2009-09-07 15:29:18 UTC (rev 2655) +++ trunk/src/main/java/org/chorem/jtimer/ui/systray/AWTSystray.java 2009-09-09 08:32:30 UTC (rev 2656) @@ -1,382 +0,0 @@ -/* *##% - * Copyright (C) 2008, 2009 Code Lutin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -package org.chorem.jtimer.ui.systray; - -import java.awt.AWTException; -import java.awt.Image; -import java.awt.SystemTray; -import java.awt.TrayIcon; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.WindowEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -import javax.swing.JMenuItem; -import javax.swing.JPopupMenu; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.entities.TimerTask; -import org.jdesktop.application.ApplicationContext; -import org.jdesktop.application.ResourceManager; -import org.jdesktop.application.ResourceMap; - -/** - * Manager for systray icon. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ By : $Author$ - */ -public class AWTSystray extends SystrayManager implements ActionListener, - MouseListener, PropertyChangeListener { - - /** Log */ - private static Log log = LogFactory.getLog(AWTSystray.class); - - /** I18n resources map */ - protected ResourceMap resourceMap; - - /** Tray icon */ - protected TrayIcon trayIcon; - - /** Idle image */ - protected Image idleImage; - /** Running image */ - protected Image runningImage; - /** Idle detect image */ - protected Image idleDetectImage; - - /** Reference how many tasks are running */ - protected int nbTasksRunning = 0; - - /** popup menu instance */ - protected JPopupMenu popup; - - /** Menu show */ - protected JMenuItem showItem; - - /** - * Constructor. - * - * Protected to be called only by factory. - * - * @param parent parent - */ - protected AWTSystray(JTimer parent) { - - super(parent); - - // init resources map - ApplicationContext ctxt = parent.getContext(); - ResourceManager mgr = ctxt.getResourceManager(); - resourceMap = mgr.getResourceMap(AWTSystray.class); - - // load an image - // use FQN to not conflict with annotation - idleImage = resourceMap.getImageIcon("idleImage").getImage(); - runningImage = resourceMap.getImageIcon("runningImage").getImage(); - idleDetectImage = resourceMap.getImageIcon("idleDetectImage") - .getImage(); - } - - /** - * Install try icon into systray. - */ - public void install() { - - // get the SystemTray instance - SystemTray tray = SystemTray.getSystemTray(); - - // create a action listener to listen for default action executed on - // the tray icon - // create a popup menu - popup = new JPopupMenu(); - - // show - showItem = new JMenuItem(resourceMap.getString("hideMenuText")); - // showItem.setName("trayShowMenu"); seems don't work with awt - // components - showItem.addActionListener(this); - showItem.setActionCommand("showHide"); - popup.add(showItem); - popup.addSeparator(); - - // quit - JMenuItem quitItem = new JMenuItem(resourceMap - .getString("quitMenuText")); - // defaultItem.setName("quit"); - quitItem.addActionListener(this); - quitItem.setActionCommand("quit"); - popup.add(quitItem); - - // / ... add other items - // construct a TrayIcon - - trayIcon = new TrayIcon(idleImage, resourceMap - .getString("tooltipIdleText"), null); - trayIcon.setImageAutoSize(true); - trayIcon.addMouseListener(this); - - // add the tray image - try { - tray.add(trayIcon); - } catch (AWTException e) { - - // exception is throw if systray is currently missing - // not big deal, we will set it when it'll be ready - if (log.isWarnEnabled()) { - log.warn("Error while setting system tray", e); - } - - // add listener - tray.addPropertyChangeListener("trayIcons", this); - } - - // call to super install - super.install(); - } - - /* - * @see org.chorem.jtimer.ui.systray.SystrayManager#startTask(org.chorem.jtimer.entities.TimerTask) - */ - @Override - public void startTask(TimerTask task) { - startStopTask(task, true); - } - - /* - * @see org.chorem.jtimer.ui.systray.SystrayManager#stopTask(org.chorem.jtimer.entities.TimerTask) - */ - @Override - public void stopTask(TimerTask task) { - startStopTask(task, false); - } - - /** - * Common code for start or stop task. - * - * @param task task - * @param start start(true) or stop(false) task - */ - protected void startStopTask(TimerTask task, boolean start) { - // increment or decrement task - if (start) { - ++nbTasksRunning; - } else { - --nbTasksRunning; - } - - // display message - String message = null; - if (nbTasksRunning == 0) { - message = resourceMap.getString("tooltipIdleText"); - - trayIcon.setImage(idleImage); - } else { - trayIcon.setImage(runningImage); - if (nbTasksRunning == 1) { - message = resourceMap.getString("tooltipRunningTaskText", - nbTasksRunning); - } else { - message = resourceMap.getString("tooltipRunningTasksText", - nbTasksRunning); - } - } - trayIcon.setToolTip(message); - - } - - /* - * @see org.chorem.jtimer.ui.systray.SystrayManager#postIdleDetect() - */ - @Override - public void postIdleDetect() { - - if (log.isDebugEnabled()) { - log.debug("Post idle detect"); - } - - if (nbTasksRunning == 0) { - trayIcon.setImage(idleImage); - } else { - trayIcon.setImage(runningImage); - } - - } - - /* - * @see org.chorem.jtimer.ui.systray.SystrayManager#preIdleDetect() - */ - @Override - public void preIdleDetect() { - - if (log.isDebugEnabled()) { - log.debug("Pre idle detect"); - } - - trayIcon.setImage(idleDetectImage); - } - - /* - * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) - */ - @Override - public void propertyChange(PropertyChangeEvent evt) { - - // get event name - String event = evt.getPropertyName(); - - if (log.isDebugEnabled()) { - log.debug("Property change on system tray : " + event); - } - - // systemTray event is only available in jdk7 - if (event.equals("trayIcons")) { - - if (log.isDebugEnabled()) { - log.debug("Systray event : " + evt.getPropertyName()); - } - - SystemTray tray = SystemTray.getSystemTray(); - - // tray become available - if (tray != null) { - try { - tray.add(trayIcon); - } catch (AWTException e) { - if (log.isErrorEnabled()) { - log.error("System tray seems to become available, but can't set it !", - e); - } - } - } - } - } - - /* - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - */ - public void actionPerformed(ActionEvent e) { - - String actionCommand = e.getActionCommand(); - - if ("showHide".equals(actionCommand)) { - if (parent.getMainFrame().isVisible()) { - // on la cache - parent.hide(); - showItem.setText(resourceMap.getString("showMenuText")); - } else { - // sinon on la montre - parent.show(); - showItem.setText(resourceMap.getString("hideMenuText")); - } - } - - if ("quit".equals(actionCommand)) { - parent.quit(e); - } - } - - /* - * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) - */ - @Override - public void mouseClicked(MouseEvent e) { - - // ne fait pas de double affichage si plus de clics - // et ne change pas l'affichage si clic droit - if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON1) { - - // si la fenetre est affichee - if (parent.getMainFrame().isVisible()) { - showItem.setText(resourceMap.getString("showMenuText")); - - // on la cache - parent.hide(); - - } else { - - showItem.setText(resourceMap.getString("hideMenuText")); - - // sinon on la montre - // correct iconified bug - // http://www.java-forums.org/awt-swing/7000-problem-setvisible-linux.html - //parent.getMainFrame().setExtendedState(JFrame.NORMAL); - parent.show(); - - } - } - - } - - /* - * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) - */ - @Override - public void mouseEntered(MouseEvent e) { - - } - - /* - * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) - */ - @Override - public void mouseExited(MouseEvent e) { - - } - - /* - * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) - */ - @Override - public void mousePressed(MouseEvent e) { - - } - - /* - * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) - */ - @Override - public void mouseReleased(MouseEvent e) { - - // use sun workarround http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6285881 - if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON3) { - popup.setLocation(e.getX(), e.getY()); - popup.setInvoker(popup); - popup.setVisible(true); - } - } - - /* - * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent) - */ - @Override - public void windowClosing(WindowEvent e) { - - // hide window (without exiting) - parent.hide(); - showItem.setText(resourceMap.getString("showMenuText")); - } -} Deleted: trunk/src/main/java/org/chorem/jtimer/ui/systray/NoSystray.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/systray/NoSystray.java 2009-09-07 15:29:18 UTC (rev 2655) +++ trunk/src/main/java/org/chorem/jtimer/ui/systray/NoSystray.java 2009-09-09 08:32:30 UTC (rev 2656) @@ -1,57 +0,0 @@ -/* *##% - * Copyright (C) 2008, 2009 Code Lutin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -package org.chorem.jtimer.ui.systray; - -import java.awt.event.WindowEvent; - -import org.chorem.jtimer.JTimer; - -/** - * Systray implementation, for non available systray. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class NoSystray extends SystrayManager { - - /** - * Constructor. - * - * Protected to be called only by factory. - * - * @param parent parent - */ - protected NoSystray(JTimer parent) { - super(parent); - } - - /* - * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent) - */ - @Override - public void windowClosing(WindowEvent e) { - - // just exit here - parent.exit(e); - - } -} Modified: trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java 2009-09-07 15:29:18 UTC (rev 2655) +++ trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java 2009-09-09 08:32:30 UTC (rev 2656) @@ -18,20 +18,35 @@ package org.chorem.jtimer.ui.systray; +import java.awt.AWTException; +import java.awt.EventQueue; +import java.awt.Image; import java.awt.SystemTray; +import java.awt.TrayIcon; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.Collection; import java.util.Date; import java.util.List; -import java.util.Timer; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; import org.chorem.jtimer.data.DataEventListener; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; +import org.jdesktop.application.ApplicationContext; +import org.jdesktop.application.ResourceManager; +import org.jdesktop.application.ResourceMap; /** * Factory to get correct working systray implementation. @@ -42,56 +57,91 @@ * Last update : $Date$ * By : $Author$ */ -public abstract class SystrayManager implements DataEventListener, - WindowListener { +public class SystrayManager implements ActionListener, DataEventListener, + MouseListener, Runnable, WindowListener { - /** Log */ + /** Log. */ private static Log log = LogFactory.getLog(SystrayManager.class); - - /** Parent reference */ + + /** Parent reference. */ protected JTimer parent; + /** I18n resources map. */ + protected ResourceMap resourceMap; + + /** Idle image. */ + protected Image idleImage; + + /** Running image. */ + protected Image runningImage; + + /** Idle detect image. */ + protected Image idleDetectImage; + + /** Tray icon. (null values when tray is non available) */ + protected TrayIcon trayIcon; + + /** Reference how many tasks are running. */ + protected int nbTasksRunning = 0; + + /** Popup menu instance. */ + protected JPopupMenu popup; + + /** Menu show. (used to change text) */ + protected JMenuItem showItem; + /** * Default constructor. * * @param parent parent */ - protected SystrayManager(JTimer parent) { + public SystrayManager(JTimer parent) { this.parent = parent; + + // init resources map + ApplicationContext ctxt = parent.getContext(); + ResourceManager mgr = ctxt.getResourceManager(); + resourceMap = mgr.getResourceMap(SystrayManager.class); + + // load an image + // use FQN to not conflict with annotation + idleImage = resourceMap.getImageIcon("idleImage").getImage(); + runningImage = resourceMap.getImageIcon("runningImage").getImage(); + idleDetectImage = resourceMap.getImageIcon("idleDetectImage").getImage(); + + // make popup menu instance + buildPopupMenu(); } /** - * Get systray. - * - * @param parentApp parent application ref - * - * @return systray impl + * Build popup menu. */ - public static SystrayManager getSystray(JTimer parentApp) { + private void buildPopupMenu() { - SystrayManager systray = null; + // create a action listener to listen for default action executed on + // the tray icon + // create a popup menu + popup = new JPopupMenu(); - // is awt sytray available ? - if (SystemTray.isSupported()) { - if (log.isDebugEnabled()) { - log.debug("Systray is supported, use AWT systray"); - } - systray = new AWTSystray(parentApp); - } else { - if (log.isDebugEnabled()) { - log.debug("Systray is not supported, use no systray"); - } - systray = new NoSystray(parentApp); - } + // show + showItem = new JMenuItem(resourceMap.getString("hideMenuText")); + // showItem.setName("trayShowMenu"); seems don't work with awt + // components + showItem.addActionListener(this); + showItem.setActionCommand("showHide"); + popup.add(showItem); + popup.addSeparator(); - return systray; + // quit + JMenuItem quitItem = new JMenuItem(resourceMap.getString("quitMenuText")); + // defaultItem.setName("quit"); + quitItem.addActionListener(this); + quitItem.setActionCommand("quit"); + popup.add(quitItem); } /** - * Default install method. - * - * Just remove all windows listener and add this systray - * instance, the only one. + * Install try icon into systray. */ public void install() { @@ -101,8 +151,42 @@ } // et la reactive de facon personnalisee parent.getMainFrame().addWindowListener(this); + + EventQueue.invokeLater(this); } + /** + * Tray icon installation is make into a thread, put un AWT event + * queue. + * + * @see EventQueue#invokeLater(Runnable) + */ + @Override + public void run() { + if (SystemTray.isSupported()) { + // get the SystemTray instance + SystemTray tray = SystemTray.getSystemTray(); + + // construct a TrayIcon + trayIcon = new TrayIcon(idleImage, resourceMap.getString("tooltipIdleText"), null); + trayIcon.setImageAutoSize(true); + trayIcon.addMouseListener(this); + + // add listener + //tray.addPropertyChangeListener("trayIcons", this); + + // add the tray image + try { + tray.add(trayIcon); + } catch (AWTException e) { + // exception is throw if systray is currently missing + if (log.isWarnEnabled()) { + log.warn("Error while setting system tray", e); + } + } + } + } + /* * @see org.chorem.jtimer.data.event.DataEventListener#addProject(org.chorem.jtimer.entities.TimerProject) */ @@ -127,7 +211,6 @@ } - /* * @see org.chorem.jtimer.data.DataEventListener#preDeleteProject(org.chorem.jtimer.entities.TimerProject) */ @@ -193,22 +276,157 @@ } /* - * @see org.chorem.jtimer.data.event.DataEventListener#startTask(org.chorem.jtimer.entities.TimerTask) + * @see org.chorem.jtimer.ui.systray.SystrayManager#startTask(org.chorem.jtimer.entities.TimerTask) */ @Override public void startTask(TimerTask task) { - + startStopTask(task, true); } /* - * @see org.chorem.jtimer.data.event.DataEventListener#stopTask(org.chorem.jtimer.entities.TimerTask) + * @see org.chorem.jtimer.ui.systray.SystrayManager#stopTask(org.chorem.jtimer.entities.TimerTask) */ @Override public void stopTask(TimerTask task) { + startStopTask(task, false); + } + /** + * Common code for start or stop task. + * + * @param task task + * @param start start(true) or stop(false) task + */ + protected void startStopTask(TimerTask task, boolean start) { + // increment or decrement task + if (start) { + ++nbTasksRunning; + } else { + --nbTasksRunning; + } + + // display message + String message = null; + if (nbTasksRunning == 0) { + message = resourceMap.getString("tooltipIdleText"); + + trayIcon.setImage(idleImage); + } else { + trayIcon.setImage(runningImage); + if (nbTasksRunning == 1) { + message = resourceMap.getString("tooltipRunningTaskText", nbTasksRunning); + } else { + message = resourceMap.getString("tooltipRunningTasksText", nbTasksRunning); + } + } + trayIcon.setToolTip(message); + } + /** + * Called by main application UI on idle detect. + */ + public void preIdleDetect() { + + if (log.isDebugEnabled()) { + log.debug("Pre idle detect"); + } + + // tray available only if trayIcon != null + if (trayIcon != null) { + trayIcon.setImage(idleDetectImage); + } + } + + /** + * Called by main application UI after idle detect. + */ + public void postIdleDetect() { + + if (log.isDebugEnabled()) { + log.debug("Post idle detect"); + } + + // tray available only if trayIcon != null + if (trayIcon != null) { + if (nbTasksRunning == 0) { + trayIcon.setImage(idleImage); + } else { + trayIcon.setImage(runningImage); + } + } + } + /* + * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) + * + public void propertyChange(PropertyChangeEvent evt) { + + // get event name + String event = evt.getPropertyName(); + + if (log.isDebugEnabled()) { + log.debug("Property change on system tray : " + event); + } + + if (evt.getNewValue() == null) { + if (log.isDebugEnabled()) { + log.debug("Disable tray icon"); + } + trayIcon = null; + } + else { + SystemTray tray = (SystemTray)evt.getSource(); + + boolean alreadyInTray = false; + TrayIcon[] installedIcons = tray.getTrayIcons(); + for (TrayIcon installedIcon : installedIcons) { + if (installedIcon.equals(trayIcon)) { + alreadyInTray = true; + } + } + + if (alreadyInTray) { + if (log.isDebugEnabled()) { + log.debug("Tray icon already installed"); + } + } + else { + if (log.isDebugEnabled()) { + log.debug("Install tray icons"); + } + EventQueue.invokeLater(this); + } + } + }/ + + /* + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) { + + // This is only popop menu action here + + String actionCommand = e.getActionCommand(); + + if ("showHide".equals(actionCommand)) { + if (parent.getMainFrame().isVisible()) { + // on la cache + parent.hide(); + showItem.setText(resourceMap.getString("showMenuText")); + } else { + // sinon on la montre + parent.show(); + showItem.setText(resourceMap.getString("hideMenuText")); + } + } + + if ("quit".equals(actionCommand)) { + parent.quit(e); + } + } + + /* * @see org.chorem.jtimer.event.DataEventListener#setAnnotation(org.chorem.jtimer.entities.TimerTask, java.util.Date, java.lang.String) */ @Override @@ -252,49 +470,114 @@ * @see org.chorem.jtimer.data.DataEventListener#preMergeTasks(org.chorem.jtimer.entities.TimerTask, java.util.List) */ @Override - public void preMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { + public void preMergeTasks(TimerTask destinationTask, + List<TimerTask> otherTasks) { } - /** - * Notify idle dtect ended. + /* + * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) */ - public void postIdleDetect() { + @Override + public void mouseClicked(MouseEvent e) { + // ne fait pas de double affichage si plus de clics + // et ne change pas l'affichage si clic droit + if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON1) { + + // si la fenetre est affichee + if (parent.getMainFrame().isVisible()) { + showItem.setText(resourceMap.getString("showMenuText")); + + // on la cache + parent.hide(); + + } else { + + showItem.setText(resourceMap.getString("hideMenuText")); + + // sinon on la montre + // correct iconified bug + // http://www.java-forums.org/awt-swing/7000-problem-setvisible-linux.html + //parent.getMainFrame().setExtendedState(JFrame.NORMAL); + parent.show(); + + } + } } - /** - * Notify idle detect. + /* + * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) */ - public void preIdleDetect() { - + @Override + public void mouseEntered(MouseEvent e) { + } - + /* - * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent) + * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) */ @Override - public void windowActivated(WindowEvent e) { + public void mouseExited(MouseEvent e) { } /* - * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent) + * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) */ @Override - public void windowClosed(WindowEvent e) { + public void mousePressed(MouseEvent e) { } /* + * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) + */ + @Override + public void mouseReleased(MouseEvent e) { + + // use sun workarround http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6285881 + if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON3) { + popup.setLocation(e.getX(), e.getY()); + popup.setInvoker(popup); + popup.setVisible(true); + } + } + + /* * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent) */ @Override public void windowClosing(WindowEvent e) { + // tray available only if trayIcon != null + if (trayIcon != null) { + // hide window (without exiting) + parent.hide(); + showItem.setText(resourceMap.getString("showMenuText")); + } else { + // just exit here + parent.exit(e); + } } /* + * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent) + */ + @Override + public void windowActivated(WindowEvent e) { + + } + + /* + * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent) + */ + @Override + public void windowClosed(WindowEvent e) { + + } + + /* * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent) */ @Override @@ -325,5 +608,4 @@ public void windowOpened(WindowEvent e) { } - -} +} \ No newline at end of file Modified: trunk/src/main/java/org/chorem/jtimer/ui/systray/package-info.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/systray/package-info.java 2009-09-07 15:29:18 UTC (rev 2655) +++ trunk/src/main/java/org/chorem/jtimer/ui/systray/package-info.java 2009-09-09 08:32:30 UTC (rev 2656) @@ -1,4 +1,4 @@ /** - * Systray implementations. + * System tray implementations. */ package org.chorem.jtimer.ui.systray; Deleted: trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/AWTSystray.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/AWTSystray.properties 2009-09-07 15:29:18 UTC (rev 2655) +++ trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/AWTSystray.properties 2009-09-09 08:32:30 UTC (rev 2656) @@ -1,12 +0,0 @@ -#�tray icon -idleImage = jtimer-40-orange.png -runningImage = jtimer-40-green.png -idleDetectImage = jtimer-40-grey.png - -# tray i18n -tooltipIdleText = ${Application.title} -tooltipRunningTaskText = ${Application.title} - %d task running -tooltipRunningTasksText = ${Application.title} - %d tasks running -showMenuText = Show -hideMenuText = Hide -quitMenuText = Quit \ No newline at end of file Deleted: trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/AWTSystray_fr.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/AWTSystray_fr.properties 2009-09-07 15:29:18 UTC (rev 2655) +++ trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/AWTSystray_fr.properties 2009-09-09 08:32:30 UTC (rev 2656) @@ -1,7 +0,0 @@ -# tray i18n -tooltipIdleText = ${Application.title} -tooltipRunningTaskText = ${Application.title} - %d t\u00E2che en cours -tooltipRunningTasksText = ${Application.title} - %d t\u00E2ches en cours -showMenuText = Montrer -hideMenuText = Cacher -quitMenuText = Quitter \ No newline at end of file Copied: trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager.properties (from rev 2643, trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/AWTSystray.properties) =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager.properties (rev 0) +++ trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager.properties 2009-09-09 08:32:30 UTC (rev 2656) @@ -0,0 +1,12 @@ +#�tray icon +idleImage = jtimer-40-orange.png +runningImage = jtimer-40-green.png +idleDetectImage = jtimer-40-grey.png + +# tray i18n +tooltipIdleText = ${Application.title} +tooltipRunningTaskText = ${Application.title} - %d task running +tooltipRunningTasksText = ${Application.title} - %d tasks running +showMenuText = Show +hideMenuText = Hide +quitMenuText = Quit \ No newline at end of file Copied: trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager_fr.properties (from rev 2643, trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/AWTSystray_fr.properties) =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager_fr.properties (rev 0) +++ trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager_fr.properties 2009-09-09 08:32:30 UTC (rev 2656) @@ -0,0 +1,7 @@ +# tray i18n +tooltipIdleText = ${Application.title} +tooltipRunningTaskText = ${Application.title} - %d t\u00E2che en cours +tooltipRunningTasksText = ${Application.title} - %d t\u00E2ches en cours +showMenuText = Montrer +hideMenuText = Cacher +quitMenuText = Quitter \ No newline at end of file
participants (1)
-
echatellier@users.chorem.org