r2732 - in isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui: simulator widget
Author: chatellier Date: 2009-11-02 16:39:13 +0000 (Mon, 02 Nov 2009) New Revision: 2732 Removed: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/EnabledIfItemSelectedInList.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/EnabledIfListNotEmpty.java Log: Replaced by jaxx bindings Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java 2009-11-02 16:37:16 UTC (rev 2731) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorListeners.java 2009-11-02 16:39:13 UTC (rev 2732) @@ -1,171 +0,0 @@ -/* *##% - * Copyright (C) 2005 - 2009 - * Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -package fr.ifremer.isisfish.ui.simulator; - -import fr.ifremer.isisfish.simulator.launcher.SimulationService; -import fr.ifremer.isisfish.ui.widget.EnabledIfListNotEmpty; -import fr.ifremer.isisfish.ui.widget.EnabledIfItemSelectedInList; - -import static org.nuiton.i18n.I18n._; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JButton; -import javax.swing.JList; -import javax.swing.JTable; -import javax.swing.ListModel; - -/** - * This class contains some listeners used in ui. Some are generics and could - * be push in a library. - * <p/> - * TODO ne fonctionne pas avec l'uitlisation de l'attribut init dans le xml - * TODO Il faudrait fixer cette anomalie afin de pouvoir directement appelé - * TODO ce code depuis le xml... - * - * @author chemit - * - * @deprecated since 20090414, use jaxx bindings instead - */ -public class SimulatorListeners { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - private static Log log = LogFactory.getLog(SimulatorListeners.class); - - public static void initAnalysePlanButtonsListener(JButton remove, JList list) { - initButtonRemoveIfItemSelected(remove, list); - } - - public static void initRuleButtonsListener(JButton remove, JList list) { - initButtonRemoveIfItemSelected(remove, list); - - } - -// public static void initSimulQueueButtonsListener( -// final JButton start, final JButton remove, final JButton showLog, -// final JTable table, final JTable tableDone) { -// -// SimulationService.getService().addPropertyChangeListener("autoLaunch", -// new PropertyChangeListener() { -// public void propertyChange(PropertyChangeEvent evt) { -// start.setEnabled(isSimulStartButtonEnabled(table)); -// } -// }); -// -// table.getModel().addTableModelListener(new TableModelListener() { -// public void tableChanged(TableModelEvent e) { -// start.setEnabled(isSimulStartButtonEnabled(table)); -// } -// }); -// -// table.getSelectionModel().addListSelectionListener( -// new ListSelectionListener() { -// public void valueChanged(ListSelectionEvent e) { -// remove.setEnabled(isSimulRemoveButtonEnabled(table)); -// } -// }); -// -// tableDone.getSelectionModel().addListSelectionListener( -// new ListSelectionListener() { -// public void valueChanged(ListSelectionEvent e) { -// showLog.setEnabled(isSimulShowLogButtonEnabled(tableDone)); -// } -// } -// ); -// -// // apply it now -// start.setEnabled(isSimulStartButtonEnabled(table)); -// remove.setEnabled(isSimulRemoveButtonEnabled(table)); -// showLog.setEnabled(isSimulShowLogButtonEnabled(tableDone)); -// } - - public static void initButtonRemoveIfItemSelected( - final JButton button, final JList list) { - if (button == null || list == null) { - log.warn(_("isisfish.error.init.remove.button", button, list)); - return; - } - button.setEnabled(list.getSelectedIndex() > -1); - EnabledIfItemSelectedInList listener = new EnabledIfItemSelectedInList(button, list); - list.getSelectionModel().addListSelectionListener(listener); - // apply it now - listener.setEnabled(button, list); - } - - public static void initButtonClearIfListNotEmpty( - final JButton button, final ListModel list) { - - EnabledIfListNotEmpty listener = new EnabledIfListNotEmpty(list, button); - list.addListDataListener(listener); - // apply it now - listener.setEnabled(button, list); - } - - /** - * Wonders if user can actually launch simulations based on two criteri : - * <ul><li> first : simulationManager must not be in autoLaunch mode</li> - * <li> second : simulation table must not be empty</li></ul> - * - * @param table table containing queue of simulations not already done - * @return <code>true</code> if user can launch simulations, - * <code>false</code> otherwise - */ - public static boolean isSimulStartButtonEnabled(JTable table) { - return !SimulationService.getService().isAutoLaunch() && - (table.getRowCount() > 0); - } - - /** - * Wonders if user can actually stop a simulation on two criteri : - * <ul><li> first : use must have select a simulation - * (but not a done one)</li> - * <li> second : the selected simulation must be running</li></ul> - * - * @param table table containing queue of simulations not already done - * @return <code>true</code> if user can stop the selected simulation, - * <code>false</code> otherwise - */ - public static boolean isSimulRemoveButtonEnabled(JTable table) { - return isItemSelected(table); - } - - /** - * Wonders if user can actually show log of a done simulation on one criteria : - * <ul><li> first : use must have select a done simulation - * (but not a undone one)</li> - * - * @param table table containing queue of simulations not already done - * @return <code>true</code> if user can show log the selected done - * simulation,<code>false</code> otherwise - */ - public static boolean isSimulShowLogButtonEnabled(JTable table) { - return isItemSelected(table); - } - - public static boolean isItemSelected(JTable table) { - return table.getRowCount() > 0 && table.getSelectedRow() > -1; - } - - public static boolean isItemSelected(JList table) { - return table.getModel().getSize() > 0 && table.getSelectedIndex() > -1; - } - -} Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/EnabledIfItemSelectedInList.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/EnabledIfItemSelectedInList.java 2009-11-02 16:37:16 UTC (rev 2731) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/EnabledIfItemSelectedInList.java 2009-11-02 16:39:13 UTC (rev 2732) @@ -1,46 +0,0 @@ -/* *##% - * Copyright (C) 2002 - 2009 Code Lutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -package fr.ifremer.isisfish.ui.widget; - -import javax.swing.event.ListSelectionListener; -import javax.swing.event.ListSelectionEvent; -import javax.swing.JComponent; -import javax.swing.JList; -import javax.swing.JButton; - -/** - * Enable a button if the associated list is not empty. - */ -public class EnabledIfItemSelectedInList implements ListSelectionListener { - private final JComponent button; - private final JList list; - - public EnabledIfItemSelectedInList(JButton button, JList list) { - this.button = button; - this.list = list; - } - - public void setEnabled(JComponent button, JList list) { - button.setEnabled(list.getSelectedIndex() > -1); - } - - public void valueChanged(ListSelectionEvent e) { - setEnabled(button, list); - } -} Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/EnabledIfListNotEmpty.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/EnabledIfListNotEmpty.java 2009-11-02 16:37:16 UTC (rev 2731) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/EnabledIfListNotEmpty.java 2009-11-02 16:39:13 UTC (rev 2732) @@ -1,59 +0,0 @@ -/* *##% - * Copyright (C) 2002 - 2009 Code Lutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -package fr.ifremer.isisfish.ui.widget; - -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.ListModel; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; - -/** - * Enable a button if the associated list is not empty. - */ -public class EnabledIfListNotEmpty implements ListDataListener { - - private JComponent target; - private ListModel list; - - public EnabledIfListNotEmpty(ListModel list, JButton target) { - this.target = target; - this.list = list; - } - - public void contentsChanged(ListDataEvent e) { - setEnabled(target, list); - } - - public void intervalAdded(ListDataEvent e) { - setEnabled(target, list); - } - - public void intervalRemoved(ListDataEvent e) { - setEnabled(target, list); - } - - public void setEnabled(JComponent button, ListModel list) { - button.setEnabled(list.getSize() > 0); - } - - public void setTarget(JComponent target) { - this.target = target; - } -}
participants (1)
-
chatellier@users.labs.libre-entreprise.org