Author: tchemit Date: 2009-10-29 17:48:10 +0100 (Thu, 29 Oct 2009) New Revision: 1617 Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx Log: - use DecoratorProviderListCellRenderer Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java =================================================================== --- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-10-29 14:55:21 UTC (rev 1616) +++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-10-29 16:48:10 UTC (rev 1617) @@ -20,26 +20,28 @@ */ package jaxx.demo; -import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.JAXXContext; +import jaxx.runtime.context.DefaultApplicationContext; +import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.context.JAXXInitialContext; +import jaxx.runtime.decorator.DecoratorProvider; +import jaxx.runtime.swing.AboutPanel; +import jaxx.runtime.swing.ErrorDialogUI; +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.navigation.NavigationTreeNode; +import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.i18n.I18n; import static org.nuiton.i18n.I18n._; import static org.nuiton.i18n.I18n.n_; -import java.awt.Desktop; +import javax.swing.*; +import java.awt.*; import java.net.URL; import java.util.Locale; -import javax.swing.SwingUtilities; -import jaxx.runtime.context.DefaultApplicationContext; -import jaxx.runtime.context.JAXXContextEntryDef; -import jaxx.runtime.swing.AboutPanel; -import jaxx.runtime.swing.editor.config.ConfigUI; -import jaxx.runtime.swing.editor.config.ConfigUIBuilder; -import jaxx.runtime.swing.editor.config.model.ConfigUIModel; -import org.nuiton.i18n.I18n; /** * Le handler de l'ui principale. @@ -49,7 +51,9 @@ */ public class DemoUIHandler { //implements JAXXHelp { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** + * to use log facility, just put in your code: log.info(\"...\"); + */ static private Log log = LogFactory.getLog(DemoUIHandler.class); static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = jaxx.runtime.Util.newContextEntryDef("mainui", DemoUI.class); @@ -78,6 +82,10 @@ // share config context.add(rootContext.getContextValue(DemoConfig.class)); + // share a unique DecoratorProviderListCellRenderer + DecoratorProvider decoratorProvider = rootContext.getContextValue(DecoratorProvider.class); + context.add(new DecoratorProviderListCellRenderer(decoratorProvider)); + // instanciate ui DemoUI ui = new DemoUI(context); @@ -145,7 +153,7 @@ // scan main ui DemoUI ui = getUI(rootContext); - NavigationTreeNode node = null; + NavigationTreeNode node; String nodePath = null; if (ui != null) { @@ -181,7 +189,7 @@ * mode console (c'est à dire en mode plein écran exclusif), sinon on * passe en mode fenetré normal. * - * @param context l'ui principale de l'application + * @param context l'ui principale de l'application * @param fullscreen le nouvel état requis. */ public void changeScreen(JAXXContext context, final boolean fullscreen) { @@ -250,7 +258,7 @@ ConfigUIBuilder.showConfigUI(configUI, ui, false); } -// @Override + // @Override public void showHelp(JAXXContext context, String helpId) { // DemoUI mainUI = getUI(context); // ObserveHelpBroker helpBroker = context.getContextValue(ObserveHelpBroker.class); Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java =================================================================== --- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java 2009-10-29 14:55:21 UTC (rev 1616) +++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java 2009-10-29 16:48:10 UTC (rev 1617) @@ -20,7 +20,11 @@ */ package jaxx.demo; +import jaxx.demo.component.jaxx.navigation.Movie; +import jaxx.demo.component.jaxx.navigation.People; +import jaxx.runtime.SwingUtil; import jaxx.runtime.context.DefaultApplicationContext; +import jaxx.runtime.decorator.DecoratorProvider; import jaxx.runtime.swing.ErrorDialogUI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -28,10 +32,7 @@ import static org.nuiton.i18n.I18n._; import org.nuiton.util.StringUtil; -import jaxx.runtime.SwingUtil; - /** - * * @author chemit */ public class RunDemo { @@ -41,17 +42,13 @@ */ private static Log log = LogFactory.getLog(RunDemo.class); /** - * When application was started - */ - private static long startingTime = System.nanoTime(); - /** * The singleton instance of the main context */ protected static DefaultApplicationContext context; public static void main(String[] args) { - startingTime = System.nanoTime(); + long startingTime = System.nanoTime(); log.info("JAXX Demo start at " + new java.util.Date() + " args: " + java.util.Arrays.toString(args)); try { @@ -81,6 +78,20 @@ // share the config rootContext.setContextValue(config); + // init decorator provider + DecoratorProvider p = new DecoratorProvider() { + + @Override + protected void loadDecorators() { + + registerMultiJXPathDecorator(Movie.class, "${title}$s##${year}$s", "##", " - "); + registerMultiJXPathDecorator(People.class, "${firstName}$s##${lastName}$s", "##", " "); + } + }; + + // share the decorator provider + rootContext.setContextValue(p); + long t00 = System.nanoTime(); // init i18n @@ -141,6 +152,7 @@ * l'context partagée. * <p/> * Note : Cette méthode ne peut être appelée qu'une seule fois. + * * @return l'context partagée * @throws IllegalStateException si un contexte applicatif a déja été positionné. */ Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java =================================================================== --- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2009-10-29 14:55:21 UTC (rev 1616) +++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2009-10-29 16:48:10 UTC (rev 1617) @@ -20,10 +20,10 @@ */ package jaxx.demo.component.jaxx.navigation; -import jaxx.runtime.JAXXObject; import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.Util; import jaxx.runtime.context.JAXXContextEntryDef; -import jaxx.runtime.decorator.DecoratorUtils; import jaxx.runtime.swing.CardLayout2; import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.swing.navigation.NavigationTreeHandler; @@ -34,11 +34,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - +import javax.swing.*; import java.util.Arrays; import java.util.List; -import javax.swing.JPanel; -import jaxx.runtime.Util; /** * @@ -47,17 +45,17 @@ */ public class FullNavigationTreeHelper extends NavigationTreeHelper { - static { - // register decorator one for all - - DecoratorUtils.register( - Movie.class.getSimpleName(), - DecoratorUtils.newMultiJXPathDecorator(Movie.class, "${title}$s##${year}$s", "##", " - ")); - - DecoratorUtils.register( - People.class.getSimpleName(), - DecoratorUtils.newMultiJXPathDecorator(People.class, "${firstName}$s##${lastName}$s", "##", " ")); - } +// static { +// // register decorator one for all +// +// DecoratorUtils.register( +// Movie.class.getSimpleName(), +// DecoratorUtils.newMultiJXPathDecorator(Movie.class, "${title}$s##${year}$s", "##", " - ")); +// +// DecoratorUtils.register( +// People.class.getSimpleName(), +// DecoratorUtils.newMultiJXPathDecorator(People.class, "${firstName}$s##${lastName}$s", "##", " ")); +// } /** * Logger */ Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java =================================================================== --- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2009-10-29 14:55:21 UTC (rev 1616) +++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2009-10-29 16:48:10 UTC (rev 1617) @@ -20,14 +20,17 @@ */ package jaxx.demo.component.jaxx.navigation; +import jaxx.demo.component.jaxx.navigation.content.ActorContentUI; +import jaxx.demo.component.jaxx.navigation.content.ActorsContentUI; +import jaxx.demo.component.jaxx.navigation.content.MovieContentUI; +import jaxx.demo.component.jaxx.navigation.content.MoviesContentUI; import jaxx.runtime.JAXXContext; import jaxx.runtime.decorator.Decorator; -import jaxx.runtime.decorator.DecoratorUtils; +import jaxx.runtime.decorator.DecoratorProvider; import jaxx.runtime.swing.navigation.NavigationTreeModelBuilder; import jaxx.runtime.swing.navigation.NavigationTreeNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import jaxx.demo.component.jaxx.navigation.content.*; import static org.nuiton.i18n.I18n._; import java.util.List; @@ -39,7 +42,6 @@ */ public class FullNavigationTreeModelBuilder extends NavigationTreeModelBuilder { - private static final long serialVersionUID = 1l; /** * Logger */ @@ -67,8 +69,9 @@ } - Decorator<Movie> mDecorator = DecoratorUtils.get(Movie.class.getSimpleName()); - Decorator<People> pDecorator = DecoratorUtils.get(People.class.getSimpleName()); + DecoratorProvider decoratorProvider = getModel().getContext().getContextValue(DecoratorProvider.class); + Decorator<Movie> mDecorator = decoratorProvider.getDecorator(Movie.class); + Decorator<People> pDecorator = decoratorProvider.getDecorator(People.class); // construction du noeud root // il ne contient pas de context et ne sera pas visible Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx =================================================================== --- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2009-10-29 14:55:21 UTC (rev 1616) +++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2009-10-29 16:48:10 UTC (rev 1617) @@ -23,8 +23,7 @@ <script><![CDATA[ import jaxx.runtime.SwingUtil; import jaxx.demo.component.jaxx.navigation.*; -import jaxx.runtime.decorator.DecoratorUtils; -import jaxx.runtime.swing.renderer.MultiDecoratorListCellRenderer; +import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer; import jaxx.runtime.swing.navigation.NavigationTreeNode; @Override @@ -56,7 +55,7 @@ columnHeaderView='{toolbar}' horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}' verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'> - <JList id='list' model='{new DefaultListModel()}' cellRenderer='{getContextValue(MultiDecoratorListCellRenderer.class)}'/> + <JList id='list' model='{new DefaultListModel()}' cellRenderer='{getContextValue(DecoratorProviderListCellRenderer.class)}'/> </JScrollPane> <JToolBar id='toolbar' constraints='BorderLayout.SOUTH' floatable='false'> Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx =================================================================== --- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2009-10-29 14:55:21 UTC (rev 1616) +++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2009-10-29 16:48:10 UTC (rev 1617) @@ -26,18 +26,9 @@ <script><![CDATA[ import jaxx.runtime.SwingUtil; import jaxx.demo.component.jaxx.navigation.*; -import jaxx.runtime.decorator.DecoratorUtils; -import jaxx.runtime.decorator.MultiJXPathDecorator; -import jaxx.runtime.swing.renderer.MultiDecoratorListCellRenderer; import jaxx.runtime.swing.navigation.NavigationTreeNode; import jaxx.runtime.swing.navigation.NavigationContentUI; -// init shared list decorator -MultiJXPathDecorator<?> d0 = (MultiJXPathDecorator<?>)DecoratorUtils.get(People.class.getSimpleName()); -MultiJXPathDecorator<?> d1 = (MultiJXPathDecorator<?>)DecoratorUtils.get(Movie.class.getSimpleName()); -MultiDecoratorListCellRenderer r = new MultiDecoratorListCellRenderer(d0,d1); -setContextValue(r); - ContentUIHandler getHandler() { return getContextValue(ContentUIHandler.class); } Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx =================================================================== --- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2009-10-29 14:55:21 UTC (rev 1616) +++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2009-10-29 16:48:10 UTC (rev 1617) @@ -23,8 +23,7 @@ <script><![CDATA[ import jaxx.runtime.SwingUtil; import jaxx.demo.component.jaxx.navigation.*; -import jaxx.runtime.decorator.DecoratorUtils; -import jaxx.runtime.swing.renderer.MultiDecoratorListCellRenderer; +import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer; import jaxx.runtime.swing.navigation.NavigationTreeNode; @Override @@ -56,7 +55,7 @@ columnHeaderView='{toolbar}' horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}' verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'> - <JList id='list' model='{new DefaultListModel()}' cellRenderer='{getContextValue(MultiDecoratorListCellRenderer.class)}'/> + <JList id='list' model='{new DefaultListModel()}' cellRenderer='{getContextValue(DecoratorProviderListCellRenderer.class)}'/> </JScrollPane> <JToolBar id='toolbar' opaque='false' constraints='BorderLayout.SOUTH' floatable='false'>