001: package com.xoetrope.builder.w3c.html;
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.XTextHolder;
010: import java.awt.FlowLayout;
011: import net.xoetrope.swing.XPanel;
012: import java.awt.Dimension;
013: import net.xoetrope.swing.XEdit;
014: import net.xoetrope.swing.XPassword;
015: import javax.swing.BorderFactory;
016: import com.xoetrope.swing.XSlider;
017: import net.xoetrope.registry.ComponentAdapter;
018: import net.xoetrope.swing.XTextArea;
019:
020: /**
021: * A factory class used to add the components available as part of the html form/page
022: * <p>Copyright: Copyright Xoetrope Ltd. (c) 2001-2006</p>
023: * <p>License: see license.txt</p>
024: * <p>$Revision: 1.3 $</p>
025: */
026: public class XHtmlComponentFactory implements XComponentConstructor {
027: private String packageName = "net.xoetrope.swing";
028:
029: public XHtmlComponentFactory() {
030: }
031:
032: public void update() {
033: }
034:
035: public void setPackageName(String defPackage) {
036: packageName = defPackage;
037: }
038:
039: /**
040: * Constructs HTML components on behalf of the component factory. At present
041: * the following types are supported
042: * <UL>
043: * <LI>ProgressBar</LI>
044: * </UL>
045: * @param cf the calling component factory
046: * @param type the component type name
047: * @param content the contents if applicable
048: * @return the new component
049: */
050: public Component constructComponent(XComponentFactory cf,
051: String type, String content) {
052: Component comp = null;
053: try {
054: comp = null;
055: if (type.equals("label")) {
056: comp = (Component) Class.forName(
057: packageName + ".XLabel").newInstance();
058: ((XTextHolder) comp).setText(content);
059: } else if (type.equals("combo"))
060: comp = (Component) Class.forName(
061: packageName + ".XComboBox").newInstance();
062: else if (type.equals("select"))
063: comp = (Component) Class.forName(
064: packageName + ".XComboBox").newInstance();
065: else if (type.equals("panel")) {
066: comp = (Component) Class.forName(
067: packageName + ".XPanel").newInstance();
068: ((XPanel) comp).setLayout(new FlowLayout());
069: } else if (type.equals("edit")) {
070: comp = (Component) Class
071: .forName(packageName + ".XEdit").newInstance();
072: ((XTextHolder) comp).setText(content);
073: ((XEdit) comp).setPreferredSize(new Dimension(50, 20));
074: } else if (type.equals("button") || type.equals("submit")
075: || type.equals("reset")) {
076: comp = (Component) Class.forName(
077: packageName + ".XButton").newInstance();
078: ((XTextHolder) comp).setText(content);
079: } else if (type.equals("imagebutton")) {
080: comp = (Component) Class.forName(
081: packageName + ".XImageButton").newInstance();
082: } else if (type.equals("textarea") || type.equals("text")) {
083: comp = (Component) Class.forName(
084: packageName + ".XTextArea").newInstance();
085: ((XTextHolder) comp).setText(content);
086: ((XTextArea) comp).setPreferredSize(new Dimension(50,
087: 20));
088: ((XTextArea) comp).setBorder(BorderFactory
089: .createEtchedBorder());
090: } else if (type.equals("radio")) {
091: comp = (Component) Class.forName(
092: packageName + ".XRadioButton").newInstance();
093: ((XTextHolder) comp).setText(content);
094: } else if (type.equals("checkbox")) {
095: comp = (Component) Class.forName(
096: packageName + ".XCheckbox").newInstance();
097: ((XTextHolder) comp).setText(content);
098: } else if (type.equals("password")) {
099: comp = (Component) Class.forName(
100: packageName + ".XPassword").newInstance();
101: ((XTextHolder) comp).setText(content);
102: ((XPassword) comp).setPreferredSize(new Dimension(50,
103: 20));
104: ((XPassword) comp).setColumns(12);
105: ((XEdit) comp).setBackground(java.awt.Color.green);
106: } else if (type.equals("slider")) {
107: comp = new XSlider();
108: ((XSlider) comp)
109: .setPreferredSize(new Dimension(350, 45));
110: ((XSlider) comp).setSize(new Dimension(350, 45));
111: } else if (type.equals("file")) {
112: // Create a link to a file control.
113: } else if (type.equals("hidden")) {
114: // Create a hidden input element or a model node
115: }
116: } catch (Exception ex) {
117: ex.printStackTrace();
118: }
119: return comp;
120: }
121:
122: /**
123: * A factory method for adding non component elements. This includes question
124: * response elements
125: * @param cf the calling component factory
126: * @param type the object type
127: * @param name a name identifying the element to be created
128: * @param content the component text/content
129: * @param attribs the element attributes if any
130: */
131: public Object addElement(XComponentFactory cf, String type,
132: String name, String content, Hashtable attribs) {
133: return null;
134: }
135:
136: /**
137: * Get the component adapter for this type
138: * @param the name identifying the type
139: */
140: public ComponentAdapter getComponentAdapter(String type) {
141: return null;
142: }
143: }
|