001: package com.xoetrope.builder.w3c.xforms;
002:
003: import java.util.Hashtable;
004:
005: import java.awt.Component;
006:
007: import net.xoetrope.xui.XComponentConstructor;
008: import net.xoetrope.xui.XComponentFactory;
009: import net.xoetrope.xui.XImageHolder;
010: import net.xoetrope.xui.XTextHolder;
011: import java.awt.Color;
012: import java.awt.FlowLayout;
013: import net.xoetrope.swing.XPanel;
014: import java.awt.Dimension;
015: import net.xoetrope.swing.XComboBox;
016: import net.xoetrope.swing.XEdit;
017: import net.xoetrope.swing.XTextArea;
018: import net.xoetrope.swing.XPassword;
019: import net.xoetrope.swing.XTextPane;
020: import javax.swing.BorderFactory;
021: import com.xoetrope.swing.XSlider;
022: import net.xoetrope.registry.ComponentAdapter;
023:
024: /**
025: * A factory class used to add the components available as part of the XForms
026: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
027: * the GNU Public License (GPL), please see license.txt for more details. If
028: * you make commercial use of this software you must purchase a commercial
029: * license from Xoetrope.</p>
030: * <p> $Revision: 1.5 $</p>
031: */
032: public class XFormsComponentFactory implements XComponentConstructor {
033: private String packageName = "net.xoetrope.swing";
034:
035: public XFormsComponentFactory() {
036: }
037:
038: public void update() {
039: }
040:
041: public void setPackageName(String defPackage) {
042: packageName = defPackage;
043: }
044:
045: /**
046: * Constructs XForms components on behalf of the component factory. At present
047: * the following types are supported
048: * @param cf the calling component factory
049: * @param type
050: * @param content
051: * @return
052: */
053: public Component constructComponent(XComponentFactory cf, int type,
054: String content) {
055: return null;
056: }
057:
058: /**
059: * Constructs XForms components on behalf of the component factory. At present
060: * the following types are supported
061: * <UL>
062: * <LI>ProgressBar</LI>
063: * </UL>
064: * @param cf the calling component factory
065: * @param type the component type name
066: * @param content the contents if applicable
067: * @return the new component
068: */
069: public Component constructComponent(XComponentFactory cf,
070: String type, String content) {
071: Component comp = null;
072: try {
073: comp = null;
074: if (type.compareToIgnoreCase("label") == 0) {
075: comp = (Component) Class.forName(
076: packageName + ".XLabel").newInstance();
077: ((XTextHolder) comp).setText(content);
078: } else if (type.compareToIgnoreCase("combo") == 0)
079: comp = (Component) Class.forName(
080: packageName + ".XComboBox").newInstance();
081: else if (type.compareToIgnoreCase("select") == 0) {
082: comp = (Component) Class.forName(
083: packageName + ".XComboBox").newInstance();
084: } else if (type.compareToIgnoreCase("panel") == 0) {
085: comp = (Component) Class.forName(
086: packageName + ".XPanel").newInstance();
087: ((XPanel) comp).setLayout(new FlowLayout());
088: } else if (type.compareToIgnoreCase("edit") == 0) {
089: comp = (Component) Class
090: .forName(packageName + ".XEdit").newInstance();
091: ((XTextHolder) comp).setText(content);
092: ((XEdit) comp).setPreferredSize(new Dimension(100, 25));
093: } else if (type.compareToIgnoreCase("button") == 0) {
094: comp = (Component) Class.forName(
095: packageName + ".XButton").newInstance();
096: ((XTextHolder) comp).setText(content);
097: } else if (type.compareToIgnoreCase("textarea") == 0) {
098: comp = (Component) Class.forName(
099: packageName + ".XTextPane").newInstance();
100: ((XTextHolder) comp).setText(content);
101: ((XTextPane) comp).setPreferredSize(new Dimension(100,
102: 50));
103: ((XTextPane) comp).setBorder(BorderFactory
104: .createEtchedBorder());
105: } else if (type.compareToIgnoreCase("radio") == 0) {
106: comp = (Component) Class.forName(
107: packageName + ".XRadioButton").newInstance();
108: ((XTextHolder) comp).setText(content);
109: } else if (type.compareToIgnoreCase("password") == 0) {
110: comp = (Component) Class.forName(
111: packageName + ".XPassword").newInstance();
112: ((XTextHolder) comp).setText(content);
113: ((XPassword) comp).setPreferredSize(new Dimension(50,
114: 35));
115: } else if (type.compareToIgnoreCase("slider") == 0) {
116: comp = new XSlider();
117: ((XSlider) comp)
118: .setPreferredSize(new Dimension(350, 45));
119: ((XSlider) comp).setSize(new Dimension(350, 45));
120: }
121: } catch (Exception ex) {
122: ex.printStackTrace();
123: }
124: return comp;
125: }
126:
127: /**
128: * A factory method for adding non component elements. This includes question
129: * response elements
130: * @param cf the calling component factory
131: * @param type the object type
132: * @param name a name identifying the element to be created
133: * @param content the component text/content
134: * @param attribs the element attributes if any
135: */
136: public Object addElement(XComponentFactory cf, String type,
137: String name, String content, Hashtable attribs) {
138: return null;
139: }
140:
141: /**
142: * Get the component adapter for this type
143: * @param the name identifying the type
144: */
145: public ComponentAdapter getComponentAdapter(String type) {
146: return null;
147: }
148: }
|