r2187 - in trunk: . jaxx-compiler jaxx-compiler/src/main/java/jaxx/compiler jaxx-compiler/src/main/java/jaxx/compiler/binding jaxx-compiler/src/main/java/jaxx/compiler/binding/writers jaxx-compiler/src/main/java/jaxx/compiler/css jaxx-compiler/src/main/java/jaxx/compiler/decorators jaxx-compiler/src/main/java/jaxx/compiler/finalizers jaxx-compiler/src/main/java/jaxx/compiler/java jaxx-compiler/src/main/java/jaxx/compiler/reflect jaxx-compiler/src/main/java/jaxx/compiler/script jaxx-compiler/s
Author: tchemit Date: 2011-01-31 18:54:12 +0100 (Mon, 31 Jan 2011) New Revision: 2187 Url: http://nuiton.org/repositories/revision/jaxx/2187 Log: Evolution #1266: Uses Eugene for generation Clean a lot of codes Make generation nearly clean Added: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/AbstractJAXXBindingWriter.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/DefaultJAXXBindingWriter.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/JAXXBindingWriter.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/SimpleJAXXObjectBindingWriter.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/AbstractFinalizer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/JAXXCompilerFinalizer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaElementFactory.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanelHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUIHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizorHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/HidorButtonHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/MemoryStatusWidgetHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/I18nEditorHandler.java Removed: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompilerFinalizer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/AbstractJAXXBindingWriter.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DefaultJAXXBindingWriter.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/JAXXBindingWriter.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/SimpleJAXXObjectBindingWriter.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/ColumnSelector.jaxx Modified: trunk/jaxx-compiler/pom.xml trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObjectDecorator.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/EventHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/I18nHelper.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataBinding.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/css/StylesheetHelper.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/SwingFinalizer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/ValidatorFinalizer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaArgument.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaField.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFileGenerator.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaMethod.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptor.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/TagHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JToolBarHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/ExcludeFieldValidatorHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateTask.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeManager.java trunk/jaxx-compiler/src/test/java/jaxx/compiler/binding/JavaParserUtilTest.java trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFileTest.java trunk/jaxx-demo/src/main/java/jaxx/demo/DemoSources.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTab.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/BoxedDecoratorDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/I18nEditorDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JButtonDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JCheckBoxDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JComboBoxDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JDialogDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JMenuItemDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JProgressBarDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JRadioButtonDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JRadioButtonMenuItemDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSliderDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSpinnerDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSplitPaneDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JTextFieldDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/BindingExtremeDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/ActorContentUI.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/ActorsContentUI.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/MovieContentUI.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/MoviesContentUI.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/feature/validation/ValidationListDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/feature/validation/ValidationTableDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/fun/CalculatorDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/fun/LabelStyleDemo.jaxx 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-widgets/src/main/java/jaxx/runtime/swing/AboutPanel.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ClockWidget.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUI.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizor.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/HidorButton.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ListSelectorUI.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/MemoryStatusWidget.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanel.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanelHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/I18nEditor.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/NumberEditor.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/TimeEditor.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBox.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanListHeader.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1751Test.java trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/compilerTest/cSSTests/GrandChild.jaxx trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/compilerTest/cSSTests/SimpleCSS.jaxx trunk/pom.xml Modified: trunk/jaxx-compiler/pom.xml =================================================================== --- trunk/jaxx-compiler/pom.xml 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/pom.xml 2011-01-31 17:54:12 UTC (rev 2187) @@ -62,6 +62,11 @@ </dependency> <dependency> + <groupId>org.nuiton.eugene</groupId> + <artifactId>eugene</artifactId> + </dependency> + + <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </dependency> Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -474,6 +474,7 @@ protected String getInitializationCode(EventHandler handler, JAXXCompiler compiler) { MethodDescriptor addMethod = handler.getAddMethod(); ClassDescriptor listenerClass = addMethod.getParameterTypes()[0]; + compiler.addImport(listenerClass.getName()); //TC-20091026 use 'this' instead of root object javaCode //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple name return getJavaCode() + '.' + addMethod.getName() + "(JAXXUtil.getEventListener(" + listenerClass.getSimpleName() + ".class, " + Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObjectDecorator.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObjectDecorator.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObjectDecorator.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -44,18 +44,22 @@ String getName(); /** - * Obtain the setup code of the given {@code object} from the {@code compiler} to be inject in the generated - * method {@code $completeSetup}. + * Obtain the setup code of the given {@code object} from the + * {@code compiler} to be inject in the generated method + * {@code $completeSetup}. * * @param compiler the compiler to use * @param object the compiled object to treate * @param javaFile the file to treate * @return the code to inject in $completeSetup method in file */ - String createCompleteSetupMethod(JAXXCompiler compiler, CompiledObject object, JavaFile javaFile); + String createCompleteSetupMethod(JAXXCompiler compiler, + CompiledObject object, + JavaFile javaFile); /** - * Create the initializer code for the given compiled {@code object} and inject it in the {@code code}. + * Create the initializer code for the given compiled {@code object} and + * inject it in the {@code code}. * * @param compiler the compiler to use * @param root the root compiled object of the jaxx file @@ -64,7 +68,11 @@ * @param lastWasMethodCall {@code true} if last instruction call was a method call * @return {@code true} if the last instruction was a method call */ - boolean createInitializer(JAXXCompiler compiler, CompiledObject root, CompiledObject object, StringBuffer code, boolean lastWasMethodCall); + boolean createInitializer(JAXXCompiler compiler, + CompiledObject root, + CompiledObject object, + StringBuffer code, + boolean lastWasMethodCall); /** * Finalize the given compiled object before any generation in the {@code file}. @@ -77,7 +85,13 @@ * @param className the (simple ?) class name * @param fullClassName the fully class name */ - void finalizeCompiler(JAXXCompiler compiler, CompiledObject root, CompiledObject object, JavaFile javaFile, String packageName, String className, String fullClassName); + void finalizeCompiler(JAXXCompiler compiler, + CompiledObject root, + CompiledObject object, + JavaFile javaFile, + String packageName, + String className, + String fullClassName); /** * Obtain the creation code of the given {@code object} from the {@code compiler} to inject in generate method @@ -88,5 +102,6 @@ * @return the code to inject in $initialize (or in the createXXX in not inline) method to create the given object * @throws CompilerException if any pb */ - String getCreationCode(JAXXCompiler compiler, CompiledObject object) throws CompilerException; + String getCreationCode(JAXXCompiler compiler, + CompiledObject object) throws CompilerException; } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,6 +25,7 @@ package jaxx.compiler; +import jaxx.compiler.finalizers.JAXXCompilerFinalizer; import jaxx.compiler.spi.Initializer; import jaxx.runtime.JAXXContext; @@ -81,7 +82,7 @@ /** * Returns whether or not should recurse in css for existing JAXX Object. - * + * <p/> * <b>Note:</b> This functionnality was here at the beginning of the project * but offers nothing very usefull, will be remove probably in JAXX 3.0. * @@ -98,11 +99,6 @@ */ File getTargetDirectory(); - /** @return the type of validator to use. - * @deprecated since 2.3, will not be replaced since new validator api does not support it.*/ - @Deprecated - Class<?> getValidatorClass(); - /** @return {@code true} if a logger must add on each generated jaxx object */ boolean isAddLogger(); @@ -127,6 +123,12 @@ /** @return {@code true} if compiler is verbose */ boolean isVerbose(); + /** + * @return {@code true} to trace the Class descriptor loading. + * @since 2.4 + */ + boolean isShowClassDescriptorLoading(); + /** @return the encoding to use to write files */ String getEncoding(); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,6 +25,7 @@ package jaxx.compiler; +import jaxx.compiler.finalizers.JAXXCompilerFinalizer; import jaxx.compiler.spi.Initializer; import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXObject; @@ -42,8 +43,7 @@ /** Options of the {@link JAXXCompiler} and {@link JAXXEngine}. */ public class DefaultCompilerConfiguration implements CompilerConfiguration { - - /** Logger */ + /** Logger. */ private static final Log log = LogFactory.getLog(DefaultCompilerConfiguration.class); @@ -87,16 +87,6 @@ private Class<? extends JAXXCompiler> compilerClass; /** - * the validator class to use. - * - * @since 1.6.0 - * @deprecated since 2.3, will not be replaced, since new validator api - * does not support it. - */ - @Deprecated - private Class<?> validatorClass; - - /** * the default compiled object decorator to use if none specifed via * decorator attribute */ @@ -130,6 +120,13 @@ /** initializes availables */ protected Map<String, Initializer> initializers; + /** + * To trace class descriptor loading. + * + * @since 2.4 + */ + private boolean showClassDescriptorLoading; + @Override public File getTargetDirectory() { return targetDirectory; @@ -145,6 +142,11 @@ return verbose; } + @Override + public boolean isShowClassDescriptorLoading() { + return showClassDescriptorLoading; + } + public void setVerbose(boolean verbose) { this.verbose = verbose; } @@ -220,11 +222,6 @@ } @Override - public Class<?> getValidatorClass() { - return validatorClass; - } - - @Override public String getEncoding() { return encoding; } @@ -241,7 +238,8 @@ // load decorators ServiceLoader<CompiledObjectDecorator> services = - ServiceLoader.load(CompiledObjectDecorator.class, classloader); + ServiceLoader.load(CompiledObjectDecorator.class, + classloader); for (CompiledObjectDecorator decorator : services) { if (log.isInfoEnabled()) { log.info("detected " + decorator); @@ -264,7 +262,8 @@ } ServiceLoader<JAXXCompilerFinalizer> services = - ServiceLoader.load(JAXXCompilerFinalizer.class, classloader); + ServiceLoader.load(JAXXCompilerFinalizer.class, + classloader); for (JAXXCompilerFinalizer finalizer : services) { if (log.isInfoEnabled()) { log.info("detected " + finalizer); @@ -310,6 +309,7 @@ @Override public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + return ToStringBuilder.reflectionToString( + this, ToStringStyle.MULTI_LINE_STYLE); } } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/EventHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/EventHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/EventHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -31,13 +31,23 @@ public class EventHandler { private String eventId; + private String objectCode; + private ClassDescriptor listenerClass; + private MethodDescriptor addMethod; + private MethodDescriptor listenerMethod; + private String javaCode; - public EventHandler(String eventId, String objectCode, MethodDescriptor addMethod, ClassDescriptor listenerClass, MethodDescriptor listenerMethod, String javaCode) { + public EventHandler(String eventId, + String objectCode, + MethodDescriptor addMethod, + ClassDescriptor listenerClass, + MethodDescriptor listenerMethod, + String javaCode) { this.eventId = eventId; this.objectCode = objectCode; this.addMethod = addMethod; @@ -72,6 +82,8 @@ @Override public String toString() { - return "EventHandler[" + eventId + ", " + listenerClass.getName() + ", " + objectCode + ", " + javaCode + "]"; + return "EventHandler[" + eventId + ", " + + listenerClass.getName() + ", " + + objectCode + ", " + javaCode + "]"; } } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/I18nHelper.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/I18nHelper.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/I18nHelper.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -27,12 +27,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.i18n.I18n; import java.util.Arrays; import java.util.List; /** - * I18n methods to add {@link org.nuiton.i18n.I18n#_(String, Object...)} method on some attributes. + * I18n methods to add {@link I18n#_(String, Object...)} method on some attributes. * <p/> * Make sure to set an i18nable compiler to have his {@link CompilerConfiguration#isI18nable()} returning true. * @@ -41,6 +42,7 @@ public class I18nHelper { protected static final Log log = LogFactory.getLog(I18nHelper.class); + public static final List<String> I18N_ATTRIBUTES = Arrays.asList("text", "title", "toolTipText"); /** @@ -69,7 +71,7 @@ * <p/> * Note: <b>Be ware : </b> no test is done here to ensure we are on a i18neable attribute for an i18nable compiler. * <p/> - * Make sure with the method {@link jaxx.compiler.I18nHelper#isI18nableAttribute(String, JAXXCompiler)} returns + * Make sure with the method {@link I18nHelper#isI18nableAttribute(String, JAXXCompiler)} returns * <code>true</code< before using this method. * * @param widgetId the id of the widget @@ -86,6 +88,7 @@ if (attributeValueCode.contains("_(") && attributeValueCode.contains(")")) { compiler.reportWarning("\n\tjaxx supports i18n, no need to add explicit call to I18n._ for attribute '" + attributeName + "' in component '" + widgetId + "' : [" + attributeValueCode + "]"); } else { + compiler.addImport("static " + I18n.class.getName() + "._"); attributeValueCode = "_(" + attributeValueCode + ")"; } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -27,6 +27,8 @@ import jaxx.compiler.binding.DataBindingHelper; import jaxx.compiler.css.StylesheetHelper; +import jaxx.compiler.finalizers.JAXXCompilerFinalizer; +import jaxx.compiler.java.JavaElementFactory; import jaxx.compiler.java.JavaField; import jaxx.compiler.java.JavaFile; import jaxx.compiler.java.JavaFileGenerator; @@ -44,9 +46,12 @@ import jaxx.runtime.JAXXObjectDescriptor; import jaxx.runtime.css.Rule; import jaxx.runtime.css.Stylesheet; +import org.apache.commons.collections.BeanMap; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.java.JavaGeneratorUtil; +import org.nuiton.eugene.java.extension.ImportsManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.Attributes; @@ -67,6 +72,7 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.sax.SAXSource; +import java.awt.BorderLayout; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; @@ -89,7 +95,6 @@ import java.util.Map; import java.util.Set; import java.util.Stack; -import java.util.StringTokenizer; /** * Compiles a given {@link #jaxxFile} into a {@link #javaFile}. @@ -126,6 +131,8 @@ protected static String lineSeparator = System.getProperty("line.separator", "\n"); + public static final String BORDER_LAYOUT_PREFIX = BorderLayout.class.getSimpleName() + "."; + /** The unique object handler used in first pass */ protected final DefaultObjectHandler firstPassClassTagHandler; @@ -319,7 +326,6 @@ importedPackages = new HashSet<String>(); importedClasses = new HashSet<String>(); sourceFiles = new Stack<File>(); - if (jaxxFile == null) { src = null; baseDir = null; @@ -339,8 +345,8 @@ bindingHelper = new DataBindingHelper(this); if (defaultImports != null) { - for (Object staticImport : defaultImports) { - addImport((String) staticImport); + for (String defaultImport : defaultImports) { + addDefaultImport(defaultImport); } } @@ -489,41 +495,57 @@ tag.getAttribute(DefaultObjectHandler.IMPLEMENTS_ATTRIBUTE); if (!interfacesStr.isEmpty()) { // there is some interfaces to deal with - StringTokenizer stk = new StringTokenizer(interfacesStr, ","); - List<String> tmp = new ArrayList<String>(); - while (stk.hasMoreTokens()) { - String c = stk.nextToken(); - if (c.contains("<") && !c.contains(">")) { - // deal with a generic interface with more than one - // parameter - boolean done = false; - while (stk.hasMoreTokens()) { - String next = stk.nextToken(); - if (!next.contains(">")) { - // still a parameter of the generic type - continue; - } - // ok find the ending token - done = true; - break; - } - if (!done) { - // the syntax is not valid (missed one >) - throw new CompilerException( - "Syntax error of interfaces " + - interfacesStr); - } - c = c.substring(0, c.indexOf("<")); + + try { + String[] interfaces = + JavaGeneratorUtil.splitFqnList(interfacesStr, ','); + if (log.isDebugEnabled()) { + log.debug("detect interfaces : " + + Arrays.toString(interfaces)); } - tmp.add(c.trim()); + symbolTable.setInterfaces(interfaces); + } catch (Exception e) { + // the syntax is not valid (missed one >) + throw new CompilerException( + "Syntax error of interfaces " + + interfacesStr); } - String[] interfaces = tmp.toArray(new String[tmp.size()]); - if (log.isDebugEnabled()) { - log.debug("detect interfaces : " + - Arrays.toString(interfaces)); - } - symbolTable.setInterfaces(interfaces); +// StringTokenizer stk = new StringTokenizer(interfacesStr, ","); +// List<String> tmp = new ArrayList<String>(); +// while (stk.hasMoreTokens()) { +// String c = stk.nextToken(); +// if (c.contains("<") && !c.contains(">")) { +// // deal with a generic interface with more than one +// // parameter +// boolean done = false; +// while (stk.hasMoreTokens()) { +// +// String next = stk.nextToken(); +// if (!next.contains(">")) { +// // still a parameter of the generic type +// continue; +// } +// // ok find the ending token +// done = true; +// break; +// } +// if (!done) { +// // the syntax is not valid (missed one >) +// throw new CompilerException( +// "Syntax error of interfaces " + +// interfacesStr); +// } +// //c = c.substring(0, c.indexOf("<")); +// } +// tmp.add(c.trim()); +// } +// String[] interfaces = tmp.toArray(new String[tmp.size()]); +// if (log.isDebugEnabled()) { +// log.debug("detect interfaces : " + +// Arrays.toString(interfaces)); +// } +// symbolTable.setInterfaces(interfaces); } } @@ -653,6 +675,13 @@ public void openComponent(CompiledObject component, String constraints) throws CompilerException { + if (constraints != null) { + + // try to add the constraints class in imports + if (constraints.startsWith(BORDER_LAYOUT_PREFIX)) { + addImport(BorderLayout.class.getName()); + } + } CompiledObject parent = getOpenComponent(); openInvisibleComponent(component); if (parent != null && !component.isOverride()) { @@ -1181,6 +1210,32 @@ return classLoader; } + /** + * Checks if the super class of the mirrored javaFile is aware of the + * iven {@code type}. + * <p/> + * <strong>Note:</strong> If no super-class exist, then returns + * {@code false}. + * + * @param type the type to check against super class + * @return {@code true} if super class exists and is assignable against the + * given type, {@code false} otherwise + * @throws ClassNotFoundException if could not find class descriptor for + * super-class + */ + public boolean isSuperClassAware(Class<?> type) throws ClassNotFoundException { + ClassDescriptor superClass = root.getObjectClass(); + if (superClass == null) { + + // no super class, not awre of anything + return false; + } + + boolean aware = ClassDescriptorHelper.isAssignableFrom(superClass, + type); + return aware; + } + public JAXXObjectDescriptor getJAXXObjectDescriptor() { runInitializers(); CompiledObject[] components = new ArrayList<CompiledObject>( @@ -1287,6 +1342,10 @@ /*-- Other methods -------------------------------------------------------*/ /*------------------------------------------------------------------------*/ + public void addImport(Class<?> clazz) { + addImport(clazz.getName()); + } + public void addImport(String text) { if (text.endsWith("*")) { importedPackages.add(text.substring(0, text.length() - 1)); @@ -1299,6 +1358,14 @@ } } + protected void addDefaultImport(String text) { + if (text.endsWith("*")) { + importedPackages.add(text.substring(0, text.length() - 1)); + } else { + importedClasses.add(text); + } + } + public void addDependencyClass(String className) { if (engine.containsJaxxFileClassName(className)) { @@ -1477,14 +1544,16 @@ if (javaFile == null) { String outputClassName = getOutputClassName(); if (outputClassName == null) { - javaFile = new JavaFile(); + javaFile = JavaElementFactory.newFile(0, ""); } else { int dotPos = outputClassName.lastIndexOf("."); String packageName = dotPos != -1 ? outputClassName.substring(0, dotPos) : null; String simpleClassName = outputClassName.substring(dotPos + 1); - javaFile = new JavaFile(0, packageName + "." + simpleClassName); + javaFile = JavaElementFactory.newFile( + Modifier.PUBLIC, + packageName + "." + simpleClassName); } } return javaFile; @@ -1508,8 +1577,7 @@ javaFile, packageName, simpleClassName, - getOutputClassName() - ); + getOutputClassName()); } // obtain list of finalizers to apply @@ -1810,4 +1878,8 @@ public void setClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } + + public ImportsManager getImportManager() { + return getJavaFile().getImportManager(); + } } Deleted: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompilerFinalizer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompilerFinalizer.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompilerFinalizer.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -1,79 +0,0 @@ -/* - * #%L - * JAXX :: Compiler - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package jaxx.compiler; - -import jaxx.compiler.java.JavaFile; - -/** - * Contract of any object to interact with a {@link JAXXCompiler} before the - * generation pass. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0.0 - */ -public interface JAXXCompilerFinalizer { - /** - * Test if the finalizer must be apply on the given {@code compiler}. - * - * @param compiler the compiler - * @return {@code true} if the finalizer must be apply of compiler - */ - boolean accept(JAXXCompiler compiler); - - /** - * Finalize compiler for a given compiler on the finalizer pass before any - * generation. - * - * @param root the root object - * @param compiler the current compiler - * @param javaFile the java file to generate - * @param packageName the package name of the file to generate - * @param className the class name of the file to generate - * @throws Exception if any pb - */ - void finalizeCompiler(CompiledObject root, - JAXXCompiler compiler, - JavaFile javaFile, - String packageName, - String className) throws Exception; - - /** - * Prepare java file after any compiler finalizer pass, says the last - * action before generation. - * - * @param root the root object - * @param compiler the current compiler - * @param javaFile the java file to generate - * @param packageName the package name of the file to generate - * @param className the class name of the file to generate - * @throws Exception if any pb - */ - void prepareJavaFile(CompiledObject root, - JAXXCompiler compiler, - JavaFile javaFile, - String packageName, - String className) throws Exception; -} Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,6 +25,7 @@ package jaxx.compiler; +import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.compiler.tasks.CompileFirstPassTask; import jaxx.compiler.tasks.CompileSecondPassTask; import jaxx.compiler.tasks.FinalizeTask; @@ -96,6 +97,9 @@ errors = new ArrayList<String>(); compilingFiles = new ArrayList<JAXXCompilerFile>(); + if (configuration.isShowClassDescriptorLoading()) { + ClassDescriptorHelper.setShowLoading(true); + } // add all default files to compile for (String relativePath : relativePaths) { JAXXCompilerFile compilerFile = @@ -204,6 +208,8 @@ profiler = null; } clearReports(); + + ClassDescriptorHelper.setShowLoading(false); } public void clearReports() { @@ -212,7 +218,7 @@ } public String getVersion() { - return "2.0.2"; + return "2.4"; } /** @@ -398,7 +404,7 @@ * * @param jaxxFile the definition of jaxx file to compile * @return the new compiler - * @throws Exception if any pb while creation of compiler + * @throws Exception if any pb while creating of compiler */ public JAXXCompiler newCompiler(JAXXCompilerFile jaxxFile) throws Exception { @@ -416,10 +422,8 @@ List.class ); - JAXXCompiler jaxxCompiler = (JAXXCompiler) cons.newInstance( - this, - jaxxFile, - Arrays.asList( + /* + Arrays.asList( "java.awt.*", "java.awt.event.*", "java.io.*", @@ -433,6 +437,22 @@ "static org.nuiton.i18n.I18n._", "static jaxx.runtime.SwingUtil.createImageIcon" ) + */ + JAXXCompiler jaxxCompiler = (JAXXCompiler) cons.newInstance( + this, + jaxxFile, + Arrays.asList( + "java.awt.*", +// "java.awt.event.*", +// "java.io.*", + "java.lang.*", +// "java.util.*", + "javax.swing.*", + "javax.swing.border.*", +// "javax.swing.event.*", +// "jaxx.runtime.*", + "jaxx.runtime.swing.*" + ) ); jaxxFile.setCompiler(jaxxCompiler); return jaxxCompiler; Deleted: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/AbstractJAXXBindingWriter.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/AbstractJAXXBindingWriter.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/AbstractJAXXBindingWriter.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -1,79 +0,0 @@ -/* - * #%L - * JAXX :: Compiler - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package jaxx.compiler.binding; - -import jaxx.compiler.JAXXCompiler; -import jaxx.compiler.finalizers.DefaultFinalizer; -import jaxx.compiler.java.JavaFileGenerator; -import jaxx.compiler.java.JavaMethod; -import jaxx.runtime.JAXXBinding; - -import java.util.List; - -/** - * Created: 5 déc. 2009 - * - * @author tchemit <chemit@codelutin.com> - * @version $Revision$ - * <p/> - * Mise a jour: $Date$ par : - * $Author$ - */ -public abstract class AbstractJAXXBindingWriter<B extends JAXXBinding> implements JAXXBindingWriter<B> { - - private final Class<B> type; - protected boolean used; - - protected AbstractJAXXBindingWriter(Class<B> type) { - this.type = type; - } - - @Override - public boolean isUsed() { - return used; - } - - - public Class<B> getType() { - return type; - } - - protected abstract String getConstructorParams(DataBinding binding, DataListener[] trackers); - - protected void writeInvocationMethod(DataBinding binding, DataListener[] trackers, JavaFileGenerator generator, StringBuilder buffer, List<JavaMethod> bMethods) { - used = true; - String eol = JAXXCompiler.getLineSeparator(); - buffer.append(DefaultFinalizer.METHOD_NAME_REGISTER_DATA_BINDING + "(new "); - buffer.append(getType().getSimpleName()).append("(").append(getConstructorParams(binding, trackers)).append(") {").append(eol); - for (JavaMethod m : bMethods) { - buffer.append(eol).append(JavaFileGenerator.indent(generator.generateMethod(m), 4, false, eol)).append(eol); - } - buffer.append("});").append(eol); - - if (binding.getInitDataBinding() != null) { - buffer.append(binding.getInitDataBinding()); - } - } -} \ No newline at end of file Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataBinding.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataBinding.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataBinding.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -47,7 +47,7 @@ */ public class DataBinding { - /** Logger */ + /** Logger. */ protected static final Log log = LogFactory.getLog(DataBinding.class); /** Id of the data binding */ Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -29,7 +29,8 @@ import jaxx.compiler.CompilerException; import jaxx.compiler.JAXXCompiler; import jaxx.compiler.UnsupportedAttributeException; -import jaxx.compiler.java.JavaArgument; +import jaxx.compiler.finalizers.AbstractFinalizer; +import jaxx.compiler.java.JavaElementFactory; import jaxx.compiler.java.JavaMethod; import jaxx.compiler.java.parser.JavaParser; import jaxx.compiler.java.parser.JavaParserConstants; @@ -106,7 +107,11 @@ * @param compiler the current <code>JAXXCompiler</code> * @param methods where to store extra method to add to binding */ - public DataSource(String id, String constantId, String source, JAXXCompiler compiler, List<JavaMethod> methods) { + public DataSource(String id, + String constantId, + String source, + JAXXCompiler compiler, + List<JavaMethod> methods) { this.id = id; this.constantId = constantId; this.source = source; @@ -528,7 +533,7 @@ null, "addPropertyChangeListener(\"" + memberName + "\", this);" + eol, // "addPropertyChangeListener(\"" + memberName + "\", " + listenerId + ");" + eol, -"removePropertyChangeListener(\"" + memberName + "\", this);" + eol); + "removePropertyChangeListener(\"" + memberName + "\", this);" + eol); // "removePropertyChangeListener(\"" + memberName + "\", " + listenerId + ");" + eol); assert contextClass != null : "script field '" + memberName + "' is defined, but has type null"; @@ -588,16 +593,22 @@ } } - private void addListener(String dependencySymbol, String objectCode, String addCode, String removeCode) { + private void addListener(String dependencySymbol, + String objectCode, + String addCode, + String removeCode) { if (objectCode != null) { objectCode = objectCode.trim(); } - boolean needTest = objectCode != null && !compiler.getRootObject().getId().equals(objectCode); + boolean needTest = objectCode != null && + !compiler.getRootObject().getId().equals(objectCode); if (!needTest) { objectCode = null; } if (log.isDebugEnabled()) { - log.debug("try to add listener [dependencySymbol:" + dependencySymbol + ", objectCode:" + objectCode + ", addCode:" + addCode + "]"); + log.debug("try to add listener [dependencySymbol:" + + dependencySymbol + ", objectCode:" + objectCode + + ", addCode:" + addCode + "]"); } for (DataListener tracker : trackers) { @@ -606,7 +617,11 @@ return; } } - DataListener tracker = new DataListener(dependencySymbol, objectCode, addCode, removeCode); + DataListener tracker = new DataListener(dependencySymbol, + objectCode, + addCode, + removeCode + ); if (log.isDebugEnabled()) { log.debug("add tracker " + tracker); } @@ -639,7 +654,11 @@ * @param compiler the current <code>JAXXCompiler</code> * @return Java code snippet which causes the listener to be added to the object */ - public String getAddMemberListenerCode(DefaultObjectHandler handler, String objectCode, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler) { + public String getAddMemberListenerCode(DefaultObjectHandler handler, + String objectCode, + String memberName, + String propertyChangeListenerCode, + JAXXCompiler compiler) { if ("getClass".equals(memberName)) { return null; } @@ -651,20 +670,42 @@ String methodName = "$pr" + compiler.getUniqueId(propertyChangeListenerCode.equals("this") ? constantId : propertyChangeListenerCode); boolean methodExists = hasMethod(methodName); ClassDescriptor eventClass = DefaultObjectHandler.getEventClass(eventInfo.getListenerClass()); + String type = compiler.getImportManager().getType(JAXXCompiler.getCanonicalName(eventClass)); if (!methodExists) { - methods.add(new JavaMethod(Modifier.PUBLIC, "void", methodName, - new JavaArgument[]{new JavaArgument(JAXXCompiler.getCanonicalName(eventClass), "event")}, null, - "propertyChange(null);", false)); + JavaMethod method = JavaElementFactory.newMethod( + Modifier.PUBLIC, + AbstractFinalizer.TYPE_VOID, + methodName, + "propertyChange(null);", + false, + JavaElementFactory.newArgument(type, "event")); + methods.add(method); } String code = objectCode + (eventInfo.getModelName() != null ? ".get" + StringUtils.capitalize(eventInfo.getModelName()) + "()" : ""); result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator()); //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name - result.append(code).append('.').append(eventInfo.getAddMethod()).append("( JAXXUtil.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));"); + ClassDescriptor listenerClass = eventInfo.getListenerClass(); + compiler.addImport(listenerClass.getName()); + result.append(code); + result.append('.'); + result.append(eventInfo.getAddMethod()); + result.append("( JAXXUtil.getEventListener("); + result.append(listenerClass.getSimpleName()); + result.append(".class, "); + result.append("this"); + result.append(", "); + result.append(TypeManager.getJavaCode(methodName)); + result.append("));"); result.append(JAXXCompiler.getLineSeparator()); if (eventInfo.getModelName() != null) { - result.append(getAddMemberListenerCode(handler, objectCode, "get" + StringUtils.capitalize(eventInfo.getModelName()), - JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(" + compiler.getOutputClassName() + ".this" + ", " + constantId + ")", - compiler)); + String addCode = getAddMemberListenerCode( + handler, + objectCode, + "get" + StringUtils.capitalize(eventInfo.getModelName()), + JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(" + compiler.getOutputClassName() + ".this" + ", " + constantId + ")", + compiler + ); + result.append(addCode); } return result.toString(); } @@ -708,7 +749,11 @@ return null; } - public String getRemoveMemberListenerCode(DefaultObjectHandler handler, String objectCode, String memberName, String propertyChangeListenerCode, JAXXCompiler compiler) { + public String getRemoveMemberListenerCode(DefaultObjectHandler handler, + String objectCode, + String memberName, + String propertyChangeListenerCode, + JAXXCompiler compiler) { if ("getClass".equals(memberName)) { return null; } @@ -722,20 +767,38 @@ boolean methodExists = hasMethod(methodName); if (!methodExists) { ClassDescriptor eventClass = DefaultObjectHandler.getEventClass(eventInfo.getListenerClass()); - methods.add(new JavaMethod(Modifier.PUBLIC, "void", methodName, - new JavaArgument[]{new JavaArgument(JAXXCompiler.getCanonicalName(eventClass), "event")}, null, - "propertyChange(null);", false)); + compiler.addImport(eventClass.getName()); + JavaMethod method = JavaElementFactory.newMethod( + Modifier.PUBLIC, + "void", + methodName, + "propertyChange(null);", + false, + JavaElementFactory.newArgument(JAXXCompiler.getCanonicalName(eventClass), "event")); + methods.add(method); } try { String modelMemberName = eventInfo.getModelName() != null ? "get" + StringUtils.capitalize(eventInfo.getModelName()) : null; String modelClassName = modelMemberName != null ? handler.getBeanClass().getMethodDescriptor(modelMemberName).getReturnType().getName() : JAXXCompiler.getCanonicalName(handler.getBeanClass()); + String modelType = compiler.getImportManager().getType(modelClassName); String code = objectCode + (eventInfo.getModelName() != null ? "." + modelMemberName + "()" : ""); String eol = JAXXCompiler.getLineSeparator(); - result.append(modelClassName).append(" $target = ((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\"));").append(eol); + result.append(modelType).append(" $target = (").append(modelType).append(") $bindingSources.remove(\"").append(code).append("\");").append(eol); //TC-20091105 test if $target is not null result.append("if ($target != null) {").append(eol); //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name - result.append(" $target.").append(eventInfo.getRemoveMethod()).append("( JAXXUtil.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol); + ClassDescriptor listenerClass = eventInfo.getListenerClass(); + String listenerType = compiler.getImportManager().getType(listenerClass.getName()); + result.append(" $target."); + result.append(eventInfo.getRemoveMethod()); + result.append("( JAXXUtil.getEventListener("); + result.append(listenerType); + result.append(".class, "); + result.append("this"); + result.append(", "); + result.append(TypeManager.getJavaCode(methodName)); + result.append("));"); + result.append(eol); result.append("}").append(eol); if (eventInfo.getModelName() != null) { result.append(getRemoveMemberListenerCode(handler, objectCode, "get" + StringUtils.capitalize(eventInfo.getModelName()), Deleted: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DefaultJAXXBindingWriter.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DefaultJAXXBindingWriter.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DefaultJAXXBindingWriter.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -1,92 +0,0 @@ -/* - * #%L - * JAXX :: Compiler - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package jaxx.compiler.binding; - -import jaxx.compiler.JAXXCompiler; -import jaxx.compiler.finalizers.DefaultFinalizer; -import jaxx.compiler.java.JavaFileGenerator; -import jaxx.compiler.java.JavaMethod; -import jaxx.runtime.binding.DefaultJAXXBinding; - -import static java.lang.reflect.Modifier.PUBLIC; -import java.util.List; - -/** - * Created: 5 déc. 2009 - * - * @author tchemit <chemit@codelutin.com> - * @version $Revision$ - * <p/> - * Mise a jour: $Date$ par : - * $Author$ - */ -public class DefaultJAXXBindingWriter extends AbstractJAXXBindingWriter<DefaultJAXXBinding> { - - public DefaultJAXXBindingWriter() { - super(DefaultJAXXBinding.class); - } - - @Override - public boolean accept(DataBinding binding) { - return true; - } - - @Override - public void write(DataBinding binding, JavaFileGenerator generator, StringBuilder buffer) { - DataListener[] trackers = binding.getTrackers(); - String eol = JAXXCompiler.getLineSeparator(); - - StringBuilder addBuffer = new StringBuilder(); - StringBuilder removeBuffer = new StringBuilder(); - - for (DataListener tracker : trackers) { - boolean needTest = tracker.getObjectCode() != null; - if (needTest) { - addBuffer.append("if (").append(tracker.getObjectCode()).append(" != null) {").append(eol); - removeBuffer.append("if (").append(tracker.getObjectCode()).append(" != null) {").append(eol); - } - addBuffer.append(JavaFileGenerator.indent(tracker.getAddListenerCode(), needTest ? 4 : 0, false, eol)); - removeBuffer.append(JavaFileGenerator.indent(tracker.getRemoveListenerCode(), needTest ? 4 : 0, false, eol)); - if (needTest) { - addBuffer.append(eol).append("}"); - removeBuffer.append(eol).append("}"); - } - addBuffer.append(eol); - removeBuffer.append(eol); - } - - List<JavaMethod> bMethods = binding.getMethods(); - bMethods.add(0, JavaFileGenerator.newMethod(PUBLIC, DefaultFinalizer.TYPE_VOID, DefaultFinalizer.METHOD_NAME_REMOVE_DATA_BINDING, removeBuffer.toString(), true)); - bMethods.add(0, JavaFileGenerator.newMethod(PUBLIC, DefaultFinalizer.TYPE_VOID, DefaultFinalizer.METHOD_NAME_PROCESS_DATA_BINDING, binding.getProcessDataBinding(), true)); - bMethods.add(0, JavaFileGenerator.newMethod(PUBLIC, DefaultFinalizer.TYPE_VOID, DefaultFinalizer.METHOD_NAME_APPLY_DATA_BINDING, addBuffer.toString(), true)); - - writeInvocationMethod(binding, trackers, generator, buffer, bMethods); - } - - @Override - protected String getConstructorParams(DataBinding binding, DataListener[] trackers) { - return "this, " + binding.getConstantId() + ", true"; - } -} Deleted: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/JAXXBindingWriter.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/JAXXBindingWriter.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/JAXXBindingWriter.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -1,75 +0,0 @@ -/* - * #%L - * JAXX :: Compiler - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package jaxx.compiler.binding; - -import jaxx.compiler.java.JavaFileGenerator; -import jaxx.runtime.JAXXBinding; - -/** - * The contract of a writer of {@link JAXXBinding} creation code from a - * {@link DataBinding}. - * <p/> - * Created: 5 déc. 2009 - * - * @author tchemit <chemit@codelutin.com> - * @version $Revision$ - * <p/> - * Mise a jour: $Date$ par : - * $Author$ - */ -public interface JAXXBindingWriter<B extends JAXXBinding> { - - /** - * Test if a binding can be treated by the writer. - * - * @param binding the binding to test - * @return {@code true} if this writer can be used to generate binding creation code, {@code false} otherwise. - */ - boolean accept(DataBinding binding); - - /** - * Test if the writer was at least used once (says that the method - * {@link #write(DataBinding, JavaFileGenerator, StringBuilder)} was at least invoked once). - * - * @return {@code true} if this writer was used - */ - boolean isUsed(); - - /** - * @return the type of {@link JAXXBinding} to generate - */ - Class<B> getType(); - - /** - * Generate the creation code of the given {@code binding} and push it in the given {@code buffer}. - * <p/> - * Note: after beean in this method, the {@link #isUsed()} should always return {@code true}. - * - * @param binding the binding to use - * @param generator common generator to build creation code - * @param buffer where to push creation code - */ - void write(DataBinding binding, JavaFileGenerator generator, StringBuilder buffer); -} Deleted: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/SimpleJAXXObjectBindingWriter.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/SimpleJAXXObjectBindingWriter.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/SimpleJAXXObjectBindingWriter.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -1,93 +0,0 @@ -/* - * #%L - * JAXX :: Compiler - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package jaxx.compiler.binding; - -import jaxx.compiler.finalizers.DefaultFinalizer; -import jaxx.compiler.java.JavaFileGenerator; -import jaxx.compiler.java.JavaMethod; -import jaxx.runtime.binding.SimpleJAXXObjectBinding; - -import java.lang.reflect.Modifier; -import java.util.List; - -/** - * Created: 5 déc. 2009 - * - * @author tchemit <chemit@codelutin.com> - * @version $Revision$ - * <p/> - * Mise a jour: $Date$ par : - * $Author$ - */ -public class SimpleJAXXObjectBindingWriter extends AbstractJAXXBindingWriter<SimpleJAXXObjectBinding> { - - protected boolean used; - - public SimpleJAXXObjectBindingWriter() { - super(SimpleJAXXObjectBinding.class); - } - - @Override - public boolean accept(DataBinding binding) { - DataListener[] trackers = binding.getTrackers(); - if (trackers.length > 0) { - for (DataListener tracker : trackers) { - if (tracker.getObjectCode() != null) { - // tracker must be without any requirement - return false; - } - } - } - return true; - } - - @Override - protected String getConstructorParams(DataBinding binding, DataListener[] trackers) { - - StringBuilder addBuffer = new StringBuilder(); - addBuffer.append("this, ").append(binding.getConstantId()).append(", true"); - - for (DataListener tracker : trackers) { - String symbol = tracker.getSymbol(); - String propertyName = symbol.substring(symbol.indexOf(".") + 1); - if (JavaParserUtil.getMethodInvocationParameters(propertyName) != null) { - // obtain the property name from the method name - propertyName = JavaParserUtil.getPropertyNameFromMethod(propertyName); - } - addBuffer.append(" ,\"").append(propertyName).append("\""); - } - return addBuffer.toString(); - } - - @Override - public void write(DataBinding binding, JavaFileGenerator generator, StringBuilder buffer) { - DataListener[] trackers = binding.getTrackers(); - List<JavaMethod> bMethods = binding.getMethods(); - - bMethods.add(0, JavaFileGenerator.newMethod(Modifier.PUBLIC, DefaultFinalizer.TYPE_VOID, DefaultFinalizer.METHOD_NAME_PROCESS_DATA_BINDING, binding.getProcessDataBinding(), true)); - - writeInvocationMethod(binding, trackers, generator, buffer, bMethods); - } -} \ No newline at end of file Copied: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/AbstractJAXXBindingWriter.java (from rev 2186, trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/AbstractJAXXBindingWriter.java) =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/AbstractJAXXBindingWriter.java (rev 0) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/AbstractJAXXBindingWriter.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,97 @@ +/* + * #%L + * JAXX :: Compiler + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package jaxx.compiler.binding.writers; + +import jaxx.compiler.JAXXCompiler; +import jaxx.compiler.binding.DataBinding; +import jaxx.compiler.binding.DataListener; +import jaxx.compiler.finalizers.DefaultFinalizer; +import jaxx.compiler.java.JavaFileGenerator; +import jaxx.compiler.java.JavaMethod; +import jaxx.runtime.JAXXBinding; + +import java.util.List; + +/** + * Created: 5 déc. 2009 + * + * @author tchemit <chemit@codelutin.com> + * @version $Id$ + */ +public abstract class AbstractJAXXBindingWriter<B extends JAXXBinding> implements JAXXBindingWriter<B> { + + private final Class<B> type; + + protected boolean used; + + protected AbstractJAXXBindingWriter(Class<B> type) { + this.type = type; + } + + @Override + public boolean isUsed() { + return used; + } + + @Override + public Class<B> getType() { + return type; + } + + @Override + public void reset() { + used = false; + } + + protected abstract String getConstructorParams(DataBinding binding, + DataListener[] trackers); + + protected void writeInvocationMethod(DataBinding binding, + DataListener[] trackers, + JavaFileGenerator generator, + StringBuilder buffer, + List<JavaMethod> bMethods) { + used = true; + String eol = JAXXCompiler.getLineSeparator(); + buffer.append(DefaultFinalizer.METHOD_NAME_REGISTER_DATA_BINDING); + buffer.append("(new "); + buffer.append(getType().getSimpleName()); + buffer.append("("); + buffer.append(getConstructorParams(binding, trackers)); + buffer.append(") {"); + buffer.append(eol); + for (JavaMethod m : bMethods) { + buffer.append(eol); + String source = generator.generateMethod(m); + buffer.append(JavaFileGenerator.indent(source, 4, false, eol)); + buffer.append(eol); + } + buffer.append("});").append(eol); + + if (binding.getInitDataBinding() != null) { + buffer.append(binding.getInitDataBinding()); + } + } +} \ No newline at end of file Property changes on: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/AbstractJAXXBindingWriter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Copied: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/DefaultJAXXBindingWriter.java (from rev 2186, trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DefaultJAXXBindingWriter.java) =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/DefaultJAXXBindingWriter.java (rev 0) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/DefaultJAXXBindingWriter.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,128 @@ +/* + * #%L + * JAXX :: Compiler + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package jaxx.compiler.binding.writers; + +import jaxx.compiler.JAXXCompiler; +import jaxx.compiler.binding.DataBinding; +import jaxx.compiler.binding.DataListener; +import jaxx.compiler.finalizers.AbstractFinalizer; +import jaxx.compiler.finalizers.DefaultFinalizer; +import jaxx.compiler.java.JavaElementFactory; +import jaxx.compiler.java.JavaFileGenerator; +import jaxx.compiler.java.JavaMethod; +import jaxx.runtime.binding.DefaultJAXXBinding; + +import java.util.List; + +import static java.lang.reflect.Modifier.PUBLIC; + +/** + * Created: 5 déc. 2009 + * + * @author tchemit <chemit@codelutin.com> + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author$ + */ +public class DefaultJAXXBindingWriter extends AbstractJAXXBindingWriter<DefaultJAXXBinding> { + + public DefaultJAXXBindingWriter() { + super(DefaultJAXXBinding.class); + } + + @Override + public boolean accept(DataBinding binding) { + return true; + } + + @Override + public void write(DataBinding binding, + JavaFileGenerator generator, + StringBuilder buffer) { + DataListener[] trackers = binding.getTrackers(); + String eol = JAXXCompiler.getLineSeparator(); + + StringBuilder addBuffer = new StringBuilder(); + StringBuilder removeBuffer = new StringBuilder(); + + for (DataListener tracker : trackers) { + boolean needTest = tracker.getObjectCode() != null; + if (needTest) { + addBuffer.append("if ("); + addBuffer.append(tracker.getObjectCode()); + addBuffer.append(" != null) {"); + addBuffer.append(eol); + + removeBuffer.append("if ("); + removeBuffer.append(tracker.getObjectCode()); + removeBuffer.append(" != null) {"); + removeBuffer.append(eol); + } + int indentLevel = needTest?4:0; + addBuffer.append(JavaFileGenerator.indent( + tracker.getAddListenerCode(), indentLevel, false, eol)); + removeBuffer.append(JavaFileGenerator.indent( + tracker.getRemoveListenerCode(), indentLevel, false, eol)); + if (needTest) { + addBuffer.append(eol).append("}"); + removeBuffer.append(eol).append("}"); + } + addBuffer.append(eol); + removeBuffer.append(eol); + } + + List<JavaMethod> bMethods = binding.getMethods(); + bMethods.add(0, JavaElementFactory.newMethod( + PUBLIC, + AbstractFinalizer.TYPE_VOID, + DefaultFinalizer.METHOD_NAME_REMOVE_DATA_BINDING, + removeBuffer.toString(), + true) + ); + bMethods.add(0, JavaElementFactory.newMethod( + PUBLIC, + AbstractFinalizer.TYPE_VOID, + DefaultFinalizer.METHOD_NAME_PROCESS_DATA_BINDING, + binding.getProcessDataBinding(), + true) + ); + bMethods.add(0, JavaElementFactory.newMethod( + PUBLIC, + AbstractFinalizer.TYPE_VOID, + DefaultFinalizer.METHOD_NAME_APPLY_DATA_BINDING, + addBuffer.toString(), + true) + ); + + writeInvocationMethod(binding, trackers, generator, buffer, bMethods); + } + + @Override + protected String getConstructorParams(DataBinding binding, + DataListener[] trackers) { + return "this, " + binding.getConstantId() + ", true"; + } +} Property changes on: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/DefaultJAXXBindingWriter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Copied: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/JAXXBindingWriter.java (from rev 2186, trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/JAXXBindingWriter.java) =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/JAXXBindingWriter.java (rev 0) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/JAXXBindingWriter.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,87 @@ +/* + * #%L + * JAXX :: Compiler + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package jaxx.compiler.binding.writers; + +import jaxx.compiler.binding.DataBinding; +import jaxx.compiler.java.JavaFileGenerator; +import jaxx.runtime.JAXXBinding; + +/** + * The contract of a writer of {@link JAXXBinding} creation code from a + * {@link DataBinding}. + * <p/> + * Created: 5 déc. 2009 + * + * @author tchemit <chemit@codelutin.com> + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author$ + */ +public interface JAXXBindingWriter<B extends JAXXBinding> { + + /** + * Test if a binding can be treated by the writer. + * + * @param binding the binding to test + * @return {@code true} if this writer can be used to generate binding creation code, {@code false} otherwise. + */ + boolean accept(DataBinding binding); + + /** + * Test if the writer was at least used once (says that the method + * {@link #write(DataBinding, JavaFileGenerator, StringBuilder)} was at least invoked once). + * + * @return {@code true} if this writer was used + */ + boolean isUsed(); + + /** @return the type of {@link JAXXBinding} to generate */ + Class<B> getType(); + + /** + * Generate the creation code of the given {@code binding} and push it in the given {@code buffer}. + * <p/> + * Note: after beean in this method, the {@link #isUsed()} should always return {@code true}. + * + * @param binding the binding to use + * @param generator common generator to build creation code + * @param buffer where to push creation code + */ + void write(DataBinding binding, + JavaFileGenerator generator, + StringBuilder buffer); + + /** + * Reset internal states. + * <p/> + * At the moment, there is only the {@code used} property which is + * internal and must be reset to {@code false} for each compiler in order + * to know if a type of writer is used for the file. + * + * @since 2.4 + */ + void reset(); +} Property changes on: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/JAXXBindingWriter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Copied: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/SimpleJAXXObjectBindingWriter.java (from rev 2186, trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/SimpleJAXXObjectBindingWriter.java) =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/SimpleJAXXObjectBindingWriter.java (rev 0) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/SimpleJAXXObjectBindingWriter.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,111 @@ +/* + * #%L + * JAXX :: Compiler + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package jaxx.compiler.binding.writers; + +import jaxx.compiler.binding.DataBinding; +import jaxx.compiler.binding.DataListener; +import jaxx.compiler.binding.JavaParserUtil; +import jaxx.compiler.finalizers.AbstractFinalizer; +import jaxx.compiler.finalizers.DefaultFinalizer; +import jaxx.compiler.java.JavaElementFactory; +import jaxx.compiler.java.JavaFileGenerator; +import jaxx.compiler.java.JavaMethod; +import jaxx.runtime.binding.SimpleJAXXObjectBinding; + +import java.lang.reflect.Modifier; +import java.util.List; + +/** + * Created: 5 déc. 2009 + * + * @author tchemit <chemit@codelutin.com> + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author$ + */ +public class SimpleJAXXObjectBindingWriter extends AbstractJAXXBindingWriter<SimpleJAXXObjectBinding> { + + protected boolean used; + + public SimpleJAXXObjectBindingWriter() { + super(SimpleJAXXObjectBinding.class); + } + + @Override + public boolean accept(DataBinding binding) { + DataListener[] trackers = binding.getTrackers(); + if (trackers.length > 0) { + for (DataListener tracker : trackers) { + if (tracker.getObjectCode() != null) { + // tracker must be without any requirement + return false; + } + } + } + return true; + } + + @Override + protected String getConstructorParams(DataBinding binding, + DataListener[] trackers) { + + StringBuilder addBuffer = new StringBuilder(); + addBuffer.append("this, "); + addBuffer.append(binding.getConstantId()); + addBuffer.append(", true"); + + for (DataListener tracker : trackers) { + String symbol = tracker.getSymbol(); + String name = symbol.substring(symbol.indexOf(".") + 1); + if (JavaParserUtil.getMethodInvocationParameters(name) != null) { + // obtain the property name from the method name + name = JavaParserUtil.getPropertyNameFromMethod(name); + } + addBuffer.append(" ,\"").append(name).append("\""); + } + return addBuffer.toString(); + } + + @Override + public void write(DataBinding binding, + JavaFileGenerator generator, + StringBuilder buffer) { + DataListener[] trackers = binding.getTrackers(); + List<JavaMethod> bMethods = binding.getMethods(); + + JavaMethod method = JavaElementFactory.newMethod( + Modifier.PUBLIC, + AbstractFinalizer.TYPE_VOID, + DefaultFinalizer.METHOD_NAME_PROCESS_DATA_BINDING, + binding.getProcessDataBinding(), + true + ); + + bMethods.add(0, method); + + writeInvocationMethod(binding, trackers, generator, buffer, bMethods); + } +} \ No newline at end of file Property changes on: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/SimpleJAXXObjectBindingWriter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/css/StylesheetHelper.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/css/StylesheetHelper.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/css/StylesheetHelper.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -41,6 +41,7 @@ import jaxx.compiler.tags.DefaultObjectHandler; import jaxx.compiler.tags.TagManager; import jaxx.compiler.types.TypeManager; +import jaxx.runtime.css.Pseudoclasses; import jaxx.runtime.css.Rule; import jaxx.runtime.css.Selector; import jaxx.runtime.css.Stylesheet; @@ -296,28 +297,28 @@ public static String unwrap(ClassDescriptor type, String valueCode) { if (ClassDescriptorHelper.getClassDescriptor(boolean.class).equals(type)) { - return "((java.lang.Boolean) " + valueCode + ").booleanValue()"; + return "((Boolean) " + valueCode + ").booleanValue()"; } if (ClassDescriptorHelper.getClassDescriptor(byte.class).equals(type)) { - return "((java.lang.Byte) " + valueCode + ").byteValue()"; + return "((Byte) " + valueCode + ").byteValue()"; } if (ClassDescriptorHelper.getClassDescriptor(short.class).equals(type)) { - return "((java.lang.Short) " + valueCode + ").shortValue()"; + return "((Short) " + valueCode + ").shortValue()"; } if (ClassDescriptorHelper.getClassDescriptor(int.class).equals(type)) { - return "((java.lang.Integer) " + valueCode + ").intValue()"; + return "((Integer) " + valueCode + ").intValue()"; } if (ClassDescriptorHelper.getClassDescriptor(long.class).equals(type)) { - return "((java.lang.Long) " + valueCode + ").longValue()"; + return "((Long) " + valueCode + ").longValue()"; } if (ClassDescriptorHelper.getClassDescriptor(float.class).equals(type)) { - return "((java.lang.Float) " + valueCode + ").floatValue()"; + return "((Float) " + valueCode + ").floatValue()"; } if (ClassDescriptorHelper.getClassDescriptor(double.class).equals(type)) { - return "((java.lang.Double) " + valueCode + ").doubleValue()"; + return "((Double) " + valueCode + ").doubleValue()"; } if (ClassDescriptorHelper.getClassDescriptor(char.class).equals(type)) { - return "((java.lang.Character) " + valueCode + ").charValue()"; + return "((Character) " + valueCode + ").charValue()"; } return valueCode; } @@ -356,6 +357,14 @@ boolean valueDeclared = false; String eol = JAXXCompiler.getLineSeparator(); DataBindingHelper bindingHelper = compiler.getBindingHelper(); + + if (!properties.isEmpty()) { + compiler.getImportManager().addImport(Pseudoclasses.class); + compiler.getImportManager().addImport(jaxx.runtime.css.DataBinding.class); + } + + String outputClassName = compiler.getImportManager().getType(compiler.getOutputClassName()); + for (Map.Entry<String, String> e : properties.entrySet()) { String property = e.getKey(); ClassDescriptor type = handler.getPropertyType(object, @@ -371,7 +380,7 @@ String valueCode; if (dataBindingCode != null) { String code = object.getId() + "." + property + "." + priority; - valueCode = "new jaxx.runtime.css.DataBinding(" + + valueCode = "new " + jaxx.runtime.css.DataBinding.class.getSimpleName() + "(" + TypeManager.getJavaCode(code) + ")"; DataBinding binding = new DataBinding( code, @@ -403,13 +412,39 @@ } } if (!valueDeclared) { - buffer.append("java.lang.Object "); + buffer.append("Object "); valueDeclared = true; } - buffer.append("value = jaxx.runtime.css.Pseudoclasses.applyProperty(").append(compiler.getOutputClassName()).append(".this, ").append(object.getJavaCode()).append(", ").append(TypeManager.getJavaCode(property)).append(", ").append(valueCode).append(", jaxx.runtime.css.Pseudoclasses.wrap(").append(handler.getGetPropertyCode(object.getJavaCode(), property, compiler)).append("), ").append(priority).append(");").append(eol); - buffer.append("if (!(value instanceof jaxx.runtime.css.DataBinding)) {").append(eol); + + buffer.append("value = "); + buffer.append(Pseudoclasses.class.getSimpleName()); + buffer.append(".applyProperty("); + buffer.append(outputClassName); + buffer.append(".this, "); + buffer.append(object.getJavaCode()); + buffer.append(", "); + buffer.append(TypeManager.getJavaCode(property)); + buffer.append(", "); + buffer.append(valueCode); + buffer.append(", "); + buffer.append(Pseudoclasses.class.getSimpleName()); + buffer.append(".wrap("); + buffer.append(handler.getGetPropertyCode(object.getJavaCode(), property, compiler)); + buffer.append("), "); + buffer.append(priority); + buffer.append(");"); + buffer.append(eol); + + buffer.append("if (!(value instanceof "); + buffer.append(jaxx.runtime.css.DataBinding.class.getSimpleName()); + buffer.append(")) {"); + buffer.append(eol); + + String simpleType = compiler.getImportManager().getType(JAXXCompiler.getCanonicalName(type)); String unwrappedValue = unwrap(type, "value"); - buffer.append(" ").append(handler.getSetPropertyCode(object.getJavaCode(), property, "(" + JAXXCompiler.getCanonicalName(type) + ") " + unwrappedValue, compiler)).append(eol); + buffer.append(" "); + buffer.append(handler.getSetPropertyCode(object.getJavaCode(), property, "(" + simpleType + ") " + unwrappedValue, compiler)); + buffer.append(eol); buffer.append("}").append(eol); } @@ -435,7 +470,7 @@ String valueCode; if (dataBindingCode != null) { String code = object.getId() + "." + property + "." + priority; - valueCode = "new jaxx.runtime.css.DataBinding(" + TypeManager.getJavaCode(code) + ")"; + valueCode = "new " + jaxx.runtime.css.DataBinding.class.getSimpleName() + "(" + TypeManager.getJavaCode(code) + ")"; DataBinding binding = new DataBinding( code, dataBindingCode, @@ -458,18 +493,19 @@ } } if (!valueDeclared) { - buffer.append("java.lang.Object "); + buffer.append("Object "); valueDeclared = true; } - buffer.append("value = jaxx.runtime.css.Pseudoclasses.removeProperty("); - buffer.append(compiler.getOutputClassName()); + buffer.append("value = ").append(Pseudoclasses.class.getSimpleName()).append(".removeProperty("); + + buffer.append(outputClassName); buffer.append(".this, "); buffer.append(object.getJavaCode()); buffer.append(", "); buffer.append(TypeManager.getJavaCode(property)); buffer.append(", "); buffer.append(valueCode); - buffer.append(", jaxx.runtime.css.Pseudoclasses.wrap("); + buffer.append(", ").append(Pseudoclasses.class.getSimpleName()).append(".wrap("); buffer.append(handler.getGetPropertyCode(object.getJavaCode(), property, compiler) @@ -478,14 +514,19 @@ buffer.append(priority); buffer.append(");"); buffer.append(eol); - buffer.append("if (!(value instanceof jaxx.runtime.css.DataBinding)) {"); + + buffer.append("if (!(value instanceof "); + buffer.append(jaxx.runtime.css.DataBinding.class.getSimpleName()); + buffer.append(")) {"); buffer.append(eol); + + String simpleType = compiler.getImportManager().getType(JAXXCompiler.getCanonicalName(type)); String unwrappedValue = unwrap(type, "value"); buffer.append(" "); buffer.append(handler.getSetPropertyCode( object.getJavaCode(), property, - "(" + JAXXCompiler.getCanonicalName(type) + ") " + unwrappedValue, + "(" + simpleType + ") " + unwrappedValue, compiler) ); buffer.append(eol); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -29,9 +29,9 @@ import jaxx.compiler.CompiledObjectDecorator; import jaxx.compiler.CompilerException; import jaxx.compiler.JAXXCompiler; +import jaxx.compiler.java.JavaElementFactory; import jaxx.compiler.java.JavaField; import jaxx.compiler.java.JavaFile; -import jaxx.compiler.java.JavaFileGenerator; import jaxx.compiler.java.JavaMethod; import jaxx.compiler.script.ScriptInitializer; import jaxx.compiler.types.TypeManager; @@ -98,7 +98,7 @@ if (log.isDebugEnabled()) { log.debug("Add specialized getter " + methodName + " : " + body); } - JavaMethod getter = JavaFileGenerator.newMethod( + JavaMethod getter = JavaElementFactory.newMethod( Modifier.PUBLIC, fqn, methodName, @@ -112,19 +112,19 @@ int access = id.startsWith("$") ? Modifier.PRIVATE : Modifier.PROTECTED; if (root.equals(object)) { - JavaField field = JavaFileGenerator.newField(access, - className, - id, - false, - "this" + JavaField field = JavaElementFactory.newField(access, + className, + id, + false, + "this" ); javaFile.addSimpleField(field); } else { - JavaField field = JavaFileGenerator.newField(access, - fqn, - id, - override + JavaField field = JavaElementFactory.newField(access, + fqn, + id, + override ); javaFile.addField(field, object.isJavaBean()); } @@ -142,7 +142,7 @@ if (code != null) { - JavaMethod javaMethod = JavaFileGenerator.newMethod( + JavaMethod javaMethod = JavaElementFactory.newMethod( Modifier.PROTECTED, "void", object.getCreationMethodName(), @@ -272,7 +272,7 @@ code.append(object.getAdditionMethodName()).append("();").append(eol); additionCode = "if (!allComponentsCreated) {" + eol + " return;" + eol + "}" + eol + additionCode; - javaFile.addMethod(JavaFileGenerator.newMethod( + javaFile.addMethod(JavaElementFactory.newMethod( Modifier.PROTECTED, "void", object.getAdditionMethodName(), Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -28,9 +28,8 @@ import jaxx.compiler.CompiledObject; import jaxx.compiler.CompilerConfiguration; import jaxx.compiler.JAXXCompiler; -import jaxx.compiler.java.JavaArgument; +import jaxx.compiler.java.JavaElementFactory; import jaxx.compiler.java.JavaFile; -import jaxx.compiler.java.JavaFileGenerator; import jaxx.runtime.swing.help.JAXXHelpUI; import java.lang.reflect.Modifier; @@ -38,6 +37,8 @@ import java.util.Iterator; import java.util.Set; +import static jaxx.compiler.java.JavaElementFactory.newArgument; + /** * A decorator to place on a root compiled object to process javaHelp on the file. * @@ -82,8 +83,7 @@ javaFile, packageName, className, - fullClassName - ) + fullClassName) ; CompilerConfiguration options = compiler.getConfiguration(); @@ -96,24 +96,24 @@ JAXXCompiler.getCanonicalName(validatorInterface) + "<" + helpBrokerFQN + ">"); - javaFile.addMethod(JavaFileGenerator.newMethod( + javaFile.addMethod(JavaElementFactory.newMethod( Modifier.PUBLIC, "void", "registerHelpId", "broker.installUI(component, helpId);", true, - new JavaArgument(helpBrokerFQN, "broker"), - new JavaArgument("Component", "component"), - new JavaArgument("String", "helpId")) + newArgument(helpBrokerFQN, "broker"), + newArgument("java.awt.Component", "component"), + newArgument("String", "helpId")) ); - javaFile.addMethod(JavaFileGenerator.newMethod( + javaFile.addMethod(JavaElementFactory.newMethod( Modifier.PUBLIC, "void", "showHelp", "getBroker().showHelp(this, helpId);", true, - new JavaArgument("String", "helpId")) + newArgument("String", "helpId")) ); StringBuilder buffer = new StringBuilder(); Added: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/AbstractFinalizer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/AbstractFinalizer.java (rev 0) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/AbstractFinalizer.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,68 @@ +package jaxx.compiler.finalizers; + +import jaxx.compiler.java.JavaElementFactory; +import jaxx.compiler.java.JavaField; +import jaxx.compiler.java.JavaFile; +import jaxx.compiler.java.JavaMethod; + +/** + * Base implementation of a {@link JAXXCompilerFinalizer}. + * <p/> + * Contains commons methods and constants. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.4 + */ +public abstract class AbstractFinalizer implements JAXXCompilerFinalizer { + + public static final String TYPE_STRING = "String"; + + public static final String TYPE_VOID = "void"; + + public static final String TYPE_BOOLEAN = "boolean"; + + public static final String TYPE_OBJECT = "Object"; + + /** + * Clones the given {@code field} and adds it to the {@code file} as a + * property via the method {@link JavaFile#addField(JavaField)}. + * + * @param file the file where to add the cloned field + * @param field the field to clone + * @since 2.4 + */ + protected void addField(JavaFile file, JavaField field) { + + JavaField clonedField = JavaElementFactory.cloneField(field); + file.addField(clonedField); + } + + /** + * Clones the given {@code method} and adds it to the {@code file} as a + * simple method using the method {@link JavaFile#addMethod(JavaMethod)}. + * + * @param file the file where to add the cloned field + * @param field the field to clone + * @since 2.4 + */ + protected void addSimpleField(JavaFile file, JavaField field) { + + JavaField clonedField = JavaElementFactory.cloneField(field); + file.addSimpleField(clonedField); + } + + /** + * Clones the given {@code field} and adds it to the {@code file} as a + * simple field using the method {@link JavaFile#addSimpleField(JavaField)}. + * + * @param file the file where to add the cloned method + * @param method the method to clone + * @since 2.4 + */ + protected void addMethod(JavaFile file, JavaMethod method) { + + JavaMethod clonedMethod = JavaElementFactory.cloneMethod(method); + file.addMethod(clonedMethod); + } + +} Property changes on: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/AbstractFinalizer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,31 +25,55 @@ package jaxx.compiler.finalizers; -import jaxx.compiler.*; +import jaxx.compiler.CompiledObject; +import jaxx.compiler.CompiledObjectDecorator; +import jaxx.compiler.CompilerException; +import jaxx.compiler.EventHandler; +import jaxx.compiler.JAXXCompiler; import jaxx.compiler.binding.DataBinding; -import jaxx.compiler.binding.DefaultJAXXBindingWriter; -import jaxx.compiler.binding.JAXXBindingWriter; -import jaxx.compiler.binding.SimpleJAXXObjectBindingWriter; -import jaxx.compiler.java.*; -import static jaxx.compiler.java.JavaFileGenerator.newField; -import static jaxx.compiler.java.JavaFileGenerator.newMethod; +import jaxx.compiler.binding.writers.DefaultJAXXBindingWriter; +import jaxx.compiler.binding.writers.JAXXBindingWriter; +import jaxx.compiler.binding.writers.SimpleJAXXObjectBindingWriter; +import jaxx.compiler.java.JavaArgument; +import jaxx.compiler.java.JavaElementFactory; +import jaxx.compiler.java.JavaField; +import jaxx.compiler.java.JavaFile; +import jaxx.compiler.java.JavaFileGenerator; +import jaxx.compiler.java.JavaMethod; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.compiler.reflect.FieldDescriptor; import jaxx.compiler.reflect.MethodDescriptor; import jaxx.compiler.types.TypeManager; -import jaxx.runtime.*; +import jaxx.runtime.Base64Coder; +import jaxx.runtime.JAXXBinding; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.JAXXObjectDescriptor; +import jaxx.runtime.JAXXUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.java.extension.ImportsManager; +import java.awt.Container; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.IOException; -import static java.lang.reflect.Modifier.*; import java.util.Iterator; import java.util.List; import java.util.Map; +import static java.lang.reflect.Modifier.FINAL; +import static java.lang.reflect.Modifier.PRIVATE; +import static java.lang.reflect.Modifier.PROTECTED; +import static java.lang.reflect.Modifier.PUBLIC; +import static java.lang.reflect.Modifier.STATIC; +import static java.lang.reflect.Modifier.isProtected; +import static java.lang.reflect.Modifier.isPublic; +import static jaxx.compiler.java.JavaElementFactory.newArgument; +import static jaxx.compiler.java.JavaElementFactory.newField; +import static jaxx.compiler.java.JavaElementFactory.newMethod; + /** * This class is a refactoring of the {@link JAXXCompiler}. * <p/> @@ -57,220 +81,405 @@ * {@link JAXXCompiler} now only deals with the compilation of files. * * @author tchemit <chemit@codelutin.com> - * @plexus.component role-hint="default" role="jaxx.compiler.JAXXCompilerFinalizer" + * @plexus.component role-hint="default" role="jaxx.compiler.finalizers.JAXXCompilerFinalizer" */ -public class DefaultFinalizer implements JAXXCompilerFinalizer { +public class DefaultFinalizer extends AbstractFinalizer { - /** - * Logger - */ + /** Logger. */ protected static final Log log = LogFactory.getLog(DefaultFinalizer.class); private static final String PARAMETER_NAME_$BINDING = "$binding"; public static final String FIELD_NAME_$BINDING_SOURCES = "$bindingSources"; + public static final String FIELD_NAME_$OBJECT_MAP = "$objectMap"; + public static final String FIELD_NAME_$ACTIVE_BINDINGS = "$activeBindings"; + public static final String FIELD_NAME_ALL_COMPONENTS_CREATED = "allComponentsCreated"; + public static final String FIELD_NAME_CONTEXT_INITIALIZED = "contextInitialized"; + public static final String FIELD_NAME_$PREVIOUS_VALUES = "$previousValues"; + public static final String FIELD_NAME_$BINDINGS = "$bindings"; + public static final String FIELD_NAME_$PROPERTY_CHANGE_SUPPORT = "$propertyChangeSupport"; + public static final String FIELD_NAME_DELEGATE_CONTEXT = "delegateContext"; + public static final String FIELD_NAME_SERIAL_VERSION_UID = "serialVersionUID"; + public static final String FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR = "$jaxxObjectDescriptor"; public static final String METHOD_NAME_$GET_JAXXOBJECT_DESCRIPTOR = "$getJAXXObjectDescriptor"; + public static final String METHOD_NAME_$REGISTER_DEFAULT_BINDINGS = "$registerDefaultBindings"; + public static final String METHOD_NAME_REGISTER_DATA_BINDING = "registerDataBinding"; + public static final String METHOD_NAME_REMOVE_DATA_BINDING = "removeDataBinding"; + public static final String METHOD_NAME_APPLY_DATA_BINDING = "applyDataBinding"; + public static final String METHOD_NAME_PROCESS_DATA_BINDING = "processDataBinding"; + public static final String METHOD_NAME_FIRE_PROPERTY_CHANGE = "firePropertyChange"; + public static final String METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT = "$getPropertyChangeSupport"; + public static final String METHOD_NAME_$INITIALIZE = "$initialize"; + public static final String METHOD_NAME_$COMPLETE_SETUP = "$completeSetup"; + public static final String METHOD_NAME_$AFTER_COMPLETE_SETUP = "$afterCompleteSetup"; - public static final String TYPE_STRING = "String"; - public static final String TYPE_VOID = "void"; - public static final String TYPE_BOOLEAN = "boolean"; - public static final String TYPE_OBJECT = "Object"; + /** serialVersionUID field */ + protected static final JavaField SERIAL_VERSION_UID_FIELD = newField( + PRIVATE | STATIC | FINAL, + "long", + FIELD_NAME_SERIAL_VERSION_UID, + false, + "1L" + ); + /** - * serialVersionUID field - */ - protected static final JavaField SERIAL_VERSION_UID_FIELD = newField(PRIVATE | STATIC | FINAL, - "long", FIELD_NAME_SERIAL_VERSION_UID, false, "1L"); - /** * */ - protected static final JavaField ACTIVE_BINDINGS_FIELD = newField(PROTECTED, - "java.util.List<" + TYPE_OBJECT + ">", FIELD_NAME_$ACTIVE_BINDINGS, false, "new ArrayList<" + TYPE_OBJECT + ">()"); + protected static final JavaField ACTIVE_BINDINGS_FIELD = newField( + PROTECTED, + "java.util.List<" + TYPE_OBJECT + ">", + FIELD_NAME_$ACTIVE_BINDINGS, + false, + "new java.util.ArrayList<" + TYPE_OBJECT + ">()" + ); + /** * */ - protected static final JavaField BINDING_SOURCES_FIELD = newField(PROTECTED, - "Map<" + TYPE_STRING + ", " + TYPE_OBJECT + ">", FIELD_NAME_$BINDING_SOURCES, false, "new HashMap<" + TYPE_STRING + ", " + TYPE_OBJECT + ">()"); + protected static final JavaField BINDING_SOURCES_FIELD = newField( + PROTECTED, + "java.util.Map<" + TYPE_STRING + ", " + TYPE_OBJECT + ">", + FIELD_NAME_$BINDING_SOURCES, + false, + "new java.util.HashMap<" + TYPE_STRING + ", " + TYPE_OBJECT + ">()" + ); + /** * */ - protected static final JavaField OBJECT_MAP_FIELD = newField(PROTECTED, - "Map<" + TYPE_STRING + ", " + TYPE_OBJECT + ">", FIELD_NAME_$OBJECT_MAP, true, "new HashMap<" + TYPE_STRING + ", " + TYPE_OBJECT + ">()"); + protected static final JavaField OBJECT_MAP_FIELD = newField( + PROTECTED, + "java.util.Map<" + TYPE_STRING + ", " + TYPE_OBJECT + ">", + FIELD_NAME_$OBJECT_MAP, + true, + "new java.util.HashMap<" + TYPE_STRING + ", " + TYPE_OBJECT + ">()" + ); + /** * */ - protected static final JavaField ALL_COMPONENTS_CREATED_FIELD = newField(PRIVATE, - TYPE_BOOLEAN, FIELD_NAME_ALL_COMPONENTS_CREATED, false); + protected static final JavaField ALL_COMPONENTS_CREATED_FIELD = newField( + PRIVATE, + TYPE_BOOLEAN, + FIELD_NAME_ALL_COMPONENTS_CREATED, + false + ); + /** * */ - protected static final JavaField CONTEXT_INITIALIZED = newField(PRIVATE, - TYPE_BOOLEAN, FIELD_NAME_CONTEXT_INITIALIZED, false, "true"); + protected static final JavaField CONTEXT_INITIALIZED = newField( + PRIVATE, + TYPE_BOOLEAN, + FIELD_NAME_CONTEXT_INITIALIZED, + false, + "true" + ); + /** * */ - protected static final JavaField PREVIOUS_VALUES_FIELD = newField(PROTECTED, - "Map<?,?>", FIELD_NAME_$PREVIOUS_VALUES, false, "new java.util.HashMap<" + TYPE_OBJECT + ", " + TYPE_OBJECT + ">()"); + protected static final JavaField PREVIOUS_VALUES_FIELD = newField( + PROTECTED, + "java.util.Map<?,?>", FIELD_NAME_$PREVIOUS_VALUES, + false, + "new java.util.HashMap<" + TYPE_OBJECT + ", " + TYPE_OBJECT + ">()" + ); + /** * */ - protected static final JavaField BINDINGS_FIELD = newField(PROTECTED | FINAL, - "Map<" + TYPE_STRING + ", JAXXBinding>", FIELD_NAME_$BINDINGS, false, "new java.util.TreeMap<" + TYPE_STRING + ", JAXXBinding>()"); + protected static final JavaField BINDINGS_FIELD = newField( + PROTECTED | FINAL, + "java.util.Map<" + TYPE_STRING + ", " + JAXXBinding.class.getName() + ">", + FIELD_NAME_$BINDINGS, + false, + "new java.util.TreeMap<" + TYPE_STRING + ", JAXXBinding>()" + ); + /** * */ - protected static final JavaField PROPERTY_CHANGE_SUPPORT_FIELD = newField(PROTECTED, - "PropertyChangeSupport", FIELD_NAME_$PROPERTY_CHANGE_SUPPORT, false); + protected static final JavaField PROPERTY_CHANGE_SUPPORT_FIELD = newField( + PROTECTED, + PropertyChangeSupport.class.getName(), + FIELD_NAME_$PROPERTY_CHANGE_SUPPORT, + false + ); + /** * */ - protected static final JavaMethod GET_CONTEXT_VALUE_METHOD = newMethod(PUBLIC, "<T> T", "getContextValue", - "return " + FIELD_NAME_DELEGATE_CONTEXT + ".getContextValue(clazz, null);", true, - new JavaArgument("Class<T>", "clazz")); + protected static final JavaMethod GET_CONTEXT_VALUE_METHOD = newMethod( + PUBLIC, + "<T> T", + "getContextValue", + "return " + FIELD_NAME_DELEGATE_CONTEXT + ".getContextValue(clazz, null);", + true, + newArgument("Class<T>", "clazz") + ); + /** * */ - protected static final JavaMethod GET_CONTEXT_VALUE_NAMED_METHOD = newMethod(PUBLIC, "<T> T", "getContextValue", - "return " + FIELD_NAME_DELEGATE_CONTEXT + ".getContextValue(clazz, name);", true, - new JavaArgument("Class<T>", "clazz"), new JavaArgument(TYPE_STRING, "name")); + protected static final JavaMethod GET_CONTEXT_VALUE_NAMED_METHOD = newMethod( + PUBLIC, + "<T> T", + "getContextValue", + "return " + FIELD_NAME_DELEGATE_CONTEXT + ".getContextValue(clazz, name);", + true, + newArgument("Class<T>", "clazz"), newArgument(TYPE_STRING, "name") + ); + /** * */ - protected static final JavaMethod SET_CONTEXT_VALUE_NAMED_METHOD = newMethod(PUBLIC, "<T> " + TYPE_VOID, "setContextValue", - FIELD_NAME_DELEGATE_CONTEXT + ".setContextValue(o, name);", true, - new JavaArgument("T", "o"), new JavaArgument(TYPE_STRING, "name")); + protected static final JavaMethod SET_CONTEXT_VALUE_NAMED_METHOD = newMethod( + PUBLIC, + "<T> " + TYPE_VOID, + "setContextValue", + FIELD_NAME_DELEGATE_CONTEXT + ".setContextValue(o, name);", + true, + newArgument("T", "o"), newArgument(TYPE_STRING, "name")); + /** * */ - protected static final JavaMethod SET_CONTEXT_VALUE_METHOD = newMethod(PUBLIC, "<T> " + TYPE_VOID, "setContextValue", - FIELD_NAME_DELEGATE_CONTEXT + ".setContextValue(o, null);", true, - new JavaArgument("T", "o")); + protected static final JavaMethod SET_CONTEXT_VALUE_METHOD = newMethod( + PUBLIC, + "<T> " + TYPE_VOID, + "setContextValue", + FIELD_NAME_DELEGATE_CONTEXT + ".setContextValue(o, null);", + true, + newArgument("T", "o") + ); + /** * */ - protected static final JavaMethod REMOVE_CONTEXT_VALUE_NAMED_METHOD = newMethod(PUBLIC, "<T> " + TYPE_VOID, "removeContextValue", - FIELD_NAME_DELEGATE_CONTEXT + ".removeContextValue(clazz, name);", true, - new JavaArgument("Class<T>", "clazz"), new JavaArgument(TYPE_STRING, "name")); + protected static final JavaMethod REMOVE_CONTEXT_VALUE_NAMED_METHOD = newMethod( + PUBLIC, + "<T> " + TYPE_VOID, + "removeContextValue", + FIELD_NAME_DELEGATE_CONTEXT + ".removeContextValue(clazz, name);", + true, + newArgument("Class<T>", "clazz"), + newArgument(TYPE_STRING, "name") + ); + /** * */ - protected static final JavaMethod REMOVE_CONTEXT_VALUE_METHOD = newMethod(PUBLIC, "<T> " + TYPE_VOID, "removeContextValue", - FIELD_NAME_DELEGATE_CONTEXT + ".removeContextValue(clazz, null);", true, - new JavaArgument("Class<T>", "clazz")); + protected static final JavaMethod REMOVE_CONTEXT_VALUE_METHOD = newMethod( + PUBLIC, + "<T> " + TYPE_VOID, + "removeContextValue", + FIELD_NAME_DELEGATE_CONTEXT + ".removeContextValue(clazz, null);", + true, + newArgument("Class<T>", "clazz") + ); + /** * */ - protected static final JavaMethod GET_PARENT_CONTAINER_MORE_METHOD = newMethod(PUBLIC, "<O extends Container> O", "getParentContainer", - "return SwingUtil.getParentContainer(source, clazz);", true, - new JavaArgument("Object", "source"), new JavaArgument("Class<O>", "clazz")); + protected static final JavaMethod GET_PARENT_CONTAINER_MORE_METHOD = newMethod( + PUBLIC, + "<O extends Container> O", + "getParentContainer", + "return SwingUtil.getParentContainer(source, clazz);", + true, + newArgument("Object", "source"), newArgument("Class<O>", "clazz") + ); + /** * */ - protected static final JavaMethod GET_PARENT_CONTAINER_METHOD = newMethod(PUBLIC, "<O extends Container> O", "getParentContainer", - "return SwingUtil.getParentContainer(this, clazz);", true, - new JavaArgument("Class<O>", "clazz")); + protected static final JavaMethod GET_PARENT_CONTAINER_METHOD = newMethod( + PUBLIC, + "<O extends Container> O", + "getParentContainer", + "return SwingUtil.getParentContainer(this, clazz);", + true, + newArgument("Class<O>", "clazz") + ); + /** * */ - protected static final JavaMethod GET_OBJECT_BY_ID_METHOD = newMethod(PUBLIC, TYPE_OBJECT, "getObjectById", - "return " + FIELD_NAME_$OBJECT_MAP + ".get(id);", true, - new JavaArgument(TYPE_STRING, "id")); + protected static final JavaMethod GET_OBJECT_BY_ID_METHOD = newMethod( + PUBLIC, TYPE_OBJECT, "getObjectById", + "return " + FIELD_NAME_$OBJECT_MAP + ".get(id);", + true, + newArgument(TYPE_STRING, "id") + ); + /** * */ - protected static final JavaMethod GET_JAXX_OBJECT_DESCRIPTOR_METHOD = newMethod(PUBLIC | STATIC, "JAXXObjectDescriptor", METHOD_NAME_$GET_JAXXOBJECT_DESCRIPTOR, - "return JAXXUtil.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", false); + protected static final JavaMethod GET_JAXX_OBJECT_DESCRIPTOR_METHOD = newMethod( + PUBLIC | STATIC, + JAXXObjectDescriptor.class.getName(), + METHOD_NAME_$GET_JAXXOBJECT_DESCRIPTOR, + "return JAXXUtil.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", + false + ); + /** * */ - protected static final JavaMethod PROCESS_DATA_BINDING_METHOD = newMethod(PUBLIC, TYPE_VOID, METHOD_NAME_PROCESS_DATA_BINDING, - METHOD_NAME_PROCESS_DATA_BINDING + "(" + PARAMETER_NAME_$BINDING + ", false);", true, - new JavaArgument(TYPE_STRING, PARAMETER_NAME_$BINDING)); + protected static final JavaMethod PROCESS_DATA_BINDING_METHOD = newMethod( + PUBLIC, + TYPE_VOID, + METHOD_NAME_PROCESS_DATA_BINDING, + METHOD_NAME_PROCESS_DATA_BINDING + "(" + PARAMETER_NAME_$BINDING + ", false);", + true, + newArgument(TYPE_STRING, PARAMETER_NAME_$BINDING) + ); /** * */ - protected static final JavaMethod REGISTER_DATA_BINDING_METHOD = newMethod(PUBLIC, TYPE_VOID, METHOD_NAME_REGISTER_DATA_BINDING, + protected static final JavaMethod REGISTER_DATA_BINDING_METHOD = newMethod( + PUBLIC, + TYPE_VOID, + METHOD_NAME_REGISTER_DATA_BINDING, FIELD_NAME_$BINDINGS + ".put(binding.getId(), binding);", true, - new JavaArgument(JAXXBinding.class.getSimpleName(), "binding")); + newArgument(JAXXBinding.class.getSimpleName(), "binding") + ); + /** * */ - protected static final JavaMethod GET_DATA_BINDING_METHOD = newMethod(PUBLIC, JAXXBinding.class.getSimpleName() + "[]", "getDataBindings", + protected static final JavaMethod GET_DATA_BINDING_METHOD = newMethod( + PUBLIC, + JAXXBinding.class.getSimpleName() + "[]", + "getDataBindings", "return " + FIELD_NAME_$BINDINGS + ".values().toArray(new " + JAXXBinding.class.getSimpleName() + "[" + FIELD_NAME_$BINDINGS + ".size()]);", - true); + true + ); /** * */ - protected static final JavaMethod FIRE_PROPERTY_CHANGE_METHOD = newMethod(PUBLIC, TYPE_VOID, METHOD_NAME_FIRE_PROPERTY_CHANGE, - "super." + METHOD_NAME_FIRE_PROPERTY_CHANGE + "(propertyName, oldValue, newValue);", true, - new JavaArgument(TYPE_STRING, "propertyName"), new JavaArgument(TYPE_OBJECT, "oldValue"), new JavaArgument(TYPE_OBJECT, "newValue")); + protected static final JavaMethod FIRE_PROPERTY_CHANGE_METHOD = newMethod( + PUBLIC, + TYPE_VOID, + METHOD_NAME_FIRE_PROPERTY_CHANGE, + "super." + METHOD_NAME_FIRE_PROPERTY_CHANGE + "(propertyName, oldValue, newValue);", + true, + newArgument(TYPE_STRING, "propertyName"), + newArgument(TYPE_OBJECT, "oldValue"), + newArgument(TYPE_OBJECT, "newValue") + ); + /** * */ - protected static final JavaMethod FIRE_PROPERTY_CHANGE_NAMED_METHOD = newMethod(PUBLIC, TYPE_VOID, METHOD_NAME_FIRE_PROPERTY_CHANGE, - METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT + "()." + METHOD_NAME_FIRE_PROPERTY_CHANGE + "(propertyName, oldValue, newValue);", true, - new JavaArgument(TYPE_STRING, "propertyName"), new JavaArgument(TYPE_OBJECT, "oldValue"), new JavaArgument(TYPE_OBJECT, "newValue")); + protected static final JavaMethod FIRE_PROPERTY_CHANGE_NAMED_METHOD = newMethod( + PUBLIC, + TYPE_VOID, + METHOD_NAME_FIRE_PROPERTY_CHANGE, + METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT + "()." + METHOD_NAME_FIRE_PROPERTY_CHANGE + "(propertyName, oldValue, newValue);", + true, + newArgument(TYPE_STRING, "propertyName"), + newArgument(TYPE_OBJECT, "oldValue"), + newArgument(TYPE_OBJECT, "newValue") + ); + /** * */ - protected static final JavaMethod GET_PROPERTY_CHANGE_SUPPORT_METHOD = newMethod(0, PropertyChangeSupport.class.getSimpleName(), METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT, + protected static final JavaMethod GET_PROPERTY_CHANGE_SUPPORT_METHOD = newMethod( + 0, + PropertyChangeSupport.class.getName(), + METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT, "if (" + FIELD_NAME_$PROPERTY_CHANGE_SUPPORT + " == null)\n" + - " " + FIELD_NAME_$PROPERTY_CHANGE_SUPPORT + " = new PropertyChangeSupport(this);\n" + - "return " + FIELD_NAME_$PROPERTY_CHANGE_SUPPORT + ";", false); + " " + FIELD_NAME_$PROPERTY_CHANGE_SUPPORT + " = new PropertyChangeSupport(this);\n" + + "return " + FIELD_NAME_$PROPERTY_CHANGE_SUPPORT + ";", + false + ); + /** * */ - protected static final JavaMethod ADD_PROPERTY_CHANGE_SUPPORT_METHOD = newMethod(PUBLIC, TYPE_VOID, "addPropertyChangeListener", - METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT + "().addPropertyChangeListener(listener);", true, - new JavaArgument(PropertyChangeListener.class.getSimpleName(), "listener")); + protected static final JavaMethod ADD_PROPERTY_CHANGE_SUPPORT_METHOD = newMethod( + PUBLIC, + TYPE_VOID, + "addPropertyChangeListener", + METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT + "().addPropertyChangeListener(listener);", + true, + newArgument(PropertyChangeListener.class.getName(), "listener") + ); + /** * */ - protected static final JavaMethod ADD_PROPERTY_CHANGE_SUPPORT_NAMED_METHOD = newMethod(PUBLIC, TYPE_VOID, "addPropertyChangeListener", - METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT + "().addPropertyChangeListener(property, listener);", true, - new JavaArgument(TYPE_STRING, "property"), new JavaArgument(PropertyChangeListener.class.getSimpleName(), "listener")); + protected static final JavaMethod ADD_PROPERTY_CHANGE_SUPPORT_NAMED_METHOD = newMethod( + PUBLIC, + TYPE_VOID, + "addPropertyChangeListener", + METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT + "().addPropertyChangeListener(property, listener);", + true, + newArgument(TYPE_STRING, "property"), + newArgument(PropertyChangeListener.class.getName(), "listener") + ); + /** * */ - protected static final JavaMethod REMOVE_PROPERTY_CHANGE_SUPPORT_METHOD = newMethod(PUBLIC, TYPE_VOID, "removePropertyChangeListener", - METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT + "().removePropertyChangeListener(listener);", true, - new JavaArgument(PropertyChangeListener.class.getSimpleName(), "listener")); + protected static final JavaMethod REMOVE_PROPERTY_CHANGE_SUPPORT_METHOD = newMethod( + PUBLIC, + TYPE_VOID, + "removePropertyChangeListener", + METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT + "().removePropertyChangeListener(listener);", + true, + newArgument(PropertyChangeListener.class.getName(), "listener") + ); + /** * */ - protected static final JavaMethod REMOVE_PROPERTY_CHANGE_SUPPORT_NAMED_METHOD = newMethod(PUBLIC, TYPE_VOID, "removePropertyChangeListener", - METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT + "().removePropertyChangeListener(property, listener);", true, - new JavaArgument(TYPE_STRING, "property"), new JavaArgument(PropertyChangeListener.class.getSimpleName(), "listener")); + protected static final JavaMethod REMOVE_PROPERTY_CHANGE_SUPPORT_NAMED_METHOD = newMethod( + PUBLIC, + TYPE_VOID, + "removePropertyChangeListener", + METHOD_NAME_$GET_PROPERTY_CHANGE_SUPPORT + "().removePropertyChangeListener(property, listener);", + true, + newArgument(TYPE_STRING, "property"), + newArgument(PropertyChangeListener.class.getName(), "listener") + ); + private static final String PARAMETER_NAME_PARENT_CONTEXT = "parentContext"; @Override public boolean accept(JAXXCompiler compiler) { + + // alwyas use the default finalizer return true; } @@ -279,7 +488,7 @@ JAXXCompiler compiler, JavaFile javaFile, String packageName, - String className) { + String className) throws ClassNotFoundException { String fullClassName = packageName != null ? packageName + "." + className : className; @@ -287,22 +496,20 @@ throw new CompilerException("root tag can not be null"); } ClassDescriptor superclass = root.getObjectClass(); - ClassDescriptor descriptor = - ClassDescriptorHelper.getClassDescriptor(JAXXObject.class); boolean superclassIsJAXXObject = - descriptor.isAssignableFrom(superclass); + compiler.isSuperClassAware(JAXXObject.class); javaFile.setModifiers(PUBLIC); javaFile.setName(fullClassName); javaFile.setSuperClass(JAXXCompiler.getCanonicalName(superclass)); javaFile.setSuperclassIsJAXXObject(superclassIsJAXXObject); - javaFile.addInterfaces(compiler.getExtraInterfaces()); + javaFile.addInterface(compiler.getExtraInterfaces()); javaFile.setAbstractClass(compiler.isAbstractClass()); javaFile.setGenericType(compiler.getGenericType()); javaFile.setSuperGenericType(compiler.getSuperGenericType()); if (!superclassIsJAXXObject) { - javaFile.addInterface(JAXXObject.class.getSimpleName()); + javaFile.addInterface(JAXXObject.class.getName()); } } @@ -313,39 +520,32 @@ String packageName, String className) throws ClassNotFoundException { - String fullClassName = javaFile.getName(); - String jaxxContextImplementorClass = compiler.getConfiguration().getJaxxContextClass().getName(); boolean superclassIsJAXXObject = javaFile.isSuperclassIsJAXXObject(); - if (!superclassIsJAXXObject) { - javaFile.addImport(JAXXObject.class); - } - javaFile.addImport(JAXXContext.class); - javaFile.addImport(JAXXObjectDescriptor.class); - javaFile.addImport(JAXXBinding.class); - // add logger + // add logger support if (compiler.getConfiguration().isAddLogger()) { - javaFile.addImport(Log.class); + javaFile.addImport(LogFactory.class); - //TC-20091127 : let the logger stays protected + javaFile.addSimpleField(newField( - PRIVATE| STATIC | FINAL, - "Log", + PRIVATE | STATIC | FINAL, + Log.class.getName(), "log", false, - "LogFactory.getLog(" + fullClassName + ".class)") + "LogFactory.getLog(" + className + ".class)") ); } + if (!superclassIsJAXXObject) { - - // JAXXObject - javaFile.addField(OBJECT_MAP_FIELD); + + // add JAXXObject support + addField(javaFile, OBJECT_MAP_FIELD); javaFile.addMethod(GET_OBJECT_BY_ID_METHOD); - javaFile.addSimpleField(BINDING_SOURCES_FIELD); - javaFile.addSimpleField(ACTIVE_BINDINGS_FIELD); - javaFile.addSimpleField(BINDINGS_FIELD); + addSimpleField(javaFile, BINDING_SOURCES_FIELD); + addSimpleField(javaFile, ACTIVE_BINDINGS_FIELD); + addSimpleField(javaFile, BINDINGS_FIELD); javaFile.addMethod(REGISTER_DATA_BINDING_METHOD); javaFile.addMethod(GET_DATA_BINDING_METHOD); @@ -354,13 +554,20 @@ javaFile.addMethod(createRemoveDataBindingMethod()); // JAXXContext + + String type = + javaFile.getImportManager().getType(jaxxContextImplementorClass); + javaFile.addField(newField( PROTECTED | FINAL, - JAXXContext.class.getSimpleName(), + JAXXContext.class.getName(), FIELD_NAME_DELEGATE_CONTEXT, true, - "new " + jaxxContextImplementorClass + "()") + "new " + type + "()") ); + + javaFile.addImport(Container.class); + javaFile.addMethod(SET_CONTEXT_VALUE_METHOD); javaFile.addMethod(SET_CONTEXT_VALUE_NAMED_METHOD); javaFile.addMethod(GET_CONTEXT_VALUE_METHOD); @@ -375,9 +582,15 @@ // DataBinding javaFile.addMethod(PROCESS_DATA_BINDING_METHOD); + } else { + + //FIXME tchemit 2011-01-30 : We should not add it (if user want to use it in script it must add the correct import + // Will be removed in version 3.0 with strict imports features + javaFile.addImport(JAXXContext.class); } - javaFile.addSimpleField(SERIAL_VERSION_UID_FIELD); - javaFile.addSimpleField(ALL_COMPONENTS_CREATED_FIELD); + + addSimpleField(javaFile, SERIAL_VERSION_UID_FIELD); + addSimpleField(javaFile, ALL_COMPONENTS_CREATED_FIELD); boolean overrideContextInitialized = false; FieldDescriptor[] scriptFields = compiler.getScriptFields(); for (FieldDescriptor f : scriptFields) { @@ -387,10 +600,11 @@ } } if (!overrideContextInitialized) { - javaFile.addSimpleField(CONTEXT_INITIALIZED); + addSimpleField(javaFile, CONTEXT_INITIALIZED); } - javaFile.addSimpleField( - createJAXXObjectDescriptorField(compiler, javaFile)); + JavaField descriptorField = + createJAXXObjectDescriptorField(compiler, javaFile); + javaFile.addSimpleField(descriptorField); if (compiler.getStylesheet() != null) { boolean needField = true; @@ -400,25 +614,32 @@ if (log.isDebugEnabled()) { log.debug("superclass : " + superclass); } - JAXXCompiler parentCompiler = compiler.getEngine().getJAXXCompiler(superclass.getName()); + JAXXCompiler parentCompiler = + compiler.getEngine().getJAXXCompiler( + superclass.getName() + ); + if (parentCompiler != null) { needField = parentCompiler.getStylesheet() == null; } else { try { - superclass.getDeclaredFieldDescriptor(PREVIOUS_VALUES_FIELD.getName()); + superclass.getDeclaredFieldDescriptor( + PREVIOUS_VALUES_FIELD.getName()); needField = false; } catch (NoSuchFieldException ex) { // field not found } } if (needField && log.isDebugEnabled()) { - log.debug("no " + PREVIOUS_VALUES_FIELD.getName() + " field in super class"); + log.debug("no " + PREVIOUS_VALUES_FIELD.getName() + + " field in super class"); } } if (needField) { - javaFile.addSimpleField(PREVIOUS_VALUES_FIELD); + addSimpleField(javaFile, PREVIOUS_VALUES_FIELD); } } + //TC 20090228 - only generate constructors if not done in scripts boolean constructorDetected = false; MethodDescriptor[] methods = compiler.getScriptMethods(); @@ -434,8 +655,20 @@ } } if (!constructorDetected) { - javaFile.addMethod(createConstructor(compiler, className, superclassIsJAXXObject)); - javaFile.addMethod(createConstructorWithInitialContext(compiler, className, superclassIsJAXXObject)); + + //creates default constructors + + JavaMethod constructor = createConstructor(compiler, + className, + superclassIsJAXXObject + ); + javaFile.addMethod(constructor); + constructor = createConstructorWithInitialContext( + compiler, + className, + superclassIsJAXXObject + ); + javaFile.addMethod(constructor); } DataBinding[] bindings = compiler.getBindingHelper().getDataBindings(); @@ -444,14 +677,18 @@ boolean hasDataBindings = nbBindings > 0; javaFile.addMethod(createInitializer(compiler, nbBindings)); - javaFile.addMethod(GET_JAXX_OBJECT_DESCRIPTOR_METHOD); + addMethod(javaFile, GET_JAXX_OBJECT_DESCRIPTOR_METHOD); + javaFile.addBodyCode(compiler.getBodyCode().toString()); if (hasDataBindings) { // create the $registerDefaultBindings method + for (JAXXBindingWriter<?> writer : bindingWriters) { + writer.reset(); + } javaFile.addMethod(createRegisterDefaultBindingsMethod(compiler)); // add import on each type of JAXXBinding used @@ -470,9 +707,13 @@ // add the data binding constant Id - compiler.addSimpleField(JavaFileGenerator.newField( + compiler.addSimpleField(newField( (constantId.startsWith("BINDING_$") ? PRIVATE : PUBLIC) | FINAL | STATIC, - TYPE_STRING, constantId, false, TypeManager.getJavaCode(binding.getRealId()))); + TYPE_STRING, + constantId, + false, + TypeManager.getJavaCode(binding.getRealId())) + ); } } @@ -481,9 +722,9 @@ addEventHandlers(compiler, javaFile); } - protected static final JAXXBindingWriter<?>[] bindingWriters = new JAXXBindingWriter[]{ - new SimpleJAXXObjectBindingWriter(), - new DefaultJAXXBindingWriter() + protected final JAXXBindingWriter<?>[] bindingWriters = new + JAXXBindingWriter[]{new SimpleJAXXObjectBindingWriter(), + new DefaultJAXXBindingWriter() }; protected JavaMethod createRegisterDefaultBindingsMethod(JAXXCompiler compiler) { @@ -494,7 +735,10 @@ JavaFileGenerator generator = new JavaFileGenerator(eol, true); //TODO use optimized writer for simple cases - initCode.append("// register ").append(bindings.length).append(" data bindings").append(eol); + initCode.append("// register "); + initCode.append(bindings.length); + initCode.append(" data bindings"); + initCode.append(eol); for (DataBinding binding : bindings) { @@ -505,13 +749,19 @@ } } } - return JavaFileGenerator.newMethod(PRIVATE, TYPE_VOID, METHOD_NAME_$REGISTER_DEFAULT_BINDINGS, initCode.toString(), false); + return newMethod(PRIVATE, + TYPE_VOID, + METHOD_NAME_$REGISTER_DEFAULT_BINDINGS, + initCode.toString(), + false + ); } /*---------------------------------------------------------------------------------*/ /*-- Create fields ----------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/ - protected JavaField createJAXXObjectDescriptorField(JAXXCompiler compiler, JavaFile javaFile) { + protected JavaField createJAXXObjectDescriptorField(JAXXCompiler compiler, + JavaFile javaFile) { try { JAXXObjectDescriptor descriptor = compiler.getJAXXObjectDescriptor(); String data = Base64Coder.serialize(descriptor, true); @@ -529,19 +779,36 @@ int sizeLimit = 65000; // constant strings are limited to 64K, and I'm not brave enough to push right up to the limit if (data.length() < sizeLimit) { - return newField(PRIVATE | STATIC | FINAL, TYPE_STRING, FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR, false, TypeManager.getJavaCode(data)); + return newField(PRIVATE | STATIC | FINAL, + TYPE_STRING, + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR, + false, + TypeManager.getJavaCode(data) + ); } else { StringBuffer initializer = new StringBuffer(); for (int i = 0; i < data.length(); i += sizeLimit) { String name = FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + i; - javaFile.addField(new JavaField(PRIVATE | STATIC, TYPE_STRING, name, false, - TypeManager.getJavaCode(data.substring(i, Math.min(i + sizeLimit, data.length()))))); + javaFile.addField(newField( + PRIVATE | STATIC, + TYPE_STRING, + name, + false, + TypeManager.getJavaCode(data.substring(i, Math.min(i + sizeLimit, data.length())))) + ); if (initializer.length() > 0) { initializer.append(" + "); } - initializer.append(TYPE_STRING + ".valueOf(").append(name).append(")"); + initializer.append(TYPE_STRING + ".valueOf("); + initializer.append(name); + initializer.append(")"); } - return newField(PRIVATE | STATIC | FINAL, TYPE_STRING, FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR, false, initializer.toString()); + return newField(PRIVATE | STATIC | FINAL, + TYPE_STRING, + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR, + false, + initializer.toString() + ); } } catch (IOException e) { throw new RuntimeException("Internal error: can't-happen error", e); @@ -551,34 +818,40 @@ /*---------------------------------------------------------------------------------*/ /*-- Create methods ---------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/ - protected void addPropertyChangeSupport(CompiledObject root, JavaFile javaFile) { + protected void addPropertyChangeSupport(CompiledObject root, + JavaFile javaFile) { ClassDescriptor currentClass = root.getObjectClass(); MethodDescriptor firePropertyChange = null; while (firePropertyChange == null && currentClass != null) { try { - firePropertyChange = currentClass.getDeclaredMethodDescriptor(METHOD_NAME_FIRE_PROPERTY_CHANGE, ClassDescriptorHelper.getClassDescriptor(String.class), + firePropertyChange = currentClass.getDeclaredMethodDescriptor( + METHOD_NAME_FIRE_PROPERTY_CHANGE, + ClassDescriptorHelper.getClassDescriptor(String.class), ClassDescriptorHelper.getClassDescriptor(Object.class), - ClassDescriptorHelper.getClassDescriptor(Object.class)); + ClassDescriptorHelper.getClassDescriptor(Object.class) + ); } catch (NoSuchMethodException e) { currentClass = currentClass.getSuperclass(); } } - int modifiers = firePropertyChange != null ? firePropertyChange.getModifiers() : 0; + int modifiers = firePropertyChange != null ? + firePropertyChange.getModifiers() : 0; if (isPublic(modifiers)) { // we have all the support we need return; } if (isProtected(modifiers)) { + // there is property change support but the firePropertyChange method is protected javaFile.addMethod(FIRE_PROPERTY_CHANGE_METHOD); } else { // either no support at all or firePropertyChange isn't accessible - javaFile.addImport(PropertyChangeListener.class); - javaFile.addImport(PropertyChangeSupport.class); +// javaFile.addImport(PropertyChangeListener.class); +// javaFile.addImport(PropertyChangeSupport.class); - javaFile.addField(PROPERTY_CHANGE_SUPPORT_FIELD); + addField(javaFile, PROPERTY_CHANGE_SUPPORT_FIELD); javaFile.addMethod(GET_PROPERTY_CHANGE_SUPPORT_METHOD); javaFile.addMethod(ADD_PROPERTY_CHANGE_SUPPORT_METHOD); javaFile.addMethod(ADD_PROPERTY_CHANGE_SUPPORT_NAMED_METHOD); @@ -588,7 +861,11 @@ } } - protected void addEventHandlers(JAXXCompiler compiler, JavaFile javaFile) { + protected void addEventHandlers(JAXXCompiler compiler, + JavaFile javaFile) { + + ImportsManager importManager = javaFile.getImportManager(); + for (Map.Entry<String, Map<ClassDescriptor, List<EventHandler>>> e1 : compiler.getEventHandlers().entrySet()) { // outer loop is iterating over different objects (well, technically, different Java expressions) @@ -603,19 +880,41 @@ if (listenerMethod.getParameterTypes().length != 1) { throw new CompilerException("Expected event handler " + listenerMethod.getName() + " of class " + handler.getListenerClass() + " to have exactly one argument"); } - javaFile.addMethod(newMethod(PUBLIC, TYPE_VOID, methodName, handler.getJavaCode(), false, - new JavaArgument(JAXXCompiler.getCanonicalName(listenerMethod.getParameterTypes()[0]), "event"))); + + ClassDescriptor eventType = listenerMethod.getParameterTypes()[0]; + + String type = importManager.getType( + JAXXCompiler.getCanonicalName(eventType)); + + JavaArgument argument = + JavaElementFactory.newArgument( + type, + "event" + ); + javaFile.addMethod(JavaElementFactory.newMethod( + PUBLIC, + TYPE_VOID, + methodName, + handler.getJavaCode(), + false, + argument) + ); } } } } - protected JavaMethod createConstructor(JAXXCompiler compiler, String className, boolean superclassIsJAXXObject) throws CompilerException { + protected JavaMethod createConstructor(JAXXCompiler compiler, + String className, + boolean superclassIsJAXXObject) throws CompilerException { StringBuffer code = new StringBuffer(); String constructorParams = compiler.getRootObject().getConstructorParams(); String eol = JAXXCompiler.getLineSeparator(); if (constructorParams != null) { - code.append(" super(").append(constructorParams).append(");").append(eol); + code.append(" super("); + code.append(constructorParams); + code.append(");"); + code.append(eol); } else { if (superclassIsJAXXObject) { code.append(" super();").append(eol); @@ -623,10 +922,17 @@ } code.append(METHOD_NAME_$INITIALIZE + "();"); code.append(eol); - return newMethod(PUBLIC, null, className, code.toString(), false); + return JavaElementFactory.newMethod(PUBLIC, + null, + className, + code.toString(), + false + ); } - protected JavaMethod createConstructorWithInitialContext(JAXXCompiler compiler, String className, boolean superclassIsJAXXObject) throws CompilerException { + protected JavaMethod createConstructorWithInitialContext(JAXXCompiler compiler, + String className, + boolean superclassIsJAXXObject) throws CompilerException { StringBuffer code = new StringBuffer(); String constructorParams = compiler.getRootObject().getConstructorParams(); String eol = JAXXCompiler.getLineSeparator(); @@ -636,26 +942,43 @@ //TODO constructor with extra first parameter as parentContext constructorParams = PARAMETER_NAME_PARENT_CONTEXT + ", " + constructorParams; } - code.append(" super(").append(constructorParams).append(");").append(eol); + code.append(" super("); + code.append(constructorParams); + code.append(");"); + code.append(eol); } else { if (superclassIsJAXXObject) { - code.append(" super(" + PARAMETER_NAME_PARENT_CONTEXT + ");").append(eol); + code.append(" super(" + PARAMETER_NAME_PARENT_CONTEXT + ");"); + code.append(eol); } } if (!superclassIsJAXXObject) { - code.append(JAXXUtil.class.getSimpleName()).append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");"); + code.append(JAXXUtil.class.getSimpleName()); + code.append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");"); code.append(eol); } code.append(METHOD_NAME_$INITIALIZE + "();"); code.append(eol); - return newMethod(PUBLIC, null, className, code.toString(), false, new JavaArgument(JAXXContext.class.getSimpleName(), PARAMETER_NAME_PARENT_CONTEXT)); + JavaArgument argument = JavaElementFactory.newArgument( + JAXXContext.class.getName(), + PARAMETER_NAME_PARENT_CONTEXT + ); + return JavaElementFactory.newMethod(PUBLIC, + null, + className, + code.toString(), + false, + argument + ); } - public JavaMethod createInitializer(JAXXCompiler compiler, int nbBindings) throws CompilerException { + public JavaMethod createInitializer(JAXXCompiler compiler, + int nbBindings) throws CompilerException { String eol = JAXXCompiler.getLineSeparator(); StringBuffer code = new StringBuffer(); CompiledObject root = compiler.getRootObject(); - code.append("if (" + FIELD_NAME_ALL_COMPONENTS_CREATED + " || !" + FIELD_NAME_CONTEXT_INITIALIZED + ") {").append(eol); + code.append("if (" + FIELD_NAME_ALL_COMPONENTS_CREATED + " || !" + FIELD_NAME_CONTEXT_INITIALIZED + ") {"); + code.append(eol); code.append(" return;").append(eol); code.append("}").append(eol); // // register bindings before anything else @@ -669,7 +992,10 @@ // code.append(dataBindingsCode).append(eol); // } //TODO-TC20091025 we should remove this if no used anywhere - code.append(FIELD_NAME_$OBJECT_MAP + ".put(").append(TypeManager.getJavaCode(root.getId())).append(", this);").append(eol); + code.append(FIELD_NAME_$OBJECT_MAP + ".put("); + code.append(TypeManager.getJavaCode(root.getId())); + code.append(", this);"); + code.append(eol); Iterator<CompiledObject> i = compiler.getObjectCreationOrder(); boolean lastWasMethodCall = false; @@ -681,30 +1007,54 @@ continue; } CompiledObjectDecorator decorator = object.getDecorator(); - lastWasMethodCall = decorator.createInitializer(compiler, root, object, code, lastWasMethodCall); + lastWasMethodCall = decorator.createInitializer(compiler, + root, + object, + code, + lastWasMethodCall + ); } - root.getDecorator().createInitializer(compiler, root, root, code, lastWasMethodCall); + root.getDecorator().createInitializer(compiler, + root, + root, + code, + lastWasMethodCall + ); if (compiler.getInitializer().length() > 0) { code.append(compiler.getInitializer()); } // register bindings before anything else if (nbBindings > 0) { // ajout invocation a la methode d'enregistrement des bindings - code.append("// registers ").append(nbBindings).append(" data bindings").append(eol); - code.append(METHOD_NAME_$REGISTER_DEFAULT_BINDINGS + "();").append(eol); + code.append("// registers "); + code.append(nbBindings); + code.append(" data bindings"); + code.append(eol); + code.append(METHOD_NAME_$REGISTER_DEFAULT_BINDINGS + "();"); + code.append(eol); } - code.append(METHOD_NAME_$COMPLETE_SETUP + "();").append(eol); - return newMethod(PRIVATE, TYPE_VOID, METHOD_NAME_$INITIALIZE, code.toString(), false); + code.append(METHOD_NAME_$COMPLETE_SETUP + "();"); + code.append(eol); + return JavaElementFactory.newMethod(PRIVATE, + TYPE_VOID, + METHOD_NAME_$INITIALIZE, + code.toString(), + false + ); } - protected JavaMethod createCompleteSetupMethod(JAXXCompiler compiler, JavaFile javaFile) { + protected JavaMethod createCompleteSetupMethod(JAXXCompiler compiler, + JavaFile javaFile) { StringBuffer code = new StringBuffer(); code.append(FIELD_NAME_ALL_COMPONENTS_CREATED + " = true;"); String eol = JAXXCompiler.getLineSeparator(); code.append(eol); for (CompiledObject object : compiler.getObjects().values()) { CompiledObjectDecorator decorator = object.getDecorator(); - code.append(decorator.createCompleteSetupMethod(compiler, object, javaFile)); + code.append(decorator.createCompleteSetupMethod(compiler, + object, + javaFile) + ); } String simpleBindingsCode = createInitBindingsCode(compiler); if (simpleBindingsCode != null && !simpleBindingsCode.isEmpty()) { @@ -716,11 +1066,17 @@ code.append(compiler.getLateInitializer()).append(eol); } //TC-20090313 add an extra method after complete setup - MethodDescriptor method = compiler.getScriptMethod(METHOD_NAME_$AFTER_COMPLETE_SETUP); + MethodDescriptor method = + compiler.getScriptMethod(METHOD_NAME_$AFTER_COMPLETE_SETUP); if (method != null) { code.append(METHOD_NAME_$AFTER_COMPLETE_SETUP + "();").append(eol); } - return newMethod(PRIVATE, TYPE_VOID, METHOD_NAME_$COMPLETE_SETUP, code.toString(), false); + return JavaElementFactory.newMethod(PRIVATE, + TYPE_VOID, + METHOD_NAME_$COMPLETE_SETUP, + code.toString(), + false + ); } protected String createInitBindingsCode(JAXXCompiler compiler) { @@ -732,8 +1088,14 @@ bindings = compiler.getBindingHelper().getDataBindings(); if (bindings.length > 0) { - result.append(eol).append("// apply ").append(bindings.length).append(" data bindings").append(eol); - result.append(JAXXUtil.class.getSimpleName()).append("." + METHOD_NAME_APPLY_DATA_BINDING + "(this, " + FIELD_NAME_$BINDINGS + ".keySet());").append(eol); + result.append(eol); + result.append("// apply "); + result.append(bindings.length); + result.append(" data bindings"); + result.append(eol); + result.append(JAXXUtil.class.getSimpleName()); + result.append("." + METHOD_NAME_APPLY_DATA_BINDING + "(this, " + FIELD_NAME_$BINDINGS + ".keySet());"); + result.append(eol); } bindings = compiler.getBindingHelper().getSimpleBindings(); @@ -751,7 +1113,11 @@ if (initCode.length() > 0) { - result.append(eol).append("// apply ").append(bindings.length).append(" property setters").append(eol); + result.append(eol); + result.append("// apply "); + result.append(bindings.length); + result.append(" property setters"); + result.append(eol); result.append(initCode.toString().trim()); } @@ -763,45 +1129,75 @@ StringBuilder buffer = new StringBuilder(); String eol = JAXXCompiler.getLineSeparator(); - buffer.append("if (" + FIELD_NAME_ALL_COMPONENTS_CREATED + " && " + FIELD_NAME_$BINDINGS + ".containsKey(" + PARAMETER_NAME_$BINDING + ")) {").append(eol); - buffer.append(" " + FIELD_NAME_$BINDINGS + ".get(" + PARAMETER_NAME_$BINDING + ")." + METHOD_NAME_APPLY_DATA_BINDING + "();").append(eol); + buffer.append("if (" + FIELD_NAME_ALL_COMPONENTS_CREATED + " && " + FIELD_NAME_$BINDINGS + ".containsKey(" + PARAMETER_NAME_$BINDING + ")) {"); + buffer.append(eol); + buffer.append(" " + FIELD_NAME_$BINDINGS + ".get(" + PARAMETER_NAME_$BINDING + ")." + METHOD_NAME_APPLY_DATA_BINDING + "();"); + buffer.append(eol); buffer.append("}"); - buffer.append(eol).append(METHOD_NAME_PROCESS_DATA_BINDING + "(" + PARAMETER_NAME_$BINDING + ");"); - return newMethod(PUBLIC, TYPE_VOID, METHOD_NAME_APPLY_DATA_BINDING, buffer.toString(), true, - new JavaArgument(TYPE_STRING, PARAMETER_NAME_$BINDING)); + buffer.append(eol); + buffer.append(METHOD_NAME_PROCESS_DATA_BINDING + "(" + PARAMETER_NAME_$BINDING + ");"); + return JavaElementFactory.newMethod( + PUBLIC, + TYPE_VOID, + METHOD_NAME_APPLY_DATA_BINDING, + buffer.toString(), + true, + JavaElementFactory.newArgument(TYPE_STRING, PARAMETER_NAME_$BINDING) + ); } protected JavaMethod createRemoveDataBindingMethod() { StringBuilder buffer = new StringBuilder(); String eol = JAXXCompiler.getLineSeparator(); - buffer.append("if (" + FIELD_NAME_ALL_COMPONENTS_CREATED + " && " + FIELD_NAME_$BINDINGS + ".containsKey(" + PARAMETER_NAME_$BINDING + ")) {").append(eol); - buffer.append(" " + FIELD_NAME_$BINDINGS + ".get(" + PARAMETER_NAME_$BINDING + ")." + METHOD_NAME_REMOVE_DATA_BINDING + "();").append(eol); + buffer.append("if (" + FIELD_NAME_ALL_COMPONENTS_CREATED + " && " + FIELD_NAME_$BINDINGS + ".containsKey(" + PARAMETER_NAME_$BINDING + ")) {"); + buffer.append(eol); + buffer.append(" " + FIELD_NAME_$BINDINGS + ".get(" + PARAMETER_NAME_$BINDING + ")." + METHOD_NAME_REMOVE_DATA_BINDING + "();"); + buffer.append(eol); buffer.append("}"); - return newMethod(PUBLIC, TYPE_VOID, METHOD_NAME_REMOVE_DATA_BINDING, buffer.toString(), true, - new JavaArgument(TYPE_STRING, PARAMETER_NAME_$BINDING)); + return JavaElementFactory.newMethod( + PUBLIC, + TYPE_VOID, + METHOD_NAME_REMOVE_DATA_BINDING, + buffer.toString(), + true, + JavaElementFactory.newArgument(TYPE_STRING, PARAMETER_NAME_$BINDING) + ); } protected JavaMethod createProcessDataBindingMethod() { StringBuffer code = new StringBuffer(); String eol = JAXXCompiler.getLineSeparator(); - + // the force parameter forces the update to happen even if it is already in activeBindings. This // is used on superclass invocations b/c by the time the call gets to the superclass, it is already // marked active and would otherwise be skipped - code.append(" if (!$force && " + FIELD_NAME_$ACTIVE_BINDINGS + ".contains(" + PARAMETER_NAME_$BINDING + ")) { ").append(eol); - code.append(" return;").append(eol); + code.append(" if (!$force && " + FIELD_NAME_$ACTIVE_BINDINGS + ".contains(" + PARAMETER_NAME_$BINDING + ")) { "); + code.append(eol); + code.append(" return;"); + code.append(eol); code.append("}").append(eol); - code.append(FIELD_NAME_$ACTIVE_BINDINGS + ".add(" + PARAMETER_NAME_$BINDING + ");").append(eol); + code.append(FIELD_NAME_$ACTIVE_BINDINGS + ".add(" + PARAMETER_NAME_$BINDING + ");"); + code.append(eol); code.append("try {").append(eol); - code.append(" if (" + FIELD_NAME_ALL_COMPONENTS_CREATED + " && " + FIELD_NAME_$BINDINGS + ".containsKey(" + PARAMETER_NAME_$BINDING + ")) {").append(eol); - code.append(" " + FIELD_NAME_$BINDINGS + ".get(" + PARAMETER_NAME_$BINDING + ")." + METHOD_NAME_PROCESS_DATA_BINDING + "();").append(eol); + code.append(" if (" + FIELD_NAME_ALL_COMPONENTS_CREATED + " && " + FIELD_NAME_$BINDINGS + ".containsKey(" + PARAMETER_NAME_$BINDING + ")) {"); + code.append(eol); + code.append(" " + FIELD_NAME_$BINDINGS + ".get(" + PARAMETER_NAME_$BINDING + ")." + METHOD_NAME_PROCESS_DATA_BINDING + "();"); + code.append(eol); code.append(" }").append(eol); code.append("} finally {").append(eol); - code.append(" " + FIELD_NAME_$ACTIVE_BINDINGS + ".remove(" + PARAMETER_NAME_$BINDING + ");").append(eol); + code.append(" " + FIELD_NAME_$ACTIVE_BINDINGS + ".remove(" + PARAMETER_NAME_$BINDING + ");"); + code.append(eol); code.append("}").append(eol); - return newMethod(PUBLIC, TYPE_VOID, METHOD_NAME_PROCESS_DATA_BINDING, code.toString(), true, - new JavaArgument(TYPE_STRING, PARAMETER_NAME_$BINDING), new JavaArgument(TYPE_BOOLEAN, "$force")); + return JavaElementFactory.newMethod( + PUBLIC, + TYPE_VOID, + METHOD_NAME_PROCESS_DATA_BINDING, + code.toString(), + true, + newArgument(TYPE_STRING, PARAMETER_NAME_$BINDING), + newArgument(TYPE_BOOLEAN, "$force") + ); } } Copied: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/JAXXCompilerFinalizer.java (from rev 2186, trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompilerFinalizer.java) =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/JAXXCompilerFinalizer.java (rev 0) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/JAXXCompilerFinalizer.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,82 @@ +/* + * #%L + * JAXX :: Compiler + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package jaxx.compiler.finalizers; + +import jaxx.compiler.CompiledObject; +import jaxx.compiler.JAXXCompiler; +import jaxx.compiler.java.JavaFile; + +/** + * Contract of any object to interact with a {@link JAXXCompiler} before the + * generation pass. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0.0 + */ +public interface JAXXCompilerFinalizer { + + /** + * Test if the finalizer must be apply on the given {@code compiler}. + * + * @param compiler the compiler + * @return {@code true} if the finalizer must be apply of compiler + */ + boolean accept(JAXXCompiler compiler); + + /** + * Finalize compiler for a given compiler on the finalizer pass before any + * generation. + * + * @param root the root object + * @param compiler the current compiler + * @param javaFile the java file to generate + * @param packageName the package name of the file to generate + * @param className the class name of the file to generate + * @throws Exception if any pb + */ + void finalizeCompiler(CompiledObject root, + JAXXCompiler compiler, + JavaFile javaFile, + String packageName, + String className) throws Exception; + + /** + * Prepare java file after any compiler finalizer pass, says the last + * action before generation. + * + * @param root the root object + * @param compiler the current compiler + * @param javaFile the java file to generate + * @param packageName the package name of the file to generate + * @param className the class name of the file to generate + * @throws Exception if any pb + */ + void prepareJavaFile(CompiledObject root, + JAXXCompiler compiler, + JavaFile javaFile, + String packageName, + String className) throws Exception; +} Property changes on: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/JAXXCompilerFinalizer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:mergeinfo + Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/SwingFinalizer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/SwingFinalizer.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/SwingFinalizer.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -27,42 +27,67 @@ import jaxx.compiler.CompiledObject; import jaxx.compiler.JAXXCompiler; -import jaxx.compiler.JAXXCompilerFinalizer; -import jaxx.compiler.java.JavaArgument; +import jaxx.compiler.java.JavaElementFactory; import jaxx.compiler.java.JavaFile; -import jaxx.compiler.java.JavaFileGenerator; +import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.runtime.swing.Application; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import javax.swing.SwingUtilities; import java.lang.reflect.Modifier; /** * @author tchemit <chemit@codelutin.com> - * @plexus.component role-hint="swing" role="jaxx.compiler.JAXXCompilerFinalizer" + * @plexus.component role-hint="swing" role="jaxx.compiler.finalizers.JAXXCompilerFinalizer" */ -public class SwingFinalizer implements JAXXCompilerFinalizer { +public class SwingFinalizer extends AbstractFinalizer { + /** Logger. */ + protected static final Log log = LogFactory.getLog(DefaultFinalizer.class); + @Override public boolean accept(JAXXCompiler compiler) { - //TODO Should check root object is a component - return true; + + ClassDescriptor descriptor = + ClassDescriptorHelper.getClassDescriptor(Application.class); + CompiledObject root = compiler.getRootObject(); + boolean accept = descriptor.isAssignableFrom(root.getObjectClass()); + return accept; } @Override - public void finalizeCompiler(CompiledObject root, JAXXCompiler compiler, JavaFile javaFile, String packageName, String className) { + public void finalizeCompiler(CompiledObject root, + JAXXCompiler compiler, + JavaFile javaFile, + String packageName, + String className) { } @Override - public void prepareJavaFile(CompiledObject root, JAXXCompiler compiler, JavaFile javaFile, String packageName, String className) throws ClassNotFoundException { + public void prepareJavaFile(CompiledObject root, + JAXXCompiler compiler, + JavaFile javaFile, + String packageName, + String className) throws ClassNotFoundException { - if (!compiler.isMainDeclared() && ClassDescriptorHelper.getClassDescriptor(Application.class.getName()).isAssignableFrom(root.getObjectClass())) { - javaFile.addMethod(JavaFileGenerator.newMethod( - Modifier.PUBLIC | Modifier.STATIC, - "void", - "main", - "SwingUtilities.invokeLater(new Runnable() { public void run() { new " + className + "().setVisible(true); } });", - false, - new JavaArgument("String[]", "arg"))); + if (compiler.isMainDeclared()) { + + // main method was already defined, can not generate this method. + return; } + + javaFile.addImport(SwingUtilities.class); + String code = "SwingUtilities.invokeLater(new Runnable() { " + + "public void run() { new " + className + + "().setVisible(true); } });"; + javaFile.addMethod(JavaElementFactory.newMethod( + Modifier.PUBLIC | Modifier.STATIC, + TYPE_VOID, + "main", + code, + false, + JavaElementFactory.newArgument("String[]", "arg"))); } } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/ValidatorFinalizer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/ValidatorFinalizer.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/ValidatorFinalizer.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -29,14 +29,10 @@ import jaxx.compiler.CompiledObject.ChildRef; import jaxx.compiler.CompilerException; import jaxx.compiler.JAXXCompiler; -import jaxx.compiler.JAXXCompilerFinalizer; -import jaxx.compiler.java.JavaArgument; import jaxx.compiler.java.JavaElement; +import jaxx.compiler.java.JavaElementFactory; import jaxx.compiler.java.JavaField; import jaxx.compiler.java.JavaFile; -import jaxx.compiler.java.JavaFileGenerator; -import jaxx.compiler.reflect.ClassDescriptor; -import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.compiler.tags.validator.BeanValidatorHandler; import jaxx.compiler.tags.validator.BeanValidatorHandler.CompiledBeanValidator; import jaxx.compiler.types.TypeManager; @@ -50,6 +46,7 @@ import org.apache.commons.logging.LogFactory; import java.lang.reflect.Modifier; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -57,25 +54,31 @@ * To finalize validators fields. * * @author tchemit <chemit@codelutin.com> - * @plexus.component role-hint="validators" role="jaxx.compiler.JAXXCompilerFinalizer" + * @plexus.component role-hint="validators" role="jaxx.compiler.finalizers.JAXXCompilerFinalizer" */ -public class ValidatorFinalizer implements JAXXCompilerFinalizer { +public class ValidatorFinalizer extends AbstractFinalizer { /** Logger. */ static Log log = LogFactory.getLog(ValidatorFinalizer.class); + protected static final String VALIDATOR_UTIL_PREFIX = + SwingValidatorUtil.class.getSimpleName() + "."; + protected static final JavaField VALIDATOR_IDS_FIELD = - JavaFileGenerator.newField( + JavaElementFactory.newField( Modifier.PROTECTED, - "java.util.List<String>", + List.class.getName() + "<String>", "validatorIds", true, - "new ArrayList<String>()" + "new java.util.ArrayList<String>()" ); @Override public boolean accept(JAXXCompiler compiler) { - return BeanValidatorHandler.hasValidator(compiler); + + //use this finalizer if compiler is validation aware + boolean accept = BeanValidatorHandler.hasValidator(compiler); + return accept; } @Override @@ -92,13 +95,16 @@ } for (ChildRef child : childs) { String javaCode = child.getChildJavaCode(); + // some validators are defined on this object boolean found = BeanValidatorHandler.isComponentUsedByValidator( compiler, child.getChild().getId() ); + if (found) { + // box the child component in a JxLayer child.setChildJavaCode( SwingUtil.class.getSimpleName() + @@ -114,64 +120,32 @@ javaFile.addImport(Validator.class); javaFile.addImport(ValidatorField.class); javaFile.addImport(SwingValidatorUtil.class); - compiler.getJavaFile().addMethod(JavaFileGenerator.newMethod( + javaFile.addImport(ArrayList.class); + + compiler.getJavaFile().addMethod(JavaElementFactory.newMethod( Modifier.PUBLIC, - "void", + AbstractFinalizer.TYPE_VOID, "registerValidatorFields", - SwingValidatorUtil.class.getSimpleName() + ".installFields(this);", + VALIDATOR_UTIL_PREFIX + "installFields(this);", true) ); builder.append("// register "); builder.append(validators.size()); builder.append(" validator(s)"); builder.append(eol); + builder.append("validatorIds = "); - builder.append(SwingValidatorUtil.class.getSimpleName()).append(".initUI(this);"); + builder.append(VALIDATOR_UTIL_PREFIX).append("initUI(this);"); builder.append(eol); -// builder.append("registerValidatorFields();"); -// builder.append(eol); - builder.append(SwingValidatorUtil.class.getSimpleName()).append(".installUI(this);"); + + builder.append(VALIDATOR_UTIL_PREFIX).append("installUI(this);"); builder.append(eol); compiler.appendLateInitializer(builder.toString()); + for (CompiledBeanValidator validator : validators) { registerValidator(validator, compiler, javaFile); } - -// StringBuilder registerValidatorFieldsMethod = new StringBuilder(); -// registerValidatorFieldsMethod.append(SwingValidatorUtil.class.getSimpleName()).append(".installFields(this);"); - -// for (CompiledBeanValidator validator : validators) { -// validator.registerValidator(compiler, javaFile); -// -// String id = TypeManager.getJavaCode(validator.getId()); - - -// builder.append("validatorIds.add("); -// builder.append(id); -// builder.append(");"); -// builder.append(eol); -// builder.append("getValidator("); -// builder.append(id); -// builder.append(").installUIs();"); -// builder.append(eol); -// builder.append("getValidator("); -// builder.append(id); -// builder.append(").reloadBean();"); -// builder.append(eol); - // init fields -// validator.addFieldRepresentations(compiler, registerValidatorFieldsMethod); -// } -// builder.append("validatorIds = java.util.Collections.unmodifiableList(validatorIds);"); -// builder.append(eol); -// compiler.appendLateInitializer(builder.toString()); -// compiler.getJavaFile().addMethod(JavaFileGenerator.newMethod( -// Modifier.PUBLIC, -// "void", -// "registerValidatorFields", -// SwingValidatorUtil.class.getSimpleName() + ".installFields(this);", -// true) -// ); } @Override @@ -181,40 +155,36 @@ String packageName, String className) throws ClassNotFoundException { Class<?> validatorClass = SwingValidator.class; -// compiler.getConfiguration().getValidatorClass(); - String validatorFQN = validatorClass.getName(); - javaFile.addImport(validatorFQN); - //TODO use the specific JAXXValidator interface (swing, gwt,...) Class<?> validatorInterface = JAXXValidator.class; - //TC-20091202 : pass this test if we want to interact with non generated code ? -// if (javaFile.isSuperclassIsJAXXObject()) { - ClassDescriptor superClass = - ClassDescriptorHelper.getClassDescriptor(javaFile.getSuperClass()); - ClassDescriptor validatorInterfaceDescriptor = - ClassDescriptorHelper.getClassDescriptor(validatorInterface); boolean parentIsValidator = - validatorInterfaceDescriptor.isAssignableFrom(superClass); + compiler.isSuperClassAware(validatorInterface); if (parentIsValidator) { + // nothing to generate (use the parent directly) return; } -// } // add JAXXValidator interface javaFile.addInterface(JAXXCompiler.getCanonicalName(validatorInterface)); // implements JAXXValidator - javaFile.addField(VALIDATOR_IDS_FIELD); - javaFile.addMethod(JavaFileGenerator.newMethod( + addField(javaFile, VALIDATOR_IDS_FIELD); + + String initializer = "return (" + validatorClass.getSimpleName() + + "<?>) (validatorIds.contains(validatorId) ? " + + "getObjectById(validatorId) : null);"; + + javaFile.addMethod(JavaElementFactory.newMethod( Modifier.PUBLIC, - validatorFQN + "<?>", + validatorClass.getName() + "<?>", "getValidator", - "return (" + validatorFQN + "<?>) (validatorIds.contains(validatorId) ? getObjectById(validatorId) : null);", + initializer, true, - new JavaArgument("String", "validatorId")) + JavaElementFactory.newArgument( + AbstractFinalizer.TYPE_STRING, "validatorId")) ); } @@ -227,8 +197,7 @@ String validatorId = TypeManager.getJavaCode(validator.getId()); String validatorAnnotation = Validator.class.getSimpleName() + - "( validatorId = " + validatorId + - ")"; + "( validatorId = " + validatorId + ")"; validatorField.addAnnotation(validatorAnnotation); Map<String, String> fields = validator.getFields(); @@ -245,44 +214,46 @@ String editorCode = TypeManager.getJavaCode(component); JavaElement editor = javaFile.getField(component); if (editor == null) { - String message = "Could not find editor [" + - component + "] for property [" + propertyName + - "] for file " + javaFile.getName(); - log.warn(message); + if (log.isDebugEnabled()) { + String message = "Could not find editor [" + component + + "] for property [" + propertyName + + "] for file " + javaFile.getName(); + log.debug(message); + } // find in the compiler the object - CompiledObject compiledObject = compiler.getCompiledObject(component); + CompiledObject compiledObject = + compiler.getCompiledObject(component); if (compiledObject == null) { // this is an error, editor is unknown (this case should - // not happen) + // never happen) - String errorMessage = "Could not find editor [" + - component + "] for property [" + propertyName + - "] for file " + javaFile.getName(); + String errorMessage = + "Could not find editor [" + component + + "] for property [" + propertyName + + "] for file " + javaFile.getName(); throw new CompilerException(errorMessage); } // now must add a getter in the javaFile - String fqn = JAXXCompiler.getCanonicalName(compiledObject); editor = javaFile.addGetterMethod(component, Modifier.PUBLIC, fqn, true, - true); + true + ); } String annotation = ValidatorField.class.getSimpleName() + "( validatorId = " + validatorId + "," + " propertyName = " + keyCode + "," + - " editorName = " + editorCode + "" + - ")"; + " editorName = " + editorCode + "" + ")"; editor.addAnnotation(annotation); } } - } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaArgument.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaArgument.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaArgument.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -43,7 +43,7 @@ * @param type the argument's type, as it would appear in Java source code * @param name the argument's name */ - public JavaArgument(String type, String name) { + JavaArgument(String type, String name) { this(type, name, false); } @@ -56,7 +56,7 @@ * @param name the argument's name * @param isFinal <code>true</code> if the argument should be marked final */ - public JavaArgument(String type, String name, boolean isFinal) { + JavaArgument(String type, String name, boolean isFinal) { super(0, name); this.type = type; this.isFinal = isFinal; @@ -79,4 +79,8 @@ public boolean isFinal() { return isFinal; } + + public void setType(String type) { + this.type = type; + } } Added: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaElementFactory.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaElementFactory.java (rev 0) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaElementFactory.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,132 @@ +package jaxx.compiler.java; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.StringUtil; + +/** + * Factory of any element in a {@link JavaFile}. + * <p/> + * Always pass by this factory to have common behaviour (imports,...) + * + * @author tchemit <chemit@codelutin.com> + * @since 2.4 + */ +public class JavaElementFactory { + + /** Logger. */ + static private final Log log = LogFactory.getLog(JavaElementFactory.class); + + public static JavaFile newFile(int modifiers, String className) { + JavaFile file = new JavaFile(modifiers, className); + return file; + } + + public static JavaArgument newArgument(String type, + String name) { + JavaArgument argument = newArgument(type, name, false); + return argument; + } + + public static JavaArgument newArgument(String type, + String name, + boolean isFinal) { + JavaArgument argument = new JavaArgument(type, name, isFinal); + return argument; + } + + public static JavaField newField(int modifiers, + String returnType, + String name, + boolean override) { + return newField(modifiers, returnType, name, override, null); + } + + public static JavaField newField(int modifiers, + String returnType, + String name, + boolean override, + String initializer) { + return new JavaField(modifiers, + returnType, + name, + override, + initializer + ); + } + + public static JavaMethod newMethod(int modifiers, + String returnType, + String name, + String initializer, + boolean override, + String[] exceptions, + JavaArgument... arguments) { + if (log.isDebugEnabled()) { + log.debug(name + " returns : " + returnType); + } + return new JavaMethod(modifiers, + returnType, + name, + arguments, + exceptions, + initializer, + override + ); + } + + public static JavaMethod newMethod(int modifiers, + String returnType, + String name, + String initializer, + boolean override, + JavaArgument... arguments) { + return newMethod(modifiers, + returnType, + name, + initializer, + override, + StringUtil.EMPTY_STRING_ARRAY, + arguments + ); + } + + public static JavaField cloneField(JavaField field) { + return newField( + field.getModifiers(), + field.getType(), + field.getName(), + field.isOverride(), + field.getInitializer()); + } + + public static JavaMethod cloneMethod(JavaMethod method) { + + String[] incomingExceptions = method.getExceptions(); + String[] exceptions = new String[incomingExceptions.length]; + System.arraycopy(incomingExceptions, 0, exceptions, 0, exceptions.length); + + JavaArgument[] arguments = new JavaArgument[method.getArguments().length]; + for (int i = 0; i < arguments.length; i++) { + JavaArgument argument = arguments[i]; + arguments[i] = cloneArgument(argument); + } + return newMethod( + method.getModifiers(), + method.getReturnType(), + method.getName(), + method.getBody(), + method.isOverride(), + exceptions, + arguments); + } + + public static JavaArgument cloneArgument(JavaArgument argument) { + JavaArgument result = newArgument( + argument.getType(), + argument.getName(), + argument.isFinal() + ); + return result; + } +} Property changes on: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaElementFactory.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaField.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaField.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaField.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -59,10 +59,10 @@ * @param name the field's name * @param override flag to add @Override annotation on getter and setter */ - public JavaField(int modifiers, - String type, - String name, - boolean override) { + JavaField(int modifiers, + String type, + String name, + boolean override) { this(modifiers, type, name, override, null); } @@ -79,11 +79,11 @@ * @param override {@code true} if method should be marked as overriden * @param initializer the initial value of the field, as it would appear in Java source code */ - public JavaField(int modifiers, - String type, - String name, - boolean override, - String initializer) { + JavaField(int modifiers, + String type, + String name, + boolean override, + String initializer) { super(modifiers, name); this.type = type; this.initializer = initializer; @@ -118,6 +118,10 @@ getType() + ", modifiers:" + Modifier.toString(getModifiers()); } + public void setType(String type) { + this.type = type; + } + public enum FieldOrder { staticsBean(Modifier.STATIC | Modifier.PUBLIC, Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -26,12 +26,15 @@ package jaxx.compiler.java; import jaxx.compiler.types.TypeManager; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.java.extension.ImportsManager; import java.lang.reflect.Modifier; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -43,14 +46,14 @@ */ public class JavaFile extends JavaElement { - /** Logger */ + /** Logger. */ static Log log = LogFactory.getLog(JavaFile.class); protected static final String GETTER_PATTERN = "return %1$s;"; protected static final String BOOLEAN_GETTER_PATTERN = "return %1$s !=null && %1$s;"; - protected static final String SETTER_PATTERN = "%1$s oldValue = this.%2$s;\nthis.%2$s = newValue;\nfirePropertyChange(%3$s, oldValue, newValue);"; + protected static final String SETTER_PATTERN = "%1$s oldValue = this.%2$s;\nthis.%2$s = %2$s;\nfirePropertyChange(%3$s, oldValue, %2$s);"; private Set<String> imports = new HashSet<String>(); @@ -74,33 +77,67 @@ private String superGenericType; - public JavaFile() { - this(0, ""); - } + private final ImportsManager importManager; - public JavaFile(int modifiers, String className) { + JavaFile(int modifiers, String className) { super(modifiers, className); + importManager = new ImportsManager(); + // add the fqn before all in the import manager to deal with alias classes + importManager.addImport(className); } - public JavaFile(int modifiers, String className, String superClass) { + /** @deprecated since 2.4, never be used */ + @Deprecated + JavaFile() { + this(0, ""); + } + + /** + * @param modifiers + * @param className + * @param superClass + * @deprecated since 2.4, never be used + */ + @Deprecated + JavaFile(int modifiers, String className, String superClass) { this(modifiers, className, superClass, null); } - public JavaFile(int modifiers, - String className, - String superClass, - List<String> interfaces) { - super(modifiers, className); - this.superClass = superClass; - this.interfaces = interfaces; + /** + * @param modifiers + * @param className + * @param superClass + * @param interfaces + * @deprecated since 2.4, never be used + */ + @Deprecated + JavaFile(int modifiers, + String className, + String superClass, + List<String> interfaces) { + this(modifiers, className); + setSuperClass(superClass); + if (CollectionUtils.isNotEmpty(interfaces)) { + addInterface(interfaces.toArray(new String[interfaces.size()])); + } +// this.superClass = superClass; +// this.interfaces = interfaces; } - public void addImport(String importString) { - imports.add(importString); + public String getPackageName() { + String name = getName(); + + String packageName; + if (name.contains(".")) { + packageName = name.substring(0, name.lastIndexOf(".")); + } else { + packageName = null; + } + return packageName; } - public void addImport(Class<?> importString) { - addImport(importString.getName()); + public ImportsManager getImportManager() { + return importManager; } public String[] getImports() { @@ -109,14 +146,16 @@ return result.toArray(new String[result.size()]); } + public List<String> getImportsList() { + List<String> result = new ArrayList<String>(imports); + Collections.sort(result); + return result; + } + public String getSuperClass() { return superClass; } - public void setSuperClass(String superClass) { - this.superClass = superClass; - } - public List<String> getInterfaces() { if (interfaces == null) { interfaces = new ArrayList<String>(); @@ -124,22 +163,138 @@ return interfaces; } - public void setInterfaces(List<String> interfaces) { - this.interfaces = interfaces; + public List<JavaMethod> getMethods() { + return methods; } + public List<JavaField> getFields() { + return fields; + } + + public boolean isAbstractClass() { + return abstractClass; + } + + public String getGenericType() { + return genericType; + } + + public List<JavaFile> getInnerClasses() { + return innerClasses; + } + + public StringBuffer getRawBodyCode() { + return rawBodyCode; + } + + public String getSuperGenericType() { + return superGenericType; + } + + public boolean isSuperclassIsJAXXObject() { + return superclassIsJAXXObject; + } + + public JavaField getField(String componentId) { + for (JavaField field : fields) { + if (componentId.equals(field.getName())) { + return field; + } + } + return null; + } + + public void addImport(String importString) { +// if (GeneratorUtil.isPrimitiveType(importString)) { +// // do nothing +// return; +// } + try { + boolean wasAdded = importManager.addImport(importString); +// if (!wasAdded) { +// return; +// } + } catch (Exception e) { + log.info("Could not determine simple name of import " + importString); + } + imports.add(importString); + } + + public void addImport(Class<?> importString) { + addImport(importString.getName()); + } + + public void setImports(Collection<String> imports) { + this.imports = new HashSet<String>(imports); + } + public void setGenericType(String genericType) { this.genericType = genericType; } + public void setSuperClass(String superClass) { + this.superClass = superClass; + } + + public void addInterface(String... canonicalNames) { + if (canonicalNames == null) { + return; + } + for (String canonicalName : canonicalNames) { + if (interfaces == null || !interfaces.contains(canonicalName)) { + getInterfaces().add(canonicalName); + } + } + } + + public void setInterfaces(List<String> interfaces) { + List<String> simpleInterfaces = new ArrayList<String>(); + for (String anInterface : interfaces) { + try { + String type = importManager.getType(anInterface); + anInterface = type; + } catch (Exception e) { + log.error("Could not determine simple name of interface " + anInterface); + } + simpleInterfaces.add(anInterface); + } + this.interfaces = simpleInterfaces; + } + public void addMethod(JavaMethod method) { + String returnType = method.getReturnType(); + try { + String type = importManager.getReturnType(returnType); + method.setReturnType(type); + } catch (Exception e) { + log.error("Could not determine simple name of return type " + returnType + " for method " + method.getName()); + } + for (JavaArgument argument : method.getArguments()) { + String argumentType = argument.getType(); + try { + String type = importManager.getType(argumentType); + argument.setType(type); + } catch (Exception e) { + log.error("Could not determine simple name of argument type " + argumentType + " of argument " + argument.getName() + " for method " + method.getName()); + } + } + + String[] exceptions = method.getExceptions(); + for (int i = 0, length = exceptions.length; i < length; i++) { + String exception = exceptions[i]; + try { + String exceptionSimple = importManager.getType(exception); + exceptions[i] = exceptionSimple; + } catch (Exception e) { + log.error("Could not determine simple name of exception " + exception + " for method " + method.getName()); + } + + } + + methods.add(method); } - public List<JavaMethod> getMethods() { - return methods; - } - public void addField(JavaField field) { addField(field, false); @@ -160,11 +315,11 @@ bodyCode = id; } String content = String.format(GETTER_PATTERN, bodyCode); - JavaMethod method = JavaFileGenerator.newMethod(modifiers, - type, - methodName, - content, - overridde + JavaMethod method = JavaElementFactory.newMethod(modifiers, + type, + methodName, + content, + overridde ); addMethod(method); return method; @@ -191,15 +346,29 @@ // name of property to make it easier to use // compute the property constant String constantId = TypeManager.convertVariableNameToConstantName("property" + capitalizedName); - addSimpleField(JavaFileGenerator.newField(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL, String.class.getSimpleName(), constantId, false, "\"" + id + "\"")); + addSimpleField(JavaElementFactory.newField(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL, String.class.getSimpleName(), constantId, false, "\"" + id + "\"")); - if (Boolean.class.getName().equals(field.getType())) { + if (Boolean.class.getSimpleName().equals(field.getType())) { String content = String.format(BOOLEAN_GETTER_PATTERN, id); - addMethod(new JavaMethod(Modifier.PUBLIC, field.getType(), "is" + capitalizedName, null, null, content, field.isOverride())); + JavaMethod method = JavaElementFactory.newMethod( + Modifier.PUBLIC, + field.getType(), + "is" + capitalizedName, + content, + field.isOverride() + ); + addMethod(method); } String content = String.format(SETTER_PATTERN, field.getType(), id, constantId); - JavaArgument arg = new JavaArgument(field.getType(), "newValue"); - addMethod(new JavaMethod(Modifier.PUBLIC, "void", "set" + capitalizedName, new JavaArgument[]{arg}, null, content, field.isOverride())); + JavaArgument arg = JavaElementFactory.newArgument(field.getType(), id); + JavaMethod method = JavaElementFactory.newMethod( + Modifier.PUBLIC, + "void", + "set" + capitalizedName, + content, + field.isOverride(), + arg); + addMethod(method); } } @@ -207,76 +376,56 @@ if (log.isDebugEnabled()) { log.debug("[" + getName() + "] Add field " + field.getName()); } + String fieldType = field.getType(); + try { + String type = importManager.getType(fieldType); + field.setType(type); + } catch (Exception e) { + log.error("Could not determine simple name of field [" + field.getName() + "] type " + fieldType); + } fields.add(field); } - public List<JavaField> getFields() { - return fields; + public void setSuperclassIsJAXXObject(boolean superclassIsJAXXObject) { + this.superclassIsJAXXObject = superclassIsJAXXObject; } - public void addBodyCode(String bodyCode) { - rawBodyCode.append(bodyCode); + public void setAbstractClass(boolean abstractClass) { + this.abstractClass = abstractClass; } - public boolean isAbstractClass() { - return abstractClass; + public void setSuperGenericType(String superGenericType) { + this.superGenericType = superGenericType; } - public String getGenericType() { - return genericType; + public void addBodyCode(String bodyCode) { + rawBodyCode.append(bodyCode); } - public List<JavaFile> getInnerClasses() { - return innerClasses; - } - - public StringBuffer getRawBodyCode() { - return rawBodyCode; - } - - public String getSuperGenericType() { - return superGenericType; - } - - public void addInterface(String canonicalName) { - if (interfaces == null || !interfaces.contains(canonicalName)) { - getInterfaces().add(canonicalName); + public void clear() { + importManager.clearImports(); + if (interfaces != null) { + interfaces.clear(); + interfaces = null; } - } - - public void addInterfaces(String[] canonicalNames) { - if (canonicalNames == null) { - return; + if (methods != null) { + methods.clear(); + methods = null; } - for (String canonicalName : canonicalNames) { - if (interfaces == null || !interfaces.contains(canonicalName)) { - getInterfaces().add(canonicalName); - } + if (fields != null) { + fields.clear(); + fields = null; } + if (imports != null) { + imports.clear(); + } } - public boolean isSuperclassIsJAXXObject() { - return superclassIsJAXXObject; - } +// public void addInterface(String canonicalName) { +// if (interfaces == null || !interfaces.contains(canonicalName)) { +// getInterfaces().add(canonicalName); +// } +// } - public void setSuperclassIsJAXXObject(boolean superclassIsJAXXObject) { - this.superclassIsJAXXObject = superclassIsJAXXObject; - } - public void setAbstractClass(boolean abstractClass) { - this.abstractClass = abstractClass; - } - - public void setSuperGenericType(String superGenericType) { - this.superGenericType = superGenericType; - } - - public JavaField getField(String componentId) { - for (JavaField field : fields) { - if (componentId.equals(field.getName())) { - return field; - } - } - return null; - } } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFileGenerator.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFileGenerator.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFileGenerator.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -27,9 +27,9 @@ import jaxx.compiler.JAXXCompiler; import jaxx.compiler.java.JavaMethod.MethodOrder; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.util.StringUtil; import java.io.PrintWriter; import java.util.Arrays; @@ -46,62 +46,9 @@ */ public class JavaFileGenerator { - /** Logger */ + /** Logger. */ static private final Log log = LogFactory.getLog(JavaFileGenerator.class); - public static JavaField newField(int modifiers, - String returnType, - String name, - boolean override) { - return newField(modifiers, returnType, name, override, null); - } - - public static JavaField newField(int modifiers, - String returnType, - String name, - boolean override, - String initializer) { - return new JavaField(modifiers, - returnType, - name, - override, - initializer - ); - } - - public static JavaMethod newMethod(int modifiers, - String returnType, - String name, - String initializer, - boolean override, - String[] exceptions, - JavaArgument... arguments) { - return new JavaMethod(modifiers, - returnType, - name, - arguments, - exceptions, - initializer, - override - ); - } - - public static JavaMethod newMethod(int modifiers, - String returnType, - String name, - String initializer, - boolean override, - JavaArgument... arguments) { - return newMethod(modifiers, - returnType, - name, - initializer, - override, - StringUtil.EMPTY_STRING_ARRAY, - arguments - ); - } - public static String getHeader(String header) { String all = "/*-----------------------------------------------------------------------*/"; int size = header.length(); @@ -127,7 +74,7 @@ protected final boolean verbose; /** current prefix indent size */ - protected int indentationLevel = 0; + protected int indentationLevel; public JavaFileGenerator(String eol, boolean verbose) { this.eol = eol; @@ -144,21 +91,33 @@ log.info(name); } indentationLevel = 0; - if (name.contains(".")) { + String packageName = f.getPackageName(); +// if (name.contains(".")) { + if (packageName != null) { +// packageName = name.substring(0, name.lastIndexOf(".")); result.append("package "); - result.append(name.substring(0, name.lastIndexOf("."))); + result.append(packageName); result.append(";"); result.append(eol).append(eol); } - String[] imports = f.getImports(); - if (imports.length > 0) { - for (String anImport : imports) { - result.append(generateImport(anImport)); - } + generateImports(f, result); + + result.append(generateClass(f)); + } + + public void generateImports(JavaFile f, PrintWriter result) { + + List<String> imports = f.getImportsList(); + + boolean addImports = CollectionUtils.isNotEmpty(imports); + for (String anImport : imports) { + result.append(generateImport(anImport)); + } + + if (addImports) { result.append(eol); } - result.append(generateClass(f)); } public String generateClass(JavaFile f) { Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaMethod.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaMethod.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaMethod.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -71,13 +71,13 @@ * @param bodyCode Java source code which should appear in the method body * @param override flag with {@code true} value when the method overrides (or implements) a super class method */ - public JavaMethod(int modifiers, - String returnType, - String name, - JavaArgument[] arguments, - String[] exceptions, - String bodyCode, - boolean override) { + JavaMethod(int modifiers, + String returnType, + String name, + JavaArgument[] arguments, + String[] exceptions, + String bodyCode, + boolean override) { super(modifiers, name); this.returnType = returnType; this.override = override; @@ -127,6 +127,10 @@ return JavaElementComparator.compare(this, o); } + public void setReturnType(String returnType) { + this.returnType = returnType; + } + public enum MethodOrder { statics(Modifier.STATIC, "Statics methods"), Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptor.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptor.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptor.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -170,12 +170,16 @@ public MethodDescriptor getMethodDescriptor(String name, ClassDescriptor... parameterTypes) throws NoSuchMethodException { - for (MethodDescriptor methodDescriptor : methodDescriptors) { - if (methodDescriptor.getName().equals(name) && methodDescriptor.getParameterTypes().length == parameterTypes.length && Arrays.equals(methodDescriptor.getParameterTypes(), parameterTypes)) { - return methodDescriptor; + for (MethodDescriptor m : methodDescriptors) { + if (m.getName().equals(name) && + m.getParameterTypes().length == parameterTypes.length && + Arrays.equals(m.getParameterTypes(), parameterTypes)) { + return m; } } - throw new NoSuchMethodException("Could not find method " + name + "(" + Arrays.asList(parameterTypes) + ") in " + getName()); + throw new NoSuchMethodException( + "Could not find method " + name + "(" + + Arrays.asList(parameterTypes) + ") in " + getName()); } public FieldDescriptor[] getFieldDescriptors() { @@ -188,7 +192,8 @@ return fieldDescriptor; } } - throw new NoSuchFieldException("Could not find field " + name + " in " + getName()); + throw new NoSuchFieldException( + "Could not find field " + name + " in " + getName()); } public JAXXObjectDescriptor getJAXXObjectDescriptor() { Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -83,6 +83,13 @@ // on instance } + public static boolean isAssignableFrom(ClassDescriptor classDescriptor, + Class<?> awareClass) throws ClassNotFoundException { + ClassDescriptor awareDescriptor = getClassDescriptor(awareClass); + boolean result = awareDescriptor.isAssignableFrom(classDescriptor); + return result; + } + public static ClassDescriptor getClassDescriptor(String className) throws ClassNotFoundException { ClassDescriptor descriptor = getClassDescriptor(className, @@ -492,4 +499,8 @@ throw new RuntimeException(e); } } + + public static void setShowLoading(boolean b) { + SHOW_LOADING = b; + } } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,15 +25,19 @@ package jaxx.compiler.script; -import jaxx.compiler.*; +import jaxx.compiler.CompilerException; +import jaxx.compiler.JAXXCompiler; +import jaxx.compiler.finalizers.AbstractFinalizer; import jaxx.compiler.java.parser.JavaParser; import jaxx.compiler.java.parser.JavaParserTreeConstants; import jaxx.compiler.java.parser.SimpleNode; import jaxx.compiler.reflect.FieldDescriptor; import jaxx.compiler.reflect.MethodDescriptor; import jaxx.compiler.tags.TagManager; +import jaxx.runtime.JAXXUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.GeneratorUtil; import java.io.StringReader; import java.lang.reflect.Modifier; @@ -87,7 +91,8 @@ } /** - * Scans through a compound symbol (foo.bar.baz) to identify and compile the JAXX class it refers to, if any. + * Scans through a compound symbol (foo.bar.baz) to identify and compile + * the JAXX class it refers to, if any. * * @param symbol symbol to scan */ @@ -100,14 +105,16 @@ } currentSymbol.append(token.trim()); - String contextClass = TagManager.resolveClassName(currentSymbol.toString(), compiler); + String contextClass = TagManager.resolveClassName( + currentSymbol.toString(), compiler); if (contextClass != null) { compiler.addDependencyClass(contextClass); } } } - private void preprocessScriptNode(SimpleNode node, boolean staticContext) throws CompilerException { + private void preprocessScriptNode(SimpleNode node, + boolean staticContext) throws CompilerException { // identify static methods and initializers -- we can't fire events statically if (node.getId() == JavaParserTreeConstants.JJTMETHODDECLARATION) { if (node.getParent().getChild(0).getText().contains("static")) { @@ -125,7 +132,8 @@ } int id = node.getId(); - if (id == JavaParserTreeConstants.JJTNAME || id == JavaParserTreeConstants.JJTCLASSORINTERFACETYPE) { + if (id == JavaParserTreeConstants.JJTNAME || + id == JavaParserTreeConstants.JJTCLASSORINTERFACETYPE) { scanCompoundSymbol(node.getText()); } if (!staticContext) { @@ -133,7 +141,8 @@ if (id == JavaParserTreeConstants.JJTASSIGNMENTEXPRESSION || id == JavaParserTreeConstants.JJTPOSTFIXEXPRESSION && node.jjtGetNumChildren() == 2) { lhs = ((SimpleNode) node.jjtGetChild(0)).getText().trim(); - } else if (id == JavaParserTreeConstants.JJTPREINCREMENTEXPRESSION || id == JavaParserTreeConstants.JJTPREDECREMENTEXPRESSION) { + } else if (id == JavaParserTreeConstants.JJTPREINCREMENTEXPRESSION || + id == JavaParserTreeConstants.JJTPREDECREMENTEXPRESSION) { lhs = ((SimpleNode) node.jjtGetChild(0)).getText().trim(); } if (lhs != null) { @@ -141,7 +150,8 @@ for (FieldDescriptor field : fields) { if (field.getName().equals(lhs)) { //lhs.substring(lhs.lastIndexOf(".") + 1); - node.firstToken.image = "jaxx.runtime.JAXXUtil.assignment(" + node.firstToken.image; + compiler.addImport(JAXXUtil.class); + node.firstToken.image = "JAXXUtil.assignment(" + node.firstToken.image; String outputClassName = compiler.getOutputClassName(); node.lastToken.image = node.lastToken.image + ", \"" + lhs + "\", " + outputClassName + ".this)"; } @@ -272,7 +282,7 @@ compiler.appendBodyCode(node.getText()); compiler.addScriptMethod(new MethodDescriptor(name, Modifier.PUBLIC, returnType, parameterTypes.toArray(new String[parameterTypes.size()]), compiler.getClassLoader())); } else if (nodeType == JavaParserTreeConstants.JJTCLASSORINTERFACEDECLARATION || - nodeType == JavaParserTreeConstants.JJTINITIALIZER) { + nodeType == JavaParserTreeConstants.JJTINITIALIZER) { String str = node.getText().trim(); if (str.endsWith(";")) { str += ";"; @@ -317,7 +327,7 @@ } declaration = newDeclaration; } - + String[] declarationTokens = declaration.split("\\s"); boolean isFinal = Arrays.asList(declarationTokens).contains("final"); boolean isStatic = Arrays.asList(declarationTokens).contains("static"); @@ -327,13 +337,22 @@ } String className = declarationTokens[declarationTokens.length - 2]; if (log.isDebugEnabled()) { - log.debug("Found type : " + className +" : "+ Arrays.toString(declarationTokens)); + log.debug("Found type : " + className + " : " + + Arrays.toString(declarationTokens)); } String type = TagManager.resolveClassName(className, compiler); if (type == null) { - throw new CompilerException("Could not find type of " + className+" for expression " + text); + throw new CompilerException( + "Could not find type of " + className + + " for expression " + text); } +// className = className.trim(); +// if (!AbstractFinalizer.TYPE_STRING.equals(className) && +// !GeneratorUtil.isPrimitiveType(className)) { +// log.info("[" + compiler.getJavaFile().getName() + "] : Import " + type + " from a script..."); +// compiler.getJavaFile().addImport(type); +// } compiler.addScriptField(new FieldDescriptor(name, Modifier.PUBLIC, type, compiler.getClassLoader())); // TODO: determine the actual modifiers if (equals != -1 && !isFinal && !isStatic) { Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,51 +25,70 @@ package jaxx.compiler.tags; +import jaxx.compiler.CompiledObject; import jaxx.compiler.CompilerException; -import jaxx.compiler.UnsupportedAttributeException; -import jaxx.compiler.CompiledObject; import jaxx.compiler.I18nHelper; import jaxx.compiler.JAXXCompiler; +import jaxx.compiler.UnsupportedAttributeException; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Attr; import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import javax.swing.BorderFactory; +import javax.swing.border.TitledBorder; import java.awt.Component; import java.awt.Container; +import java.awt.Font; import java.awt.event.ComponentListener; import java.awt.event.ContainerListener; import java.awt.event.FocusListener; +import java.awt.event.KeyEvent; import java.beans.IntrospectionException; import java.io.IOException; import java.lang.reflect.Field; -import org.w3c.dom.Attr; -import org.w3c.dom.NamedNodeMap; - public class DefaultComponentHandler extends DefaultObjectHandler { + + public static final String BORDER_ATTRIBUTE = "border"; + public static final String ACTION_ICON_ATTRIBUTE = "actionIcon"; + public static final String CONTAINER_DELEGATE_ATTRIBUTE = "containerDelegate"; + public static final String FONT_FACE_ATTRIBUTE = "font-face"; + public static final String FONT_SIZE_ATTRIBUTE = "font-size"; + public static final String FONT_STYLE_ATTRIBUTE = "font-style"; + public static final String FONT_WEIGHT_ATTRIBUTE = "font-weight"; + public static final String HEIGHT_ATTRIBUTE = "height"; + public static final String ICON_ATTRIBUTE = "icon"; + public static final String NAME_ATTRIBUTE = "name"; + public static final String WIDTH_ATTRIBUTE = "width"; + public static final String X_ATTRIBUTE = "x"; + public static final String Y_ATTRIBUTE = "y"; - /** - * Logger - */ + + /** Logger */ protected static final Log log = LogFactory.getLog(DefaultComponentHandler.class); - /** - * container delegate (if any) - */ + + public static final String BORDER_FACTORY_PREFIX = BorderFactory.class.getSimpleName() + "."; + + public static final String TITLED_BORDER_PREFIX = TitledBorder.class.getSimpleName() + "("; + + /** container delegate (if any) */ private String containerDelegate; public DefaultComponentHandler(ClassDescriptor beanClass) { @@ -108,24 +127,30 @@ } @Override - protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) throws CompilerException { + protected void setDefaults(CompiledObject object, + Element tag, + JAXXCompiler compiler) throws CompilerException { super.setDefaults(object, tag, compiler); setAttribute(object, NAME_ATTRIBUTE, object.getId(), false, compiler); openComponent(object, tag, compiler); } @Override - public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + public void compileFirstPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { super.compileFirstPass(tag, compiler); } @Override - public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + public void compileSecondPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { super.compileSecondPass(tag, compiler); closeComponent(compiler.getOpenComponent(), tag, compiler); } - protected void openComponent(CompiledObject object, Element tag, JAXXCompiler compiler) throws CompilerException { + protected void openComponent(CompiledObject object, + Element tag, + JAXXCompiler compiler) throws CompilerException { String constraints = tag.getAttribute(CONSTRAINTS_ATTRIBUTE); if (constraints != null && constraints.length() > 0) { compiler.openComponent(object, constraints); @@ -134,7 +159,9 @@ } } - protected void closeComponent(CompiledObject object, Element tag, JAXXCompiler compiler) throws CompilerException { + protected void closeComponent(CompiledObject object, + Element tag, + JAXXCompiler compiler) throws CompilerException { compiler.closeComponent(object); } @@ -144,86 +171,103 @@ } @Override - public ClassDescriptor getPropertyType(CompiledObject object, String propertyName, JAXXCompiler compiler) throws CompilerException { - if (propertyName.equals(X_ATTRIBUTE) || - propertyName.equals(Y_ATTRIBUTE) || - propertyName.equals(WIDTH_ATTRIBUTE) || - propertyName.equals(HEIGHT_ATTRIBUTE) || - FONT_SIZE_ATTRIBUTE.equals(propertyName)) { + public ClassDescriptor getPropertyType(CompiledObject object, + String propertyName, + JAXXCompiler compiler) throws CompilerException { + if (X_ATTRIBUTE.equals(propertyName) || + Y_ATTRIBUTE.equals(propertyName) || + WIDTH_ATTRIBUTE.equals(propertyName) || + HEIGHT_ATTRIBUTE.equals(propertyName) || + FONT_SIZE_ATTRIBUTE.equals(propertyName)) { return ClassDescriptorHelper.getClassDescriptor(Integer.class); } - if (propertyName.equals(FONT_FACE_ATTRIBUTE) || - propertyName.equals(FONT_STYLE_ATTRIBUTE) || - propertyName.equals(FONT_WEIGHT_ATTRIBUTE)) { + if (FONT_FACE_ATTRIBUTE.equals(propertyName) || + FONT_STYLE_ATTRIBUTE.equals(propertyName) || + FONT_WEIGHT_ATTRIBUTE.equals(propertyName)) { return ClassDescriptorHelper.getClassDescriptor(String.class); } return super.getPropertyType(object, propertyName, compiler); } @Override - public String getGetPropertyCode(String id, String name, JAXXCompiler compiler) throws CompilerException { - if (name.equals(FONT_FACE_ATTRIBUTE)) { + public String getGetPropertyCode(String id, + String name, + JAXXCompiler compiler) throws CompilerException { + if (FONT_FACE_ATTRIBUTE.equals(name)) { return id + ".getFont().getFontName()"; } - if (name.equals(FONT_SIZE_ATTRIBUTE)) { + if (FONT_SIZE_ATTRIBUTE.equals(name)) { return id + ".getFont().getSize()"; } - if (name.equals(FONT_WEIGHT_ATTRIBUTE)) { + if (FONT_WEIGHT_ATTRIBUTE.equals(name)) { + compiler.addImport(Font.class); return "(" + id + ".getFont().getStyle() & Font.BOLD) != 0 ? \"bold\" : \"normal\""; } - if (name.equals(FONT_STYLE_ATTRIBUTE)) { + if (FONT_STYLE_ATTRIBUTE.equals(name)) { + compiler.addImport(Font.class); return "(" + id + ".getFont().getStyle() & Font.ITALIC) != 0 ? \"italic\" : \"normal\""; } return super.getGetPropertyCode(id, name, compiler); } @Override - public String getSetPropertyCode(String id, String name, String valueCode, JAXXCompiler compiler) throws CompilerException { - if (name.equals(X_ATTRIBUTE)) { + public String getSetPropertyCode(String id, + String name, + String valueCode, + JAXXCompiler compiler) throws CompilerException { + if (X_ATTRIBUTE.equals(name)) { return id + ".setLocation(" + valueCode + ", " + id + ".getY());"; } - if (name.equals(Y_ATTRIBUTE)) { + if (Y_ATTRIBUTE.equals(name)) { return id + ".setLocation(" + id + ".getX(), " + valueCode + ");"; } - if (name.equals(WIDTH_ATTRIBUTE)) { + if (WIDTH_ATTRIBUTE.equals(name)) { // need to optimize case when both width and height are being assigned return SwingUtil.class.getSimpleName() + ".setComponentWidth(" + id + "," + valueCode + ");"; } - if (name.equals(HEIGHT_ATTRIBUTE)) { + if (HEIGHT_ATTRIBUTE.equals(name)) { return SwingUtil.class.getSimpleName() + ".setComponentHeight(" + id + "," + valueCode + ");"; } - if (name.equals(FONT_FACE_ATTRIBUTE)) { + if (FONT_FACE_ATTRIBUTE.equals(name)) { + compiler.addImport(Font.class); return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(new Font(" + valueCode + ", " + id + ".getFont().getStyle(), " + id + ".getFont().getSize()));\n}"; } - if (name.equals(FONT_SIZE_ATTRIBUTE)) { + if (FONT_SIZE_ATTRIBUTE.equals(name)) { + compiler.addImport(Font.class); return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont((float) " + valueCode + "));\n}"; } - if (name.equals(FONT_WEIGHT_ATTRIBUTE)) { + if (FONT_WEIGHT_ATTRIBUTE.equals(name)) { if (valueCode.equals("\"bold\"")) { + compiler.addImport(Font.class); return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | Font.BOLD));\n}"; } if (valueCode.equals("\"normal\"")) { + compiler.addImport(Font.class); return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~Font.BOLD));\n}"; } if (!valueCode.startsWith("\"")) { + compiler.addImport(Font.class); return "if (" + id + ".getFont() != null) {\n if ((" + valueCode + ").equals(\"bold\")) {\n " + - id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | Font.BOLD));\n } else {\n " + - id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~Font.BOLD));\n }\n}"; + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | Font.BOLD));\n } else {\n " + + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~Font.BOLD));\n }\n}"; } compiler.reportError("font-weight must be either \"normal\" or \"bold\", found " + valueCode); return ""; } - if (name.equals(FONT_STYLE_ATTRIBUTE)) { + if (FONT_STYLE_ATTRIBUTE.equals(name)) { if (valueCode.equals("\"italic\"")) { + compiler.addImport(Font.class); return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | Font.ITALIC));\n}"; } if (valueCode.equals("\"normal\"")) { + compiler.addImport(Font.class); return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~Font.ITALIC));\n}"; } if (!valueCode.startsWith("\"")) { + compiler.addImport(Font.class); return "if (" + id + ".getFont() != null) {\n if ((" + valueCode + ").equals(\"italic\")) {\n " + - id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | Font.ITALIC));\n } else {\n " + - id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~Font.ITALIC));\n }\n}"; + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | Font.ITALIC));\n } else {\n " + + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~Font.ITALIC));\n }\n}"; } compiler.reportError("font-style must be either \"normal\" or \"italic\", found " + valueCode); return ""; @@ -256,13 +300,20 @@ //object.appendAdditionCode(object.getJavaCode() + ".putClientProperty(\"" + propertyName.substring(1) + "\", " + stringValue + ");"); return; } + if (BORDER_ATTRIBUTE.equals(propertyName)) { + if (stringValue.contains(BORDER_FACTORY_PREFIX)) { + compiler.addImport(BorderFactory.class); + } else if (stringValue.contains(TITLED_BORDER_PREFIX)) { + compiler.addImport(TitledBorder.class); + } + } if (ICON_ATTRIBUTE.equals(propertyName)) { if (!(stringValue.startsWith("{") || stringValue.endsWith("}"))) { // this is a customized icon, add the icon creation code if (compiler.getConfiguration().isUseUIManagerForIcon()) { - stringValue = "{" + SwingUtil.class.getName() + ".getUIManagerIcon(\"" + stringValue + "\")}"; + stringValue = "{" + SwingUtil.class.getSimpleName() + ".getUIManagerIcon(\"" + stringValue + "\")}"; } else { - stringValue = "{" + SwingUtil.class.getName() + ".createImageIcon(\"" + stringValue + "\")}"; + stringValue = "{" + SwingUtil.class.getSimpleName() + ".createImageIcon(\"" + stringValue + "\")}"; } } } else if (ACTION_ICON_ATTRIBUTE.equals(propertyName)) { @@ -274,16 +325,17 @@ } propertyName = ICON_ATTRIBUTE; if (compiler.getConfiguration().isUseUIManagerForIcon()) { - stringValue = "{" + SwingUtil.class.getName() + ".getUIManagerActionIcon(\"" + stringValue + "\")}"; + stringValue = "{" + SwingUtil.class.getSimpleName() + ".getUIManagerActionIcon(\"" + stringValue + "\")}"; } else { - stringValue = "{" + SwingUtil.class.getName() + ".createActionIcon(\"" + stringValue + "\")}"; + stringValue = "{" + SwingUtil.class.getSimpleName() + ".createActionIcon(\"" + stringValue + "\")}"; } } super.setAttribute(object, propertyName, stringValue, inline, compiler); } @Override - protected void scanAttributesForDependencies(Element tag, JAXXCompiler compiler) { + protected void scanAttributesForDependencies(Element tag, + JAXXCompiler compiler) { super.scanAttributesForDependencies(tag, compiler); // check for clientProperty attributes //FIXME make this works,... it seems jaxx compiler does not come here ? @@ -319,12 +371,13 @@ */ @Override protected int constantValue(String key, String value) { - if ((key.equals(MNEMONIC_ATTRIBUTE) || key.equals(DISPLAYED_MNEMONIC_ATTRIBUTE))) { + if (key.equals(MNEMONIC_ATTRIBUTE) || + key.equals(DISPLAYED_MNEMONIC_ATTRIBUTE)) { if (value.length() == 1) { return value.charAt(0); } try { - Field vk = java.awt.event.KeyEvent.class.getField(value); + Field vk = KeyEvent.class.getField(value); return (Integer) vk.get(null); } catch (NoSuchFieldException e) { throw new IllegalArgumentException("mnemonics must be either a single character or the name of a field in KeyEvent (found: '" + value + "')"); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -52,6 +52,8 @@ import org.w3c.dom.NodeList; import org.w3c.dom.Text; +import java.awt.BorderLayout; +import java.awt.GridLayout; import java.beans.IntrospectionException; import java.beans.Introspector; import java.io.IOException; @@ -107,6 +109,10 @@ public static final String SUPER_GENERIC_TYPE_ATTRIBUTE = "superGenericType"; + public static final String GRID_LAYOUT_PREFIX = GridLayout.class.getSimpleName() + "("; + + public static final String BORDER_LAYOUT_PREFIX = BorderLayout.class.getSimpleName() + "("; + /** The class that this handler provides support for. */ private ClassDescriptor beanClass; @@ -299,7 +305,8 @@ } else if (name.startsWith("is")) { propertyName = Introspector.decapitalize(name.substring("is".length())); } - JAXXPropertyDescriptor property = propertyName != null ? properties.get(propertyName) : null; + JAXXPropertyDescriptor property = propertyName != null ? + properties.get(propertyName) : null; if (property != null) { return property.isBound(); } @@ -445,13 +452,15 @@ } @Override - public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + public void compileFirstPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { scanAttributesForDependencies(tag, compiler); compileChildrenFirstPass(tag, compiler); } @Override - public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + public void compileSecondPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { safeInit(); CompiledObject object = objectMap.get(tag); if (object == null) { @@ -595,7 +604,9 @@ * @param tag the tag from which to pull attributes * @param compiler the current <code>JAXXCompiler</code> */ - public void setAttributes(CompiledObject object, Element tag, JAXXCompiler compiler) { + public void setAttributes(CompiledObject object, + Element tag, + JAXXCompiler compiler) { List<Attr> attributes = new ArrayList<Attr>(); NamedNodeMap children = tag.getAttributes(); for (int i = 0; i < children.getLength(); i++) { @@ -636,7 +647,9 @@ compiler.reportError("'" + IMPLEMENTS_ATTRIBUTE + "' attribute can only be found on root tag but was found on tag " + tag); return; } - String[] interfaces = value.split(","); + //tchemit 2011-01-29 reuse what was filled in symbols table + String[] interfaces = compiler.getSymbolTable().getInterfaces(); +// String[] interfaces = value.split(","); compiler.setExtraInterfaces(interfaces); continue; } @@ -673,7 +686,8 @@ if (name.equals(DECORATOR_ATTRIBUTE)) { if (!value.isEmpty()) { - CompiledObjectDecorator decorator = compiler.getEngine().getDecorator(value); + CompiledObjectDecorator decorator = + compiler.getEngine().getDecorator(value); object.setDecorator(decorator); } continue; @@ -684,7 +698,11 @@ if (!value.endsWith(";")) { value += ";"; } - addEventHandler(object, Introspector.decapitalize(name.substring(2)), value, compiler); + addEventHandler(object, + Introspector.decapitalize(name.substring(2)), + value, + compiler + ); continue; } // simple property @@ -803,8 +821,13 @@ if (!withBinding) { // no bindings, convert from string try { - Class<?> typeClass = type != null ? ClassDescriptorHelper.getClass(type.getName(), type.getClassLoader()) : null; - Object value = convertFromString(propertyName, stringValue, typeClass); + Class<?> typeClass = type != null ? + ClassDescriptorHelper.getClass(type.getName(), type.getClassLoader()) : + null; + Object value = convertFromString(propertyName, + stringValue, + typeClass + ); setProperty(object, propertyName, value, compiler); return; } catch (NumberFormatException e) { @@ -817,11 +840,22 @@ } String setPropertyCode = getSetPropertyCode(object.getJavaCode(), propertyName, binding, compiler); if (propertyName.equals(LAYOUT_ATTRIBUTE)) { + + // try to add the layout class in imports + if (setPropertyCode.contains(BORDER_LAYOUT_PREFIX)) { + compiler.addImport(BorderLayout.class); + } else if (setPropertyCode.contains(GRID_LAYOUT_PREFIX)) { + compiler.addImport(GridLayout.class); + } // handle containerDelegate (e.g. contentPane on JFrame) // have to set layout early, before children are added object.appendInitializationCode(setPropertyCode); } - compiler.getBindingHelper().registerDataBinding(object.getId() + "." + propertyName, binding, setPropertyCode); + compiler.getBindingHelper().registerDataBinding( + object.getId() + "." + propertyName, + binding, + setPropertyCode + ); } catch (UnsupportedAttributeException e) { compiler.reportError("class " + object.getObjectClass().getName() + " does not support attribute '" + propertyName + "'"); } @@ -831,7 +865,9 @@ applyStylesheets(object, compiler, null); } - private void applyStylesheets(CompiledObject object, JAXXCompiler compiler, Stylesheet overrides) { + private void applyStylesheets(CompiledObject object, + JAXXCompiler compiler, + Stylesheet overrides) { applyStylesheets(object, compiler, overrides, true); } @@ -861,7 +897,11 @@ // this is the safe mode to use, just apply stlySheet to object if (stylesheet != null) { - StylesheetHelper.applyTo(object, compiler, stylesheet, overrides); + StylesheetHelper.applyTo(object, + compiler, + stylesheet, + overrides + ); } return; } @@ -928,10 +968,14 @@ * @param value the Java code snippet to execute when the event is fired * @param compiler the current <code>JAXXCompiler</code> */ - public void addEventHandler(CompiledObject object, String name, String value, JAXXCompiler compiler) { + public void addEventHandler(CompiledObject object, + String name, + String value, + JAXXCompiler compiler) { JAXXEventSetDescriptor JAXXEventSetDescriptor = events.get(name); if (JAXXEventSetDescriptor != null) { - MethodDescriptor[] listenerMethods = JAXXEventSetDescriptor.getListenerMethods(); + MethodDescriptor[] listenerMethods = + JAXXEventSetDescriptor.getListenerMethods(); MethodDescriptor listenerMethod = null; for (MethodDescriptor listenerMethod1 : listenerMethods) { if (listenerMethod1.getName().equals(name)) { @@ -944,7 +988,13 @@ } try { value = compiler.preprocessScript(value); - object.addEventHandler(name, JAXXEventSetDescriptor.getAddListenerMethod(), listenerMethod, value, compiler); + object.addEventHandler( + name, + JAXXEventSetDescriptor.getAddListenerMethod(), + listenerMethod, + value, + compiler + ); } catch (CompilerException e) { compiler.reportError("While parsing event handler for '" + name + "': " + e.getMessage()); } @@ -963,7 +1013,9 @@ * @return the snippet * @throws CompilerException if a compilation error occurs */ - public String getGetPropertyCode(String javaCode, String name, JAXXCompiler compiler) { + public String getGetPropertyCode(String javaCode, + String name, + JAXXCompiler compiler) { safeInit(); JAXXPropertyDescriptor property = properties.get(name); @@ -987,7 +1039,10 @@ * @return the snippet * @throws CompilerException if a compilation error occurs */ - public String getSetPropertyCode(String javaCode, String name, String valueCode, JAXXCompiler compiler) { + public String getSetPropertyCode(String javaCode, + String name, + String valueCode, + JAXXCompiler compiler) { JAXXPropertyDescriptor property = properties.get(name); if (property != null) { if (property.getWriteMethodDescriptor() != null) { @@ -1020,8 +1075,17 @@ * @param compiler the current <code>JAXXCompiler</code> * @throws CompilerException if a compilation error occurs */ - public void setProperty(CompiledObject object, String name, Object value, JAXXCompiler compiler) { - object.appendInitializationCode(getSetPropertyCode(object.getJavaCodeForProperty(name), name, TypeManager.getJavaCode(value), compiler)); + public void setProperty(CompiledObject object, + String name, + Object value, + JAXXCompiler compiler) { + object.appendInitializationCode( + getSetPropertyCode(object.getJavaCodeForProperty(name), + name, + TypeManager.getJavaCode(value), + compiler + ) + ); } /** @@ -1041,11 +1105,13 @@ */ protected int constantValue(String key, String value) { JAXXBeanInfo JAXXBeanInfo = getJAXXBeanInfo(); - JAXXPropertyDescriptor[] props = JAXXBeanInfo.getJAXXPropertyDescriptors(); + JAXXPropertyDescriptor[] props = + JAXXBeanInfo.getJAXXPropertyDescriptors(); String lowercaseValue = value.toLowerCase(); for (JAXXPropertyDescriptor property : props) { if (property.getName().equals(key)) { - Object[] values = (Object[]) property.getValue("enumerationValues"); + Object[] values = (Object[]) + property.getValue("enumerationValues"); if (values != null) { for (int j = 0; j < values.length - 2; j += 3) { if (((String) values[j]).toLowerCase().equals(lowercaseValue)) { @@ -1053,7 +1119,9 @@ } } - StringBuffer message = new StringBuffer("value of '" + key + "' must be one of: ["); + StringBuffer message = + new StringBuffer("value of '" + + key + "' must be one of: ["); for (int j = 0; j < values.length - 2; j += 3) { if (j != 0) { message.append(", "); @@ -1102,7 +1170,8 @@ * @throws CompilerException if a compilation error occurs * @throws IOException if an I/O error occurs */ - protected void compileChildrenFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + protected void compileChildrenFirstPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { NodeList children = tag.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); @@ -1123,7 +1192,8 @@ * @throws CompilerException if a compilation error occurs * @throws IOException if an I/O error occurs */ - protected void compileChildrenSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + protected void compileChildrenSecondPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { NodeList children = tag.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); @@ -1149,7 +1219,8 @@ * @throws CompilerException if a compilation error occurs * @throws IOException if an I/O error occurs */ - protected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + protected void compileChildTagFirstPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { compiler.compileFirstPass(tag); } @@ -1162,7 +1233,8 @@ * @throws CompilerException if a compilation error occurs * @throws IOException if an I/O error occurs */ - protected void compileChildTagSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + protected void compileChildTagSecondPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { compiler.compileSecondPass(tag); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/TagHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/TagHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/TagHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -53,7 +53,8 @@ * @throws CompilerException if a compilation error occurs * @throws IOException if an I/O error occurs */ - void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException; + void compileFirstPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException; /** * Performs the second pass of compilation on an XML tag from a JAXX source file. @@ -65,5 +66,6 @@ * @throws CompilerException if a compilation error occurs * @throws IOException if an I/O error occurs */ - void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException; + void compileSecondPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException; } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,39 +25,61 @@ package jaxx.compiler.tags.swing; +import jaxx.compiler.CompiledObject; import jaxx.compiler.CompilerException; -import jaxx.compiler.CompiledObject; import jaxx.compiler.JAXXCompiler; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; +import jaxx.compiler.types.TypeManager; import jaxx.runtime.swing.Application; -import jaxx.compiler.types.TypeManager; import org.w3c.dom.Element; import javax.swing.WindowConstants; public class ApplicationHandler extends JWindowHandler { + public static final String ATTRIBUTE_LOOK_AND_FEEL = "lookAndFeel"; public static final String ATTRIBUTE_DEFAULT_CLOSE_OPERATION = "defaultCloseOperation"; public ApplicationHandler(ClassDescriptor beanClass) { super(beanClass); - ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, Application.class); + ClassDescriptorHelper.checkSupportClass(getClass(), + beanClass, + Application.class + ); } @Override - public void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler) throws CompilerException { - if (propertyName.equals(ATTRIBUTE_LOOK_AND_FEEL) && stringValue != null && !stringValue.trim().startsWith("{")) { + public void setAttribute(CompiledObject object, + String propertyName, + String stringValue, + boolean inline, + JAXXCompiler compiler) throws CompilerException { + if (propertyName.equals(ATTRIBUTE_LOOK_AND_FEEL) && + stringValue != null && + !stringValue.trim().startsWith("{")) { compiler.appendBodyCode("{ " + object.getJavaCode() + ".setLookAndFeel(" + TypeManager.getJavaCode(stringValue) + "); }" + JAXXCompiler.getLineSeparator()); } else { - super.setAttribute(object, propertyName, stringValue, inline, compiler); + super.setAttribute(object, + propertyName, + stringValue, + inline, + compiler + ); } } @Override - protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) throws CompilerException { + protected void setDefaults(CompiledObject object, + Element tag, + JAXXCompiler compiler) throws CompilerException { super.setDefaults(object, tag, compiler); - setAttribute(object, ATTRIBUTE_DEFAULT_CLOSE_OPERATION, String.valueOf(WindowConstants.EXIT_ON_CLOSE), false, compiler); + setAttribute(object, + ATTRIBUTE_DEFAULT_CLOSE_OPERATION, + String.valueOf(WindowConstants.EXIT_ON_CLOSE), + false, + compiler + ); } } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,10 +25,10 @@ package jaxx.compiler.tags.swing; +import jaxx.compiler.CompiledObject; import jaxx.compiler.CompilerException; +import jaxx.compiler.JAXXCompiler; import jaxx.compiler.UnsupportedAttributeException; -import jaxx.compiler.CompiledObject; -import jaxx.compiler.JAXXCompiler; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.compiler.tags.DefaultComponentHandler; @@ -36,11 +36,13 @@ import jaxx.runtime.swing.JAXXButtonGroup; import javax.swing.AbstractButton; +import javax.swing.ButtonGroup; import javax.swing.event.ChangeListener; public class JRadioButtonHandler extends DefaultComponentHandler { private static final String VALUE_PROPERTY = JAXXButtonGroup.VALUE_CLIENT_PROPERTY.substring(1); + private static final String BUTTON_GROUP_PROPERTY = JAXXButtonGroup.BUTTON8GROUP_CLIENT_PROPERTY.substring(1); public JRadioButtonHandler(ClassDescriptor beanClass) { @@ -91,10 +93,15 @@ compiler.registerCompiledObject(buttonGroup); } } - return "{ javax.swing.ButtonGroup $buttonGroup = " + valueCode + "; " + id + ".putClientProperty(\"$buttonGroup\", $buttonGroup); $buttonGroup.add(" + id + "); }\n"; + String type = compiler.getImportManager().getType( + ButtonGroup.class.getName()); + + return "{ " + type + " $buttonGroup = " + valueCode + "; " + id + ".putClientProperty(\"$buttonGroup\", $buttonGroup); $buttonGroup.add(" + id + "); }\n"; } else if (name.equals(VALUE_PROPERTY)) { + String type = compiler.getImportManager().getType( + JAXXButtonGroup.class.getName()); return "{ " + id + ".putClientProperty(\"" + JAXXButtonGroup.VALUE_CLIENT_PROPERTY + "\", " + valueCode + "); Object $buttonGroup = " + id + ".getClientProperty(\"" + JAXXButtonGroup.BUTTON8GROUP_CLIENT_PROPERTY + "\");" + - " if ($buttonGroup instanceof jaxx.runtime.swing.JAXXButtonGroup) { ((jaxx.runtime.swing.JAXXButtonGroup) $buttonGroup).updateSelectedValue(); } }\n"; + " if ($buttonGroup instanceof " + type + ") { ((" + type + ") $buttonGroup).updateSelectedValue(); } }\n"; } else { return super.getSetPropertyCode(id, name, valueCode, compiler); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -53,15 +53,26 @@ public JTextComponentHandler(ClassDescriptor beanClass) { super(beanClass); - ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, JTextComponent.class); + ClassDescriptorHelper.checkSupportClass(getClass(), + beanClass, + JTextComponent.class); } @Override - protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) throws CompilerException { + protected void setDefaults(CompiledObject object, + Element tag, + JAXXCompiler compiler) throws CompilerException { super.setDefaults(object, tag, compiler); try { - object.getObjectClass().getMethodDescriptor("setColumns", ClassDescriptorHelper.getClassDescriptor(int.class)); - setAttribute(object, ATTRIBUTE_COLUMNS, String.valueOf(DEFAULT_COLUMNS), false, compiler); + object.getObjectClass().getMethodDescriptor("setColumns", + ClassDescriptorHelper.getClassDescriptor(int.class) + ); + setAttribute(object, + ATTRIBUTE_COLUMNS, + String.valueOf(DEFAULT_COLUMNS), + false, + compiler + ); } catch (NoSuchMethodException e) { // ignore ? } @@ -73,10 +84,15 @@ } @Override - public String getSetPropertyCode(String id, String name, String valueCode, JAXXCompiler compiler) throws CompilerException { + public String getSetPropertyCode(String id, + String name, + String valueCode, + JAXXCompiler compiler) throws CompilerException { if (name.equals(ATTRIBUTE_TEXT)) { - return SwingUtil.class.getName() + ".setText(" + id + ", " + valueCode + ");\n"; - //return "jaxx.runtime.swing.Utils.setText(" + id + ", " + valueCode + ");\n"; + compiler.addImport(SwingUtil.class); + return SwingUtil.class.getSimpleName() + ".setText(" + + id + ", " + valueCode + ");" + + JAXXCompiler.getLineSeparator(); } return super.getSetPropertyCode(id, name, valueCode, compiler); } @@ -85,7 +101,7 @@ protected int getAttributeOrdering(Attr attr) { // delay text in case other attributes affect how it's processed, as is the case // with JEditorPane's contentType - if (attr.getName().equals(ATTRIBUTE_TEXT)) { + if (ATTRIBUTE_TEXT.equals(attr.getName())) { return 1; } return super.getAttributeOrdering(attr); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JToolBarHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JToolBarHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JToolBarHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -33,9 +33,9 @@ import javax.swing.JToolBar; public class JToolBarHandler extends DefaultComponentHandler { + public static final String ATTRIBUTE_ORIENTATION = "orientation"; - enum Orientation { horizontal(JToolBar.HORIZONTAL), vertical(JToolBar.VERTICAL); @@ -53,7 +53,10 @@ public JToolBarHandler(ClassDescriptor beanClass) { super(beanClass); - ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, JToolBar.class); + ClassDescriptorHelper.checkSupportClass(getClass(), + beanClass, + JToolBar.class + ); } /** @@ -63,11 +66,13 @@ */ @Override protected int constantValue(String key, String value) { - if (key.equals(ATTRIBUTE_ORIENTATION)) { + if (ATTRIBUTE_ORIENTATION.equals(key)) { value = value.trim().toLowerCase(); Orientation fill = Orientation.valueOf(value); if (fill == null) { - throw new CompilerException("invalid value for orientation attribute: '" + value + "'"); + throw new CompilerException( + "invalid value for orientation attribute: '" + value + + "'"); } return fill.getIntValue(); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,10 +25,10 @@ package jaxx.compiler.tags.swing; +import jaxx.compiler.CompiledObject; import jaxx.compiler.CompilerException; +import jaxx.compiler.JAXXCompiler; import jaxx.compiler.UnsupportedAttributeException; -import jaxx.compiler.CompiledObject; -import jaxx.compiler.JAXXCompiler; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.compiler.tags.DefaultComponentHandler; @@ -46,7 +46,9 @@ public TableHandler(ClassDescriptor beanClass) { super(beanClass); - ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, Table.class); + ClassDescriptorHelper.checkSupportClass(getClass(), + beanClass, + Table.class); } @Override @@ -82,9 +84,13 @@ class CompiledTable extends CompiledObject { private List<Integer> rowSpans = new ArrayList<Integer>(); + private GridBagConstraints tableConstraints; + private GridBagConstraints rowConstraints; + private GridBagConstraints cellConstraints; + private boolean emptyCell; public CompiledTable(String id, @@ -95,6 +101,8 @@ tableConstraints.gridx = -1; tableConstraints.gridy = -1; tableConstraints.insets = DEFAULT_INSETS; + compiler.addImport(GridBagConstraints.class.getName()); + compiler.addImport(Insets.class.getName()); } @Override Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -258,7 +258,8 @@ } protected static ClassDescriptor getDescriptor( - ClassDescriptor objectClass, JAXXCompiler compiler) { + ClassDescriptor objectClass, + JAXXCompiler compiler) { Class<?> validatorClass = SwingValidator.class; // compiler.getConfiguration().getValidatorClass(); ClassDescriptor result = Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/ExcludeFieldValidatorHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/ExcludeFieldValidatorHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/ExcludeFieldValidatorHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -27,6 +27,7 @@ import jaxx.compiler.CompilerException; import jaxx.compiler.JAXXCompiler; +import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.compiler.tags.TagHandler; import jaxx.compiler.tags.validator.BeanValidatorHandler.CompiledBeanValidator; @@ -46,7 +47,8 @@ static private Log log = LogFactory.getLog(ExcludeFieldValidatorHandler.class); @Override - public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + public void compileFirstPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { if (compiler.getConfiguration().isVerbose()) { log.info(tag); } @@ -54,32 +56,45 @@ } @Override - public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + public void compileSecondPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { if (compiler.getConfiguration().isVerbose()) { log.debug(tag); } - if (!ClassDescriptorHelper.getClassDescriptor(SwingValidator.class).isAssignableFrom(compiler.getOpenComponent().getObjectClass())) { - compiler.reportError(TAG + " tag may only appear within " + BeanValidatorHandler.TAG + " tag but was " + tag); + ClassDescriptor descriptor = + ClassDescriptorHelper.getClassDescriptor(SwingValidator.class); + if (!descriptor.isAssignableFrom( + compiler.getOpenComponent().getObjectClass())) { + compiler.reportError(TAG + " tag may only appear within " + + BeanValidatorHandler.TAG + " tag but was " + + tag); return; } - CompiledBeanValidator info = (CompiledBeanValidator) compiler.getOpenComponent(); + CompiledBeanValidator info = + (CompiledBeanValidator) compiler.getOpenComponent(); if (!info.getAutoField()) { - compiler.reportError(TAG + " tag can not be used without an 'autoField' validator : " + tag); + compiler.reportError(TAG + " tag can not be used without an " + + "'autoField' validator : " + tag); return; } String name = tag.getAttribute(NAME_ATTRIBUTE); String component = tag.getAttribute(COMPONENT_ATTRIBUTE); if (name == null || name.trim().isEmpty()) { - compiler.reportError(TAG + " tag requires a " + NAME_ATTRIBUTE + " attribute"); + compiler.reportError(TAG + " tag requires a " + NAME_ATTRIBUTE + + " attribute"); return; } name = name.trim(); if (component == null || component.trim().isEmpty()) { // try to use the name as component if (!compiler.checkReference(tag, name, false, name)) { - compiler.reportError(TAG + " tag requires a " + COMPONENT_ATTRIBUTE + " attribute, try to use the name attribute [" + name + "] for the component, but no such component found"); + compiler.reportError(TAG + " tag requires a " + + COMPONENT_ATTRIBUTE + " attribute, try " + + "to use the name attribute [" + name + + "] for the component, but no such " + + "component found"); return; } component = name; @@ -88,11 +103,15 @@ // check component is not already used by this compiled object if (info.getFields().containsValue(component)) { - compiler.reportError(TAG + " tag found a attribute " + COMPONENT_ATTRIBUTE + " [" + component + "] already used in this validator"); + compiler.reportError(TAG + " tag found a attribute " + + COMPONENT_ATTRIBUTE + " [" + component + + "] already used in this validator"); return; } if (info.getExcludeFields().containsValue(component)) { - compiler.reportError(TAG + " tag found a attribute " + COMPONENT_ATTRIBUTE + " [" + component + "] already used in this validator"); + compiler.reportError(TAG + " tag found a attribute " + + COMPONENT_ATTRIBUTE + " [" + component + + "] already used in this validator"); return; } // check component exist (again perharps, but let the error knows exactly which tag failed...) Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -51,7 +51,8 @@ /** Logger */ static private Log log = LogFactory.getLog(FieldValidatorHandler.class); - public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + public void compileFirstPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { if (compiler.getConfiguration().isVerbose()) { log.debug(tag); } @@ -59,7 +60,8 @@ } @Override - public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + public void compileSecondPass(Element tag, + JAXXCompiler compiler) throws CompilerException, IOException { if (compiler.getConfiguration().isVerbose()) { log.debug(tag); } @@ -105,7 +107,8 @@ complexType = true; // means a complex reference (says a java Code in facts) - component = compiler.preprocessScript(component.substring(1, component.length() - 1)); + component = compiler.preprocessScript( + component.substring(1, component.length() - 1)); } if (log.isDebugEnabled()) { Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateTask.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateTask.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateTask.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -27,10 +27,18 @@ import jaxx.compiler.JAXXCompiler; import jaxx.compiler.JAXXCompilerFile; import jaxx.compiler.JAXXEngine; +import jaxx.compiler.java.JavaFile; import jaxx.compiler.java.JavaFileGenerator; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.java.extension.ImportsManager; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + /** * Last task to generate java files. * @@ -54,7 +62,7 @@ // check all files are attached to a compiler checkAllFilesCompiled(engine); - + boolean success = true; boolean verbose = engine.isVerbose(); @@ -63,16 +71,21 @@ new JavaFileGenerator(JAXXCompiler.getLineSeparator(), verbose); JAXXCompilerFile[] files = engine.getCompiledFiles(); - + for (JAXXCompilerFile jaxxFile : files) { - if (verbose) { log.info("start " + jaxxFile.getClassName()); } JAXXCompiler compiler = jaxxFile.getCompiler(); + addStartProfileTime(engine, compiler); - compiler.generate(generator); + + try { + consumeCompiler(compiler, generator); + } finally { + compiler.getJavaFile().clear(); + } addEndProfileTime(engine, compiler); if (compiler.isFailed()) { success = false; @@ -80,4 +93,110 @@ } return success; } + + public void consumeCompiler(JAXXCompiler compiler, + JavaFileGenerator generator) throws IOException { + + JavaFile javaFile = compiler.getJavaFile(); + + String packageName = javaFile.getPackageName(); + + // optimize imports + List<String> imports = optimizeImports( + javaFile, + packageName); + + String packageToExclude = packageName + ".*"; + + // push back previous imports + for (String importFQN : javaFile.getImports()) { + if (!packageToExclude.equals(importFQN) && + !imports.contains(importFQN)) { + imports.add(importFQN); + } + } + + // set them to the file to generate + javaFile.setImports(imports); + + + // generate java file + compiler.generate(generator); + } + + public List<String> optimizeImports(JavaFile f, String packageName) { + + ImportsManager importsManager = f.getImportManager(); + + // all jaxx files needs it +// importsManager.addImport(Container.class); +// importsManager.addImport(JAXXUtil.class); +// importsManager.addImport(SwingUtil.class); +// importsManager.addImport(List.class); +// importsManager.addImport(Map.class); + + List<String> result; + + for (String importFQN : f.getImports()) { + if (log.isDebugEnabled()) { + log.debug("Add import : " + importFQN); + } + importsManager.addImport(importFQN); + } + + if (f.getSuperClass() != null) { + String superClass = f.getSuperClass(); + try { + String type = importsManager.getType(superClass); + f.setSuperClass(type); + } catch (Exception e) { + log.error("file [" + f.getName() + + "] Could not determine simple name of super class " + + superClass); + } + } + + List<String> interfaces = f.getInterfaces(); + List<String> interfaces2 = new ArrayList<String>(interfaces.size()); + for (String anInterface : interfaces) { + try { + String newInterface = importsManager.getType(anInterface); + interfaces2.add(newInterface); + } catch (Exception e) { + log.error("file [" + f.getName() + + "] Could not get interface " + anInterface + " :: " + + e.getMessage()); + interfaces2.add(anInterface); + } + } + f.setInterfaces(interfaces2); + + // make sure this imports where done +// importsManager.addImport(Container.class); + importsManager.addImport(JAXXUtil.class); + importsManager.addImport(SwingUtil.class); +// importsManager.addImport(List.class); +// importsManager.addImport(Map.class); + + result = importsManager.getImports(packageName); + result.remove(packageName + ".*"); + if (log.isDebugEnabled()) { + log.debug("[" + f.getName() + "] Detect " + result.size() + + " imports to add."); + for (String s : result) { + log.debug(" " + s); + } +// log.info("[" + f.getName() + "] Registred classnames " + compiler.getResolvedClassNames().size() + "."); +// for (String s : compiler.getResolvedClassNames().values()) { +// log.info(" " + s); +// } + } + if (log.isDebugEnabled()) { + + } + + return result; + + + } } \ No newline at end of file Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeManager.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeManager.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/TypeManager.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -43,7 +43,8 @@ if (converters == null) { converters = new HashMap<Class<?>, TypeConverter>(); // load converters - ServiceLoader<TypeConverter> loader = ServiceLoader.load(TypeConverter.class); + ServiceLoader<TypeConverter> loader = + ServiceLoader.load(TypeConverter.class); for (TypeConverter c : loader) { // for each supported type, register the converter for (Class<?> type : c.getSupportedTypes()) { Modified: trunk/jaxx-compiler/src/test/java/jaxx/compiler/binding/JavaParserUtilTest.java =================================================================== --- trunk/jaxx-compiler/src/test/java/jaxx/compiler/binding/JavaParserUtilTest.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/test/java/jaxx/compiler/binding/JavaParserUtilTest.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -305,8 +305,8 @@ literals.clear(); casts.clear(); - if (log.isInfoEnabled()) { - log.info(source); + if (log.isDebugEnabled()) { + log.debug(source); } JavaParser p; Modified: trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFileTest.java =================================================================== --- trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFileTest.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFileTest.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -83,8 +83,8 @@ File src = new File(testSourceRoot, javaFilePath); Assert.assertTrue(src.exists()); - if (log.isInfoEnabled()) { - log.info("file to parse " + src); + if (log.isDebugEnabled()) { + log.debug("file to parse " + src); } ClassDescriptorResolverFromJavaFile resolver = @@ -94,8 +94,8 @@ resolver.resolvDescriptor(klass.getName(), src.toURI().toURL()); Assert.assertNotNull(descriptor); - if (log.isInfoEnabled()) { - log.info("loaded " + descriptor); + if (log.isDebugEnabled()) { + log.debug("loaded " + descriptor); } Assert.assertEquals(klass.getName(), descriptor.getName()); return descriptor; @@ -278,7 +278,6 @@ "The follwing interfaces were not find found : " + doFind, doFind.isEmpty() ); - } public static void assertSuperClass(ClassDescriptor descriptor, Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoSources.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoSources.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoSources.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,6 +25,13 @@ <JPanel layout='{new BorderLayout()}'> + <import> + org.fife.ui.rsyntaxtextarea.RSyntaxTextArea + jaxx.runtime.swing.FontSizor + javax.swing.DefaultComboBoxModel + java.awt.RenderingHints + </import> + <script><![CDATA[ import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import jaxx.runtime.swing.FontSizor; Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTab.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTab.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTab.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,6 +25,10 @@ <JTabbedPane id='top'> + <import> + javax.swing.SwingUtilities + </import> + <script><![CDATA[ private void $afterCompleteSetup() { Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUI.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -29,7 +29,9 @@ onWindowClosing='getHandler().close(mainFrame)'> <import> - jaxx.demo.tree.*; + java.awt.Dimension + jaxx.demo.tree.DemoTreeHelper + jaxx.demo.tree.DemoCellRenderer jaxx.runtime.swing.CardLayout2 jaxx.runtime.swing.StatusMessagePanel Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/BoxedDecoratorDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/BoxedDecoratorDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/BoxedDecoratorDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -29,6 +29,11 @@ <import> jaxx.runtime.swing.BlockingLayerUI jaxx.runtime.swing.BlockingLayerUI2 + javax.swing.JComponent + javax.swing.DefaultListModel + java.awt.Color + javax.swing.AbstractAction + java.awt.event.ActionEvent </import> <BlockingLayerUI id='layerUI' acceptAction='{new AbstractAction() { Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/I18nEditorDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/I18nEditorDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/I18nEditorDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -26,6 +26,7 @@ <jaxx.demo.DemoPanel> <import> + javax.swing.border.Border jaxx.runtime.swing.editor.I18nEditor org.nuiton.i18n.I18n java.util.Arrays Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JButtonDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JButtonDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JButtonDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -45,6 +45,11 @@ } </script> + <import> + javax.swing.JOptionPane + java.awt.Color + </import> + <javax.swing.ImageIcon id='pencil' constructorParams='getClass().getResource("/jaxx/demo/images/pencil_black.gif")'/> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JCheckBoxDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JCheckBoxDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JCheckBoxDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,9 @@ --> <jaxx.demo.DemoPanel> + <import> + java.awt.Font + </import> <script><![CDATA[ public String getText(boolean bold, boolean italic, boolean underline) { String text ="Sample Text"; Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JComboBoxDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JComboBoxDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JComboBoxDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,9 +25,12 @@ <jaxx.demo.DemoPanel> + <import> + javax.swing.DefaultComboBoxModel + static org.nuiton.i18n.I18n.n_ + </import> + <script><![CDATA[ -import static org.nuiton.i18n.I18n.n_; - private void $afterCompleteSetup() { jaxxComboBox.setSelectedIndex(0); } Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JDialogDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JDialogDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JDialogDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,11 @@ --> <jaxx.demo.DemoPanel> + <import> + javax.swing.JRootPane + javax.swing.JComponent + javax.swing.KeyStroke + </import> <script> String username; String password; Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JMenuItemDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JMenuItemDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JMenuItemDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,10 @@ --> <jaxx.demo.DemoPanel> + <import> + javax.swing.JOptionPane + </import> + <script> void $afterCompleteSetup(){} </script> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JProgressBarDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JProgressBarDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JProgressBarDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,10 @@ --> <jaxx.demo.DemoPanel layout='{new BorderLayout()}'> + <import> + javax.swing.UIManager + java.awt.Color + </import> <script><![CDATA[ import javax.swing.Timer; Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JRadioButtonDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JRadioButtonDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JRadioButtonDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,10 @@ --> <jaxx.demo.DemoPanel> + <import> + javax.swing.ImageIcon + </import> + <HBox horizontalAlignment='center' verticalAlignment='middle'> <VBox> <JRadioButton text='Animal' value='Lynx.jpg' buttonGroup='radioButtons' Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JRadioButtonMenuItemDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JRadioButtonMenuItemDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JRadioButtonMenuItemDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,11 @@ --> <JMenuItemDemo> + <import> + java.awt.Font + javax.swing.UIManager + </import> + <script><![CDATA[ protected Font updateFont(Object selectedValue) { Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSliderDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSliderDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSliderDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,10 @@ --> <jaxx.demo.DemoPanel> + <import> + java.awt.Color + </import> + <HBox horizontalAlignment='center' verticalAlignment='middle'> <VBox> <JSlider id='red' maximum='255' value='200'/> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSpinnerDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSpinnerDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSpinnerDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,10 @@ --> <jaxx.demo.DemoPanel> + <import> + javax.swing.SpinnerNumberModel + </import> + <JLabel text='Spacing:' displayedMnemonic='S' labelFor='{spinner}'/> <JSpinner minimum='0' maximum='50' id='spinner'/> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSplitPaneDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSplitPaneDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JSplitPaneDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,9 @@ --> <jaxx.demo.DemoPanel> + <import> + javax.swing.ImageIcon + </import> <JSplitPane> <JScrollPane> <JLabel Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JTextFieldDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JTextFieldDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/swing/JTextFieldDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,9 @@ --> <jaxx.demo.DemoPanel> + <import> + javax.swing.JOptionPane + </import> <Table> <row> <cell> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/BindingExtremeDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/BindingExtremeDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/BindingExtremeDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -26,6 +26,13 @@ <jaxx.demo.DemoPanel id='mainFrame' implements='DemoUIModel'> + <import> + jaxx.runtime.JAXXBinding + java.awt.Color + javax.swing.border.TitledBorder + javax.swing.DefaultListModel + javax.swing.SwingUtilities + </import> <style> JTextArea { editable:false; } Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/ActorContentUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/ActorContentUI.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/ActorContentUI.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,7 +25,8 @@ <AbstractContentUI superGenericType='People'> <import> - jaxx.demo.entities.* + jaxx.demo.entities.People + static org.nuiton.i18n.I18n._ </import> <People id='data' javaBean='null'/> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/ActorsContentUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/ActorsContentUI.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/ActorsContentUI.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,7 +25,7 @@ <AbstractContentUI superGenericType='java.util.List<People>'> <import> - jaxx.demo.entities.* + jaxx.demo.entities.People jaxx.runtime.swing.editor.bean.BeanListHeader jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer </import> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/MovieContentUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/MovieContentUI.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/MovieContentUI.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,7 +25,8 @@ <AbstractContentUI superGenericType='Movie'> <import> - jaxx.demo.entities.* + jaxx.demo.entities.Movie + static org.nuiton.i18n.I18n._ </import> <Movie id='data' javaBean='null'/> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/MoviesContentUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/MoviesContentUI.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/feature/nav/content/MoviesContentUI.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,7 +25,7 @@ <AbstractContentUI superGenericType='java.util.List<Movie>'> <import> - jaxx.demo.entities.* + jaxx.demo.entities.Movie jaxx.runtime.swing.editor.bean.BeanListHeader jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer </import> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/feature/validation/ValidationListDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/feature/validation/ValidationListDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/feature/validation/ValidationListDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -26,11 +26,16 @@ <jaxx.demo.DemoPanel> <style source="Validation.css"/> + <import> + javax.swing.JOptionPane + static org.nuiton.i18n.I18n.n_ + jaxx.demo.entities.Identity + jaxx.demo.entities.Model + jaxx.runtime.validator.swing.SwingValidatorMessageListRenderer + jaxx.runtime.validator.swing.SwingValidatorMessageListModel + </import> + <script><![CDATA[ -import static org.nuiton.i18n.I18n.n_; -import jaxx.demo.entities.*; -import jaxx.runtime.validator.swing.SwingValidatorMessageListRenderer; -import jaxx.runtime.validator.swing.SwingValidatorMessageListModel; void $afterCompleteSetup() { } Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/feature/validation/ValidationTableDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/feature/validation/ValidationTableDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/feature/validation/ValidationTableDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -26,13 +26,17 @@ <jaxx.demo.DemoPanel> <style source="Validation.css"/> + <import> + javax.swing.JOptionPane + static org.nuiton.i18n.I18n.n_ + jaxx.demo.entities.Identity + jaxx.demo.entities.Model + jaxx.runtime.validator.swing.SwingValidatorUtil + jaxx.runtime.validator.swing.SwingValidatorMessageTableRenderer + jaxx.runtime.validator.swing.SwingValidatorMessageTableModel + </import> + <script><![CDATA[ -import static org.nuiton.i18n.I18n.n_; -import jaxx.demo.entities.*; -import jaxx.runtime.validator.swing.SwingValidatorUtil; -import jaxx.runtime.validator.swing.SwingValidatorMessageTableRenderer; -import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; - void $afterCompleteSetup() { SwingValidatorUtil.installUI(errorTable, new SwingValidatorMessageTableRenderer()); } Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/fun/CalculatorDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/fun/CalculatorDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/fun/CalculatorDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,13 @@ --> <jaxx.demo.DemoPanel> + + <import> + java.awt.Color + javax.swing.BorderFactory + javax.swing.border.BevelBorder + </import> + <!--<style source='CalculatorDemo.css'/>--> <script><![CDATA[ plus.setText("+"); Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/fun/LabelStyleDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/fun/LabelStyleDemo.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/fun/LabelStyleDemo.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,6 +24,12 @@ --> <jaxx.demo.DemoPanel> + + <import> + java.awt.Color + javax.swing.BorderFactory + </import> + <!--<style source="LabelStyleDemo.css"/>--> <script><![CDATA[ @Override 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 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties 2011-01-31 17:54:12 UTC (rev 2187) @@ -15,6 +15,7 @@ 7= 8= 9= +\== Age\:= Animal= Blue= 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 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties 2011-01-31 17:54:12 UTC (rev 2187) @@ -15,6 +15,7 @@ 7=7 8=8 9=9 +\== Age\:=Age \: Animal=Animal Blue=Bleu Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanel.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanel.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanel.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -27,29 +27,32 @@ background='{getBackgroundColor()}' border='{BorderFactory.createLineBorder(Color.BLACK, 1)}'> -<String id='title' javaBean='null'/> + <import> + java.awt.Color + java.awt.Frame + javax.swing.BorderFactory + javax.swing.SwingConstants + </import> -<String id='iconPath' javaBean='null'/> + <AboutPanelHandler id='handler' constructorParams='this'/> -<String id='aboutText' javaBean='null'/> + <String id='title' javaBean='null'/> -<String id='bottomText' javaBean='null'/> + <String id='iconPath' javaBean='null'/> -<String id='licenseText' javaBean='null'/> + <String id='aboutText' javaBean='null'/> -<String id='thirdpartyText' javaBean='null'/> + <String id='bottomText' javaBean='null'/> -<Color id='backgroundColor' javaBean='null'/> + <String id='licenseText' javaBean='null'/> - <script><![CDATA[ -import org.nuiton.util.Resource; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import org.apache.commons.io.IOUtils; + <String id='thirdpartyText' javaBean='null'/> -final Action closeAction = new AbstractAction("close") { + <Color id='backgroundColor' javaBean='null'/> + + <script><![CDATA[ + +/*final Action closeAction = new AbstractAction("close") { private static final long serialVersionUID = 1L; @Override @@ -61,32 +64,36 @@ setVisible(false); } } -}; +};*/ public void setLicenseFile(String filename) { - String load = load(filename); - setLicenseText(load); + handler.setLicenseFile(filename); + //String load = load(filename); + //setLicenseText(load); } public void setThirdpartyFile(String filename) { - String load = load(filename); - setThirdpartyText(load); + handler.setThirdpartyFile(filename); + //String load = load(filename); + //setThirdpartyText(load); } public void buildTopPanel() { + handler.buildTopPanel(); // image - JLabel labelIcon; - if (iconPath != null) { - Icon logoIcon = Resource.getIcon(iconPath); - labelIcon = new JLabel(logoIcon); - } else { - labelIcon = new JLabel(); - } - topPanel.add(labelIcon); + //JLabel labelIcon; + //if (iconPath != null) { + // Icon logoIcon = Resource.getIcon(iconPath); + // labelIcon = new JLabel(logoIcon); + //} else { + // labelIcon = new JLabel(); + //} + //topPanel.add(labelIcon); } public void init() { - if (getAboutText() == null) { + handler.init(); + /*if (getAboutText() == null) { tabs.remove(aboutContent); } if (getLicenseText() == null) { @@ -111,11 +118,12 @@ thirdpartyTextArea.setCaretPosition(0); } }); - } + }*/ } public void showInDialog(Frame ui, boolean undecorated) { - JDialog f = new JDialog(ui, true); + handler.showInDialog(ui, undecorated); + /*JDialog f = new JDialog(ui, true); f.add(this); if (iconPath != null) { f.setIconImage(SwingUtil.createIcon(iconPath).getImage()); @@ -139,10 +147,10 @@ } }); SwingUtil.center(ui, f); - f.setVisible(true); + f.setVisible(true);*/ } -protected String load(String filename) { +/*protected String load(String filename) { InputStream licenseStream = getClass().getResourceAsStream("/" + filename); String result = null; try { @@ -164,74 +172,76 @@ result = "resource " + filename + " not found"; } return result; -} +}*/ void $afterCompleteSetup() { - buildTopPanel(); - close.setText(_("aboutframe.ok")); + handler.$afterCompleteSetup(); + //buildTopPanel(); + //close.setText(_("aboutframe.ok")); } ]]> - </script> - <row> - <cell weightx='1' fill='both'> - <JPanel background='{Color.WHITE}' layout='{new BorderLayout()}'> - <JLabel text='{SwingUtil.getStringValue(getTitle())}' - visible='{getTitle() != null}' - font-size='12' - constraints='BorderLayout.CENTER'/> - </JPanel> - </cell> - </row> - <row> - <cell weightx='1' fill='both'> - <JPanel id='topPanel'/> - </cell> - </row> - <row> - <cell weighty='1' fill='both'> - <JTabbedPane id='tabs'> - <tab title="aboutframe.about"> - <JScrollPane id='aboutContent' border='{null}'> - <JEditorPane contentType='text/html' - editable='false' - border='{null}' - text='{SwingUtil.getStringValue(getAboutText())}' - onHyperlinkUpdate='SwingUtil.openLink(event)'/> - </JScrollPane> - </tab> - <tab title="aboutframe.license"> - <JScrollPane id='licenseContent' border='{null}'> - <JTextArea id='licenseTextArea' - editable='false' - font-size='11' - border='{null}' - text='{SwingUtil.getStringValue(getLicenseText())}'/> - </JScrollPane> - </tab> - <tab title="aboutframe.thirdparty"> - <JScrollPane id='thirdpartyContent' border='{null}'> - <JTextArea id='thirdpartyTextArea' - editable='false' - font-size='11' - border='{null}' - text='{SwingUtil.getStringValue(getThirdpartyText())}'/> - </JScrollPane> - </tab> - </JTabbedPane> - </cell> - </row> - <row> - <cell fill='both'> - <JPanel layout='{new BorderLayout()}'> - <JLabel id='bottomLabel' - constraints='BorderLayout.CENTER' - horizontalAlignment='{SwingConstants.CENTER}' - text='{SwingUtil.getStringValue(getBottomText())}' - visible='{getBottomText() != null}'/> - <JButton id='close' action='{closeAction}' constraints='BorderLayout.EAST'/> - </JPanel> - </cell> - </row> + </script> + <row> + <cell weightx='1' fill='both'> + <JPanel background='{Color.WHITE}' layout='{new BorderLayout()}'> + <JLabel text='{SwingUtil.getStringValue(getTitle())}' + visible='{getTitle() != null}' + font-size='12' + constraints='BorderLayout.CENTER'/> + </JPanel> + </cell> + </row> + <row> + <cell weightx='1' fill='both'> + <JPanel id='topPanel'/> + </cell> + </row> + <row> + <cell weighty='1' fill='both'> + <JTabbedPane id='tabs'> + <tab title="aboutframe.about"> + <JScrollPane id='aboutContent' border='{null}'> + <JEditorPane contentType='text/html' + editable='false' + border='{null}' + text='{SwingUtil.getStringValue(getAboutText())}' + onHyperlinkUpdate='SwingUtil.openLink(event)'/> + </JScrollPane> + </tab> + <tab title="aboutframe.license"> + <JScrollPane id='licenseContent' border='{null}'> + <JTextArea id='licenseTextArea' + editable='false' + font-size='11' + border='{null}' + text='{SwingUtil.getStringValue(getLicenseText())}'/> + </JScrollPane> + </tab> + <tab title="aboutframe.thirdparty"> + <JScrollPane id='thirdpartyContent' border='{null}'> + <JTextArea id='thirdpartyTextArea' + editable='false' + font-size='11' + border='{null}' + text='{SwingUtil.getStringValue(getThirdpartyText())}'/> + </JScrollPane> + </tab> + </JTabbedPane> + </cell> + </row> + <row> + <cell fill='both'> + <JPanel layout='{new BorderLayout()}'> + <JLabel id='bottomLabel' + constraints='BorderLayout.CENTER' + horizontalAlignment='{SwingConstants.CENTER}' + text='{SwingUtil.getStringValue(getBottomText())}' + visible='{getBottomText() != null}'/> + <JButton id='close' action='{handler.closeAction}' + constraints='BorderLayout.EAST'/> + </JPanel> + </cell> + </row> </Table> Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanelHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanelHandler.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanelHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,166 @@ +package jaxx.runtime.swing; + +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.SwingUtil; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.Resource; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JRootPane; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import java.awt.Component; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.IOException; +import java.io.InputStream; + +import static org.nuiton.i18n.I18n._; + +/** + * Handler of the ui {@link AboutPanel}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.4 + */ +public class AboutPanelHandler { + + private static final Log log = LogFactory.getLog(AboutPanelHandler.class); + + protected final AboutPanel ui; + + public AboutPanelHandler(AboutPanel ui) { + this.ui = ui; + } + + final protected Action closeAction = new AbstractAction("close") { + private static final long serialVersionUID = 1L; + + @Override + public void actionPerformed(ActionEvent e) { + JDialog container = ui.getParentContainer(JDialog.class); + if (container != null) { + container.dispose(); + } else { + ui.setVisible(false); + } + } + }; + + public void setLicenseFile(String filename) { + String load = load(filename); + ui.setLicenseText(load); + } + + public void setThirdpartyFile(String filename) { + String load = load(filename); + ui.setThirdpartyText(load); + } + + public void buildTopPanel() { + // image + JLabel labelIcon; + if (ui.iconPath != null) { + Icon logoIcon = Resource.getIcon(ui.iconPath); + labelIcon = new JLabel(logoIcon); + } else { + labelIcon = new JLabel(); + } + ui.topPanel.add(labelIcon); + } + + public void init() { + if (ui.getAboutText() == null) { + ui.tabs.remove(ui.aboutContent); + } + if (ui.getLicenseText() == null) { + ui.tabs.remove(ui.licenseContent); + } else { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + ui.licenseTextArea.setCaretPosition(0); + } + }); + + } + if (ui.getThirdpartyText() == null) { + ui.tabs.remove(ui.thirdpartyContent); + } else { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + ui.thirdpartyTextArea.setCaretPosition(0); + } + }); + } + } + + public void showInDialog(Frame ui, boolean undecorated) { + JDialog f = new JDialog(ui, true); + f.add(this.ui); + if (this.ui.iconPath != null) { + f.setIconImage(SwingUtil.createIcon(this.ui.iconPath).getImage()); + } + f.setResizable(false); + f.setSize(550, 450); + f.setUndecorated(undecorated); + JRootPane rootPane = f.getRootPane(); + rootPane.setDefaultButton(this.ui.close); + rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close"); + rootPane.getActionMap().put("close", closeAction); + f.addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent e) { + Component ui = (Component) e.getSource(); + if (log.isInfoEnabled()) { + log.info("destroy ui " + ui); + } + JAXXUtil.destroy(ui); + JAXXUtil.destroy(AboutPanelHandler.this.ui); + } + }); + SwingUtil.center(ui, f); + f.setVisible(true); + } + + protected String load(String filename) { + InputStream licenseStream = getClass().getResourceAsStream("/" + filename); + String result = null; + try { + if (licenseStream != null) { + result = IOUtils.toString(licenseStream); + } + } catch (IOException ex) { + // ignore it + } finally { + if (licenseStream != null) { + try { + licenseStream.close(); + } catch (IOException ex) { + log.error("could not close file " + filename); + } + } + } + if (result == null) { + result = "resource " + filename + " not found"; + } + return result; + } + + void $afterCompleteSetup() { + buildTopPanel(); + ui.close.setText(_("aboutframe.ok")); + } +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanelHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ClockWidget.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ClockWidget.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ClockWidget.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -29,6 +29,12 @@ <javax.swing.Timer id='timer' constructorParams='60000,this' /> + <import> + java.awt.Color + java.awt.event.ActionEvent + java.text.DateFormat + java.util.Date + </import> <script><![CDATA[ @Override @@ -51,7 +57,7 @@ } protected void update() { - setText(java.text.DateFormat.getTimeInstance(3).format(new Date())); + setText(DateFormat.getTimeInstance(3).format(new Date())); } ]]> </script> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUI.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUI.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUI.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,15 +24,26 @@ --> <JDialog title='errorUI.title' modal='true'> - <script><![CDATA[ + + <import> + java.awt.Frame + </import> + + <ErrorDialogUIHandler id='handler' constructorParams='this'/> + + <script><![CDATA[ protected static ErrorDialogUI instance; + public static void init(Frame frame) { - disposeUI(); + ErrorDialogUIHandler.init(frame); + /*disposeUI(); instance = new ErrorDialogUI(frame); - instance.setModalityType(ModalityType.TOOLKIT_MODAL); + instance.setModalityType(ModalityType.TOOLKIT_MODAL);*/ } + public static void showError(Exception e) { - if (instance == null) { + ErrorDialogUIHandler.showError(e); + /*if (instance == null) { instance = new ErrorDialogUI(); } instance.getErrorMessage().setText(e.getMessage()); @@ -42,13 +53,14 @@ instance.getErrorStack().setCaretPosition(0); instance.pack(); jaxx.runtime.SwingUtil.center(instance.getContextValue(JFrame.class,"parent"), instance); - instance.setVisible(true); + instance.setVisible(true);*/ } public static void disposeUI() { - if (instance != null) { + ErrorDialogUIHandler.disposeUI(); + /*if (instance != null) { JAXXUtil.destroy(instance); } - instance=null; + instance=null;*/ } public ErrorDialogUI(Frame frame) { @@ -60,35 +72,40 @@ } -JRootPane rootPane = getRootPane(); +void $afterCompleteSetup() { + handler.$afterCompleteSetup(); +} + +/*JRootPane rootPane = getRootPane(); rootPane.setDefaultButton(close); rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close"); -rootPane.getActionMap().put("close", close.getAction()); +rootPane.getActionMap().put("close", close.getAction());*/ ]]></script> - <Table> - <row fill='both'> - <cell> - <JPanel> - <JLabel text='errorUI.message'/> - </JPanel> - </cell> - </row> - <row fill='both'> - <cell> - <JLabel id='errorMessage'/> - </cell> - </row> - <row fill='both' weightx='1' weighty='1'> - <cell> - <JScrollPane width='600' height='200'> - <JTextArea id='errorStack' editable='false' font-size='9'/> - </JScrollPane> - </cell> - </row> - <row fill='horizontal'> - <cell> - <JButton id='close' text='errorUI.action.close' onActionPerformed='dispose()'/> - </cell> - </row> - </Table> + <Table> + <row fill='both'> + <cell> + <JPanel> + <JLabel text='errorUI.message'/> + </JPanel> + </cell> + </row> + <row fill='both'> + <cell> + <JLabel id='errorMessage'/> + </cell> + </row> + <row fill='both' weightx='1' weighty='1'> + <cell> + <JScrollPane width='600' height='200'> + <JTextArea id='errorStack' editable='false' font-size='9'/> + </JScrollPane> + </cell> + </row> + <row fill='horizontal'> + <cell> + <JButton id='close' text='errorUI.action.close' + onActionPerformed='dispose()'/> + </cell> + </row> + </Table> </JDialog> Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUIHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUIHandler.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUIHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,76 @@ +package jaxx.runtime.swing; + +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.SwingUtil; + +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JRootPane; +import javax.swing.KeyStroke; +import java.awt.Dialog; +import java.awt.Frame; +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * Handler of ui {@link ErrorDialogUI}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class ErrorDialogUIHandler { + + protected final ErrorDialogUI ui; + + public ErrorDialogUIHandler(ErrorDialogUI ui) { + this.ui = ui; + } + + public static void init(Frame frame) { + disposeUI(); + ErrorDialogUI.instance = new ErrorDialogUI(); + ErrorDialogUI.instance.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL); + } + + public static void showError(Exception e) { + ErrorDialogUI instance = ErrorDialogUI.instance; + if (instance == null) { + instance = new ErrorDialogUI(); + } + instance.getErrorMessage().setText(e.getMessage()); + StringWriter w = new StringWriter(); + PrintWriter writer = new PrintWriter(w); + try { + e.printStackTrace(writer); + instance.getErrorStack().setText(w.toString()); + } finally { + writer.close(); + } + instance.getErrorStack().setCaretPosition(0); + instance.pack(); + SwingUtil.center(instance.getContextValue(JFrame.class, "parent"), instance); + instance.setVisible(true); + } + + public static void disposeUI() { + ErrorDialogUI instance = ErrorDialogUI.instance; + if (instance != null) { + JAXXUtil.destroy(instance); + } + ErrorDialogUI.instance = null; + } + + void $afterCompleteSetup() { + JRootPane rootPane = ui.getRootPane(); + + JButton close = ui.close; + rootPane.setDefaultButton(close); + InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); + inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "close"); + rootPane.getActionMap().put("close", close.getAction()); + } + + +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizor.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizor.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizor.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -26,36 +26,46 @@ <JPanel layout='{new BorderLayout()}'> - <!-- default size of font --> - <Float id='defaultFontSize' javaBean='12f'/> + <!--import> + java.awt.BorderLayout + </import--> - <!-- size of font --> - <Float id='fontSize' javaBean='null'/> + <FontSizorHandler id='handler' constructorParams='this'/> - <Boolean id='showDefaultFontSize' javaBean='true'/> + <!-- default size of font --> + <Float id='defaultFontSize' javaBean='12f'/> - <Boolean id='showFontSize' javaBean='false'/> + <!-- size of font --> + <Float id='fontSize' javaBean='null'/> - <script><![CDATA[ + <Boolean id='showDefaultFontSize' javaBean='true'/> + <Boolean id='showFontSize' javaBean='false'/> + + <script><![CDATA[ +/* public static final String BINDING_FONT_SIZE_CALL_BACK = "fontSize.callBack"; public static final String BINDING_DEFAULT_FONT_SIZE_CALL_BACK = "defaultFontSize.callBack"; +*/ public void init() { - if (fontSize == null) { + handler.init(); + /*if (fontSize == null) { setFontSize(defaultFontSize); - } + }*/ } boolean updateDefaultSizeEnabled(Float fontSize, Float defaultFontSize, boolean enabled) { - if (fontSize==null || defaultFontSize==null) { + return handler.updateDefaultSizeEnabled( fontSize,defaultFontSize, enabled); + /*if (fontSize==null || defaultFontSize==null) { return false; } - return !fontSize.equals(defaultFontSize) && enabled; + return !fontSize.equals(defaultFontSize) && enabled;*/ } public void setCallBack(final Runnable action) { - removeDataBinding(BINDING_FONT_SIZE_CALL_BACK); + handler.setCallBack(action); + /*removeDataBinding(BINDING_FONT_SIZE_CALL_BACK); registerDataBinding(new SimpleJAXXObjectBinding(this, BINDING_FONT_SIZE_CALL_BACK, true ,"fontSize") { @Override @@ -63,11 +73,12 @@ action.run(); } }); - applyDataBinding(BINDING_FONT_SIZE_CALL_BACK); + applyDataBinding(BINDING_FONT_SIZE_CALL_BACK);*/ } void $afterCompleteSetup() { - registerDataBinding(new SimpleJAXXObjectBinding(this, BINDING_DEFAULT_FONT_SIZE_CALL_BACK, true ,"defaultFontSize") { + handler.$afterCompleteSetup(); + /*registerDataBinding(new SimpleJAXXObjectBinding(this, BINDING_DEFAULT_FONT_SIZE_CALL_BACK, true ,"defaultFontSize") { @Override public void processDataBinding() { @@ -75,40 +86,41 @@ } }); //applyDataBinding(BINDING_DEFAULT_FONT_SIZE_CALL_BACK); + */ } ]]> - </script> - <JToolBar floatable='false' - borderPainted='false' - opaque='{isOpaque()}' - constraints='BorderLayout.CENTER'> + </script> + <JToolBar floatable='false' + borderPainted='false' + opaque='{isOpaque()}' + constraints='BorderLayout.CENTER'> - <JButton id='downSize' - actionIcon='font-size-down' - toolTipText='fontsize.action.down.tip' - focusable='false' - focusPainted='false' - enabled='{isEnabled()}' - onActionPerformed='setFontSize(fontSize - 1)'/> + <JButton id='downSize' + actionIcon='font-size-down' + toolTipText='fontsize.action.down.tip' + focusable='false' + focusPainted='false' + enabled='{isEnabled()}' + onActionPerformed='setFontSize(fontSize - 1)'/> - <JButton id='defaultSize' - actionIcon='font-size' - toolTipText='fontsize.action.default.tip' - focusable='false' - focusPainted='false' - visible='{isShowDefaultFontSize()}' - enabled='{updateDefaultSizeEnabled(getFontSize(), getDefaultFontSize(), isEnabled())}' - onActionPerformed='setFontSize(defaultFontSize)'/> - <JButton id='upSize' - actionIcon='font-size-up' - toolTipText='fontsize.action.up.tip' - focusable='false' - focusPainted='false' - enabled='{isEnabled()}' - onActionPerformed='setFontSize(fontSize + 1)'/> - - <JLabel visible='{isShowFontSize()}' - text='{SwingUtil.getStringValue(getFontSize())}'/> - </JToolBar> + <JButton id='defaultSize' + actionIcon='font-size' + toolTipText='fontsize.action.default.tip' + focusable='false' + focusPainted='false' + visible='{isShowDefaultFontSize()}' + enabled='{updateDefaultSizeEnabled(getFontSize(), getDefaultFontSize(), isEnabled())}' + onActionPerformed='setFontSize(defaultFontSize)'/> + <JButton id='upSize' + actionIcon='font-size-up' + toolTipText='fontsize.action.up.tip' + focusable='false' + focusPainted='false' + enabled='{isEnabled()}' + onActionPerformed='setFontSize(fontSize + 1)'/> + <JLabel visible='{isShowFontSize()}' + text='{SwingUtil.getStringValue(getFontSize())}'/> + </JToolBar> + </JPanel> Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizorHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizorHandler.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizorHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,60 @@ +package jaxx.runtime.swing; + +import jaxx.runtime.binding.SimpleJAXXObjectBinding; + +/** + * Handler of ui {@link FontSizor}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class FontSizorHandler { + + protected final FontSizor ui; + + public FontSizorHandler(FontSizor ui) { + this.ui = ui; + } + + public static final String BINDING_FONT_SIZE_CALL_BACK = "fontSize.callBack"; + + public static final String BINDING_DEFAULT_FONT_SIZE_CALL_BACK = "defaultFontSize.callBack"; + + public void init() { + if (ui.fontSize == null) { + ui.setFontSize(ui.defaultFontSize); + } + } + + boolean updateDefaultSizeEnabled(Float fontSize, + Float defaultFontSize, + boolean enabled) { + if (fontSize == null || defaultFontSize == null) { + return false; + } + return !fontSize.equals(defaultFontSize) && enabled; + } + + public void setCallBack(final Runnable action) { + ui.removeDataBinding(BINDING_FONT_SIZE_CALL_BACK); + ui.registerDataBinding(new SimpleJAXXObjectBinding(ui, BINDING_FONT_SIZE_CALL_BACK, true, "fontSize") { + + @Override + public void processDataBinding() { + action.run(); + } + }); + ui.applyDataBinding(BINDING_FONT_SIZE_CALL_BACK); + } + + void $afterCompleteSetup() { + ui.registerDataBinding(new SimpleJAXXObjectBinding(ui, BINDING_DEFAULT_FONT_SIZE_CALL_BACK, true, "defaultFontSize") { + + @Override + public void processDataBinding() { + ui.setFontSize(ui.defaultFontSize); + } + }); + //applyDataBinding(BINDING_DEFAULT_FONT_SIZE_CALL_BACK); + } +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizorHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/HidorButton.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/HidorButton.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/HidorButton.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -23,29 +23,44 @@ #L% --> <JToggleButton id='hidor' - text='{updateText(isTargetVisible())}' - toolTipText='{updateToolTipText(isTargetVisible())}' - icon="{updateIcon(isTargetVisible())}" + text='{myHandler.updateText(isTargetVisible())}' + toolTipText='{myHandler.updateToolTipText(isTargetVisible())}' + icon="{myHandler.updateIcon(isTargetVisible())}" _hideIcon='{SwingUtil.createActionIcon("collapse")}' _showIcon='{SwingUtil.createActionIcon("expand")}' onActionPerformed='setTargetVisible(!targetVisible)'> - <Boolean id='targetVisible' javaBean='null'/> + <import> + javax.swing.Icon + javax.swing.JComponent + </import> + + <HidorButtonHandler id='myHandler' constructorParams='this'/> - <String id='hideText' javaBean='""'/> + <Boolean id='targetVisible' javaBean='null'/> - <String id='showText' javaBean='""'/> + <String id='hideText' javaBean='""'/> - <String id='hideTip' javaBean='_("hidor.hideTip")'/> + <String id='showText' javaBean='""'/> - <String id='showTip' javaBean='_("hidor.showTip")'/> + <String id='hideTip' javaBean='_("hidor.hideTip")'/> - <script><![CDATA[ -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; + <String id='showTip' javaBean='_("hidor.showTip")'/> -addPropertyChangeListener("targetVisible", new PropertyChangeListener() { + <script><![CDATA[ +protected JComponent target; + +public JComponent getTarget() { + return target; +} + +void $afterCompleteSetup() { + myHandler.$afterCompleteSetup(); +} + +/*addPropertyChangeListener("targetVisible", new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { if (log.isDebugEnabled()) { @@ -56,14 +71,8 @@ target.setVisible(newValue); } } -}); +});*/ -protected JComponent target; - -public JComponent getTarget() { - return target; -} - public void setTarget(JComponent target) { JComponent oldValue = this.target; this.target = target; @@ -78,7 +87,7 @@ putClientProperty("hideIcon", icon); } -protected String updateToolTipText(boolean c) { +/*protected String updateToolTipText(boolean c) { String i = c ? hideTip : showTip; return i; } @@ -91,7 +100,7 @@ protected Icon updateIcon(boolean c) { String key = c ? "hideIcon" : "showIcon"; return (Icon) getClientProperty(key); -} +}*/ ]]> - </script> + </script> </JToggleButton> Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/HidorButtonHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/HidorButtonHandler.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/HidorButtonHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,73 @@ +package jaxx.runtime.swing; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.Icon; +import javax.swing.JComponent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +/** + * Handler of ui {@link HidorButton}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class HidorButtonHandler { + + private static final Log log = + LogFactory.getLog(HidorButtonHandler.class); + + protected final HidorButton ui; + + public HidorButtonHandler(HidorButton ui) { + this.ui = ui; + } + + void $afterCompleteSetup() { + + ui.addPropertyChangeListener("targetVisible", new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (log.isDebugEnabled()) { + log.debug("target visible changed <" + evt.getOldValue() + ":" + evt.getNewValue() + ">"); + } + boolean newValue = (Boolean) evt.getNewValue(); + if (ui.target != null) { + ui.target.setVisible(newValue); + } + } + }); + } + + public void setTarget(JComponent target) { + JComponent oldValue = ui.target; + ui.target = target; + ui.firePropertyChange("target", oldValue, target); + } + + public void setExpandIcon(Icon icon) { + ui.putClientProperty("expandIcon", icon); + } + + public void setHideIcon(Icon icon) { + ui.putClientProperty("hideIcon", icon); + } + + protected String updateToolTipText(boolean c) { + String i = c ? ui.hideTip : ui.showTip; + return i; + } + + protected String updateText(boolean c) { + String i = c ? ui.hideText : ui.showText; + return i; + } + + protected Icon updateIcon(boolean c) { + String key = c ? "hideIcon" : "showIcon"; + return (Icon) ui.getClientProperty(key); + } +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/HidorButtonHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ListSelectorUI.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ListSelectorUI.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ListSelectorUI.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,22 +24,28 @@ --> <JPanel layout='{new BorderLayout()}' genericType='B'> - <!-- show hidor property --> - <Boolean id='showHidor' javaBean='false'/> + <import> + java.util.List + javax.swing.DefaultComboBoxModel + javax.swing.DefaultListModel + </import> - <Boolean id='modified' javaBean='false'/> + <!-- show hidor property --> + <Boolean id='showHidor' javaBean='false'/> - <String id='addToListTip' javaBean='"+"'/> + <Boolean id='modified' javaBean='false'/> - <String id='addToComboTip' javaBean='"-"'/> + <String id='addToListTip' javaBean='"+"'/> - <ListCellRenderer id='renderer' javaBean='null'/> + <String id='addToComboTip' javaBean='"-"'/> - <!-- ui handler --> - <ListSelectorHandler id='handler' genericType='B' constructorParams='this'/> + <ListCellRenderer id='renderer' javaBean='null'/> - <script><![CDATA[ + <!-- ui handler --> + <ListSelectorHandler id='handler' genericType='B' constructorParams='this'/> + <script><![CDATA[ + public void setHandler(ListSelectorHandler handler) { this.handler = handler; } @@ -47,14 +53,14 @@ /** * @return the datas from the combo box. */ -public java.util.List<B> getComboDatas() { +public List<B> getComboDatas() { return handler.getComboDatas(); } /** * @return the data for the list. */ -public java.util.List<B> getListDatas() { +public List<B> getListDatas() { return handler.getListDatas(); } @@ -64,59 +70,59 @@ * @param toCombo datas to set in combo * @param toList datas to set in list */ -public void init(java.util.List<B> toCombo, java.util.List<B> toList) { +public void init(List<B> toCombo, List<B> toList) { handler.init(toCombo, toList); } ]]> - </script> + </script> - <JScrollPane id='listPane' constraints='BorderLayout.CENTER' - columnHeaderView='{header}'> - <!--minimumSize='{SwingUtil.newMinDimension()}'>--> - <!--verticalScrollBarPolicy='vertical_scrollbar_always'--> - <JPanel layout="{new BorderLayout()}" minimumSize='{getMinimumSize()}'> - <JList id='list' - constraints='BorderLayout.CENTER' - enabled='{isEnabled()}' - model='{new DefaultListModel()}' - font-size='11' - onMouseClicked='if (event.getClickCount()==2) { handler.transfertToCombo((B[]) list.getSelectedValues()); }' - cellRenderer='{getRenderer()}'/> - </JPanel> + <JScrollPane id='listPane' constraints='BorderLayout.CENTER' + columnHeaderView='{header}'> + <!--minimumSize='{SwingUtil.newMinDimension()}'>--> + <!--verticalScrollBarPolicy='vertical_scrollbar_always'--> + <JPanel layout="{new BorderLayout()}" minimumSize='{getMinimumSize()}'> + <JList id='list' + constraints='BorderLayout.CENTER' + enabled='{isEnabled()}' + model='{new DefaultListModel()}' + font-size='11' + onMouseClicked='if (event.getClickCount()==2) { handler.transfertToCombo((B[]) list.getSelectedValues()); }' + cellRenderer='{getRenderer()}'/> + </JPanel> - </JScrollPane> + </JScrollPane> - <Table id="header" insets='0' constraints='BorderLayout.SOUTH'> - <row> - <cell fill='horizontal' weightx='1' anchor="west"> - <JComboBox id='combo' enabled='{isEnabled()}' - model='{new DefaultComboBoxModel()}' - renderer='{getRenderer()}'/> - </cell> - <cell anchor='east'> - <JToolBar id='actions' floatable='false'> - <JButton id="add" - toolTipText='{getAddToListTip()}' - actionIcon='add' - enabled='{handler.updateAddEnabled(combo.isEnabled() && combo.getSelectedIndex() > -1)}' - onActionPerformed='handler.transfertToList((B) combo.getSelectedItem());'/> + <Table id="header" insets='0' constraints='BorderLayout.SOUTH'> + <row> + <cell fill='horizontal' weightx='1' anchor="west"> + <JComboBox id='combo' enabled='{isEnabled()}' + model='{new DefaultComboBoxModel()}' + renderer='{getRenderer()}'/> + </cell> + <cell anchor='east'> + <JToolBar id='actions' floatable='false'> + <JButton id="add" + toolTipText='{getAddToListTip()}' + actionIcon='add' + enabled='{handler.updateAddEnabled(combo.isEnabled() && combo.getSelectedIndex() > -1)}' + onActionPerformed='handler.transfertToList((B) combo.getSelectedItem());'/> - <JButton id="remove" - toolTipText='{getAddToComboTip()}' - actionIcon='remove' - enabled='{handler.updateRemoveEnabled(list.isEnabled() && list.getSelectedIndex() > -1)}' - onActionPerformed='handler.transfertToCombo((B[]) list.getSelectedValues())'/> + <JButton id="remove" + toolTipText='{getAddToComboTip()}' + actionIcon='remove' + enabled='{handler.updateRemoveEnabled(list.isEnabled() && list.getSelectedIndex() > -1)}' + onActionPerformed='handler.transfertToCombo((B[]) list.getSelectedValues())'/> - <HidorButton id="hidor" - target='{list}' - visible='{isShowHidor()}' - enabled='{isEnabled()}' - hideTip='{_("listSelector.hideList")}' - showTip='{_("listSelector.showList")}' - targetVisible='{true}'/> - </JToolBar> - </cell> - </row> - </Table> + <HidorButton id="hidor" + target='{list}' + visible='{isShowHidor()}' + enabled='{isEnabled()}' + hideTip='{_("listSelector.hideList")}' + showTip='{_("listSelector.showList")}' + targetVisible='{true}'/> + </JToolBar> + </cell> + </row> + </Table> </JPanel> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/MemoryStatusWidget.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/MemoryStatusWidget.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/MemoryStatusWidget.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,16 +24,30 @@ --> -<JComponent implements='java.awt.event.ActionListener' - foreground='{Color.BLACK}' - background='{Color.WHITE}'> +<JComponent implements='java.awt.event.ActionListener' + foreground='{Color.BLACK}' + background='{Color.WHITE}'> - <javax.swing.Timer id='timer' javaBean='null'/> + <import> + java.awt.Color + java.awt.Graphics + java.awt.font.FontRenderContext + java.awt.font.LineMetrics + java.awt.geom.Rectangle2D + java.awt.event.ActionEvent + javax.swing.Timer + </import> - <Color id='progressBackground' javaBean='Color.decode("#666699a")'/> - <Color id='progressForeground' javaBean='Color.decode("#cccccc")'/> + <MemoryStatusWidgetHandler id='handler' constructorParams='this'/> + + <javax.swing.Timer id='timer' javaBean='null'/> - <script><![CDATA[ + <Color id='progressBackground' javaBean='Color.decode("#666699a")'/> + <Color id='progressForeground' javaBean='Color.decode("#cccccc")'/> + + <script><![CDATA[ + + /* import java.awt.font.FontRenderContext; import java.awt.font.LineMetrics; import java.awt.geom.Rectangle2D; @@ -43,6 +57,7 @@ private FontRenderContext frc = new FontRenderContext(null, false, false); private LineMetrics lm = new JLabel().getFont().getLineMetrics(memoryTestStr, frc); +*/ @Override public void actionPerformed(ActionEvent evt) { @@ -53,7 +68,7 @@ @Override public void addNotify() { super.addNotify(); - setTimer(new javax.swing.Timer(2000, this)); + setTimer(new Timer(2000, this)); timer.start(); } @@ -68,7 +83,8 @@ @Override public void paintComponent(Graphics g) { - Insets insets = new Insets(0, 0, 0, 0); + handler.paintComponent(g); + /*Insets insets = new Insets(0, 0, 0, 0); Runtime runtime = Runtime.getRuntime(); int freeMemory = (int) (runtime.freeMemory() / 1024L); int totalMemory = (int) (runtime.totalMemory() / 1024L); @@ -99,17 +115,18 @@ g2.drawString(str, insets.left + (int) ((double) width - bounds.getWidth()) / 2, (int) ((float) insets.top + lm.getAscent())); - g2.dispose(); + g2.dispose();*/ } void $afterCompleteSetup() { - setFont(new JLabel().getFont()); + handler.$afterCompleteSetup(); + /*setFont(new JLabel().getFont()); Rectangle2D bounds = getFont().getStringBounds(memoryTestStr, frc); Dimension dim = new Dimension((int) bounds.getWidth(), (int) bounds .getHeight()); setPreferredSize(dim); - setMaximumSize(dim); + setMaximumSize(dim);*/ } ]]> - </script> + </script> </JComponent> Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/MemoryStatusWidgetHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/MemoryStatusWidgetHandler.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/MemoryStatusWidgetHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,77 @@ +package jaxx.runtime.swing; + +import javax.swing.JLabel; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.font.FontRenderContext; +import java.awt.font.LineMetrics; +import java.awt.geom.Rectangle2D; + +import static org.nuiton.i18n.I18n._; + +/** + * Handler of ui {@link MemoryStatusWidget}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class MemoryStatusWidgetHandler { + + private final static String memoryTestStr = "99999/99999Mb"; + + private FontRenderContext frc = new FontRenderContext(null, false, false); + + private LineMetrics lm = new JLabel().getFont().getLineMetrics(memoryTestStr, frc); + + protected final MemoryStatusWidget ui; + + public MemoryStatusWidgetHandler(MemoryStatusWidget ui) { + this.ui = ui; + } + + public void paintComponent(Graphics g) { + Insets insets = new Insets(0, 0, 0, 0); + Runtime runtime = Runtime.getRuntime(); + int freeMemory = (int) (runtime.freeMemory() / 1024L); + int totalMemory = (int) (runtime.totalMemory() / 1024L); + int usedMemory = totalMemory - freeMemory; + int width = ui.getWidth() - insets.left - insets.right; + int height = ui.getHeight() - insets.top - insets.bottom - 1; + float fraction = (float) usedMemory / (float) totalMemory; + g.setColor(ui.progressBackground); + g.fillRect(insets.left, insets.top, (int) ((float) width * fraction), height); + // No i18n string was : + // String str = usedMemory / 1024 + "/" + totalMemory / 1024 + "Mb"; + String str = _("memorywidget.memory", usedMemory / 1024, totalMemory / 1024); + //FontRenderContext frc = new FontRenderContext(null, false, false); + Rectangle2D bounds = g.getFont().getStringBounds(str, frc); + Graphics g2 = g.create(); + g2.setClip(insets.left, insets.top, + (int) ((float) width * fraction), height); + g2.setColor(ui.progressForeground); + g2.drawString(str, insets.left + + (int) ((double) width - bounds.getWidth()) / 2, + (int) ((float) insets.top + lm.getAscent())); + g2.dispose(); + g2 = g.create(); + g2.setClip(insets.left + (int) ((float) width * fraction), + insets.top, ui.getWidth() - insets.left + - (int) ((float) width * fraction), height); + g2.setColor(ui.getForeground()); + g2.drawString(str, insets.left + + (int) ((double) width - bounds.getWidth()) / 2, + (int) ((float) insets.top + lm.getAscent())); + g2.dispose(); + } + + + void $afterCompleteSetup() { + ui.setFont(new JLabel().getFont()); + Rectangle2D bounds = ui.getFont().getStringBounds(memoryTestStr, frc); + Dimension dim = new Dimension((int) bounds.getWidth(), (int) bounds.getHeight()); + ui.setPreferredSize(dim); + ui.setMaximumSize(dim); + } + +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/MemoryStatusWidgetHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanel.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanel.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanel.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,19 +24,27 @@ --> -<Table border='{BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)}' - insets='0' - implements='java.awt.event.ActionListener'> +<Table border='{BorderFactory.createBevelBorder(BevelBorder.LOWERED)}' + insets='0' + implements='java.awt.event.ActionListener'> - <script><![CDATA[ + <import> + java.awt.Component + java.awt.event.ActionEvent + javax.swing.BorderFactory + javax.swing.border.BevelBorder + </import> + + <script><![CDATA[ // To ensure status bar constant height, no matter what font are in use... protected final static String EMPTY_STATUS = " "; public void clearStatus() { - handler.stopStatusFader(this); + handler.clearStatus(); + /*handler.stopStatusFader(this); getStatusLabel().setText(EMPTY_STATUS); - //getStatusLabel().setString(EMPTY_STATUS); + //getStatusLabel().setString(EMPTY_STATUS);*/ } public void startProgress() { @@ -58,8 +66,8 @@ } public void setStatus(String status) { - - if (status != null) { + handler.setStatus(status); + /*if (status != null) { handler.stopStatusFader(this); getStatusLabel().setText(status); //getStatusLabel().setString(status); @@ -67,7 +75,7 @@ if (!isBusy()) { handler.startStatusFader(this); - } + }*/ } @Override @@ -93,62 +101,64 @@ } public void init() { - if (isShowBusy()) { + handler.init(); + /*if (isShowBusy()) { Dimension dim = new Dimension(30, 15); //Dimension dim = new Dimension(30, (int) statusLabel.getPreferredSize().getHeight()); //log.info("dimension of busy = "+ dim); //busyWidget.setPreferredSize(dim); busyWidget.setMaximumSize(dim); busyWidget.setMinimumSize(dim); - } + }*/ } void $afterCompleteSetup() { - init(); +handler.$afterCompleteSetup(); + //init(); } ]]> - </script> + </script> - <Boolean id='showMemoryStatus' javaBean='Boolean.TRUE'/> - <Boolean id='showClock' javaBean='Boolean.TRUE'/> - <Boolean id='showI18n' javaBean='Boolean.FALSE'/> - <Boolean id='showBusy' javaBean='Boolean.FALSE'/> - <Boolean id='busy' javaBean='Boolean.FALSE'/> + <Boolean id='showMemoryStatus' javaBean='Boolean.TRUE'/> + <Boolean id='showClock' javaBean='Boolean.TRUE'/> + <Boolean id='showI18n' javaBean='Boolean.FALSE'/> + <Boolean id='showBusy' javaBean='Boolean.FALSE'/> + <Boolean id='busy' javaBean='Boolean.FALSE'/> - <StatusMessagePanelHandler id='handler'/> + <StatusMessagePanelHandler id='handler' constructorParams='this'/> - <row> - <cell anchor='west' fill='both' weightx='1'> - <Box constructorParams='0'> - <JProgressBar id='busyWidget' - visible='{isShowBusy()}' - enabled='{isBusy()}' - indeterminate='{isBusy()}' - stringPainted='false' - borderPainted='true'/> - <!--visible='{isBusy() && isShowBusy()}'--> + <row> + <cell anchor='west' fill='both' weightx='1'> + <Box constructorParams='0'> + <JProgressBar id='busyWidget' + visible='{isShowBusy()}' + enabled='{isBusy()}' + indeterminate='{isBusy()}' + stringPainted='false' + borderPainted='true'/> + <!--visible='{isBusy() && isShowBusy()}'--> - <JLabel id='statusLabel'/> + <JLabel id='statusLabel'/> - </Box> + </Box> - </cell> - <cell anchor='east'> - <Box id='box' constructorParams='0'> + </cell> + <cell anchor='east'> + <Box id='box' constructorParams='0'> - <!--JProgressBar id='busyWidget' - visible='{isBusy() && isShowBusy()}' - indeterminate='{isBusy()}' - stringPainted='false' - borderPainted='true'/--> - <!-- - minimumSize='{new Dimension(30,1)}' - maximumSize='{new Dimension(30,30)}' - preferredSize='{new Dimension(30,30)}' - --> - <MemoryStatusWidget/> - <ClockWidget/> - </Box> - </cell> - </row> + <!--JProgressBar id='busyWidget' + visible='{isBusy() && isShowBusy()}' + indeterminate='{isBusy()}' + stringPainted='false' + borderPainted='true'/--> + <!-- +minimumSize='{new Dimension(30,1)}' + maximumSize='{new Dimension(30,30)}' + preferredSize='{new Dimension(30,30)}' + --> + <MemoryStatusWidget/> + <ClockWidget/> + </Box> + </cell> + </row> </Table> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanelHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanelHandler.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanelHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -25,8 +25,9 @@ package jaxx.runtime.swing; -import javax.swing.*; -import java.awt.*; +import javax.swing.Timer; +import java.awt.Color; +import java.awt.Dimension; /** * @author tchemit <chemit@codelutin.com> @@ -34,12 +35,51 @@ */ public class StatusMessagePanelHandler { + protected final StatusMessagePanel ui; + protected Color statusForeground; protected String statusReferenceContent; protected Timer timer; + public StatusMessagePanelHandler(StatusMessagePanel ui) { + this.ui = ui; + } + + void $afterCompleteSetup() { + init(); + } + + public void init() { + if (ui.isShowBusy()) { + Dimension dim = new Dimension(30, 15); + //Dimension dim = new Dimension(30, (int) statusLabel.getPreferredSize().getHeight()); + //log.info("dimension of busy = "+ dim); + //busyWidget.setPreferredSize(dim); + ui.busyWidget.setMaximumSize(dim); + ui.busyWidget.setMinimumSize(dim); + } + } + + public void clearStatus() { + stopStatusFader(ui); + ui.getStatusLabel().setText(StatusMessagePanel.EMPTY_STATUS); + //getStatusLabel().setString(EMPTY_STATUS); + } + + public void setStatus(String status) { + if (status != null) { + stopStatusFader(ui); + ui.getStatusLabel().setText(status); + //getStatusLabel().setString(status); + } + + if (!ui.isBusy()) { + startStatusFader(ui); + } + } + protected void fadeStatus(StatusMessagePanel ui) { for (int i = 0; i < 8; i++) { // synchronized (this) { Deleted: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/ColumnSelector.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/ColumnSelector.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/ColumnSelector.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -1,158 +0,0 @@ -<!-- - #%L - JAXX :: Widgets - - $Id$ - $HeadURL$ - %% - Copyright (C) 2008 - 2010 CodeLutin - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Lesser Public License for more details. - - You should have received a copy of the GNU General Lesser Public - License along with this program. If not, see - <http://www.gnu.org/licenses/lgpl-3.0.html>. - #L% - --> - -<JPanel implements='PropertyChangeListener, ActionListener' - layout='{new BorderLayout()}' - onFocusGained='button.requestFocus()' - onFocusLost='setPopupVisible(false)'> - - <!-- table to works with --> - <Object id='myTable' javaBean='null'/> - - <!-- internal state --> - <Boolean id='popupVisible' javaBean='false'/> - - <!-- ui handler --> - <!--ColumnSelectorHandler id='handler' constructorParams='this'/--> - - <JPopupMenu id='popup' - border='{new TitledBorder(_("i18neditor.popup.title"))}' - onPopupMenuWillBecomeInvisible='button.setSelected(false)' - onPopupMenuCanceled='button.setSelected(false)'> - <JLabel id='popupLabel' enabled='false' text='i18neditor.empty.locales'/> - </JPopupMenu> - - <script><![CDATA[ -import javax.swing.table.TableColumn; -import javax.swing.table.TableCellRenderer; -import jaxx.runtime.swing.renderer.I18nTableCellRenderer; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeEvent; - -public static final String TABLE_PROPERTY = "myTable"; -public static final String POPUP_VISIBLE_PROPERTY = "popupVisible"; - -@Override -public void propertyChange(PropertyChangeEvent evt) { - String name = evt.getPropertyName(); - if (log.isDebugEnabled()) { - log.debug(name+" <old:"+evt.getOldValue()+" - new:"+evt.getNewValue()+">"); - } - //log.info(name+" <old:"+evt.getOldValue()+" - new:"+evt.getNewValue()+">"); - if (TABLE_PROPERTY.equals(name)) { - // table has changed, rebuild the popup - try { - - popup.removeAll(); - JTable t = (JTable) evt.getNewValue(); - if (t != null) { - log.info("table has changed ! " + t.getName()); - for (int i = 0, columnCount = t.getColumnCount(); i < columnCount; i++) { - TableColumn column = t.getColumnModel().getColumn(i); - TableCellRenderer defaultRenderer = t.getTableHeader().getDefaultRenderer(); - String columnName = column.getHeaderValue() + ""; - if (defaultRenderer instanceof I18nTableCellRenderer) { - I18nTableCellRenderer renderer = (I18nTableCellRenderer) defaultRenderer; - columnName = _(renderer.getKeys()[i]); - } - JRadioButtonMenuItem b = new JRadioButtonMenuItem(columnName, null, true); - popup.add(b); - b.addActionListener(this); - b.putClientProperty("columnIndex", i); - b.putClientProperty("columnName", columnName); - b.putClientProperty("column", column); - } - } - } finally { - popup.invalidate(); - } - return; - } - if (POPUP_VISIBLE_PROPERTY.equals(name)) { - Boolean newValue = (Boolean) evt.getNewValue(); - if (newValue == null || !newValue) { - if (getPopup() != null && getPopup().isVisible()) { - getPopup().setVisible(false); - } - return; - } - if (!getPopup().isVisible()) { - SwingUtilities.invokeLater(showPopupRunnable); - } - return; - } - -} - -@Override -public void actionPerformed(ActionEvent event) { - JRadioButtonMenuItem source = (JRadioButtonMenuItem) event.getSource(); - boolean selected = source.isSelected(); - TableColumn column = (TableColumn) source.getClientProperty("column"); - Integer columnIndex = (Integer) source.getClientProperty("columnIndex"); - String columnName = (String) source.getClientProperty("columnName"); - log.info(columnName + ", selected : " + selected); - JTable t = (JTable) myTable; - if (selected) { - // reinject the column in table - t.getColumnModel().addColumn(column); - } else { - // remove column from table - t.getColumnModel().removeColumn(column); - } -} - -protected Runnable showPopupRunnable = new Runnable() { - @Override - public void run() { - getPopup().pack(); - Dimension dim = getPopup().getPreferredSize(); - JToggleButton invoker = getButton(); - getPopup().show(invoker, (int) (invoker.getPreferredSize().getWidth() - dim.getWidth()), invoker.getHeight()); - } -}; - - -addPropertyChangeListener(TABLE_PROPERTY,this); -addPropertyChangeListener(POPUP_VISIBLE_PROPERTY,this); -]]> - </script> - <JToolBar floatable='false' - opaque='false' - borderPainted='false'> - <JToggleButton - id='button' - toolTipText='columnselector.action.tip' - actionIcon='numbereditor-calculator' - constraints='BorderLayout.CENTER' - selected='{popup.isVisible()}' - focusable='true' - focusPainted='false' - borderPainted='false' - rolloverEnabled='false' - onItemStateChanged='if (event.getStateChange() == ItemEvent.SELECTED) { setPopupVisible(true); } else { popupVisible = false; }'/> - </JToolBar> -</JPanel> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/I18nEditor.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/I18nEditor.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/I18nEditor.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -29,49 +29,69 @@ layout='{new BorderLayout()}' onFocusGained='button.requestFocus()' onFocusLost='setPopupVisible(false)'> + + <import> + java.awt.BorderLayout + java.awt.event.ItemEvent + java.awt.event.ActionEvent + java.awt.event.ActionListener + javax.swing.border.TitledBorder + + java.beans.PropertyChangeListener + java.beans.PropertyChangeEvent + java.util.Locale + + jaxx.runtime.swing.renderer.LocaleListCellRenderer - <String id='selectedToolTipText' javaBean='null'/> - <String id='notSelectedToolTipText' javaBean='null'/> - - <Border id='popupBorder' javaBean='new TitledBorder(_("i18neditor.popup.title"))'/> - - <Boolean id='showText' javaBean='Boolean.TRUE'/> - <Boolean id='showIcon' javaBean='Boolean.TRUE'/> - <Boolean id='showPopupText' javaBean='Boolean.TRUE'/> - <Boolean id='showPopupIcon' javaBean='Boolean.TRUE'/> - <Boolean id='popupVisible' javaBean='Boolean.FALSE'/> - - <java.util.List id='locales' javaBean='null' genericType='Locale'/> + static org.nuiton.i18n.I18n.n_ + </import> - <Locale id='selectedLocale' javaBean='Locale.getDefault()'/> + <I18nEditorHandler id='handler' constructorParams='this'/> - <jaxx.runtime.swing.renderer.LocaleListCellRenderer id='renderer' - showIcon='{isShowIcon()}' - showText='{isShowText()}' - javaBean='new LocaleListCellRenderer(showIcon , showText)'/> + <String id='selectedToolTipText' javaBean='null'/> + <String id='notSelectedToolTipText' javaBean='null'/> - <!-- popup to change sorted property--> - <JPopupMenu id='popup' - border='{getPopupBorder()}' - onPopupMenuWillBecomeInvisible='button.setSelected(false)' - onPopupMenuCanceled='button.setSelected(false)'> - <JLabel id='popupLabel' enabled='false' text='i18neditor.empty.locales'/> - </JPopupMenu> + <Border id='popupBorder' + javaBean='new TitledBorder(_("i18neditor.popup.title"))'/> - <JToggleButton - id='button' - text='{SwingUtil.getStringValue(renderer.getText(getSelectedLocale()))}' - toolTipText='{getTip(getSelectedLocale())}' - icon='{renderer.getIcon(getSelectedLocale())}' - constraints='BorderLayout.CENTER' - selected='{popup.isVisible()}' - focusable='true' - focusPainted='false' - onItemStateChanged='if (event.getStateChange() == ItemEvent.SELECTED) { setPopupVisible(true); } else { popupVisible = false; }'/> + <Boolean id='showText' javaBean='Boolean.TRUE'/> + <Boolean id='showIcon' javaBean='Boolean.TRUE'/> + <Boolean id='showPopupText' javaBean='Boolean.TRUE'/> + <Boolean id='showPopupIcon' javaBean='Boolean.TRUE'/> + <Boolean id='popupVisible' javaBean='Boolean.FALSE'/> - <ButtonGroup id='indexes' onStateChanged='log.info(indexes.getSelectedValue())'/> - - <script><![CDATA[ + <java.util.List id='locales' javaBean='null' genericType='Locale'/> + + <Locale id='selectedLocale' javaBean='Locale.getDefault()'/> + + <LocaleListCellRenderer id='renderer' + showIcon='{isShowIcon()}' + showText='{isShowText()}' + javaBean='new LocaleListCellRenderer(showIcon , showText)'/> + + <!-- popup to change sorted property--> + <JPopupMenu id='popup' + border='{getPopupBorder()}' + onPopupMenuWillBecomeInvisible='button.setSelected(false)' + onPopupMenuCanceled='button.setSelected(false)'> + <JLabel id='popupLabel' enabled='false' text='i18neditor.empty.locales'/> + </JPopupMenu> + + <JToggleButton + id='button' + text='{SwingUtil.getStringValue(renderer.getText(getSelectedLocale()))}' + toolTipText='{getTip(getSelectedLocale())}' + icon='{renderer.getIcon(getSelectedLocale())}' + constraints='BorderLayout.CENTER' + selected='{popup.isVisible()}' + focusable='true' + focusPainted='false' + onItemStateChanged='if (event.getStateChange() == ItemEvent.SELECTED) { setPopupVisible(true); } else { popupVisible = false; }'/> + + <ButtonGroup id='indexes' + onStateChanged='log.info(indexes.getSelectedValue())'/> + + <script><![CDATA[ import java.util.Locale; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -90,9 +110,18 @@ public static final String POPUP_BORDER_PROPERTY = "popupBorder"; public static final String POPUP_VISIBLE_PROPERTY = "popupVisible"; + + +void $afterCompleteSetup() { + handler.$afterCompleteSetup(); + //buildTopPanel(); + //close.setText(_("aboutframe.ok")); +} + @Override public void propertyChange(PropertyChangeEvent evt) { - String name = evt.getPropertyName(); + handler.propertyChange(evt); + /*String name = evt.getPropertyName(); if (log.isDebugEnabled()) { log.debug(name+" <old:"+evt.getOldValue()+" - new:"+evt.getNewValue()+">"); } @@ -173,26 +202,29 @@ popup.invalidate(); } return; - } + }*/ } @Override public void actionPerformed(ActionEvent event) { - Locale value = (Locale) + handler.actionPerformed(event); + /*Locale value = (Locale) ((JComponent)event.getSource()).getClientProperty("locale"); if (log.isDebugEnabled()) { log.debug("new locale : " + value); } - setSelectedLocale(value); + setSelectedLocale(value);*/ } public void loadI18nBundles() { - Locale[] locales = org.nuiton.i18n.I18n.getStore().getLocales(); - setLocales(java.util.Arrays.asList(locales)); + handler.loadI18nBundles(); + /*Locale[] locales = org.nuiton.i18n.I18n.getStore().getLocales(); + setLocales(java.util.Arrays.asList(locales));*/ } protected void rebuildPopup() { - log.debug("start rebuild"); + handler.rebuildPopup(); + /*log.debug("start rebuild"); try { for (Component c : popup.getComponents()) { if (c instanceof JRadioButtonMenuItem) { @@ -208,38 +240,41 @@ } } finally { popup.invalidate(); - } + }*/ } protected String getTip(Locale l) { - boolean selected = l.equals(selectedLocale); + return handler.getTip(l); + /*boolean selected = l.equals(selectedLocale); String tip = selected ? getSelectedTip(l):getNotSelectedTip(l); - return tip; + return tip;*/ } protected String getSelectedTip(Locale l) { - String selectedTip = getSelectedToolTipText(); + return handler.getSelectedTip(l); + /*String selectedTip = getSelectedToolTipText(); if (selectedTip == null) { // use default selected tip text selectedTip = DEFAULT_SELECTED_TOOLTIP; } String tip = renderer.getToolTipText(l); tip = _(selectedTip, tip); - return tip; + return tip;*/ } protected String getNotSelectedTip(Locale l) { - String selectedTip = getNotSelectedToolTipText(); + return handler.getNotSelectedTip(l); + /*String selectedTip = getNotSelectedToolTipText(); if (selectedTip == null) { // use default not selected tip text selectedTip = DEFAULT_NOT_SELECTED_TOOLTIP; } String tip = renderer.getToolTipText(l); tip = _(selectedTip, tip); - return tip; + return tip;*/ } -protected Runnable showPopupRunnable = new Runnable() { +/*protected Runnable showPopupRunnable = new Runnable() { @Override public void run() { getPopup().pack(); @@ -249,10 +284,11 @@ getPopup().show(invoker, (int) (invokerDim.getWidth() - dim.getWidth()), invoker.getHeight()); // getPopup().setVisible(true); } -}; +};*/ -addPropertyChangeListener(this); +/* +addPropertyChangeListener(this);*/ ]]> - </script> + </script> </JPanel> Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/I18nEditorHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/I18nEditorHandler.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/I18nEditorHandler.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -0,0 +1,226 @@ +package jaxx.runtime.swing.editor; + +import jaxx.runtime.swing.JAXXButtonGroup; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.i18n.I18n; + +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JToggleButton; +import javax.swing.SwingUtilities; +import javax.swing.border.Border; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Arrays; +import java.util.Collection; +import java.util.Locale; + +import static org.nuiton.i18n.I18n._; +import static org.nuiton.i18n.I18n.n_; + +/** + * Handler of ui {@link I18nEditor}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class I18nEditorHandler implements PropertyChangeListener, ActionListener { + + private static final Log log = LogFactory.getLog(I18nEditorHandler.class); + + protected final I18nEditor ui; + + public I18nEditorHandler(I18nEditor ui) { + this.ui = ui; + } + + public static final String DEFAULT_SELECTED_TOOLTIP = n_("i18neditor.selected"); + + public static final String DEFAULT_NOT_SELECTED_TOOLTIP = n_("i18neditor.unselected"); + + public static final String LOCALES_PROPERTY = "locales"; + + public static final String SELECTED_LOCALE_PROPERTY = "selectedLocale"; + + public static final String SHOW_ICON_PROPERTY = "showIcon"; + + public static final String SHOW_TEXT_PROPERTY = "showText"; + + public static final String SHOW_POPUP_ICON_PROPERTY = "showPopupIcon"; + + public static final String SHOW_POPUP_TEXT_PROPERTY = "showPopupText"; + + public static final String POPUP_BORDER_PROPERTY = "popupBorder"; + + public static final String POPUP_VISIBLE_PROPERTY = "popupVisible"; + + @Override + public void propertyChange(PropertyChangeEvent evt) { + String name = evt.getPropertyName(); + if (log.isDebugEnabled()) { + log.debug(name + " <old:" + evt.getOldValue() + " - new:" + evt.getNewValue() + ">"); + } + log.info(name + " <old:" + evt.getOldValue() + " - new:" + evt.getNewValue() + ">"); + if (LOCALES_PROPERTY.equals(name)) { + Collection<?> newLocales = (Collection<?>) evt.getNewValue(); + // mise a jour de la popup + boolean oldShowText = ui.renderer.isShowText(); + try { + ui.renderer.setShowText(true); + ui.popup.removeAll(); + for (Object o : newLocales) { + Locale l = (Locale) o; + boolean selected = l.equals(ui.selectedLocale); + String text = ui.isShowPopupText() ? ui.renderer.getText(l) : null; + Icon icon = ui.isShowPopupIcon() ? ui.renderer.getIcon(l) : null; + JRadioButtonMenuItem b = new JRadioButtonMenuItem(text, icon, selected); + ui.popup.add(b); + b.addActionListener(ui); + b.putClientProperty("locale", l); + b.setToolTipText(getTip(l)); + b.putClientProperty(JAXXButtonGroup.BUTTON8GROUP_CLIENT_PROPERTY, ui.getIndexes()); + b.putClientProperty(JAXXButtonGroup.VALUE_CLIENT_PROPERTY, l); + } + } finally { + ui.renderer.setShowText(oldShowText); + ui.popup.invalidate(); + } + return; + } + if (SHOW_ICON_PROPERTY.equals(name)) { + ui.renderer.setShowIcon((Boolean) evt.getNewValue()); + ui.processDataBinding("button.icon"); + return; + } + if (SHOW_TEXT_PROPERTY.equals(name)) { + ui.renderer.setShowText((Boolean) evt.getNewValue()); + ui.processDataBinding("button.text"); + return; + } + if (SHOW_POPUP_ICON_PROPERTY.equals(name)) { + rebuildPopup(); + return; + } + if (SHOW_POPUP_TEXT_PROPERTY.equals(name)) { + rebuildPopup(); + return; + } + if (POPUP_BORDER_PROPERTY.equals(name)) { + ui.popup.setBorder((Border) evt.getNewValue()); + return; + } + if (POPUP_VISIBLE_PROPERTY.equals(name)) { + Boolean newValue = (Boolean) evt.getNewValue(); + if (newValue == null || !newValue) { + if (ui.getPopup() != null && ui.getPopup().isVisible()) { + ui.getPopup().setVisible(false); + } + return; + } + if (!ui.getPopup().isVisible()) { + SwingUtilities.invokeLater(showPopupRunnable); + } + return; + } + if (SELECTED_LOCALE_PROPERTY.equals(name)) { + Locale newLocale = (Locale) evt.getNewValue(); + // mise a jour de la popup + try { + for (Component c : ui.popup.getComponents()) { + if (c instanceof JRadioButtonMenuItem) { + JRadioButtonMenuItem b = (JRadioButtonMenuItem) c; + Locale l = (Locale) b.getClientProperty("locale"); + b.setSelected(newLocale.equals(l)); + } + } + } finally { + ui.popup.invalidate(); + } + } + } + + @Override + public void actionPerformed(ActionEvent event) { + Locale value = (Locale) + ((JComponent) event.getSource()).getClientProperty("locale"); + if (log.isDebugEnabled()) { + log.debug("new locale : " + value); + } + ui.setSelectedLocale(value); + } + + public void loadI18nBundles() { + Locale[] locales = I18n.getStore().getLocales(); + ui.setLocales(Arrays.asList(locales)); + } + + protected void rebuildPopup() { + log.debug("start rebuild"); + try { + for (Component c : ui.popup.getComponents()) { + if (c instanceof JRadioButtonMenuItem) { + JRadioButtonMenuItem b = (JRadioButtonMenuItem) c; + Locale l = (Locale) b.getClientProperty("locale"); + String text = ui.isShowPopupText() ? ui.renderer.getSafeText(l) : null; + Icon icon = ui.isShowPopupIcon() ? ui.renderer.getSafeIcon(l) : null; + b.setIcon(icon); + b.setText(text); + log.debug("text=" + text); + log.debug("icon=" + icon); + } + } + } finally { + ui.popup.invalidate(); + } + } + + protected String getTip(Locale l) { + boolean selected = l.equals(ui.selectedLocale); + String tip = selected ? getSelectedTip(l) : getNotSelectedTip(l); + return tip; + } + + protected String getSelectedTip(Locale l) { + String selectedTip = ui.getSelectedToolTipText(); + if (selectedTip == null) { + // use default selected tip text + selectedTip = DEFAULT_SELECTED_TOOLTIP; + } + String tip = ui.renderer.getToolTipText(l); + tip = _(selectedTip, tip); + return tip; + } + + protected String getNotSelectedTip(Locale l) { + String selectedTip = ui.getNotSelectedToolTipText(); + if (selectedTip == null) { + // use default not selected tip text + selectedTip = DEFAULT_NOT_SELECTED_TOOLTIP; + } + String tip = ui.renderer.getToolTipText(l); + tip = _(selectedTip, tip); + return tip; + } + + protected Runnable showPopupRunnable = new Runnable() { + @Override + public void run() { + ui.getPopup().pack(); + JToggleButton invoker = ui.getButton(); + Dimension dim = ui.getPopup().getPreferredSize(); + Dimension invokerDim = invoker.getSize(); + ui.getPopup().show(invoker, (int) (invokerDim.getWidth() - dim.getWidth()), invoker.getHeight()); +// getPopup().setVisible(true); + } + }; + + void $afterCompleteSetup() { + ui.addPropertyChangeListener(this); + } +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/I18nEditorHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/NumberEditor.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/NumberEditor.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/NumberEditor.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -29,6 +29,15 @@ onFocusLost='setPopupVisible(false);popup.setVisible(false);' onMouseExited='setPopupVisible(false);popup.setVisible(false);'> + <import> + java.awt.Color + java.awt.BorderLayout + java.awt.GridLayout + java.awt.Dimension + + javax.swing.BorderFactory + + </import> <!-- onFocusGained='if (autoPopup) setPopupVisible(true); textField.requestFocus();'--> <!-- bean property associated with the editing value --> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/TimeEditor.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/TimeEditor.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/TimeEditor.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -28,6 +28,9 @@ <import> java.util.Date + java.awt.BorderLayout + javax.swing.SpinnerNumberModel + javax.swing.DefaultBoundedRangeModel </import> <!-- bean property --> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBox.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBox.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBox.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -30,6 +30,7 @@ <import> static org.nuiton.i18n.I18n.n_ jaxx.runtime.decorator.JXPathDecorator + javax.swing.border.TitledBorder </import> <!-- auto complete property --> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanListHeader.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanListHeader.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanListHeader.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -28,6 +28,7 @@ <import> static org.nuiton.i18n.I18n.n_ jaxx.runtime.decorator.JXPathDecorator + javax.swing.border.TitledBorder </import> <!-- show reset property --> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -23,7 +23,12 @@ #L% --> <JPanel layout='{new BorderLayout()}'> - <script><![CDATA[ + + <!--import> + java.awt.BorderLayout + </import--> + + <script><![CDATA[ import jaxx.runtime.swing.editor.config.model.*; /** @@ -33,31 +38,31 @@ getHandler().init(this); } ]]> - </script> + </script> - <ConfigCallBackUIHandler - id='handler' - initializer='getContextValue(ConfigCallBackUIHandler.class)'/> + <ConfigCallBackUIHandler + id='handler' + initializer='getContextValue(ConfigCallBackUIHandler.class)'/> - <JScrollPane constraints='BorderLayout.CENTER' - columnHeaderView='{treeHeader}'> + <JScrollPane constraints='BorderLayout.CENTER' + columnHeaderView='{treeHeader}'> - <JTree id='detectedCallBack' - editable='false' - rootVisible='false' - rowHeight='24'/> + <JTree id='detectedCallBack' + editable='false' + rootVisible='false' + rowHeight='24'/> - </JScrollPane> + </JScrollPane> - <JButton constraints='BorderLayout.SOUTH' - id='go' - text='config.launch.callBack' - toolTipText='config.launch.callBack.tip' - actionIcon='config-quit' - onActionPerformed='getHandler().doAction(this)'/> + <JButton constraints='BorderLayout.SOUTH' + id='go' + text='config.launch.callBack' + toolTipText='config.launch.callBack.tip' + actionIcon='config-quit' + onActionPerformed='getHandler().doAction(this)'/> - <JPanel id='treeHeader' constraints='BorderLayout.EAST'> - <JLabel text='config.detected.callBack'/> - </JPanel> + <JPanel id='treeHeader' constraints='BorderLayout.EAST'> + <JLabel text='config.detected.callBack'/> + </JPanel> </JPanel> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,11 +24,19 @@ --> <JPanel layout='{new BorderLayout()}'> - <!--<style source='ConfigCategoryUI.css'/>--> + <import> + java.awt.Color + java.awt.Font + javax.swing.DefaultListSelectionModel + javax.swing.ScrollPaneConstants + jaxx.runtime.swing.editor.config.model.OptionModel + static org.nuiton.i18n.I18n.n_ + </import> - <script><![CDATA[ + <!--<style source='ConfigCategoryUI.css'/>--> + + <script><![CDATA[ import jaxx.runtime.swing.editor.config.model.*; -import jaxx.runtime.swing.editor.ColumnSelector; import static org.nuiton.i18n.I18n.n_; void $afterCompleteSetup() { @@ -81,47 +89,47 @@ description.setText(buffer.toString()); } ]]> - </script> + </script> - <!-- le modele de l'ui --> - <ConfigUIModel id='model' - initializer='getContextValue(ConfigUIModel.class)'/> + <!-- le modele de l'ui --> + <ConfigUIModel id='model' + initializer='getContextValue(ConfigUIModel.class)'/> - <CategoryModel id='categoryModel' - javaBean='getContextValue(CategoryModel.class)'/> + <CategoryModel id='categoryModel' + javaBean='getContextValue(CategoryModel.class)'/> - <ConfigTableModel id='tableModel' constructorParams='categoryModel' - onTableChanged='updateDescriptionText()'/> + <ConfigTableModel id='tableModel' constructorParams='categoryModel' + onTableChanged='updateDescriptionText()'/> - <ListSelectionModel id='selectionModel' - javaBean='new DefaultListSelectionModel()' - onValueChanged='if (!event.getValueIsAdjusting()) { updateDescriptionText(); }'/> + <ListSelectionModel id='selectionModel' + javaBean='new DefaultListSelectionModel()' + onValueChanged='if (!event.getValueIsAdjusting()) { updateDescriptionText(); }'/> - <!--<ColumnSelector id='columnSelector' />--> + <!--<ColumnSelector id='columnSelector' />--> - <!-- categorie label --> - <JPanel id="categoryLabelPanel" constraints='BorderLayout.NORTH'> - <JLabel id='categoryLabel'/> - </JPanel> + <!-- categorie label --> + <JPanel id="categoryLabelPanel" constraints='BorderLayout.NORTH'> + <JLabel id='categoryLabel'/> + </JPanel> - <!-- table of options --> - <JScrollPane id='tablePane' constraints='BorderLayout.CENTER'> - <JTable id="table" constructorParams='tableModel' - selectionModel='{selectionModel}'/> + <!-- table of options --> + <JScrollPane id='tablePane' constraints='BorderLayout.CENTER'> + <JTable id="table" constructorParams='tableModel' + selectionModel='{selectionModel}'/> + </JScrollPane> + + <JPanel layout='{new BorderLayout()}' constraints='BorderLayout.SOUTH'> + + <!-- description of selected option in table --> + <JScrollPane id="descriptionPane" constraints='BorderLayout.CENTER'> + <JTextArea id='description'/> </JScrollPane> - <JPanel layout='{new BorderLayout()}' constraints='BorderLayout.SOUTH'> - - <!-- description of selected option in table --> - <JScrollPane id="descriptionPane" constraints='BorderLayout.CENTER'> - <JTextArea id='description'/> - </JScrollPane> - - <!-- actions of the category --> - <JPanel layout='{new GridLayout(1,0)}' - constraints='BorderLayout.SOUTH'> - <JButton id='reset' onActionPerformed='model.reset()'/> - <JButton id='save' onActionPerformed='model.saveModified()'/> - </JPanel> + <!-- actions of the category --> + <JPanel layout='{new GridLayout(1,0)}' + constraints='BorderLayout.SOUTH'> + <JButton id='reset' onActionPerformed='model.reset()'/> + <JButton id='save' onActionPerformed='model.saveModified()'/> </JPanel> + </JPanel> </JPanel> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -24,11 +24,14 @@ --> <JPanel layout='{new BorderLayout()}'> - <!--<style source='ConfigUI.css'/>--> + <import> + jaxx.runtime.swing.editor.config.model.ConfigUIModel + </import> - <script><![CDATA[ -import jaxx.runtime.swing.editor.config.model.ConfigUIModel; + <!--<style source='ConfigUI.css'/>--> + <script><![CDATA[ + public void init(String defaultCategory) { getHandler().initUI(defaultCategory); } @@ -45,20 +48,20 @@ destroy(); } ]]> - </script> + </script> - <ConfigUIHandler id='handler' constructorParams='this'/> - - <!-- le modele de l'ui --> - <ConfigUIModel id='model' - initializer='getContextValue(ConfigUIModel.class)'/> + <ConfigUIHandler id='handler' constructorParams='this'/> - <!-- les differentes categories de la configuration --> - <JTabbedPane id='categories' constraints='BorderLayout.CENTER' - onStateChanged='getHandler().changeCategory(event)' /> + <!-- le modele de l'ui --> + <ConfigUIModel id='model' + initializer='getContextValue(ConfigUIModel.class)'/> - <!-- pour quitter l'ui --> - <JPanel layout='{new GridLayout(1,0)}' constraints='BorderLayout.SOUTH'> - <JButton id='quit'/> - </JPanel> + <!-- les differentes categories de la configuration --> + <JTabbedPane id='categories' constraints='BorderLayout.CENTER' + onStateChanged='getHandler().changeCategory(event)'/> + + <!-- pour quitter l'ui --> + <JPanel layout='{new GridLayout(1,0)}' constraints='BorderLayout.SOUTH'> + <JButton id='quit'/> + </JPanel> </JPanel> Modified: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java =================================================================== --- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -179,7 +179,12 @@ public boolean _final; - Option(String key, String description, String defaultValue, Class<?> type, boolean _transient, boolean _final) { + Option(String key, + String description, + String defaultValue, + Class<?> type, + boolean _transient, + boolean _final) { this.key = key; this.description = description; this.defaultValue = defaultValue; Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java =================================================================== --- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -29,7 +29,7 @@ import jaxx.compiler.CompilerConfiguration; import jaxx.compiler.I18nHelper; import jaxx.compiler.JAXXCompiler; -import jaxx.compiler.JAXXCompilerFinalizer; +import jaxx.compiler.finalizers.JAXXCompilerFinalizer; import jaxx.compiler.JAXXEngine; import jaxx.compiler.JAXXFactory; import jaxx.compiler.beans.BeanInfoUtil; @@ -39,7 +39,6 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXObject; import jaxx.runtime.swing.help.JAXXHelpBroker; -import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.apache.maven.plugin.MojoExecutionException; @@ -106,19 +105,6 @@ protected String compilerFQN; /** - * Le compilateur à utiliser (par défaut celui de Swing). - * <p/> - * Ce paramètre n'est plus utilisable et ne sera pas pris en compte - * par le compilateur JAXX. - * - * @parameter expression="${jaxx.validatorFQN}" - * @deprecated since 2.3, will not be replaced, using the new api of validator - * does not support it - */ - @Deprecated - protected String validatorFQN; - - /** * the name of implementation of {@link JAXXContext}to be used on {@link * JAXXObject}. * <p/> @@ -315,6 +301,16 @@ */ protected String helpBrokerFQN; + /** + * To trace class descriptor loading. + * <p/> + * By default, do not trace it. + * + * @parameter expression="${jaxx.showClassDescriptorLoading}" default-value="false" + * @since 2.4 + */ + private boolean showClassDescriptorLoading; + /** detected jaxx files in {@link #init()} method */ protected String[] files; @@ -328,9 +324,6 @@ /** type of error ui class (in validation) to use */ private Class<?> defaultErrorUIClass; - /** type of validator to use */ - private final Class<?> validatorClass = SwingValidator.class; - /** type of {@link CompiledObjectDecorator} to use */ private Class<? extends CompiledObjectDecorator> defaultDecoratorClass; @@ -358,9 +351,9 @@ protected Map<String, CompiledObjectDecorator> decorators; /** - * finalizers available in engine. + * Finalizers available in engine. * - * @component role="jaxx.compiler.JAXXCompilerFinalizer" + * @component role="jaxx.compiler.finalizers.JAXXCompilerFinalizer" * @since 2.0.2 */ protected Map<String, JAXXCompilerFinalizer> finalizers; @@ -582,6 +575,11 @@ } @Override + public boolean isShowClassDescriptorLoading() { + return showClassDescriptorLoading; + } + + @Override public Class<? extends JAXXContext> getJaxxContextClass() { return jaxxContextClass; } @@ -637,11 +635,6 @@ } @Override - public Class<?> getValidatorClass() { - return validatorClass; - } - - @Override public Map<String, CompiledObjectDecorator> getDecorators() { return decorators; } Modified: trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1751Test.java =================================================================== --- trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1751Test.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1751Test.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -36,7 +36,7 @@ mojo.execute(); assertNumberJaxxFiles(3); - checkPattern(mojo, "implements java.io.Serializable", true); + checkPattern(mojo, "implements Serializable", true); checkPattern(mojo, "setText(_(\"test\"))", true); } Modified: trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java =================================================================== --- trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java 2011-01-31 17:54:12 UTC (rev 2187) @@ -68,12 +68,13 @@ } mojo.jaxxContextFQN = DefaultJAXXContext.class.getName(); mojo.compilerFQN = JAXXCompiler.class.getName(); - mojo.validatorFQN = SwingValidator.class.getName(); mojo.defaultDecoratorFQN = DefaultCompiledObjectDecorator.class.getName(); - } - protected void checkPattern(GenerateMojo mojo, String pattern, boolean required, String... files) throws IOException { + protected void checkPattern(GenerateMojo mojo, + String pattern, + boolean required, + String... files) throws IOException { if (files.length == 0) { files = mojo.files; } Modified: trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/compilerTest/cSSTests/GrandChild.jaxx =================================================================== --- trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/compilerTest/cSSTests/GrandChild.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/compilerTest/cSSTests/GrandChild.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -1,28 +1,31 @@ -<!-- - #%L - JAXX :: Maven plugin - - $Id$ - $HeadURL$ - %% - Copyright (C) 2008 - 2010 CodeLutin - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Lesser Public License for more details. - - You should have received a copy of the GNU General Lesser Public - License along with this program. If not, see - <http://www.gnu.org/licenses/lgpl-3.0.html>. - #L% - --> +<!-- + #%L + JAXX :: Maven plugin + + $Id$ + $HeadURL$ + %% + Copyright (C) 2008 - 2010 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> <JPanel layout='{new BorderLayout()}'> + <import> + java.awt.Color + </import> <script> public String getText() { return grandChild.getText(); Modified: trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/compilerTest/cSSTests/SimpleCSS.jaxx =================================================================== --- trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/compilerTest/cSSTests/SimpleCSS.jaxx 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/compilerTest/cSSTests/SimpleCSS.jaxx 2011-01-31 17:54:12 UTC (rev 2187) @@ -1,29 +1,32 @@ -<!-- - #%L - JAXX :: Maven plugin - - $Id$ - $HeadURL$ - %% - Copyright (C) 2008 - 2010 CodeLutin - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Lesser Public License for more details. - - You should have received a copy of the GNU General Lesser Public - License along with this program. If not, see - <http://www.gnu.org/licenses/lgpl-3.0.html>. - #L% - --> +<!-- + #%L + JAXX :: Maven plugin + + $Id$ + $HeadURL$ + %% + Copyright (C) 2008 - 2010 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> <VBox> <JPanel layout='{new GridLayout(0, 1, 6, 6)}'> + <import> + java.awt.Color + </import> <style> JPanel { border: {null}; font-size: 18; } Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2011-01-27 14:47:10 UTC (rev 2186) +++ trunk/pom.xml 2011-01-31 17:54:12 UTC (rev 2187) @@ -108,6 +108,34 @@ </dependency> <dependency> + <groupId>org.nuiton.eugene</groupId> + <artifactId>eugene</artifactId> + <version>${eugeneVersion}</version> + <exclusions> + <exclusion> + <groupId>jaxen</groupId> + <artifactId>jaxen</artifactId> + </exclusion> + <exclusion> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + </exclusion> + <exclusion> + <groupId>xml-apis</groupId> + <artifactId>xml-apis</artifactId> + </exclusion> + <exclusion> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </exclusion> + <exclusion> + <groupId>commons-digester</groupId> + <artifactId>commons-digester</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> <groupId>org.nuiton</groupId> <artifactId>maven-helper-plugin</artifactId> <version>${helperPluginVersion}</version> @@ -387,7 +415,8 @@ <projectId>jaxx</projectId> <nuitonUtilsVersion>2.0</nuitonUtilsVersion> - <nuitonI18nVersion>2.2</nuitonI18nVersion> + <nuitonI18nVersion>2.3</nuitonI18nVersion> + <eugeneVersion>2.3.2-SNAPSHOT</eugeneVersion> <xworkVersion>2.2.1.1</xworkVersion> <jxLayerVersion>3.0.3</jxLayerVersion> <javaHelpVersion>2.0.02</javaHelpVersion>
participants (1)
-
tchemit@users.nuiton.org