001: package com.xoetrope.carousel.catalog;
002:
003: import com.xoetrope.carousel.build.BuildProperties;
004: import com.xoetrope.carousel.wizard.XWizardPanel;
005: import com.xoetrope.util.XTextDefaults;
006: import java.io.BufferedReader;
007: import java.io.File;
008: import java.io.FileReader;
009: import java.io.IOException;
010: import java.net.MalformedURLException;
011: import java.net.URL;
012:
013: import java.awt.BorderLayout;
014: import java.awt.GridLayout;
015: import java.awt.Rectangle;
016: import java.awt.event.ActionEvent;
017: import java.awt.event.ActionListener;
018: import javax.swing.BorderFactory;
019: import javax.swing.ButtonGroup;
020: import javax.swing.JButton;
021: import javax.swing.JCheckBox;
022: import javax.swing.JEditorPane;
023: import javax.swing.JFileChooser;
024: import javax.swing.JLabel;
025: import javax.swing.JPanel;
026: import javax.swing.JRadioButton;
027: import javax.swing.JScrollPane;
028: import javax.swing.JTextArea;
029: import javax.swing.JTextField;
030: import javax.swing.JViewport;
031: import javax.swing.SwingConstants;
032: import javax.swing.event.ChangeEvent;
033: import javax.swing.event.ChangeListener;
034: import javax.swing.text.html.HTMLEditorKit;
035: import net.xoetrope.editor.project.XEditorProject;
036: import net.xoetrope.editor.project.XEditorProjectManager;
037: import net.xoetrope.editor.project.helper.AFileFilter;
038: import net.xoetrope.swing.XImage;
039:
040: //import org.netbeans.api.debugger.jpda.This;
041:
042: /**
043: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
044: * the GNU Public License (GPL), please see license.txt for more details. If
045: * you make commercial use of this software you must purchase a commercial
046: * license from Xoetrope.</p>
047: * <p> $Revision: 1.10 $</p>
048: */
049: public class Welcome extends XWizardPanel implements ActionListener,
050: ChangeListener {
051: public final static String DEF_WALLPAPER_FILE = "background.jpg";
052: public final static String DEF_CLOGO_FILE = "clogo.gif";
053: public final static String DEF_SPLASH_FILE = "splash.gif";
054: public final static String DEF_SPLASH_SOUND = "splash.wav";
055:
056: public final static String DEF_TITLE_TEXT = "Product Catalogue";
057: public final static String DEF_SUBTITLE_TEXT = "Welcome to the Product Catalogue";
058: public final static String DEF_GREETING_TEXT = "";
059:
060: private boolean isStandalone = false;
061: private XCatalogueWizardDialog wizard;
062: private XImage imageControl1 = new XImage();
063: private JTextArea jTextArea1 = new JTextArea();
064:
065: private JLabel jLabel1 = new JLabel();
066: private JLabel jLabel2 = new JLabel();
067: private JPanel jPanel1 = new JPanel();
068:
069: private ButtonGroup buttonGroup = new ButtonGroup();
070: private JRadioButton tiledRB = new JRadioButton();
071: private JRadioButton stretchRB = new JRadioButton();
072: private JRadioButton centredRB = new JRadioButton();
073:
074: private GridLayout gridLayout1 = new GridLayout();
075:
076: private JCheckBox portfolioCB = new JCheckBox();
077: private JCheckBox backgroundCB = new JCheckBox();
078: private JCheckBox clogoCB = new JCheckBox();
079: private JCheckBox splashImgCB = new JCheckBox();
080: private JCheckBox greetingCB = new JCheckBox();
081:
082: private JTextField titleField = new JTextField();
083: private JTextField subTitleField = new JTextField();
084: private JTextField portfolioImageField = new JTextField();
085: private JTextField backgroundImageField = new JTextField();
086: private JTextField logoImageField = new JTextField();
087: private JTextField splashImageField = new JTextField();
088: private JTextArea greetingEditor;
089: private JScrollPane scrollPane;
090:
091: private JButton wallpaperBrowseBtn = new JButton();
092: private JButton portfolioBrowseBtn = new JButton();
093: private JButton logoBrowseBtn = new JButton();
094: private JButton splashBrowseBtn = new JButton();
095: private JButton soundBrowseBtn = new JButton();
096: private JButton textBrowseBtn = new JButton();
097:
098: /**
099: * Constructor which takes an instance of the <CODE>XCatalogueWizardDialog</CODE> and
100: * a String specifying the super class name.
101: * @param wiz the <CODE>XCatalogueWizardDialog</CODE> instance passed to this class.
102: * @param name the <CODE>String</CODE> instance passed to this class specifying the super class name.
103: */
104: public Welcome(XCatalogueWizardDialog wiz, String name) {
105: super (name);
106: wizard = wiz;
107:
108: try {
109: jbInit();
110: } catch (Exception ex) {
111: if (BuildProperties.DEBUG)
112: ex.printStackTrace();
113: }
114: }
115:
116: /**
117: * Method responsible for initialising the components used in this wizard panel.
118: */
119: void jbInit() throws Exception {
120: setLayout(null);
121:
122: tiledRB.setFocusable(false);
123: stretchRB.setFocusable(false);
124: centredRB.setFocusable(false);
125:
126: portfolioCB.setFocusable(false);
127: backgroundCB.setFocusable(false);
128: clogoCB.setFocusable(false);
129: splashImgCB.setFocusable(false);
130: centredRB.setFocusable(false);
131:
132: wallpaperBrowseBtn.setFocusable(false);
133: portfolioBrowseBtn.setFocusable(false);
134: logoBrowseBtn.setFocusable(false);
135: splashBrowseBtn.setFocusable(false);
136: soundBrowseBtn.setFocusable(false);
137: textBrowseBtn.setFocusable(false);
138:
139: imageControl1.setBackground(getBackground());
140: imageControl1.setBounds(new Rectangle(5, 9, 179, 366));
141: imageControl1.setImage(((XEditorProject) (XEditorProjectManager
142: .getCurrentProject())).getImage(getClass(),
143: "com/xoetrope/carousel/catalog/welcome.jpg"));
144: jTextArea1.setBackground(getBackground());
145: jTextArea1
146: .setText("Step 1: Configure the initial appearance of your catalogue including company logos and welcoming text.");
147: jTextArea1.setLineWrap(true);
148: jTextArea1.setEditable(false);
149: jTextArea1.setWrapStyleWord(true);
150: jTextArea1.setBounds(new Rectangle(190, 10, 400, 39));
151: jLabel1.setText("Title");
152: jLabel1.setBounds(new Rectangle(190, 61, 41, 17));
153: titleField
154: .setToolTipText("Enter the main catalogue title as it will appear on the welcome or home page.");
155: titleField.setText(DEF_TITLE_TEXT);
156: jLabel2.setText("Subtitle");
157: jLabel2.setBounds(new Rectangle(191, 79, 41, 17));
158: subTitleField
159: .setToolTipText("Enter the product subtitle or a one line description");
160: subTitleField.setText(DEF_SUBTITLE_TEXT);
161:
162: portfolioCB
163: .setToolTipText("Check to use a photo of your companies products on the welcome / home page.");
164: portfolioCB.setText("Product portfolio photo");
165: portfolioCB.setBounds(new Rectangle(190, 99, 144, 22));
166: portfolioCB.addChangeListener(this );
167: portfolioCB.setSelected(true);
168:
169: backgroundCB
170: .setToolTipText("Select to use a background image for the catalogue.");
171: backgroundCB.setText("Background image");
172: backgroundCB.setBounds(new Rectangle(191, 125, 140, 20));
173: backgroundCB.addChangeListener(this );
174: backgroundCB.setSelected(true);
175:
176: portfolioImageField
177: .setToolTipText("Enter the path to an image showing a selection of your products");
178: portfolioImageField.setText("portfolio.png");
179:
180: backgroundImageField.setEnabled(true);
181: backgroundImageField
182: .setToolTipText("Enter the path to an image for the forms\' background");
183: backgroundImageField.setText(DEF_WALLPAPER_FILE);
184:
185: jPanel1.setBorder(BorderFactory.createEtchedBorder());
186: jPanel1.setBounds(new Rectangle(207, 150, 381, 28));
187: jPanel1.setLayout(gridLayout1);
188:
189: portfolioBrowseBtn.setToolTipText("Click here to pick a file");
190: wallpaperBrowseBtn.setToolTipText("Click here to pick a file");
191: logoBrowseBtn.setToolTipText("Click here to pick a file");
192: splashBrowseBtn.setToolTipText("Click here to pick a file");
193: textBrowseBtn.setToolTipText("Click here to pick a text file");
194:
195: clogoCB
196: .setToolTipText("Select to use a company logo on each page / form within the catalogue");
197: splashImgCB
198: .setToolTipText("Check this item to display a splash screen image while the catalogue loads.");
199: greetingCB
200: .setToolTipText("Choose this option to enter greeting text for the catalogue to appear along side any product portfolio photo.");
201: stretchRB
202: .setToolTipText("Stretch the wallpaper image so that it fills the entire form background area.");
203: tiledRB
204: .setToolTipText("Use multiple copies of the wallpaper image arranged in a tiled grid to fill the form background.");
205: centredRB
206: .setToolTipText("Centre a single copy of he wallpaper image on the form background");
207:
208: logoImageField.setText(DEF_CLOGO_FILE);
209: splashImageField.setText(DEF_SPLASH_FILE);
210:
211: buttonGroup.add(tiledRB);
212: buttonGroup.add(stretchRB);
213: buttonGroup.add(centredRB);
214:
215: tiledRB.setEnabled(false);
216: tiledRB.setText("Tiled");
217: tiledRB.setHorizontalAlignment(SwingConstants.CENTER);
218:
219: stretchRB.setEnabled(false);
220: stretchRB.setText("Stretched");
221: stretchRB.setHorizontalAlignment(SwingConstants.CENTER);
222:
223: centredRB.setEnabled(false);
224: centredRB.setText("Centred");
225: centredRB.setHorizontalAlignment(SwingConstants.CENTER);
226:
227: clogoCB.setSelected(true);
228: clogoCB.setText("Company logo");
229: clogoCB.setBounds(new Rectangle(193, 150, 138, 25));
230: clogoCB.addChangeListener(this );
231:
232: splashImgCB.setText("Splash screen image");
233: splashImgCB.setBounds(new Rectangle(193, 184, 141, 25));
234: splashImgCB.addChangeListener(this );
235: splashImgCB.setSelected(true);
236:
237: greetingCB.setText("Greeting Text");
238: greetingCB.setBounds(new Rectangle(193, 208, 140, 25));
239: greetingCB.addChangeListener(this );
240:
241: greetingEditor = new JTextArea();
242: greetingEditor.setWrapStyleWord(true);
243: greetingEditor.setLineWrap(true);
244: greetingEditor.setEditable(true);
245: greetingEditor.setEnabled(false);
246: scrollPane = new JScrollPane(greetingEditor);
247: scrollPane.setEnabled(false);
248:
249: greetingEditor
250: .setToolTipText("Insert information about your company and its products in html format here.");
251: logoImageField
252: .setToolTipText("Enter the path to a logo file for your company. This will appear on each page of the catalogue.");
253: splashImageField
254: .setToolTipText("Enter the path to a splash screen image to be displayed while the catalogue loads.");
255:
256: titleField.setBounds(new Rectangle(250, 54, 338, 21));
257: subTitleField.setBounds(new Rectangle(250, 77, 338, 21));
258: portfolioImageField.setBounds(new Rectangle(340, 100, 166, 21));
259: backgroundImageField
260: .setBounds(new Rectangle(340, 124, 166, 21));
261:
262: splashImageField.setBounds(new Rectangle(340, 184, 166, 21));
263: logoImageField.setBounds(new Rectangle(340, 150, 166, 21));
264: scrollPane.setBounds(new Rectangle(340, 208, 166, 96));
265:
266: logoBrowseBtn.setText("Browse");
267: wallpaperBrowseBtn.setText("Browse");
268: portfolioBrowseBtn.setText("Browse");
269: splashBrowseBtn.setText("Browse");
270: soundBrowseBtn.setText("Browse");
271: textBrowseBtn.setText("Browse");
272:
273: textBrowseBtn.setEnabled(false);
274:
275: logoBrowseBtn.addActionListener(this );
276: wallpaperBrowseBtn.addActionListener(this );
277: portfolioBrowseBtn.addActionListener(this );
278: splashBrowseBtn.addActionListener(this );
279: soundBrowseBtn.addActionListener(this );
280: textBrowseBtn.addActionListener(this );
281:
282: portfolioBrowseBtn.setBounds(new Rectangle(509, 99, 79, 22));
283: wallpaperBrowseBtn.setBounds(new Rectangle(509, 124, 79, 22));
284: logoBrowseBtn.setBounds(new Rectangle(509, 150, 79, 22));
285: splashBrowseBtn.setBounds(new Rectangle(509, 184, 79, 22));
286: soundBrowseBtn.setBounds(new Rectangle(509, 208, 79, 22));
287: textBrowseBtn.setBounds(new Rectangle(509, 208, 79, 22));
288:
289: add(jTextArea1, null);
290: add(imageControl1, null);
291: add(jLabel1, null);
292: add(jLabel2, null);
293: add(subTitleField, null);
294: add(titleField, null);
295: add(portfolioCB, null);
296: add(portfolioImageField, null);
297: add(backgroundImageField, null);
298:
299: jPanel1.add(stretchRB, null);
300: jPanel1.add(tiledRB, null);
301: jPanel1.add(centredRB, null);
302:
303: add(backgroundCB, null);
304: add(logoImageField, null);
305: add(splashImageField, null);
306: add(scrollPane, null);
307: add(splashImgCB, null);
308: add(greetingCB, null);
309: add(clogoCB, null);
310: add(portfolioBrowseBtn, null);
311: add(wallpaperBrowseBtn, null);
312: add(logoBrowseBtn, null);
313: add(splashBrowseBtn, null);
314: add(textBrowseBtn, null);
315: }
316:
317: /**
318: * Listens for action events on the file selection buttons within this wizard panel
319: * @param the passed <CODE>ActionEvent</CODE>
320: */
321: public void actionPerformed(ActionEvent evt) {
322: AFileFilter dbFileFilter;
323: AFileFilter txtFileFilter;
324: JFileChooser fileDialog = new JFileChooser();
325:
326: if (evt.getActionCommand().compareTo("Browse") == 0) {
327: dbFileFilter = new AFileFilter("jpg", "JPEG Images");
328: txtFileFilter = new AFileFilter("txt", "Text files");
329:
330: if (evt.getSource() == textBrowseBtn) {
331: fileDialog.addChoosableFileFilter(txtFileFilter);
332: fileDialog.setFileFilter(txtFileFilter);
333: } else {
334: fileDialog.addChoosableFileFilter(dbFileFilter);
335: fileDialog.setFileFilter(dbFileFilter);
336: }
337: fileDialog.setFileHidingEnabled(false);
338: fileDialog
339: .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
340:
341: int retval = fileDialog.showDialog(this , null);
342: if (retval == JFileChooser.APPROVE_OPTION) {
343:
344: } else
345: return;
346: }
347:
348: try {
349: if (evt.getSource() == portfolioBrowseBtn)
350: portfolioImageField.setText(fileDialog
351: .getSelectedFile().getCanonicalPath());
352: else if (evt.getSource() == wallpaperBrowseBtn)
353: backgroundImageField.setText(fileDialog
354: .getSelectedFile().getCanonicalPath());
355: else if (evt.getSource() == logoBrowseBtn)
356: logoImageField.setText(fileDialog.getSelectedFile()
357: .getCanonicalPath());
358: else if (evt.getSource() == splashBrowseBtn)
359: splashImageField.setText(fileDialog.getSelectedFile()
360: .getCanonicalPath());
361: else if (evt.getSource() == textBrowseBtn) {
362: File f = new File(fileDialog.getSelectedFile()
363: .getCanonicalPath());
364:
365: if (f.exists()) {
366: BufferedReader reader = new BufferedReader(
367: new FileReader(f));
368:
369: String content = null, line = null;
370: while ((line = reader.readLine()) != null) {
371: if (content == null)
372: content = line;
373: else
374: content = content + line;
375: }
376: reader.close();
377:
378: greetingEditor.setText(content);
379: }
380: }
381: } catch (Exception ex) {
382: if (BuildProperties.DEBUG)
383: ex.printStackTrace();
384: }
385: }
386:
387: /**
388: * Listens for change events on the check boxes used in this XWizardPanel
389: * @param evt the <CODE>ChangeEvent</CODE> instance passed to this method
390: */
391: public void stateChanged(ChangeEvent evt) {
392: try {
393: boolean state = ((JCheckBox) evt.getSource()).isSelected();
394:
395: if (evt.getSource() == portfolioCB) {
396: portfolioImageField.setEnabled(state);
397: portfolioBrowseBtn.setEnabled(state);
398: } else if (evt.getSource() == backgroundCB) {
399: backgroundImageField.setEnabled(state);
400: wallpaperBrowseBtn.setEnabled(state);
401: stretchRB.setEnabled(state);
402: tiledRB.setEnabled(state);
403: centredRB.setEnabled(state);
404: } else if (evt.getSource() == clogoCB) {
405: logoImageField.setEnabled(state);
406: logoBrowseBtn.setEnabled(state);
407: } else if (evt.getSource() == splashImgCB) {
408: splashImageField.setEnabled(state);
409: splashBrowseBtn.setEnabled(state);
410: } else if (evt.getSource() == greetingCB) {
411: greetingEditor.setEnabled(state);
412: scrollPane.setEnabled(state);
413: textBrowseBtn.setEnabled(state);
414: }
415: } catch (Exception ex) {
416: if (BuildProperties.DEBUG)
417: ex.printStackTrace();
418: }
419: }
420:
421: /**
422: * Returns the catalogue name
423: * @return <CODE>String</CODE> specifying the catalogue name
424: */
425: public String getCatalogueName() {
426: // Strip blanks
427: String title = titleField.getText();
428: String buffer = titleField.getText();
429: int idx = title.lastIndexOf(' ');
430: while (idx > -1) {
431: title = title.substring(0, idx) + buffer.substring(idx + 1);
432: buffer = title;
433: idx = title.lastIndexOf(' ');
434: }
435:
436: return title;
437: }
438:
439: /**
440: * Returns whether a logo is to be used within the catalogue
441: * @return <CODE>boolean</CODE> specifying whether a logo is to be used or not
442: */
443: public boolean usesLogo() {
444: return clogoCB.isSelected();
445: }
446:
447: /**
448: * Returns whether a background image is to be used within the catalogue
449: * @return <CODE>boolean</CODE> specifying whether a background image is to be used or not
450: */
451: public boolean usesBackground() {
452: return backgroundCB.isSelected();
453: }
454:
455: /**
456: * Returns whether a portfolio image is to be used within the catalogue
457: * @return <CODE>boolean</CODE> specifying whether a portfolio image is to be used or not
458: */
459: public boolean usesPortfolioImage() {
460: return portfolioCB.isSelected();
461: }
462:
463: /**
464: * Returns whether a splash image is to be used within the catalogue
465: * @return <CODE>boolean</CODE> specifying whether a splash image is to be used or not
466: */
467: public boolean usesSplashImage() {
468: return splashImgCB.isSelected();
469: }
470:
471: /**
472: * Returns whether greeting text is to be used within the catalogue
473: * @return <CODE>boolean</CODE> specifying whether greeting text is to be used or not
474: */
475: public boolean usesGreetingText() {
476: return greetingCB.isSelected();
477: }
478:
479: /**
480: * Returns the background image file name
481: * @return <CODE>String</CODE> specifying the background image file name
482: */
483: public String getBackgroundFile() {
484: String fileName = backgroundImageField.getText();
485: if (fileName.length() > 0)
486: return fileName;
487:
488: return DEF_WALLPAPER_FILE;
489: }
490:
491: /**
492: * Returns the portfolio image file name
493: * @return <CODE>String</CODE> specifying the portfolio image file name
494: */
495: public String getPortfolioImageFile() {
496: String fileName = portfolioImageField.getText();
497: if (fileName.length() > 0)
498: return fileName;
499:
500: return DEF_WALLPAPER_FILE;
501: }
502:
503: /**
504: * Returns the logo image file name
505: * @return <CODE>String</CODE> specifying the logo image file name
506: */
507: public String getLogoImageFile() {
508: String fileName = logoImageField.getText();
509: if (fileName.length() > 0)
510: return fileName;
511:
512: return DEF_CLOGO_FILE;
513: }
514:
515: /**
516: * Returns the splash image file name
517: * @return <CODE>String</CODE> specifying the splash image file name
518: */
519: public String getSplashImageFile() {
520: String fileName = splashImageField.getText();
521: if (fileName.length() > 0)
522: return fileName;
523:
524: return DEF_SPLASH_FILE;
525: }
526:
527: /**
528: * Returns the title of the catalogue
529: * @return <CODE>String</CODE> specifying the catalogue title name
530: */
531: public String getTitleText() {
532: String fileName = titleField.getText();
533: if (fileName.length() > 0)
534: return fileName;
535:
536: return DEF_TITLE_TEXT;
537: }
538:
539: /**
540: * Returns the subtitle of the catalogue
541: * @return <CODE>String</CODE> specifying the catalogue subtitle name
542: */
543: public String getSubTitleText() {
544: String fileName = subTitleField.getText();
545: if (fileName.length() > 0)
546: return fileName;
547:
548: return DEF_SUBTITLE_TEXT;
549: }
550:
551: /**
552: * Returns the greeting text to be used in the catalogue
553: * @return <CODE>String</CODE> specifying the greeting text
554: */
555: public String getGreetingText() {
556: String fileName = greetingEditor.getText();
557: if (fileName.length() > 0)
558: return fileName;
559:
560: return DEF_GREETING_TEXT;
561: }
562: }
|