Skip to content

Commit c0ffe39

Browse files
committed
ScriptInfo: add support for stepSize attribute
It's probably still a little hacky, since stepSize is typed as Number rather than T. But it should work OK in normal circumstances.
1 parent a45b057 commit c0ffe39

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/org/scijava/script/ScriptInfo.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,14 @@ else if ("softMin".equalsIgnoreCase(key)) {
472472
item.setSoftMinimum(convertService.convert(value, item.getType()));
473473
}
474474
else if ("stepSize".equalsIgnoreCase(key)) {
475-
// FIXME
476-
item.setStepSize(convertService.convert(value, Number.class));
475+
try {
476+
final double stepSize = Double.parseDouble(value);
477+
item.setStepSize(stepSize);
478+
}
479+
catch (final NumberFormatException exc) {
480+
log.warn("Script parameter " + item.getName() +
481+
" has an invalid stepSize: " + value);
482+
}
477483
}
478484
else if ("style".equalsIgnoreCase(key)) {
479485
item.setWidgetStyle(value);

src/test/java/org/scijava/script/ScriptInfoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void testParameters() {
152152

153153
final ModuleItem<?> sliderValue = info.getInput("sliderValue");
154154
assertItem("sliderValue", int.class, "Slider Value", ItemIO.INPUT, true,
155-
true, null, "slider", 11, null, null, 5, 15, 3, sliderValue);
155+
true, null, "slider", 11, null, null, 5, 15, 3.0, sliderValue);
156156

157157
final ModuleItem<?> buffer = info.getOutput("buffer");
158158
assertItem("buffer", StringBuilder.class, null, ItemIO.BOTH, true, true,
@@ -195,7 +195,7 @@ private void assertItem(final String name, final Class<?> type,
195195
assertEquals(max, item.getMaximumValue());
196196
assertEquals(softMin, item.getSoftMinimum());
197197
assertEquals(softMax, item.getSoftMaximum());
198-
// assertEquals(stepSize, item.getStepSize());
198+
assertEquals(stepSize, item.getStepSize());
199199
}
200200

201201
/**

0 commit comments

Comments
 (0)