0001: package com.xoetrope.carousel.survey;
0002:
0003: import java.awt.Color;
0004: import java.awt.event.KeyEvent;
0005: import java.awt.event.KeyListener;
0006: import java.io.BufferedWriter;
0007: import java.io.File;
0008: import java.io.FileInputStream;
0009: import java.io.FileOutputStream;
0010: import java.io.FileWriter;
0011: import java.io.IOException;
0012: import java.io.InputStream;
0013: import java.io.OutputStream;
0014: import java.net.URL;
0015: import java.sql.Connection;
0016: import java.sql.DriverManager;
0017: import java.sql.SQLException;
0018: import java.sql.Statement;
0019: import java.util.Iterator;
0020: import java.util.Locale;
0021: import java.util.Properties;
0022: import java.util.Vector;
0023: import java.util.Hashtable;
0024:
0025: import java.awt.BorderLayout;
0026: import java.awt.Component;
0027: import java.awt.Cursor;
0028: import java.awt.FlowLayout;
0029: import java.awt.Font;
0030: import java.awt.Image;
0031: import java.awt.Rectangle;
0032: import java.awt.event.ActionEvent;
0033: import java.awt.event.ActionListener;
0034: import java.awt.event.ItemEvent;
0035: import java.awt.event.ItemListener;
0036:
0037: import javax.swing.BorderFactory;
0038: import javax.swing.DefaultComboBoxModel;
0039: import javax.swing.ImageIcon;
0040: import javax.swing.JButton;
0041: import javax.swing.JComponent;
0042: import javax.swing.JDialog;
0043: import javax.swing.JFileChooser;
0044: import javax.swing.JOptionPane;
0045: import javax.swing.JPanel;
0046: import javax.swing.JTabbedPane;
0047: import javax.swing.SwingConstants;
0048: import javax.swing.event.ChangeEvent;
0049: import javax.swing.event.ChangeListener;
0050:
0051: import net.n3.nanoxml.IXMLElement;
0052: import net.n3.nanoxml.XMLElement;
0053: import net.n3.nanoxml.XMLWriter;
0054: import net.xoetrope.editor.project.XEditorProject;
0055: import net.xoetrope.editor.project.style.XEditorStyleFactory;
0056: import net.xoetrope.editor.project.style.XEditorStyleManager;
0057: import net.xoetrope.editor.XEditorUtilities;
0058: import net.xoetrope.editor.project.pages.XPageResource;
0059: import net.xoetrope.editor.project.helper.AFileFilter;
0060: import net.xoetrope.debug.DebugLogger;
0061: import net.xoetrope.swing.XButton;
0062: import net.xoetrope.swing.XCheckbox;
0063: import net.xoetrope.swing.XComboBox;
0064: import net.xoetrope.swing.XEdit;
0065: import net.xoetrope.swing.XLabel;
0066: import net.xoetrope.swing.XImage;
0067: import net.xoetrope.swing.XPassword;
0068: import net.xoetrope.swing.XRadioButton;
0069: import com.xoetrope.swing.XProgressBar;
0070: import com.xoetrope.swing.survey.XQuestion;
0071: import com.xoetrope.carousel.wizard.XColourPanel;
0072: import com.xoetrope.carousel.wizard.XFontPanel;
0073: import com.xoetrope.carousel.wizard.XWizardPanel;
0074: import com.xoetrope.survey.Question;
0075: import com.xoetrope.survey.Survey;
0076: import com.xoetrope.survey.SurveyManager;
0077: import net.xoetrope.editor.project.helper.BuddyHelper;
0078: import net.xoetrope.xml.XmlElement;
0079: import net.xoetrope.xml.nanoxml.NanoXmlElement;
0080: import net.xoetrope.xml.nanoxml.NanoXmlWriter;
0081: import net.xoetrope.xui.XComponentFactory;
0082: import net.xoetrope.xui.XPage;
0083: import net.xoetrope.xui.XRadioButtonGroup;
0084: import net.xoetrope.xui.style.XStyle;
0085: import net.xoetrope.xui.style.XStyleFactory;
0086: import net.xoetrope.xui.helper.SwingWorker;
0087: import net.xoetrope.xui.helper.XLayoutHelper;
0088:
0089: //import org.netbeans.api.debugger.jpda.This;
0090:
0091: /**
0092: * A wizard dialog for building surveys based on XForms
0093: *
0094: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
0095: * the GNU Public License (GPL), please see license.txt for more details. If
0096: * you make commercial use of this software you must purchase a commercial
0097: * license from Xoetrope.</p>
0098: * <p> $Revision: 1.14 $</p>
0099: */
0100: public class XSurveyWizard extends JDialog implements ChangeListener,
0101: ActionListener {
0102: private XEditorProject currentProject;
0103:
0104: private Properties properties;
0105:
0106: private int clientWidth, clientHeight;
0107: private String questionPage;
0108: private String defaultQuestionFormat;
0109: private String exclusiveTemplate, multipleTemplate, freeTemplate;
0110: private String startClass;
0111: private String banner;
0112: private String navigationPanel;
0113: private String thankyouPage;
0114: private int questionsPerPage;
0115: private String responsesFile;
0116:
0117: private JTabbedPane tabPane;
0118: private JPanel controlPanel, layoutPanel, navPanel, dataPanel,
0119: outputPanel;
0120: private XColourPanel colourPanel;
0121: private XFontPanel fontPanel;
0122: private JButton prevBtn, nextBtn;
0123:
0124: // Layout tab
0125: private XComboBox questionStyleCombo, pageSizeCombo;
0126: private XEdit questionsPerPageEdit;
0127:
0128: // Navigation tab
0129: private XCheckbox welcomeChk, farewellChk, restartChk, forwardChk,
0130: backChk, homeChk, internationalizeChk, navigationChk,
0131: bannerChk, logoChk;
0132: private XEdit nextEdit, prevEdit, homeEdit;
0133: private XButton forwardBtn, backBtn, homeBtn;
0134:
0135: private XEdit welcomeEdit, logoEdit, titleEdit, thanksEdit;
0136: private XCheckbox[] langChks = new XCheckbox[6];
0137:
0138: // Data tab
0139: private XButton logoBtn;
0140: private XLabel logoFileCaption, titleCaption, messageCaption;
0141:
0142: // Input items
0143: private XRadioButton dbInputRb, fileInputRb;
0144: private XEdit dbInputUser;
0145: private XComboBox dbInputUrl, dbInputDriver;
0146: private XEdit surveyNameEdit;
0147: private XPassword dbInputPassword;
0148:
0149: // Output items
0150: private XRadioButton dbOutputRb, fileOutputRb;
0151: private XEdit dbOutputUser;
0152: protected XComboBox dbOutputDriver, dbOutputUrl;
0153: private XPassword dbOutputPassword;
0154: private XEdit fileOutputName;
0155: private XButton fileOutputBtn;
0156:
0157: private Vector colours, fonts;
0158: private SurveyManager surveyManager;
0159: private XEditorStyleFactory factory;
0160:
0161: protected String languageNames[] = { "English", "Fran\u00e7ais",
0162: "Espaņol", "Deutsch", "Italiano", "Dansk" };
0163:
0164: protected String languageCodes[] = { "en", "fr", "es", "de", "it",
0165: "da" };
0166:
0167: protected String[] dbUrls = { "jdbc:odbc:odbcDataSource",
0168: "jdbc:hsqldb:<<DataBase URL>>",
0169: "jdbc:derby:<<DataBase URL>>",
0170: "jdbc:<protocol>:<subprotocol>://<url>:<port>/" };
0171:
0172: protected String[] dbDrivers = { "sun.jdbc.odbc.JdbcOdbcDriver",
0173: "org.hsqldb.jdbcDriver",
0174: "org.apache.derby.jdbc.ClientDriver", "<Other>" };
0175:
0176: protected String defaultDbUser = "sa";
0177:
0178: protected XLayoutHelper layoutHelper;
0179: private JFileChooser fileChooser;
0180:
0181: public XSurveyWizard(XEditorProject project) {
0182: currentProject = project;
0183: layoutHelper = (XLayoutHelper) project
0184: .getObject("LayoutHelper");
0185: setModal(true);
0186: setSize(610, 500);
0187: setTitle("Survey Wizard");
0188:
0189: getContentPane().setLayout(new BorderLayout());
0190: tabPane = new JTabbedPane();
0191: getContentPane().add(tabPane, BorderLayout.CENTER);
0192:
0193: colours = new Vector();
0194: fonts = new Vector();
0195:
0196: controlPanel = new JPanel();
0197: FlowLayout layout = new FlowLayout();
0198: layout.setAlignment(FlowLayout.RIGHT);
0199: controlPanel.setLayout(layout);
0200: prevBtn = new JButton("Previous");
0201: prevBtn.setEnabled(false);
0202: prevBtn.addActionListener(this );
0203: prevBtn.setIcon(new ImageIcon(currentProject
0204: .getImage("com/xoetrope/carousel/resources/back.gif")));
0205: nextBtn = new JButton("Next");
0206: nextBtn
0207: .setIcon(new ImageIcon(
0208: currentProject
0209: .getImage("com/xoetrope/carousel/resources/forward.gif")));
0210: nextBtn.setHorizontalAlignment(SwingConstants.RIGHT);
0211: nextBtn.addActionListener(this );
0212: controlPanel.add(prevBtn);
0213: controlPanel.add(nextBtn);
0214: getContentPane().add(controlPanel, BorderLayout.SOUTH);
0215:
0216: layoutPanel = setupLayoutPanel();
0217: navPanel = setupNavigationPanel();
0218: colourPanel = setupColourPanel();
0219: fontPanel = setupFontPanel();
0220: dataPanel = setupDataPanel();
0221: outputPanel = setupOutputPanel();
0222: tabPane.add(layoutPanel, "Layout");
0223: tabPane.add(colourPanel, "Colours");
0224: tabPane.add(fontPanel, "Fonts");
0225: tabPane.add(navPanel, "Navigation");
0226: tabPane.add(dataPanel, "Data");
0227: tabPane.add(outputPanel, "Output");
0228:
0229: tabPane.setSelectedIndex(0);
0230: tabPane.addChangeListener(this );
0231:
0232: Component c = currentProject.getAppFrame();
0233: if (c != null) {
0234: Rectangle rect = c.getBounds();
0235: setLocation(rect.x + (c.getSize().width - getSize().width)
0236: / 2, rect.y
0237: + (c.getSize().height - getSize().height) / 2);
0238: }
0239:
0240: factory = new XEditorStyleFactory(currentProject, null,
0241: currentProject.getWidgetPackageName());
0242: fileChooser = new JFileChooser(currentProject.getPath());
0243: }
0244:
0245: private boolean checkLanguageSelection() {
0246: boolean state = !internationalizeChk.isEnabled()
0247: || !internationalizeChk.isSelected();
0248: if (!state)
0249: for (int i = 0; !state && (i < 6); i++)
0250: state |= langChks[i].isSelected();
0251: return state;
0252: }
0253:
0254: private boolean checkOutputFile() {
0255: return (!fileOutputRb.isSelected() || fileOutputName.getText()
0256: .length() > 0);
0257: }
0258:
0259: public void stateChanged(ChangeEvent e) {
0260: JPanel selectedPanel = (JPanel) tabPane.getSelectedComponent();
0261:
0262: if (selectedPanel == layoutPanel)
0263: prevBtn.setEnabled(false);
0264: else
0265: prevBtn.setEnabled(true);
0266:
0267: if (selectedPanel == outputPanel)
0268: nextBtn.setText("Finish");
0269: else
0270: nextBtn.setText("Next");
0271: }
0272:
0273: public void actionPerformed(ActionEvent e) {
0274: Object source = e.getSource();
0275: int selIdx = tabPane.getSelectedIndex();
0276: if (source == nextBtn) {
0277: if ((selIdx == 3) && !checkLanguageSelection())
0278: JOptionPane.showMessageDialog(this ,
0279: "Please choose at least one language.");
0280: else if (selIdx < 5)
0281: tabPane.setSelectedIndex(++selIdx);
0282: else if (!checkOutputFile())
0283: JOptionPane.showMessageDialog(this ,
0284: "Please choose the output file.");
0285: else
0286: buildSurvey();
0287: } else if (source == prevBtn) {
0288: tabPane.setSelectedIndex(--selIdx);
0289: }
0290: }
0291:
0292: private void pickOutputFile() {
0293: try {
0294: fileChooser.setFileFilter(new AFileFilter("xml",
0295: "survey output file"));
0296: int n = fileChooser.showOpenDialog(this );
0297: if (n == 0) {
0298: fileOutputName.setText(fileChooser.getSelectedFile()
0299: .getCanonicalPath());
0300: }
0301: } catch (Exception ex) {
0302: ex.printStackTrace();
0303: }
0304: }
0305:
0306: private void pickLogoFile() {
0307: try {
0308: AFileFilter filter = new AFileFilter("gif", "Image files");
0309: fileChooser.setFileFilter(filter);
0310: filter.addExtension("png");
0311: filter.addExtension("jpg");
0312: int i = fileChooser.showOpenDialog(this );
0313: if (i == 0)
0314: logoEdit.setText(fileChooser.getSelectedFile()
0315: .getCanonicalPath());
0316: } catch (Exception ex) {
0317: ex.printStackTrace();
0318: }
0319: }
0320:
0321: private void pickHomeIcon() {
0322: try {
0323: AFileFilter filter = new AFileFilter("gif", "Image files");
0324: fileChooser.setFileFilter(filter);
0325: filter.addExtension("png");
0326: filter.addExtension("jpg");
0327: int i = fileChooser.showOpenDialog(this );
0328: if (i == 0)
0329: homeEdit.setText(fileChooser.getSelectedFile()
0330: .getCanonicalPath());
0331: } catch (Exception ex) {
0332: ex.printStackTrace();
0333: }
0334: }
0335:
0336: private void pickForwardIcon() {
0337: try {
0338: AFileFilter filter = new AFileFilter("gif", "Image files");
0339: fileChooser.setFileFilter(filter);
0340: filter.addExtension("png");
0341: filter.addExtension("jpg");
0342: int i = fileChooser.showOpenDialog(this );
0343: if (i == 0)
0344: nextEdit.setText(fileChooser.getSelectedFile()
0345: .getCanonicalPath());
0346: } catch (Exception ex) {
0347: ex.printStackTrace();
0348: }
0349: }
0350:
0351: private void pickBackIcon() {
0352: try {
0353: AFileFilter filter = new AFileFilter("gif", "Image files");
0354: fileChooser.setFileFilter(filter);
0355: filter.addExtension("png");
0356: filter.addExtension("jpg");
0357: int i = fileChooser.showOpenDialog(this );
0358: if (i == 0)
0359: prevEdit.setText(fileChooser.getSelectedFile()
0360: .getCanonicalPath());
0361: } catch (Exception ex) {
0362: ex.printStackTrace();
0363: }
0364: }
0365:
0366: // tab 1
0367: private void buildLayout() throws Exception {
0368: // setup the page size
0369: String pageSize = (String) pageSizeCombo.getSelectedItem();
0370: clientWidth = Integer.parseInt(pageSize.substring(0, pageSize
0371: .indexOf(' ')));
0372: clientHeight = Integer.parseInt(pageSize.substring(pageSize
0373: .lastIndexOf(' ') + 1));
0374:
0375: // the max number of questions that can be shown on one page
0376: questionsPerPage = new Integer(questionsPerPageEdit.getText())
0377: .intValue();
0378:
0379: // set the question style
0380: defaultQuestionFormat = null;
0381: String styleText = (String) questionStyleCombo
0382: .getSelectedObject();
0383: if ("Normal".equals(styleText))
0384: defaultQuestionFormat = "Question";
0385: else if ("Wrap around".equals(styleText))
0386: defaultQuestionFormat = "WrapQuestion";
0387: else if ("Kiosk".equals(styleText))
0388: defaultQuestionFormat = "KioskQuestion";
0389: else if ("Template".equals(styleText)) {
0390: defaultQuestionFormat = "TemplateQuestion";
0391:
0392: questionPage = "questionPage";
0393: buildDefaultQuestionPageTemplate("questionPage.xml");
0394:
0395: exclusiveTemplate = "exclusiveTemplate";
0396: buildDefaultExclusiveTemplate("exclusiveTemplate.xml");
0397:
0398: multipleTemplate = "multipleTemplate";
0399: buildDefaultMultipleTemplate("multipleTemplate.xml");
0400:
0401: freeTemplate = "freeTemplate";
0402: buildDefaultFreeTemplate("freeTemplate.xml");
0403:
0404: buildDefaultCheckbox("checkbox.xml");
0405: buildDefaultRadiobutton("radiobutton.xml");
0406: buildDefaultEdit("edit.xml");
0407: }
0408:
0409: if (!"Template".equals(styleText)) {
0410: questionPage = "questionPage";
0411: buildDefaultQuestionPage("questionPage.xml");
0412: }
0413:
0414: if (farewellChk.isSelected()) {
0415: thankyouPage = "thankYouPage";
0416: buildThankyouPage("thankYouPage.xml");
0417: } else {
0418: thankyouPage = null;
0419: }
0420:
0421: if (welcomeChk.isSelected()) {
0422: buildWelcomePage("Welcome.xml");
0423: startClass = "Welcome";
0424: } else {
0425: startClass = questionPage;
0426: }
0427:
0428: banner = "Banner";
0429: if (bannerChk.isSelected()) {
0430: buildBanner("Banner.xml");
0431: } else {
0432: buildEmptyPage("Banner.xml");
0433: }
0434:
0435: navigationPanel = "NavigationPanel";
0436: if (navigationChk.isSelected()) {
0437: buildNavigationPanel("NavigationPanel.xml");
0438: } else {
0439: buildEmptyPage("NavigationPanel.xml");
0440: }
0441:
0442: }
0443:
0444: protected void buildDefaultExclusiveTemplate(String pageName) {
0445: String mainPanelLayout = "Border";
0446: String mainPanelHeight = "120";
0447: String mainPanelConstraint = "center";
0448: String mainPanelOpaque = "false";
0449: String mainPanelBorder = "0";
0450: String questionPanelConstraint = "north";
0451: String questionPanelHeight = "60";
0452: String questionPanelOpaque = "true";
0453: String questionPanelStyle = "base/Question/Shade";
0454: String imageContent = "qmark.gif";
0455: String imageConstraint = "west";
0456: String imageOpaque = "false";
0457: String questionLabelX = "20";
0458: String questionLabelWidth = "400";
0459: String questionLabelHeight = "20";
0460: String questionLabelConstraint = "CENTER";
0461: String questionLabelAntialias = "true";
0462: String questionLabelOpaque = "false";
0463: String questionLabelStyle = "base/Question/Cue";
0464: String responsesPanelLayout = "Flow";
0465: String responsesPanelLayoutStyle = "0";
0466: String responsesPanelConstraint = "CENTER";
0467: String responsesPanelAntialias = "true";
0468: String responsesPanelOpaque = "false";
0469: String responsesPanelStyle = "base/Question";
0470: String responsesPanelHeight = "100";
0471:
0472: XmlElement pageXml = new NanoXmlElement("XPage");
0473: XmlElement componentsXml = new NanoXmlElement("Components");
0474: pageXml.addChild(componentsXml);
0475:
0476: XmlElement mainPanelXml = new NanoXmlElement("Panel");
0477: componentsXml.addChild(mainPanelXml);
0478: mainPanelXml.setAttribute("layout", mainPanelLayout);
0479: mainPanelXml.setAttribute("w", String.valueOf(clientWidth));
0480: mainPanelXml.setAttribute("h", mainPanelHeight);
0481: mainPanelXml.setAttribute("constraint", mainPanelConstraint);
0482: mainPanelXml.setAttribute("opaque", mainPanelOpaque);
0483: mainPanelXml.setAttribute("border", mainPanelBorder);
0484:
0485: XmlElement questionPanelXml = new NanoXmlElement("Panel");
0486: mainPanelXml.addChild(questionPanelXml);
0487: questionPanelXml.setAttribute("constraint",
0488: questionPanelConstraint);
0489: questionPanelXml.setAttribute("w", String.valueOf(clientWidth));
0490: questionPanelXml.setAttribute("h", questionPanelHeight);
0491: questionPanelXml.setAttribute("opaque", questionPanelOpaque);
0492: questionPanelXml.setAttribute("style", questionPanelStyle);
0493:
0494: XmlElement imageXml = new NanoXmlElement("image");
0495: questionPanelXml.addChild(imageXml);
0496: imageXml.setAttribute("name", "icon");
0497: imageXml.setAttribute("w", "14");
0498: imageXml.setAttribute("h", "14");
0499: imageXml.setAttribute("x", "2");
0500: imageXml.setAttribute("y", "2");
0501: imageXml.setAttribute("content", imageContent);
0502: imageXml.setAttribute("constraint", imageConstraint);
0503: imageXml.setAttribute("opaque", imageOpaque);
0504:
0505: XmlElement questionLabelXml = new NanoXmlElement("Label");
0506: questionPanelXml.addChild(questionLabelXml);
0507: questionLabelXml.setAttribute("name", "qtext");
0508: questionLabelXml.setAttribute("x", questionLabelX);
0509: questionLabelXml.setAttribute("w", questionLabelWidth);
0510: questionLabelXml.setAttribute("h", questionLabelHeight);
0511: questionLabelXml.setAttribute("content",
0512: "${getCurrentQuestion()}");
0513: questionLabelXml.setAttribute("constraint",
0514: questionLabelConstraint);
0515: questionLabelXml.setAttribute("antialias",
0516: questionLabelAntialias);
0517: questionLabelXml.setAttribute("style", questionLabelStyle);
0518:
0519: XmlElement responsesPanelXml = new NanoXmlElement("Panel");
0520: mainPanelXml.addChild(responsesPanelXml);
0521: responsesPanelXml.setAttribute("layout", responsesPanelLayout);
0522: responsesPanelXml.setAttribute("layoutStyle",
0523: responsesPanelLayoutStyle);
0524: responsesPanelXml.setAttribute("constraint",
0525: responsesPanelConstraint);
0526: responsesPanelXml
0527: .setAttribute("w", String.valueOf(clientWidth));
0528: responsesPanelXml.setAttribute("h", responsesPanelHeight);
0529: responsesPanelXml.setAttribute("opaque", responsesPanelOpaque);
0530:
0531: XmlElement repeatXml = new NanoXmlElement("Repeat");
0532: responsesPanelXml.addChild(repeatXml);
0533: repeatXml.setAttribute("while", "${hasMoreOptions()}");
0534:
0535: XmlElement includeXml = new NanoXmlElement("Include");
0536: repeatXml.addChild(includeXml);
0537: includeXml.setAttribute("file", "radiobutton");
0538:
0539: savePage(pageXml, pageName);
0540: }
0541:
0542: protected void buildDefaultMultipleTemplate(String pageName) {
0543: String mainPanelLayout = "Border";
0544: String mainPanelHeight = "120";
0545: String mainPanelConstraint = "center";
0546: String mainPanelOpaque = "false";
0547: String mainPanelBorder = "0";
0548: String questionPanelConstraint = "north";
0549: String questionPanelHeight = "60";
0550: String questionPanelOpaque = "true";
0551: String questionPanelStyle = "base/Question/Shade";
0552: String imageContent = "qmark.gif";
0553: String imageConstraint = "west";
0554: String imageOpaque = "false";
0555: String questionLabelX = "20";
0556: String questionLabelWidth = "400";
0557: String questionLabelHeight = "20";
0558: String questionLabelConstraint = "CENTER";
0559: String questionLabelAntialias = "true";
0560: String questionLabelOpaque = "false";
0561: String questionLabelStyle = "base/Question/Cue";
0562: String responsesPanelLayout = "Flow";
0563: String responsesPanelLayoutStyle = "0";
0564: String responsesPanelConstraint = "CENTER";
0565: String responsesPanelAntialias = "true";
0566: String responsesPanelOpaque = "false";
0567: String responsesPanelStyle = "base/Question";
0568: String responsesPanelHeight = "100";
0569:
0570: XmlElement pageXml = new NanoXmlElement("XPage");
0571: XmlElement componentsXml = new NanoXmlElement("Components");
0572: pageXml.addChild(componentsXml);
0573:
0574: XmlElement mainPanelXml = new NanoXmlElement("Panel");
0575: componentsXml.addChild(mainPanelXml);
0576: mainPanelXml.setAttribute("layout", mainPanelLayout);
0577: mainPanelXml.setAttribute("w", String.valueOf(clientWidth));
0578: mainPanelXml.setAttribute("h", mainPanelHeight);
0579: mainPanelXml.setAttribute("constraint", mainPanelConstraint);
0580: mainPanelXml.setAttribute("opaque", mainPanelOpaque);
0581: mainPanelXml.setAttribute("border", mainPanelBorder);
0582:
0583: XmlElement questionPanelXml = new NanoXmlElement("Panel");
0584: mainPanelXml.addChild(questionPanelXml);
0585: questionPanelXml.setAttribute("constraint",
0586: questionPanelConstraint);
0587: questionPanelXml.setAttribute("h", questionPanelHeight);
0588: questionPanelXml.setAttribute("opaque", questionPanelOpaque);
0589: questionPanelXml.setAttribute("style", questionPanelStyle);
0590:
0591: XmlElement imageXml = new NanoXmlElement("Image");
0592: questionPanelXml.addChild(imageXml);
0593: imageXml.setAttribute("name", "icon");
0594: imageXml.setAttribute("w", "14");
0595: imageXml.setAttribute("h", "14");
0596: imageXml.setAttribute("x", "2");
0597: imageXml.setAttribute("y", "2");
0598: imageXml.setAttribute("content", imageContent);
0599: imageXml.setAttribute("constraint", imageConstraint);
0600: imageXml.setAttribute("opaque", imageOpaque);
0601:
0602: XmlElement questionLabelXml = new NanoXmlElement("Label");
0603: questionPanelXml.addChild(questionLabelXml);
0604: questionLabelXml.setAttribute("name", "qtext");
0605: questionLabelXml.setAttribute("x", questionLabelX);
0606: questionLabelXml.setAttribute("w", questionLabelWidth);
0607: questionLabelXml.setAttribute("h", questionLabelHeight);
0608: questionLabelXml.setAttribute("content",
0609: "${getCurrentQuestion()}");
0610: questionLabelXml.setAttribute("constraint",
0611: questionLabelConstraint);
0612: questionLabelXml.setAttribute("antialias",
0613: questionLabelAntialias);
0614: questionLabelXml.setAttribute("opaque", questionLabelOpaque);
0615: questionLabelXml.setAttribute("style", questionLabelStyle);
0616:
0617: XmlElement responsesPanelXml = new NanoXmlElement("Panel");
0618: mainPanelXml.addChild(responsesPanelXml);
0619: responsesPanelXml.setAttribute("layout", responsesPanelLayout);
0620: responsesPanelXml.setAttribute("layoutStyle",
0621: responsesPanelLayoutStyle);
0622: responsesPanelXml.setAttribute("constraint",
0623: responsesPanelConstraint);
0624: responsesPanelXml
0625: .setAttribute("w", String.valueOf(clientWidth));
0626: responsesPanelXml.setAttribute("h", responsesPanelHeight);
0627: responsesPanelXml.setAttribute("opaque", responsesPanelOpaque);
0628:
0629: // XmlElement layoutXml = new NanoXmlElement( "Layout" );
0630: // responsesPanelXml.addChild( layoutXml );
0631: // layoutXml.setAttribute( "vgap", "15" );
0632: // layoutXml.setAttribute( "hgap", "8" );
0633:
0634: XmlElement repeatXml = new NanoXmlElement("repeat");
0635: responsesPanelXml.addChild(repeatXml);
0636: repeatXml.setAttribute("while", "${hasMoreOptions()}");
0637:
0638: XmlElement includeXml = new NanoXmlElement("include");
0639: repeatXml.addChild(includeXml);
0640: includeXml.setAttribute("file", "checkbox");
0641:
0642: XmlElement labelXml = new NanoXmlElement("label");
0643: repeatXml.addChild(labelXml);
0644: labelXml.setAttribute("w", "30");
0645: labelXml.setAttribute("h", "20");
0646: labelXml.setAttribute("content", "");
0647: labelXml.setAttribute("opaque", "false");
0648:
0649: savePage(pageXml, pageName);
0650: }
0651:
0652: protected void buildDefaultFreeTemplate(String pageName) {
0653: String mainPanelLayout = "Border";
0654: String mainPanelHeight = "120";
0655: String mainPanelConstraint = "center";
0656: String mainPanelOpaque = "false";
0657: String mainPanelBorder = "0";
0658: String questionPanelConstraint = "north";
0659: String questionPanelX = "10";
0660: String questionPanelWidth = String.valueOf(clientWidth);
0661: String questionPanelHeight = "60";
0662: String questionPanelOpaque = "true";
0663: String questionPanelStyle = "base/Question/Shade";
0664: String imageContent = "qmark.gif";
0665: String imageConstraint = "WEST";
0666: String imageOpaque = "true";
0667: String questionLabelX = "20";
0668: String questionLabelWidth = "400";
0669: String questionLabelHeight = "20";
0670: String questionLabelConstraint = "CENTER";
0671: String questionLabelAntialias = "true";
0672: String questionLabelOpaque = "false";
0673: String questionLabelStyle = "base/Question/Cue";
0674: String responsesPanelLayout = "Flow";
0675: String responsesPanelLayoutStyle = "0";
0676: String responsesPanelConstraint = "CENTER";
0677: String responsesPanelAntialias = "true";
0678: String responsesPanelOpaque = "false";
0679: String responsesPanelStyle = "base/Question";
0680: String responsesPanelHeight = "100";
0681: String optionLabelWidth = "100";
0682: String optionLabelHeight = "20";
0683: String optionLabelStyle = "base/Question/Check";
0684: String optionLabelOpaque = "false";
0685:
0686: XmlElement pageXml = new NanoXmlElement("XPage");
0687: XmlElement componentsXml = new NanoXmlElement("Components");
0688: pageXml.addChild(componentsXml);
0689:
0690: XmlElement mainPanelXml = new NanoXmlElement("Panel");
0691: componentsXml.addChild(mainPanelXml);
0692: mainPanelXml.setAttribute("layout", mainPanelLayout);
0693: mainPanelXml.setAttribute("w", String.valueOf(clientWidth));
0694: mainPanelXml.setAttribute("h", mainPanelHeight);
0695: mainPanelXml.setAttribute("constraint", mainPanelConstraint);
0696: mainPanelXml.setAttribute("opaque", mainPanelOpaque);
0697: mainPanelXml.setAttribute("border", mainPanelBorder);
0698:
0699: XmlElement questionPanelXml = new NanoXmlElement("Panel");
0700: mainPanelXml.addChild(questionPanelXml);
0701: questionPanelXml.setAttribute("constraint",
0702: questionPanelConstraint);
0703: questionPanelXml.setAttribute("x", questionPanelX);
0704: questionPanelXml.setAttribute("w", questionPanelWidth);
0705: questionPanelXml.setAttribute("h", questionPanelHeight);
0706: questionPanelXml.setAttribute("opaque", questionPanelOpaque);
0707: questionPanelXml.setAttribute("style", questionPanelStyle);
0708:
0709: XmlElement imageXml = new NanoXmlElement("Image");
0710: questionPanelXml.addChild(imageXml);
0711: imageXml.setAttribute("name", "icon");
0712: imageXml.setAttribute("w", "14");
0713: imageXml.setAttribute("h", "14");
0714: imageXml.setAttribute("x", "2");
0715: imageXml.setAttribute("y", "2");
0716: imageXml.setAttribute("content", imageContent);
0717: imageXml.setAttribute("constraint", imageConstraint);
0718: imageXml.setAttribute("opaque", imageOpaque);
0719:
0720: XmlElement questionLabelXml = new NanoXmlElement("Label");
0721: questionPanelXml.addChild(questionLabelXml);
0722: questionLabelXml.setAttribute("name", "qtext");
0723: questionLabelXml.setAttribute("x", questionLabelX);
0724: questionLabelXml.setAttribute("w", questionLabelWidth);
0725: questionLabelXml.setAttribute("h", questionLabelHeight);
0726: questionLabelXml.setAttribute("content",
0727: "${getCurrentQuestion()}");
0728: questionLabelXml.setAttribute("constraint",
0729: questionLabelConstraint);
0730: questionLabelXml.setAttribute("antialias",
0731: questionLabelAntialias);
0732: questionLabelXml.setAttribute("opaque", questionLabelOpaque);
0733: questionLabelXml.setAttribute("style", questionLabelStyle);
0734:
0735: XmlElement responsesPanelXml = new NanoXmlElement("Panel");
0736: mainPanelXml.addChild(responsesPanelXml);
0737: responsesPanelXml.setAttribute("layout", responsesPanelLayout);
0738: responsesPanelXml.setAttribute("layoutStyle",
0739: responsesPanelLayoutStyle);
0740: responsesPanelXml.setAttribute("constraint",
0741: responsesPanelConstraint);
0742: responsesPanelXml
0743: .setAttribute("w", String.valueOf(clientWidth));
0744: responsesPanelXml.setAttribute("h", responsesPanelHeight);
0745: responsesPanelXml.setAttribute("opaque", responsesPanelOpaque);
0746:
0747: // XmlElement layoutXml = new NanoXmlElement( "Layout" );
0748: // responsesPanelXml.addChild( layoutXml );
0749: // layoutXml.setAttribute( "vgap", "15" );
0750: // layoutXml.setAttribute( "hgap", "8" );
0751:
0752: XmlElement repeatXml = new NanoXmlElement("Repeat");
0753: responsesPanelXml.addChild(repeatXml);
0754: repeatXml.setAttribute("while", "${hasMoreOptions()}");
0755:
0756: XmlElement optionLabelXml = new NanoXmlElement("Label");
0757: repeatXml.addChild(optionLabelXml);
0758: optionLabelXml.setAttribute("w", optionLabelWidth);
0759: optionLabelXml.setAttribute("h", optionLabelHeight);
0760: optionLabelXml.setAttribute("content", "${getNextOption()}");
0761: optionLabelXml.setAttribute("style", optionLabelStyle);
0762: optionLabelXml.setAttribute("opaque", optionLabelOpaque);
0763:
0764: XmlElement includeXml = new NanoXmlElement("include");
0765: repeatXml.addChild(includeXml);
0766: includeXml.setAttribute("file", "edit");
0767:
0768: XmlElement gapLabelXml = new NanoXmlElement("Label");
0769: repeatXml.addChild(gapLabelXml);
0770: gapLabelXml.setAttribute("w", "30");
0771: gapLabelXml.setAttribute("h", "20");
0772: gapLabelXml.setAttribute("content", "");
0773: gapLabelXml.setAttribute("opaque", "false");
0774:
0775: savePage(pageXml, pageName);
0776: }
0777:
0778: /**
0779: * Default checkbox for use in the page templates.
0780: */
0781: protected void buildDefaultCheckbox(String pageName) {
0782: String width = "100";
0783: String height = "20";
0784: String style = "base/Question/Check";
0785: String opaque = "false";
0786: String antialias = "true";
0787:
0788: XmlElement pageXml = new NanoXmlElement("Page");
0789: XmlElement componentsXml = new NanoXmlElement("Components");
0790: pageXml.addChild(componentsXml);
0791:
0792: XmlElement checkboxXml = new NanoXmlElement("CheckBox");
0793: componentsXml.addChild(checkboxXml);
0794: checkboxXml.setAttribute("content", "${getNextOption()}");
0795: checkboxXml.setAttribute("name", "${getCurrentOptionName()}");
0796: checkboxXml.setAttribute("w", width);
0797: checkboxXml.setAttribute("h", height);
0798: checkboxXml.setAttribute("style", style);
0799: checkboxXml.setAttribute("opaque", opaque);
0800: checkboxXml.setAttribute("antialias", antialias);
0801:
0802: XmlElement dataXml = new NanoXmlElement("Data");
0803: pageXml.addChild(dataXml);
0804:
0805: XmlElement bindXml = new NanoXmlElement("Bind");
0806: dataXml.addChild(bindXml);
0807: bindXml.setAttribute("target", "${getCurrentOptionName()}");
0808: bindXml.setAttribute("source", "${getMultiOptionModelPath()}");
0809: bindXml.setAttribute("output", "${getMultiOptionModelPath()}");
0810: bindXml.setAttribute("reeval", "false");
0811:
0812: XmlElement eventsXml = new NanoXmlElement("Events");
0813: pageXml.addChild(eventsXml);
0814:
0815: XmlElement eventXml = new NanoXmlElement("Event");
0816: eventsXml.addChild(eventXml);
0817: eventXml.setAttribute("method", "handleMouse");
0818: eventXml.setAttribute("target", "${getCurrentOptionName()}");
0819: eventXml.setAttribute("type", "MouseHandler");
0820:
0821: savePage(pageXml, pageName);
0822: }
0823:
0824: /**
0825: * Default radiobutton for use in the page templates.
0826: */
0827: protected void buildDefaultRadiobutton(String pageName) {
0828: String width = "100";
0829: String height = "20";
0830: String style = "base/Question/Check";
0831: String opaque = "false";
0832: String antialias = "true";
0833:
0834: XmlElement pageXml = new NanoXmlElement("Page");
0835: XmlElement componentsXml = new NanoXmlElement("Components");
0836: pageXml.addChild(componentsXml);
0837:
0838: XmlElement radiobuttonXml = new NanoXmlElement("RadioButton");
0839: componentsXml.addChild(radiobuttonXml);
0840: radiobuttonXml.setAttribute("content", "${getNextOption()}");
0841: radiobuttonXml
0842: .setAttribute("name", "${getCurrentOptionName()}");
0843: radiobuttonXml.setAttribute("qid", "${getCurrentQuestionId()}");
0844: radiobuttonXml.setAttribute("w", width);
0845: radiobuttonXml.setAttribute("h", height);
0846: radiobuttonXml.setAttribute("style", style);
0847: radiobuttonXml.setAttribute("opaque", opaque);
0848: radiobuttonXml.setAttribute("antialias", antialias);
0849:
0850: XmlElement dataXml = new NanoXmlElement("Data");
0851: pageXml.addChild(dataXml);
0852:
0853: XmlElement bindXml = new NanoXmlElement("Bind");
0854: dataXml.addChild(bindXml);
0855: bindXml.setAttribute("target", "${getCurrentOptionName()}");
0856: bindXml.setAttribute("source",
0857: "${getExclusiveOptionModelPath()}");
0858: bindXml.setAttribute("output",
0859: "${getExclusiveOptionModelPath()}");
0860: bindXml.setAttribute("reeval", "false");
0861:
0862: XmlElement eventsXml = new NanoXmlElement("Events");
0863: pageXml.addChild(eventsXml);
0864:
0865: XmlElement eventXml = new NanoXmlElement("Event");
0866: eventsXml.addChild(eventXml);
0867: eventXml.setAttribute("method", "handleMouse");
0868: eventXml.setAttribute("target", "${getCurrentOptionName()}");
0869: eventXml.setAttribute("type", "MouseHandler");
0870:
0871: savePage(pageXml, pageName);
0872: }
0873:
0874: /**
0875: * Default text edito for use in the page templates
0876: */
0877: protected void buildDefaultEdit(String pageName) {
0878: String alignment = "leading";
0879: String style = "base/Question/Response";
0880: String preferredSize = "100,20";
0881:
0882: XmlElement pageXml = new NanoXmlElement("XPage");
0883: XmlElement componentsXml = new NanoXmlElement("Components");
0884: pageXml.addChild(componentsXml);
0885:
0886: XmlElement editXml = new NanoXmlElement("Edit");
0887: componentsXml.addChild(editXml);
0888: editXml.setAttribute("name", "${getCurrentOptionName()}");
0889: editXml.setAttribute("alignment", alignment);
0890: editXml.setAttribute("style", style);
0891: editXml.setAttribute("preferredSize", preferredSize);
0892:
0893: XmlElement dataXml = new NanoXmlElement("Data");
0894: pageXml.addChild(dataXml);
0895:
0896: XmlElement bindXml = new NanoXmlElement("Bind");
0897: dataXml.addChild(bindXml);
0898: bindXml.setAttribute("target", "${getCurrentOptionName()}");
0899: bindXml.setAttribute("source",
0900: "${getFreeTextOptionModelPath()}");
0901: bindXml.setAttribute("output",
0902: "${getFreeTextOptionModelPath()}");
0903: bindXml.setAttribute("reeval", "false");
0904:
0905: XmlElement eventsXml = new NanoXmlElement("Events");
0906: pageXml.addChild(eventsXml);
0907:
0908: XmlElement eventXml = new NanoXmlElement("Event");
0909: eventsXml.addChild(eventXml);
0910: eventXml.setAttribute("method", "handleFocus");
0911: eventXml.setAttribute("target", "${getCurrentOptionName()}");
0912: eventXml.setAttribute("type", "FocusHandler");
0913:
0914: savePage(pageXml, pageName);
0915: }
0916:
0917: /**
0918: * Default page xml for use with the XuiPro question components
0919: */
0920: protected void buildDefaultQuestionPage(String pageName) {
0921: String panelLayout = "Box";
0922: String panelX = "0";
0923: String panelY = "0";
0924: String panelStyle = "base/Question";
0925: String panelLayoutStyle = "1";
0926: String questionHeight = "30";
0927: String questionCue = "cue.gif";
0928:
0929: copyImage(questionCue);
0930:
0931: int bannerHeight = getBannerHeight();
0932: int footerHeight = getFooterHeight();
0933: int pageHeight = clientHeight - bannerHeight - footerHeight;
0934:
0935: //@todo set up the "finish_page" attribute if required
0936: XmlElement pageXml = new NanoXmlElement("XPage");
0937: pageXml.setAttribute("question_page", "questionPage");
0938: pageXml.setAttribute("class",
0939: "com.xoetrope.swing.survey.XQuestionPage");
0940: if (thankyouPage != null)
0941: pageXml.setAttribute("finish_page", thankyouPage);
0942:
0943: XmlElement componentsXml = new NanoXmlElement("Components");
0944: pageXml.addChild(componentsXml);
0945:
0946: XmlElement panelXml = new NanoXmlElement("Panel");
0947: componentsXml.addChild(panelXml);
0948: panelXml.setAttribute("layout", panelLayout);
0949: panelXml.setAttribute("x", panelX);
0950: panelXml.setAttribute("y", panelY);
0951: panelXml.setAttribute("w", String.valueOf(clientWidth + 15));
0952: panelXml.setAttribute("h", String.valueOf(pageHeight));
0953: panelXml.setAttribute("style", panelStyle);
0954: panelXml.setAttribute("layoutStyle", panelLayoutStyle);
0955:
0956: XmlElement repeatXml = new NanoXmlElement("Repeat");
0957: panelXml.addChild(repeatXml);
0958: repeatXml.setAttribute("while", "${hasMoreQuestions()}");
0959:
0960: XmlElement questionXml = new NanoXmlElement("Question");
0961: repeatXml.addChild(questionXml);
0962: questionXml.setAttribute("ref", "true");
0963: questionXml.setAttribute("cue", questionCue);
0964: questionXml.setAttribute("h", questionHeight);
0965:
0966: savePage(pageXml, pageName);
0967: }
0968:
0969: /**
0970: * Copies the specified page to the project's "page" folder
0971: * @param pagePath the path to the page which is to be copied
0972: */
0973: private void copyPage(String sourcePage) throws Exception {
0974: String pageName = sourcePage;
0975: int idx = pageName.lastIndexOf("\\");
0976: if (idx == -1)
0977: idx = pageName.lastIndexOf("/");
0978: if (idx > 0)
0979: pageName = pageName.substring(idx + 1);
0980: String outputPage = currentProject.getPath() + File.separator
0981: + "pages" + File.separator + pageName;
0982:
0983: File sourceFile = new File(sourcePage);
0984: File outputFile = new File(outputPage);
0985: InputStream is = new FileInputStream(sourcePage);
0986: OutputStream os = new FileOutputStream(outputPage);
0987: //XEditorUtilities.copy( is, os );
0988: }
0989:
0990: /**
0991: * Copies the specified file to the given project's folder.
0992: * @param sourcePath path to the file which is to be copied
0993: * @param projectFolder current project's folder where the file
0994: * will be copied to.
0995: */
0996: private void copyFile(String sourcePath, String projectFolder)
0997: throws Exception {
0998: String sourceFile = sourcePath;
0999: int idx = sourceFile.lastIndexOf("\\");
1000: if (idx == -1)
1001: idx = sourceFile.lastIndexOf("/");
1002: if (idx > 0)
1003: sourceFile = sourceFile.substring(idx + 1);
1004: String outputFile = currentProject.getPath() + File.separator
1005: + projectFolder + File.separator + sourceFile;
1006:
1007: File source = new File(sourcePath);
1008: File output = new File(outputFile);
1009: InputStream is = new FileInputStream(source);
1010: OutputStream os = new FileOutputStream(output);
1011: //XEditorUtilities.copy( is, os );
1012: }
1013:
1014: /**
1015: * Retrieves the name of the page from the
1016: * given path to the page file.
1017: * @param path the path to the file containing a xml
1018: * page definition
1019: * @return the page name
1020: */
1021: private String getPageName(String path) {
1022: int idx = path.lastIndexOf("\\");
1023: if (idx == -1)
1024: idx = path.lastIndexOf("/");
1025: if (idx > 0)
1026: path = path.substring(idx + 1);
1027:
1028: if (path.endsWith(".xml"))
1029: path = path.substring(0, path.length() - 4);
1030:
1031: return path;
1032: }
1033:
1034: private String getFileName(String path) {
1035: if (path == null)
1036: return null;
1037: int idx = path.lastIndexOf("\\");
1038: if (idx == -1)
1039: idx = path.lastIndexOf("/");
1040: if (idx > 0)
1041: path = path.substring(idx + 1);
1042: return path;
1043: }
1044:
1045: private void buildInputData() throws Exception {
1046: if (fileInputRb.isSelected()) {
1047: // create survey data files
1048:
1049: Properties langProperties = new Properties();
1050:
1051: String path = currentProject.getPath() + File.separator
1052: + "lang" + File.separator;
1053:
1054: if (internationalizeChk.isEnabled()
1055: && internationalizeChk.isSelected()) {
1056: for (int i = 0; i < 6; i++)
1057: if (langChks[i].isSelected()) {
1058: String langName = languageNames[i];
1059: String langCode = languageCodes[i];
1060: langProperties.put(langName, langCode);
1061: }
1062: } else {
1063: // use English as the default language
1064: langProperties.put("English", "en");
1065: }
1066:
1067: File langFile = new File(path + "LanguageList.properties");
1068: langProperties.store(new FileOutputStream(langFile), null);
1069:
1070: // create a file stub for each language
1071: String surveyName = surveyNameEdit.getText();
1072:
1073: Iterator langCodesIter = langProperties.values().iterator();
1074: while (langCodesIter.hasNext()) {
1075: String langCode = (String) langCodesIter.next();
1076: String fileName = path + langCode + "_" + surveyName
1077: + ".xml";
1078:
1079: File file = new File(fileName);
1080: if (!file.exists()) {
1081: file.createNewFile();
1082: createEmptySurveyFile(file);
1083: }
1084:
1085: }
1086: } else {
1087: //@todo create the database structure
1088:
1089: }
1090: }
1091:
1092: private void createEmptySurveyFile(File file) {
1093: try {
1094: NanoXmlElement surveyXml = new NanoXmlElement("Survey");
1095:
1096: FileWriter fw = new FileWriter(file);
1097: BufferedWriter bw = new BufferedWriter(fw);
1098: NanoXmlWriter writer = new NanoXmlWriter(bw);
1099: writer.write(surveyXml, true, 4);
1100: } catch (Exception ex) {
1101: ex.printStackTrace();
1102: }
1103: }
1104:
1105: private void buildSurvey() {
1106: if (!checkLanguageSelection()) {
1107: JOptionPane.showMessageDialog(this ,
1108: "Please choose at least one language");
1109: tabPane.setSelectedIndex(3);
1110: return;
1111: }
1112:
1113: int rc = JOptionPane
1114: .showConfirmDialog(
1115: this ,
1116: "This plugin can only be used with an empty project. Do you want all existing pages to be deleted?",
1117: "Error", JOptionPane.ERROR_MESSAGE,
1118: JOptionPane.YES_NO_CANCEL_OPTION);
1119: if (rc == JOptionPane.NO_OPTION) {
1120: setVisible(false);
1121: return;
1122: } else if (rc == JOptionPane.CANCEL_OPTION)
1123: setVisible(false);
1124: else
1125: currentProject.removeAllPages();
1126:
1127: SwingWorker worker = new SwingWorker() {
1128: public Object construct() {
1129: try {
1130: getContentPane().setCursor(
1131: new Cursor(Cursor.WAIT_CURSOR));
1132: buildLayout();
1133: buildStyles();
1134: buildInputData();
1135: setStartupProperties();
1136: copyResources();
1137: } catch (Exception ex) {
1138: ex.printStackTrace();
1139: }
1140: return null;
1141: }
1142:
1143: public void finished() {
1144: getContentPane().setCursor(
1145: new Cursor(Cursor.DEFAULT_CURSOR));
1146: setVisible(false);
1147: }
1148:
1149: };
1150:
1151: worker.start();
1152:
1153: }
1154:
1155: private void copyResources() {
1156: copyResourceFile("survey.jar", "/lib/survey.jar");
1157: addJar("survey.jar");
1158: copyResourceFile("survey.jar", "/lib/survey.jar");
1159: }
1160:
1161: /**
1162: * Used to copy files from the XuiPro resources directory to the current project.
1163: * @param in <CODE>String</CODE> representing the path of the file to be copied.
1164: * @param out <CODE>String</CODE> representing the path where it is to be copied too.
1165: */
1166: public void copyResourceFile(String src, String dst) {
1167: String location = getClass().getResource("").toString();
1168: location = location.substring(0, location.indexOf("com/"));
1169:
1170: try {
1171: URL url = new URL(location
1172: + "com/xoetrope/carousel/resources/" + src);
1173: OutputStream os = new FileOutputStream(new File(
1174: currentProject.getPath() + dst));
1175: InputStream is = url.openStream();
1176:
1177: //XEditorUtilities.copy( is, os );
1178:
1179: is.close();
1180: os.flush();
1181: os.close();
1182: } catch (Exception ex) {
1183: ex.printStackTrace();
1184: }
1185: }
1186:
1187: /**
1188: * Add jar to the project properties.
1189: * @param name <CODE>String</CODE> representing the path of the jar to be added.
1190: */
1191: public void addJar(String name) {
1192: try {
1193: String s = currentProject.getPath() + "\\lib\\" + name;
1194: File f = new File(s);
1195: URL jarUrl = f.toURI().toURL();
1196: currentProject.getEditorUtility().addJar(currentProject,
1197: jarUrl);
1198: } catch (Exception ex) {
1199: ex.printStackTrace();
1200: }
1201: }
1202:
1203: private void setStartupProperties() {
1204: // general properties
1205: currentProject.setFrameFile("frames.xml");
1206:
1207: String[] factories;
1208: if (!"TemplateQuestion".equals(defaultQuestionFormat)) {
1209: factories = new String[2];
1210: factories[0] = "net.xoetrope.registry.XRegisteredComponentFactory";
1211: factories[1] = "com.xoetrope.swing.XuiProComponentFactory";
1212: } else {
1213: factories = new String[1];
1214: factories[0] = "net.xoetrope.registry.XRegisteredComponentFactory";
1215: }
1216: currentProject.setComponentFactories(factories);
1217:
1218: currentProject.setStartupProperty("StartClass", startClass);
1219: currentProject.setStartupProperty("LifeCycleListener",
1220: "com.xoetrope.survey.SurveyManager");
1221: currentProject.setStartupProperty("Frames", "frames");
1222: currentProject.setStartupProperty("Title", "Xui Survey");
1223: currentProject.setStartupProperty("UseWindow", "false");
1224:
1225: currentProject.setUseFrames(true);
1226: currentProject.setStyleFile("XStyles.xml");
1227:
1228: int wd = 15; //???
1229: int hd = 36; //???
1230: currentProject.setWidth(clientWidth + wd);
1231: currentProject.setHeight(clientHeight + hd);
1232:
1233: // input data properties
1234: currentProject.setStartupProperty("SurveyName", surveyNameEdit
1235: .getText());
1236:
1237: if (fileInputRb.isSelected()) {
1238: currentProject
1239: .setStartupProperty("SurveyInputType", "File");
1240: } else if (dbInputRb.isSelected()) {
1241: currentProject.setStartupProperty("SurveyInputType", "Db");
1242: currentProject.setStartupProperty("SurveyInputDbUser",
1243: dbInputUser.getText());
1244: currentProject.setStartupProperty("SurveyInputDbPassword",
1245: dbInputPassword.getText());
1246: currentProject.setStartupProperty("SurveyInputDbUrl",
1247: (String) dbInputUrl.getSelectedObject());
1248: currentProject.setStartupProperty("SurveyInputDbDriver",
1249: (String) dbInputDriver.getSelectedObject());
1250: }
1251:
1252: // output data properties
1253: if (fileOutputRb.isSelected()) { // file
1254: currentProject.setStartupProperty("SurveyOutputType",
1255: "File");
1256: currentProject.setStartupProperty("SurveyOutputFile",
1257: fileOutputName.getText());
1258: } else if (dbOutputRb.isSelected()) { // database
1259: currentProject.setStartupProperty("SurveyOutputType", "Db");
1260: currentProject.setStartupProperty("SurveyOutputDbUser",
1261: dbOutputUser.getText());
1262: currentProject.setStartupProperty("SurveyOutputDbPasswrod",
1263: dbOutputPassword.getText());
1264: currentProject.setStartupProperty("SurveyOutputDbUrl",
1265: (String) dbOutputUrl.getSelectedObject());
1266: currentProject.setStartupProperty("SurveyOutputDbDriver",
1267: (String) dbOutputDriver.getSelectedObject());
1268: }
1269:
1270: // should the survey be restarted automatically
1271: String restartSurvey = (restartChk.isEnabled()
1272: && restartChk.isSelected() ? "true" : "false");
1273: currentProject.setStartupProperty("RestartSurvey",
1274: restartSurvey);
1275:
1276: // UI and navigation properties
1277: currentProject.setStartupProperty("FinishPage",
1278: (thankyouPage != null ? thankyouPage : ""));
1279:
1280: currentProject.setStartupProperty("DefaultQuestionFormat",
1281: defaultQuestionFormat);
1282: if ("TemplateQuestion".equals(defaultQuestionFormat)) {
1283: currentProject.setStartupProperty("MultipleChoiceTemplate",
1284: multipleTemplate);
1285: currentProject.setStartupProperty(
1286: "MutuallyExclusiveTemplate", exclusiveTemplate);
1287: currentProject.setStartupProperty("FreeTextTemplate",
1288: freeTemplate);
1289: }
1290:
1291: currentProject.setStartupProperty("QuestionsPerPage", String
1292: .valueOf(questionsPerPage));
1293:
1294: if (languageCodes.length > 0)
1295: currentProject.setStartupProperty("Language",
1296: languageCodes[0]);
1297: else
1298: currentProject.setStartupProperty("Language", "en");
1299:
1300: // set frame files and frame sizes
1301: String[] frameFiles = new String[5];
1302: frameFiles[0] = banner;
1303: frameFiles[1] = null;
1304: frameFiles[2] = startClass;
1305: frameFiles[3] = null;
1306: frameFiles[4] = navigationPanel;
1307: int[] frameSizes = new int[4];
1308: frameSizes[0] = getBannerHeight();
1309: frameSizes[1] = 0;
1310: frameSizes[2] = 0;
1311: frameSizes[3] = getFooterHeight();
1312: currentProject.setFrameFiles(frameFiles);
1313: currentProject.setFrameSizes(frameSizes);
1314:
1315: currentProject.save();
1316: }
1317:
1318: private void buildThankyouPage(String pageName) {
1319: String labelName = "Welcome";
1320: String labelStyle = "base/Question/Title";
1321: String labelOpaque = "false";
1322: String labelAntialias = "true";
1323: String labelAlignment = "Center";
1324: String labelContent = thanksEdit.getText();
1325: int labelX = 0;
1326: int labelY = (clientHeight - getBannerHeight() - getFooterHeight()) / 3;
1327: int labelWidth = clientWidth;
1328: int labelHeight = 60;
1329:
1330: XmlElement pageXml = new NanoXmlElement("XPage");
1331: pageXml.setAttribute("style", "base");
1332:
1333: XmlElement componentsXml = new NanoXmlElement("Components");
1334: pageXml.addChild(componentsXml);
1335:
1336: XmlElement labelXml = new NanoXmlElement("Label");
1337: componentsXml.addChild(labelXml);
1338: labelXml.setAttribute("name", labelName);
1339: labelXml.setAttribute("content", labelContent);
1340: labelXml.setAttribute("alignment", labelAlignment);
1341: labelXml.setAttribute("antialias", labelAntialias);
1342: labelXml.setAttribute("opaque", labelOpaque);
1343: labelXml.setAttribute("style", labelStyle);
1344: labelXml.setAttribute("x", String.valueOf(labelX));
1345: labelXml.setAttribute("y", String.valueOf(labelY));
1346: labelXml.setAttribute("w", String.valueOf(labelWidth));
1347: labelXml.setAttribute("h", String.valueOf(labelHeight));
1348:
1349: savePage(pageXml, pageName);
1350: }
1351:
1352: private void buildWelcomePage(String pageName) {
1353: String labelName = "Welcome";
1354: String labelContent = welcomeEdit.getText();
1355: String labelAlignment = "Center";
1356: String labelAntialias = "true";
1357: String labelOpaque = "false";
1358:
1359: String labelStyle = "base/Question/SubTitle";
1360: int labelX = 0;
1361: int labelY = (clientHeight - getBannerHeight() - getFooterHeight()) / 3;
1362: int labelWidth = clientWidth - 2 * labelX;
1363:
1364: int labelHeight = 60;
1365: String langPanelLayout = "Flow";
1366: String langPanelLayoutStyle = "0";
1367: String langPanelOpaque = "false";
1368: String langPanelStyle = "base";
1369: int langPanelHeight = 100;
1370: int langPanelX = 0;
1371: int langPanelY = labelY + 40;
1372: int avgap = 15;
1373: int hgap = 8;
1374: String imageName = "sprach";
1375: String imageContent = "sprach.gif";
1376: int imageX = 75;
1377: int imageY = 15;
1378: int imageWidth = 51;
1379: int imageHeight = 28;
1380: String langRadioStyle = "base/Question/Check";
1381: String langRadioOpaque = "false";
1382: int langRadioY = 20;
1383: int langRadioWidth = 100;
1384: int langRadioHeight = 20;
1385:
1386: XmlElement pageXml = new NanoXmlElement("XPage");
1387: pageXml.setAttribute("question_page", questionPage);
1388: pageXml.setAttribute("finish_page", thankyouPage);
1389: pageXml.setAttribute("style", "base");
1390:
1391: XmlElement componentsXml = new NanoXmlElement("Components");
1392: pageXml.addChild(componentsXml);
1393:
1394: XmlElement labelXml = new NanoXmlElement("Label");
1395: componentsXml.addChild(labelXml);
1396: labelXml.setAttribute("name", labelName);
1397: labelXml.setAttribute("content", labelContent);
1398: labelXml.setAttribute("alignment", labelAlignment);
1399: labelXml.setAttribute("antialias", labelAntialias);
1400: labelXml.setAttribute("opaque", labelOpaque);
1401: labelXml.setAttribute("style", labelStyle);
1402: labelXml.setAttribute("x", String.valueOf(labelX));
1403: labelXml.setAttribute("y", String.valueOf(labelY));
1404: labelXml.setAttribute("w", String.valueOf(labelWidth));
1405: labelXml.setAttribute("h", String.valueOf(labelHeight));
1406:
1407: XmlElement langPanelXml = new NanoXmlElement("Panel");
1408: componentsXml.addChild(langPanelXml);
1409: langPanelXml.setAttribute("layout", langPanelLayout);
1410: langPanelXml.setAttribute("layoutStyle", langPanelLayoutStyle);
1411: langPanelXml.setAttribute("opaque", langPanelOpaque);
1412: langPanelXml.setAttribute("style", langPanelStyle);
1413: langPanelXml.setAttribute("w", String.valueOf(clientWidth));
1414: langPanelXml.setAttribute("h", String.valueOf(langPanelHeight));
1415: langPanelXml.setAttribute("x", String.valueOf(langPanelX));
1416: langPanelXml.setAttribute("y", String.valueOf(langPanelY));
1417: langPanelXml.setAttribute("h", String.valueOf(langPanelHeight));
1418:
1419: String[] langNames = getSelectedLanguages();
1420: int numLangs = langNames.length;
1421: // if there's only one language provided do not create a radiobutton
1422: if (numLangs == 1)
1423: numLangs = 0;
1424:
1425: if (numLangs > 0) {
1426: copyImage(imageContent);
1427: XmlElement imageXml = new NanoXmlElement("Image");
1428: langPanelXml.addChild(imageXml);
1429: imageXml.setAttribute("name", imageName);
1430: imageXml.setAttribute("content", imageContent);
1431: imageXml.setAttribute("x", String.valueOf(imageX));
1432: imageXml.setAttribute("y", String.valueOf(imageY));
1433: imageXml.setAttribute("w", String.valueOf(imageWidth));
1434: imageXml.setAttribute("h", String.valueOf(imageHeight));
1435: }
1436:
1437: for (int i = 0; i < numLangs; i++) {
1438: XmlElement langRadioXml = new NanoXmlElement("RadioButton");
1439: langPanelXml.addChild(langRadioXml);
1440: langRadioXml.setAttribute("w", String
1441: .valueOf(langRadioWidth));
1442: langRadioXml.setAttribute("h", String
1443: .valueOf(langRadioHeight));
1444: langRadioXml.setAttribute("style", String
1445: .valueOf(langRadioStyle));
1446: langRadioXml.setAttribute("opaque", String
1447: .valueOf(langRadioOpaque));
1448: String langName = langChks[i].getText();
1449: langRadioXml.setAttribute("content", langName);
1450: langRadioXml.setAttribute("name", langName);
1451: langRadioXml.setAttribute("selected", (i == 0 ? "true"
1452: : "false"));
1453: }
1454:
1455: XmlElement dataXml = new NanoXmlElement("Data");
1456: pageXml.addChild(dataXml);
1457: for (int i = 0; i < numLangs; i++) {
1458: XmlElement bindXml = new NanoXmlElement("Bind");
1459: dataXml.addChild(bindXml);
1460: bindXml.setAttribute("target", langChks[i].getText());
1461: bindXml.setAttribute("source", "currentSurveyLanguage");
1462: bindXml.setAttribute("output", "currentSurveyLanguage");
1463: bindXml.setAttribute("reeval", "false");
1464: }
1465:
1466: XmlElement eventsXml = new NanoXmlElement("Events");
1467: pageXml.addChild(eventsXml);
1468: for (int i = 0; i < numLangs; i++) {
1469: XmlElement eventXml = new NanoXmlElement("Event");
1470: eventsXml.addChild(eventXml);
1471: eventXml.setAttribute("target", langChks[i].getText());
1472: eventXml.setAttribute("method", "saveBoundComponentValues");
1473: eventXml.setAttribute("type", "MouseHandler");
1474: }
1475:
1476: savePage(pageXml, pageName);
1477: }
1478:
1479: private String[] getSelectedLanguages() {
1480: int n = 0;
1481: for (int i = 0; i < 6; i++)
1482: n += (langChks[i].isSelected() ? 1 : 0);
1483: String[] selLangs = new String[n];
1484: n = 0;
1485: for (int i = 0; i < 6; i++)
1486: if (langChks[i].isSelected())
1487: selLangs[n++] = languageNames[i];
1488: return selLangs;
1489: }
1490:
1491: private void savePage(XmlElement pageXml, String pageName) {
1492: String fileName = currentProject.getPath() + File.separator
1493: + "pages" + File.separator + pageName;
1494: File pageFile = new File(fileName);
1495: FileWriter fw = null;
1496: try {
1497: fw = new FileWriter(pageFile);
1498: BufferedWriter bw = new BufferedWriter(fw);
1499: NanoXmlWriter writer = new NanoXmlWriter(bw);
1500: writer.write(pageXml, true, 4);
1501: } catch (IOException e) {
1502: e.printStackTrace();
1503: }
1504: }
1505:
1506: private int getBannerHeight() {
1507: int bannerHeight = bannerChk.isSelected() ? Math.max(
1508: clientHeight / 10, 60) : 0;
1509: return bannerHeight;
1510: }
1511:
1512: private int getFooterHeight() {
1513: int footerHeight = navigationChk.isSelected() ? Math.max(
1514: clientHeight / 10, 40) : 0;
1515: return footerHeight;
1516: }
1517:
1518: private void buildDefaultQuestionPageTemplate(String pageFile) {
1519: String pageSize = (String) pageSizeCombo.getSelectedItem();
1520: int bannerHeight = getBannerHeight();
1521: int footerHeight = getFooterHeight();
1522: int pageHeight = clientHeight - bannerHeight - footerHeight;
1523: int pageWidth = clientWidth;
1524:
1525: XmlElement pageXml = new NanoXmlElement("XPage");
1526: pageXml.setAttribute("question_page", getPageName(pageFile));
1527: pageXml.setAttribute("class",
1528: "com.xoetrope.swing.survey.XQuestionPage");
1529: pageXml.setAttribute("finish_page", thankyouPage);
1530: pageXml.setAttribute("style", "base");
1531:
1532: XmlElement componentsXml = new NanoXmlElement("Components");
1533: pageXml.addChild(componentsXml);
1534:
1535: XmlElement panel2Xml = new NanoXmlElement("Panel");
1536: componentsXml.addChild(panel2Xml);
1537: panel2Xml.setAttribute("x", "0");
1538: panel2Xml.setAttribute("y", "0");
1539: panel2Xml.setAttribute("w", String.valueOf(pageWidth));
1540: panel2Xml.setAttribute("h", String.valueOf(pageHeight));
1541: panel2Xml.setAttribute("layout", "Box");
1542: panel2Xml.setAttribute("style", "base");
1543: panel2Xml.setAttribute("layoutStyle", "1");
1544:
1545: XmlElement repeatXml = new NanoXmlElement("Repeat");
1546: panel2Xml.addChild(repeatXml);
1547: repeatXml.setAttribute("while", "${hasMoreQuestions()}");
1548:
1549: XmlElement includeXml = new NanoXmlElement("Include");
1550: repeatXml.addChild(includeXml);
1551: includeXml.setAttribute("execute", "${getNextQuestion()}");
1552: includeXml.setAttribute("file",
1553: "${getCurrentQuestionTemplate()}");
1554:
1555: savePage(pageXml, pageFile);
1556: }
1557:
1558: private void buildCheckBoxTemplate() {
1559: String pageSize = (String) pageSizeCombo.getSelectedItem();
1560: int pageWidth = Integer.parseInt(pageSize.substring(0, pageSize
1561: .indexOf(' ')));
1562:
1563: XmlElement pageXml = new NanoXmlElement("XPage");
1564:
1565: XmlElement componentsXml = new NanoXmlElement("Components");
1566: pageXml.addChild(componentsXml);
1567:
1568: XmlElement panel0Xml = new NanoXmlElement("Panel");
1569: componentsXml.addChild(panel0Xml);
1570: panel0Xml.setAttribute("layout", "Border");
1571: panel0Xml.setAttribute("style", "question");
1572: panel0Xml.setAttribute("w", String.valueOf(pageWidth));
1573: panel0Xml.setAttribute("h", "60");
1574: panel0Xml.setAttribute("constraint", "center");
1575:
1576: XmlElement panel1Xml = new NanoXmlElement("Panel");
1577: panel0Xml.addChild(panel1Xml);
1578: panel1Xml.setAttribute("layout", "Border");
1579: panel1Xml.setAttribute("style", "question");
1580: panel1Xml.setAttribute("constraint", "north");
1581: panel1Xml.setAttribute("w", String.valueOf(pageWidth));
1582: panel1Xml.setAttribute("h", "20");
1583:
1584: XmlElement imageXml = new NanoXmlElement("Image");
1585: panel1Xml.addChild(imageXml);
1586: imageXml.setAttribute("name", "icon");
1587: imageXml.setAttribute("w", "20");
1588: imageXml.setAttribute("h", "20");
1589: imageXml.setAttribute("contenet", "qmark.gif");
1590: imageXml.setAttribute("style", "question");
1591: imageXml.setAttribute("constraint", "WEST");
1592:
1593: XmlElement labelXml = new NanoXmlElement("Label");
1594: panel1Xml.addChild(labelXml);
1595: labelXml.setAttribute("name", "qtext");
1596: labelXml.setAttribute("w", String.valueOf(pageWidth - 10));
1597: labelXml.setAttribute("h", "20");
1598: labelXml.setAttribute("content", "${getQuestionText()}");
1599: labelXml.setAttribute("style", "question");
1600: labelXml.setAttribute("constraint", "CENTER");
1601: labelXml.setAttribute("opaque", "true");
1602:
1603: XmlElement panel2Xml = new NanoXmlElement("Panel ");
1604: panel0Xml.addChild(panel2Xml);
1605: panel2Xml.setAttribute("layout", "Flow");
1606: panel2Xml.setAttribute("layoutStyle", "0");
1607: panel2Xml.setAttribute("constraint", "center");
1608: panel2Xml.setAttribute("w", String.valueOf(pageWidth - 10));
1609: panel2Xml.setAttribute("h", "25");
1610:
1611: XmlElement repeatXml = new NanoXmlElement("Repeat");
1612: repeatXml.setAttribute("while", "${hasMoreOptions()}");
1613: panel2Xml.addChild(repeatXml);
1614:
1615: XmlElement includeXml = new NanoXmlElement("include");
1616: repeatXml.addChild(includeXml);
1617: includeXml.setAttribute("file", "checkbox");
1618:
1619: savePage(pageXml, "checkBoxTemplate.xml");
1620: }
1621:
1622: private void buildRadioButtonTemplate() {
1623: String pageSize = (String) pageSizeCombo.getSelectedItem();
1624: int pageWidth = Integer.parseInt(pageSize.substring(0, pageSize
1625: .indexOf(' ')));
1626:
1627: XmlElement pageXml = new NanoXmlElement("XPage");
1628:
1629: XmlElement componentsXml = new NanoXmlElement("Components");
1630: pageXml.addChild(componentsXml);
1631:
1632: XmlElement panel0Xml = new NanoXmlElement("Panel");
1633: componentsXml.addChild(panel0Xml);
1634: panel0Xml.setAttribute("layout", "Border");
1635: panel0Xml.setAttribute("style", "question");
1636: panel0Xml.setAttribute("w", String.valueOf(pageWidth));
1637: panel0Xml.setAttribute("h", "60");
1638: panel0Xml.setAttribute("constraint", "center");
1639:
1640: XmlElement panel1Xml = new NanoXmlElement("Panel");
1641: panel0Xml.addChild(panel1Xml);
1642: panel1Xml.setAttribute("layout", "Border");
1643: panel1Xml.setAttribute("style", "question");
1644: panel1Xml.setAttribute("constraint", "north");
1645: panel1Xml.setAttribute("w", String.valueOf(pageWidth));
1646: panel1Xml.setAttribute("h", "20");
1647:
1648: XmlElement imageXml = new NanoXmlElement("Image");
1649: panel1Xml.addChild(imageXml);
1650: imageXml.setAttribute("name", "icon");
1651: imageXml.setAttribute("w", "20");
1652: imageXml.setAttribute("h", "20");
1653: imageXml.setAttribute("contenet", "qmark.gif");
1654: imageXml.setAttribute("style", "question");
1655: imageXml.setAttribute("constraint", "WEST");
1656:
1657: XmlElement labelXml = new NanoXmlElement("Label");
1658: panel1Xml.addChild(labelXml);
1659: labelXml.setAttribute("name", "qtext");
1660: labelXml.setAttribute("w", String.valueOf(pageWidth - 10));
1661: labelXml.setAttribute("h", "20");
1662: labelXml.setAttribute("content", "${getQuestionText()}");
1663: labelXml.setAttribute("style", "question");
1664: labelXml.setAttribute("constraint", "CENTER");
1665: labelXml.setAttribute("opaque", "true");
1666:
1667: XmlElement panel2Xml = new NanoXmlElement("Panel ");
1668: panel0Xml.addChild(panel2Xml);
1669: panel2Xml.setAttribute("layout", "Flow");
1670: panel2Xml.setAttribute("layoutStyle", "0");
1671: panel2Xml.setAttribute("constraint", "center");
1672: panel2Xml.setAttribute("w", String.valueOf(pageWidth - 10));
1673: panel2Xml.setAttribute("h", "25");
1674:
1675: XmlElement repeatXml = new NanoXmlElement("Repeat");
1676: repeatXml.setAttribute("while", "${hasMoreOptions()}");
1677: panel2Xml.addChild(repeatXml);
1678:
1679: XmlElement includeXml = new NanoXmlElement("include");
1680: repeatXml.addChild(includeXml);
1681: includeXml.setAttribute("file", "radioButton");
1682:
1683: savePage(pageXml, "radioButtonTemplate.xml");
1684: }
1685:
1686: private void buildEmptyPage(String pageName) {
1687: XmlElement pageXml = new NanoXmlElement("XPage");
1688: savePage(pageXml, pageName);
1689: }
1690:
1691: private void buildBanner(String pageName) throws Exception {
1692: String bannerImageFile = "logo.gif";
1693: String bannerImageName = "logo";
1694: String bannerImageOpaque = "false";
1695: int bannerImageWidth = 0;
1696: int bannerImageHeight = 0;
1697: int bannerImageX = 10;
1698: int bannerImageY = 10;
1699: String bannerLabelName = "title";
1700: String bannerLabelContent = "On-line survey";
1701: String bannerLabelOpaque = "false";
1702: String bannerLabelStyle = "base/Question";
1703: String bannerLabelAntiAlias = "true";
1704: int bannerLabelX = 10;
1705: int bannerLabelY = 10;
1706: int bannerLabelWidth = 560;
1707: int bannerLabelHeight = 446;
1708: String bannerLabelAlignment = "RIGHT";
1709: int eggX = 620;
1710: int eggY = 0;
1711: int eggWidth = 20;
1712: int eggHeight = 20;
1713:
1714: XmlElement pageXml = new NanoXmlElement("XPage");
1715: pageXml.setAttribute("style", "base/Header");
1716: XmlElement componentsXml = new NanoXmlElement("Components");
1717: pageXml.addChild(componentsXml);
1718:
1719: bannerImageFile = logoEdit.getText();
1720: if (logoChk.isSelected() && (bannerImageFile != null)
1721: && !"".equals(bannerImageFile)) {
1722: Image bannerImage = copyImage(bannerImageFile);
1723: bannerImageWidth = bannerImage.getWidth(null);
1724: bannerImageHeight = bannerImage.getHeight(null);
1725: XmlElement imageXml = new NanoXmlElement("Image");
1726: componentsXml.addChild(imageXml);
1727: imageXml.setAttribute("name", bannerImageName);
1728: imageXml.setAttribute("imageName", bannerImageFile);
1729: imageXml.setAttribute("opaque", bannerImageOpaque);
1730: imageXml.setAttribute("x", String.valueOf(bannerImageX));
1731: imageXml.setAttribute("y", String.valueOf(bannerImageY));
1732: imageXml
1733: .setAttribute("w", String.valueOf(bannerImageWidth));
1734: imageXml.setAttribute("h", String
1735: .valueOf(bannerImageHeight));
1736: bannerLabelX += bannerImageWidth + 10;
1737: }
1738:
1739: bannerLabelContent = titleEdit.getText();
1740: if ((bannerLabelContent != null)
1741: && !"".equals(bannerLabelContent)) {
1742: bannerLabelWidth = clientWidth - bannerLabelX - 10;
1743: XmlElement labelXml = new NanoXmlElement("Label");
1744: componentsXml.addChild(labelXml);
1745: labelXml.setAttribute("name", bannerLabelName);
1746: labelXml.setAttribute("x", String.valueOf(bannerLabelX));
1747: labelXml.setAttribute("y", String.valueOf(bannerLabelY));
1748: labelXml
1749: .setAttribute("w", String.valueOf(bannerLabelWidth));
1750: labelXml.setAttribute("h", String
1751: .valueOf(bannerLabelHeight));
1752: labelXml.setAttribute("content", bannerLabelContent);
1753: labelXml.setAttribute("opaque", bannerLabelOpaque);
1754: labelXml.setAttribute("style", bannerLabelStyle);
1755: labelXml.setAttribute("antialias", bannerLabelAntiAlias);
1756: labelXml.setAttribute("alignment", bannerLabelAlignment);
1757: }
1758:
1759: savePage(pageXml, pageName);
1760: }
1761:
1762: private void buildNavigationPanel(String pageName) {
1763: String prevImageName = prevEdit.getText();
1764: String nextImageName = nextEdit.getText();
1765: String homeImageName = homeEdit.getText();
1766:
1767: boolean prev = backChk.isSelected()
1768: && !"".equals(prevImageName);
1769: boolean home = homeChk.isSelected()
1770: && !"".equals(homeImageName);
1771:
1772: int nextImageWidth = 0;
1773: int nextImageHeight = 0;
1774: int prevImageWidth = 0;
1775: int prevImageHeight = 0;
1776: int homeImageWidth = 0;
1777: int homeImageHeight = 0;
1778:
1779: int vgap = 5;
1780: int hgap = 10;
1781:
1782: int footerHeight = navigationChk.isSelected() ? Math.max(
1783: clientHeight / 5, 100) : 0;
1784:
1785: XmlElement pageXml = new NanoXmlElement("XPage");
1786: pageXml.setAttribute("class",
1787: "com.xoetrope.swing.survey.XQuestionPage");
1788: pageXml.setAttribute("style", "base/Footer");
1789: XmlElement componentsXml = new NanoXmlElement("Components");
1790: pageXml.addChild(componentsXml);
1791:
1792: // "home page" button
1793: if (home) {
1794: Image homeImage = copyImage(homeImageName);
1795: homeImageWidth = homeImage.getWidth(null);
1796: homeImageHeight = homeImage.getHeight(null);
1797: XmlElement homeImageXml = new NanoXmlElement("Image");
1798: componentsXml.addChild(homeImageXml);
1799: homeImageXml.setAttribute("name", "homeButton");
1800: homeImageXml.setAttribute("x", String.valueOf(hgap));
1801: homeImageXml.setAttribute("y", String.valueOf(vgap));
1802: homeImageXml.setAttribute("w", String
1803: .valueOf(homeImageWidth));
1804: homeImageXml.setAttribute("h", String
1805: .valueOf(homeImageHeight));
1806: homeImageXml.setAttribute("imageName", homeImageName);
1807: homeImageXml.setAttribute("content", homeImageName);
1808: }
1809:
1810: // "previous page" button
1811: if (prev) {
1812: Image prevImage = copyImage(prevImageName);
1813: prevImageWidth = prevImage.getWidth(null);
1814: prevImageHeight = prevImage.getHeight(null);
1815: XmlElement prevImageXml = new NanoXmlElement("Image");
1816: componentsXml.addChild(prevImageXml);
1817: prevImageXml.setAttribute("name", "prevButton");
1818: prevImageXml.setAttribute("x", String.valueOf(hgap
1819: + (home ? homeImageWidth + hgap : 0)));
1820: prevImageXml.setAttribute("y", String.valueOf(vgap));
1821: prevImageXml.setAttribute("w", String
1822: .valueOf(prevImageWidth));
1823: prevImageXml.setAttribute("h", String
1824: .valueOf(prevImageHeight));
1825: prevImageXml.setAttribute("imageName", prevImageName);
1826: prevImageXml.setAttribute("content", prevImageName);
1827: }
1828:
1829: Image nextImage = copyImage(nextImageName);
1830: nextImageWidth = nextImage.getWidth(null);
1831: nextImageHeight = nextImage.getHeight(null);
1832: XmlElement nextImageXml = new NanoXmlElement("Image");
1833: componentsXml.addChild(nextImageXml);
1834: nextImageXml.setAttribute("name", "nextButton");
1835: nextImageXml.setAttribute("x", String.valueOf(clientWidth
1836: - hgap - nextImageWidth));
1837: nextImageXml.setAttribute("y", String.valueOf(vgap));
1838: nextImageXml.setAttribute("w", String.valueOf(nextImageWidth));
1839: nextImageXml.setAttribute("h", String.valueOf(nextImageHeight));
1840: nextImageXml.setAttribute("imageName", nextImageName);
1841: nextImageXml.setAttribute("content", nextImageName);
1842:
1843: XmlElement eventsXml = new NanoXmlElement("Events");
1844: pageXml.addChild(eventsXml);
1845:
1846: if (home) {
1847: XmlElement prevEventXml = new NanoXmlElement("Event");
1848: eventsXml.addChild(prevEventXml);
1849: prevEventXml.setAttribute("method", "firstPageClick");
1850: prevEventXml.setAttribute("target", "homeButton");
1851: prevEventXml.setAttribute("type", "MouseHandler");
1852: }
1853:
1854: if (prev) {
1855: XmlElement prevEventXml = new NanoXmlElement("Event");
1856: eventsXml.addChild(prevEventXml);
1857: prevEventXml.setAttribute("method", "prevPageClick");
1858: prevEventXml.setAttribute("target", "prevButton");
1859: prevEventXml.setAttribute("type", "MouseHandler");
1860: }
1861:
1862: XmlElement nextEventXml = new NanoXmlElement("Event");
1863: eventsXml.addChild(nextEventXml);
1864: nextEventXml.setAttribute("method", "nextPageClick");
1865: nextEventXml.setAttribute("target", "nextButton");
1866: nextEventXml.setAttribute("type", "MouseHandler");
1867:
1868: savePage(pageXml, pageName);
1869: }
1870:
1871: private void buildStyles() {
1872: XEditorStyleManager sm = (XEditorStyleManager) currentProject
1873: .getStyleManager();
1874: sm.removeAll();
1875:
1876: sm.addStyle("base", setupStyle(colourPanel.COLOR_BODYTEXT,
1877: colourPanel.COLOR_BKGROUND, fontPanel.FONT_BODYTEXT));
1878: sm.addStyle("base/Question", setupStyle(
1879: colourPanel.COLOR_HEADING, colourPanel.COLOR_BKGROUND,
1880: fontPanel.FONT_HEADING));
1881: sm.addStyle("base/Question/Check", setupStyle(
1882: colourPanel.COLOR_CODE, colourPanel.COLOR_BKGROUND,
1883: fontPanel.FONT_BODYTEXT));
1884: sm.addStyle("base/Question/Cue", setupStyle(
1885: colourPanel.COLOR_CAPTION, colourPanel.COLOR_BKGROUND,
1886: fontPanel.FONT_BODYTEXT));
1887: sm.addStyle("base/Question/Response", setupStyle(
1888: colourPanel.COLOR_BODYTEXT, colourPanel.COLOR_BKGROUND,
1889: fontPanel.FONT_BODYTEXT));
1890: sm
1891: .addStyle("base/Question/Shade", setupStyle(
1892: colourPanel.COLOR_BTNTEXT,
1893: colourPanel.COLOR_PLACEHOLDER,
1894: fontPanel.FONT_BODYTEXT));
1895: sm.addStyle("base/Question/ThreeD", setupStyle(
1896: colourPanel.COLOR_BTNTEXT, colourPanel.COLOR_BTNFACE,
1897: fontPanel.FONT_BODYTEXT));
1898: sm.addStyle("base/Stripe", setupStyle(
1899: colourPanel.COLOR_BTNTEXT, colourPanel.COLOR_LINE,
1900: fontPanel.FONT_BODYTEXT));
1901: sm.addStyle("base/Sidebar", setupStyle(
1902: colourPanel.COLOR_BTNTEXT,
1903: colourPanel.COLOR_PLACEHOLDER, fontPanel.FONT_CAPTION));
1904: sm.addStyle("base/Title", setupStyle(colourPanel.COLOR_HEADING,
1905: colourPanel.COLOR_BKGROUND, fontPanel.FONT_HEADING));
1906: sm.addStyle("base/SubTitle", setupStyle(
1907: colourPanel.COLOR_SUBHEADING,
1908: colourPanel.COLOR_BKGROUND, fontPanel.FONT_SUBHEADING));
1909: sm.addStyle("base/Progress", setupStyle(colourPanel.COLOR_CODE,
1910: colourPanel.COLOR_BKGROUND, fontPanel.FONT_CODE));
1911:
1912: // tmp: header and footer styles
1913: sm.addStyle("base/Header", setupHeaderStyle());
1914: sm.addStyle("base/Footer", setupFooterStyle());
1915:
1916: sm.saveStyles(currentProject.getPath()
1917: + "/resources/XStyles.xml");
1918: }
1919:
1920: // tmp
1921: private XStyle setupHeaderStyle() {
1922: XStyle style = new XStyle();
1923: style.setStyle(XStyle.COLOR_BACK, Color.WHITE);
1924: return style;
1925: }
1926:
1927: // tmp
1928: private XStyle setupFooterStyle() {
1929: XStyle style = new XStyle();
1930: style.setStyle(XStyle.COLOR_BACK, Color.WHITE);
1931: return style;
1932: }
1933:
1934: private XStyle setupStyle(int foreIdx, int backIdx, int fontIdx) {
1935: XStyle style = new XStyle();
1936: Font font = fontPanel.getFont(fontIdx);
1937: style.setStyle(XStyle.FONT_FACE, font.getFamily());
1938: style.setStyle(XStyle.FONT_SIZE, font.getSize());
1939: style.setStyle(XStyle.FONT_WEIGHT, font.isBold() ? 1 : 0);
1940: style.setStyle(XStyle.FONT_ITALIC, font.isItalic() ? 1 : 0);
1941: style
1942: .setStyle(XStyle.COLOR_BACK, colourPanel
1943: .getColor(backIdx));
1944: style
1945: .setStyle(XStyle.COLOR_FORE, colourPanel
1946: .getColor(foreIdx));
1947: return style;
1948: }
1949:
1950: private JPanel setupLayoutPanel() {
1951: int panelWidth = getSize().width - 224;
1952: int startX = 189;
1953: JPanel panel = new JPanel();
1954: panel.setLayout(null);
1955:
1956: XStyleFactory componentFactory = new XStyleFactory(
1957: currentProject, "net.xoetrope.swing");
1958: BuddyHelper buddy = new BuddyHelper(
1959: (XStyleFactory) componentFactory);
1960: componentFactory.setParentComponent(panel);
1961: XImage imageControl = (XImage) componentFactory.addComponent(
1962: XPage.IMAGE, 5, 9, 179, 366,
1963: "com/xoetrope/carousel/survey/layout.jpg", null);
1964: imageControl.setBorder(BorderFactory.createEtchedBorder());
1965: componentFactory.addComponent(XPage.LABEL, 190, 10, 400, 39,
1966: "Step 1: Choose the layout for your questionaire");
1967: questionStyleCombo = (XComboBox) buddy.addComponent(
1968: XPage.COMBO, startX + 8, startX + 150, 58,
1969: panelWidth - 8, 20, "Question Style", "", null);
1970:
1971: questionStyleCombo.addItemListener(new ItemListener() {
1972: public void itemStateChanged(ItemEvent e) {
1973: if ("Kiosk".equals(questionStyleCombo
1974: .getSelectedObject()))
1975: questionsPerPageEdit.setText("1");
1976: else
1977: questionsPerPageEdit.setText("5");
1978: questionsPerPageEdit.repaint();
1979: }
1980: });
1981:
1982: int editY = 58;
1983:
1984: questionsPerPageEdit = (XEdit) buddy.addComponent(XPage.EDIT,
1985: startX + 8, startX + 150, editY += 24, 180, 20,
1986: "Questions per page", "", null);
1987: pageSizeCombo = (XComboBox) buddy.addComponent(XPage.COMBO,
1988: startX + 8, startX + 150, editY += 24, panelWidth - 8,
1989: 20, "Page size", "", null);
1990:
1991: questionStyleCombo.addItem("Normal");
1992: questionStyleCombo.addItem("Wrap around");
1993: questionStyleCombo.addItem("Kiosk");
1994: questionStyleCombo.addItem("Template");
1995: questionStyleCombo.setSelectedIndex(0);
1996:
1997: questionsPerPageEdit.setText("5");
1998:
1999: pageSizeCombo.addItem("240 x 320");
2000: pageSizeCombo.addItem("320 x 240");
2001: pageSizeCombo.addItem("640 x 480");
2002: pageSizeCombo.addItem("800 x 600");
2003: pageSizeCombo.addItem("1024 x 768");
2004: pageSizeCombo.addItem("1280 x 1024");
2005: pageSizeCombo.addItem("1400 x 1050");
2006: pageSizeCombo.setSelectedIndex(2);
2007:
2008: return panel;
2009: }
2010:
2011: private JPanel setupNavigationPanel() {
2012: int halfPanelWidth = (getSize().width - 224) / 2;
2013: int startPanel2 = (getSize().width - 224) / 2 + 16;
2014: int startX = 189;
2015: JPanel panel = new JPanel();
2016: panel.setLayout(null);
2017:
2018: XStyleFactory componentFactory = new XStyleFactory(
2019: currentProject, "net.xoetrope.swing");
2020: BuddyHelper buddy = new BuddyHelper(
2021: (XStyleFactory) componentFactory);
2022: componentFactory.setParentComponent(panel);
2023:
2024: XImage imageControl = (XImage) componentFactory.addComponent(
2025: XPage.IMAGE, 5, 9, 179, 366,
2026: "com/xoetrope/carousel/survey/navigation.jpg", null);
2027: imageControl.setBorder(BorderFactory.createEtchedBorder());
2028: componentFactory.addComponent(XPage.LABEL, 190, 10, 400, 39,
2029: "Step 4: Choose the navigation options for the survey");
2030:
2031: int posY = 14;
2032: welcomeChk = (XCheckbox) componentFactory.addComponent(
2033: XPage.CHECK, startX + 6, posY += 24, halfPanelWidth,
2034: 20, "Welcome page");
2035: welcomeEdit = (XEdit) buddy.addComponent(XPage.EDIT,
2036: startX + 26, startX + 100, posY += 24, 342, 20,
2037: "Message", "30 seconds for your opinion", null);
2038: internationalizeChk = (XCheckbox) componentFactory
2039: .addComponent(XPage.CHECK, startX + 26, posY += 24,
2040: halfPanelWidth - 20, 20, "Internationalize");
2041: int ox = 10;
2042:
2043: langChks[0] = (XCheckbox) componentFactory.addComponent(
2044: XPage.CHECK, startX + 30 + ox, posY += 24, 150, 20,
2045: languageNames[0]);
2046: langChks[0].setSelected(true);
2047: langChks[0].setEnabled(true);
2048: langChks[1] = (XCheckbox) componentFactory.addComponent(
2049: XPage.CHECK, startX + startPanel2 + ox, posY, 150, 20,
2050: languageNames[1]);
2051: langChks[1].setEnabled(true);
2052: langChks[2] = (XCheckbox) componentFactory.addComponent(
2053: XPage.CHECK, startX + 30 + ox, posY += 24, 150, 20,
2054: languageNames[2]);
2055: langChks[2].setEnabled(true);
2056: langChks[3] = (XCheckbox) componentFactory.addComponent(
2057: XPage.CHECK, startX + startPanel2 + ox, posY, 150, 20,
2058: languageNames[3]);
2059: langChks[3].setEnabled(true);
2060: langChks[4] = (XCheckbox) componentFactory.addComponent(
2061: XPage.CHECK, startX + 30 + ox, posY += 24, 150, 20,
2062: languageNames[4]);
2063: langChks[4].setEnabled(true);
2064: langChks[5] = (XCheckbox) componentFactory.addComponent(
2065: XPage.CHECK, startX + startPanel2 + ox, posY, 150, 20,
2066: languageNames[5]);
2067: langChks[5].setEnabled(true);
2068:
2069: bannerChk = (XCheckbox) componentFactory.addComponent(
2070: XPage.CHECK, startX + 6, posY += 24, halfPanelWidth,
2071: 20, "Banner", null);
2072: titleEdit = (XEdit) buddy.addComponent(XPage.EDIT, startX + 26,
2073: startX + 100, posY += 24, 344, 20, "Title",
2074: "On-line survey", null);
2075: titleCaption = (XLabel) buddy.getBuddy(titleEdit);
2076: logoChk = (XCheckbox) componentFactory.addComponent(
2077: XPage.CHECK, startX + 26, posY += 24,
2078: halfPanelWidth - 20, 20, "Logo", null);
2079: logoEdit = (XEdit) buddy.addComponent(XPage.EDIT, startX
2080: + startPanel2 - 20, startX + startPanel2 + 50, posY,
2081: halfPanelWidth - 32, 20, "Logo file", "logo.gif", null);
2082:
2083: logoBtn = (XButton) componentFactory.addComponent(XPage.BUTTON,
2084: startX + startPanel2 + halfPanelWidth - 48, posY, 20,
2085: 20, "...");
2086:
2087: navigationChk = (XCheckbox) componentFactory.addComponent(
2088: XPage.CHECK, startX + 6, posY += 24, halfPanelWidth,
2089: 20, "Navigation panel", null);
2090:
2091: homeChk = (XCheckbox) componentFactory.addComponent(
2092: XPage.CHECK, startX + 26, posY += 24,
2093: halfPanelWidth - 20, 20, "Home button", null);
2094: homeEdit = (XEdit) buddy.addComponent(XPage.EDIT, startX
2095: + startPanel2 - 20, startX + startPanel2 + 50, posY,
2096: halfPanelWidth - 32, 20, "Icon", "", null);
2097: homeBtn = (XButton) componentFactory.addComponent(XPage.BUTTON,
2098: startX + startPanel2 + halfPanelWidth - 48, posY, 20,
2099: 20, "...");
2100:
2101: forwardChk = (XCheckbox) componentFactory.addComponent(
2102: XPage.CHECK, startX + 26, posY += 24,
2103: halfPanelWidth - 20, 20, "Forward button", null);
2104: nextEdit = (XEdit) buddy.addComponent(XPage.EDIT, startX
2105: + startPanel2 - 20, startX + startPanel2 + 50, posY,
2106: halfPanelWidth - 32, 20, "Icon", "", null);
2107: forwardBtn = (XButton) componentFactory.addComponent(
2108: XPage.BUTTON, startX + startPanel2 + halfPanelWidth
2109: - 48, posY, 20, 20, "...");
2110:
2111: backChk = (XCheckbox) componentFactory.addComponent(
2112: XPage.CHECK, startX + 26, posY += 24,
2113: halfPanelWidth - 20, 20, "Back button", null);
2114: prevEdit = (XEdit) buddy.addComponent(XPage.EDIT, startX
2115: + startPanel2 - 20, startX + startPanel2 + 50, posY,
2116: halfPanelWidth - 32, 20, "Icon", "", null);
2117: backBtn = (XButton) componentFactory.addComponent(XPage.BUTTON,
2118: startX + startPanel2 + halfPanelWidth - 48, posY, 20,
2119: 20, "...");
2120:
2121: farewellChk = (XCheckbox) componentFactory.addComponent(
2122: XPage.CHECK, startX + 6, posY += 24, halfPanelWidth,
2123: 20, "Thank you page", null);
2124: restartChk = (XCheckbox) componentFactory.addComponent(
2125: XPage.CHECK, startX + 26, posY += 24,
2126: halfPanelWidth - 20, 20, "Automatice restart", null);
2127: thanksEdit = (XEdit) buddy.addComponent(XPage.EDIT, startX
2128: + startPanel2, startX + startPanel2 + 70, posY,
2129: halfPanelWidth - 8, 20, "Message",
2130: "Thanks for your time", null);
2131: messageCaption = (XLabel) buddy.getBuddy(thanksEdit);
2132:
2133: nextEdit.setText("right.gif");
2134: prevEdit.setText("left.gif");
2135: homeEdit.setText("home.gif");
2136:
2137: // setup the listeners
2138: welcomeChk.addActionListener(new ActionListener() {
2139: public void actionPerformed(ActionEvent e) {
2140: boolean state = welcomeChk.isSelected();
2141: welcomeEdit.setEnabled(state);
2142: internationalizeChk.setEnabled(state);
2143: state = state && internationalizeChk.isSelected();
2144: state = state && internationalizeChk.isSelected();
2145: for (int i = 0; i < 6; i++) {
2146: langChks[i].setEnabled(state);
2147: }
2148: }
2149: });
2150:
2151: internationalizeChk.addActionListener(new ActionListener() {
2152: public void actionPerformed(ActionEvent e) {
2153: boolean state = internationalizeChk.isSelected();
2154: for (int i = 0; i < 6; i++) {
2155: langChks[i].setEnabled(state);
2156: }
2157: }
2158: });
2159:
2160: bannerChk.addActionListener(new ActionListener() {
2161: public void actionPerformed(ActionEvent e) {
2162: boolean state = bannerChk.isSelected();
2163: logoChk.setEnabled(state);
2164: titleEdit.setEnabled(state);
2165: state = state && logoChk.isSelected();
2166: logoEdit.setEnabled(state);
2167: logoBtn.setEnabled(state);
2168: }
2169: });
2170:
2171: logoChk.addActionListener(new ActionListener() {
2172: public void actionPerformed(ActionEvent e) {
2173: boolean state = logoChk.isSelected();
2174: logoEdit.setEnabled(state);
2175: logoBtn.setEnabled(state);
2176: }
2177: });
2178:
2179: logoBtn.addActionListener(new ActionListener() {
2180: public void actionPerformed(ActionEvent e) {
2181: pickLogoFile();
2182: }
2183: });
2184:
2185: navigationChk.addActionListener(new ActionListener() {
2186: public void actionPerformed(ActionEvent e) {
2187: boolean state = navigationChk.isSelected();
2188: homeChk.setEnabled(state);
2189: forwardChk.setEnabled(state);
2190: backChk.setEnabled(state);
2191:
2192: boolean home = state && homeChk.isSelected();
2193: homeEdit.setEnabled(home);
2194: homeBtn.setEnabled(home);
2195:
2196: boolean forward = state && forwardChk.isSelected();
2197: nextEdit.setEnabled(forward);
2198: forwardBtn.setEnabled(forward);
2199:
2200: boolean back = state && backChk.isSelected();
2201: prevEdit.setEnabled(back);
2202: backBtn.setEnabled(back);
2203: }
2204: });
2205:
2206: homeChk.addActionListener(new ActionListener() {
2207: public void actionPerformed(ActionEvent e) {
2208: boolean state = homeChk.isSelected();
2209: homeEdit.setEnabled(state);
2210: homeBtn.setEnabled(state);
2211: }
2212: });
2213:
2214: forwardChk.addActionListener(new ActionListener() {
2215: public void actionPerformed(ActionEvent e) {
2216: forwardChk.setSelected(true);
2217: nextEdit.setEnabled(true);
2218: forwardBtn.setEnabled(true);
2219: }
2220: });
2221:
2222: backChk.addActionListener(new ActionListener() {
2223: public void actionPerformed(ActionEvent e) {
2224: boolean state = backChk.isSelected();
2225: prevEdit.setEnabled(state);
2226: backBtn.setEnabled(state);
2227: }
2228: });
2229:
2230: farewellChk.addActionListener(new ActionListener() {
2231: public void actionPerformed(ActionEvent e) {
2232: boolean state = farewellChk.isSelected();
2233: thanksEdit.setEnabled(state);
2234: restartChk.setEnabled(state);
2235: }
2236: });
2237:
2238: backBtn.addActionListener(new ActionListener() {
2239: public void actionPerformed(ActionEvent e) {
2240: pickBackIcon();
2241: }
2242: });
2243:
2244: forwardBtn.addActionListener(new ActionListener() {
2245: public void actionPerformed(ActionEvent e) {
2246: pickForwardIcon();
2247: }
2248: });
2249:
2250: homeBtn.addActionListener(new ActionListener() {
2251: public void actionPerformed(ActionEvent e) {
2252: pickHomeIcon();
2253: }
2254: });
2255:
2256: setOpaque(panel, false);
2257:
2258: internationalizeChk.setHorizontalAlignment(JButton.LEADING);
2259:
2260: welcomeChk.setHorizontalAlignment(JButton.LEADING);
2261: farewellChk.setHorizontalAlignment(JButton.LEADING);
2262: restartChk.setHorizontalAlignment(JButton.LEADING);
2263: forwardChk.setHorizontalAlignment(JButton.LEADING);
2264: backChk.setHorizontalAlignment(JButton.LEADING);
2265: homeChk.setHorizontalAlignment(JButton.LEADING);
2266:
2267: welcomeChk.setSelected(true);
2268: internationalizeChk.setSelected(true);
2269: bannerChk.setSelected(true);
2270: logoChk.setSelected(true);
2271:
2272: navigationChk.setSelected(true);
2273: homeChk.setSelected(true);
2274: forwardChk.setSelected(true);
2275: backChk.setSelected(true);
2276:
2277: farewellChk.setSelected(true);
2278:
2279: panel.doLayout();
2280: return panel;
2281: }
2282:
2283: private XColourPanel setupColourPanel() {
2284: return new XColourPanel(currentProject, colours, fonts,
2285: "Colours", "2");
2286: }
2287:
2288: private XFontPanel setupFontPanel() {
2289: return new XFontPanel(currentProject, colours, fonts, "Fonts",
2290: "3");
2291: }
2292:
2293: private JPanel setupOutputPanel() {
2294: int startX = 189;
2295: int panelWidth = getSize().width - 224;
2296: int halfPanelWidth = (getSize().width - 224) / 2;
2297: int startPanel2 = (getSize().width - 224) / 2 + 16;
2298: JPanel panel = new JPanel();
2299: panel.setLayout(null);
2300: XStyleFactory componentFactory = new XStyleFactory(
2301: currentProject, "net.xoetrope.swing");
2302: BuddyHelper buddy = new BuddyHelper(
2303: (XStyleFactory) componentFactory);
2304: componentFactory.setParentComponent(panel);
2305:
2306: XImage imageControl = (XImage) componentFactory.addComponent(
2307: XPage.IMAGE, 5, 9, 179, 366,
2308: "com/xoetrope/carousel/survey/output.jpg", null);
2309: imageControl.setBorder(BorderFactory.createEtchedBorder());
2310: componentFactory.addComponent(XPage.LABEL, 190, 10, 400, 39,
2311: "Step 6: Choose where to save the captured data");
2312: int posY = 34;
2313:
2314: dbOutputRb = (XRadioButton) componentFactory.addComponent(
2315: XPage.RADIO, startX + 8, posY += 24, panelWidth - 26,
2316: 20, "Save responses to a database");
2317:
2318: dbOutputDriver = (XComboBox) buddy.addComponent(XPage.COMBO,
2319: startX + 26, startX + 150, posY += 24, panelWidth - 26,
2320: 20, "Driver", "", null);
2321: dbOutputDriver.setEditable(true);
2322: dbOutputDriver.setModel(new DefaultComboBoxModel(dbDrivers));
2323:
2324: dbOutputUrl = (XComboBox) buddy.addComponent(XPage.COMBO,
2325: startX + 26, startX + 150, posY += 24, panelWidth - 26,
2326: 20, "URL", "", null);
2327: dbOutputUrl.setEditable(true);
2328: dbOutputUrl.setModel(new DefaultComboBoxModel(dbUrls));
2329:
2330: dbOutputUser = (XEdit) buddy.addComponent(XPage.EDIT,
2331: startX + 26, startX + 150, posY += 24, panelWidth - 26,
2332: 20, "Username", "", null);
2333: dbOutputUser.setText(defaultDbUser);
2334: dbOutputPassword = (XPassword) buddy.addComponent(
2335: XPage.PASSWORD, startX + 26, startX + 150, posY += 24,
2336: panelWidth - 26, 20, "Password", "", null);
2337:
2338: fileOutputRb = (XRadioButton) componentFactory.addComponent(
2339: XPage.RADIO, startX + 8, posY += 24, panelWidth - 26,
2340: 20, "Save responses to a file");
2341: fileOutputRb.setRadioButtonGroup(dbOutputRb.createGroup());
2342:
2343: fileOutputName = (XEdit) buddy.addComponent(XPage.EDIT,
2344: startX + 26, startX + 150, posY += 24, panelWidth - 60,
2345: 20, "Output file", "", null);
2346: fileOutputName.setText("responses.xml");
2347: fileOutputBtn = (XButton) componentFactory.addComponent(
2348: XPage.BUTTON, startX + panelWidth - 28, posY, 28, 20,
2349: "...");
2350:
2351: ActionListener rbSelListener = (new ActionListener() {
2352: public void actionPerformed(ActionEvent e) {
2353: boolean sel = fileOutputRb.isSelected();
2354: dbOutputDriver.setEnabled(!sel);
2355: dbOutputUrl.setEnabled(!sel);
2356: dbOutputUser.setEnabled(!sel);
2357: dbOutputPassword.setEnabled(!sel);
2358: fileOutputName.setEnabled(sel);
2359: fileOutputBtn.setEnabled(sel);
2360: }
2361: });
2362:
2363: dbOutputRb.addActionListener(rbSelListener);
2364: fileOutputRb.addActionListener(rbSelListener);
2365: fileOutputRb.setSelected(true);
2366: dbOutputDriver.setEnabled(false);
2367: dbOutputUrl.setEnabled(false);
2368: dbOutputUser.setEnabled(false);
2369: dbOutputPassword.setEnabled(false);
2370:
2371: fileOutputBtn.addActionListener(new ActionListener() {
2372: public void actionPerformed(ActionEvent e) {
2373: pickOutputFile();
2374: }
2375: });
2376:
2377: return panel;
2378: }
2379:
2380: private JPanel setupDataPanel() {
2381: int startX = 189;
2382: int panelWidth = getSize().width - 224;
2383: int halfPanelWidth = (getSize().width - 32) / 2;
2384: int startPanel2 = (getSize().width - 32) / 2 + 16;
2385: JPanel panel = new JPanel();
2386: panel.setLayout(null);
2387: XStyleFactory componentFactory = new XStyleFactory(
2388: currentProject, "net.xoetrope.swing");
2389: BuddyHelper buddy = new BuddyHelper(
2390: (XStyleFactory) componentFactory);
2391: componentFactory.setParentComponent(panel);
2392:
2393: XImage imageControl = (XImage) componentFactory.addComponent(
2394: XPage.IMAGE, 5, 9, 179, 366,
2395: "com/xoetrope/carousel/survey/disks.jpg", null);
2396: imageControl.setBorder(BorderFactory.createEtchedBorder());
2397: componentFactory.addComponent(XPage.LABEL, 190, 10, 400, 39,
2398: "Step 5: Connect the application to a questionaire");
2399:
2400: int posY = 34;
2401: surveyNameEdit = (XEdit) buddy.addComponent(XPage.EDIT,
2402: startX + 26, startX + 150, posY += 24, panelWidth - 26,
2403: 20, "Survey name", "", null);
2404: surveyNameEdit.setText("SampleSurvey"); // default survey name
2405: dbInputRb = (XRadioButton) componentFactory.addComponent(
2406: XPage.RADIO, startX + 8, posY += 24, panelWidth - 26,
2407: 20, "Get questions from a database");
2408:
2409: dbInputDriver = (XComboBox) buddy.addComponent(XPage.COMBO,
2410: startX + 26, startX + 150, posY += 24, panelWidth - 26,
2411: 20, "Database driver", "", null);
2412: dbInputDriver.setEditable(true);
2413: dbInputDriver.setModel(new DefaultComboBoxModel(dbDrivers));
2414:
2415: dbInputUrl = (XComboBox) buddy.addComponent(XPage.COMBO,
2416: startX + 26, startX + 150, posY += 24, panelWidth - 26,
2417: 20, "Database url", "", null);
2418: dbInputUrl.setEditable(true);
2419: dbInputUrl.setModel(new DefaultComboBoxModel(dbUrls));
2420:
2421: dbInputUser = (XEdit) buddy.addComponent(XPage.EDIT,
2422: startX + 26, startX + 150, posY += 24, panelWidth - 26,
2423: 20, "Database user", "", null);
2424: dbInputUser.setText(defaultDbUser);
2425: dbInputPassword = (XPassword) buddy.addComponent(
2426: XPage.PASSWORD, startX + 26, startX + 150, posY += 24,
2427: panelWidth - 26, 20, "Database password", "", null);
2428: Object rbg = dbInputRb.createGroup();
2429:
2430: posY = 184;
2431: fileInputRb = (XRadioButton) componentFactory.addComponent(
2432: XPage.RADIO, startX + 8, posY += 24, panelWidth, 20,
2433: "Get questions from a file");
2434: ((XRadioButtonGroup) fileInputRb).setRadioButtonGroup(rbg);
2435:
2436: ActionListener rbSelListener = new ActionListener() {
2437: public void actionPerformed(ActionEvent e) {
2438: boolean sel = fileInputRb.isSelected();
2439: dbInputDriver.setEnabled(!sel);
2440: dbInputUrl.setEnabled(!sel);
2441: dbInputUser.setEnabled(!sel);
2442: dbInputPassword.setEnabled(!sel);
2443: }
2444: };
2445: dbInputRb.addActionListener(rbSelListener);
2446: fileInputRb.addActionListener(rbSelListener);
2447:
2448: fileInputRb.setSelected(true);
2449: dbInputDriver.setEnabled(false);
2450: dbInputUrl.setEnabled(false);
2451: dbInputUser.setEnabled(false);
2452: dbInputPassword.setEnabled(false);
2453:
2454: setOpaque(panel, false);
2455: return panel;
2456: }
2457:
2458: protected Image copyImage(String fileName) {
2459: String sourceFile = fileName;
2460: if (sourceFile.indexOf(":") < 0)
2461: sourceFile = "com/xoetrope/carousel/survey/" + fileName;
2462: copyFile(sourceFile);
2463: Image copiedImage = currentProject.getImage(currentProject
2464: .getPath()
2465: + "/resources/" + fileName);
2466: if (copiedImage == null)
2467: return null;
2468:
2469: try {
2470: int sleepCount = 0;
2471: while ((sleepCount < 10)
2472: && (copiedImage.getWidth(null) < 0)) {
2473: Thread.currentThread().sleep(100);
2474: sleepCount++;
2475: }
2476: } catch (InterruptedException ex) {
2477: ex.printStackTrace();
2478: }
2479: return copiedImage;
2480: }
2481:
2482: protected void copyFile(String fileName) {
2483: String sourceFile = fileName;
2484: if (sourceFile.indexOf("/") < 0)
2485: sourceFile = "com/xoetrope/carousel/survey/" + fileName;
2486: else
2487: fileName = fileName
2488: .substring(fileName.lastIndexOf('/') + 1);
2489: XEditorUtilities.copyFile(currentProject, getClass(),
2490: sourceFile, currentProject.getPath() + "/resources/"
2491: + fileName, false);
2492: }
2493:
2494: /**
2495: * Make selected children of the panel opaque
2496: * @param cont the container
2497: * @param state the opaque state
2498: */
2499: protected void setOpaque(JComponent cont, boolean state) {
2500: int numChildren = cont.getComponentCount();
2501: for (int i = 0; i < numChildren; i++) {
2502: Component comp = cont.getComponent(i);
2503: try {
2504: if (comp instanceof XCheckbox)
2505: ((XCheckbox) comp).setOpaque(state);
2506: else if (comp instanceof XRadioButton)
2507: ((XRadioButton) comp).setOpaque(state);
2508: else
2509: setOpaque(((JComponent) comp), state);
2510: } catch (Exception ex) {
2511: }
2512: }
2513: }
2514:
2515: }
|