001: package com.xoetrope.swing;
002:
003: import com.xoetrope.swing.survey.XKioskQuestion;
004: import com.xoetrope.swing.survey.XQuestion;
005: import com.xoetrope.swing.survey.XWrapQuestion;
006: import java.util.Hashtable;
007:
008: import java.awt.Component;
009:
010: import net.xoetrope.xui.XComponentConstructor;
011: import net.xoetrope.xui.XComponentFactory;
012: import net.xoetrope.xui.XImageHolder;
013: import net.xoetrope.xui.XProjectManager;
014: import net.xoetrope.xui.XTextHolder;
015: import net.xoetrope.registry.ComponentAdapter;
016: import net.xoetrope.xui.XProject;
017:
018: /**
019: * @todo get rid of this class, all components should be added through the registry
020: * A component factory for XForms swing components
021: *
022: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
023: * the GNU Public License (GPL), please see license.txt for more details. If
024: * you make commercial use of this software you must purchase a commercial
025: * license from Xoetrope.</p>
026: * <p> $Revision: 1.9 $</p>
027: */
028: public class XuiProComponentFactory implements XComponentConstructor {
029: private String packageName = "com.xoetrope.swing";
030: private XQuestion lastQuestion;
031: private int nextValue = 0;
032: private String defaultQuestionFormat;
033:
034: /**
035: * The owner project and the context in which this object operates.
036: */
037: protected XProject currentProject;
038:
039: public XuiProComponentFactory(XProject project) {
040: currentProject = project;
041: update();
042: }
043:
044: public void update() {
045: try {
046: defaultQuestionFormat = currentProject
047: .getStartupParam("DefaultQuestionFormat");
048: } catch (Exception ex) {
049: }
050: if (defaultQuestionFormat == null)
051: defaultQuestionFormat = "Question";
052: }
053:
054: public void setPackageName(String defPackage) {
055: packageName = defPackage;
056: }
057:
058: public Component constructComponent(XComponentFactory cf, int type,
059: String content) {
060: return null;
061: }
062:
063: public Object constructComponent(XComponentFactory cf, String type,
064: String content) {
065: Component comp = null;
066: if (type.compareToIgnoreCase("Question") == 0) {
067: if (defaultQuestionFormat.compareTo("WrapQuestion") == 0)
068: comp = lastQuestion = new XWrapQuestion();
069: else if (defaultQuestionFormat.compareTo("KioskQuestion") == 0)
070: comp = lastQuestion = new XKioskQuestion();
071: if (comp == null)
072: comp = lastQuestion = new XQuestion();
073: ((XTextHolder) comp).setText(content);
074: nextValue = 0;
075: }
076: // else if ( type.compareToIgnoreCase( "EasterEgg" ) == 0 ) {
077: // comp = new XEasterEgg();
078: // ((XImageHolder)comp).setImage( currentProject.getImage( content ));
079: // }
080: // else if ( type.compareToIgnoreCase( "ProgressBar" ) == 0 )
081: // comp = new XProgressBar();
082: // else if ( type.compareToIgnoreCase( "Date" ) == 0 )
083: // comp = new XDateEdit();
084: // else if ( type.compareToIgnoreCase( "DateChooser" ) == 0 )
085: // comp = new XDateChooser();
086: // else if ( type.compareToIgnoreCase( "Keypad" ) == 0 )
087: // comp = new XKeypad();
088: // else if ( type.compareToIgnoreCase( "Money" ) == 0 )
089: // comp = new XMoneyEdit();
090: // else if ( type.compareToIgnoreCase( "Shape" ) == 0 )
091: // comp = new XShape();
092: // else if ( type.compareToIgnoreCase( "AWTSpinner" ) == 0 )
093: // comp = new XSpinner();
094: // else if ( type.compareToIgnoreCase( "AnimatedText" ) == 0 )
095: // comp = new XAnimatedText();
096: // else if ( type.compareToIgnoreCase( "Audio" ) == 0 )
097: // comp = new XAudio();
098: // else if ( type.compareToIgnoreCase( "Credits" ) == 0 )
099: // comp = new XCreditsText();
100: // else if ( type.compareToIgnoreCase( "FlowedText" ) == 0 )
101: // comp = new XFlowedTextComponent();
102: // else if ( type.compareToIgnoreCase( "Graph" ) == 0 )
103: // comp = new XGraph();
104: // else if ( type.compareToIgnoreCase( "Html" ) == 0 )
105: // comp = new XHtmlText();
106: // else if ( type.compareToIgnoreCase( "Marquee" ) == 0 )
107: // comp = new XMarqueeText();
108: // else if ( type.compareToIgnoreCase( "PolygonalTextArea" ) == 0 )
109: // comp = new XPolygonalTextArea();
110: // else if ( type.compareToIgnoreCase( "RotatedText" ) == 0 )
111: // comp = new XRotatedText();
112: // else if ( type.compareToIgnoreCase( "Slider" ) == 0 )
113: // comp = new XSlider();
114: // else if ( type.compareToIgnoreCase( "Spinner" ) == 0 )
115: // comp = new XSpinner();
116: // else if ( type.compareToIgnoreCase( "TreeView" ) == 0 )
117: // comp = new XTreeView();
118: // else if ( type.compareToIgnoreCase( "Video" ) == 0 )
119: // comp = new XVideo();
120:
121: return comp;
122: }
123:
124: public Object addElement(XComponentFactory cf, String type,
125: String name, String content, Hashtable attribs) {
126: if (type.compareToIgnoreCase("Response") == 0)
127: lastQuestion.addResponse(new Integer((String) attribs
128: .get("id")).intValue(), content);
129: else if (type.compareToIgnoreCase("QuestionManager") == 0) {
130: int slots = new Integer((String) attribs.get("slots"))
131: .intValue();
132: int width = new Integer((String) attribs.get("w"))
133: .intValue();
134: int height = new Integer((String) attribs.get("h"))
135: .intValue();
136: for (int i = 0; i < slots; i++) {
137: Component comp = lastQuestion = (XQuestion) cf
138: .addComponent("Question", 0, 0, width, height,
139: "");
140: comp.setName(name);
141: ((XTextHolder) comp).setText(content);
142: lastQuestion.setAttribute("ref", "next");
143: }
144: nextValue = 0;
145: }
146:
147: return lastQuestion;
148: }
149:
150: /**
151: * Get the component adapter for this type
152: * @param type the name identifying the type
153: */
154: public ComponentAdapter getComponentAdapter(String type) {
155: return null;
156: }
157: }
|