Author: tchemit Date: 2009-12-22 18:35:06 +0100 (Tue, 22 Dec 2009) New Revision: 1695 Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java trunk/jaxx-demo/src/main/java/jaxx/demo/DemoSources.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java trunk/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties trunk/jaxx-demo/src/main/resources/log4j.properties Log: use ConfigModelBuilder api + improve application design Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2009-12-22 17:34:34 UTC (rev 1694) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2009-12-22 17:35:06 UTC (rev 1695) @@ -20,9 +20,11 @@ */ 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; @@ -53,11 +55,34 @@ * le projet (version, license,...) et la configuration des ui (icons, ...) */ public static final String APPLICATION_PROPERTIES = "/jaxx-demo.properties"; + + 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"; + /** - * un drapeau pour savoir si on est en mode pleine écran + * un drapeau pour bloquer la sauvegarde lors de la modification en masse des options + * via les setter. */ - protected boolean fullscreen; + 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); @@ -89,12 +114,27 @@ String sVersion = VersionUtil.removeSnapshot(getOption("application.version")); 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; } public String getCopyrightText() { return "Version " + getVersion() + " Codelutin @ 2008-2009"; } + @Override + public void setOption(String key, String value) { + if (key.equals(PROPERTY_ADJUSTING)) { + setAdjusting(Boolean.valueOf(value)); + return; + } + super.setOption(key, value); + } + /** * @return la version de l'application. */ @@ -126,23 +166,39 @@ public void setFullscreen(boolean fullscreen) { Object oldValue = null; setOption(Option.FULL_SCREEN.key, fullscreen + ""); - saveForUser(); - firePropertyChange("fullscreen", oldValue, fullscreen); +// saveForUser(); + firePropertyChange(PROPERTY_FULLSCREEN, oldValue, fullscreen); } public void setLocale(Locale newLocale) { setOption(Option.LOCALE.key, newLocale.toString()); - saveForUser(); - firePropertyChange("locale", null, newLocale); +// saveForUser(); + firePropertyChange(PROPERTY_LOCALE, null, newLocale); } public void setFontSize(Float newFontSize) { Float oldValue = getFontSize(); + if (log.isDebugEnabled()) { + log.debug("changing font-size to " + newFontSize); + } setOption(Option.FONT_SIZE.key, newFontSize.toString()); - saveForUser(); - firePropertyChange("fontSize", oldValue, newFontSize); +// 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(PROPERTY_ADJUSTING, oldValue, adjusting); + } + /** * Save configuration, in user home directory using the * {@link #getConfigFileName}. Default, env and commande line note saved @@ -153,7 +209,7 @@ } public static final String[] DEFAULT_JAXX_PCS = { - "fullScreen", "locale", "fontSize" + PROPERTY_FULLSCREEN, PROPERTY_LOCALE, PROPERTY_FONT_SIZE, PROPERTY_ADJUSTING }; public void removeJaxxPropertyChangeListener() { @@ -180,8 +236,8 @@ CONFIG_FILE(CONFIG_FILE_NAME, _("jaxxdemo.config.configFileName.description"), "jaxxdemo", String.class, true, true), FULL_SCREEN("ui.fullscreen", _("jaxxdemo.config.ui.fullscreen"), "false", Boolean.class, false, false), - LOCALE("ui.locale", _("jaxxdemo.config.ui.locale"), Locale.FRANCE.toString(), Locale.class, false, false), - FONT_SIZE("ui.fontSize", _("jaxxdemo.config.ui.fontSize"), "10f", Float.class, false, false), + LOCALE("ui." + PROPERTY_LOCALE, _("jaxxdemo.config.ui." + PROPERTY_LOCALE), Locale.FRANCE.toString(), Locale.class, false, false), + FONT_SIZE("ui." + PROPERTY_FONT_SIZE, _("jaxxdemo.config.ui." + PROPERTY_FONT_SIZE), "10f", Float.class, false, false), DEMO_PATH("ui.demo.path", _("jaxxdemo.config.ui.demo.path"), "$root/jaxxdemo.tree.component.jaxx/jaxxdemo.tree.component.jaxx.tree.navigation/" + FullNavigationTreeDemo.class.getSimpleName(), String.class, false, false); public final String key; public final String description; Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoSources.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoSources.jaxx 2009-12-22 17:34:34 UTC (rev 1694) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoSources.jaxx 2009-12-22 17:35:06 UTC (rev 1695) @@ -70,7 +70,7 @@ onItemStateChanged='if(event.getStateChange() == ItemEvent.SELECTED) { updateSource(event); }'/> <javax.swing.Box.Filler constructorParams='SwingUtil.newMinDimension(), SwingUtil.newMinDimension(), SwingUtil.newMaxXDimension()'/> - <FontSizor id='fontSizor' opaque='false' showFontSize='true' defaultFontSize='{getConfig().getFontSize()}'/> + <FontSizor id='fontSizor' opaque='false' showFontSize='true' fontSize='{getConfig().getFontSize()}'/> <!--defaultFontSize='{getConfig().getFontSize()}' fontSize='{getConfig().getFontSize()}'/>--> </JToolBar> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-12-22 17:34:34 UTC (rev 1694) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-12-22 17:35:06 UTC (rev 1695) @@ -30,6 +30,7 @@ import jaxx.runtime.swing.editor.config.ConfigUI; import jaxx.runtime.swing.editor.config.ConfigUIBuilder; import jaxx.runtime.swing.editor.config.model.ConfigUIModel; +import jaxx.runtime.swing.editor.config.model.ConfigUIModelBuilder; import jaxx.runtime.swing.navigation.NavigationTreeNode; import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer; import org.apache.commons.logging.Log; @@ -61,15 +62,26 @@ * Methode pour initialiser l'ui principale sans l'afficher. * * @param rootContext le context applicatif - * @param fullscreen flag pour indiquer si on doit ouvrir l'ui en model console (pleine ecran). + * @param config la configuration a utiliser * @return l'ui instancie et initialisee mais non visible encore */ - public DemoUI initUI(DefaultApplicationContext rootContext, boolean fullscreen) { + public DemoUI initUI(DefaultApplicationContext rootContext, DemoConfig config) { if (log.isDebugEnabled()) { - log.debug("fullscreen ? " + fullscreen); + log.debug("fullscreen ? " + config.isFullScreen()); } + DecoratorProvider decoratorProvider = rootContext.getContextValue(DecoratorProvider.class); + if (!config.getLocale().equals(I18n.getLoader().getLanguage().getLocale())) { + if (log.isInfoEnabled()) { + log.info("re-init I18n with locale " + config.getLocale()); + } + // change i18n language + I18n.init(config.getLocale()); + // reload decorators + decoratorProvider.reload(); + } + // create restrict context for ui JAXXInitialContext context = new JAXXInitialContext(); @@ -82,11 +94,10 @@ // share config context.add(rootContext.getContextValue(DemoConfig.class)); + // share a unique DecoratorProvider + context.add(decoratorProvider); + // share a unique DecoratorProviderListCellRenderer - DecoratorProvider decoratorProvider = rootContext.getContextValue(DecoratorProvider.class); - - context.add(decoratorProvider); - context.add(new DecoratorProviderListCellRenderer(decoratorProvider)); // instanciate ui @@ -99,7 +110,7 @@ ErrorDialogUI.init(ui); // set fullscreen propery on main ui - ui.getGraphicsConfiguration().getDevice().setFullScreenWindow(fullscreen ? ui : null); + ui.getGraphicsConfiguration().getDevice().setFullScreenWindow(config.isFullScreen() ? ui : null); return ui; } @@ -149,9 +160,9 @@ * Permet de recharger l'ui principale et de changer de le mode d'affichage. * * @param rootContext le contexte applicatif - * @param fullscreen le type de fenetre à reouvrir + * @param config la configuration a utiliser */ - public void reloadUI(DefaultApplicationContext rootContext, boolean fullscreen) { + public void reloadUI(DefaultApplicationContext rootContext, DemoConfig config) { // scan main ui DemoUI ui = getUI(rootContext); @@ -167,7 +178,9 @@ if (node != null) { nodePath = node.getFullPath(); - log.info("selected node " + nodePath); + if (log.isDebugEnabled()) { + log.debug("selected node " + nodePath); + } } ErrorDialogUI.init(null); @@ -177,10 +190,9 @@ ui.setVisible(false); MAIN_UI_ENTRY_DEF.removeContextValue(rootContext); - } - ui = initUI(rootContext, fullscreen); + ui = initUI(rootContext, config); displayUI(ui, nodePath); } @@ -200,10 +212,11 @@ DemoUI ui = getUI(context); // sauvegarde de l'état dans la configuration - ui.getConfig().setFullscreen(fullscreen); + DemoConfig config = ui.getConfig(); + config.setFullscreen(fullscreen); // rechargement de l'ui - reloadUI(RunDemo.get(), fullscreen); + reloadUI(RunDemo.get(), config); } public void changeLanguage(JAXXContext context, Locale newLocale) { @@ -215,11 +228,8 @@ // sauvegarde de la nouvelle locale config.setLocale(newLocale); - // chargement de la nouvelle locale dans le système i18n - I18n.init(newLocale); - // rechargement de l'ui - reloadUI(RunDemo.get(), config.isFullScreen()); + reloadUI(RunDemo.get(), config); } /** @@ -240,23 +250,49 @@ public void showConfig(JAXXContext context) { DemoUI ui = getUI(context); - DemoConfig config = ui.getConfig(); - ConfigUIModel model = new ConfigUIModel(config); + final DemoConfig config = ui.getConfig(); + ConfigUIModelBuilder builder = new ConfigUIModelBuilder(); + + builder.createModel(config); + + builder.setReloadUICallback(new Runnable() { + + @Override + public void run() { + if (log.isInfoEnabled()) { + log.info("will reload ui"); + } + DefaultApplicationContext context = RunDemo.get(); + DemoUI ui = getUI(context); + DemoConfig config = ui.getConfig(); + reloadUI(context, config); + } + }); + // categorie repertoires - model.addCategory( - n_("jaxxdemo.config.category.directories"), - n_("jaxxdemo.config.category.directories.description"), - DemoConfig.Option.CONFIG_FILE); + builder.addCategory(n_("jaxxdemo.config.category.directories"), + n_("jaxxdemo.config.category.directories.description")); + + builder.addOption(DemoConfig.Option.CONFIG_FILE); + // others - model.addCategory( - n_("jaxxdemo.config.category.other"), - n_("jaxxdemo.config.category.other.description"), - DemoConfig.Option.FULL_SCREEN, - DemoConfig.Option.FONT_SIZE, - DemoConfig.Option.LOCALE); + builder.addCategory(n_("jaxxdemo.config.category.other"), + n_("jaxxdemo.config.category.other.description")); + builder.addOption(DemoConfig.Option.FULL_SCREEN); + builder.setOptionPropertyName(DemoConfig.PROPERTY_FULLSCREEN); + builder.setOptionNeedReloadUI(true); + + builder.addOption(DemoConfig.Option.FONT_SIZE); + builder.setOptionPropertyName(DemoConfig.PROPERTY_FONT_SIZE); + + builder.addOption(DemoConfig.Option.LOCALE); + builder.setOptionPropertyName(DemoConfig.PROPERTY_LOCALE); + builder.setOptionNeedReloadUI(true); + + ConfigUIModel model = builder.flushModel(); ConfigUI configUI = ConfigUIBuilder.newConfigUI(context, model, "jaxxdemo.config.category.directories"); ConfigUIBuilder.showConfigUI(configUI, ui, false); Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java 2009-12-22 17:34:34 UTC (rev 1694) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java 2009-12-22 17:35:06 UTC (rev 1695) @@ -126,7 +126,7 @@ // on affiche l'ui principale DemoUIHandler handler = new DemoUIHandler(); - DemoUI ui = handler.initUI(rootContext, config.isFullScreen()); + DemoUI ui = handler.initUI(rootContext, config); log.info(_("jaxxdemo.init.ui.done")); Modified: trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties 2009-12-22 17:34:34 UTC (rev 1694) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties 2009-12-22 17:35:06 UTC (rev 1695) @@ -165,6 +165,7 @@ jaxxdemo.config.category.other=Others jaxxdemo.config.category.other.description=Others preferences jaxxdemo.config.configFileName.description=Configuration file name +jaxxdemo.config.ui.= jaxxdemo.config.ui.demo.path= jaxxdemo.config.ui.fontSize= jaxxdemo.config.ui.fullscreen=To change the screen mode (true for full screen) Modified: trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties 2009-12-22 17:34:34 UTC (rev 1694) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties 2009-12-22 17:35:06 UTC (rev 1695) @@ -165,6 +165,7 @@ jaxxdemo.config.category.other=Autre jaxxdemo.config.category.other.description=Autres options jaxxdemo.config.configFileName.description=Le nom du fichier de configuration +jaxxdemo.config.ui.= jaxxdemo.config.ui.demo.path= jaxxdemo.config.ui.fontSize= jaxxdemo.config.ui.fullscreen=Pour afficher l'aplication en mode pleine \u00E9cran Modified: trunk/jaxx-demo/src/main/resources/log4j.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/log4j.properties 2009-12-22 17:34:34 UTC (rev 1694) +++ trunk/jaxx-demo/src/main/resources/log4j.properties 2009-12-22 17:35:06 UTC (rev 1695) @@ -6,8 +6,7 @@ log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n log4j.logger.jaxx.demo=INFO -log4j.logger.jaxx.runtime.swing.editor.I18nEditor=INFO -#log4j.logger.jaxx.runtime.swing.navigation.NavigationTreeCellRenderer=DEBUG -#log4j.logger.jaxx.runtime.swing.navigation.NavigationTreeNodeRenderer=DEBUG -#log4j.logger.jaxx.runtime.swing.navigation.NavigationTreeModel=DEBUG +log4j.logger.jaxx.demo.DemoConfig=DEBUG +log4j.logger.jaxx.runtime.swing.editor.config=INFO +log4j.logger.jaxx.runtime.swing.editor.config.model.ConfigUIModelBuilder=DEBUG log4j.logger.org.nuiton=WARN