Author: tchemit Date: 2008-02-04 18:58:07 +0000 (Mon, 04 Feb 2008) New Revision: 653 Removed: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAbstractAction.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ShowTabAbstractAction.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractAction.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractTabAction.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ToggleTabAbstractAction.java Log: normalisation nom paquetage Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAbstractAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAbstractAction.java 2008-02-04 18:57:45 UTC (rev 652) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAbstractAction.java 2008-02-04 18:58:07 UTC (rev 653) @@ -1,87 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* 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.cemagref.simexplorer.is.ui.swing.action; - -import fr.cemagref.simexplorer.is.ui.SimExplorer; -import org.apache.commons.beanutils.Converter; -import org.codelutin.i18n.CountryEnum; -import org.codelutin.i18n.I18n; -import org.codelutin.i18n.LanguageEnum; -import org.codelutin.util.ConverterUtil; - -import java.awt.event.ActionEvent; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Une action pour recharger la locale. - * <p/> - * Le nom de l'action doit etre de la forme i18n_XX_YY où XX est la langue - * et YY le pays de la locale à charger. - * - * @author chemit - * @see LanguageEnum - * @see CountryEnum - */ -public abstract class ChangeI18nAbstractAction extends SimExplorerAbstractAction { - - public static final Pattern PATTERN_NAME = Pattern.compile("i18n_(\\w\\w)_(\\w\\w)"); - - protected LanguageEnum language; - protected CountryEnum country; - - private static final long serialVersionUID = 4180668477670765253L; - - public ChangeI18nAbstractAction(String name) { - super(name); - Matcher matcher = PATTERN_NAME.matcher(name); - if (!matcher.matches()) { - throw new IllegalArgumentException(I18n._(getClass().getName() + " should have a nmae like this 'i18n_XX_YY', but was {0}", name)); - } - Converter convertorLanguage = ConverterUtil.getConverter(LanguageEnum.class); - language = (LanguageEnum) convertorLanguage.convert(LanguageEnum.class, matcher.group(1)); - - convertorLanguage = ConverterUtil.getConverter(CountryEnum.class); - country = (CountryEnum) convertorLanguage.convert(CountryEnum.class, matcher.group(2)); - } - - @Override - public void doAction(java.awt.event.ActionEvent e) { - - //TODO Should ask confirm from user since it will close ui, and re instanciate ui - - getMainUI().getQuit().getAction().actionPerformed(new ActionEvent(this, ActionEvent.ACTION_FIRST, "cancel")); - SimExplorer.reloadUI(); - getContext().getConfig().setI18n(language, country); - getContext().getConfig().initI18n(); - - SimExplorer.launch(); - - SimExplorer.getContext().saveSafely(); - } - - public boolean equalsLocale(LanguageEnum lang, CountryEnum countr) { - return language == lang && country == countr; - } - - @Override - public String toString() { - return super.toString() + " Language " + language + " Country " + country; - } -} \ No newline at end of file Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ShowTabAbstractAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ShowTabAbstractAction.java 2008-02-04 18:57:45 UTC (rev 652) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ShowTabAbstractAction.java 2008-02-04 18:58:07 UTC (rev 653) @@ -1,89 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit, Gariel Landais -* -* 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.cemagref.simexplorer.is.ui.swing.action; - -import jaxx.runtime.JAXXObject; -import jaxx.runtime.builder.TabModel; - -import java.awt.event.ActionEvent; - -/** - * Action pour afficher une tab. * - * - * @author chemit - */ -public abstract class ShowTabAbstractAction<U extends JAXXObject, M extends TabModel> extends SimExplorerAbstractTabAction { - - protected abstract void initFirstUsage(U ui, M model); - - protected abstract void initUI(U ui, M model); - - protected Boolean firstTime; - - - private static final long serialVersionUID = -2050956371415306760L; - - protected ShowTabAbstractAction(String name) { - super(name, "showTab"); - } - - - @Override - protected boolean beforeAction(ActionEvent e) throws Exception { - - // mark the first use of the tab - firstTime = getUI() == null; - - return true; - } - - @Override - protected void doAction(ActionEvent e) throws Exception { - getTab().showTab(getTabContainer()); - } - - @Override - protected void afterAction(ActionEvent e) throws Exception { - super.afterAction(e); - U ui = getTabUI(); - M model = getTabModel(); - if (firstTime) { - initFirstUsage(ui, model); - } - initUI(ui,model); - - } - - @Override - protected void clear() { - super.clear(); - firstTime = null; - } - - @SuppressWarnings({"unchecked"}) - protected U getTabUI() { - return (U) getUI(); - } - - @SuppressWarnings({"unchecked"}) - protected M getTabModel() { - return (M) getModel(); - } - -} Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractAction.java 2008-02-04 18:57:45 UTC (rev 652) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractAction.java 2008-02-04 18:58:07 UTC (rev 653) @@ -1,107 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* 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.cemagref.simexplorer.is.ui.swing.action; - -import fr.cemagref.simexplorer.is.ui.SimExplorer; -import fr.cemagref.simexplorer.is.ui.SimExplorerContext; -import fr.cemagref.simexplorer.is.ui.SimExplorerRuntimeException; -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerMainUI; -import jaxx.runtime.JAXXObject; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JComponent; -import java.awt.event.ActionEvent; - -/** - * La classe de base à utiliser pour toutes les action de l'application - * - * @author chemit - */ -public abstract class SimExplorerAbstractAction extends javax.swing.AbstractAction { - - private static final long serialVersionUID = -810023044364620841L; - - static protected Log log = LogFactory.getLog(SimExplorerAbstractAction.class); - - public void actionPerformed(java.awt.event.ActionEvent e) { - - log.info("------------------------------------------------------------"); - log.info("event : " + e); - log.info("source : " + e.getSource()); - try { - boolean accepted = beforeAction(e); - log.info("action : " + this); - log.info("doAction : (" + accepted + ") : " + getActionName()); - if (accepted) { - doAction(e); - afterAction(e); - } - } catch (Exception e1) { - throw new SimExplorerRuntimeException(e1); - } finally { - // always clear action after use : actions are staless - clear(); - } - } - - protected SimExplorerAbstractAction(String name) { - super(name); - log.debug("> " + this); - } - - protected SimExplorerContext getContext() { - return SimExplorer.getContext(); - } - - protected SimExplorerMainUI getMainUI() { - return SimExplorer.getUI(); - } - - protected String getActionName() { - return (String) getValue(ACTION_COMMAND_KEY); - } - - protected String getName() { - return (String) getValue(NAME); - } - - protected boolean beforeAction(ActionEvent e) throws Exception { - return isEnabled(); - } - - protected void doAction(ActionEvent e) throws Exception { - // nothing by default - } - - protected void afterAction(ActionEvent e) throws Exception { - // nothing by default - } - - protected void clear() { - // nothing by default - } - - protected JComponent getUIObject(String name, JAXXObject container) { - if (container == null) { - return null; - } - return (JComponent) container.getObjectById(name); - } -} Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractTabAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractTabAction.java 2008-02-04 18:57:45 UTC (rev 652) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractTabAction.java 2008-02-04 18:58:07 UTC (rev 653) @@ -1,121 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* 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.cemagref.simexplorer.is.ui.swing.action; - -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerTab; -import jaxx.runtime.JAXXObject; -import jaxx.runtime.builder.TabModel; -import org.apache.commons.beanutils.Converter; -import org.codelutin.i18n.I18n; -import org.codelutin.util.ConverterUtil; - -import javax.swing.JComponent; -import javax.swing.JTabbedPane; -import java.awt.Component; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * La classe d'action de base pour toutes les action sur les Tab - * - * @author chemit - */ -public abstract class SimExplorerAbstractTabAction extends SimExplorerAbstractAction { - - private SimExplorerTab tab; - protected String param; - - private static final long serialVersionUID = 5285229914266682509L; - - protected SimExplorerAbstractTabAction(String name, String prefixPatternName) { - super(name); - if (prefixPatternName == null) { - throw new IllegalArgumentException("prefixPatternName can not be null, but was."); - } - - Pattern patternName = Pattern.compile(prefixPatternName + "_(\\w+)"); - Matcher matcher = patternName.matcher(name); - if (!matcher.matches()) { - throw new IllegalArgumentException(I18n._("{0} should have a name like this {1}, but was {2}", getClass().getName(), patternName, name)); - } - - param = prefixPatternName; - - Converter convertorLanguage = ConverterUtil.getConverter(SimExplorerTab.class); - tab = (SimExplorerTab) convertorLanguage.convert(SimExplorerTab.class, matcher.group(1)); - - log.debug(">>> " + this); - } - - protected SimExplorerAbstractTabAction(String name) { - super(name); - param = name; - log.debug(">>> " + this); - } - - public String getParam() { - return param; - } - - public JTabbedPane getTabContainer() { - return getMainUI().getContent(); - } - - public SimExplorerTab getTab() { - if (tab == null) { - Component comp = getTabContainer().getSelectedComponent(); - for (SimExplorerTab explorerTab : SimExplorerTab.values()) { - if (comp.equals(explorerTab.getUI())) { - tab = explorerTab; - break; - } - } - if (tab == null) { - throw new IllegalStateException("could not found tab to match for action " + this); - } - } - return tab; - } - - public JAXXObject getUI() { - return getTab().getUI(); - } - - public TabModel getModel() { - return getTab().getModel(); - } - - @Override - public String toString() { - String s = super.toString(); - return s.substring(s.lastIndexOf(".") + 1) + "<tab: " + tab + ", param: " + param + ">"; - } - - protected JComponent getUIObject(String name) { - return getUIObject(name, getUI()); - } - - protected void setTab(SimExplorerTab tab) { - this.tab = tab; - } - - protected boolean isRemote() { - return getTab() == SimExplorerTab.remote; - } -} Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ToggleTabAbstractAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ToggleTabAbstractAction.java 2008-02-04 18:57:45 UTC (rev 652) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ToggleTabAbstractAction.java 2008-02-04 18:58:07 UTC (rev 653) @@ -1,77 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* 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.cemagref.simexplorer.is.ui.swing.action; - -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerActionManager; - -import javax.swing.AbstractAction; -import javax.swing.AbstractButton; -import javax.swing.JTabbedPane; -import java.awt.event.ActionEvent; - -/** - * Action pour siwtcher un tab - * - * @author chemit - */ -public abstract class ToggleTabAbstractAction extends SimExplorerAbstractTabAction { - - private static final long serialVersionUID = -5457476021698351850L; - - AbstractAction showAction; - AbstractAction closeAction; - - AbstractAction action; - - public ToggleTabAbstractAction(String name) { - super(name, "toggleTab"); - } - - @Override - protected boolean beforeAction(ActionEvent e) throws Exception { - super.beforeAction(e); - // find real action to perform - JTabbedPane container = getMainUI().getContent(); - if (getTab().isTabVisible(container)) { - action = getCloseAction(); - } else { - action = getShowAction(); - } - return action != null; - } - - @Override - protected void doAction(ActionEvent e) throws Exception { - action.actionPerformed(e); - } - - public AbstractAction getCloseAction() { - if (closeAction == null) { - closeAction = SimExplorerActionManager.newAction("closeTab_" + getTab().name(), (AbstractButton) null); - } - return closeAction; - } - - public AbstractAction getShowAction() { - if (showAction == null) { - showAction = SimExplorerActionManager.newAction("showTab_" + getTab().name(), (AbstractButton) null); - } - return showAction; - } -}
participants (1)
-
tchemit@users.labs.libre-entreprise.org