From 58384447a950409a10e6d6c33ac4a83a680cdc96 Mon Sep 17 00:00:00 2001 From: Calixte DENIZET Date: Mon, 19 Aug 2013 16:54:33 +0200 Subject: [PATCH] Bug 12816 fixed: Numbers pasted in editvar were not parsed according to locale Change-Id: I469805edcab7de782f0c51b117fe32b352cb69f0 --- scilab/CHANGES_5.5.X | 4 +++- .../variableeditor/actions/PasteAction.java | 24 +++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/scilab/CHANGES_5.5.X b/scilab/CHANGES_5.5.X index dc5b719..fb9a82d 100644 --- a/scilab/CHANGES_5.5.X +++ b/scilab/CHANGES_5.5.X @@ -536,4 +536,6 @@ Bug fixes * Bug #12790 fixed - Links to zcos files in doc were broken. -* Bug #12808 fixed - Add missing in doc generation (note, warning, ...). \ No newline at end of file +* Bug #12808 fixed - Add missing in doc generation (note, warning, ...). + +* Bug #12816 fixed - Numbers pasted in editvar were not parsed according to locale. diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variableeditor/actions/PasteAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variableeditor/actions/PasteAction.java index 653aee4..9c331e6 100644 --- a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variableeditor/actions/PasteAction.java +++ b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variableeditor/actions/PasteAction.java @@ -17,6 +17,8 @@ import java.awt.Toolkit; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.IOException; +import java.text.NumberFormat; +import java.text.ParsePosition; import java.util.StringTokenizer; import java.util.Vector; @@ -74,6 +76,15 @@ public final class PasteAction extends CommonCallBack { JTable table = editor.getCurrentTable(); int col = table.getSelectedColumn(); int row = table.getSelectedRow(); + + if (col == -1) { + col = 0; + } + + if (row == -1) { + row = 0; + } + table.setColumnSelectionInterval(col, col); table.setRowSelectionInterval(row, row); String str = ""; @@ -85,15 +96,26 @@ public final class PasteAction extends CommonCallBack { } catch (IOException ex2) { System.err.println(ex2); } + StringTokenizer rElems = new StringTokenizer(str, "\n"); int countRows = rElems.countTokens(); Vector vr = new Vector(countRows); + NumberFormat format = NumberFormat.getInstance(); + ParsePosition position = new ParsePosition(0); + format.setParseIntegerOnly(false); for (int i = 0; i < countRows; i++) { StringTokenizer cElems = new StringTokenizer(rElems.nextToken(), "\t"); int countCols = cElems.countTokens(); Vector vc = new Vector(countCols); for (int j = 0; j < countCols; j++) { - vc.addElement(cElems.nextToken()); + String ss = cElems.nextToken(); + Number x = format.parse(ss, position); + if (position.getIndex() == ss.length()) { + vc.addElement(x.toString()); + } else { + vc.addElement(ss); + } + position.setIndex(0); } vr.addElement(vc); } -- 1.7.9.5