0001: package com.xoetrope.carousel.catalog;
0002:
0003: import com.xoetrope.carousel.build.BuildProperties;
0004: import com.xoetrope.carousel.wizard.XColourPanel;
0005: import com.xoetrope.carousel.wizard.XFontPanel;
0006: import com.xoetrope.carousel.wizard.XWizardPanel;
0007: import com.xoetrope.template.XTemplateEngine;
0008: import java.io.DataInputStream;
0009: import java.io.File;
0010: import java.io.FileInputStream;
0011: import java.io.FileNotFoundException;
0012: import java.io.FileOutputStream;
0013: import java.io.FileReader;
0014: import java.io.IOException;
0015: import java.io.InputStream;
0016: import java.io.OutputStream;
0017: import java.net.MalformedURLException;
0018: import java.net.URL;
0019: import java.sql.Connection;
0020: import java.sql.Statement;
0021: import java.util.HashMap;
0022: import java.util.Properties;
0023: import java.util.Vector;
0024:
0025: import java.awt.BorderLayout;
0026: import java.awt.Color;
0027: import java.awt.Component;
0028: import java.awt.Dimension;
0029: import java.awt.Font;
0030: import java.awt.Rectangle;
0031: import java.awt.SystemColor;
0032: import java.awt.event.ActionEvent;
0033: import java.awt.event.ActionListener;
0034: import java.awt.event.ComponentEvent;
0035: import javax.swing.BorderFactory;
0036: import javax.swing.ImageIcon;
0037: import javax.swing.JComponent;
0038: import javax.swing.JDialog;
0039: import javax.swing.JPanel;
0040: import javax.swing.JProgressBar;
0041: import javax.swing.JTabbedPane;
0042: import javax.swing.event.ChangeEvent;
0043: import javax.swing.event.ChangeListener;
0044: import net.xoetrope.swing.XButton;
0045: import net.xoetrope.swing.XPanel;
0046: import net.xoetrope.xml.XmlElement;
0047: import net.xoetrope.xml.XmlSource;
0048: import net.xoetrope.xml.jaxp.JaxpXmlWriter;
0049: import net.xoetrope.xui.PageSupport;
0050: import net.xoetrope.xui.XComponentFactory;
0051: import net.xoetrope.xui.XPage;
0052: import net.xoetrope.xui.XProject;
0053: import net.xoetrope.xui.style.XStyleFactory;
0054: import java.awt.Image;
0055: import net.xoetrope.swing.XImage;
0056: import net.xoetrope.swing.XLabel;
0057: import net.xoetrope.xui.style.XStyle;
0058: import javax.swing.JOptionPane;
0059: import java.awt.Cursor;
0060: import net.xoetrope.deprecated.xui.XResourceManager;
0061: import net.xoetrope.editor.XEditorUtilities;
0062: import net.xoetrope.editor.project.XEditorProject;
0063: import net.xoetrope.editor.project.XEditorProjectManager;
0064: import net.xoetrope.editor.project.pages.XPageResource;
0065: import net.xoetrope.editor.project.style.XEditorStyleFactory;
0066: import net.xoetrope.editor.project.style.XEditorStyleManager;
0067: import net.xoetrope.xui.helper.SwingWorker;
0068:
0069: import net.xoetrope.editor.project.pages.IEditorUtility;
0070:
0071: /**
0072: * A wizard to generate a product catalogue application
0073: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
0074: * the GNU Public License (GPL), please see license.txt for more details. If
0075: * you make commercial use of this software you must purchase a commercial
0076: * license from Xoetrope.</p>
0077: * <p> $Revision: 1.12 $</p>
0078: */
0079: public class XCatalogueWizardDialog extends JDialog implements
0080: ActionListener {
0081: private BorderLayout borderLayout1 = new BorderLayout();
0082:
0083: private XButton cancelBtn, backBtn, nextBtn;
0084:
0085: private XColourPanel colourPanel;
0086: private Databases databasesPanel;
0087: private Facilities facilitiesPanel;
0088: private XFontPanel fontPanel;
0089: private Navigation navigationPanel;
0090: private Orders ordersPanel;
0091: private Products productsPanel;
0092: private Styles stylesPanel;
0093: private Welcome welcomePanel;
0094: private JPanel mainPanel = new JPanel();
0095: private JTabbedPane tabPane = new JTabbedPane();
0096: private JPanel dialogControlPanel = new JPanel();
0097:
0098: private boolean isStandalone = false;
0099:
0100: private Vector catFonts;
0101: private Vector catColors;
0102: private Vector graphicsFiles;
0103:
0104: private int headlineColour = 0;
0105: private int subHeadingColour = 0;
0106: private int bodyTextColour = 0;
0107: private int captionColour = 0;
0108: private int codeColour = 0;
0109: private int btnTextColour = 0;
0110: private int btnFaceColour = 0;
0111: private int backgroundColour = 0;
0112: private int lineColour = 0;
0113: private int placeholderColour = 0;
0114:
0115: private int headlineFont = 0;
0116: private int subHeadingFont = 0;
0117: private int bodyTextFont = 0;
0118: private int captionFont = 0;
0119: private int codeFont = 0;
0120:
0121: private Dimension formSize = new Dimension(1024, 768);
0122: private int buttonW = 80;
0123: private int buttonH = 30;
0124: private JProgressBar buildProgress = new JProgressBar();
0125: private int progressLevel = 0;
0126: private XEditorProject currentProject;
0127:
0128: private String[] nextLocations = { "NxtTopLeft", "NxtTopRight",
0129: "NxtBottomLeft", "NxtBottomRight" };
0130: private String[] backLocations = { "BackTopLeft", "BackTopRight",
0131: "BackBottomLeft", "BackBottomRight" };
0132: private String[] aboutLocations = { "AbtTopLeft", "AbtTopRight",
0133: "AbtBottomLeft", "AbtBottomRight" };
0134: private String[] homeLocations = { "HomeTopLeft", "HomeTopRight",
0135: "HomeBottomLeft", "HomeBottomRight" };
0136: private String[] closeLocations = { "CloseTopLeft",
0137: "CloseTopRight", "CloseBottomLeft", "CloseBottomRight" };
0138:
0139: private String xuiProPath;
0140:
0141: /**
0142: * Constructor, which takes an <CODE>XEditorProject</CODE> instance
0143: * @param project the passed <CODE>XEditorProject</CODE> instance
0144: */
0145: public XCatalogueWizardDialog(XEditorProject project) {
0146: super ((java.awt.Frame) null, "Catalogue Wizard", true);
0147: currentProject = project;
0148: isStandalone = true;
0149:
0150: File file = new File(
0151: "src/com/xoetrope/carousel/catalog/templates");
0152: xuiProPath = file.getAbsolutePath();
0153:
0154: try {
0155: jbInit();
0156: pack();
0157: } catch (Exception ex) {
0158: if (BuildProperties.DEBUG)
0159: ex.printStackTrace();
0160: }
0161: }
0162:
0163: /**
0164: * Method used to initialise the components use in the wizard.
0165: */
0166: void jbInit() throws Exception {
0167: catFonts = new Vector();
0168: mainPanel
0169: .addComponentListener(new java.awt.event.ComponentAdapter() {
0170: public void componentShown(ComponentEvent e) {
0171: ; //mainPanel_componentShown(e);
0172: }
0173: });
0174: buildProgress.setToolTipText("Wizard progress");
0175: buildProgress.setBorder(BorderFactory.createEtchedBorder());
0176: buildProgress.setMaximum(30);
0177: buildProgress.setStringPainted(true);
0178: buildProgress.setVisible(false);
0179:
0180: catFonts.add(new java.awt.Font("SansSerif", 1, 16));
0181: catFonts.add(new java.awt.Font("SansSerif", 1, 10));
0182: catFonts.add(new java.awt.Font("SansSerif", 0, 10));
0183: catFonts.add(new java.awt.Font("SansSerif", 2, 10));
0184: catFonts.add(new java.awt.Font("Monospaced", 0, 10));
0185:
0186: catColors = new Vector();
0187: catColors.add(SystemColor.controlText);
0188: catColors.add(SystemColor.controlText);
0189: catColors.add(SystemColor.controlText);
0190: catColors.add(SystemColor.controlText);
0191: catColors.add(SystemColor.controlText);
0192: catColors.add(SystemColor.controlText);
0193: catColors.add(SystemColor.control);
0194: catColors.add(SystemColor.control);
0195: catColors.add(Color.red);
0196: catColors.add(Color.gray);
0197:
0198: graphicsFiles = new Vector();
0199:
0200: Font font = new java.awt.Font("SansSerif", 0, 11);
0201: mainPanel.setLayout(borderLayout1);
0202: colourPanel = new XColourPanel(currentProject, catColors,
0203: catFonts, "Colours", "8");
0204: databasesPanel = new Databases(this , currentProject,
0205: "Databases");
0206: facilitiesPanel = new Facilities(this , "Facilities");
0207: fontPanel = new XFontPanel(currentProject, catColors, catFonts,
0208: "Fonts", "7");
0209: navigationPanel = new Navigation(this , "Navigation");
0210: ordersPanel = new Orders(this , "Orders");
0211: productsPanel = new Products(this , "Products");
0212: stylesPanel = new Styles(this , "Styles");
0213: welcomePanel = new Welcome(this , "Welcome");
0214:
0215: tabPane.setPreferredSize(new Dimension(610, 410));
0216:
0217: colourPanel.useColorScheme(0);
0218:
0219: dialogControlPanel.setLayout(null);
0220: XStyleFactory componentFactory = new XStyleFactory(
0221: XEditorProjectManager.getCurrentProject(),
0222: "net.xoetrope.swing");
0223: componentFactory.setParentComponent(dialogControlPanel);
0224:
0225: dialogControlPanel.setMinimumSize(new Dimension(391, 36));
0226: dialogControlPanel.setPreferredSize(new Dimension(391, 36));
0227:
0228: cancelBtn = (XButton) componentFactory.addComponent("Button",
0229: 280, 5, 100, 25, "Cancel");
0230: backBtn = (XButton) componentFactory.addComponent("Button",
0231: 385, 5, 100, 25, "Back");
0232: nextBtn = (XButton) componentFactory.addComponent("Button",
0233: 490, 5, 100, 25, "Next");
0234:
0235: cancelBtn.setFocusable(false);
0236: backBtn.setFocusable(false);
0237: nextBtn.setFocusable(false);
0238:
0239: cancelBtn.setMnemonic('C');
0240: ImageIcon img = new ImageIcon(
0241: ((XEditorProject) (XEditorProjectManager
0242: .getCurrentProject())).getImage(getClass(),
0243: "com/xoetrope/carousel/resources/stop.gif"),
0244: "Cancel");
0245: cancelBtn.setIcon(img);
0246:
0247: backBtn.setMnemonic('B');
0248: img = new ImageIcon(((XEditorProject) (XEditorProjectManager
0249: .getCurrentProject()))
0250: .getImage("com/xoetrope/carousel/resources/back.gif"),
0251: "Back");
0252: backBtn.setIcon(img);
0253: backBtn.setEnabled(false);
0254:
0255: nextBtn.setMnemonic('N');
0256: img = new ImageIcon(((XEditorProject) (XEditorProjectManager
0257: .getCurrentProject())).getImage(getClass(),
0258: "com/xoetrope/carousel/resources/forward.gif"), "Next");
0259: nextBtn.setIcon(img);
0260: nextBtn.setDefaultCapable(true);
0261: getRootPane().setDefaultButton(nextBtn);
0262:
0263: buildProgress.setBounds(3, 5, 259, 27);
0264: dialogControlPanel.add(buildProgress);
0265: mainPanel.add(dialogControlPanel, BorderLayout.SOUTH);
0266:
0267: cancelBtn.setFont(font);
0268: backBtn.setFont(font);
0269: nextBtn.setFont(font);
0270:
0271: cancelBtn.addActionListener(this );
0272: backBtn.addActionListener(this );
0273: nextBtn.addActionListener(this );
0274:
0275: tabPane.setFocusable(false);
0276: tabPane.add(welcomePanel, "Welcome");
0277: tabPane.add(facilitiesPanel, "Facilities");
0278: tabPane.add(productsPanel, "Products");
0279: tabPane.add(ordersPanel, "Orders");
0280: tabPane.add(navigationPanel, "Navigation");
0281: tabPane.add(stylesPanel, "Styles");
0282: // tabPane.add( fontPanel, "Fonts" );
0283: // tabPane.add( colourPanel, "Colours" );
0284: tabPane.add(databasesPanel, "Databases");
0285: // tabPane.add( locationPanel, "Location" );
0286: tabPane.setFont(font);
0287:
0288: tabPane.addChangeListener(new ChangeListener() {
0289: public void stateChanged(ChangeEvent evt) {
0290: int tabIdx = tabPane.getSelectedIndex();
0291: if (tabIdx == (tabPane.getTabCount() - 1)) {
0292: nextBtn.setText("Finish");
0293: backBtn.setEnabled(true);
0294: } else {
0295: nextBtn.setText("Next");
0296: backBtn.setEnabled(tabIdx != 0);
0297: }
0298:
0299: if (tabIdx == 2) {
0300: productsPanel.enableSampleSelect(facilitiesPanel
0301: .wantsProductsPanel());
0302: }
0303: }
0304: });
0305:
0306: mainPanel.add(tabPane, BorderLayout.CENTER);
0307: getContentPane().add(mainPanel);
0308: }
0309:
0310: /**
0311: * Action listener which listens for events on the cancel, next, back and finish button of the wizard.
0312: * @param evt the passed <CODE>ActionEvent</CODE> instance
0313: */
0314: public void actionPerformed(ActionEvent evt) {
0315: if (evt.getActionCommand().compareTo("Cancel") == 0)
0316: dispose();
0317: else if (evt.getActionCommand().compareTo("Next") == 0)
0318: tabPane.setSelectedIndex(tabPane.getSelectedIndex() + 1);
0319: else if (evt.getActionCommand().compareTo("Back") == 0)
0320: tabPane.setSelectedIndex(tabPane.getSelectedIndex() - 1);
0321: else if (evt.getActionCommand().compareTo("Finish") == 0) {
0322: buildNewCatalogue();
0323: dispose();
0324: }
0325: }
0326:
0327: /**
0328: * Called after completion of the catalogue wizard to build the generated catalogue
0329: */
0330: public void buildNewCatalogue() {
0331: buildProgress.setVisible(true);
0332:
0333: processWelcomeTemplate();
0334: processProductsTemplate();
0335: processCheckoutTemplate();
0336: setStyleInfo();
0337: setDataBaseInfo();
0338:
0339: dialogControlPanel.doLayout();
0340: dialogControlPanel.paintImmediately(0, 0, 2350, 2225);
0341: }
0342:
0343: /**
0344: * Responsible for setting up and processing the Welcome page template.
0345: */
0346: public void processWelcomeTemplate() {
0347: String projectPath = currentProject
0348: .getStartupParam("ProjectPath");
0349: String s = xuiProPath + "/pages";
0350: String t = projectPath + "/pages";
0351: XCustomXmlTemplateEngine te = new XCustomXmlTemplateEngine(
0352: currentProject, s, t);
0353: String[] r = { "Welcome.xml" };
0354:
0355: s = xuiProPath + "/javaclasses";
0356: t = projectPath + "/src/com/xoetrope/myproject";
0357: XCustomJavaTemplateEngine jte = new XCustomJavaTemplateEngine(
0358: currentProject, s, t);
0359: jte.setPackageName("com.xoetrope.myproject");
0360: String[] r1 = { "Welcome.java" };
0361:
0362: if (welcomePanel.getSubTitleText() != null) {
0363: te.addContent("SubTitle", welcomePanel.getSubTitleText());
0364: }
0365:
0366: if (welcomePanel.usesLogo()) {
0367: te.addInclude("Logo", true);
0368: }
0369:
0370: if (welcomePanel.usesGreetingText()) {
0371: te
0372: .addContent("WelcomeText", welcomePanel
0373: .getGreetingText());
0374: }
0375:
0376: if (welcomePanel.usesPortfolioImage()) {
0377: copyFile("templates/images/"
0378: + welcomePanel.getPortfolioImageFile(),
0379: currentProject.getPath()
0380: + "/resources/portfolio.png");
0381: }
0382:
0383: if (navigationPanel.useAbout()) {
0384: jte.addInclude("ABOUT", true);
0385: te.addInclude(aboutLocations[navigationPanel
0386: .getButtonLocation()], true);
0387: te.addInclude(aboutLocations[navigationPanel
0388: .getButtonLocation()].substring(0, 3), true);
0389: }
0390:
0391: if (navigationPanel.useForwardBackward()) {
0392: jte.addInclude("NEXT", true);
0393: te.addInclude(nextLocations[navigationPanel
0394: .getButtonLocation()], true);
0395: te.addInclude(nextLocations[navigationPanel
0396: .getButtonLocation()].substring(0, 3), true);
0397: }
0398:
0399: if (navigationPanel.usesStatusBar()) {
0400: te.addInclude("Status", true);
0401: }
0402:
0403: if (!navigationPanel.useHints()) {
0404: te.addContent("ToolTip", "");
0405: }
0406:
0407: if (welcomePanel.usesBackground()) {
0408: te.addInclude("Background", true);
0409: copyFile("templates/images/"
0410: + welcomePanel.getBackgroundFile(), currentProject
0411: .getPath()
0412: + "/resources/background.jpg");
0413: } else {
0414: deleteFile(currentProject.getPath()
0415: + "/resources/background.jpg");
0416: }
0417:
0418: if (welcomePanel.usesLogo()) {
0419: copyFile("templates/images/"
0420: + welcomePanel.getLogoImageFile(), currentProject
0421: .getPath()
0422: + "/resources/clogo.gif");
0423: te.addInclude("Logo", true);
0424: } else {
0425: deleteFile(currentProject.getPath() + "/resources/logo.gif");
0426: }
0427:
0428: IEditorUtility editor = currentProject.getEditorUtility();
0429: if (welcomePanel.usesSplashImage()) {
0430: copyFile("templates/images/"
0431: + welcomePanel.getSplashImageFile(), currentProject
0432: .getPath()
0433: + "/resources/splash.gif");
0434: //editor.setMainClass( (XEditorProject)currentProject, "net.xoetrope.swing.splash.XSplashWindow" );
0435: } else {
0436: //editor.setMainClass( (XEditorProject)currentProject, "net.xoetrope.swing.XApplet" );
0437: deleteFile(currentProject.getPath()
0438: + "/resources/splash.gif");
0439: }
0440:
0441: if (welcomePanel.usesGreetingText()
0442: && welcomePanel.getGreetingText() != "") {
0443: String text = welcomePanel.getGreetingText();
0444: }
0445:
0446: String style = stylesPanel.getStyle();
0447: if (style != null)
0448: te.addContent("CatalogStyle", style);
0449:
0450: te.process(r);
0451: jte.process(r1);
0452: }
0453:
0454: /**
0455: * Responsible for setting up and processing the Products page template.
0456: */
0457: private void processProductsTemplate() {
0458: String projectPath = currentProject
0459: .getStartupParam("ProjectPath");
0460: String source;
0461:
0462: addProperty("Title", welcomePanel.getTitleText());
0463:
0464: // Set the template to be used.
0465: if (facilitiesPanel.wantsLayout2()) {
0466: source = "/layout2";
0467: } else {
0468: source = "/layout1";
0469: }
0470:
0471: String s = xuiProPath + source;
0472: String t = projectPath + "/pages";
0473: String target = projectPath + "/pages";
0474: XCustomXmlTemplateEngine te = new XCustomXmlTemplateEngine(
0475: currentProject, s, t);
0476: String[] resources = { "Products.xml" };
0477:
0478: s = xuiProPath + "/javaclasses";
0479: t = projectPath + "/src/com/xoetrope/myproject";
0480: XCustomJavaTemplateEngine jte1 = new XCustomJavaTemplateEngine(
0481: currentProject, s, t);
0482: jte1.setPackageName("com.xoetrope.myproject");
0483: jte1
0484: .setImportName1("com.xoetrope.myproject.XGraphicListCellRenderer");
0485: String[] r1 = { "Products.java" };
0486:
0487: XCustomJavaTemplateEngine jte2 = new XCustomJavaTemplateEngine(
0488: currentProject, s, t);
0489: jte2.setPackageName("com.xoetrope.myproject");
0490: String[] r2 = { "XGraphicListCellRenderer.java" };
0491:
0492: String dataSource = xuiProPath + "/files";
0493: String dataTarget = projectPath + "/resources";
0494: XCustomXmlTemplateEngine data = new XCustomXmlTemplateEngine(
0495: currentProject, dataSource, dataTarget);
0496: String[] r3 = { "staticdata.xml" };
0497:
0498: if (facilitiesPanel.wantsProductsPanel()) {
0499: te.addInclude("ProductsPanel", true);
0500: jte1.addInclude("PRODUCTS", true);
0501: }
0502:
0503: if (facilitiesPanel.wantsDetailsPanel()) {
0504: te.addInclude("DetailsPanel", true);
0505: jte1.addInclude("DESCRIP", true);
0506: }
0507:
0508: if (welcomePanel.usesBackground()) {
0509: te.addInclude("Background", true);
0510: copyFile("templates/images/"
0511: + welcomePanel.getBackgroundFile(), currentProject
0512: .getPath()
0513: + "/resources/background.jpg");
0514: } else {
0515: deleteFile(currentProject.getPath()
0516: + "/resources/background.jpg");
0517: }
0518:
0519: if (welcomePanel.usesSplashImage()) {
0520: copyFile("templates/images/"
0521: + welcomePanel.getSplashImageFile(), currentProject
0522: .getPath()
0523: + "/resources/splash.gif");
0524: // EditorUtility editor = new EditorUtility();
0525: // editor.setMainClass( (XEditorProject)currentProject, "net.xoetrope.swing.splash.XSplashWindow" );
0526: } else {
0527: // EditorUtility editor = new EditorUtility();
0528: // editor.setMainClass( (XEditorProject)currentProject, "net.xoetrope.swing.XApplet" );
0529: deleteFile(currentProject.getPath()
0530: + "/resources/splash.gif");
0531: }
0532:
0533: if (welcomePanel.usesGreetingText()
0534: && welcomePanel.getGreetingText() != "") {
0535: String text = welcomePanel.getGreetingText();
0536: }
0537:
0538: if (facilitiesPanel.wantsProductsPanel()) {
0539: te.addInclude("ProductsPanel", true);
0540: }
0541: if (facilitiesPanel.wantsDetailsPanel()) {
0542: te.addInclude("DetailsPanel", true);
0543: }
0544: if (facilitiesPanel.wantsCartPanel()) {
0545: te.addInclude("CartPanel", true);
0546: jte1.addInclude("CART", true);
0547: }
0548:
0549: if (facilitiesPanel.wantsTreeView()) {
0550: te.addInclude("TreeView", true);
0551: } else if (facilitiesPanel.wantsSimpleView()) {
0552: te.addInclude("SimpleView", true);
0553: }
0554:
0555: if (navigationPanel.useForwardBackward()) {
0556: te.addInclude(backLocations[navigationPanel
0557: .getButtonLocation()], true);
0558: te.addInclude(backLocations[navigationPanel
0559: .getButtonLocation()].substring(0, 3), true);
0560: te.addInclude(nextLocations[navigationPanel
0561: .getButtonLocation()], true);
0562: te.addInclude(nextLocations[navigationPanel
0563: .getButtonLocation()].substring(0, 3), true);
0564: jte1.addInclude("PREVIOUS", true);
0565: jte1.addInclude("NEXT", true);
0566: }
0567:
0568: if (navigationPanel.useHome()) {
0569: te.addInclude(homeLocations[navigationPanel
0570: .getButtonLocation()], true);
0571: te.addInclude(homeLocations[navigationPanel
0572: .getButtonLocation()].substring(0, 3), true);
0573: jte1.addInclude("HOME", true);
0574: }
0575:
0576: if (navigationPanel.usesStatusBar()) {
0577: te.addInclude("Status", true);
0578: }
0579:
0580: if (!navigationPanel.useHints()) {
0581: te.addContent("ToolTip", "");
0582: }
0583:
0584: if (navigationPanel.usesStatusBar()) {
0585: te.addInclude("Status", true);
0586: }
0587:
0588: if (navigationPanel.useAbout()) {
0589: te.addInclude(aboutLocations[navigationPanel
0590: .getButtonLocation()], true);
0591: te.addInclude(aboutLocations[navigationPanel
0592: .getButtonLocation()].substring(0, 3), true);
0593: jte1.addInclude("ABOUT", true);
0594: copyFile("templates/images/question.png", currentProject
0595: .getPath()
0596: + "/resources/question.png");
0597: copyFile("templates/images/question_over.png",
0598: currentProject.getPath()
0599: + "/resources/question_over.png");
0600: copyFile("templates/images/question_pressed.png",
0601: currentProject.getPath()
0602: + "/resources/question_pressed.png");
0603: } else {
0604: deleteFile(currentProject.getPath()
0605: + "/resources/question.gif");
0606: deleteFile(currentProject.getPath()
0607: + "/resources/question_over.gif");
0608: deleteFile(currentProject.getPath()
0609: + "/resources/question_pressed.gif");
0610: }
0611:
0612: copyFile("templates/pages/About.xml", currentProject.getPath()
0613: + "/pages/About.xml");
0614: File f = new File(currentProject.getPath()
0615: + "/src/com/xoetrope/myproject");
0616: f.mkdirs();
0617:
0618: if (productsPanel.wantsSampleProducts() != -1) {
0619: // if using a simple view, copy images used for products to the project.
0620: if (facilitiesPanel.wantsSimpleView()) {
0621: te.useSampleProducts(productsPanel
0622: .wantsSampleProducts());
0623:
0624: jte1.addInclude("IMPORTS", true);
0625: jte1.addInclude("DRAGINFO", true);
0626: jte1.addInclude("MOUSE", true);
0627: jte1.addInclude("VARS", true);
0628: jte1.addInclude("STYLE", true);
0629:
0630: jte1.useSampleProducts(productsPanel
0631: .wantsSampleProducts());
0632:
0633: if (productsPanel.usePhotos()) {
0634: jte1.addInclude("DETAILS", true);
0635: jte1.addInclude("PHOTOS", true);
0636:
0637: if (productsPanel.wantsSampleProducts() > 0) {
0638: copyFile("templates/images/camera.jpg",
0639: currentProject.getPath()
0640: + "/resources/camera.jpg");
0641: copyFile(
0642: "templates/images/networkstorage.jpg",
0643: currentProject.getPath()
0644: + "/resources/networkstorage.jpg");
0645: }
0646:
0647: if (productsPanel.wantsSampleProducts() > 2) {
0648: copyFile("templates/images/wirelesscard.jpg",
0649: currentProject.getPath()
0650: + "/resources/wirelesscard.jpg");
0651: copyFile("templates/images/blackberry.jpg",
0652: currentProject.getPath()
0653: + "/resources/blackberry.jpg");
0654: }
0655:
0656: if (productsPanel.wantsSampleProducts() > 4) {
0657: copyFile("templates/images/graphicscard.jpg",
0658: currentProject.getPath()
0659: + "/resources/graphicscard.jpg");
0660: copyFile("templates/images/earphones.jpg",
0661: currentProject.getPath()
0662: + "/resources/earphones.jpg");
0663: copyFile("templates/images/dictionary.jpg",
0664: currentProject.getPath()
0665: + "/resources/dictionary.jpg");
0666: copyFile("templates/images/iphone.jpg",
0667: currentProject.getPath()
0668: + "/resources/iphone.jpg");
0669: }
0670:
0671: if (productsPanel.wantsSampleProducts() > 8) {
0672: copyFile("templates/images/tabletpc.jpg",
0673: currentProject.getPath()
0674: + "/resources/tabletpc.jpg");
0675: copyFile("templates/images/mp3player.jpg",
0676: currentProject.getPath()
0677: + "/resources/mp3player.jpg");
0678: copyFile("templates/images/harddrive.jpg",
0679: currentProject.getPath()
0680: + "/resources/harddrive.jpg");
0681: copyFile("templates/images/digitaltv.jpg",
0682: currentProject.getPath()
0683: + "/resources/digitaltv.jpg");
0684: }
0685: } else {
0686: te.addContent("ProductPhotos", "");
0687: }
0688:
0689: if (productsPanel.usePriceInfo()) {
0690: jte1.addInclude("PRICES", true);
0691: }
0692:
0693: if (productsPanel.useProductDetails()) {
0694: jte1.addInclude("DETAILS", true);
0695: }
0696:
0697: deleteFile(currentProject.getPath()
0698: + "/resources/datasources.xml");
0699: deleteFile(currentProject.getPath()
0700: + "/resources/staticdata.xml");
0701: removeProperty("ModelData");
0702: }
0703: // else, copy static data for products to project.
0704: else if (facilitiesPanel.wantsTreeView()) {
0705: data.addInclude("TreeView", true);
0706: te.addInclude("ProductTree", true);
0707:
0708: if (productsPanel.usePriceInfo()) {
0709: jte1.addInclude("PRICES", true);
0710: }
0711:
0712: if (productsPanel.useProductDetails()) {
0713: jte1.addInclude("DETAILS", true);
0714: }
0715:
0716: jte1.addInclude("IMPORTS", true);
0717: jte1.addInclude("VARS", true);
0718: jte1.addInclude("STYLE", true);
0719:
0720: data.useSampleProducts(productsPanel
0721: .wantsSampleProducts());
0722: }
0723: }
0724: // if a tree view is being used, delete unused images from project as they are not needed.
0725: else if (facilitiesPanel.wantsTreeView()) {
0726: deleteFile(currentProject.getPath()
0727: + "/resources/camera.svg");
0728: deleteFile(currentProject.getPath()
0729: + "/resources/networkstorage.svg");
0730: deleteFile(currentProject.getPath()
0731: + "/resources/wirelesscard.svg");
0732: deleteFile(currentProject.getPath()
0733: + "/resources/blackberry.svg");
0734: deleteFile(currentProject.getPath()
0735: + "/resources/graphicscard.svg");
0736: deleteFile(currentProject.getPath()
0737: + "/resources/earphones.svg");
0738: deleteFile(currentProject.getPath()
0739: + "/resources/dictionary.svg");
0740: deleteFile(currentProject.getPath()
0741: + "/resources/iphone.svg");
0742: deleteFile(currentProject.getPath()
0743: + "/resources/tabletpc.svg");
0744: deleteFile(currentProject.getPath()
0745: + "/resources/mp3player.svg");
0746: deleteFile(currentProject.getPath()
0747: + "/resources/harddrive.svg");
0748: deleteFile(currentProject.getPath()
0749: + "/resources/digitaltv.svg");
0750: deleteFile(currentProject.getPath()
0751: + "/resources/datasources.xml");
0752: }
0753:
0754: // copy images used for graphic buttons.
0755: copyFile("templates/images/prev.png", currentProject.getPath()
0756: + "/resources/prev.png");
0757: copyFile("templates/images/prev_over.png", currentProject
0758: .getPath()
0759: + "/resources/prev_over.png");
0760: copyFile("templates/images/prev_pressed.png", currentProject
0761: .getPath()
0762: + "/resources/prev_pressed.png");
0763: copyFile("templates/images/next.png", currentProject.getPath()
0764: + "/resources/next.png");
0765: copyFile("templates/images/next_over.png", currentProject
0766: .getPath()
0767: + "/resources/next_over.png");
0768: copyFile("templates/images/next_pressed.png", currentProject
0769: .getPath()
0770: + "/resources/next_pressed.png");
0771: copyFile("templates/images/home.png", currentProject.getPath()
0772: + "/resources/home.png");
0773: copyFile("templates/images/home_over.png", currentProject
0774: .getPath()
0775: + "/resources/home_over.png");
0776: copyFile("templates/images/home_pressed.png", currentProject
0777: .getPath()
0778: + "/resources/home_pressed.png");
0779: copyFile("templates/files/styles.xml", currentProject.getPath()
0780: + "/resources/styles.xml");
0781:
0782: String style = stylesPanel.getStyle();
0783: if (style != null)
0784: te.addContent("CatalogStyle", style);
0785:
0786: te.process(resources);
0787:
0788: copyResourceFile("XuiProSwingComponents.jar",
0789: "/lib/XuiProSwingComponents.jar");
0790: copyResourceFile("XuiProSvgComponents.jar",
0791: "/lib/XuiProSvgComponents.jar");
0792: copyResourceFile("svgSalamander.jar", "/lib/svgSalamander.jar");
0793: copyResourceFile("TimingFramework.jar",
0794: "/lib/TimingFramework.jar");
0795:
0796: addJar("XuiProSwingComponents.jar");
0797: addJar("XuiProSvgComponents.jar");
0798: addJar("svgSalamander.jar");
0799: addJar("TimingFramework.jar");
0800:
0801: copyResourceFile("XuiProSwingComponents.jar",
0802: "/lib/XuiProSwingComponents.jar");
0803: copyResourceFile("XuiProSvgComponents.jar",
0804: "/lib/XuiProSvgComponents.jar");
0805: copyResourceFile("xuiProComponents.xml",
0806: "/resources/xuiProComponents.xml");
0807: copyResourceFile("svgSalamander.jar", "/lib/svgSalamander.jar");
0808: copyResourceFile("TimingFramework.jar",
0809: "/lib/TimingFramework.jar");
0810:
0811: addProperty("ComponentRegistry", "xuiProComponents.xml");
0812: addProperty("LAF",
0813: "net.xoetrope.optional.laf.WindowsLafInstaller");
0814:
0815: jte1.process(r1);
0816: jte2.process(r2);
0817: data.process(r3);
0818: }
0819:
0820: /**
0821: * Responsible for setting up and processing the Checkout page template.
0822: */
0823: public void processCheckoutTemplate() {
0824: String projectPath = currentProject
0825: .getStartupParam("ProjectPath");
0826: String s = xuiProPath + "/pages";
0827: String t = projectPath + "/pages";
0828: XCustomXmlTemplateEngine te = new XCustomXmlTemplateEngine(
0829: currentProject, s, t);
0830: String[] r = { "Checkout.xml" };
0831:
0832: s = xuiProPath + "/javaclasses";
0833: t = projectPath + "/src/com/xoetrope/myproject";
0834: XCustomJavaTemplateEngine jte = new XCustomJavaTemplateEngine(
0835: currentProject, s, t);
0836: jte.setPackageName("com.xoetrope.myproject");
0837: String[] r1 = { "Checkout.java" };
0838:
0839: if (welcomePanel.usesLogo()) {
0840: te.addInclude("Logo", true);
0841: }
0842:
0843: if (welcomePanel.usesBackground()) {
0844: te.addInclude("Background", true);
0845: copyFile("templates/images/"
0846: + welcomePanel.getBackgroundFile(), currentProject
0847: .getPath()
0848: + "/resources/background.jpg");
0849: } else {
0850: deleteFile(currentProject.getPath()
0851: + "/resources/background.jpg");
0852: }
0853:
0854: if (navigationPanel.useForwardBackward()) {
0855: te.addInclude(backLocations[navigationPanel
0856: .getButtonLocation()], true);
0857: te.addInclude(backLocations[navigationPanel
0858: .getButtonLocation()].substring(0, 3), true);
0859: te.addInclude(nextLocations[navigationPanel
0860: .getButtonLocation()], true);
0861: te.addInclude(nextLocations[navigationPanel
0862: .getButtonLocation()].substring(0, 3), true);
0863:
0864: te.addInclude(closeLocations[navigationPanel
0865: .getButtonLocation()], true);
0866:
0867: jte.addInclude("PREVIOUS", true);
0868: jte.addInclude("CLOSE", true);
0869: } else {
0870: te.addInclude("CloseBottomLeft", true);
0871: }
0872:
0873: if (navigationPanel.useHome()) {
0874: te.addInclude(homeLocations[navigationPanel
0875: .getButtonLocation()], true);
0876: te.addInclude(homeLocations[navigationPanel
0877: .getButtonLocation()].substring(0, 3), true);
0878: jte.addInclude("HOME", true);
0879: }
0880:
0881: if (navigationPanel.useAbout()) {
0882: te.addInclude(aboutLocations[navigationPanel
0883: .getButtonLocation()], true);
0884: te.addInclude(aboutLocations[navigationPanel
0885: .getButtonLocation()].substring(0, 3), true);
0886: jte.addInclude("ABOUT", true);
0887: }
0888:
0889: if (navigationPanel.usesStatusBar()) {
0890: te.addInclude("Status", true);
0891: }
0892:
0893: if (!navigationPanel.useHints()) {
0894: te.addContent("ToolTip", "");
0895: }
0896:
0897: if (productsPanel.wantsSampleProducts() > 0) {
0898: jte.addInclude("VARS", true);
0899: jte.addInclude("IMPORTS", true);
0900:
0901: if (productsPanel.usePriceInfo()) {
0902: jte.addInclude("PRICES", true);
0903: }
0904: }
0905:
0906: String[] includes = { "City", "Street", "Country", "Telephone",
0907: "TelExt", "Fax", "FaxExt", "Email", "Website",
0908: "Company", "Department", "Job" };
0909: int[] fields = ordersPanel.getSelectedFields();
0910: for (int i = 0; i < fields.length; i++) {
0911: for (int k = 0; k < includes.length; k++) {
0912: if (fields[i] == k) {
0913: te.addInclude(includes[k], true);
0914: }
0915: }
0916: }
0917:
0918: if (ordersPanel.wantsBillingAddress()
0919: || ordersPanel.wantsDeliveryAddress()) {
0920: te.addInclude("TabPanel", true);
0921:
0922: if (ordersPanel.wantsBillingAddress()) {
0923: te.addInclude("Billing", true);
0924: }
0925: if (ordersPanel.wantsDeliveryAddress()) {
0926: te.addInclude("Delivery", true);
0927: }
0928: } else {
0929: te.addInclude("AddressPanel", true);
0930: }
0931:
0932: String style = stylesPanel.getStyle();
0933: if (style != null)
0934: te.addContent("CatalogStyle", style);
0935:
0936: te.process(r);
0937: jte.process(r1);
0938:
0939: s = xuiProPath + "/pages";
0940: t = projectPath + "/pages";
0941: XTemplateEngine te2 = new XTemplateEngine(currentProject, s, t);
0942: String[] resources = { "Submit.xml" };
0943: te2.process(resources);
0944:
0945: s = xuiProPath + "/images";
0946: t = projectPath + "/resources";
0947: XTemplateEngine te3 = new XTemplateEngine(currentProject, s, t);
0948: String[] resources2 = { "close.png", "close_over.png",
0949: "close_pressed.png" };
0950: te3.process(resources2);
0951: }
0952:
0953: /**
0954: * Set the preferred size for the generated catalog.
0955: */
0956: public void setStyleInfo() {
0957: addProperty("ClientWidth", "1024");
0958: addProperty("ClientHeight", "768");
0959: }
0960:
0961: /**
0962: * Transfer files related to the setting up of a database connection within the project.
0963: */
0964: public void setDataBaseInfo() {
0965: int db = databasesPanel.useDataBase();
0966:
0967: String projectPath = currentProject
0968: .getStartupParam("ProjectPath");
0969: String s = xuiProPath + "/files";
0970: String t = projectPath + "/resources";
0971: XCustomXmlTemplateEngine te = new XCustomXmlTemplateEngine(
0972: currentProject, s, t);
0973: String[] r = { "datasources.xml" };
0974: te.addInclude("Database", true);
0975:
0976: try {
0977: XmlElement xml = XmlSource.read(new FileReader(s
0978: + "/handler_connection.xml"));
0979: Vector children = xml.getChildren();
0980:
0981: XmlElement child = (XmlElement) children.elementAt(0);
0982: child.setAttribute("driver", databasesPanel.getDriver());
0983:
0984: String url = databasesPanel.getUrl();
0985: child.setAttribute("url", url);
0986:
0987: child.setAttribute("user", databasesPanel.getUserName());
0988: child.setAttribute("pwd", databasesPanel.getPassword());
0989:
0990: FileOutputStream stream = new FileOutputStream(t
0991: + "/handler_connection.xml");
0992: JaxpXmlWriter writer = new JaxpXmlWriter();
0993: writer.setOutputStream(stream);
0994: writer.write(xml, true, 0);
0995: } catch (Exception ex) {
0996: if (BuildProperties.DEBUG)
0997: ex.printStackTrace();
0998: }
0999:
1000: te.process(r);
1001: addProperty("ModelData", "datasources.xml");
1002:
1003: if (db == 1) {
1004: copyFile("templates/files/hsqldb.jar", currentProject
1005: .getPath()
1006: + "/lib/hsqldb.jar");
1007: addJar("hsqldb.jar");
1008: copyFile("templates/files/hsqldb.jar", currentProject
1009: .getPath()
1010: + "/lib/hsqldb.jar");
1011: } else if (db == 2) {
1012: copyFile("templates/files/derbyclient.jar", currentProject
1013: .getPath()
1014: + "/lib/derbyclient.jar");
1015: addJar("derbyclient.jar");
1016: copyFile("templates/files/derbyclient.jar", currentProject
1017: .getPath()
1018: + "/lib/derbyclient.jar");
1019: }
1020:
1021: if (databasesPanel.wantsNewTables()) {
1022: Connection connection = databasesPanel.getConnection();
1023: String products = "CREATE TABLE \"Products\" " + "("
1024: + "\"Product_ID\" VARCHAR(30), "
1025: + "\"Product_NAME\" VARCHAR(30), "
1026: + "\"Product_Price\" VARCHAR(10) " + ")";
1027:
1028: String customers = "CREATE TABLE \"Customers\" " + "("
1029: + "\"Customer_ID\" VARCHAR(30), "
1030: + "\"Customer_FIRSTNAME\" VARCHAR(30), "
1031: + "\"Customer_SURNAME\" VARCHAR(10) " + ")";
1032:
1033: Statement statement = null;
1034: try {
1035: statement = connection.createStatement();
1036: statement.execute(products);
1037: statement.execute(customers);
1038: } catch (Exception ex) {
1039: if (BuildProperties.DEBUG)
1040: ex.printStackTrace();
1041: }
1042: }
1043:
1044: if (databasesPanel.wantsDummyData()) {
1045: Connection connection = databasesPanel.getConnection();
1046: String[] data = {
1047: "INSERT INTO \"Products\" VALUES ( 'camera', 'Canon Digital Camera', '$249.99')",
1048: "INSERT INTO \"Products\" VALUES ( 'netstore', 'Netgear Network Storage Device', '$99.99')",
1049: "INSERT INTO \"Products\" VALUES ( 'wireless', 'Netgear Wireless Card', '$39.99')",
1050: "INSERT INTO \"Products\" VALUES ( 'blackberry', 'Blackberry', '$399.99')",
1051: "INSERT INTO \"Products\" VALUES ( 'netstore', 'Netgear Network Storage Device', '$299.99')",
1052: "INSERT INTO \"Products\" VALUES ( 'graphicscard', 'ATI Graphics Card', '$19.99')",
1053: "INSERT INTO \"Products\" VALUES ( 'earphones', 'Noise Reduction Earphones', '$49.99')",
1054: "INSERT INTO \"Products\" VALUES ( 'dictionary', 'Electronic Dictionary', '$799.99')",
1055: "INSERT INTO \"Products\" VALUES ( 'iphone', 'iPhone', '$699.99')",
1056: "INSERT INTO \"Products\" VALUES ( 'tabletpc', 'Tablet PC', '$49.99')",
1057: "INSERT INTO \"Products\" VALUES ( 'mp3player', 'Mp3 Player', '$99.99')",
1058: "INSERT INTO \"Products\" VALUES ( 'harddrive', 'Hard-Drive', '$89.99')",
1059: "INSERT INTO \"Products\" VALUES ( 'digitaltv', 'Phillips Digital Tv', '$1599.99')" };
1060:
1061: Statement statement = null;
1062: try {
1063: statement = connection.createStatement();
1064: for (int i = 0; i < data.length; i++) {
1065: statement.execute(data[i]);
1066: }
1067: } catch (Exception ex) {
1068: if (BuildProperties.DEBUG)
1069: ex.printStackTrace();
1070: }
1071: }
1072: }
1073:
1074: /**
1075: * Used to add a property to the startup.properties file.
1076: * @param key <CODE>String</CODE> representing the property key.
1077: * @param value <CODE>String</CODE> representing the property value.
1078: */
1079: public void addProperty(String key, String value) {
1080: try {
1081: Properties prop = new Properties();
1082: prop.load(new FileInputStream(currentProject.getPath()
1083: + "/resources/startup.properties"));
1084: prop.put(key, value);
1085:
1086: FileOutputStream stream = new FileOutputStream(
1087: currentProject.getPath()
1088: + "/resources/startup.properties");
1089: prop.store(stream, "startup properties");
1090: stream.flush();
1091: stream.close();
1092: } catch (Exception ex) {
1093: if (BuildProperties.DEBUG)
1094: ex.printStackTrace();
1095: }
1096: }
1097:
1098: /**
1099: * Used to remove a property from the startup.properties file.
1100: * @param key <CODE>String</CODE> representing the property key.
1101: */
1102: public void removeProperty(String key) {
1103: try {
1104: Properties prop = new Properties();
1105: prop.load(new FileInputStream(currentProject.getPath()
1106: + "/resources/startup.properties"));
1107: prop.remove(key);
1108:
1109: FileOutputStream stream = new FileOutputStream(
1110: currentProject.getPath()
1111: + "/resources/startup.properties");
1112: prop.store(stream, "startup properties");
1113: stream.flush();
1114: stream.close();
1115: } catch (Exception ex) {
1116: if (BuildProperties.DEBUG)
1117: ex.printStackTrace();
1118: }
1119: }
1120:
1121: /**
1122: * Used to copy files from the carousel resources directory to the current project.
1123: * @param in <CODE>String</CODE> representing the path of the file to be copied.
1124: * @param out <CODE>String</CODE> representing the path where it is to be copied too.
1125: */
1126: public void copyResourceFile(String src, String dst) {
1127: String location = getClass().getResource("").toString();
1128: location = location.substring(0, location.indexOf("com/"));
1129:
1130: try {
1131: URL url = new URL(location
1132: + "com/xoetrope/carousel/resources/" + src);
1133: OutputStream os = new FileOutputStream(new File(
1134: currentProject.getPath() + dst));
1135: InputStream is = url.openStream();
1136:
1137: // Transfer bytes from in to out
1138: byte[] buf = new byte[1024];
1139: int len;
1140: while ((len = is.read(buf)) > 0) {
1141: os.write(buf, 0, len);
1142: }
1143: is.close();
1144: os.close();
1145: } catch (Exception ex) {
1146: if (BuildProperties.DEBUG)
1147: ex.printStackTrace();
1148: }
1149: }
1150:
1151: /**
1152: * Add jar to the project properties.
1153: * @param name <CODE>String</CODE> representing the path of the jar to be added.
1154: */
1155: public void addJar(String name) {
1156: try {
1157: String s = currentProject.getPath() + "/lib/" + name;
1158: File f = new File(s);
1159: URL jarUrl = f.toURI().toURL();
1160: currentProject.getEditorUtility().addJar(currentProject,
1161: jarUrl);
1162: } catch (Exception ex) {
1163: ex.printStackTrace();
1164: }
1165: }
1166:
1167: /**
1168: * Copy class resource file to the current project.
1169: * @param src <CODE>String</CODE> representing the path of the file to be copied.
1170: * @param dst <CODE>String</CODE> representing the path where it is to be copied too.
1171: */
1172: protected void copyFile(String src, String dst) {
1173: try {
1174: InputStream in = getClass().getResourceAsStream(src);
1175: OutputStream out = new FileOutputStream(new File(dst));
1176:
1177: // Transfer bytes from in to out
1178: byte[] buf = new byte[1024];
1179: int len;
1180: while ((len = in.read(buf)) > 0) {
1181: out.write(buf, 0, len);
1182: }
1183: in.close();
1184: out.close();
1185: } catch (Exception ex) {
1186: ex.printStackTrace();
1187: }
1188: }
1189:
1190: /**
1191: * Delete a file from the current project.
1192: * @param f <CODE>String</CODE> representing the file to be deleted.
1193: */
1194: private void deleteFile(String f) {
1195: File file = new File(f);
1196: if (file.exists()) {
1197: file.delete();
1198: }
1199: }
1200:
1201: /**
1202: * Increase and repaint the progress bar.
1203: */
1204: private void moreProgress() {
1205: buildProgress.setValue(progressLevel++);
1206: buildProgress.paintImmediately(0, 0, 250, 25);
1207: }
1208: }
|