Author: tchemit Date: 2010-04-14 14:43:46 +0200 (Wed, 14 Apr 2010) New Revision: 1838 Log: fix new ApplicationConfig api Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-04-14 12:29:18 UTC (rev 1837) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-04-14 12:43:46 UTC (rev 1838) @@ -28,11 +28,9 @@ package jaxx.demo; -import java.beans.PropertyChangeEvent; import java.io.IOException; import java.io.InputStream; import java.beans.PropertyChangeListener; -import java.util.Date; import java.util.Locale; import java.util.Properties; @@ -41,6 +39,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationConfig; import org.nuiton.util.Version; import org.nuiton.util.VersionUtil; import static org.nuiton.i18n.I18n._; @@ -53,7 +52,7 @@ * @author tchemit <chemit@codelutin.com> * @since 1.7.2 */ -public class DemoConfig extends org.nuiton.util.ApplicationConfig { +public class DemoConfig extends ApplicationConfig { /** * to use log facility, just put in your code: log.info(\"...\"); @@ -68,39 +67,39 @@ public static final String PROPERTY_FULLSCREEN = "fullscreen"; public static final String PROPERTY_LOCALE = "locale"; public static final String PROPERTY_FONT_SIZE = "fontSize"; - public static final String PROPERTY_ADJUSTING = "adjusting"; +// public static final String ADJUSTING_PROPERTY = "adjusting"; +// +// /** +// * un drapeau pour bloquer la sauvegarde lors de la modification en +// * masse des options via les setter. +// */ +// protected boolean adjusting; +// protected final PropertyChangeListener saveAction = +// new PropertyChangeListener() { +// +// @Override +// public void propertyChange(PropertyChangeEvent evt) { +// if (adjusting) { +// if (log.isDebugEnabled()) { +// log.debug("skip save while adjusting"); +// } +// return; +// } +// if (log.isDebugEnabled()) { +// log.debug("Saving configuration at " + new Date()); +// } +// saveForUser(); +// } +// }; - /** - * un drapeau pour bloquer la sauvegarde lors de la modification en - * masse des options via les setter. - */ - protected boolean adjusting; - protected final PropertyChangeListener saveAction = - new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (adjusting) { - if (log.isDebugEnabled()) { - log.debug("skip save while adjusting"); - } - return; - } - if (log.isDebugEnabled()) { - log.debug("Saving configuration at " + new Date()); - } - saveForUser(); - } - }; - public DemoConfig() { setConfigFileName(Option.CONFIG_FILE.defaultValue); // chargement de la configuration interne - InputStream stream = getClass().getResourceAsStream( - APPLICATION_PROPERTIES); + InputStream stream = + getClass().getResourceAsStream(APPLICATION_PROPERTIES); Properties p = new Properties(); try { @@ -127,11 +126,14 @@ Version version = VersionUtil.valueOf(sVersion); setDefaultOption("version", version.getVersion()); - adjusting = true; - addPropertyChangeListener(PROPERTY_FULLSCREEN, saveAction); - addPropertyChangeListener(PROPERTY_FONT_SIZE, saveAction); - addPropertyChangeListener(PROPERTY_LOCALE, saveAction); - adjusting = false; + installSaveUserAction(PROPERTY_FULLSCREEN, + PROPERTY_FONT_SIZE, + PROPERTY_LOCALE); +// adjusting = true; +// addPropertyChangeListener(PROPERTY_FULLSCREEN, saveAction); +// addPropertyChangeListener(PROPERTY_FONT_SIZE, saveAction); +// addPropertyChangeListener(PROPERTY_LOCALE, saveAction); +// adjusting = false; } public String getCopyrightText() { @@ -140,7 +142,7 @@ @Override public void setOption(String key, String value) { - if (key.equals(PROPERTY_ADJUSTING)) { + if (key.equals(ADJUSTING_PROPERTY)) { setAdjusting(Boolean.valueOf(value)); return; } @@ -197,20 +199,20 @@ // saveForUser(); firePropertyChange(PROPERTY_FONT_SIZE, oldValue, newFontSize); } +// +// public boolean isAdjusting() { +// return adjusting; +// } +// +// public void setAdjusting(boolean adjusting) { +// if (log.isDebugEnabled()) { +// log.debug("changing adjusting to " + adjusting); +// } +// boolean oldValue = this.adjusting; +// this.adjusting = adjusting; +// firePropertyChange(ADJUSTING_PROPERTY, oldValue, adjusting); +// } - public boolean isAdjusting() { - return adjusting; - } - - public void setAdjusting(boolean adjusting) { - if (log.isDebugEnabled()) { - log.debug("changing adjusting to " + adjusting); - } - boolean oldValue = this.adjusting; - this.adjusting = adjusting; - firePropertyChange(PROPERTY_ADJUSTING, oldValue, adjusting); - } - /** * Save configuration, in user home directory using the * {@link #getConfigFileName}. Default, env and commande line note saved @@ -224,7 +226,7 @@ PROPERTY_FULLSCREEN, PROPERTY_LOCALE, PROPERTY_FONT_SIZE, - PROPERTY_ADJUSTING + ADJUSTING_PROPERTY }; public void removeJaxxPropertyChangeListener() { @@ -289,10 +291,10 @@ true); public final String key; public final String description; - public final String defaultValue; + public String defaultValue; public final Class<?> type; - public final boolean _transient; - public final boolean _final; + public boolean _transient; + public boolean _final; Option(String key, String description, String defaultValue, Class<?> type, boolean _transient, boolean _final) { this.key = key; @@ -309,6 +311,21 @@ } @Override + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + @Override + public void setTransient(boolean _transient) { + this._transient=_transient; + } + + @Override + public void setFinal(boolean _final) { + this._final=_final; + } + + @Override public boolean isTransient() { return _transient; } @@ -332,5 +349,7 @@ public Class<?> getType() { return type; } + + } }