diff --git a/pom.xml b/pom.xml
index dc24cb149..535f71eac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
scijava-common
- 2.40.1-SNAPSHOT
+ 2.41.0-SNAPSHOT
SciJava Common
SciJava Common is a shared library for SciJava software. It provides a plugin framework, with an extensible mechanism for service discovery, backed by its own annotation processor, so that plugins can be loaded dynamically. It is used by both ImageJ and SCIFIO.
diff --git a/src/main/java/org/scijava/module/DefaultModuleService.java b/src/main/java/org/scijava/module/DefaultModuleService.java
index d4fef8424..c6a53ad5d 100644
--- a/src/main/java/org/scijava/module/DefaultModuleService.java
+++ b/src/main/java/org/scijava/module/DefaultModuleService.java
@@ -92,7 +92,7 @@ public class DefaultModuleService extends AbstractService implements
private PrefService prefService;
@Parameter
- private ConvertService conversionService;
+ private ConvertService convertService;
/** Index of registered modules. */
private ModuleIndex moduleIndex;
@@ -269,7 +269,7 @@ public void save(final ModuleItem item, final T value) {
final String sValue = value == null ? "" : value.toString();
// do not persist if object cannot be converted back from a string
- if (!conversionService.supports(sValue, item.getType())) return;
+ if (!convertService.supports(sValue, item.getType())) return;
final String persistKey = item.getPersistKey();
if (persistKey == null || persistKey.isEmpty()) {
@@ -297,9 +297,25 @@ public T load(final ModuleItem item) {
// if persisted value has never been set before return null
if (sValue == null) return null;
- return conversionService.convert(sValue, item.getType());
+ return convertService.convert(sValue, item.getType());
}
+ @Override
+ public T getDefaultValue(final ModuleItem item) {
+ final T min = item.getMinimumValue();
+ if (min != null) return min;
+ final T softMin = item.getSoftMinimum();
+ if (softMin != null) return softMin;
+ final T max = item.getMaximumValue();
+ if (max != null) return max;
+ final T softMax = item.getSoftMaximum();
+ if (softMax != null) return softMax;
+ final T zero = convertService.convert("0", item.getType());
+ if (zero != null) return zero;
+ // no known default value
+ return null;
+ }
+
// -- Service methods --
@Override
@@ -399,7 +415,7 @@ private void assignInputs(final Module module,
}
else {
final Class> type = input.getType();
- converted = conversionService.convert(value, type);
+ converted = convertService.convert(value, type);
if (value != null && converted == null) {
log.error("For input " + name + ": incompatible object " +
value.getClass().getName() + " for type " + type.getName());
diff --git a/src/main/java/org/scijava/module/ModuleService.java b/src/main/java/org/scijava/module/ModuleService.java
index 3bcba759b..3573e2b3e 100644
--- a/src/main/java/org/scijava/module/ModuleService.java
+++ b/src/main/java/org/scijava/module/ModuleService.java
@@ -285,4 +285,8 @@ Future run(M module,
* {@link ModuleItem}.
*/
T load(ModuleItem item);
+
+ /** Gets the default value of the given {@link ModuleItem}. */
+ T getDefaultValue(final ModuleItem item);
+
}