diff --git a/Zutil.jar b/Zutil.jar index 93ca69c..0cc3da4 100755 Binary files a/Zutil.jar and b/Zutil.jar differ diff --git a/src/zutil/ui/Configurator.java b/src/zutil/ui/Configurator.java index 11303c2..a9befe8 100755 --- a/src/zutil/ui/Configurator.java +++ b/src/zutil/ui/Configurator.java @@ -68,6 +68,8 @@ public class Configurator { private T obj; private ConfigurationParam[] params; + private PreConfigurationActionListener preListener; + private PostConfigurationActionListener postListener; public Configurator(T obj){ this.obj = obj; @@ -141,13 +143,35 @@ public class Configurator { } + /** + * Set a listener that will be called just before the configuration has been applied + */ + public void setPreConfigurationListener(PreConfigurationActionListener listener){ + preListener = listener; + } + + /** + * Set a listener that will be called after the configuration has been applied + */ + public void setPostConfigurationListener(PostConfigurationActionListener listener){ + postListener = listener; + } + /** * All configuration parameters that was set * for each parameter will be applied to the object. * - * The postConfigurationAction() method will be called on the target object if it implements the ConfigurationActionListener interface. + * The preConfigurationAction() method will be called before the target object has + * been configured if it implements the PreConfigurationActionListener interface. + * The postConfigurationAction() method will be called after the target object is + * configured if it implements the PostConfigurationActionListener interface. */ public void applyConfiguration(){ + if(preListener != null) + preListener.preConfigurationAction(this, obj); + if(obj instanceof PreConfigurationActionListener) + ((PreConfigurationActionListener) obj).preConfigurationAction(this, obj); + StringBuilder strParams = new StringBuilder(); for(ConfigurationParam param : params){ try { @@ -163,17 +187,22 @@ public class Configurator { } catch (IllegalAccessException e) { logger.log(Level.WARNING, null, e); } - if(obj instanceof ConfigurationActionListener) - ((ConfigurationActionListener) obj).postConfigurationAction(); } if(logger.isLoggable(Level.FINE)) logger.fine("Configured object: " + obj.getClass().getName() + " ("+ strParams +")"); + + if(obj instanceof PostConfigurationActionListener) + ((PostConfigurationActionListener) obj).postConfigurationAction(this, obj); + if(postListener != null) + postListener.postConfigurationAction(this, obj); } - - public interface ConfigurationActionListener{ - void postConfigurationAction(); + public interface PreConfigurationActionListener { + void preConfigurationAction(Configurator configurator, T obj); + } + public interface PostConfigurationActionListener { + void postConfigurationAction(Configurator configurator, T obj); }