0001: /*
0002: * $RCSfile: VAIBuilderController.java,v $
0003: * @modification $Date: 2001/09/28 19:27:49 $
0004: * @version $Id: VAIBuilderController.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
0005: *
0006: */
0007:
0008: package com.memoire.vainstall.builder;
0009:
0010: import com.memoire.vainstall.*;
0011: import com.memoire.vainstall.builder.action.*;
0012: import com.memoire.vainstall.builder.event.*;
0013: import com.memoire.vainstall.builder.gui.*;
0014: import com.memoire.vainstall.builder.util.VAInstallTheme;
0015:
0016: import java.awt.*;
0017: import java.awt.event.*;
0018: import java.io.File;
0019: import java.util.Hashtable;
0020: import java.util.Iterator;
0021: import java.util.Random;
0022:
0023: import javax.swing.*;
0024: import javax.swing.plaf.metal.MetalLookAndFeel;
0025:
0026: /**
0027: * This is the controller that handles the builder main window
0028: * and the datamodel for the builder.
0029: *
0030: * @see com.memoire.vainstall.builder.VABuilderFrame
0031: * @see com.memoire.vainstall.builder.VABuilderModel
0032: *
0033: * @author Henrik Falk
0034: * @version $Id: VAIBuilderController.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
0035: */
0036: public class VAIBuilderController implements WindowListener,
0037: VAIBuilderListener, VAIProductListener {
0038:
0039: /**
0040: * The main window for the builder
0041: */
0042: VAIBuilderFrame frame;
0043:
0044: /**
0045: * The menubar
0046: */
0047: JMenuBar menuBar = null;
0048:
0049: /**
0050: * The toolbar
0051: */
0052: JToolBar toolBar = null;
0053:
0054: /**
0055: * The builder datamodel
0056: */
0057: VAIBuilderModel model = new VAIBuilderModel();
0058:
0059: /**
0060: * List of actions that are used for menu items, buttons etc.
0061: */
0062: private Hashtable actionList = new Hashtable();
0063:
0064: /**
0065: * List of menu items and toolbar items
0066: */
0067: private Hashtable itemList = new Hashtable();
0068:
0069: private Hashtable productControllerList = new Hashtable();
0070:
0071: private VAIProductController activeProductController = null;
0072:
0073: private Random random;
0074:
0075: /**
0076: * Constructor
0077: */
0078: public VAIBuilderController() {
0079: super ();
0080: initialize();
0081: }
0082:
0083: /**
0084: * Initialize the controller and construct the various
0085: * actions, menus etc.
0086: */
0087: public void initialize() {
0088:
0089: MetalLookAndFeel.setCurrentTheme(new VAInstallTheme());
0090:
0091: // load builder preferences
0092: model.load();
0093:
0094: // initialize actionlist
0095: getActionList();
0096:
0097: // setup tooltip manager for the application
0098: ToolTipManager.sharedInstance().setInitialDelay(0);
0099: ToolTipManager.sharedInstance().setReshowDelay(0);
0100: ToolTipManager.sharedInstance().setDismissDelay(7000);
0101:
0102: // create main window
0103: frame = new VAIBuilderFrame();
0104:
0105: // initialize the tree view(project data) in the mainwindow
0106: // frame.getStepsTree().setCellRenderer(new NodeTreeCellRenderer());
0107: // frame.getStepsTree().addTreeSelectionListener(this);
0108:
0109: // add Menubar
0110: frame.setJMenuBar(getMenuBar());
0111:
0112: // add Toolbar
0113: frame.setJToolBar(getToolBar());
0114:
0115: frame.addWindowListener(this );
0116:
0117: // set bounds from properties
0118: if (getModel().getWindowList().get("VAIBuilderFrame") == null) {
0119: frame.setSize(740, 600);
0120: frame.center();
0121: } else {
0122: frame.setBounds((Rectangle) getModel().getWindowList().get(
0123: "VAIBuilderFrame"));
0124: }
0125:
0126: // initialize model
0127: model.addVAIBuilderListener(this );
0128: model.load();
0129:
0130: // set information
0131: frame.setTitle(VAGlobals.NAME + " Builder - v"
0132: + VAGlobals.VERSION);
0133: setInformationText(VAGlobals.getResource(
0134: "com.memoire.vainstall.builder.Language",
0135: "Information_Ready"));
0136:
0137: // show the main window
0138: frame.setVisible(true);
0139: }
0140:
0141: /**
0142: * Returns the list of action items used for buttons and menus
0143: * @return a Hashtable of action items used for buttons and menus as <action name, reference>
0144: */
0145: public Hashtable getActionList() {
0146:
0147: if (actionList.size() == 0) {
0148:
0149: // NewProductAction
0150: NewProductAction newProductAction = new NewProductAction();
0151: newProductAction.initialize(this );
0152: actionList.put("NewProductAction", newProductAction);
0153:
0154: // OpenProductAction
0155: OpenProductAction openProductAction = new OpenProductAction();
0156: openProductAction.initialize(this );
0157: actionList.put("OpenProductAction", openProductAction);
0158:
0159: // SaveProductAction
0160: SaveProductAction saveProductAction = new SaveProductAction();
0161: saveProductAction.initialize(this );
0162: actionList.put("SaveProductAction", saveProductAction);
0163:
0164: // SaveAllProductAction
0165: SaveAllProductAction saveAllProductAction = new SaveAllProductAction();
0166: saveAllProductAction.initialize(this );
0167: actionList
0168: .put("SaveAllProductAction", saveAllProductAction);
0169:
0170: // CloseProductAction
0171: CloseProductAction closeProductAction = new CloseProductAction();
0172: closeProductAction.initialize(this );
0173: actionList.put("CloseProductAction", closeProductAction);
0174:
0175: // last opened project 1
0176: LastOpenProductAction lastOpen1ProductAction = new LastOpenProductAction();
0177: lastOpen1ProductAction.initialize(this , 0);
0178: actionList.put("LastOpen1ProductAction",
0179: lastOpen1ProductAction);
0180:
0181: // last opened project 2
0182: LastOpenProductAction lastOpen2ProductAction = new LastOpenProductAction();
0183: lastOpen2ProductAction.initialize(this , 1);
0184: actionList.put("LastOpen2ProductAction",
0185: lastOpen2ProductAction);
0186:
0187: // last opened project 3
0188: LastOpenProductAction lastOpen3ProductAction = new LastOpenProductAction();
0189: lastOpen3ProductAction.initialize(this , 2);
0190: actionList.put("LastOpen3ProductAction",
0191: lastOpen3ProductAction);
0192:
0193: // last opened project 4
0194: LastOpenProductAction lastOpen4ProductAction = new LastOpenProductAction();
0195: lastOpen4ProductAction.initialize(this , 3);
0196: actionList.put("LastOpen4ProductAction",
0197: lastOpen4ProductAction);
0198:
0199: // last opened project 5
0200: LastOpenProductAction lastOpen5ProductAction = new LastOpenProductAction();
0201: lastOpen5ProductAction.initialize(this , 4);
0202: actionList.put("LastOpen5ProductAction",
0203: lastOpen5ProductAction);
0204:
0205: // PreferencesAction
0206: PreferencesAction preferencesAction = new PreferencesAction();
0207: preferencesAction.initialize(this );
0208: actionList.put("PreferencesAction", preferencesAction);
0209:
0210: // QuitAction
0211: QuitAction quitAction = new QuitAction();
0212: quitAction.initialize(this );
0213: actionList.put("QuitAction", quitAction);
0214:
0215: // ShowRequirementsAction
0216: ShowRequirementsAction showRequirementsAction = new ShowRequirementsAction();
0217: showRequirementsAction.initialize(this );
0218: actionList.put("ShowRequirementsAction",
0219: showRequirementsAction);
0220:
0221: // CascadeWindowsAction
0222: CascadeWindowsAction cascadeWindowsAction = new CascadeWindowsAction();
0223: cascadeWindowsAction.initialize(this );
0224: actionList
0225: .put("CascadeWindowsAction", cascadeWindowsAction);
0226:
0227: // TileWindowsHorizontalAction
0228: TileWindowsHorizontalAction tileWindowsHorizontalAction = new TileWindowsHorizontalAction();
0229: tileWindowsHorizontalAction.initialize(this );
0230: actionList.put("TileWindowsHorizontalAction",
0231: tileWindowsHorizontalAction);
0232:
0233: // TileWindowsVerticalAction
0234: TileWindowsVerticalAction tileWindowsVerticalAction = new TileWindowsVerticalAction();
0235: tileWindowsVerticalAction.initialize(this );
0236: actionList.put("TileWindowsVerticalAction",
0237: tileWindowsVerticalAction);
0238:
0239: // AboutAction
0240: AboutAction aboutAction = new AboutAction();
0241: aboutAction.initialize(this );
0242: actionList.put("AboutAction", aboutAction);
0243:
0244: }
0245:
0246: return actionList;
0247: }
0248:
0249: /**
0250: * Returns the list of menu and button items.
0251: * The list is used when the state of the application changes
0252: * and items has to be enabled and disabled.
0253: * @return a Hashtable of items used for buttons and menus as <itemname, reference>
0254: */
0255: public Hashtable getItemList() {
0256: return itemList;
0257: }
0258:
0259: /**
0260: * Returns the datamodel(preferences) of the builder
0261: * @return a VAIBuilderModel which contains the builder preferences data
0262: */
0263: public VAIBuilderModel getModel() {
0264: return model;
0265: }
0266:
0267: public VAIProductController getActiveProductController() {
0268: return activeProductController;
0269: }
0270:
0271: public Hashtable getProductControllerList() {
0272: return productControllerList;
0273: }
0274:
0275: /**
0276: * Returns a handle to the builder mainwindow.
0277: * This method are needed to track the mainwindow bounds
0278: * when the application closes.
0279: *
0280: * @return a reference to the main window of the builder
0281: * @see com.memoire.vainstall.builder.action.QuitAction
0282: */
0283: public JFrame getFrame() {
0284: return frame;
0285: }
0286:
0287: /**
0288: * Method to handle events for the WindowListener interface.
0289: * @param e java.awt.event.WindowEvent
0290: */
0291: public void windowActivated(java.awt.event.WindowEvent e) {
0292: }
0293:
0294: /**
0295: * Method to handle events for the WindowListener interface.
0296: * @param e java.awt.event.WindowEvent
0297: */
0298: public void windowClosed(java.awt.event.WindowEvent e) {
0299: }
0300:
0301: /**
0302: * Method to handle events for the WindowListener interface.
0303: * @param e java.awt.event.WindowEvent
0304: */
0305: public void windowClosing(java.awt.event.WindowEvent e) {
0306:
0307: AbstractVAIBuilderAction action = (AbstractVAIBuilderAction) getActionList()
0308: .get("QuitAction");
0309: action.runnit();
0310: }
0311:
0312: /**
0313: * Method to handle events for the WindowListener interface.
0314: * @param e java.awt.event.WindowEvent
0315: */
0316: public void windowDeactivated(java.awt.event.WindowEvent e) {
0317: }
0318:
0319: /**
0320: * Method to handle events for the WindowListener interface.
0321: * @param e java.awt.event.WindowEvent
0322: */
0323: public void windowDeiconified(java.awt.event.WindowEvent e) {
0324: }
0325:
0326: /**
0327: * Method to handle events for the WindowListener interface.
0328: * @param e java.awt.event.WindowEvent
0329: */
0330: public void windowIconified(java.awt.event.WindowEvent e) {
0331: }
0332:
0333: /**
0334: * Method to handle events for the WindowListener interface.
0335: * @param e java.awt.event.WindowEvent
0336: */
0337: public void windowOpened(java.awt.event.WindowEvent e) {
0338: }
0339:
0340: /**
0341: * Method to handle events for the VAIBuilderListener interface.
0342: * @param evt com.memoire.vainstall.builder.event.VAIBuilderEvent
0343: */
0344: public void builderChanged(VAIBuilderEvent evt) {
0345:
0346: switch (evt.getType()) {
0347: case VAIBuilderEvent.PREFERENCES_LOADED:
0348: ((AbstractButton) getItemList().get("NewProductItem"))
0349: .setEnabled(true);
0350: ((AbstractButton) getItemList().get("OpenProductItem"))
0351: .setEnabled(true);
0352:
0353: ((AbstractButton) getItemList().get("NewProductButton"))
0354: .setEnabled(true);
0355: ((AbstractButton) getItemList().get("OpenProductButton"))
0356: .setEnabled(true);
0357: break;
0358: case VAIBuilderEvent.LASTFILELIST_CHANGED:
0359:
0360: ((JMenuItem) getItemList().get("LastOpen1Product"))
0361: .setVisible(false);
0362: ((JMenuItem) getItemList().get("LastOpen2Product"))
0363: .setVisible(false);
0364: ((JMenuItem) getItemList().get("LastOpen3Product"))
0365: .setVisible(false);
0366: ((JMenuItem) getItemList().get("LastOpen4Product"))
0367: .setVisible(false);
0368: ((JMenuItem) getItemList().get("LastOpen5Product"))
0369: .setVisible(false);
0370:
0371: for (int k = 0; k < getModel().getLastOpenedProjectList()
0372: .size(); k++) {
0373: String itemString = String.valueOf(k + 1) + " "
0374: + getModel().getLastOpenedProjectList().get(k);
0375: JMenuItem item = ((JMenu) getItemList().get("FileMenu"))
0376: .getItem(8 + k);
0377: item.setText(itemString);
0378: item.setVisible(true);
0379: }
0380: if (((JMenu) getItemList().get("FileMenu")).getItem(13) != null
0381: && getModel().getLastOpenedProjectList().size() > 0) {
0382: ((JMenu) getItemList().get("FileMenu"))
0383: .insertSeparator(13);
0384: }
0385:
0386: if (((JMenuItem) getItemList().get("LastOpen1Product"))
0387: .isVisible() == false) {
0388: ((JMenu) getItemList().get("FileMenu")).remove(9);
0389: }
0390:
0391: break;
0392: }
0393: }
0394:
0395: private JMenuBar getMenuBar() {
0396:
0397: if (menuBar == null) {
0398:
0399: menuBar = new JMenuBar();
0400:
0401: // The File menu
0402: JMenu fileMenu = new JMenu();
0403: fileMenu.setText(VAGlobals.getResource(
0404: "com.memoire.vainstall.builder.Language",
0405: "Menu_File"));
0406: fileMenu.setMnemonic(VAGlobals.getResourceInt(
0407: "com.memoire.vainstall.builder.Language",
0408: "Menu_File_M"));
0409: getItemList().put("FileMenu", fileMenu);
0410:
0411: // 0
0412: JMenuItem newProductItem = new JMenuItem();
0413: newProductItem.setText(VAGlobals.getResource(
0414: "com.memoire.vainstall.builder.Language",
0415: "Menu_FileNew"));
0416: newProductItem
0417: .setIcon(new javax.swing.ImageIcon(
0418: getClass()
0419: .getResource(
0420: "/com/memoire/vainstall/builder/images/New16.gif")));
0421: newProductItem.setMnemonic(VAGlobals.getResourceInt(
0422: "com.memoire.vainstall.builder.Language",
0423: "Menu_FileNew_M"));
0424: newProductItem.setEnabled(false);
0425: newProductItem
0426: .addActionListener((AbstractVAIBuilderAction) getActionList()
0427: .get("NewProductAction"));
0428: getItemList().put("NewProductItem", newProductItem);
0429: fileMenu.add(newProductItem);
0430:
0431: // 1
0432: JMenuItem openProductItem = new JMenuItem();
0433: openProductItem.setText(VAGlobals.getResource(
0434: "com.memoire.vainstall.builder.Language",
0435: "Menu_FileOpen"));
0436: openProductItem
0437: .setIcon(new javax.swing.ImageIcon(
0438: getClass()
0439: .getResource(
0440: "/com/memoire/vainstall/builder/images/Open16.gif")));
0441: openProductItem.setMnemonic(VAGlobals.getResourceInt(
0442: "com.memoire.vainstall.builder.Language",
0443: "Menu_FileOpen_M"));
0444: openProductItem.setAccelerator(KeyStroke.getKeyStroke(
0445: KeyEvent.VK_O, ActionEvent.CTRL_MASK));
0446: openProductItem.setEnabled(false);
0447: openProductItem
0448: .addActionListener((AbstractVAIBuilderAction) getActionList()
0449: .get("OpenProductAction"));
0450: getItemList().put("OpenProductItem", openProductItem);
0451: fileMenu.add(openProductItem);
0452:
0453: // 2
0454: fileMenu.addSeparator();
0455:
0456: // 3
0457: JMenuItem saveProductItem = new JMenuItem();
0458: saveProductItem.setText(VAGlobals.getResource(
0459: "com.memoire.vainstall.builder.Language",
0460: "Menu_FileSave"));
0461: saveProductItem
0462: .setIcon(new javax.swing.ImageIcon(
0463: getClass()
0464: .getResource(
0465: "/com/memoire/vainstall/builder/images/Save16.gif")));
0466: saveProductItem.setMnemonic(VAGlobals.getResourceInt(
0467: "com.memoire.vainstall.builder.Language",
0468: "Menu_FileSave_M"));
0469: saveProductItem.setAccelerator(KeyStroke.getKeyStroke(
0470: KeyEvent.VK_C, ActionEvent.CTRL_MASK));
0471: saveProductItem.setEnabled(false);
0472: saveProductItem
0473: .addActionListener((AbstractVAIBuilderAction) getActionList()
0474: .get("SaveProductAction"));
0475: getItemList().put("SaveProductItem", saveProductItem);
0476: fileMenu.add(saveProductItem);
0477:
0478: // 4
0479: JMenuItem saveAllProductItem = new JMenuItem();
0480: saveAllProductItem.setText(VAGlobals.getResource(
0481: "com.memoire.vainstall.builder.Language",
0482: "Menu_FileSaveAll"));
0483: // saveAllProductItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/memoire/vainstall/builder/images/Save16.gif")));
0484: saveAllProductItem.setMnemonic(VAGlobals.getResourceInt(
0485: "com.memoire.vainstall.builder.Language",
0486: "Menu_FileSaveAll_M"));
0487: // saveAllProductItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
0488: saveAllProductItem.setEnabled(false);
0489: saveAllProductItem
0490: .addActionListener((AbstractVAIBuilderAction) getActionList()
0491: .get("SaveAllProductAction"));
0492: getItemList().put("SaveAllProductItem", saveAllProductItem);
0493: fileMenu.add(saveAllProductItem);
0494:
0495: // 5
0496: fileMenu.addSeparator();
0497:
0498: // 6
0499: JMenuItem closeProductItem = new JMenuItem();
0500: closeProductItem.setText(VAGlobals.getResource(
0501: "com.memoire.vainstall.builder.Language",
0502: "Menu_FileClose"));
0503: // closeProductItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/memoire/vainstall/builder/images/Save16.gif")));
0504: closeProductItem.setMnemonic(VAGlobals.getResourceInt(
0505: "com.memoire.vainstall.builder.Language",
0506: "Menu_FileClose_M"));
0507: // closeProductItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
0508: closeProductItem.setEnabled(false);
0509: closeProductItem
0510: .addActionListener((AbstractVAIBuilderAction) getActionList()
0511: .get("CloseProductAction"));
0512: getItemList().put("CloseProductItem", closeProductItem);
0513: fileMenu.add(closeProductItem);
0514:
0515: // 7
0516: fileMenu.addSeparator();
0517:
0518: // 8
0519: JMenuItem lastOpen1Product = new JMenuItem();
0520: lastOpen1Product.setMnemonic('1');
0521: lastOpen1Product.setVisible(false);
0522: lastOpen1Product
0523: .addActionListener((AbstractVAIBuilderAction) getActionList()
0524: .get("LastOpen1ProductAction"));
0525: getItemList().put("LastOpen1Product", lastOpen1Product);
0526: fileMenu.add(lastOpen1Product);
0527:
0528: // 9
0529: JMenuItem lastOpen2Product = new JMenuItem();
0530: lastOpen2Product.setMnemonic('2');
0531: lastOpen2Product.setVisible(false);
0532: lastOpen2Product
0533: .addActionListener((AbstractVAIBuilderAction) getActionList()
0534: .get("LastOpen2ProductAction"));
0535: getItemList().put("LastOpen2Product", lastOpen2Product);
0536: fileMenu.add(lastOpen2Product);
0537:
0538: // 10
0539: JMenuItem lastOpen3Product = new JMenuItem();
0540: lastOpen3Product.setMnemonic('3');
0541: lastOpen3Product.setVisible(false);
0542: lastOpen3Product
0543: .addActionListener((AbstractVAIBuilderAction) getActionList()
0544: .get("LastOpen3ProductAction"));
0545: getItemList().put("LastOpen3Product", lastOpen3Product);
0546: fileMenu.add(lastOpen3Product);
0547:
0548: // 11
0549: JMenuItem lastOpen4Product = new JMenuItem();
0550: lastOpen4Product.setMnemonic('4');
0551: lastOpen4Product.setVisible(false);
0552: lastOpen4Product
0553: .addActionListener((AbstractVAIBuilderAction) getActionList()
0554: .get("LastOpen4ProductAction"));
0555: getItemList().put("LastOpen4Product", lastOpen4Product);
0556: fileMenu.add(lastOpen4Product);
0557:
0558: // 12
0559: JMenuItem lastOpen5Product = new JMenuItem();
0560: lastOpen5Product.setMnemonic('5');
0561: lastOpen5Product.setVisible(false);
0562: lastOpen5Product
0563: .addActionListener((AbstractVAIBuilderAction) getActionList()
0564: .get("LastOpen5ProductAction"));
0565: getItemList().put("LastOpen5Product", lastOpen5Product);
0566: fileMenu.add(lastOpen5Product);
0567:
0568: // 13
0569: // dynamically added fileMenu.addSeparator();
0570:
0571: // 14
0572: JMenuItem preferencesItem = new JMenuItem();
0573: preferencesItem.setText(VAGlobals.getResource(
0574: "com.memoire.vainstall.builder.Language",
0575: "Menu_FilePreferences"));
0576: preferencesItem.setMnemonic(VAGlobals.getResourceInt(
0577: "com.memoire.vainstall.builder.Language",
0578: "Menu_FilePreferences_M"));
0579: preferencesItem
0580: .addActionListener((AbstractVAIBuilderAction) getActionList()
0581: .get("PreferencesAction"));
0582: getItemList().put("PreferencesItem", preferencesItem);
0583: fileMenu.add(preferencesItem);
0584:
0585: // 15
0586: fileMenu.addSeparator();
0587:
0588: // 16
0589: JMenuItem quitItem = new JMenuItem();
0590: quitItem.setText(VAGlobals.getResource(
0591: "com.memoire.vainstall.builder.Language",
0592: "Menu_FileQuit"));
0593: quitItem.setMnemonic(VAGlobals.getResourceInt(
0594: "com.memoire.vainstall.builder.Language",
0595: "Menu_FileQuit_M"));
0596: quitItem
0597: .addActionListener((AbstractVAIBuilderAction) getActionList()
0598: .get("QuitAction"));
0599: getItemList().put("QuitItem", quitItem);
0600: fileMenu.add(quitItem);
0601:
0602: menuBar.add(fileMenu);
0603:
0604: // The Tools menu
0605: JMenu toolsMenu = new JMenu();
0606: toolsMenu.setText(VAGlobals.getResource(
0607: "com.memoire.vainstall.builder.Language",
0608: "Menu_Tools"));
0609: toolsMenu.setMnemonic(VAGlobals.getResourceInt(
0610: "com.memoire.vainstall.builder.Language",
0611: "Menu_Tools_M"));
0612:
0613: JMenuItem showRequirementsItem = new JMenuItem();
0614: showRequirementsItem.setText(VAGlobals.getResource(
0615: "com.memoire.vainstall.builder.Language",
0616: "Menu_ToolsShowRequirements"));
0617: showRequirementsItem.setMnemonic(VAGlobals.getResourceInt(
0618: "com.memoire.vainstall.builder.Language",
0619: "Menu_ToolsShowRequirements_M"));
0620: showRequirementsItem.setEnabled(false);
0621: showRequirementsItem
0622: .addActionListener((AbstractVAIBuilderAction) getActionList()
0623: .get("ShowRequirementsAction"));
0624: getItemList().put("ShowRequirementsItem",
0625: showRequirementsItem);
0626: toolsMenu.add(showRequirementsItem);
0627:
0628: toolsMenu.addSeparator();
0629:
0630: JMenuItem exportOldItem = new JMenuItem();
0631: exportOldItem.setText(VAGlobals.getResource(
0632: "com.memoire.vainstall.builder.Language",
0633: "Menu_ToolsExportOld"));
0634: exportOldItem.setMnemonic(VAGlobals.getResourceInt(
0635: "com.memoire.vainstall.builder.Language",
0636: "Menu_ToolsExportOld_M"));
0637: exportOldItem.setEnabled(false);
0638: // exportOldItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("AboutAction"));
0639: getItemList().put("ExportOldItem", exportOldItem);
0640: toolsMenu.add(exportOldItem);
0641:
0642: menuBar.add(toolsMenu);
0643:
0644: // The Window menu
0645: JMenu windowMenu = new JMenu();
0646: windowMenu.setText(VAGlobals.getResource(
0647: "com.memoire.vainstall.builder.Language",
0648: "Menu_Window"));
0649: windowMenu.setMnemonic(VAGlobals.getResourceInt(
0650: "com.memoire.vainstall.builder.Language",
0651: "Menu_Window_M"));
0652: getItemList().put("WindowMenu", windowMenu);
0653:
0654: JMenuItem cascadeWindowsItem = new JMenuItem();
0655: cascadeWindowsItem.setText(VAGlobals.getResource(
0656: "com.memoire.vainstall.builder.Language",
0657: "Menu_CascadeWindows"));
0658: cascadeWindowsItem.setMnemonic(VAGlobals.getResourceInt(
0659: "com.memoire.vainstall.builder.Language",
0660: "Menu_CascadeWindows_M"));
0661: cascadeWindowsItem
0662: .addActionListener((AbstractVAIBuilderAction) getActionList()
0663: .get("CascadeWindowsAction"));
0664: cascadeWindowsItem.setEnabled(false);
0665: getItemList().put("CascadeWindowsItem", cascadeWindowsItem);
0666: windowMenu.add(cascadeWindowsItem);
0667:
0668: JMenuItem tileWindowsHorizontalItem = new JMenuItem();
0669: tileWindowsHorizontalItem.setText(VAGlobals.getResource(
0670: "com.memoire.vainstall.builder.Language",
0671: "Menu_TileWindowsHorizontal"));
0672: tileWindowsHorizontalItem.setMnemonic(VAGlobals
0673: .getResourceInt(
0674: "com.memoire.vainstall.builder.Language",
0675: "Menu_TileWindowsHorizontal_M"));
0676: tileWindowsHorizontalItem
0677: .addActionListener((AbstractVAIBuilderAction) getActionList()
0678: .get("TileWindowsHorizontalAction"));
0679: tileWindowsHorizontalItem.setEnabled(false);
0680: getItemList().put("TileWindowsHorizontalItem",
0681: tileWindowsHorizontalItem);
0682: windowMenu.add(tileWindowsHorizontalItem);
0683:
0684: JMenuItem tileWindowsVerticalItem = new JMenuItem();
0685: tileWindowsVerticalItem.setText(VAGlobals.getResource(
0686: "com.memoire.vainstall.builder.Language",
0687: "Menu_TileWindowsVertical"));
0688: tileWindowsVerticalItem.setMnemonic(VAGlobals
0689: .getResourceInt(
0690: "com.memoire.vainstall.builder.Language",
0691: "Menu_TileWindowsVertical_M"));
0692: tileWindowsVerticalItem
0693: .addActionListener((AbstractVAIBuilderAction) getActionList()
0694: .get("TileWindowsVerticalAction"));
0695: tileWindowsVerticalItem.setEnabled(false);
0696: getItemList().put("TileWindowsVerticalItem",
0697: tileWindowsVerticalItem);
0698: windowMenu.add(tileWindowsVerticalItem);
0699:
0700: menuBar.add(windowMenu);
0701:
0702: // The Help menu
0703: JMenu helpMenu = new JMenu();
0704: helpMenu.setText(VAGlobals.getResource(
0705: "com.memoire.vainstall.builder.Language",
0706: "Menu_Help"));
0707: helpMenu.setMnemonic(VAGlobals.getResourceInt(
0708: "com.memoire.vainstall.builder.Language",
0709: "Menu_Help_M"));
0710:
0711: JMenuItem aboutItem = new JMenuItem();
0712: aboutItem.setText(VAGlobals.getResource(
0713: "com.memoire.vainstall.builder.Language",
0714: "Menu_HelpAbout"));
0715: aboutItem.setMnemonic(VAGlobals.getResourceInt(
0716: "com.memoire.vainstall.builder.Language",
0717: "Menu_HelpAbout_M"));
0718: aboutItem
0719: .addActionListener((AbstractVAIBuilderAction) getActionList()
0720: .get("AboutAction"));
0721: getItemList().put("AboutItem", aboutItem);
0722: helpMenu.add(aboutItem);
0723:
0724: menuBar.add(helpMenu);
0725:
0726: }
0727:
0728: return menuBar;
0729: }
0730:
0731: private JToolBar getToolBar() {
0732:
0733: if (toolBar == null) {
0734:
0735: toolBar = new JToolBar();
0736: toolBar.setFloatable(false);
0737: toolBar.setBorderPainted(true);
0738:
0739: JButton newProductButton = new JButton(
0740: new javax.swing.ImageIcon(
0741: getClass()
0742: .getResource(
0743: "/com/memoire/vainstall/builder/images/New16.gif")));
0744: newProductButton
0745: .addActionListener((AbstractVAIBuilderAction) getActionList()
0746: .get("NewProductAction"));
0747: newProductButton.setToolTipText(VAGlobals.getResource(
0748: "com.memoire.vainstall.builder.Language",
0749: "ToolBarButton_New"));
0750: newProductButton.setEnabled(false);
0751: itemList.put("NewProductButton", newProductButton);
0752: toolBar.add(newProductButton);
0753:
0754: JButton openProductButton = new JButton(
0755: new javax.swing.ImageIcon(
0756: getClass()
0757: .getResource(
0758: "/com/memoire/vainstall/builder/images/Open16.gif")));
0759: openProductButton
0760: .addActionListener((AbstractVAIBuilderAction) getActionList()
0761: .get("OpenProductAction"));
0762: openProductButton.setToolTipText(VAGlobals.getResource(
0763: "com.memoire.vainstall.builder.Language",
0764: "ToolBarButton_Open"));
0765: openProductButton.setEnabled(false);
0766: itemList.put("OpenProductButton", openProductButton);
0767: toolBar.add(openProductButton);
0768:
0769: toolBar.addSeparator();
0770:
0771: JButton saveProductButton = new JButton(
0772: new javax.swing.ImageIcon(
0773: getClass()
0774: .getResource(
0775: "/com/memoire/vainstall/builder/images/Save16.gif")));
0776: saveProductButton
0777: .addActionListener((AbstractVAIBuilderAction) getActionList()
0778: .get("SaveProductAction"));
0779: saveProductButton.setToolTipText(VAGlobals.getResource(
0780: "com.memoire.vainstall.builder.Language",
0781: "ToolBarButton_Save"));
0782: saveProductButton.setEnabled(false);
0783: itemList.put("SaveProductButton", saveProductButton);
0784: toolBar.add(saveProductButton);
0785:
0786: }
0787:
0788: return toolBar;
0789: }
0790:
0791: private void setInformationText(String textAsHtml) {
0792: frame
0793: .getInformationLabel()
0794: .setIcon(
0795: new javax.swing.ImageIcon(
0796: getClass()
0797: .getResource(
0798: "/com/memoire/vainstall/builder/images/Information16.gif")));
0799: frame.getInformationLabel().setText(textAsHtml);
0800: }
0801:
0802: public void setTipOfTheDay() {
0803:
0804: String numTips = VAGlobals.getResource(
0805: "com.memoire.vainstall.builder.Language", "Tip_0");
0806:
0807: int num = 1;
0808:
0809: try {
0810: num = Integer.parseInt(numTips);
0811: } catch (NumberFormatException exc) {
0812: num = 1;
0813: }
0814:
0815: if (random == null) {
0816: long l = System.currentTimeMillis();
0817: random = new Random(l);
0818: }
0819:
0820: float floatCount = random.nextFloat();
0821: int tipNumber = (int) (floatCount * num) + 1;
0822:
0823: String text = VAGlobals.getResource(
0824: "com.memoire.vainstall.builder.Language", "Tip_"
0825: + String.valueOf(tipNumber));
0826:
0827: String textAsHtml = text;
0828: textAsHtml = "<html><b><font color=black size=1><center>"
0829: + text + "</center></font></b></html>";
0830: frame
0831: .getInformationLabel()
0832: .setIcon(
0833: new javax.swing.ImageIcon(
0834: getClass()
0835: .getResource(
0836: "/com/memoire/vainstall/builder/images/TipOfTheDay16.gif")));
0837: frame.getInformationLabel().setText(textAsHtml);
0838: }
0839:
0840: public void addProduct(String id,
0841: VAIProductController productController) {
0842:
0843: productController.getModel().addVAIProductListener(this );
0844:
0845: try {
0846: frame.getDesktopPane().add(productController.getFrame(),
0847: JLayeredPane.DEFAULT_LAYER);
0848: productController.getFrame().setVisible(true);
0849: productController.getFrame().setSelected(true);
0850: productController.getFrame().setMaximum(true);
0851: productController.getFrame().setNormalBounds(
0852: new Rectangle(0, 0, 400, 300));
0853:
0854: } catch (Exception exc) {
0855: exc.printStackTrace();
0856: return;
0857: }
0858: productControllerList.put(id, productController);
0859:
0860: getModel().addLastOpenedProject(
0861: productController.getModel().getProductDirectory()
0862: + File.separator + "vainstall.xml");
0863:
0864: JMenu windowMenu = (JMenu) getItemList().get("WindowMenu");
0865: if (windowMenu.getItemCount() == 3) {
0866: windowMenu.addSeparator();
0867: }
0868: JMenuItem item = new JMenuItem(id + File.separator
0869: + "vainstall.xml");
0870: item.addActionListener(productController);
0871: windowMenu.add(item);
0872:
0873: if (productControllerList.size() > 1) {
0874: ((AbstractButton) getItemList().get("CascadeWindowsItem"))
0875: .setEnabled(true);
0876: ((AbstractButton) getItemList().get(
0877: "TileWindowsHorizontalItem")).setEnabled(true);
0878: ((AbstractButton) getItemList().get(
0879: "TileWindowsVerticalItem")).setEnabled(true);
0880: }
0881:
0882: // set tip of the day
0883: setTipOfTheDay();
0884: }
0885:
0886: public void removeProduct(String id) {
0887: VAIProductController productController = (VAIProductController) productControllerList
0888: .get(id);
0889:
0890: productController.getFrame().setVisible(false);
0891: productController.getModel().removeVAIProductListener(this );
0892:
0893: frame.getDesktopPane().remove(productController.getFrame());
0894: getModel().fireVAIBuilderEvent(
0895: new VAIBuilderEvent(this ,
0896: VAIBuilderEvent.PROJECT_DEACTIVATED));
0897:
0898: productControllerList.remove(id);
0899:
0900: JMenu windowMenu = (JMenu) getItemList().get("WindowMenu");
0901:
0902: for (int i = 0; i < windowMenu.getItemCount(); i++) {
0903: try {
0904: if (windowMenu.getItem(i).getText() != null
0905: && windowMenu.getItem(i).getText().equals(
0906: id + File.separator + "vainstall.xml") == true) {
0907: windowMenu.remove(i);
0908: }
0909: } catch (NullPointerException exc) {
0910: // should return null
0911: }
0912: }
0913:
0914: if (windowMenu.getItemCount() == 4) {
0915: windowMenu.remove(3);
0916: }
0917:
0918: if (productControllerList.size() < 2) {
0919: ((AbstractButton) getItemList().get("CascadeWindowsItem"))
0920: .setEnabled(false);
0921: ((AbstractButton) getItemList().get(
0922: "TileWindowsHorizontalItem")).setEnabled(false);
0923: ((AbstractButton) getItemList().get(
0924: "TileWindowsVerticalItem")).setEnabled(false);
0925: }
0926:
0927: // fix event handling
0928: ((AbstractButton) getItemList().get("CloseProductItem"))
0929: .setEnabled(false);
0930: if (productControllerList.size() == 0) {
0931: ((AbstractButton) getItemList().get("ShowRequirementsItem"))
0932: .setEnabled(false);
0933: }
0934: }
0935:
0936: public void productChanged(VAIProductEvent evt) {
0937:
0938: switch (evt.getType()) {
0939: case VAIProductEvent.PROJECT_ACTIVATED:
0940: activeProductController = (VAIProductController) evt
0941: .getSource();
0942: if (activeProductController.isDirty() == true) {
0943: ((AbstractButton) getItemList().get("SaveProductItem"))
0944: .setEnabled(true);
0945: ((AbstractButton) getItemList()
0946: .get("SaveProductButton")).setEnabled(true);
0947: } else {
0948: ((AbstractButton) getItemList().get("SaveProductItem"))
0949: .setEnabled(false);
0950: ((AbstractButton) getItemList()
0951: .get("SaveProductButton")).setEnabled(false);
0952: }
0953: ((AbstractButton) getItemList().get("CloseProductItem"))
0954: .setEnabled(true);
0955:
0956: getModel().fireVAIBuilderEvent(
0957: new VAIBuilderEvent(this ,
0958: VAIBuilderEvent.PROJECT_ACTIVATED));
0959: break;
0960: case VAIProductEvent.PROJECT_DEACTIVATED:
0961: activeProductController = null;
0962: ((AbstractButton) getItemList().get("SaveProductItem"))
0963: .setEnabled(false);
0964: ((AbstractButton) getItemList().get("SaveProductButton"))
0965: .setEnabled(false);
0966: ((AbstractButton) getItemList().get("CloseProductItem"))
0967: .setEnabled(false);
0968: getModel().fireVAIBuilderEvent(
0969: new VAIBuilderEvent(this ,
0970: VAIBuilderEvent.PROJECT_DEACTIVATED));
0971: break;
0972: case VAIProductEvent.PROJECT_DIRTY:
0973: ((AbstractButton) getItemList().get("SaveProductItem"))
0974: .setEnabled(true);
0975: ((AbstractButton) getItemList().get("SaveProductButton"))
0976: .setEnabled(true);
0977: ((AbstractButton) getItemList().get("SaveAllProductItem"))
0978: .setEnabled(true);
0979: ((AbstractButton) getItemList().get("ExportOldItem"))
0980: .setEnabled(false);
0981: break;
0982: case VAIProductEvent.PROJECT_SAVED:
0983: ((AbstractButton) getItemList().get("SaveProductItem"))
0984: .setEnabled(false);
0985: ((AbstractButton) getItemList().get("SaveProductButton"))
0986: .setEnabled(false);
0987:
0988: // test is 'save all' should be enabled/disabled
0989: boolean saveAll = false;
0990: Iterator iterator = productControllerList.values()
0991: .iterator();
0992: while (iterator.hasNext() == true) {
0993: VAIProductController productController = (VAIProductController) iterator
0994: .next();
0995: if (productController.isDirty() == true) {
0996: saveAll = true;
0997: }
0998: }
0999: if (saveAll == true) {
1000: ((AbstractButton) getItemList().get(
1001: "SaveAllProductItem")).setEnabled(true);
1002: } else {
1003: ((AbstractButton) getItemList().get(
1004: "SaveAllProductItem")).setEnabled(false);
1005: }
1006: break;
1007: case VAIProductEvent.PROJECT_REQUIREMENTS_MET:
1008: ((AbstractButton) getItemList().get("ShowRequirementsItem"))
1009: .setEnabled(false);
1010: ((AbstractButton) getItemList().get("ExportOldItem"))
1011: .setEnabled(true);
1012: break;
1013: case VAIProductEvent.PROJECT_REQUIREMENTS_NOTMET:
1014: ((AbstractButton) getItemList().get("ShowRequirementsItem"))
1015: .setEnabled(true);
1016: ((AbstractButton) getItemList().get("ExportOldItem"))
1017: .setEnabled(false);
1018: break;
1019: }
1020:
1021: }
1022:
1023: }
|