Author: sbavencoff Date: 2014-03-06 11:26:55 +0100 (Thu, 06 Mar 2014) New Revision: 3754 Url: http://forge.chorem.org/projects/lima/repository/revisions/3754 Log: fixes #370 : Options non termin?\195?\169es Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/NumberSeparatorCellRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/NumberSeparatorTableCellRenderer.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/LimaConfig.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties Modified: trunk/lima-swing/src/main/java/org/chorem/lima/LimaConfig.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/LimaConfig.java 2014-03-06 08:51:59 UTC (rev 3753) +++ trunk/lima-swing/src/main/java/org/chorem/lima/LimaConfig.java 2014-03-06 10:26:55 UTC (rev 3754) @@ -25,6 +25,7 @@ package org.chorem.lima; +import com.google.common.collect.ImmutableSet; import jaxx.runtime.JAXXUtil; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -34,9 +35,9 @@ import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.service.LimaServiceFactory; import org.nuiton.config.ApplicationConfig; +import org.nuiton.config.ArgumentsParserException; import org.nuiton.config.ConfigOptionDef; import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.config.ArgumentsParserException; import org.nuiton.util.Version; import org.nuiton.util.VersionUtil; import org.nuiton.util.converter.ConverterUtil; @@ -46,6 +47,7 @@ import java.io.File; import java.io.IOException; import java.util.Locale; +import java.util.Set; import static org.nuiton.i18n.I18n._; import static org.nuiton.i18n.I18n.n_; @@ -64,6 +66,9 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(LimaConfig.class); + static public final Set<Character> NUMBER_SEPARATOR = ImmutableSet.of(' ', ',', '.', ';'); + static public final Set<Integer> NUMBER_DECIMALS = ImmutableSet.of(0, 1, 2, 3, 4, 5, 6); + protected static LimaConfig instance; private static final String configFile = "lima-config.properties"; @@ -446,7 +451,7 @@ _("lima.config.decimalseparator.label"), n_("lima.config.decimalseparator.description"), ",", - String.class, false, false), + Character.class, false, false), SCALE("lima.data.bigDecimal.scale", _("lima.config.scale.label"), @@ -458,7 +463,7 @@ _("limma.config.thousandseparator.label"), n_("limma.config.thousandseparator.description"), " ", - String.class, false, false), + Character.class, false, false), CURRENCY("lima.config.currency", _("lima.config.currency.label"), Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2014-03-06 08:51:59 UTC (rev 3753) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2014-03-06 10:26:55 UTC (rev 3754) @@ -39,6 +39,8 @@ import org.chorem.lima.ui.account.AccountView; import org.chorem.lima.ui.accountsreports.AccountsReportsView; import org.chorem.lima.ui.balance.BalanceReportsView; +import org.chorem.lima.ui.celleditor.NumberSeparatorCellRenderer; +import org.chorem.lima.ui.celleditor.NumberSeparatorTableCellRenderer; import org.chorem.lima.ui.entrybook.EntryBookView; import org.chorem.lima.ui.entrybooksreports.EntryBooksReportsView; import org.chorem.lima.ui.financialperiod.FinancialPeriodView; @@ -257,12 +259,27 @@ helper.setOptionShortLabel(LimaConfig.Option.FULL_SCREEN.getLabel()); helper.addOption(LimaConfig.Option.LOCALE); helper.setOptionShortLabel(LimaConfig.Option.LOCALE.getLabel()); + + JComboBox<Character> comboBoxSeparator = new JComboBox<Character>(LimaConfig.NUMBER_SEPARATOR.toArray(new Character[0])); + DefaultCellEditor separatorEditor = new DefaultCellEditor(comboBoxSeparator); + comboBoxSeparator.setRenderer(new NumberSeparatorCellRenderer()); + NumberSeparatorTableCellRenderer separatorRenderer = new NumberSeparatorTableCellRenderer(); helper.addOption(LimaConfig.Option.DECIMAL_SEPARATOR); helper.setOptionShortLabel(LimaConfig.Option.DECIMAL_SEPARATOR.getLabel()); + helper.setOptionRenderer(separatorRenderer); + helper.setOptionEditor(separatorEditor); + + JComboBox<Integer> comboBoxDecimal = new JComboBox<Integer>(LimaConfig.NUMBER_DECIMALS.toArray(new Integer[0])); + DefaultCellEditor decimalEditor = new DefaultCellEditor(comboBoxDecimal); helper.addOption(LimaConfig.Option.SCALE); helper.setOptionShortLabel(LimaConfig.Option.SCALE.getLabel()); + helper.setOptionEditor(decimalEditor); + helper.addOption(LimaConfig.Option.THOUSAND_SEPARATOR); helper.setOptionShortLabel(LimaConfig.Option.THOUSAND_SEPARATOR.getLabel()); + helper.setOptionRenderer(separatorRenderer); + helper.setOptionEditor(separatorEditor); + helper.addOption(LimaConfig.Option.CURRENCY); helper.setOptionShortLabel(LimaConfig.Option.CURRENCY.getLabel()); /*Pas de 'callBack' sur le changement de comportement lors de l'édition d'une cellule, Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/NumberSeparatorCellRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/NumberSeparatorCellRenderer.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/NumberSeparatorCellRenderer.java 2014-03-06 10:26:55 UTC (rev 3754) @@ -0,0 +1,48 @@ +package org.chorem.lima.ui.celleditor; + +import com.google.common.collect.ImmutableMap; + +import javax.swing.*; +import java.awt.*; +import java.util.Map; + +import static org.nuiton.i18n.I18n._; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class NumberSeparatorCellRenderer extends DefaultListCellRenderer { + + protected static final Map<Character, String> LABEL_BY_SEPARATOR = ImmutableMap.of( + ' ', "lima.config.numberSeparator.space", + ',', "lima.config.numberSeparator.comma", + '.', "lima.config.numberSeparator.dot", + ';', "lima.config.numberSeparator.semicolon"); + + public static String getSeparatorLabel(Object value) { + String separatorLabel = ""; + if (value != null) { + Character separator = (Character) value; + separatorLabel = LABEL_BY_SEPARATOR.get(separator); + if (separatorLabel == null) { + separatorLabel = ""; + } else { + separatorLabel = _(separatorLabel); + } + separatorLabel += " \"" + separator + "\""; + } + return separatorLabel; + } + + @Override + public Component getListCellRendererComponent(JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + + JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + label.setText(getSeparatorLabel(value)); + return this; + } +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/NumberSeparatorTableCellRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/NumberSeparatorTableCellRenderer.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/NumberSeparatorTableCellRenderer.java 2014-03-06 10:26:55 UTC (rev 3754) @@ -0,0 +1,14 @@ +package org.chorem.lima.ui.celleditor; + +import javax.swing.table.DefaultTableCellRenderer; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class NumberSeparatorTableCellRenderer extends DefaultTableCellRenderer { + + protected void setValue(Object value) { + super.setValue(NumberSeparatorCellRenderer.getSeparatorLabel(value)); + } + +} Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-03-06 08:51:59 UTC (rev 3753) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-03-06 10:26:55 UTC (rev 3754) @@ -162,6 +162,10 @@ lima.config.i18n.dir.label= lima.config.locale.description=Localization used by LIMA lima.config.locale.label= +lima.config.numberSeparator.comma= +lima.config.numberSeparator.dot= +lima.config.numberSeparator.semicolon= +lima.config.numberSeparator.space= lima.config.resources.dir.description= lima.config.resources.dir.label= lima.config.scale.description= @@ -520,3 +524,6 @@ lima.warning.nimbus.landf=Could not find Numbus Look&Feel limma.config.thousandseparator.description= limma.config.thousandseparator.label= +org.chorem.lima.LimaConfig.NumberSeparator.COMMA= +org.chorem.lima.LimaConfig.NumberSeparator.DOT= +org.chorem.lima.LimaConfig.NumberSeparator.SPACE= Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-03-06 08:51:59 UTC (rev 3753) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-03-06 10:26:55 UTC (rev 3754) @@ -147,6 +147,10 @@ lima.config.i18n.dir.label= lima.config.locale.description=Paramétres local utilisés par l'application lima.config.locale.label=Zone +lima.config.numberSeparator.comma=Virgule +lima.config.numberSeparator.dot=Point +lima.config.numberSeparator.semicolon=Point-virgule +lima.config.numberSeparator.space=Espace lima.config.resources.dir.description= lima.config.resources.dir.label= lima.config.scale.description=Nombre de caratères décimales pour les montants @@ -493,3 +497,6 @@ lima.warning.nimbus.landf=Le look and feel nymbus n'a pas été trouvé limma.config.thousandseparator.description=Caractère de séparation entre les blocs de milliers limma.config.thousandseparator.label=Séparateur de milliers +org.chorem.lima.LimaConfig.NumberSeparator.COMMA= +org.chorem.lima.LimaConfig.NumberSeparator.DOT= +org.chorem.lima.LimaConfig.NumberSeparator.SPACE=