001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.components;
020:
021: import java.awt.Component;
022: import java.lang.reflect.Constructor;
023:
024: import com.jeta.forms.beanmgr.BeanManager;
025: import com.jeta.forms.gui.beans.JETABean;
026: import com.jeta.forms.gui.beans.JETABeanFactory;
027: import com.jeta.forms.gui.common.FormException;
028: import com.jeta.forms.gui.components.ComponentSource;
029: import com.jeta.forms.gui.components.StandardComponentFactory;
030: import com.jeta.forms.gui.form.FormContainerComponent;
031: import com.jeta.forms.gui.form.GridComponent;
032: import com.jeta.forms.gui.form.GridView;
033: import com.jeta.forms.gui.form.StandardComponent;
034: import com.jeta.open.registry.JETARegistry;
035:
036: /**
037: * A factory for creating swing components
038: */
039: public class SwingComponentFactory extends StandardComponentFactory {
040:
041: /**
042: * The class name of the component to create
043: */
044: private String m_comp_class;
045:
046: /**
047: * Parameter types for the constructor of the component class.
048: */
049: private Class[] m_params = new Class[0];
050:
051: /**
052: * Object values for the constructor of the component class
053: */
054: private Object[] m_args = new Object[0];
055:
056: /**
057: * ctor
058: */
059: public SwingComponentFactory(ComponentSource compSrc,
060: String compClass) {
061: super (compSrc);
062: m_comp_class = compClass;
063: }
064:
065: /**
066: * ctor
067: */
068: public SwingComponentFactory(ComponentSource compSrc,
069: String compClass, Class[] params, Object[] args) {
070: super (compSrc);
071: m_comp_class = compClass;
072: m_params = params;
073: m_args = args;
074: }
075:
076: public GridComponent createComponent(String compName, GridView view)
077: throws FormException {
078: try {
079: JETABean jetabean = JETABeanFactory.createBean(
080: getComponentClass(), compName, true, true);
081: if (jetabean == null) {
082: BeanManager bm = (BeanManager) JETARegistry
083: .lookup(BeanManager.COMPONENT_ID);
084: Class c = bm.getBeanClass(getComponentClass());
085: Constructor ctor = c.getConstructor(m_params);
086: Component comp = (Component) ctor.newInstance(m_args);
087: comp.setName(compName);
088: return super .createComponent(comp, view);
089: } else {
090: if (jetabean.getDelegate() instanceof javax.swing.JTabbedPane) {
091: FormContainerComponent gc = new FormContainerComponent(
092: jetabean, view);
093: installHandlers(gc);
094: return gc;
095: } else {
096: StandardComponent gc = new StandardComponent(
097: jetabean, view);
098: installHandlers(gc);
099: return gc;
100: }
101: }
102: } catch (Exception e) {
103: e.printStackTrace();
104: throw new FormException(e);
105: }
106: }
107:
108: public String getComponentClass() {
109: return m_comp_class;
110: }
111: }
|