r1519 - in trunk: . guix-compiler/src/main/java/org/nuiton/guix guix-compiler/src/test guix-test-swing/src/main/java/org/nuiton/guix/demo
Author: kmorin Date: 2009-07-23 15:33:45 +0200 (Thu, 23 Jul 2009) New Revision: 1519 Removed: trunk/guix-maven-plugin/ Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java trunk/guix-compiler/src/test/test.guix trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.css trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.script trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo2.guix trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo3.guix trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/JButton.css Log: Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-07-23 11:51:40 UTC (rev 1518) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-07-23 13:33:45 UTC (rev 1519) @@ -188,8 +188,10 @@ } } + //if the compilation successed if (success) { int i = 0; + //check if all the objects have an existing clas or a class being generated while (success && i < classDescriptors.size()) { success = (classDescriptors.get(i).getPackageName() != null || TagManager.getGuixClassHandler(classDescriptors.get(i).getName()) != null); i++; @@ -220,6 +222,7 @@ for (GuixModelObject mo : rootModelObjects.keySet()) { try { + //init generator GuixGenerator gen = (GuixGenerator) generatorClass.newInstance(); gen.setDestDir(destDir); gen.setGmo(mo); @@ -229,6 +232,7 @@ gen.setClasses(Arrays.asList(classNames)); gen.setLauncherName(launcherName); gen.setCSSFiles(mo.getCssFiles()); + //generates the file without databinding JavaFile generatedFile = gen.generate(); if(generatedFile != null) { generatedFiles.put(gen, generatedFile); @@ -245,25 +249,34 @@ } } } + //generation of the databinding for (GuixGenerator gen : generatedFiles.keySet()) { - int dataSourceNumber = 0; + //int dataSourceNumber = 0; + //databinding creation method StringBuffer dbCreation = new StringBuffer(); + //databinding deletion method StringBuffer dbDeletion = new StringBuffer(); + //databinding execution method StringBuffer dbProcess = new StringBuffer(); JavaFile jf = generatedFiles.get(gen); + //for each field which binds the value of others objects for (String field : gen.getBindingsToGenerate().keySet()) { for (String attr : gen.getBindingsToGenerate().get(field).keySet()) { dbCreation.append(dbCreation.length() != 0 ? "else if(\"" : "if(\"").append(field).append(".").append(attr).append("\".equals(_binding)) {\n"); dbDeletion.append(dbDeletion.length() != 0 ? "else if(\"" : "if(\"").append(field).append(".").append(attr).append("\".equals(_binding)) {\n"); dbProcess.append(dbProcess.length() != 0 ? "else if(\"" : "if(\"").append(field).append(".").append(attr).append("\".equals(_binding)) {\n").append(field).append(".set").append(Character.toUpperCase(attr.charAt(0))).append(attr.substring(1)).append("("); List<String[]> bindings = new ArrayList<String[]>(); + //the parser which decompose the binding into the different elements to bind JavaParser p = new JavaParser(new StringReader(gen.getBindingsToGenerate().get(field).get(attr))); - //start parsing + //start parsing the binding value while (!p.Line()) { SimpleNode node = p.popNode(); if (node != null) { + //get the different elements to bind for (String s : browseNode(node)) { + //decompose the element s into attributes List<String> l = new ArrayList<String>(); + //number of open brackets int parOuvertes = 0; StringBuffer read = new StringBuffer(); for (char c : s.toCharArray()) { @@ -293,24 +306,31 @@ } } } + //generates the code List<Class> listeners = new ArrayList<Class>(); for (String[] binding : bindings) { StringBuffer methodToInvoke = new StringBuffer(); + //the binding value before the generator changes it StringBuffer oldBinding = new StringBuffer(); + //generates the method name for calling the databinding process method for (String s : binding) { methodToInvoke.append(s.replaceAll("\\W", "")); oldBinding.append(s).append("."); } oldBinding.setLength(oldBinding.length() - 1); + //generates the code and modify the simple attribute name in the binding by the getter listeners.addAll(gen.generateBindings(dbCreation, dbDeletion, null, jf, null, binding, 0, null, methodToInvoke.toString(), generatedFiles)); //JavaArgument[] args = new JavaArgument[]{new JavaArgument(parameterType.getName(), "event")}; + //new value of the binding with the getters StringBuffer newBinding = new StringBuffer(); for (String s : binding) { newBinding.append(s).append("."); } newBinding.setLength(newBinding.length() - 1); + //replaces the old binding by the newer one gen.getBindingsToGenerate().get(field).put(attr, gen.getBindingsToGenerate().get(field).get(attr).replace(oldBinding.toString(), newBinding.toString())); + //method called by the listener if (jf.getMethod("onChangeFrom" + methodToInvoke, /*args*/ null) == null) { jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "onChangeFrom" + methodToInvoke.toString(), /*args*/ null, null, /*"_DataSource" + dataSourceNumber + ".propertyChange(null);"*/ "processDataBinding(\"" + field + "." + attr + "\");", null)); } @@ -321,17 +341,20 @@ dbCreation.append("}\n"); dbDeletion.append("}\n"); dbProcess.append(gen.getBindingsToGenerate().get(field).get(attr)).append(");\n}\n"); + //if the binding got some elements to bind if (listeners != null) { //jf.addField(new JavaField(Modifier.PRIVATE, "java.beans.PropertyChangeListener", "_DataSource" + dataSourceNumber, "new org.nuiton.guix.runtime.DataBindingListener(this,\"" + field + "." + attr + "\")", null, null)); + //method to init the databinding jf.getMethod("initDataBinding", null).appendBodyCode("applyDataBinding(\"" + field + "." + attr + "\");", "\n"); - for (Class listener : listeners) { - final List<Method> listenerMethods = Arrays.asList(listener.getMethods()); - Class parameterType = listenerMethods.get(0).getParameterTypes()[0]; - } +// for (Class listener : listeners) { +// final List<Method> listenerMethods = Arrays.asList(listener.getMethods()); +// Class parameterType = listenerMethods.get(0).getParameterTypes()[0]; +// } } - dataSourceNumber++; + //dataSourceNumber++; } } + //if the generated file has a superclass which also is a generated class, apply the databinding of the superclass to the class if (generatedFiles.get(jf.getSuperClass()) != null) { dbCreation.append("else {\nsuper.applyDataBinding(_binding);\n" + "return;\n}"); @@ -342,10 +365,12 @@ "return;\n}\n" + "activeBindings.add(_binding);\ntry{\n"); dbProcess.append("\n} finally {\nactiveBindings.remove(_binding);\n}\n"); + jf.addField(new JavaField(Modifier.PRIVATE, "java.util.List<String>", "activeBindings", "new java.util.ArrayList<String>()", "List of the active bindings", null), false); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "applyDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbCreation.toString(), null)); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removeDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbDeletion.toString(), null)); - jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "processDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbProcess.toString(), null)); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "applyDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbCreation.toString(), "Adds the listeners to the elements which are bound by another attribute")); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removeDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbDeletion.toString(), "Removes the listeners to the elements which are bound by another attribute")); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "processDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbProcess.toString(), "Executes the binding instruction")); + //saves the files gen.saveFiles(); } serializer.endTag("", "beans"); @@ -427,9 +452,16 @@ return classDescriptors.get(i); } + /** + * Decompose the binding into the different elements to bind + * + * @param node the Node being parsed + * @return the elements to bind + */ private List<String> browseNode(SimpleNode node) { List<String> result = new ArrayList<String>(); for (int i = 0; i < node.jjtGetNumChildren(); i++) { + //if the child is not a String and are not parameters of a method if (node.getChild(i).getId() == JavaParserTreeConstants.JJTPRIMARYEXPRESSION && !node.getChild(i).getText().trim().startsWith("(") && !node.getChild(i).getText().trim().startsWith("\"")) { result.add(node.getChild(i).getText().trim()); } Modified: trunk/guix-compiler/src/test/test.guix =================================================================== --- trunk/guix-compiler/src/test/test.guix 2009-07-23 11:51:40 UTC (rev 1518) +++ trunk/guix-compiler/src/test/test.guix 2009-07-23 13:33:45 UTC (rev 1519) @@ -1,4 +1,4 @@ <?xml version='1.0' encoding='UTF-8' ?> -<org.nuiton.guix.Test> +<Application> <Panel /> -</org.nuiton.guix.Test> +</Application> Modified: trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.css =================================================================== --- trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.css 2009-07-23 11:51:40 UTC (rev 1518) +++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.css 2009-07-23 13:33:45 UTC (rev 1519) @@ -1,16 +1,37 @@ -#button:{object . getText( ) . startsWith( "-" )} +#button:{getText( ) . startsWith( "-" )} { - foreground: red; + foreground: "new java.awt.Color(0,255,0)"; } #label { - background : blue; + foreground : "new java.awt.Color(0,120,255)"; } - -.bold +#label:onMouseEntered { - font : bold; + foreground : "new java.awt.Color(255,120,0)"; } +#label:onMouseExited +{ + foreground : "new java.awt.Color(0,120,255)"; +} + +JToolBar { + border : "new javax.swing.border.EtchedBorder()"; + constraint : "BorderLayout.NORTH"; +} + +#tabPanel { + constraint : "BorderLayout.CENTER"; + size : "800,400"; +} + +#bouton1, #textfield { + size: "100,35"; +} + +.table { + border : "new javax.swing.border.EtchedBorder()"; +} Modified: trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.script =================================================================== --- trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.script 2009-07-23 11:51:40 UTC (rev 1518) +++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo.script 2009-07-23 13:33:45 UTC (rev 1519) @@ -1,3 +1,3 @@ -public void testSameName() { +static public void testSameName() { System.out.println("load the script file with the same name"); } Modified: trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo2.guix =================================================================== --- trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo2.guix 2009-07-23 11:51:40 UTC (rev 1518) +++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo2.guix 2009-07-23 13:33:45 UTC (rev 1519) @@ -1,5 +1,5 @@ <?xml version='1.0' encoding='UTF-8' ?> <!-- test javadoc Application --> -<swing:JPanel xmlns:swing='javax.swing.*'> - <swing:JToggleButton id="button" text="Push me" selected ="true" /> -</swing:JPanel> +<Panel> + <ToggleButton id="button" text="Push me" selected="true" onClick='{System.out.println("test")}' /> +</Panel> Modified: trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo3.guix =================================================================== --- trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo3.guix 2009-07-23 11:51:40 UTC (rev 1518) +++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/GuixDemo3.guix 2009-07-23 13:33:45 UTC (rev 1519) @@ -1,4 +1,4 @@ <?xml version='1.0' encoding='UTF-8' ?> <!-- test javadoc Application --> -<swing:JButton xmlns:swing='javax.swing.*'> -</swing:JButton> +<Button text="GuixDemo3"> +</Button> Modified: trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/JButton.css =================================================================== --- trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/JButton.css 2009-07-23 11:51:40 UTC (rev 1518) +++ trunk/guix-test-swing/src/main/java/org/nuiton/guix/demo/JButton.css 2009-07-23 13:33:45 UTC (rev 1519) @@ -1,30 +1,9 @@ -JButton { - font-size: 18; - width: 80; - height: 35; -} - -JButton.digit { - foreground: blue; -} - -JButton#dot { - font-size: 20; -} - -JButton.operator { - font-size: 16; - foreground: #009900; -} - -JButton.clear { - foreground: red; -} - -JButton:mouseover { - font-weight: bold; -} - -JButton.operator:mouseover { - font-weight: normal; +Button { + size: "80,35"; + foreground: "new java.awt.Color(120,255,0)"; } + +Button:onActionPerformed { + text : "click !"; +} +
participants (1)
-
kmorin@users.labs.libre-entreprise.org