Dynamically generate classes representing elements on the HTML @Page
authorJan Horvath <jan.horvath@oracle.com>
Thu, 21 Mar 2013 15:45:42 +0100
changeset 8669b4751828ceb
parent 829 0e4945540961
child 867 b3768be30aa0
Dynamically generate classes representing elements on the HTML @Page
javaquery/api/pom.xml
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/Attributes.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ElementGenerator.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PredefinedFields.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Button.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Image.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Input.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Title.java
javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ElementGeneratorTest.java
     1.1 --- a/javaquery/api/pom.xml	Sat Mar 09 16:09:35 2013 +0100
     1.2 +++ b/javaquery/api/pom.xml	Thu Mar 21 15:45:42 2013 +0100
     1.3 @@ -73,5 +73,10 @@
     1.4        <version>${project.version}</version>
     1.5        <scope>test</scope>
     1.6      </dependency>
     1.7 +    <dependency>
     1.8 +      <groupId>org.netbeans.modules</groupId>
     1.9 +      <artifactId>org-netbeans-modules-html-parser</artifactId>
    1.10 +      <version>RELEASE73</version>
    1.11 +    </dependency>
    1.12    </dependencies>
    1.13  </project>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/Attributes.java	Thu Mar 21 15:45:42 2013 +0100
     2.3 @@ -0,0 +1,57 @@
     2.4 +/**
     2.5 + * Back 2 Browser Bytecode Translator
     2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, version 2 of the License.
    2.11 + *
    2.12 + * This program is distributed in the hope that it will be useful,
    2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 + * GNU General Public License for more details.
    2.16 + *
    2.17 + * You should have received a copy of the GNU General Public License
    2.18 + * along with this program. Look for COPYING file in the top folder.
    2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    2.20 + */
    2.21 +package org.apidesign.bck2brwsr.htmlpage;
    2.22 +
    2.23 +import java.util.HashMap;
    2.24 +import java.util.Map;
    2.25 +
    2.26 +/**
    2.27 + * Temporary storing the type of attributes here. This should be implemented in HTML 5 model
    2.28 + *
    2.29 + * @author Jan Horvath <jhorvath@netbeans.org>
    2.30 + */
    2.31 +public class Attributes {
    2.32 +    
    2.33 +    static final Map<String, String> TYPES = new HashMap<String, String>() {
    2.34 +        {
    2.35 +            // HTML Global Attributes
    2.36 +            // id attribute is already defined in Element, don't add it again
    2.37 +            put("accesskey", "String");
    2.38 +            put("class", "String");
    2.39 +            put("contenteditable", "Boolean");
    2.40 +            put("contextmenu", "String");
    2.41 +            put("dir", "String");
    2.42 +            put("draggable", "Boolean");
    2.43 +            put("dropzone", "String");
    2.44 +            put("hidden", "Boolean");
    2.45 +            put("lang", "String");
    2.46 +            put("spellcheck", "Boolean");
    2.47 +            put("style", "String");
    2.48 +            put("tabindex", "String");
    2.49 +            put("title", "String");
    2.50 +            put("translate", "Boolean");
    2.51 +            put("width", "Integer");
    2.52 +            put("height", "Integer");
    2.53 +            
    2.54 +            put("value", "String");
    2.55 +            put("disabled", "Boolean");
    2.56 +            
    2.57 +//          put("text", "String"); 'text' field is used to set innerHTML of element
    2.58 +        }
    2.59 +    };
    2.60 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ElementGenerator.java	Thu Mar 21 15:45:42 2013 +0100
     3.3 @@ -0,0 +1,175 @@
     3.4 +/**
     3.5 + * Back 2 Browser Bytecode Translator
     3.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     3.7 + *
     3.8 + * This program is free software: you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License as published by
    3.10 + * the Free Software Foundation, version 2 of the License.
    3.11 + *
    3.12 + * This program is distributed in the hope that it will be useful,
    3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 + * GNU General Public License for more details.
    3.16 + *
    3.17 + * You should have received a copy of the GNU General Public License
    3.18 + * along with this program. Look for COPYING file in the top folder.
    3.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    3.20 + */
    3.21 +package org.apidesign.bck2brwsr.htmlpage;
    3.22 +
    3.23 +import java.io.IOException;
    3.24 +import java.io.OutputStreamWriter;
    3.25 +import java.io.Writer;
    3.26 +import java.util.Arrays;
    3.27 +import java.util.Collections;
    3.28 +import java.util.HashMap;
    3.29 +import java.util.Map;
    3.30 +import java.util.Map.Entry;
    3.31 +import java.util.ServiceLoader;
    3.32 +import javax.annotation.processing.ProcessingEnvironment;
    3.33 +import javax.lang.model.element.Element;
    3.34 +import javax.tools.Diagnostic;
    3.35 +import javax.tools.FileObject;
    3.36 +import org.netbeans.modules.html.editor.lib.api.HtmlVersion;
    3.37 +import org.netbeans.modules.html.editor.lib.api.model.HtmlModel;
    3.38 +import org.netbeans.modules.html.editor.lib.api.model.HtmlModelProvider;
    3.39 +import org.netbeans.modules.html.editor.lib.api.model.HtmlTag;
    3.40 +import org.netbeans.modules.html.editor.lib.api.model.HtmlTagAttribute;
    3.41 +
    3.42 +/**
    3.43 + *
    3.44 + * @author Jan Horvath <jhorvath@netbeans.org>
    3.45 + */
    3.46 +public class ElementGenerator {
    3.47 +
    3.48 +    static final Map<String, String> NAMING_EXCEPTIONS = new HashMap<String, String>() {
    3.49 +        {
    3.50 +            put("img", "Image");
    3.51 +            put("class", "Clazz");
    3.52 +        }
    3.53 +    };
    3.54 +    
    3.55 +    static final String javaKeywords[] = {
    3.56 +        "abstract", "assert", "boolean", "break", "byte", "case",
    3.57 +        "catch", "char", "class", "const", "continue", "default", 
    3.58 +        "do", "double", "else", "extends", "false", "final", "finally", 
    3.59 +        "float", "for", "goto", "if", "implements", "import", 
    3.60 +        "instanceof", "int", "interface", "long", "native", "new",
    3.61 +        "null", "package", "private", "protected", "public",
    3.62 +        "return", "short", "static", "strictfp", "super",
    3.63 +        "switch", "synchronized", "this", "throw", "throws",
    3.64 +        "transient", "true", "try", "void", "volatile", "while"
    3.65 +    };
    3.66 +    
    3.67 +    private static Map<String, String> elements = new HashMap<String, String>();
    3.68 +    private final ProcessingEnvironment processingEnv;
    3.69 +    private HtmlModel model = null;
    3.70 +
    3.71 +    ElementGenerator(ProcessingEnvironment processingEnv) {
    3.72 +        this.processingEnv = processingEnv;
    3.73 +    }
    3.74 +
    3.75 +    String getType(String pkg, String tag, Element e) {
    3.76 +        String className = elements.get(tag);
    3.77 +        if (className == null) {
    3.78 +            className = createClass(pkg, tag, e);
    3.79 +            elements.put(tag, className);
    3.80 +        }
    3.81 +        return className;
    3.82 +    }
    3.83 +
    3.84 +    private String createClass(String pkg, String tag, Element e) {
    3.85 +        String className = className(tag);
    3.86 +        Writer w;
    3.87 +        try {
    3.88 +            FileObject java = processingEnv.getFiler().createSourceFile(pkg + '.' + className, e);
    3.89 +            w = new OutputStreamWriter(java.openOutputStream());
    3.90 +            try {
    3.91 +                w.append("package " + pkg + ";\n\n");
    3.92 +                w.append("import org.apidesign.bck2brwsr.htmlpage.api.*;\n");
    3.93 +                PredefinedFields.appendImports(w, tag);
    3.94 +                w.append("\n");
    3.95 +                
    3.96 +                w.append("class ").append(className).append(" extends Element {\n\n");
    3.97 +                w.append("    public ").append(className).append("(String id) {\n");
    3.98 +                w.append("        super(id);\n");
    3.99 +                w.append("    }\n\n");
   3.100 +                for (Entry<String, String> entry : getAttributes(tag).entrySet()) {
   3.101 +                    String attrName = entry.getKey();
   3.102 +                    String attrType = entry.getValue();
   3.103 +                    // getter
   3.104 +                    w.append("    public ").append(attrType).append(" ")
   3.105 +                            .append("get").append(className(attrName)).append("() {\n");
   3.106 +                    w.append("        return (").append(attrType).append(")getAttribute(\"")
   3.107 +                            .append(attrName).append("\");\n");
   3.108 +                    w.append("    }\n\n");
   3.109 +                    // setter
   3.110 +                    w.append("    public void ")
   3.111 +                            .append("set").append(className(attrName)).append("(")
   3.112 +                            .append(attrType).append(" ").append(attributeName(attrName)).append(") {\n");
   3.113 +                    w.append("        setAttribute(\"").append(attrName).append("\", ").append(attributeName(attrName)).append(");\n");
   3.114 +                    w.append("    }\n\n");
   3.115 +                }
   3.116 +                PredefinedFields.appendFields(w, tag);
   3.117 +                w.append("}\n");
   3.118 +            } finally {
   3.119 +                w.close();
   3.120 +            }
   3.121 +        } catch (IOException ex) {
   3.122 +            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Can't create " + className + ".java", e);
   3.123 +            return null;
   3.124 +        }
   3.125 +        return className;
   3.126 +    }
   3.127 +
   3.128 +    Map<String, String> getAttributes(String tagName) {
   3.129 +        Map<String, String> result = new HashMap<String, String>();
   3.130 +
   3.131 +        if (model == null) {
   3.132 +            // HtmlModelProvider modelProvider = Lookup.getDefault().lookup(HtmlModelProvider.class);
   3.133 +            ServiceLoader<HtmlModelProvider> hmpLoader = 
   3.134 +                    ServiceLoader.load(HtmlModelProvider.class, this.getClass().getClassLoader());
   3.135 +            for (HtmlModelProvider htmlModelProvider : hmpLoader) {
   3.136 +                model = htmlModelProvider.getModel(HtmlVersion.HTML5);
   3.137 +                if (model != null) {
   3.138 +                    break;
   3.139 +                }
   3.140 +            }
   3.141 +        }
   3.142 +        
   3.143 +        if (model == null) {
   3.144 +            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, 
   3.145 +                    "HTML 5 model provider was not found on classpath");
   3.146 +            return Collections.emptyMap();
   3.147 +        }
   3.148 +        HtmlTag tag = model.getTag(tagName);
   3.149 +        for (HtmlTagAttribute attr : tag.getAttributes()) {
   3.150 +            String name = attr.getName();
   3.151 +            String type = Attributes.TYPES.get(name);
   3.152 +            if (type != null) {
   3.153 +                result.put(name, type);
   3.154 +            }
   3.155 +        }
   3.156 +        
   3.157 +        return result;
   3.158 +    }
   3.159 +
   3.160 +    private String className(String s) {
   3.161 +        if (s.length() == 0) {
   3.162 +            return s;
   3.163 +        }
   3.164 +        String name = NAMING_EXCEPTIONS.get(s.toLowerCase());
   3.165 +        if (name == null) {
   3.166 +            name = s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
   3.167 +        }
   3.168 +        return name;
   3.169 +    }
   3.170 +
   3.171 +    private String attributeName(String s) {
   3.172 +        if (Arrays.binarySearch(javaKeywords, s) >= 0) {
   3.173 +            return String.format("%sAttr", s);
   3.174 +        }
   3.175 +        return s;
   3.176 +    }
   3.177 +    
   3.178 +}
     4.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java	Sat Mar 09 16:09:35 2013 +0100
     4.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java	Thu Mar 21 15:45:42 2013 +0100
     4.3 @@ -78,6 +78,7 @@
     4.4              String pkg = pe.getQualifiedName().toString();
     4.5              
     4.6              ProcessPage pp;
     4.7 +            ElementGenerator eGen = new ElementGenerator(processingEnv);
     4.8              try {
     4.9                  InputStream is = openStream(pkg, p.xhtml());
    4.10                  pp = ProcessPage.readPage(is);
    4.11 @@ -105,7 +106,7 @@
    4.12                      }
    4.13                      for (String id : pp.ids()) {
    4.14                          String tag = pp.tagNameForId(id);
    4.15 -                        String type = type(tag);
    4.16 +                        String type = eGen.getType(pkg, tag, e);
    4.17                          w.append("  ").append("public final ").
    4.18                              append(type).append(' ').append(cnstnt(id)).append(" = new ").
    4.19                              append(type).append("(\"").append(id).append("\");\n");
    4.20 @@ -158,25 +159,6 @@
    4.21          }
    4.22      }
    4.23  
    4.24 -    private static String type(String tag) {
    4.25 -        if (tag.equals("title")) {
    4.26 -            return "Title";
    4.27 -        }
    4.28 -        if (tag.equals("button")) {
    4.29 -            return "Button";
    4.30 -        }
    4.31 -        if (tag.equals("input")) {
    4.32 -            return "Input";
    4.33 -        }
    4.34 -        if (tag.equals("canvas")) {
    4.35 -            return "Canvas";
    4.36 -        }
    4.37 -        if (tag.equals("img")) {
    4.38 -            return "Image";
    4.39 -        }
    4.40 -        return "Element";
    4.41 -    }
    4.42 -
    4.43      private static String cnstnt(String id) {
    4.44          return id.toUpperCase(Locale.ENGLISH).replace('.', '_').replace('-', '_');
    4.45      }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PredefinedFields.java	Thu Mar 21 15:45:42 2013 +0100
     5.3 @@ -0,0 +1,65 @@
     5.4 +/**
     5.5 + * Back 2 Browser Bytecode Translator
     5.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     5.7 + *
     5.8 + * This program is free software: you can redistribute it and/or modify
     5.9 + * it under the terms of the GNU General Public License as published by
    5.10 + * the Free Software Foundation, version 2 of the License.
    5.11 + *
    5.12 + * This program is distributed in the hope that it will be useful,
    5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.15 + * GNU General Public License for more details.
    5.16 + *
    5.17 + * You should have received a copy of the GNU General Public License
    5.18 + * along with this program. Look for COPYING file in the top folder.
    5.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    5.20 + */
    5.21 +package org.apidesign.bck2brwsr.htmlpage;
    5.22 +
    5.23 +import java.io.IOException;
    5.24 +import java.io.Writer;
    5.25 +import java.util.HashMap;
    5.26 +import java.util.Map;
    5.27 +
    5.28 +/**
    5.29 + *
    5.30 + * @author Jan Horvath <jhorvath@netbeans.org>
    5.31 + */
    5.32 +public class PredefinedFields {
    5.33 +    
    5.34 +    private static final Map<String, String> IMPORTS = new HashMap<String, String>() {
    5.35 +        {
    5.36 +            put("canvas", "import org.apidesign.bck2brwsr.core.JavaScriptBody;");
    5.37 +        }
    5.38 +    };
    5.39 +    
    5.40 +    private static final Map<String, String> FIELDS = new HashMap<String, String>() {
    5.41 +        {
    5.42 +            put("canvas", 
    5.43 +                    "    @JavaScriptBody(\n" +
    5.44 +                    "            args = {\"el\"},\n" +
    5.45 +                    "            body = \"var e = window.document.getElementById(el._id());\\n\"\n" +
    5.46 +                    "            + \"return e.getContext('2d');\\n\")\n" +
    5.47 +                    "    private native static Object getContextImpl(Canvas el);\n" +
    5.48 +                    "    \n" +
    5.49 +                    "    public GraphicsContext getContext() {\n" +
    5.50 +                    "        return new GraphicsContext(getContextImpl(this));\n" +
    5.51 +                    "    }");
    5.52 +        }
    5.53 +    };
    5.54 +    
    5.55 +    static void appendImports(Writer w, String tag) throws IOException {
    5.56 +        String text = IMPORTS.get(tag.toLowerCase());
    5.57 +        if (text != null) {
    5.58 +            w.append(text).append("\n");
    5.59 +        }
    5.60 +    }
    5.61 +    
    5.62 +    static void appendFields(Writer w, String tag) throws IOException {
    5.63 +        String text = FIELDS.get(tag.toLowerCase());
    5.64 +        if (text != null) {
    5.65 +            w.append(text).append("\n");
    5.66 +        }
    5.67 +    }
    5.68 +}
     6.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Button.java	Sat Mar 09 16:09:35 2013 +0100
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,36 +0,0 @@
     6.4 -/**
     6.5 - * Back 2 Browser Bytecode Translator
     6.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     6.7 - *
     6.8 - * This program is free software: you can redistribute it and/or modify
     6.9 - * it under the terms of the GNU General Public License as published by
    6.10 - * the Free Software Foundation, version 2 of the License.
    6.11 - *
    6.12 - * This program is distributed in the hope that it will be useful,
    6.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 - * GNU General Public License for more details.
    6.16 - *
    6.17 - * You should have received a copy of the GNU General Public License
    6.18 - * along with this program. Look for COPYING file in the top folder.
    6.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    6.20 - */
    6.21 -package org.apidesign.bck2brwsr.htmlpage.api;
    6.22 -
    6.23 -/**
    6.24 - *
    6.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    6.26 - */
    6.27 -public final class Button extends Element {
    6.28 -    public Button(String id) {
    6.29 -        super(id);
    6.30 -    }
    6.31 -
    6.32 -    @Override
    6.33 -    void dontSubclass() {
    6.34 -    }
    6.35 -
    6.36 -    public void setDisabled(boolean state) {
    6.37 -        setAttribute(this, "disabled", state);
    6.38 -    }
    6.39 -}
     7.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java	Sat Mar 09 16:09:35 2013 +0100
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,64 +0,0 @@
     7.4 -/**
     7.5 - * Back 2 Browser Bytecode Translator
     7.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     7.7 - *
     7.8 - * This program is free software: you can redistribute it and/or modify
     7.9 - * it under the terms of the GNU General Public License as published by
    7.10 - * the Free Software Foundation, version 2 of the License.
    7.11 - *
    7.12 - * This program is distributed in the hope that it will be useful,
    7.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.15 - * GNU General Public License for more details.
    7.16 - *
    7.17 - * You should have received a copy of the GNU General Public License
    7.18 - * along with this program. Look for COPYING file in the top folder.
    7.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    7.20 - */
    7.21 -package org.apidesign.bck2brwsr.htmlpage.api;
    7.22 -
    7.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
    7.24 -import static org.apidesign.bck2brwsr.htmlpage.api.Element.getAttribute;
    7.25 -
    7.26 -/**
    7.27 - *
    7.28 - * @author Anton Epple <toni.epple@eppleton.de>
    7.29 - */
    7.30 -public class Canvas extends Element {
    7.31 -
    7.32 -    public Canvas(String id) {
    7.33 -        super(id);
    7.34 -    }
    7.35 -
    7.36 -    public void setHeight(int height) {
    7.37 -        setAttribute(this, "height", height);
    7.38 -    }
    7.39 -
    7.40 -    public int getHeight() {
    7.41 -       Object ret =  getAttribute(this, "height");
    7.42 -       return (ret instanceof Number) ? ((Number)ret).intValue(): Integer.MIN_VALUE;
    7.43 -    }
    7.44 -    
    7.45 -    public void setWidth(int width) {
    7.46 -        setAttribute(this, "width", width);
    7.47 -    }
    7.48 -
    7.49 -    public int getWidth() {
    7.50 -       Object ret =  getAttribute(this, "width");
    7.51 -       return (ret instanceof Number) ? ((Number)ret).intValue(): Integer.MIN_VALUE;
    7.52 -    }
    7.53 -
    7.54 -    @JavaScriptBody(
    7.55 -            args = {"el"},
    7.56 -            body = "var e = window.document.getElementById(el._id());\n"
    7.57 -            + "return e.getContext('2d');\n")
    7.58 -    private native static Object getContextImpl(Canvas el);
    7.59 -
    7.60 -    public GraphicsContext getContext() {
    7.61 -        return new GraphicsContext(getContextImpl(this));
    7.62 -    }
    7.63 -
    7.64 -    @Override
    7.65 -    void dontSubclass() {
    7.66 -    }
    7.67 -}
     8.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Sat Mar 09 16:09:35 2013 +0100
     8.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Thu Mar 21 15:45:42 2013 +0100
     8.3 @@ -37,7 +37,13 @@
     8.4          return id;
     8.5      }
     8.6      
     8.7 -    abstract void dontSubclass();
     8.8 +    public String getText() {
     8.9 +        return (String)getAttribute("innerHTML");
    8.10 +    }
    8.11 +
    8.12 +    public void setText(String text) {
    8.13 +        setAttribute("innerHTML", text);
    8.14 +    }
    8.15      
    8.16      @JavaScriptBody(
    8.17          args={"el", "property", "value"},
     9.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java	Sat Mar 09 16:09:35 2013 +0100
     9.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java	Thu Mar 21 15:45:42 2013 +0100
     9.3 @@ -27,7 +27,7 @@
     9.4  
     9.5      Object context;
     9.6  
     9.7 -    GraphicsContext(Object contextImpl) {
     9.8 +    public GraphicsContext(Object contextImpl) {
     9.9          this.context = contextImpl;
    9.10      }
    9.11  
    9.12 @@ -113,15 +113,15 @@
    9.13      @JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
    9.14      public native void scale(double x, double y);
    9.15  
    9.16 -    public void drawImage(Image image, double x, double y) {
    9.17 +    public void drawImage(Element image, double x, double y) {
    9.18          drawImageImpl(context, Element.getElementById(image), x, y);
    9.19      }
    9.20  
    9.21 -    public void drawImage(Image image, double x, double y, double width, double height) {
    9.22 +    public void drawImage(Element image, double x, double y, double width, double height) {
    9.23          drawImageImpl(context, Element.getElementById(image), x, y, width, height);
    9.24      }
    9.25  
    9.26 -    public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
    9.27 +    public void drawImage(Element image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
    9.28          drawImageImpl(context, Element.getElementById(image), sx, sy, sWidth, sHeight, x, y, width, height);
    9.29      }
    9.30  
    9.31 @@ -319,12 +319,12 @@
    9.32      @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
    9.33      private  native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
    9.34  
    9.35 -    public Pattern createPattern(Image image, String repeat) {
    9.36 +    public Pattern createPattern(Element image, String repeat) {
    9.37          return new Pattern(createPatternImpl(context, image, repeat));
    9.38      }
    9.39  
    9.40      @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
    9.41 -    private static native Object createPatternImpl(Object context, Image image, String repeat);
    9.42 +    private static native Object createPatternImpl(Object context, Element image, String repeat);
    9.43  
    9.44      public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
    9.45          return new RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
    10.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Image.java	Sat Mar 09 16:09:35 2013 +0100
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,36 +0,0 @@
    10.4 -/**
    10.5 - * Back 2 Browser Bytecode Translator
    10.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    10.7 - *
    10.8 - * This program is free software: you can redistribute it and/or modify
    10.9 - * it under the terms of the GNU General Public License as published by
   10.10 - * the Free Software Foundation, version 2 of the License.
   10.11 - *
   10.12 - * This program is distributed in the hope that it will be useful,
   10.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.15 - * GNU General Public License for more details.
   10.16 - *
   10.17 - * You should have received a copy of the GNU General Public License
   10.18 - * along with this program. Look for COPYING file in the top folder.
   10.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   10.20 - */
   10.21 -package org.apidesign.bck2brwsr.htmlpage.api;
   10.22 -
   10.23 -/**
   10.24 - *
   10.25 - * @author Anton Epple <toni.epple@eppleton.de>
   10.26 - */
   10.27 -public class Image extends Element{
   10.28 -
   10.29 -    public Image(String id) {
   10.30 -        super(id);
   10.31 -    }
   10.32 -
   10.33 -    
   10.34 -    
   10.35 -    @Override
   10.36 -    void dontSubclass() {
   10.37 -    }
   10.38 -    
   10.39 -}
    11.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Input.java	Sat Mar 09 16:09:35 2013 +0100
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,44 +0,0 @@
    11.4 -/**
    11.5 - * Back 2 Browser Bytecode Translator
    11.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    11.7 - *
    11.8 - * This program is free software: you can redistribute it and/or modify
    11.9 - * it under the terms of the GNU General Public License as published by
   11.10 - * the Free Software Foundation, version 2 of the License.
   11.11 - *
   11.12 - * This program is distributed in the hope that it will be useful,
   11.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.15 - * GNU General Public License for more details.
   11.16 - *
   11.17 - * You should have received a copy of the GNU General Public License
   11.18 - * along with this program. Look for COPYING file in the top folder.
   11.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   11.20 - */
   11.21 -package org.apidesign.bck2brwsr.htmlpage.api;
   11.22 -
   11.23 -/**
   11.24 - *
   11.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   11.26 - */
   11.27 -public final class Input extends Element {
   11.28 -    public Input(String id) {
   11.29 -        super(id);
   11.30 -    }
   11.31 -
   11.32 -    @Override
   11.33 -    void dontSubclass() {
   11.34 -    }
   11.35 -    
   11.36 -    public void setAutocomplete(boolean state) {
   11.37 -        setAttribute(this, "autocomplete", state);
   11.38 -    }
   11.39 -    
   11.40 -    public final String getValue() {
   11.41 -        return (String)getAttribute(this, "value");
   11.42 -    }
   11.43 -    
   11.44 -    public final void setValue(String txt) {
   11.45 -        setAttribute(this, "value", txt);
   11.46 -    }
   11.47 -}
    12.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Title.java	Sat Mar 09 16:09:35 2013 +0100
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,36 +0,0 @@
    12.4 -/**
    12.5 - * Back 2 Browser Bytecode Translator
    12.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    12.7 - *
    12.8 - * This program is free software: you can redistribute it and/or modify
    12.9 - * it under the terms of the GNU General Public License as published by
   12.10 - * the Free Software Foundation, version 2 of the License.
   12.11 - *
   12.12 - * This program is distributed in the hope that it will be useful,
   12.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.15 - * GNU General Public License for more details.
   12.16 - *
   12.17 - * You should have received a copy of the GNU General Public License
   12.18 - * along with this program. Look for COPYING file in the top folder.
   12.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   12.20 - */
   12.21 -package org.apidesign.bck2brwsr.htmlpage.api;
   12.22 -
   12.23 -/**
   12.24 - *
   12.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   12.26 - */
   12.27 -public class Title extends Element {
   12.28 -    public Title(String id) {
   12.29 -        super(id);
   12.30 -    }
   12.31 -
   12.32 -    @Override
   12.33 -    void dontSubclass() {
   12.34 -    }
   12.35 -    
   12.36 -    public final void setText(String text) {
   12.37 -        setAttribute(this, "innerHTML", text);
   12.38 -    }
   12.39 -}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ElementGeneratorTest.java	Thu Mar 21 15:45:42 2013 +0100
    13.3 @@ -0,0 +1,35 @@
    13.4 +/**
    13.5 + * Back 2 Browser Bytecode Translator
    13.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    13.7 + *
    13.8 + * This program is free software: you can redistribute it and/or modify
    13.9 + * it under the terms of the GNU General Public License as published by
   13.10 + * the Free Software Foundation, version 2 of the License.
   13.11 + *
   13.12 + * This program is distributed in the hope that it will be useful,
   13.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.15 + * GNU General Public License for more details.
   13.16 + *
   13.17 + * You should have received a copy of the GNU General Public License
   13.18 + * along with this program. Look for COPYING file in the top folder.
   13.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   13.20 + */
   13.21 +package org.apidesign.bck2brwsr.htmlpage;
   13.22 +
   13.23 +import java.util.Map;
   13.24 +import static org.testng.Assert.*;
   13.25 +import org.testng.annotations.Test;
   13.26 +
   13.27 +/**
   13.28 + *
   13.29 + * @author Jan Horvath <jhorvath@netbeans.org>
   13.30 + */
   13.31 +public class ElementGeneratorTest {
   13.32 +    
   13.33 +    @Test public void testGetAttributes() {
   13.34 +        ElementGenerator gen = new ElementGenerator(null);
   13.35 +        Map<String, String> attrs = gen.getAttributes("input");
   13.36 +        assertEquals(attrs.get("width"), "Integer", "Expected type of width attribute is Integer");
   13.37 +    }
   13.38 +}