r3597 - trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor
Author: mallon Date: 2012-08-10 13:36:35 +0200 (Fri, 10 Aug 2012) New Revision: 3597 Url: http://chorem.org/repositories/revision/lima/3597 Log: refs #705 Correction sur l editeur des cellules de type montant 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-09 16:30:53 UTC (rev 3596) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2012-08-10 11:36:35 UTC (rev 3597) @@ -38,10 +38,15 @@ import java.awt.event.FocusListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +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> @@ -61,12 +66,12 @@ getComponent().addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { - // nothing to do + //nothing to do } @Override public void keyPressed(KeyEvent e) { - // nothing to do + //nothing to do } @Override @@ -103,6 +108,12 @@ // nothing to do } }); + getComponent().addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + runEdition(); + } + }); } @Override @@ -125,18 +136,18 @@ /** * Round the value to higher, and the number of decimal to 2; - * Parse string value to BigDecimal when it contains comma * @return bigDecimal value * */ @Override public BigDecimal getCellEditorValue() { - String editorStringValue = super.getCellEditorValue().toString(); - if (StringUtils.isBlank(editorStringValue)) { - editorStringValue = "0"; + String stringValue = super.getCellEditorValue().toString(); + if (StringUtils.isBlank(stringValue) + || stringValue.matches("[^0-9]*[0-9]*[^0-9]*") + || stringValue.matches("[^0-9]*")) { + stringValue = "0"; } - BigDecimal cellEditorValue; - DecimalFormat decimalFormat = new DecimalFormat(); - cellEditorValue = new BigDecimal(decimalFormat.parse(editorStringValue,new ParsePosition(0)).doubleValue()); + stringValue=stringValue.replaceAll(",","."); + BigDecimal cellEditorValue = new BigDecimal(stringValue); if (super.getCellEditorValue() != BigDecimal.ZERO) { return cellEditorValue.setScale(2, RoundingMode.HALF_UP); } @@ -144,14 +155,13 @@ } /** - * Limit number of comma to one - * @param e keyEvent starting control of comma + * Limit number of decimalSeparator to one + * @param e keyEvent starting control of decimalSeparator * */ protected void limitComma(KeyEvent e) { - if ( (String.valueOf(e.getKeyChar()).equals(",") && comma.equals(","))) { + if ( (String.valueOf(e.getKeyChar()).matches("[^0-9]") + && getComponent().getText().length() > 2) ) { getComponent().setText(getComponent().getText().substring(0, getComponent().getText().length()-1)); - } else if (String.valueOf(e.getKeyChar()).equals(",") && !comma.equals(",")) { - comma = ","; } }
participants (1)
-
mallon@users.chorem.org