diff --git a/src/zutil/Timer.java b/src/zutil/Timer.java index 2254d30..e0e29e5 100755 --- a/src/zutil/Timer.java +++ b/src/zutil/Timer.java @@ -27,6 +27,8 @@ package zutil; /** * This class is a timer, it will track time and * timeout after a specific amount of time. + *
+ * Note that the {@link #start()} method needs to be called for the timer to start. * * Created by Ziver on 2015-07-15. */ @@ -37,6 +39,9 @@ public class Timer { private long timestamp; + /** + * Creates a new timer that in reset state. + */ public Timer(long milisec){ this.period = milisec; reset(); diff --git a/src/zutil/db/bean/DBBeanObjectDSO.java b/src/zutil/db/bean/DBBeanObjectDSO.java index 9dd916e..3aa1733 100755 --- a/src/zutil/db/bean/DBBeanObjectDSO.java +++ b/src/zutil/db/bean/DBBeanObjectDSO.java @@ -48,7 +48,7 @@ public abstract class DBBeanObjectDSO extends DBBean{ } if (config != null && !config.isEmpty()) { - Configurator configurator = new Configurator<>(cachedObj); + Configurator configurator = getObjectConfigurator(); configurator.setValues(JSONParser.read(config)); configurator.applyConfiguration(); } @@ -60,7 +60,7 @@ public abstract class DBBeanObjectDSO extends DBBean{ if (cachedObj == null) this.config = null; else { - Configurator configurator = new Configurator<>(cachedObj); + Configurator configurator = getObjectConfigurator(); this.config = JSONWriter.toString(configurator.getValuesAsNode()); } super.save(db); @@ -95,12 +95,16 @@ public abstract class DBBeanObjectDSO extends DBBean{ setObjectClass(clazz.getName()); } - protected void setObjectClass(String clazz){ + public void setObjectClass(String clazz){ if (this.type == null || !this.type.equals(type)) { + // TODO: check if clazz is subclass of T setObject(null); this.type = clazz; + postUpdateAction(); // instantiate cached object } } - + public Configurator getObjectConfigurator(){ + return new Configurator<>(cachedObj); + } } diff --git a/src/zutil/ui/Configurator.java b/src/zutil/ui/Configurator.java index 5681a73..77e14a7 100755 --- a/src/zutil/ui/Configurator.java +++ b/src/zutil/ui/Configurator.java @@ -47,6 +47,11 @@ import java.util.logging.Logger; * object the {@link Configurator#setValues(DataNode)} or {@link Configurator#setValues(Map)} * can be used to set the individual fields and finally call {@link Configurator#applyConfiguration()} * to configure the target object. + *
+ * External listener can be registered to be called before or after configuration changes + * by implementing {@link PreConfigurationActionListener} or {@link PostConfigurationActionListener}. + * The configured object will autmatically be registered as a listener if it also implements + * these interfaces. * *
* Supported field types: String, int, boolean, enum @@ -248,6 +253,7 @@ public class Configurator { if (f.getType() == String.class) type = ConfigType.STRING; else if(f.getType() == int.class) type = ConfigType.INT; + else if(f.getType() == double.class) type = ConfigType.INT; else if(f.getType() == boolean.class) type = ConfigType.BOOLEAN; else if(f.getType().isEnum()) type = ConfigType.ENUM; else @@ -298,7 +304,11 @@ public class Configurator { case STRING: value = v; break; case INT: - value = Integer.parseInt(v); break; + if (field.getType() == double.class) + value = Double.parseDouble(v); + else + value = Integer.parseInt(v); + break; case BOOLEAN: value = Boolean.parseBoolean(v); break; case ENUM: