001: /*
002: * $RCSfile: NewProductWizard.java,v $
003: * @modification $Date: 2001/09/28 19:35:30 $
004: * @version $Id: NewProductWizard.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
005: *
006: */
007:
008: package com.memoire.vainstall.builder.gui;
009:
010: import com.memoire.vainstall.VAGlobals;
011: import com.memoire.vainstall.builder.VAIBuilderModel;
012: import com.memoire.vainstall.builder.util.*;
013:
014: import java.awt.*;
015: import java.awt.event.*;
016: import java.io.File;
017:
018: import javax.swing.*;
019: import javax.swing.border.*;
020: import javax.swing.event.*;
021: import javax.swing.text.*;
022:
023: /**
024: * This class is a wizard that 'guides' the user to create a new product.
025: *
026: * It collects the data from the user.
027: *
028: * @see com.memoire.vainstall.builder.VAIBuilderModel
029: * @see java.awt.ActionListener
030: * @see java.awt.WindowListener
031: * @see javax.swing.JDialog
032: * @see javax.swing.event.DocumentListener
033: *
034: * @author Henrik Falk
035: * @version $Id: NewProductWizard.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
036: */
037: public class NewProductWizard extends JDialog implements
038: WindowListener, ActionListener, DocumentListener {
039:
040: VAIBuilderModel model;
041:
042: private final static Border loweredBorder = new SoftBevelBorder(
043: BevelBorder.LOWERED);
044: private final static Border raisedBorder = new SoftBevelBorder(
045: BevelBorder.RAISED);
046:
047: JPanel allPanel;
048:
049: JButton okButton;
050: JButton cancelButton;
051:
052: JTextField nameField;
053: JTextField versionField;
054: JTextField directoryField;
055: JButton directoryButton;
056: JComboBox typeBox;
057:
058: String action = VAGlobals.getResource(
059: "com.memoire.vainstall.builder.Language", "Common_Cancel");
060:
061: public NewProductWizard(Frame owner) {
062: super (owner);
063: setTitle(VAGlobals.getResource(
064: "com.memoire.vainstall.builder.Language",
065: "NewProductWizard_New"));
066:
067: setModal(true);
068:
069: setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
070:
071: getRootPane().registerKeyboardAction(this , "VK_ESCAPE",
072: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false),
073: JComponent.WHEN_IN_FOCUSED_WINDOW);
074:
075: // create the all panel
076: allPanel = new JPanel(new BorderLayout());
077: allPanel.setBorder(loweredBorder);
078:
079: // ********************************************************
080: // create 'logo'
081: JPanel nPanel = new JPanel(new GridBagLayout());
082: nPanel.setBorder(raisedBorder);
083: nPanel.setBackground(Color.white);
084: GridBagLayout nLayout = (GridBagLayout) nPanel.getLayout();
085:
086: JLabel whatLabel = new JLabel(VAGlobals.getResource(
087: "com.memoire.vainstall.builder.Language",
088: "NewProductWizard_Title"));
089: whatLabel.setFont(new java.awt.Font("TimesRoman",
090: java.awt.Font.BOLD, 16));
091: GridBagConstraints nContraint = new GridBagConstraints();
092: nContraint.fill = GridBagConstraints.BOTH;
093: nContraint.insets = new Insets(4, 8, 4, 4);
094: nContraint.anchor = GridBagConstraints.WEST;
095: nContraint.gridx = 0;
096: nContraint.gridy = 0;
097: nContraint.gridwidth = 1;
098: nContraint.gridheight = 1;
099: nContraint.weightx = 1;
100: nContraint.weighty = 0;
101: nLayout.setConstraints(whatLabel, nContraint);
102: nPanel.add(whatLabel);
103:
104: JLabel helpLabel = new JLabel(VAGlobals.getResource(
105: "com.memoire.vainstall.builder.Language",
106: "NewProductWizard_SubTitle"));
107: helpLabel.setFont(new java.awt.Font("TimesRoman",
108: java.awt.Font.PLAIN, 12));
109: nContraint.fill = GridBagConstraints.BOTH;
110: nContraint.insets = new Insets(4, 16, 4, 4);
111: nContraint.anchor = GridBagConstraints.WEST;
112: nContraint.gridx = 0;
113: nContraint.gridy = 1;
114: nContraint.gridwidth = 1;
115: nContraint.gridheight = 1;
116: nContraint.weightx = 0;
117: nContraint.weighty = 0;
118: nLayout.setConstraints(helpLabel, nContraint);
119: nPanel.add(helpLabel);
120:
121: JLabel iconLabel = new JLabel(
122: new javax.swing.ImageIcon(
123: getClass()
124: .getResource(
125: "/com/memoire/vainstall/builder/images/New24.gif")));
126: // GridBagConstraints nContraint = new GridBagConstraints();
127: nContraint.fill = GridBagConstraints.BOTH;
128: nContraint.insets = new Insets(4, 4, 4, 8);
129: nContraint.anchor = GridBagConstraints.WEST;
130: nContraint.gridx = 1;
131: nContraint.gridy = 0;
132: nContraint.gridwidth = 1;
133: nContraint.gridheight = 2;
134: nContraint.weightx = 0;
135: nContraint.weighty = 0;
136: nLayout.setConstraints(iconLabel, nContraint);
137: nPanel.add(iconLabel);
138:
139: allPanel.add(nPanel, BorderLayout.NORTH);
140:
141: // ********************************************************
142: // Create body
143: JPanel cPanel = new JPanel(new GridBagLayout());
144: GridBagLayout cLayout = (GridBagLayout) cPanel.getLayout();
145: GridBagConstraints cContraint = new GridBagConstraints();
146:
147: JLabel nameLabel = new JLabel();
148: nameLabel.setText(VAGlobals.getResource(
149: "com.memoire.vainstall.builder.Language",
150: "NewProductWizard_Name"));
151: // nameLabel.setFont(new java.awt.Font("TimesRoman", java.awt.Font.PLAIN, 14));
152: cContraint.fill = GridBagConstraints.BOTH;
153: cContraint.insets = new Insets(8, 8, 0, 4);
154: cContraint.anchor = GridBagConstraints.WEST;
155: cContraint.gridx = 0;
156: cContraint.gridy = 0;
157: cContraint.gridwidth = 3;
158: cContraint.gridheight = 1;
159: cContraint.weightx = 0;
160: cContraint.weighty = 0;
161: cLayout.setConstraints(nameLabel, cContraint);
162: cPanel.add(nameLabel);
163:
164: nameField = new JTextField();
165: nameField.getDocument().addDocumentListener(this );
166: // nameField.setFont(new java.awt.Font("TimesRoman", java.awt.Font.PLAIN, 14));
167: cContraint.fill = GridBagConstraints.BOTH;
168: cContraint.insets = new Insets(4, 8, 4, 8);
169: cContraint.anchor = GridBagConstraints.CENTER;
170: cContraint.gridx = 0;
171: cContraint.gridy = 1;
172: cContraint.gridwidth = 3;
173: cContraint.gridheight = 1;
174: cContraint.weightx = 1;
175: cContraint.weighty = 0;
176: cLayout.setConstraints(nameField, cContraint);
177: cPanel.add(nameField);
178:
179: JLabel versionLabel = new JLabel();
180: versionLabel.setText(VAGlobals.getResource(
181: "com.memoire.vainstall.builder.Language",
182: "NewProductWizard_Version"));
183: // versionLabel.setFont(new java.awt.Font("TimesRoman", java.awt.Font.PLAIN, 14));
184: cContraint.fill = GridBagConstraints.BOTH;
185: cContraint.insets = new Insets(4, 8, 0, 4);
186: cContraint.anchor = GridBagConstraints.WEST;
187: cContraint.gridx = 0;
188: cContraint.gridy = 2;
189: cContraint.gridwidth = 3;
190: cContraint.gridheight = 1;
191: cContraint.weightx = 0;
192: cContraint.weighty = 0;
193: cLayout.setConstraints(versionLabel, cContraint);
194: cPanel.add(versionLabel);
195:
196: versionField = new JTextField();
197: versionField.getDocument().addDocumentListener(this );
198: // versionField.setFont(new java.awt.Font("TimesRoman", java.awt.Font.PLAIN, 14));
199: // versionField.setColumns(8);
200: cContraint.fill = GridBagConstraints.HORIZONTAL;
201: cContraint.insets = new Insets(4, 8, 4, 8);
202: cContraint.anchor = GridBagConstraints.WEST;
203: cContraint.gridx = 0;
204: cContraint.gridy = 3;
205: cContraint.gridwidth = 1;
206: cContraint.gridheight = 1;
207: cContraint.weightx = 0;
208: cContraint.weighty = 0;
209: cLayout.setConstraints(versionField, cContraint);
210: cPanel.add(versionField);
211:
212: JLabel directoryLabel = new JLabel();
213: directoryLabel.setText(VAGlobals.getResource(
214: "com.memoire.vainstall.builder.Language",
215: "NewProductWizard_Directory"));
216: // directoryLabel.setFont(new java.awt.Font("TimesRoman", java.awt.Font.PLAIN, 14));
217: cContraint.fill = GridBagConstraints.BOTH;
218: cContraint.insets = new Insets(4, 8, 0, 4);
219: cContraint.anchor = GridBagConstraints.WEST;
220: cContraint.gridx = 0;
221: cContraint.gridy = 4;
222: cContraint.gridwidth = 1;
223: cContraint.gridheight = 1;
224: cContraint.weightx = 0;
225: cContraint.weighty = 0;
226: cLayout.setConstraints(directoryLabel, cContraint);
227: cPanel.add(directoryLabel);
228:
229: directoryField = new JTextField();
230: directoryField.setEditable(false);
231: // directoryField.setEnabled(false);
232: // directoryField.setFont(new java.awt.Font("TimesRoman", java.awt.Font.PLAIN, 14));
233: cContraint.fill = GridBagConstraints.BOTH;
234: cContraint.insets = new Insets(4, 8, 4, 8);
235: cContraint.anchor = GridBagConstraints.CENTER;
236: cContraint.gridx = 0;
237: cContraint.gridy = 5;
238: cContraint.gridwidth = 2;
239: cContraint.gridheight = 1;
240: cContraint.weightx = 1;
241: cContraint.weighty = 0;
242: cLayout.setConstraints(directoryField, cContraint);
243: cPanel.add(directoryField);
244:
245: directoryButton = new JButton();
246: directoryButton.setText("Change");
247: directoryButton.setSize(directoryButton.getSize().width,
248: directoryField.getSize().height);
249: directoryButton.addActionListener(this );
250: // directoryButton.setFont(new java.awt.Font("TimesRoman", java.awt.Font.PLAIN, 14));
251: cContraint.fill = GridBagConstraints.BOTH;
252: cContraint.insets = new Insets(4, 4, 4, 8);
253: cContraint.anchor = GridBagConstraints.CENTER;
254: cContraint.gridx = 1;
255: cContraint.gridy = 5;
256: cContraint.gridwidth = 1;
257: cContraint.gridheight = 1;
258: cContraint.weightx = 0;
259: cContraint.weighty = 0;
260: cLayout.setConstraints(directoryButton, cContraint);
261: cPanel.add(directoryButton);
262:
263: JLabel typeLabel = new JLabel();
264: typeLabel.setText(VAGlobals.getResource(
265: "com.memoire.vainstall.builder.Language",
266: "NewProductWizard_Type"));
267: cContraint.fill = GridBagConstraints.BOTH;
268: cContraint.insets = new Insets(4, 8, 8, 4);
269: cContraint.anchor = GridBagConstraints.WEST;
270: cContraint.gridx = 0;
271: cContraint.gridy = 6;
272: cContraint.gridwidth = 1;
273: cContraint.gridheight = 1;
274: cContraint.weightx = 0;
275: cContraint.weighty = 0;
276: cLayout.setConstraints(typeLabel, cContraint);
277: cPanel.add(typeLabel);
278:
279: typeBox = new JComboBox();
280: typeBox.addItem(VAGlobals.getResource(
281: "com.memoire.vainstall.builder.Language",
282: "NewProductWizard_Type_Install"));
283: typeBox.addItem(VAGlobals.getResource(
284: "com.memoire.vainstall.builder.Language",
285: "NewProductWizard_Type_Update"));
286: typeBox.addItem(VAGlobals.getResource(
287: "com.memoire.vainstall.builder.Language",
288: "NewProductWizard_Type_Module"));
289: cContraint.fill = GridBagConstraints.HORIZONTAL;
290: cContraint.insets = new Insets(4, 8, 8, 8);
291: cContraint.anchor = GridBagConstraints.WEST;
292: cContraint.gridx = 1;
293: cContraint.gridy = 6;
294: cContraint.gridwidth = 2;
295: cContraint.gridheight = 1;
296: cContraint.weightx = 0;
297: cContraint.weighty = 0;
298: cLayout.setConstraints(typeBox, cContraint);
299: cPanel.add(typeBox);
300:
301: JPanel centerFillPanel = new JPanel();
302: cContraint.fill = GridBagConstraints.BOTH;
303: cContraint.insets = new Insets(8, 4, 4, 4);
304: cContraint.anchor = GridBagConstraints.WEST;
305: cContraint.gridx = 0;
306: cContraint.gridy = 7;
307: cContraint.gridwidth = 1;
308: cContraint.gridheight = 1;
309: cContraint.weightx = 0;
310: cContraint.weighty = 1;
311: cLayout.setConstraints(centerFillPanel, cContraint);
312: cPanel.add(centerFillPanel);
313:
314: allPanel.add(cPanel, BorderLayout.CENTER);
315:
316: // ********************************************************
317: // Create buttons
318: JPanel sPanel = new JPanel(new GridBagLayout());
319: sPanel.setBorder(raisedBorder);
320: GridBagLayout sLayout = (GridBagLayout) sPanel.getLayout();
321: GridBagConstraints sContraint = new GridBagConstraints();
322:
323: JPanel buttonFillPanel = new JPanel();
324: sContraint.fill = GridBagConstraints.BOTH;
325: sContraint.insets = new Insets(4, 4, 4, 4);
326: sContraint.anchor = GridBagConstraints.WEST;
327: sContraint.gridx = 0;
328: sContraint.gridy = 1;
329: sContraint.gridwidth = 1;
330: sContraint.gridheight = 1;
331: sContraint.weightx = 1;
332: sContraint.weighty = 0;
333: sLayout.setConstraints(buttonFillPanel, sContraint);
334: sPanel.add(buttonFillPanel);
335:
336: okButton = new JButton();
337: okButton.setText(VAGlobals.getResource(
338: "com.memoire.vainstall.builder.Language",
339: "Common_Finish"));
340: okButton.addActionListener(this );
341: okButton.setEnabled(false);
342: sContraint.fill = GridBagConstraints.BOTH;
343: sContraint.insets = new Insets(4, 4, 4, 4);
344: sContraint.anchor = GridBagConstraints.WEST;
345: sContraint.gridx = 1;
346: sContraint.gridy = 1;
347: sContraint.gridwidth = 1;
348: sContraint.gridheight = 1;
349: sContraint.weightx = 0;
350: sContraint.weighty = 0;
351: sLayout.setConstraints(okButton, sContraint);
352: sPanel.add(okButton);
353:
354: cancelButton = new JButton();
355: cancelButton.setText(VAGlobals.getResource(
356: "com.memoire.vainstall.builder.Language",
357: "Common_Cancel"));
358: cancelButton.addActionListener(this );
359: sContraint.fill = GridBagConstraints.BOTH;
360: sContraint.insets = new Insets(4, 4, 4, 8);
361: sContraint.anchor = GridBagConstraints.WEST;
362: sContraint.gridx = 2;
363: sContraint.gridy = 1;
364: sContraint.gridwidth = 1;
365: sContraint.gridheight = 1;
366: sContraint.weightx = 0;
367: sContraint.weighty = 0;
368: sLayout.setConstraints(cancelButton, sContraint);
369: sPanel.add(cancelButton);
370:
371: allPanel.add(sPanel, BorderLayout.SOUTH);
372:
373: // ********************************************************
374: // insert the all panel
375: this .getContentPane().add("Center", allPanel);
376:
377: setSize(500, 340);
378: center();
379: }
380:
381: /**
382: * Since we need a reference to the root project directory
383: * we need to know the VAIBuilderModel
384: */
385: public void initialize(VAIBuilderModel model) {
386: this .model = model;
387:
388: String rootDirectory = (String) model.getPropertyList().get(
389: "vainstall.projectroot");
390: if (rootDirectory == null) {
391: rootDirectory = System.getProperty("user.dir");
392: }
393: directoryField.setText(rootDirectory);
394: }
395:
396: public void actionPerformed(ActionEvent evt) {
397:
398: // extract the control that sends the event
399: Object source = evt.getSource();
400: String actionCommand = evt.getActionCommand();
401:
402: if (actionCommand != null
403: && actionCommand.equals("VK_ESCAPE") == true) {
404: action = VAGlobals.getResource(
405: "com.memoire.vainstall.builder.Language",
406: "Common_Cancel");
407: }
408:
409: if (source == directoryButton) {
410:
411: JFileChooser jfc = new JFileChooser();
412: jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
413:
414: String rootDirectory = (String) model.getPropertyList()
415: .get("vainstall.projectroot");
416: if (rootDirectory == null) {
417: rootDirectory = System.getProperty("user.dir");
418: }
419: jfc.setCurrentDirectory(new File(rootDirectory));
420:
421: int result = jfc.showDialog(null, VAGlobals.getResource(
422: "com.memoire.vainstall.builder.Language",
423: "NewProductWizard_Select"));
424: if (result == JFileChooser.APPROVE_OPTION) {
425: directoryField.setText(jfc.getSelectedFile()
426: .getAbsolutePath());
427: }
428: return;
429: }
430:
431: if (source == okButton) {
432: action = VAGlobals.getResource(
433: "com.memoire.vainstall.builder.Language",
434: "Common_Finish");
435: }
436:
437: if (source == cancelButton) {
438: action = VAGlobals.getResource(
439: "com.memoire.vainstall.builder.Language",
440: "Common_Cancel");
441: }
442:
443: setVisible(false);
444:
445: }
446:
447: public String getAction() {
448: return action;
449: }
450:
451: public void center() {
452: Dimension dimScreen = Toolkit.getDefaultToolkit()
453: .getScreenSize();
454: setLocation((dimScreen.width - this .getSize().width) / 2,
455: (dimScreen.height - this .getSize().height) / 2);
456: }
457:
458: /**
459: * Method to handle events for the WindowListener interface.
460: * @param e java.awt.event.WindowEvent
461: */
462: public void windowActivated(java.awt.event.WindowEvent e) {
463: }
464:
465: /**
466: * Method to handle events for the WindowListener interface.
467: * @param e java.awt.event.WindowEvent
468: */
469: public void windowClosed(java.awt.event.WindowEvent e) {
470: }
471:
472: /**
473: * Method to handle events for the WindowListener interface.
474: * @param e java.awt.event.WindowEvent
475: */
476: public void windowClosing(java.awt.event.WindowEvent e) {
477: }
478:
479: /**
480: * Method to handle events for the WindowListener interface.
481: * @param e java.awt.event.WindowEvent
482: */
483: public void windowDeactivated(java.awt.event.WindowEvent e) {
484: }
485:
486: /**
487: * Method to handle events for the WindowListener interface.
488: * @param e java.awt.event.WindowEvent
489: */
490: public void windowDeiconified(java.awt.event.WindowEvent e) {
491: }
492:
493: /**
494: * Method to handle events for the WindowListener interface.
495: * @param e java.awt.event.WindowEvent
496: */
497: public void windowIconified(java.awt.event.WindowEvent e) {
498: }
499:
500: /**
501: * Method to handle events for the WindowListener interface.
502: * @param e java.awt.event.WindowEvent
503: */
504: public void windowOpened(java.awt.event.WindowEvent e) {
505: okButton.requestFocus();
506: }
507:
508: public void changedUpdate(DocumentEvent e) {
509: }
510:
511: public void insertUpdate(DocumentEvent e) {
512: if (nameField.getText().length() > 0
513: && versionField.getText().length() > 0) {
514: okButton.setEnabled(true);
515: } else {
516: okButton.setEnabled(false);
517: }
518: }
519:
520: public void removeUpdate(DocumentEvent e) {
521: if (nameField.getText().length() > 0
522: && versionField.getText().length() > 0) {
523: okButton.setEnabled(true);
524: } else {
525: okButton.setEnabled(false);
526: }
527: }
528:
529: public String getProductName() {
530: return nameField.getText();
531: }
532:
533: public String getProductVersion() {
534: return versionField.getText();
535: }
536:
537: public String getProductDirectory() {
538: return directoryField.getText();
539: }
540:
541: public String getProductType() {
542: return "install";
543: }
544:
545: }
|