Author: mallon Date: 2012-08-20 17:25:30 +0200 (Mon, 20 Aug 2012) New Revision: 3621 Url: http://chorem.org/repositories/revision/lima/3621 Log: fixes #705 Correction pour la prise en compte de la configuration, concernant le nombre de decimales. Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2012-08-20 14:34:31 UTC (rev 3620) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2012-08-20 15:25:30 UTC (rev 3621) @@ -27,11 +27,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; +import org.chorem.lima.LimaContext; import javax.swing.DefaultCellEditor; import javax.swing.JTextField; import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; import javax.swing.event.AncestorEvent; import javax.swing.event.AncestorListener; import java.awt.event.FocusEvent; @@ -41,12 +41,6 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.math.BigDecimal; -import java.math.RoundingMode; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Locale; /** * @author sletellier <letellier@codelutin.com> @@ -145,10 +139,19 @@ stringValue = "0"; } stringValue=stringValue.replaceAll(",","."); - BigDecimal cellEditorValue = new BigDecimal(stringValue); - if (super.getCellEditorValue() != BigDecimal.ZERO) { - return cellEditorValue.setScale(2, RoundingMode.HALF_UP); + + BigDecimal cellEditorValue; + int pointIndex = stringValue.indexOf("."); + if (pointIndex != -1) { + LimaConfig config = LimaContext.getContext().getConfig(); + int decimal = config.getScale() + pointIndex + 1; + String roundedStringValue = stringValue.substring(0, pointIndex) + + stringValue.substring(pointIndex, decimal); + cellEditorValue = new BigDecimal(roundedStringValue); + } else { + cellEditorValue = new BigDecimal(stringValue); } + return cellEditorValue; }