Author: tchemit Date: 2008-01-22 01:53:58 +0000 (Tue, 22 Jan 2008) New Revision: 356 Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAbstractAction.java Removed: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAction.java Log: renommage action (car abstraite) Copied: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAbstractAction.java (from rev 317, trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAction.java) =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAbstractAction.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAbstractAction.java 2008-01-22 01:53:58 UTC (rev 356) @@ -0,0 +1,87 @@ +/* +* ##% 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 actionPerformed(java.awt.event.ActionEvent e) { + super.actionPerformed(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/ChangeI18nAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAction.java 2008-01-22 01:53:40 UTC (rev 355) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/ChangeI18nAction.java 2008-01-22 01:53:58 UTC (rev 356) @@ -1,88 +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.swing.action.SimExplorerAbstractAction; -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 ChangeI18nAction 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 ChangeI18nAction(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 actionPerformed(java.awt.event.ActionEvent e) { - super.actionPerformed(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
participants (1)
-
tchemit@users.labs.libre-entreprise.org