if (compProperties.size() > 0) { outProps.add("# component properties set by " + templateName); String shortClassName = forClassName.substring(forClassName.lastIndexOf(".") + 1);
if (compProperties.size() > 0 || installList.size() > 0) {
    public void generate(File directory, List outProps) throws Exception {        if (anyError)            return;        if (! directory.exists()) {            directory.mkdir();        }        else {            if (!directory.isDirectory())                throw new IllegalArgumentException(directory + " is not a directory");        }        File outFile = new File(directory, templateName + ".java");        PrintWriter out = new PrintWriter(new FileWriter(outFile));        outProps.add("#------------------- " + templateName);                out.println ("// DO NOT EDIT! Your changes will be lost: generated from '" + sourcefile.getCanonicalPath() + "'");        if (pkg != null) {            out.println ("package " + pkg + ";\n\n");            outProps.add(templateName + "=" + pkg + "." + templateName);        }        else {            out.println("// default package\n");            outProps.add(templateName + "=" + templateName);        }        out.println ("import java.io.IOException;\n");        out.println ("import org.wings.*;");        out.println ("import org.wings.border.*;");        out.println ("import org.wings.style.*;");        out.println ("import org.wings.util.*;");        out.println ("import org.wings.event.*;");        out.println ("import org.wings.io.Device;");        if (cgProperties.size() > 0 || compProperties.size() > 0 ) {            out.println ("import org.wings.plaf.CGManager;");            out.println ("import org.wings.session.SessionManager;");        }        Iterator imports = importList.iterator();        if (imports.hasNext()) {            out.println("\n// user provided imports");        }        while (imports.hasNext()) {            out.println("import " + imports.next() + ";");        }        out.println();        out.print ("public class " + templateName);        // extend other CGs ?        if (extendsClassName != null) {            out.print(" extends " + extendsClassName);        }        out.print (" implements SConstants");        /*         * find out the name of the interface to be implemented.         */        Class cgInterface = null;        for (int i=0; i < componentMethods.length; i++) {            if ("setCG".equals(componentMethods[i].getName()) &&                !(org.wings.plaf.ComponentCG.class                  .equals(componentMethods[i].getParameterTypes()[0])))                 {                    cgInterface = componentMethods[i].getParameterTypes()[0];                    break;                }        }        if (cgInterface != null) {            out.print(", " + cgInterface.getName());        }        else {            out.print(", ComponentCG");        }        out.println(" {");                // collected HTML snippets        out.println ("\n//--- byte array converted template snippets.");        Iterator n = stringPool.getNames();        while (n.hasNext()) {            String name = (String) n.next();            out.print (INDENT + "private final static byte[] ");            out.print (name);            int fillNumber = VAR_LEN - name.length();            for (int i=0; i < fillNumber; ++i)                 out.print(' ');            out.print ("= ");            out.print (stringPool.getQuotedString(name));            out.println (".getBytes();");        }                if (cgProperties.size() > 0) {            out.println("\n//--- properties of this plaf.");            Iterator props = cgProperties.iterator();            while (props.hasNext()) {                Property p = (Property) props.next();                out.print(INDENT + "private " + p.getTypeName());                out.print(" " + p.getName());                out.print(";\n");            }            out.println();                        /*             * constructor ...             */            out.println(INDENT + "/**");            out.println(INDENT + " * Initialize properties from config");            out.println(INDENT + " */");            // get settings of this CG from properties file in constructor.            out.println(INDENT + "public " + templateName + "() {");            out.println(INDENT + INDENT                         + "final CGManager manager = SessionManager.getSession().getCGManager();\n");            props = cgProperties.iterator();            while (props.hasNext()) {                Property p = (Property) props.next();                // see LookAndFeel::ResourceFactory                String globalPropName = (templateName + "." + p.getName()                                         +(p.shouldCache() ? "" : ".nocache"));                out.print(INDENT + INDENT);                out.print("set" + capitalize(p.getName()));                out.print("((" + p.getTypeName() + ") ");                out.print("manager.getObject(\"" + globalPropName);                out.print("\", ");                out.println(p.getType().getName() + ".class));");                // properties come from a file with this value.                String pValue = p.getValue();                if (pValue == null || pValue.trim().length() == 0) {                    outProps.add("#" + globalPropName + "=");                }                else {                    outProps.add(globalPropName + "=" + pValue);                }            }            out.println(INDENT + "}\n"); // end constructor.        }                out.println();        /*         * installCG()         */        out.print(INDENT);        out.println("public void installCG(final SComponent comp) {");        if (compProperties.size() > 0) {            outProps.add("# component properties set by "                         + templateName);            String shortClassName = forClassName.substring(forClassName.lastIndexOf(".") + 1);            out.println(INDENT + INDENT + "final " + forClassName                         + " component = (" + forClassName + ") comp;");            out.println(INDENT + INDENT + "final CGManager manager = component.getSession().getCGManager();");            out.println(INDENT + INDENT + "Object value;");            out.println(INDENT + INDENT + "Object previous;");            printConfigurationSetters(out, compProperties, shortClassName+".",                                      outProps);        }        out.println(INDENT + "}");        /*         * un-installCG()         */        out.print(INDENT);        out.println("public void uninstallCG(final SComponent component) {");        // nothing for now. We could reset this to old values ..        out.println(INDENT + "}");                // common stuff.        if (commonJavaCode.length() > 0) {            out.println ("\n//--- code from common area in template.");            out.print( commonJavaCode.toString() );            out.println ("\n//--- end code from common area in template.");        }                // write function header.        out.print ("\n\n" + INDENT + "public void write("                   + "final org.wings.io.Device device,\n" + INDENT                   + "                  final org.wings.SComponent _c)\n"                   + INDENT + INDENT + "throws java.io.IOException {\n");        out.println(INDENT + INDENT                    + "final " + forClassName + " component = ("                    + forClassName + ") _c;");        if (writeBorder) {            out.println(INDENT + INDENT                        + "final SBorder _border = component.getBorder();");            out.println(INDENT + INDENT                        + "if (_border != null) { _border.writePrefix(device); }");        }                out.println ("\n//--- code from write-template.");        // collected write stuff.        out.print ( writeJavaCode.toString());        out.println ("\n//--- end code from write-template.");        if (writeBorder) {            out.println(INDENT + INDENT                        + "if (_border != null) { _border.writePostfix(device); }");        }        out.println ("\n" + INDENT + "}");        if (cgProperties.size() > 0) {            out.println("\n//--- setters and getters for the properties.");            Iterator props = cgProperties.iterator();            while (props.hasNext()) {                Property p = (Property) props.next();                out.print(INDENT + "public " + p.getTypeName()                           + " get" + capitalize(p.getName()));                out.print("() { return " + p.getName() + "; }\n");                out.print(INDENT                           + "public void set" + capitalize(p.getName()));                out.print("(" + p.getTypeName() + " " + p.getName() + ") { ");                out.print("this." + p.getName() + " = " + p.getName() + "; }\n\n");            }        }        out.println ("}");        out.close();        outProps.add(""); // separator.    }