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