JTextComponentHandler.java :  » XML-UI » JAXX » jaxx » tags » swing » Java Open Source

Java Open Source » XML UI » JAXX 
JAXX » jaxx » tags » swing » JTextComponentHandler.java
/*
 * Copyright 2006 Ethan Nicholas. All rights reserved.
 * Use is subject to license terms.
 */
package jaxx.tags.swing;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import org.w3c.dom.*;
import org.w3c.dom.Element;

import jaxx.*;
import jaxx.compiler.*;
import jaxx.reflect.*;
import jaxx.tags.*;

public class JTextComponentHandler extends DefaultComponentHandler {
    private static final int DEFAULT_COLUMNS = 15;
    
    public JTextComponentHandler(ClassDescriptor beanClass) {
        super(beanClass);
        if (!ClassDescriptorLoader.getClassDescriptor(JTextComponent.class).isAssignableFrom(beanClass))
            throw new IllegalArgumentException(getClass().getName() + "does not support the class " + beanClass.getName());
    }
    
    
    protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) throws CompilerException {
        super.setDefaults(object, tag, compiler);
        try {
            object.getObjectClass().getMethodDescriptor("setColumns", new ClassDescriptor[] { ClassDescriptorLoader.getClassDescriptor(int.class) });
            setAttribute(object, "columns", String.valueOf(DEFAULT_COLUMNS), false, compiler);
        }
        catch (NoSuchMethodException e) { }

        if (ClassDescriptorLoader.getClassDescriptor(JTextArea.class).isAssignableFrom(object.getObjectClass())) {
            setAttribute(object, "lineWrap",      "true", false, compiler);
            setAttribute(object, "wrapStyleWord", "true", false, compiler);
        }
    }


    public String getSetPropertyCode(String id, String name, String valueCode, JAXXCompiler compiler) throws CompilerException {
        if (name.equals("text"))
            return "jaxx.runtime.swing.Utils.setText(" + id + ", " + valueCode + ");\n";
        else
            return super.getSetPropertyCode(id, name, valueCode, compiler);
    }


    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("text"))
            return 1;
        else
            return super.getAttributeOrdering(attr);
    }

    
    protected void configureProxyEventInfo() {
        super.configureProxyEventInfo();
        addProxyEventInfo("getText", DocumentListener.class, "document");
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.