summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authormottelet <stephane.mottelet@utc.fr>2021-05-05 18:44:36 +0200
committerClément David <clement.david@esi-group.com>2021-05-07 09:43:52 +0200
commit8a066eb30a2ac860e8cb570a77b72d6639ff7abf (patch)
tree986ea574e2c137191f13328a3aabe4d65f60cfdb /scilab
parent770a92864db626838719855fb48a004b0be1734a (diff)
downloadscilab-8a066eb30a2ac860e8cb570a77b72d6639ff7abf.zip
scilab-8a066eb30a2ac860e8cb570a77b72d6639ff7abf.tar.gz
* Bug 16540 fixed: implemented snapToTicks spinner property
http://bugzilla.scilab.org/show_bug.cgi?id=16540 Change-Id: I352368987e084556bd9d8ab90c485abf3adf6896
Diffstat (limited to 'scilab')
-rw-r--r--scilab/CHANGES.md1
-rw-r--r--scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/editbox/SwingScilabSpinner.java28
2 files changed, 20 insertions, 9 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index e63959b..3e7bdf5 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -427,6 +427,7 @@ Bug Fixes
427* [#16525](https://bugzilla.scilab.org/16525): `soundsec(t,freq)` has the trivial equivalence `0 : 1/freq : t*(1-%eps)` and should be removed. 427* [#16525](https://bugzilla.scilab.org/16525): `soundsec(t,freq)` has the trivial equivalence `0 : 1/freq : t*(1-%eps)` and should be removed.
428* [#16529](https://bugzilla.scilab.org/16529): `deff` could not return the created function as output argument, preventing to cretae and use anonymous functions. The function's headline and body had to be provided separately. For Simple functions, a one-string input (possibly console-oriented) definition was not supported. 428* [#16529](https://bugzilla.scilab.org/16529): `deff` could not return the created function as output argument, preventing to cretae and use anonymous functions. The function's headline and body had to be provided separately. For Simple functions, a one-string input (possibly console-oriented) definition was not supported.
429* [#16530](https://bugzilla.scilab.org/16530): `mapsound` needed to be reforged. 429* [#16530](https://bugzilla.scilab.org/16530): `mapsound` needed to be reforged.
430* [#16540](https://bugzilla.scilab.org/16540): uicontrol spinner did not "snaptoticks"
430* [#16549](https://bugzilla.scilab.org/16549): simple script crashed Scilab in GUI mode. 431* [#16549](https://bugzilla.scilab.org/16549): simple script crashed Scilab in GUI mode.
431* [#16551](https://bugzilla.scilab.org/16551): `num2cell` returned {} for any input array of empty strings. 432* [#16551](https://bugzilla.scilab.org/16551): `num2cell` returned {} for any input array of empty strings.
432* [#16552](https://bugzilla.scilab.org/16552): `mfile2sci`: conversion of `ispc` and `isunix` still used `MSDOS` removed far ago. Conversion of `ismac` was missing. Conversion of `exist` missed using `mtlb_exist`. Conversion of `dos` yielded some "operation +" warnings. Unit tests for the conversion of `cd`, `dir` and `ferror` overwrote some Scilab reserved keywords. Conversion of `return` yielded `mtlb(resume)`. 433* [#16552](https://bugzilla.scilab.org/16552): `mfile2sci`: conversion of `ispc` and `isunix` still used `MSDOS` removed far ago. Conversion of `ismac` was missing. Conversion of `exist` missed using `mtlb_exist`. Conversion of `dos` yielded some "operation +" warnings. Unit tests for the conversion of `cd`, `dir` and `ferror` overwrote some Scilab reserved keywords. Conversion of `return` yielded `mtlb(resume)`.
diff --git a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/editbox/SwingScilabSpinner.java b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/editbox/SwingScilabSpinner.java
index 5424a2b..1729d83 100644
--- a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/editbox/SwingScilabSpinner.java
+++ b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/editbox/SwingScilabSpinner.java
@@ -3,6 +3,7 @@ package org.scilab.modules.gui.bridge.editbox;
3import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MAX__; 3import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MAX__;
4import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MIN__; 4import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MIN__;
5import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SLIDERSTEP__; 5import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SLIDERSTEP__;
6import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SNAPTOTICKS__;
6import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VALUE__; 7import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VALUE__;
7 8
8import java.awt.Color; 9import java.awt.Color;
@@ -15,6 +16,10 @@ import javax.swing.UIManager;
15import javax.swing.border.Border; 16import javax.swing.border.Border;
16import javax.swing.event.ChangeEvent; 17import javax.swing.event.ChangeEvent;
17import javax.swing.event.ChangeListener; 18import javax.swing.event.ChangeListener;
19import javax.swing.JFormattedTextField;
20import javax.swing.text.NumberFormatter;
21
22
18 23
19import org.scilab.modules.graphic_objects.graphicController.GraphicController; 24import org.scilab.modules.graphic_objects.graphicController.GraphicController;
20import org.scilab.modules.gui.SwingViewObject; 25import org.scilab.modules.gui.SwingViewObject;
@@ -55,6 +60,14 @@ public class SwingScilabSpinner extends JSpinner implements SwingViewObject, Wid
55 addChangeListener(new ChangeListener() { 60 addChangeListener(new ChangeListener() {
56 public void stateChanged(ChangeEvent e) { 61 public void stateChanged(ChangeEvent e) {
57 Double val = (Double)getValue(); 62 Double val = (Double)getValue();
63 double userMin = (double) GraphicController.getController().getProperty(uid, __GO_UI_MIN__);
64 double userMax = (double) GraphicController.getController().getProperty(uid, __GO_UI_MAX__);
65 Double[] userStep = (Double[]) GraphicController.getController().getProperty(uid, __GO_UI_SLIDERSTEP__);
66 val = Math.max(Math.min(userMax,val),userMin);
67 if ((boolean)GraphicController.getController().getProperty(uid, __GO_UI_SNAPTOTICKS__)) {
68 val = (userMin/userStep[0]+Math.round((val-userMin)/userStep[0]))*userStep[0];
69 }
70 setValue(val);
58 GraphicController.getController().setProperty(uid, __GO_UI_VALUE__, new Double[] {val}); 71 GraphicController.getController().setProperty(uid, __GO_UI_VALUE__, new Double[] {val});
59 if (callback != null) { 72 if (callback != null) {
60 callback.actionPerformed(null); 73 callback.actionPerformed(null);
@@ -171,23 +184,20 @@ public class SwingScilabSpinner extends JSpinner implements SwingViewObject, Wid
171 Double[] step = (Double[]) controller.getProperty(getId(), __GO_UI_SLIDERSTEP__); 184 Double[] step = (Double[]) controller.getProperty(getId(), __GO_UI_SLIDERSTEP__);
172 Double[] val = (Double[]) controller.getProperty(getId(), __GO_UI_VALUE__); 185 Double[] val = (Double[]) controller.getProperty(getId(), __GO_UI_VALUE__);
173 Double v = (val != null && val.length != 0) ? val[0] : 0.0; 186 Double v = (val != null && val.length != 0) ? val[0] : 0.0;
174 if (v > max) {
175 v = max;
176 }
177 187
178 if (v < min) { 188 //adjust value to current min,max,step
179 v = min;
180 }
181
182 //adjust value to current step
183 if (step[0] != 0) { 189 if (step[0] != 0) {
184 v = Math.floor((v / step[0])) * step[0]; 190 v = Math.min(max, min+Math.max(0,Math.round((v-min) / step[0])) * step[0]);
185 } else { 191 } else {
186 v = min; 192 v = min;
187 } 193 }
188 194
189 controller.setProperty(uid, __GO_UI_VALUE__, new Double[] {v}); 195 controller.setProperty(uid, __GO_UI_VALUE__, new Double[] {v});
190 setModel(new SpinnerNumberModel(v, min, max, step[0])); 196 setModel(new SpinnerNumberModel(v, min, max, step[0]));
197 JFormattedTextField txt = ((JSpinner.NumberEditor) getEditor()).getTextField();
198 ((NumberFormatter) txt.getFormatter()).setAllowsInvalid(false);
199 ((NumberFormatter) txt.getFormatter()).setCommitsOnValidEdit(true);
200
191 break; 201 break;
192 } 202 }
193 case __GO_UI_VALUE__: { 203 case __GO_UI_VALUE__: {