r2941 - in trunk/src/main: java/org/chorem/jtimer/ui resources/org/chorem/jtimer/ui/resources
Author: tchemit Date: 2013-09-26 10:07:54 +0200 (Thu, 26 Sep 2013) New Revision: 2941 Url: http://chorem.org/projects/jtimer/repository/revisions/2941 Log: fixes #950: Improve the task editor Modified: trunk/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java trunk/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties trunk/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties Modified: trunk/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java 2013-09-26 08:03:59 UTC (rev 2940) +++ trunk/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java 2013-09-26 08:07:54 UTC (rev 2941) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2011 CodeLutin, Chorlet Stéphane, Chatellier Eric + * Copyright (C) 2008 - 2011 CodeLutin, Chorlet Stéphane, Chatellier Eric, Chemit Tony * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -61,6 +61,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; @@ -143,6 +144,11 @@ * apply button: keep reference in order to be able to call setEnabled(true or false) */ protected JButton applyButton; + + /** + * apply and quit button: keep reference in order to be able to call setEnabled(true or false) + */ + protected JButton applyAndQuitButton; /** * revert button: keep reference in order to be able to call setEnabled(true or false) */ @@ -239,23 +245,34 @@ applyButton.setActionCommand("apply"); applyButton.addActionListener(this); applyButton.setEnabled(false); + addMnemonic("apply.Action.mnemonic", applyButton); + // apply and quit button + applyAndQuitButton= new JButton(resourceMap.getString("applyAndQuit.Action.text")); + applyAndQuitButton.setActionCommand("applyAndQuit"); + applyAndQuitButton.addActionListener(this); + applyAndQuitButton.setEnabled(false); + addMnemonic("applyAndQuit.Action.mnemonic", applyAndQuitButton); + // revert button revertButton = new JButton(resourceMap.getString("revert.Action.text")); revertButton.setActionCommand("revert"); revertButton.addActionListener(this); revertButton.setEnabled(false); + addMnemonic("revert.Action.mnemonic", revertButton); // cancel button JButton cancelButton = new JButton(resourceMap .getString("cancel.Action.text")); cancelButton.setActionCommand("cancel"); cancelButton.addActionListener(this); + addMnemonic("cancel.Action.mnemonic", cancelButton); // command panel JPanel panel = new JPanel(); panel.setLayout(new FlowLayout(FlowLayout.RIGHT, 1, 0)); panel.add(applyButton); + panel.add(applyAndQuitButton); panel.add(revertButton); panel.add(cancelButton); return panel; @@ -503,10 +520,13 @@ */ @Override public void actionPerformed(ActionEvent e) { - if ("cancel".equals(e.getActionCommand())) { + String actionCommand = e.getActionCommand(); + + + if ("cancel".equals(actionCommand)) { cancel(); - } else if ("apply".equals(e.getActionCommand())) { + } else if ("apply".equals(actionCommand)) { getRootPane().setCursor( Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); @@ -524,7 +544,28 @@ getRootPane().setCursor( Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } else if ("revert".equals(e.getActionCommand())) { + }else if ("applyAndQuit".equals(actionCommand)) { + + getRootPane().setCursor( + Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + try { + apply(); + } + catch(DataViolationException ex) { + // revert changes + revert(); + + // TODO display UI message + } + + getRootPane().setCursor( + Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + + // quit editor + cancel(); + + } else if ("revert".equals(actionCommand)) { revert(); } } @@ -656,6 +697,7 @@ dateChanged.add(getSelectedDay().getTime()); applyButton.setEnabled(true); + applyAndQuitButton.setEnabled(true); revertButton.setEnabled(true); updateFlaggedDates(); @@ -684,6 +726,7 @@ dateChanged.clear(); annotationChanged.clear(); applyButton.setEnabled(false); + applyAndQuitButton.setEnabled(false); revertButton.setEnabled(false); isTitleChanged = false; isAnnotationChanged = false; @@ -724,6 +767,7 @@ dateChanged.clear(); annotationChanged.clear(); applyButton.setEnabled(false); + applyAndQuitButton.setEnabled(false); revertButton.setEnabled(false); isTitleChanged = false; isAnnotationChanged = false; @@ -733,4 +777,18 @@ dispose(); } + /** + * To add a mnemonic from a i18n key. + * + * @param key the i18n key of the mnemonic + * @param button button where to add mnemonic + * @since 1.4.3 + */ + protected void addMnemonic(String key, JButton button) { + String string = resourceMap.getString(key); + if (StringUtils.isNotBlank(string)) { + + button.setMnemonic(string.charAt(0)); + } + } } Modified: trunk/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties 2013-09-26 08:03:59 UTC (rev 2940) +++ trunk/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties 2013-09-26 08:07:54 UTC (rev 2941) @@ -5,7 +5,7 @@ # $Id$ # $HeadURL$ # %% -# Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric +# Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric, Chemit Tony # %% # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as @@ -25,12 +25,19 @@ editor.title = Edit task apply.Action.text = Apply +apply.Action.mnemonic = A apply.Action.shortDescription = Apply changes +applyAndQuit.Action.text = Apply And Quit +applyAndQuit.Action.mnemonic = p +applyAndQuit.Action.shortDescription = Apply changes and quit + cancel.Action.text = Quit +cancel.Action.mnemonic = Q cancel.Action.shortDescription = Revert changes and quit revert.Action.text = Revert +revert.Action.mnemonic= R revert.Action.shortDescription = Revert changes label.time.text = Time: Modified: trunk/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties 2013-09-26 08:03:59 UTC (rev 2940) +++ trunk/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties 2013-09-26 08:07:54 UTC (rev 2941) @@ -5,7 +5,7 @@ # $Id$ # $HeadURL$ # %% -# Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric +# Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric, Chemit Tony # %% # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as @@ -25,12 +25,19 @@ editor.title = \u00C9dition de la t\u00E2che apply.Action.text = Appliquer +apply.Action.mnemonic = A apply.Action.shortDescription = Appliquer les changements +applyAndQuit.Action.text = Appliquer et quitter +applyAndQuit.Action.mnemonic = e +applyAndQuit.Action.shortDescription = Appliquer les changements et quitter + cancel.Action.text = Quitter +cancel.Action.mnemonic= Q cancel.Action.shortDescription = Annuler et quitter revert.Action.text = Annuler +revert.Action.mnemonic= n revert.Action.shortDescription = Annuler les changements label.time.text = Temps:
participants (1)
-
tchemit@users.chorem.org