This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jtimer. See http://git.chorem.org/jtimer.git commit 7b1e363e54a3da254be578c2d9cf6d5a8c970958 Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Mar 8 14:13:13 2016 +0100 Refactor task editor with saf --- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 243 ++++++--------------- .../org/chorem/jtimer/resources/JTimer.properties | 4 +- .../jtimer/ui/resources/TimerTaskEditor.properties | 14 +- .../ui/resources/TimerTaskEditor_fr.properties | 16 +- 4 files changed, 79 insertions(+), 198 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index ca301fb..5a28e48 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -1,5 +1,5 @@ /* - * #%L +z * #%L * jTimer * %% * Copyright (C) 2008 - 2016 CodeLutin, Chorlet Stéphane, Chatellier Eric, Chemit Tony @@ -24,10 +24,9 @@ package org.chorem.jtimer.ui; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Cursor; import java.awt.FlowLayout; +import java.awt.GridLayout; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ArrayList; @@ -40,10 +39,12 @@ import java.util.Set; import java.util.StringTokenizer; import javax.swing.AbstractAction; +import javax.swing.ActionMap; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSpinner; @@ -58,7 +59,6 @@ import javax.swing.event.ChangeListener; 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; @@ -67,6 +67,7 @@ import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.data.TimerDataManager; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; +import org.jdesktop.application.Action; import org.jdesktop.application.ApplicationContext; import org.jdesktop.application.ResourceManager; import org.jdesktop.application.ResourceMap; @@ -78,7 +79,7 @@ import org.jdesktop.swingx.calendar.DateSelectionModel; * * @author sch */ -public class TimerTaskEditor extends JDialog implements ActionListener { +public class TimerTaskEditor extends JDialog { private static final long serialVersionUID = -3612429715471081966L; /** log */ @@ -86,6 +87,7 @@ public class TimerTaskEditor extends JDialog implements ActionListener { /** I18n resources map */ protected ResourceMap resourceMap; + protected ActionMap actionMap; /** task title */ protected JTextField titleText; @@ -116,6 +118,7 @@ public class TimerTaskEditor extends JDialog implements ActionListener { /** task manager */ protected TimerDataManager dataManager; + protected boolean dataChanged; /** did the modified the title ? */ protected boolean isTitleChanged; /** did the modified annotation ? */ @@ -126,6 +129,7 @@ public class TimerTaskEditor extends JDialog implements ActionListener { * this set keep track of days modified (for time, annotations or title). */ protected Set<Date> dateChanged = new HashSet<>(); + /** * days where annotation were modified: You can modify any number of days before you apply changes, * this set keep track of days where annotations were modified. @@ -137,20 +141,6 @@ public class TimerTaskEditor extends JDialog implements ActionListener { */ protected Calendar selectedDay; - /** - * 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) - */ - protected JButton revertButton; - /** * TimerTaskEditor * @@ -180,6 +170,7 @@ public class TimerTaskEditor extends JDialog implements ActionListener { ApplicationContext ctxt = application.getContext(); ResourceManager mgr = ctxt.getResourceManager(); resourceMap = mgr.getResourceMap(TimerTaskEditor.class); + actionMap = ctxt.getActionMap(this); // set title setTitle(resourceMap.getString("editor.title")); @@ -240,40 +231,18 @@ public class TimerTaskEditor extends JDialog implements ActionListener { */ protected JPanel createCommandPanel() { // apply button - applyButton = new JButton(resourceMap.getString("apply.Action.text")); - 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); + JButton applyButton = new JButton(); + applyButton.setAction(actionMap.get("apply")); // cancel button - JButton cancelButton = new JButton(resourceMap - .getString("cancel.Action.text")); - cancelButton.setActionCommand("cancel"); - cancelButton.addActionListener(this); - addMnemonic("cancel.Action.mnemonic", cancelButton); + JButton cancelButton = new JButton(); + cancelButton.setAction(actionMap.get("cancel")); // command panel JPanel panel = new JPanel(); - panel.setLayout(new FlowLayout(FlowLayout.RIGHT, 1, 0)); - panel.add(applyButton); - //panel.add(applyAndQuitButton); - panel.add(revertButton); + panel.setLayout(new GridLayout(1, 0)); panel.add(cancelButton); + panel.add(applyButton); return panel; } @@ -307,20 +276,17 @@ public class TimerTaskEditor extends JDialog implements ActionListener { */ protected JPanel createEditionPanel() { // timetask label - JLabel spinnerLabel = new JLabel(resourceMap - .getString("label.time.text")); + JLabel spinnerLabel = new JLabel(resourceMap.getString("label.time.text")); // timetask panel JPanel spinnerPanel = createSpinnersPanel(); // annotation label - JLabel annotationLabel = new JLabel(resourceMap - .getString("label.annotation.text")); + JLabel annotationLabel = new JLabel(resourceMap.getString("label.annotation.text")); // timetask textarea annotationText = new JTextArea(); - annotationText.getDocument().addDocumentListener( - annotationChangeListener); + annotationText.getDocument().addDocumentListener(annotationChangeListener); annotationText.setRows(4); annotationText.setLineWrap(true); annotationText.setWrapStyleWord(true); @@ -380,8 +346,7 @@ public class TimerTaskEditor extends JDialog implements ActionListener { monthView.setFlaggedDayForeground(Color.BLUE); // single selection - monthView - .setSelectionMode(DateSelectionModel.SelectionMode.SINGLE_SELECTION); + monthView.setSelectionMode(DateSelectionModel.SelectionMode.SINGLE_SELECTION); // upper selectable day Calendar yesterdayCalendar = Calendar.getInstance(); @@ -494,8 +459,7 @@ public class TimerTaskEditor extends JDialog implements ActionListener { spinnerS.setValue(0); } } - - } + } updateTask(); } @@ -519,59 +483,6 @@ public class TimerTaskEditor extends JDialog implements ActionListener { } /** - * events from command buttons - */ - @Override - public void actionPerformed(ActionEvent e) { - String actionCommand = e.getActionCommand(); - - - if ("cancel".equals(actionCommand)) { - cancel(); - - } else if ("apply".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)); - - } 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(); - } - } - - /** * Monthview selected day. * * @return monthview selected day @@ -697,9 +608,7 @@ public class TimerTaskEditor extends JDialog implements ActionListener { } dateChanged.add(getSelectedDay().getTime()); - applyButton.setEnabled(true); - applyAndQuitButton.setEnabled(true); - revertButton.setEnabled(true); + setDataChanged(true); updateFlaggedDates(); } @@ -708,7 +617,7 @@ public class TimerTaskEditor extends JDialog implements ActionListener { * flag calendar days according to tasktime */ public void updateFlaggedDates() { - ArrayList<Date> dates = new ArrayList<>(); + List<Date> dates = new ArrayList<>(); for (Date date : cloneTask.getAllDaysAndTimes().keySet()) { if (cloneTask.getTime(date) > 0) { @@ -721,75 +630,63 @@ public class TimerTaskEditor extends JDialog implements ActionListener { monthView.setFlaggedDates(dates.toArray(new Date[dates.size()])); } - protected void revert() { - cloneTask = task.clone(); - - dateChanged.clear(); - annotationChanged.clear(); - applyButton.setEnabled(false); - applyAndQuitButton.setEnabled(false); - revertButton.setEnabled(false); - isTitleChanged = false; - isAnnotationChanged = false; - - displayTask(getSelectedDay().getTime()); - updateFlaggedDates(); - } - - protected void apply() { + @Action(enabledProperty = "dataChanged") + public void apply() { - // title - if (isTitleChanged) { - dataManager.editTask(task, cloneTask.getName()); - } - - for (Date date : dateChanged) { - if (log.isDebugEnabled()) { - log.debug("Applying changes on: " + date); + try { + // title + if (isTitleChanged) { + dataManager.editTask(task, cloneTask.getName()); } - - // time - dataManager.changeTaskTime(task, date, cloneTask - .getTime(date)); - - // annotation - if (annotationChanged.contains(date)) { - TimerTaskHelper.removeAnnotation(task, date); - - Map<Date, String> annotations = TimerTaskHelper - .getAnnotationMap(cloneTask, date); - for (Date date2 : annotations.keySet()) { - dataManager.addAnnotation(task, date2, - annotations.get(date2)); + + for (Date date : dateChanged) { + if (log.isDebugEnabled()) { + log.debug("Applying changes on: " + date); + } + + // time + dataManager.changeTaskTime(task, date, cloneTask + .getTime(date)); + + // annotation + if (annotationChanged.contains(date)) { + TimerTaskHelper.removeAnnotation(task, date); + + Map<Date, String> annotations = TimerTaskHelper + .getAnnotationMap(cloneTask, date); + for (Date date2 : annotations.keySet()) { + dataManager.addAnnotation(task, date2, + annotations.get(date2)); + } } } + + /*dateChanged.clear(); + annotationChanged.clear(); + setDataChanged(false); + isTitleChanged = false; + isAnnotationChanged = false;*/ + } catch (DataViolationException ex) { + String title = resourceMap.getString("vetoException.title"); + String message = resourceMap.getString("vetoException.message"); + JOptionPane.showMessageDialog(this, message, title, JOptionPane.ERROR_MESSAGE); + } finally { + dispose(); } - - dateChanged.clear(); - annotationChanged.clear(); - applyButton.setEnabled(false); - applyAndQuitButton.setEnabled(false); - revertButton.setEnabled(false); - isTitleChanged = false; - isAnnotationChanged = false; } - protected void cancel() { + @Action + public void cancel() { 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)) { + public boolean isDataChanged() { + return dataChanged; + } - button.setMnemonic(string.charAt(0)); - } + public void setDataChanged(boolean dataChanged) { + boolean oldValue = this.dataChanged; + this.dataChanged = dataChanged; + firePropertyChange("dataChanged", oldValue, dataChanged); } } diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties index ea8bf2e..9c25f8f 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties @@ -182,8 +182,8 @@ vetoable.common.duplicated.project.name=A project already exists with that name vetoable.common.duplicated.task.name=A task already exists with that name at this level ! vetoable.common.merge.invalid.types=Can't merge project and task ! vetoable.common.move.invalid.types=Can't move project ! -vetoable.saver.empty.task.name=Empty task name ! -vetoable.saver.invalid.task.characters=Task name contains invalid characters ! +vetoable.saver.empty.name=Empty task name ! +vetoable.saver.invalid.characters=Task name contains invalid characters ! vetoable.ws.chorem.cant.modify.synchronized.project=Can't do this action on a synchronized project ! # Start fail i18n diff --git a/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties b/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties index 0ebe795..74ab915 100644 --- a/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties +++ b/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties @@ -2,7 +2,7 @@ # #%L # jTimer # %% -# Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric, Chemit Tony +# Copyright (C) 2007 - 2016 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,18 +25,10 @@ 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.text = Cancel +cancel.Action.mnemonic = C cancel.Action.shortDescription = Revert changes and quit -revert.Action.text = Revert -revert.Action.mnemonic= R -revert.Action.shortDescription = Revert changes - label.time.text = Time: label.annotation.text = Annotation: diff --git a/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties b/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties index e14f8ac..082dac0 100644 --- a/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties +++ b/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties @@ -2,7 +2,7 @@ # #%L # jTimer # %% -# Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric, Chemit Tony +# Copyright (C) 2007 - 2016 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 @@ -21,22 +21,14 @@ ### editor.title = \u00C9dition de la t\u00E2che -apply.Action.text = Appliquer -apply.Action.mnemonic = A +apply.Action.text = Valider +apply.Action.mnemonic = V 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.text = Annuler 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: label.annotation.text = Note: -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.