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 2d230f8e3535de87fa52d5c784836b8d3b854434 Author: Eric Chatellier <chatellier@codelutin.com> Date: Wed Mar 9 17:07:35 2016 +0100 Introduce DialogView to use proper modal view --- src/main/java/org/chorem/jtimer/JTimer.java | 3 +- .../java/org/chorem/jtimer/ui/NewTaskView.java | 11 ++-- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 63 +++++++------------ .../org/chorem/jtimer/ui/widget/DialogView.java | 72 ++++++++++++++++++++++ .../jtimer/ui/resources/TimerTaskEditor.properties | 3 - .../ui/resources/TimerTaskEditor_fr.properties | 3 - 6 files changed, 101 insertions(+), 54 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index 26b457e..c318f94 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -655,8 +655,7 @@ public class JTimer extends SingleFrameApplication implements TimerTask task = projectsAndTasksTable.getSelectedTasks().get(0); TimerTaskEditor editor = new TimerTaskEditor(this, task, core); - editor.setLocationByPlatform(true); - editor.setVisible(true); + show(editor); } /** diff --git a/src/main/java/org/chorem/jtimer/ui/NewTaskView.java b/src/main/java/org/chorem/jtimer/ui/NewTaskView.java index a571c21..f7fb709 100644 --- a/src/main/java/org/chorem/jtimer/ui/NewTaskView.java +++ b/src/main/java/org/chorem/jtimer/ui/NewTaskView.java @@ -41,8 +41,8 @@ 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.chorem.jtimer.ui.widget.DialogView; import org.jdesktop.application.Action; -import org.jdesktop.application.FrameView; /** * New task panel used to ask for: @@ -53,7 +53,7 @@ import org.jdesktop.application.FrameView; * * @author Eric Chatellier */ -public class NewTaskView extends FrameView { +public class NewTaskView extends DialogView { protected JTimer parent; protected TimerCore core; @@ -64,7 +64,7 @@ public class NewTaskView extends FrameView { protected JComboBox<String> newTaskTemplateBox; public NewTaskView(JTimer parent, TimerCore core, TimerTask selectedTask) { - super(parent); + super(parent.getMainFrame(), parent); this.parent = parent; this.core = core; this.selectedTask = selectedTask; @@ -72,9 +72,8 @@ public class NewTaskView extends FrameView { // modify frame name // otherwise, get parent frame dimention - getFrame().setName("newTask"); - getFrame().setTitle(getResourceMap().getString("newTaskTitle")); - getFrame().setResizable(false); + getDialog().setName("newTask"); + getDialog().setTitle(getResourceMap().getString("newTaskTitle")); setComponent(getMainComponent(selectedTask)); } diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index 07ccc80..7ddbda1 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -42,7 +42,6 @@ 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; @@ -67,6 +66,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.chorem.jtimer.ui.widget.DialogView; import org.jdesktop.application.Action; import org.jdesktop.application.ApplicationContext; import org.jdesktop.application.ResourceManager; @@ -79,14 +79,12 @@ import org.jdesktop.swingx.calendar.DateSelectionModel; * * @author sch */ -public class TimerTaskEditor extends JDialog { - private static final long serialVersionUID = -3612429715471081966L; +public class TimerTaskEditor extends DialogView { /** log */ private static Log log = LogFactory.getLog(TimerTaskEditor.class); - /** I18n resources map */ - protected ResourceMap resourceMap; + protected JTimer parent; protected ActionMap actionMap; /** task title */ @@ -144,19 +142,20 @@ public class TimerTaskEditor extends JDialog { /** * TimerTaskEditor * - * @param application + * @param parent * @param task * @param core */ - public TimerTaskEditor(JTimer application, TimerTask task, TimerCore core) { - super(application.getMainFrame()); - setModal(true); + public TimerTaskEditor(JTimer parent, TimerTask task, TimerCore core) { + super(parent.getMainFrame(), parent); + this.parent = parent; // remove dialog name to this dialog, due to bug // http://chorem.org/issues/484 and // http://kenai.com/jira/browse/BSAF-107 // cause infinite loop under openjdk - setName(null); // force nameExplicitlySet to true + getDialog().setName("editTask"); // force nameExplicitlySet to true + getDialog().setTitle(getResourceMap().getString("editor.title")); // set color on jxmonthview unselectable days // UIManager.put("JXMonthView.unselectableDayForeground", Color.GRAY); @@ -167,13 +166,10 @@ public class TimerTaskEditor extends JDialog { dataManager = core.getData(); // init resources map - ApplicationContext ctxt = application.getContext(); - ResourceManager mgr = ctxt.getResourceManager(); - resourceMap = mgr.getResourceMap(TimerTaskEditor.class); - actionMap = ctxt.getActionMap(this); - - // set title - setTitle(resourceMap.getString("editor.title")); + //ApplicationContext ctxt = parent.getContext(); + //ResourceManager mgr = ctxt.getResourceManager(); + //resourceMap = mgr.getResourceMap(TimerTaskEditor.class); + actionMap = parent.getContext().getActionMap(this); // build UI buildUI(); @@ -207,21 +203,10 @@ public class TimerTaskEditor extends JDialog { } }); - /* - * cancel window on window closing. - * see cancel() method - */ - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - cancel(); - } - }); - - getContentPane().setLayout(new BorderLayout(1, 0)); - getContentPane().add(createContentPanel(), BorderLayout.CENTER); - getContentPane().add(createCommandPanel(), BorderLayout.SOUTH); - pack(); + JPanel panel = new JPanel(new BorderLayout(1, 0)); + panel.add(createContentPanel(), BorderLayout.CENTER); + panel.add(createCommandPanel(), BorderLayout.SOUTH); + setComponent(panel); } /** @@ -276,13 +261,13 @@ public class TimerTaskEditor extends JDialog { */ protected JPanel createEditionPanel() { // timetask label - JLabel spinnerLabel = new JLabel(resourceMap.getString("label.time.text")); + JLabel spinnerLabel = new JLabel(getResourceMap().getString("label.time.text")); // timetask panel JPanel spinnerPanel = createSpinnersPanel(); // annotation label - JLabel annotationLabel = new JLabel(resourceMap.getString("label.annotation.text")); + JLabel annotationLabel = new JLabel(getResourceMap().getString("label.annotation.text")); // timetask textarea annotationText = new JTextArea(); @@ -633,6 +618,8 @@ public class TimerTaskEditor extends JDialog { @Action(enabledProperty = "dataChanged") public void apply() { + getApplication().hide(this); + try { // title if (isTitleChanged) { @@ -667,17 +654,13 @@ public class TimerTaskEditor extends JDialog { 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(); + parent.displayErrorMessage(ex.getExceptionKey()); } } @Action public void cancel() { - dispose(); + getApplication().hide(this); } public boolean isDataChanged() { diff --git a/src/main/java/org/chorem/jtimer/ui/widget/DialogView.java b/src/main/java/org/chorem/jtimer/ui/widget/DialogView.java new file mode 100644 index 0000000..74ec610 --- /dev/null +++ b/src/main/java/org/chorem/jtimer/ui/widget/DialogView.java @@ -0,0 +1,72 @@ +/* + * #%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.widget; + +import static org.jdesktop.application.Application.KEY_APPLICATION_ICON; +import static org.jdesktop.application.Application.KEY_APPLICATION_TITLE; + +import java.awt.Frame; +import java.awt.Image; + +import javax.swing.JDialog; +import javax.swing.JRootPane; + +import org.jdesktop.application.Application; +import org.jdesktop.application.ResourceMap; +import org.jdesktop.application.View; + +/** + * Another implementation of FrameView, but using a dialog to use modal state and non visible + * window in window task bar. + */ +public class DialogView extends View { + public static final String MAIN_DIALOG_NAME = "mainDialog"; + + protected Frame owner; + protected JDialog dialog; + + public DialogView(Frame owner, Application application) { + super(application); + this.owner = owner; + } + + public JDialog getDialog() { + if (dialog == null) { + ResourceMap resourceMap = getContext().getResourceMap(); + String title = resourceMap.getString(KEY_APPLICATION_TITLE); + + dialog = new JDialog(owner, title); + dialog.setName(MAIN_DIALOG_NAME); + dialog.setModal(true); + if (resourceMap.containsKey(KEY_APPLICATION_ICON)) { + Image icon = resourceMap.getImageIcon(KEY_APPLICATION_ICON).getImage(); + dialog.setIconImage(icon); + } + } + return dialog; + } + + @Override + public JRootPane getRootPane() { + return getDialog().getRootPane(); + } +} 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 74ab915..5d4303b 100644 --- a/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties +++ b/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties @@ -31,6 +31,3 @@ cancel.Action.shortDescription = Revert changes and quit label.time.text = Time: label.annotation.text = Annotation: - -vetoException.title = Error -vetoException.message = A veto has been raised during saving your task. \nChanges would not be saved. 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 082dac0..0325c69 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 @@ -31,6 +31,3 @@ cancel.Action.shortDescription = Annuler et quitter label.time.text = Temps: label.annotation.text = Note: - -vetoException.title = Erreur -vetoException.message = Un veto a \u00E9t\u00E9 lev\u00E9 lors de la sauvegarde de la t\u00E2che. \nLes modifications ne pourront \u00EAtre enregistr\u00E9es. -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.