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 a8041207c6b4321eb5edc0dab98e5ce93f6aa418 Author: Eric Chatellier <chatellier@codelutin.com> Date: Wed Mar 9 16:03:40 2016 +0100 fixes #1337: When creating a new task, focus is not ok fixes #1340: I cancel the creation of a new task, but it is still created --- src/main/java/org/chorem/jtimer/JTimer.java | 32 +---- .../java/org/chorem/jtimer/ui/NewTaskPanel.java | 105 -------------- .../java/org/chorem/jtimer/ui/NewTaskView.java | 159 +++++++++++++++++++++ .../org/chorem/jtimer/resources/JTimer.properties | 3 - .../chorem/jtimer/resources/JTimer_fr.properties | 3 - .../jtimer/ui/resources/NewTaskView.properties | 31 ++++ .../jtimer/ui/resources/NewTaskView_fr.properties | 30 ++++ 7 files changed, 225 insertions(+), 138 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index a8db87c..228a8be 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -67,7 +67,7 @@ import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.ui.HelpFrame; -import org.chorem.jtimer.ui.NewTaskPanel; +import org.chorem.jtimer.ui.NewTaskView; import org.chorem.jtimer.ui.StatusBar; import org.chorem.jtimer.ui.TimerTaskEditor; import org.chorem.jtimer.ui.alert.AlertEditor; @@ -550,7 +550,7 @@ public class JTimer extends SingleFrameApplication implements * * @param errorMessageKey saf error message key */ - protected void displayErrorMessage(String errorMessageKey) { + public void displayErrorMessage(String errorMessageKey) { String title = resourceMap.getString("action.invalidActionTitle"); String message = resourceMap.getString(errorMessageKey); @@ -632,32 +632,10 @@ public class JTimer extends SingleFrameApplication implements public void newTask() { // select task to add new task - TimerTask selectedTask = projectsAndTasksTable.getSelectedElements() - .get(0); - - NewTaskPanel newTaskPanel = new NewTaskPanel(this, selectedTask); - JOptionPane.showMessageDialog(getMainFrame(), newTaskPanel, resourceMap - .getString("input.newTaskTitle"), JOptionPane.QUESTION_MESSAGE); - String taskName = newTaskPanel.getTaskName(); - String taskTemplate = newTaskPanel.getTaskTemplate(); - - if (taskName != null) { - - // remove unneeded spaces - taskName = taskName.trim(); - - TimerTask t = new TimerTask(taskName); - - // Fix creation date - t.setCreationDate(new Date()); - - try { - core.getData().addTask(selectedTask, t, taskTemplate); - } catch (DataViolationException e) { - displayErrorMessage(e.getExceptionKey()); - } - } + TimerTask selectedTask = projectsAndTasksTable.getSelectedElements().get(0); + NewTaskView newTaskPanel = new NewTaskView(this, core, selectedTask); + show(newTaskPanel); } /** diff --git a/src/main/java/org/chorem/jtimer/ui/NewTaskPanel.java b/src/main/java/org/chorem/jtimer/ui/NewTaskPanel.java deleted file mode 100644 index 4d4e3bd..0000000 --- a/src/main/java/org/chorem/jtimer/ui/NewTaskPanel.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2016 CodeLutin, Chatellier Eric - * %% - * 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 3 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package org.chorem.jtimer.ui; - -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.util.Map; -import java.util.Set; - -import javax.swing.DefaultComboBoxModel; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.entities.TimerTask; -import org.jdesktop.application.Application; -import org.jdesktop.application.ResourceMap; - -/** - * New task panel used to ask for: - * <ul> - * <li>Task name</li> - * <li>Task template (if available)</li> - * </ul> - * - * @author Eric Chatellier - */ -public class NewTaskPanel extends JPanel { - - /** serialVersionUID. */ - private static final long serialVersionUID = -6725150779251233404L; - - protected JTextField newTaskField; - protected JComboBox<String> newTaskTemplateBox; - - public NewTaskPanel(Application app, TimerTask selectedTask) { - super(new GridBagLayout()); - - ResourceMap resourceMap = app.getContext().getResourceMap(); - - // task name - JLabel newTaskLabel = new JLabel(resourceMap.getString("input.newTaskMessage", selectedTask.getName())); - this.add(newTaskLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, - new Insets(1, 1, 1, 1), 0, 0)); - newTaskField = new JTextField(); - this.add(newTaskField, new GridBagConstraints(0, 1, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, - new Insets(1, 1, 1, 1), 0, 0)); - - // Task template - Map<String, Object> templates = JTimer.config.getTaskTemplates(); - - - newTaskTemplateBox = new JComboBox<>(); - if (templates != null && !templates.isEmpty()) { - - // model - Set<String> templateNames = templates.keySet(); - DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(templateNames.toArray(new String[templateNames.size()])); - model.insertElementAt(null, 0); // empty option - newTaskTemplateBox.setModel(model); - newTaskTemplateBox.setSelectedItem(null); // empty option - - JLabel newTaskTemplateLabel = new JLabel(resourceMap.getString("input.newTaskTemplate")); - this.add(newTaskTemplateLabel, new GridBagConstraints(0, 2, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, - new Insets(1, 1, 1, 1), 0, 0)); - - this.add(newTaskTemplateBox, new GridBagConstraints(0, 3, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, - new Insets(1, 1, 1, 1), 0, 0)); - } - } - - public String getTaskName() { - return newTaskField.getText(); - } - - public String getTaskTemplate() { - return (String)newTaskTemplateBox.getSelectedItem(); - } -} diff --git a/src/main/java/org/chorem/jtimer/ui/NewTaskView.java b/src/main/java/org/chorem/jtimer/ui/NewTaskView.java new file mode 100644 index 0000000..a571c21 --- /dev/null +++ b/src/main/java/org/chorem/jtimer/ui/NewTaskView.java @@ -0,0 +1,159 @@ +/* + * #%L + * jTimer + * %% + * Copyright (C) 2016 CodeLutin, Chatellier Eric + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package org.chorem.jtimer.ui; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.util.Date; +import java.util.Map; +import java.util.Set; + +import javax.swing.ActionMap; +import javax.swing.DefaultComboBoxModel; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.data.DataViolationException; +import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.entities.TimerTask; +import org.jdesktop.application.Action; +import org.jdesktop.application.FrameView; + +/** + * New task panel used to ask for: + * <ul> + * <li>Task name</li> + * <li>Task template (if available)</li> + * </ul> + * + * @author Eric Chatellier + */ +public class NewTaskView extends FrameView { + + protected JTimer parent; + protected TimerCore core; + protected ActionMap actionMap; + protected TimerTask selectedTask; + + protected JTextField newTaskField; + protected JComboBox<String> newTaskTemplateBox; + + public NewTaskView(JTimer parent, TimerCore core, TimerTask selectedTask) { + super(parent); + this.parent = parent; + this.core = core; + this.selectedTask = selectedTask; + actionMap = parent.getContext().getActionMap(this); + + // modify frame name + // otherwise, get parent frame dimention + getFrame().setName("newTask"); + getFrame().setTitle(getResourceMap().getString("newTaskTitle")); + getFrame().setResizable(false); + + setComponent(getMainComponent(selectedTask)); + } + + protected JPanel getMainComponent(TimerTask selectedTask) { + JPanel panel = new JPanel(new GridBagLayout()); + + // icon + JLabel newTaskIcon = new JLabel(new ImageIcon(getClass().getResource("../resources/document-new.png"))); + panel.add(newTaskIcon, new GridBagConstraints(0, 0, 1, 4, 0, 0, + GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + + // task name + JLabel newTaskLabel = new JLabel(getResourceMap().getString("input.newTaskMessage", selectedTask.getName())); + panel.add(newTaskLabel, new GridBagConstraints(1, 0, 2, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0)); + newTaskField = new JTextField(); + panel.add(newTaskField, new GridBagConstraints(1, 1, 2, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 0, 5), 0, 0)); + + // Task template + Map<String, Object> templates = JTimer.config.getTaskTemplates(); + + newTaskTemplateBox = new JComboBox<>(); + if (templates != null && !templates.isEmpty()) { + + // model + Set<String> templateNames = templates.keySet(); + DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(templateNames.toArray(new String[templateNames.size()])); + model.insertElementAt(null, 0); // empty option + newTaskTemplateBox.setModel(model); + newTaskTemplateBox.setSelectedItem(null); // empty option + + JLabel newTaskTemplateLabel = new JLabel(getResourceMap().getString("input.newTaskTemplate")); + panel.add(newTaskTemplateLabel, new GridBagConstraints(1, 2, 2, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0)); + + panel.add(newTaskTemplateBox, new GridBagConstraints(1, 3, 2, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 0, 5), 0, 0)); + } + + // ok cancel buttons + JButton okButton = new JButton(); + okButton.setAction(actionMap.get("valid")); + panel.add(okButton, new GridBagConstraints(1, 4, 1, 1, 1, 0, + GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 1), 0, 0)); + + JButton cancelButton = new JButton(); + cancelButton.setAction(actionMap.get("cancel")); + panel.add(cancelButton, new GridBagConstraints(2, 4, 1, 1, 1, 0, + GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 1, 5, 5), 0, 0)); + + return panel; + } + + @Action + public void valid() { + String taskName = newTaskField.getText(); + String taskTemplate = (String)newTaskTemplateBox.getSelectedItem(); + + getApplication().hide(this); + + // remove unneeded spaces + taskName = taskName.trim(); + + TimerTask t = new TimerTask(taskName); + + // Fix creation date + t.setCreationDate(new Date()); + + try { + core.getData().addTask(selectedTask, t, taskTemplate); + } catch (DataViolationException e) { + parent.displayErrorMessage(e.getExceptionKey()); + } + } + + @Action + public void cancel() { + getApplication().hide(this); + } +} diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties index 9c25f8f..7eaaa13 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties @@ -161,9 +161,6 @@ input.editProjectTitle=Edit project input.editProjectMessage=New project name : input.deleteProjectTitle=Confirm input.deleteProjectMessage=Do you want to delete project "%s" ? -input.newTaskTitle=New task -input.newTaskMessage=Task name to create for "%s" : -input.newTaskTemplate=Task template to use : input.editTaskTitle=Edit task input.editTaskMessage=New task name : input.deleteTaskTitle=Confirm diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties index ea42975..192ac7a 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties @@ -126,9 +126,6 @@ input.editProjectTitle=\u00C9dition du projet input.editProjectMessage=Nouveau nom du projet : input.deleteProjectTitle=Confirmation input.deleteProjectMessage=Voulez-vous supprimer le projet "%s" ? -input.newTaskTitle=Nouvelle t\u00E2che -input.newTaskMessage=Nom de la t\u00E2che \u00E0 cr\u00E9er pour "%s" : -input.newTaskTemplate=Template \u00E0 utiliser : input.editTaskTitle=\u00C9dition de la t\u00E2che input.editTaskMessage=Nouveau nom de la t\u00E2che : input.deleteTaskTitle=Confirmation diff --git a/src/main/resources/org/chorem/jtimer/ui/resources/NewTaskView.properties b/src/main/resources/org/chorem/jtimer/ui/resources/NewTaskView.properties new file mode 100644 index 0000000..1e5302e --- /dev/null +++ b/src/main/resources/org/chorem/jtimer/ui/resources/NewTaskView.properties @@ -0,0 +1,31 @@ +### +# #%L +# jTimer +# %% +# Copyright (C) 2016 CodeLutin, Chatellier Eric +# %% +# 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 3 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, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### +newTaskTitle=New task +newTaskIcon.icon = document-new.png +input.newTaskMessage=Task name to create for "%s" : +input.newTaskTemplate=Task template to use : + +valid.Action.text = OK +valid.Action.accelerator = control O + +cancel.Action.text = Cancel +cancel.Action.accelerator = control C diff --git a/src/main/resources/org/chorem/jtimer/ui/resources/NewTaskView_fr.properties b/src/main/resources/org/chorem/jtimer/ui/resources/NewTaskView_fr.properties new file mode 100644 index 0000000..40994da --- /dev/null +++ b/src/main/resources/org/chorem/jtimer/ui/resources/NewTaskView_fr.properties @@ -0,0 +1,30 @@ +### +# #%L +# jTimer +# %% +# Copyright (C) 2016 CodeLutin, Chatellier Eric +# %% +# 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 3 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, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### +newTaskTitle=Nouvelle t\u00E2che +input.newTaskMessage=Nom de la t\u00E2che \u00E0 cr\u00E9er pour "%s" : +input.newTaskTemplate=Template \u00E0 utiliser : + +valid.Action.text = OK +valid.Action.accelerator = control O + +cancel.Action.text = Annuler +cancel.Action.accelerator = control A -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.