01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.gui.components;
20:
21: import javax.swing.JOptionPane;
22:
23: import com.jeta.forms.gui.common.FormException;
24: import com.jeta.forms.gui.components.ComponentSource;
25: import com.jeta.forms.gui.form.GridComponent;
26: import com.jeta.forms.gui.form.GridView;
27: import com.jeta.open.i18n.I18N;
28:
29: /**
30: * A factory for creating swing components
31: */
32: public class GenericComponentFactory extends SwingComponentFactory {
33:
34: private String m_supplied_class;
35:
36: /**
37: * ctor
38: */
39: public GenericComponentFactory(ComponentSource compSrc) {
40: super (compSrc, null);
41: }
42:
43: public GridComponent createComponent(String compName, GridView view)
44: throws FormException {
45: m_supplied_class = javax.swing.JOptionPane
46: .showInputDialog(
47: view,
48: I18N
49: .getLocalizedMessage("Enter Class Name (e.g. javax.swing.JTable):"));
50:
51: if (m_supplied_class != null) {
52: try {
53: m_supplied_class = com.jeta.swingbuilder.gui.utils.FormDesignerUtils
54: .fastTrim(m_supplied_class);
55: Class c = Class.forName(m_supplied_class);
56: return super .createComponent(compName, view);
57: } catch (Exception e) {
58: String msg = I18N
59: .getLocalizedMessage("Unable to instantiate component");
60: String title = I18N.getLocalizedMessage("Error");
61: JOptionPane.showMessageDialog(view, msg, title,
62: JOptionPane.ERROR_MESSAGE);
63: ComponentSource compsrc = getComponentSource();
64: compsrc.setSelectionTool();
65: return null;
66: }
67: } else {
68: ComponentSource compsrc = getComponentSource();
69: compsrc.setSelectionTool();
70: return null;
71: }
72: }
73:
74: public String getComponentClass() {
75: return m_supplied_class;
76: }
77: }
|