1 7 8 package com.memoire.vainstall.builder; 9 10 import com.memoire.vainstall.*; 11 import com.memoire.vainstall.builder.action.*; 12 import com.memoire.vainstall.builder.event.*; 13 import com.memoire.vainstall.builder.gui.*; 14 import com.memoire.vainstall.builder.util.VAInstallTheme; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import java.io.File ; 19 import java.util.Hashtable ; 20 import java.util.Iterator ; 21 import java.util.Random ; 22 23 import javax.swing.*; 24 import javax.swing.plaf.metal.MetalLookAndFeel ; 25 26 36 public class VAIBuilderController implements WindowListener, VAIBuilderListener, VAIProductListener { 37 38 41 VAIBuilderFrame frame; 42 43 46 JMenuBar menuBar = null; 47 48 51 JToolBar toolBar = null; 52 53 56 VAIBuilderModel model = new VAIBuilderModel(); 57 58 61 private Hashtable actionList = new Hashtable (); 62 63 66 private Hashtable itemList = new Hashtable (); 67 68 private Hashtable productControllerList = new Hashtable (); 69 70 private VAIProductController activeProductController = null; 71 72 private Random random; 73 74 77 public VAIBuilderController() { 78 super(); 79 initialize(); 80 } 81 82 86 public void initialize() { 87 88 MetalLookAndFeel.setCurrentTheme(new VAInstallTheme()); 89 90 model.load(); 92 93 getActionList(); 95 96 ToolTipManager.sharedInstance().setInitialDelay(0); 98 ToolTipManager.sharedInstance().setReshowDelay(0); 99 ToolTipManager.sharedInstance().setDismissDelay(7000); 100 101 frame = new VAIBuilderFrame(); 103 104 108 frame.setJMenuBar(getMenuBar()); 110 111 frame.setJToolBar(getToolBar()); 113 114 frame.addWindowListener(this); 115 116 if(getModel().getWindowList().get("VAIBuilderFrame") == null ) { 118 frame.setSize(740,600); 119 frame.center(); 120 } else { 121 frame.setBounds((Rectangle)getModel().getWindowList().get("VAIBuilderFrame")); 122 } 123 124 model.addVAIBuilderListener(this); 126 model.load(); 127 128 frame.setTitle(VAGlobals.NAME + " Builder - v" + VAGlobals.VERSION); 130 setInformationText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Information_Ready")); 131 132 frame.setVisible(true); 134 } 135 136 140 public Hashtable getActionList() { 141 142 if(actionList.size() == 0) { 143 144 NewProductAction newProductAction = new NewProductAction(); 146 newProductAction.initialize(this); 147 actionList.put("NewProductAction",newProductAction); 148 149 OpenProductAction openProductAction = new OpenProductAction(); 151 openProductAction.initialize(this); 152 actionList.put("OpenProductAction",openProductAction); 153 154 SaveProductAction saveProductAction = new SaveProductAction(); 156 saveProductAction.initialize(this); 157 actionList.put("SaveProductAction",saveProductAction); 158 159 SaveAllProductAction saveAllProductAction = new SaveAllProductAction(); 161 saveAllProductAction.initialize(this); 162 actionList.put("SaveAllProductAction",saveAllProductAction); 163 164 CloseProductAction closeProductAction = new CloseProductAction(); 166 closeProductAction.initialize(this); 167 actionList.put("CloseProductAction",closeProductAction); 168 169 LastOpenProductAction lastOpen1ProductAction = new LastOpenProductAction(); 171 lastOpen1ProductAction.initialize(this,0); 172 actionList.put("LastOpen1ProductAction",lastOpen1ProductAction); 173 174 LastOpenProductAction lastOpen2ProductAction = new LastOpenProductAction(); 176 lastOpen2ProductAction.initialize(this,1); 177 actionList.put("LastOpen2ProductAction",lastOpen2ProductAction); 178 179 LastOpenProductAction lastOpen3ProductAction = new LastOpenProductAction(); 181 lastOpen3ProductAction.initialize(this,2); 182 actionList.put("LastOpen3ProductAction",lastOpen3ProductAction); 183 184 LastOpenProductAction lastOpen4ProductAction = new LastOpenProductAction(); 186 lastOpen4ProductAction.initialize(this,3); 187 actionList.put("LastOpen4ProductAction",lastOpen4ProductAction); 188 189 LastOpenProductAction lastOpen5ProductAction = new LastOpenProductAction(); 191 lastOpen5ProductAction.initialize(this,4); 192 actionList.put("LastOpen5ProductAction",lastOpen5ProductAction); 193 194 PreferencesAction preferencesAction = new PreferencesAction(); 196 preferencesAction.initialize(this); 197 actionList.put("PreferencesAction",preferencesAction); 198 199 QuitAction quitAction = new QuitAction(); 201 quitAction.initialize(this); 202 actionList.put("QuitAction",quitAction); 203 204 ShowRequirementsAction showRequirementsAction = new ShowRequirementsAction(); 206 showRequirementsAction.initialize(this); 207 actionList.put("ShowRequirementsAction",showRequirementsAction); 208 209 CascadeWindowsAction cascadeWindowsAction = new CascadeWindowsAction(); 211 cascadeWindowsAction.initialize(this); 212 actionList.put("CascadeWindowsAction",cascadeWindowsAction); 213 214 TileWindowsHorizontalAction tileWindowsHorizontalAction = new TileWindowsHorizontalAction(); 216 tileWindowsHorizontalAction.initialize(this); 217 actionList.put("TileWindowsHorizontalAction",tileWindowsHorizontalAction); 218 219 TileWindowsVerticalAction tileWindowsVerticalAction = new TileWindowsVerticalAction(); 221 tileWindowsVerticalAction.initialize(this); 222 actionList.put("TileWindowsVerticalAction",tileWindowsVerticalAction); 223 224 AboutAction aboutAction = new AboutAction(); 226 aboutAction.initialize(this); 227 actionList.put("AboutAction",aboutAction); 228 229 } 230 231 return actionList; 232 } 233 234 240 public Hashtable getItemList() { 241 return itemList; 242 } 243 244 248 public VAIBuilderModel getModel() { 249 return model; 250 } 251 252 public VAIProductController getActiveProductController() { 253 return activeProductController; 254 } 255 256 public Hashtable getProductControllerList() { 257 return productControllerList; 258 } 259 260 268 public JFrame getFrame() { 269 return frame; 270 } 271 272 276 public void windowActivated(java.awt.event.WindowEvent e) { 277 } 278 279 283 public void windowClosed(java.awt.event.WindowEvent e) { 284 } 285 286 290 public void windowClosing(java.awt.event.WindowEvent e) { 291 292 AbstractVAIBuilderAction action = (AbstractVAIBuilderAction)getActionList().get("QuitAction"); 293 action.runnit(); 294 } 295 296 300 public void windowDeactivated(java.awt.event.WindowEvent e) { 301 } 302 303 307 public void windowDeiconified(java.awt.event.WindowEvent e) { 308 } 309 310 314 public void windowIconified(java.awt.event.WindowEvent e) { 315 } 316 317 321 public void windowOpened(java.awt.event.WindowEvent e) { 322 } 323 324 328 public void builderChanged(VAIBuilderEvent evt) { 329 330 switch (evt.getType()) { 331 case VAIBuilderEvent.PREFERENCES_LOADED: 332 ((AbstractButton)getItemList().get("NewProductItem")).setEnabled(true); 333 ((AbstractButton)getItemList().get("OpenProductItem")).setEnabled(true); 334 335 ((AbstractButton)getItemList().get("NewProductButton")).setEnabled(true); 336 ((AbstractButton)getItemList().get("OpenProductButton")).setEnabled(true); 337 break; 338 case VAIBuilderEvent.LASTFILELIST_CHANGED: 339 340 ((JMenuItem)getItemList().get("LastOpen1Product")).setVisible(false); 341 ((JMenuItem)getItemList().get("LastOpen2Product")).setVisible(false); 342 ((JMenuItem)getItemList().get("LastOpen3Product")).setVisible(false); 343 ((JMenuItem)getItemList().get("LastOpen4Product")).setVisible(false); 344 ((JMenuItem)getItemList().get("LastOpen5Product")).setVisible(false); 345 346 for (int k = 0 ; k < getModel().getLastOpenedProjectList().size() ; k++) { 347 String itemString = String.valueOf(k+1) + " " + getModel().getLastOpenedProjectList().get(k); 348 JMenuItem item = ((JMenu)getItemList().get("FileMenu")).getItem(8+k); 349 item.setText(itemString); 350 item.setVisible(true); 351 } 352 if (((JMenu)getItemList().get("FileMenu")).getItem(13) != null && getModel().getLastOpenedProjectList().size() > 0) { 353 ((JMenu)getItemList().get("FileMenu")).insertSeparator(13); 354 } 355 356 if (((JMenuItem)getItemList().get("LastOpen1Product")).isVisible() == false) { 357 ((JMenu)getItemList().get("FileMenu")).remove(9); 358 } 359 360 break; 361 } 362 } 363 364 private JMenuBar getMenuBar() { 365 366 if(menuBar == null) { 367 368 menuBar = new JMenuBar(); 369 370 JMenu fileMenu = new JMenu(); 372 fileMenu.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_File")); 373 fileMenu.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_File_M")); 374 getItemList().put("FileMenu",fileMenu); 375 376 JMenuItem newProductItem = new JMenuItem(); 378 newProductItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_FileNew")); 379 newProductItem.setIcon(new javax.swing.ImageIcon (getClass().getResource("/com/memoire/vainstall/builder/images/New16.gif"))); 380 newProductItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_FileNew_M")); 381 newProductItem.setEnabled(false); 382 newProductItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("NewProductAction")); 383 getItemList().put("NewProductItem",newProductItem); 384 fileMenu.add(newProductItem); 385 386 JMenuItem openProductItem = new JMenuItem(); 388 openProductItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_FileOpen")); 389 openProductItem.setIcon(new javax.swing.ImageIcon (getClass().getResource("/com/memoire/vainstall/builder/images/Open16.gif"))); 390 openProductItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_FileOpen_M")); 391 openProductItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); 392 openProductItem.setEnabled(false); 393 openProductItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("OpenProductAction")); 394 getItemList().put("OpenProductItem",openProductItem); 395 fileMenu.add(openProductItem); 396 397 fileMenu.addSeparator(); 399 400 JMenuItem saveProductItem = new JMenuItem(); 402 saveProductItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_FileSave")); 403 saveProductItem.setIcon(new javax.swing.ImageIcon (getClass().getResource("/com/memoire/vainstall/builder/images/Save16.gif"))); 404 saveProductItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_FileSave_M")); 405 saveProductItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); 406 saveProductItem.setEnabled(false); 407 saveProductItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("SaveProductAction")); 408 getItemList().put("SaveProductItem",saveProductItem); 409 fileMenu.add(saveProductItem); 410 411 JMenuItem saveAllProductItem = new JMenuItem(); 413 saveAllProductItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_FileSaveAll")); 414 saveAllProductItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_FileSaveAll_M")); 416 saveAllProductItem.setEnabled(false); 418 saveAllProductItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("SaveAllProductAction")); 419 getItemList().put("SaveAllProductItem",saveAllProductItem); 420 fileMenu.add(saveAllProductItem); 421 422 fileMenu.addSeparator(); 424 425 JMenuItem closeProductItem = new JMenuItem(); 427 closeProductItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_FileClose")); 428 closeProductItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_FileClose_M")); 430 closeProductItem.setEnabled(false); 432 closeProductItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("CloseProductAction")); 433 getItemList().put("CloseProductItem",closeProductItem); 434 fileMenu.add(closeProductItem); 435 436 fileMenu.addSeparator(); 438 439 JMenuItem lastOpen1Product = new JMenuItem(); 441 lastOpen1Product.setMnemonic('1'); 442 lastOpen1Product.setVisible(false); 443 lastOpen1Product.addActionListener((AbstractVAIBuilderAction)getActionList().get("LastOpen1ProductAction")); 444 getItemList().put("LastOpen1Product",lastOpen1Product); 445 fileMenu.add(lastOpen1Product); 446 447 JMenuItem lastOpen2Product = new JMenuItem(); 449 lastOpen2Product.setMnemonic('2'); 450 lastOpen2Product.setVisible(false); 451 lastOpen2Product.addActionListener((AbstractVAIBuilderAction)getActionList().get("LastOpen2ProductAction")); 452 getItemList().put("LastOpen2Product",lastOpen2Product); 453 fileMenu.add(lastOpen2Product); 454 455 JMenuItem lastOpen3Product = new JMenuItem(); 457 lastOpen3Product.setMnemonic('3'); 458 lastOpen3Product.setVisible(false); 459 lastOpen3Product.addActionListener((AbstractVAIBuilderAction)getActionList().get("LastOpen3ProductAction")); 460 getItemList().put("LastOpen3Product",lastOpen3Product); 461 fileMenu.add(lastOpen3Product); 462 463 JMenuItem lastOpen4Product = new JMenuItem(); 465 lastOpen4Product.setMnemonic('4'); 466 lastOpen4Product.setVisible(false); 467 lastOpen4Product.addActionListener((AbstractVAIBuilderAction)getActionList().get("LastOpen4ProductAction")); 468 getItemList().put("LastOpen4Product",lastOpen4Product); 469 fileMenu.add(lastOpen4Product); 470 471 JMenuItem lastOpen5Product = new JMenuItem(); 473 lastOpen5Product.setMnemonic('5'); 474 lastOpen5Product.setVisible(false); 475 lastOpen5Product.addActionListener((AbstractVAIBuilderAction)getActionList().get("LastOpen5ProductAction")); 476 getItemList().put("LastOpen5Product",lastOpen5Product); 477 fileMenu.add(lastOpen5Product); 478 479 482 JMenuItem preferencesItem = new JMenuItem(); 484 preferencesItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_FilePreferences")); 485 preferencesItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_FilePreferences_M")); 486 preferencesItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("PreferencesAction")); 487 getItemList().put("PreferencesItem",preferencesItem); 488 fileMenu.add(preferencesItem); 489 490 fileMenu.addSeparator(); 492 493 JMenuItem quitItem = new JMenuItem(); 495 quitItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_FileQuit")); 496 quitItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_FileQuit_M")); 497 quitItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("QuitAction")); 498 getItemList().put("QuitItem",quitItem); 499 fileMenu.add(quitItem); 500 501 menuBar.add(fileMenu); 502 503 JMenu toolsMenu = new JMenu(); 505 toolsMenu.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_Tools")); 506 toolsMenu.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_Tools_M")); 507 508 JMenuItem showRequirementsItem = new JMenuItem(); 509 showRequirementsItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_ToolsShowRequirements")); 510 showRequirementsItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_ToolsShowRequirements_M")); 511 showRequirementsItem.setEnabled(false); 512 showRequirementsItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("ShowRequirementsAction")); 513 getItemList().put("ShowRequirementsItem",showRequirementsItem); 514 toolsMenu.add(showRequirementsItem); 515 516 toolsMenu.addSeparator(); 517 518 JMenuItem exportOldItem = new JMenuItem(); 519 exportOldItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_ToolsExportOld")); 520 exportOldItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_ToolsExportOld_M")); 521 exportOldItem.setEnabled(false); 522 getItemList().put("ExportOldItem",exportOldItem); 524 toolsMenu.add(exportOldItem); 525 526 menuBar.add(toolsMenu); 527 528 JMenu windowMenu = new JMenu(); 530 windowMenu.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_Window")); 531 windowMenu.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_Window_M")); 532 getItemList().put("WindowMenu",windowMenu); 533 534 JMenuItem cascadeWindowsItem = new JMenuItem(); 535 cascadeWindowsItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_CascadeWindows")); 536 cascadeWindowsItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_CascadeWindows_M")); 537 cascadeWindowsItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("CascadeWindowsAction")); 538 cascadeWindowsItem.setEnabled(false); 539 getItemList().put("CascadeWindowsItem",cascadeWindowsItem); 540 windowMenu.add(cascadeWindowsItem); 541 542 JMenuItem tileWindowsHorizontalItem = new JMenuItem(); 543 tileWindowsHorizontalItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_TileWindowsHorizontal")); 544 tileWindowsHorizontalItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_TileWindowsHorizontal_M")); 545 tileWindowsHorizontalItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("TileWindowsHorizontalAction")); 546 tileWindowsHorizontalItem.setEnabled(false); 547 getItemList().put("TileWindowsHorizontalItem",tileWindowsHorizontalItem); 548 windowMenu.add(tileWindowsHorizontalItem); 549 550 JMenuItem tileWindowsVerticalItem = new JMenuItem(); 551 tileWindowsVerticalItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_TileWindowsVertical")); 552 tileWindowsVerticalItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_TileWindowsVertical_M")); 553 tileWindowsVerticalItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("TileWindowsVerticalAction")); 554 tileWindowsVerticalItem.setEnabled(false); 555 getItemList().put("TileWindowsVerticalItem",tileWindowsVerticalItem); 556 windowMenu.add(tileWindowsVerticalItem); 557 558 menuBar.add(windowMenu); 559 560 JMenu helpMenu = new JMenu(); 562 helpMenu.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_Help")); 563 helpMenu.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_Help_M")); 564 565 JMenuItem aboutItem = new JMenuItem(); 566 aboutItem.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","Menu_HelpAbout")); 567 aboutItem.setMnemonic(VAGlobals.getResourceInt("com.memoire.vainstall.builder.Language","Menu_HelpAbout_M")); 568 aboutItem.addActionListener((AbstractVAIBuilderAction)getActionList().get("AboutAction")); 569 getItemList().put("AboutItem",aboutItem); 570 helpMenu.add(aboutItem); 571 572 menuBar.add(helpMenu); 573 574 } 575 576 return menuBar; 577 } 578 579 private JToolBar getToolBar() { 580 581 if(toolBar == null) { 582 583 toolBar = new JToolBar(); 584 toolBar.setFloatable(false); 585 toolBar.setBorderPainted(true); 586 587 JButton newProductButton = new JButton(new javax.swing.ImageIcon (getClass().getResource("/com/memoire/vainstall/builder/images/New16.gif"))); 588 newProductButton.addActionListener((AbstractVAIBuilderAction)getActionList().get("NewProductAction")); 589 newProductButton.setToolTipText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","ToolBarButton_New")); 590 newProductButton.setEnabled(false); 591 itemList.put("NewProductButton",newProductButton); 592 toolBar.add(newProductButton); 593 594 JButton openProductButton = new JButton(new javax.swing.ImageIcon (getClass().getResource("/com/memoire/vainstall/builder/images/Open16.gif"))); 595 openProductButton.addActionListener((AbstractVAIBuilderAction)getActionList().get("OpenProductAction")); 596 openProductButton.setToolTipText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","ToolBarButton_Open")); 597 openProductButton.setEnabled(false); 598 itemList.put("OpenProductButton",openProductButton); 599 toolBar.add(openProductButton); 600 601 toolBar.addSeparator(); 602 603 JButton saveProductButton = new JButton(new javax.swing.ImageIcon (getClass().getResource("/com/memoire/vainstall/builder/images/Save16.gif"))); 604 saveProductButton.addActionListener((AbstractVAIBuilderAction)getActionList().get("SaveProductAction")); 605 saveProductButton.setToolTipText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","ToolBarButton_Save")); 606 saveProductButton.setEnabled(false); 607 itemList.put("SaveProductButton",saveProductButton); 608 toolBar.add(saveProductButton); 609 610 } 611 612 return toolBar; 613 } 614 615 private void setInformationText(String textAsHtml) { 616 frame.getInformationLabel().setIcon(new javax.swing.ImageIcon (getClass().getResource("/com/memoire/vainstall/builder/images/Information16.gif"))); 617 frame.getInformationLabel().setText(textAsHtml); 618 } 619 620 public void setTipOfTheDay() { 621 622 String numTips=VAGlobals.getResource("com.memoire.vainstall.builder.Language","Tip_0"); 623 624 int num=1; 625 626 try { 627 num=Integer.parseInt(numTips); 628 } catch(NumberFormatException exc) { 629 num=1; 630 } 631 632 if (random == null) { 633 long l = System.currentTimeMillis(); 634 random=new Random (l); 635 } 636 637 float floatCount=random.nextFloat(); 638 int tipNumber=(int)(floatCount*num)+1; 639 640 String text = VAGlobals.getResource("com.memoire.vainstall.builder.Language","Tip_"+String.valueOf(tipNumber)); 641 642 String textAsHtml = text; 643 textAsHtml = "<html><b><font color=black size=1><center>"+text+"</center></font></b></html>"; 644 frame.getInformationLabel().setIcon(new javax.swing.ImageIcon (getClass().getResource("/com/memoire/vainstall/builder/images/TipOfTheDay16.gif"))); 645 frame.getInformationLabel().setText(textAsHtml); 646 } 647 648 public void addProduct(String id,VAIProductController productController) { 649 650 productController.getModel().addVAIProductListener(this); 651 652 try { 653 frame.getDesktopPane().add(productController.getFrame(),JLayeredPane.DEFAULT_LAYER); 654 productController.getFrame().setVisible(true); 655 productController.getFrame().setSelected(true); 656 productController.getFrame().setMaximum(true); 657 productController.getFrame().setNormalBounds(new Rectangle(0,0,400,300)); 658 659 } catch(Exception exc) { 660 exc.printStackTrace(); 661 return; 662 } 663 productControllerList.put(id,productController); 664 665 getModel().addLastOpenedProject(productController.getModel().getProductDirectory() + File.separator + "vainstall.xml"); 666 667 JMenu windowMenu = (JMenu)getItemList().get("WindowMenu"); 668 if(windowMenu.getItemCount() == 3) { 669 windowMenu.addSeparator(); 670 } 671 JMenuItem item = new JMenuItem(id + File.separator + "vainstall.xml"); 672 item.addActionListener(productController); 673 windowMenu.add(item); 674 675 if (productControllerList.size() > 1) { 676 ((AbstractButton)getItemList().get("CascadeWindowsItem")).setEnabled(true); 677 ((AbstractButton)getItemList().get("TileWindowsHorizontalItem")).setEnabled(true); 678 ((AbstractButton)getItemList().get("TileWindowsVerticalItem")).setEnabled(true); 679 } 680 681 setTipOfTheDay(); 683 } 684 685 public void removeProduct(String id) { 686 VAIProductController productController = (VAIProductController)productControllerList.get(id); 687 688 productController.getFrame().setVisible(false); 689 productController.getModel().removeVAIProductListener(this); 690 691 frame.getDesktopPane().remove(productController.getFrame()); 692 getModel().fireVAIBuilderEvent(new VAIBuilderEvent(this,VAIBuilderEvent.PROJECT_DEACTIVATED)); 693 694 productControllerList.remove(id); 695 696 JMenu windowMenu = (JMenu)getItemList().get("WindowMenu"); 697 698 for (int i = 0; i < windowMenu.getItemCount(); i++) { 699 try { 700 if (windowMenu.getItem(i).getText() != null && windowMenu.getItem(i).getText().equals(id + File.separator + "vainstall.xml") == true) { 701 windowMenu.remove(i); 702 } 703 } catch (NullPointerException exc) { 704 } 706 } 707 708 if(windowMenu.getItemCount() == 4) { 709 windowMenu.remove(3); 710 } 711 712 if (productControllerList.size() < 2) { 713 ((AbstractButton)getItemList().get("CascadeWindowsItem")).setEnabled(false); 714 ((AbstractButton)getItemList().get("TileWindowsHorizontalItem")).setEnabled(false); 715 ((AbstractButton)getItemList().get("TileWindowsVerticalItem")).setEnabled(false); 716 } 717 718 ((AbstractButton)getItemList().get("CloseProductItem")).setEnabled(false); 720 if (productControllerList.size() == 0) { 721 ((AbstractButton)getItemList().get("ShowRequirementsItem")).setEnabled(false); 722 } 723 } 724 725 public void productChanged(VAIProductEvent evt) { 726 727 switch (evt.getType()) { 728 case VAIProductEvent.PROJECT_ACTIVATED: 729 activeProductController = (VAIProductController)evt.getSource(); 730 if(activeProductController.isDirty() == true) { 731 ((AbstractButton)getItemList().get("SaveProductItem")).setEnabled(true); 732 ((AbstractButton)getItemList().get("SaveProductButton")).setEnabled(true); 733 } else { 734 ((AbstractButton)getItemList().get("SaveProductItem")).setEnabled(false); 735 ((AbstractButton)getItemList().get("SaveProductButton")).setEnabled(false); 736 } 737 ((AbstractButton)getItemList().get("CloseProductItem")).setEnabled(true); 738 739 getModel().fireVAIBuilderEvent(new VAIBuilderEvent(this,VAIBuilderEvent.PROJECT_ACTIVATED)); 740 break; 741 case VAIProductEvent.PROJECT_DEACTIVATED: 742 activeProductController = null; 743 ((AbstractButton)getItemList().get("SaveProductItem")).setEnabled(false); 744 ((AbstractButton)getItemList().get("SaveProductButton")).setEnabled(false); 745 ((AbstractButton)getItemList().get("CloseProductItem")).setEnabled(false); 746 getModel().fireVAIBuilderEvent(new VAIBuilderEvent(this,VAIBuilderEvent.PROJECT_DEACTIVATED)); 747 break; 748 case VAIProductEvent.PROJECT_DIRTY: 749 ((AbstractButton)getItemList().get("SaveProductItem")).setEnabled(true); 750 ((AbstractButton)getItemList().get("SaveProductButton")).setEnabled(true); 751 ((AbstractButton)getItemList().get("SaveAllProductItem")).setEnabled(true); 752 ((AbstractButton)getItemList().get("ExportOldItem")).setEnabled(false); 753 break; 754 case VAIProductEvent.PROJECT_SAVED: 755 ((AbstractButton)getItemList().get("SaveProductItem")).setEnabled(false); 756 ((AbstractButton)getItemList().get("SaveProductButton")).setEnabled(false); 757 758 boolean saveAll = false; 760 Iterator iterator = productControllerList.values().iterator(); 761 while (iterator.hasNext() == true) { 762 VAIProductController productController = (VAIProductController)iterator.next(); 763 if(productController.isDirty() == true) { 764 saveAll = true; 765 } 766 } 767 if(saveAll == true) { 768 ((AbstractButton)getItemList().get("SaveAllProductItem")).setEnabled(true); 769 } else { 770 ((AbstractButton)getItemList().get("SaveAllProductItem")).setEnabled(false); 771 } 772 break; 773 case VAIProductEvent.PROJECT_REQUIREMENTS_MET: 774 ((AbstractButton)getItemList().get("ShowRequirementsItem")).setEnabled(false); 775 ((AbstractButton)getItemList().get("ExportOldItem")).setEnabled(true); 776 break; 777 case VAIProductEvent.PROJECT_REQUIREMENTS_NOTMET: 778 ((AbstractButton)getItemList().get("ShowRequirementsItem")).setEnabled(true); 779 ((AbstractButton)getItemList().get("ExportOldItem")).setEnabled(false); 780 break; 781 } 782 783 } 784 785 } 786 | Popular Tags |