Author: echatellier Date: 2009-11-16 10:17:41 +0100 (Mon, 16 Nov 2009) New Revision: 2692 Modified: trunk/src/main/java/org/chorem/jtimer/JTimer.java trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java 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 Log: #76 : Add "Stop all tasks" action in systray popup menu Modified: trunk/src/main/java/org/chorem/jtimer/JTimer.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/JTimer.java 2009-11-13 18:05:35 UTC (rev 2691) +++ trunk/src/main/java/org/chorem/jtimer/JTimer.java 2009-11-16 09:17:41 UTC (rev 2692) @@ -23,7 +23,6 @@ import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.text.DateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -639,6 +638,19 @@ } /** + * Stop all running tasks. + */ + public void stopAllTasks() { + + TaskMonitor tm = this.getContext().getTaskMonitor(); + for (Task<Void, Long> t : tm.getTasks()) { + // task + TimerTask ttask = ((RunTaskJob) t).getTask(); + stopTask(ttask); + } + } + + /** * Close project. */ @Action(enabledProperty = "selectedSingleProject") @@ -1173,21 +1185,12 @@ if (isSelectedSingleStoppedTask()) { // can only launch non running tasks org.jdesktop.application.Task<?, ?> appTask = startTask(); - // TODO voir si c'est bien ca le lancement if (appTask != null) { + + // first, on dlb click stop all running tasks + stopAllTasks(); + this.getContext().getTaskService().execute(appTask); - - // first, on dlb click stop all running tasks - TaskMonitor tm = this.getContext().getTaskMonitor(); - for (Task<Void, Long> t : tm.getTasks()) { - if (appTask != t) { // don't stop just started - // task - TimerTask ttask = ((RunTaskJob) t) - .getTask(); - core.getData().stopTask(ttask); - ((RunTaskJob) t).wantToStop(); - } - } } } else { Modified: trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java 2009-11-13 18:05:35 UTC (rev 2691) +++ trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java 2009-11-16 09:17:41 UTC (rev 2692) @@ -22,7 +22,6 @@ 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; @@ -78,17 +77,20 @@ protected Image idleDetectImage; /** Tray icon. (null values when tray is non available) */ - protected TrayIcon trayIcon; + protected JPopupTrayIcon trayIcon; /** Reference how many tasks are running. */ protected int nbTasksRunning = 0; - /** Popup menu instance. */ + /** Non running popup menu instance. */ protected JPopupMenu popup; /** Menu show. (used to change text) */ protected JMenuItem showItem; + /** Menu stop. (used to enable/disable) */ + protected JMenuItem stopItem; + /** * Default constructor. * @@ -124,16 +126,21 @@ // 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(); + // stop task + stopItem = new JMenuItem(resourceMap.getString("stopMenuText")); + stopItem.addActionListener(this); + stopItem.setActionCommand("stop"); + stopItem.setEnabled(false); + popup.add(stopItem); + popup.addSeparator(); + // quit JMenuItem quitItem = new JMenuItem(resourceMap.getString("quitMenuText")); - // defaultItem.setName("quit"); quitItem.addActionListener(this); quitItem.setActionCommand("quit"); popup.add(quitItem); @@ -308,7 +315,7 @@ String message = null; if (nbTasksRunning == 0) { message = resourceMap.getString("tooltipIdleText"); - + trayIcon.setImage(idleImage); } else { trayIcon.setImage(runningImage); @@ -318,7 +325,11 @@ message = resourceMap.getString("tooltipRunningTasksText", nbTasksRunning); } } + trayIcon.setToolTip(message); + + // enable some menus + stopItem.setEnabled(nbTasksRunning > 0); } } @@ -375,11 +386,12 @@ parent.show(); showItem.setText(resourceMap.getString("hideMenuText")); } + } else if ("stop".equals(actionCommand)) { + parent.stopAllTasks(); + } else if ("quit".equals(actionCommand)) { + parent.quit(e); } - if ("quit".equals(actionCommand)) { - parent.quit(e); - } } /* Modified: trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager.properties 2009-11-13 18:05:35 UTC (rev 2691) +++ trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager.properties 2009-11-16 09:17:41 UTC (rev 2692) @@ -9,4 +9,5 @@ tooltipRunningTasksText = ${Application.title} - %d tasks running showMenuText = Show hideMenuText = Hide +stopMenuText = Stop all tasks quitMenuText = Quit \ No newline at end of file Modified: trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager_fr.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager_fr.properties 2009-11-13 18:05:35 UTC (rev 2691) +++ trunk/src/main/resources/org/chorem/jtimer/ui/systray/resources/SystrayManager_fr.properties 2009-11-16 09:17:41 UTC (rev 2692) @@ -4,4 +4,5 @@ tooltipRunningTasksText = ${Application.title} - %d t\u00E2ches en cours showMenuText = Montrer hideMenuText = Cacher +stopMenuText = Arr\u00EAter toutes les t\u00E2ches quitMenuText = Quitter \ No newline at end of file