1 22 23 package com.izforge.izpack.installer; 24 25 import java.awt.BorderLayout ; 26 import java.awt.Color ; 27 import java.awt.Component ; 28 import java.awt.Cursor ; 29 import java.awt.Dimension ; 30 import java.awt.Font ; 31 import java.awt.GraphicsEnvironment ; 32 import java.awt.GridBagConstraints ; 33 import java.awt.GridLayout ; 34 import java.awt.Point ; 35 import java.awt.Window ; 36 import java.awt.event.ActionEvent ; 37 import java.awt.event.ActionListener ; 38 import java.awt.event.FocusAdapter ; 39 import java.awt.event.KeyAdapter ; 40 import java.awt.event.MouseAdapter ; 41 import java.awt.event.MouseMotionAdapter ; 42 import java.awt.event.WindowAdapter ; 43 import java.awt.event.WindowEvent ; 44 import java.io.BufferedWriter ; 45 import java.io.ByteArrayOutputStream ; 46 import java.io.File ; 47 import java.io.FileNotFoundException ; 48 import java.io.FileOutputStream ; 49 import java.io.IOException ; 50 import java.io.InputStream ; 51 import java.io.ObjectOutputStream ; 52 import java.io.OutputStream ; 53 import java.io.OutputStreamWriter ; 54 import java.lang.reflect.Constructor ; 55 import java.net.URL ; 56 import java.util.ArrayList ; 57 import java.util.HashSet ; 58 import java.util.Iterator ; 59 import java.util.List ; 60 import java.util.Map ; 61 import java.util.Vector ; 62 import java.util.zip.ZipEntry ; 63 import java.util.zip.ZipException ; 64 import java.util.zip.ZipOutputStream ; 65 66 import javax.swing.BorderFactory ; 67 import javax.swing.Box ; 68 import javax.swing.BoxLayout ; 69 import javax.swing.ImageIcon ; 70 import javax.swing.JButton ; 71 import javax.swing.JComponent ; 72 import javax.swing.JFrame ; 73 import javax.swing.JLabel ; 74 import javax.swing.JOptionPane ; 75 import javax.swing.JPanel ; 76 import javax.swing.JProgressBar ; 77 import javax.swing.JSeparator ; 78 import javax.swing.SwingUtilities ; 79 import javax.swing.UIManager ; 80 import javax.swing.WindowConstants ; 81 import javax.swing.border.TitledBorder ; 82 import javax.swing.text.JTextComponent ; 83 84 import net.n3.nanoxml.NonValidator; 85 import net.n3.nanoxml.StdXMLBuilder; 86 import net.n3.nanoxml.StdXMLParser; 87 import net.n3.nanoxml.StdXMLReader; 88 import net.n3.nanoxml.XMLElement; 89 import net.n3.nanoxml.XMLWriter; 90 91 import com.izforge.izpack.CustomData; 92 import com.izforge.izpack.ExecutableFile; 93 import com.izforge.izpack.LocaleDatabase; 94 import com.izforge.izpack.Panel; 95 import com.izforge.izpack.gui.ButtonFactory; 96 import com.izforge.izpack.gui.EtchedLineBorder; 97 import com.izforge.izpack.gui.IconsDatabase; 98 import com.izforge.izpack.rules.RulesEngine; 99 import com.izforge.izpack.util.AbstractUIProgressHandler; 100 import com.izforge.izpack.util.Debug; 101 import com.izforge.izpack.util.Housekeeper; 102 import com.izforge.izpack.util.IoHelper; 103 import com.izforge.izpack.util.OsConstraint; 104 import com.izforge.izpack.util.VariableSubstitutor; 105 106 113 public class InstallerFrame extends JFrame 114 { 115 116 117 private static final long serialVersionUID = 3257852069162727473L; 118 119 122 private static final float JAVA_SPECIFICATION_VERSION = Float.parseFloat(System 123 .getProperty("java.specification.version")); 124 125 private static final String ICON_RESOURCE = "Installer.image"; 126 127 130 private static final String ICON_RESOURCE_EXT_VARIABLE_NAME = "installerimage.ext"; 131 132 133 private static final String HEADING_ICON_RESOURCE = "Heading.image"; 134 135 137 140 public LocaleDatabase langpack; 141 142 145 protected InstallData installdata; 146 147 150 public IconsDatabase icons; 151 152 155 protected JPanel panelsContainer; 156 157 160 protected JPanel contentPane; 161 162 165 protected JButton prevButton; 166 167 170 protected JButton nextButton; 171 172 175 protected JButton quitButton; 176 177 180 protected ArrayList visiblePanelMapping; 181 182 185 protected ArrayList guiListener; 186 187 190 protected JLabel [] headingLabels; 191 192 195 protected JPanel headingPanel; 196 197 200 protected JComponent headingCounterComponent; 201 202 205 private JLabel iconLabel; 206 207 210 private int interruptCount = 1; 211 212 215 private static final int MAX_INTERRUPT = 3; 216 217 220 protected RulesEngine rules; 221 222 225 private static final String CONDITIONS_SPECRESOURCENAME = "conditions.xml"; 226 229 private static final String CUSTOM_ICONS_RESOURCEFILE = "customicons.xml"; 230 231 238 public InstallerFrame(String title, InstallData installdata) throws Exception 239 { 240 super(title); 241 guiListener = new ArrayList (); 242 visiblePanelMapping = new ArrayList (); 243 this.installdata = installdata; 244 this.langpack = installdata.langpack; 245 246 addWindowListener(new WindowHandler()); 248 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); 249 250 loadConditions(); 252 253 loadIcons(); 255 loadCustomIcons(); 256 loadPanels(); 257 buildGUI(); 258 259 showFrame(); 261 switchPanel(0); 262 } 263 264 267 protected void loadConditions() 268 { 269 try 270 { 271 InputStream input = null; 272 input = this.getResource(CONDITIONS_SPECRESOURCENAME); 273 if (input == null) 274 { 275 this.rules = new RulesEngine(null, installdata); 276 return; 277 } 278 279 StdXMLParser parser = new StdXMLParser(); 280 parser.setBuilder(new StdXMLBuilder()); 281 parser.setValidator(new NonValidator()); 282 parser.setReader(new StdXMLReader(input)); 283 284 XMLElement conditionsxml = (XMLElement) parser.parse(); 286 this.rules = new RulesEngine(conditionsxml, installdata); 287 } 288 catch (Exception e) 289 { 290 Debug.trace("Can not find optional resource " + CONDITIONS_SPECRESOURCENAME); 291 this.rules = new RulesEngine(null, installdata); 293 } 294 } 295 296 301 private void loadPanels() throws Exception 302 { 303 java.util.List panelsOrder = installdata.panelsOrder; 305 int i; 306 int size = panelsOrder.size(); 307 String className; 308 Class objectClass; 309 Constructor constructor; 310 Object object; 311 IzPanel panel; 312 Class [] paramsClasses = new Class [2]; 313 paramsClasses[0] = Class.forName("com.izforge.izpack.installer.InstallerFrame"); 314 paramsClasses[1] = Class.forName("com.izforge.izpack.installer.InstallData"); 315 Object [] params = { this, installdata}; 316 317 int curVisPanelNumber = 0; 319 int lastVis = 0; 320 int count = 0; 321 for (i = 0; i < size; i++) 322 { 323 Panel p = (Panel ) panelsOrder.get(i); 325 if (!OsConstraint.oneMatchesCurrentSystem(p.osConstraints)) continue; 326 className = p.className; 327 String praefix = "com.izforge.izpack.panels."; 328 if (className.indexOf('.') > -1) 329 praefix = ""; 331 objectClass = Class.forName(praefix + className); 332 constructor = objectClass.getDeclaredConstructor(paramsClasses); 333 installdata.currentPanel = p; object = constructor.newInstance(params); 337 panel = (IzPanel) object; 338 installdata.panels.add(panel); 339 if (panel.isHidden()) 340 visiblePanelMapping.add(count, new Integer (-1)); 341 else 342 { 343 visiblePanelMapping.add(count, new Integer (curVisPanelNumber)); 344 curVisPanelNumber++; 345 lastVis = count; 346 } 347 count++; 348 XMLElement panelRoot = new XMLElement(className); 350 installdata.xmlData.addChild(panelRoot); 351 } 352 visiblePanelMapping.add(count, new Integer (lastVis)); 353 } 354 355 360 private void loadIcons() throws Exception 361 { 362 icons = new IconsDatabase(); 364 URL url; 365 ImageIcon img; 366 XMLElement icon; 367 InputStream inXML = InstallerFrame.class 368 .getResourceAsStream("/com/izforge/izpack/installer/icons.xml"); 369 370 StdXMLParser parser = new StdXMLParser(); 372 parser.setBuilder(new StdXMLBuilder()); 373 parser.setReader(new StdXMLReader(inXML)); 374 parser.setValidator(new NonValidator()); 375 376 XMLElement data = (XMLElement) parser.parse(); 378 379 Vector children = data.getChildrenNamed("icon"); 381 int size = children.size(); 382 for (int i = 0; i < size; i++) 383 { 384 icon = (XMLElement) children.get(i); 385 url = InstallerFrame.class.getResource(icon.getAttribute("res")); 386 img = new ImageIcon (url); 387 icons.put(icon.getAttribute("id"), img); 388 } 389 390 children = data.getChildrenNamed("sysicon"); 392 size = children.size(); 393 for (int i = 0; i < size; i++) 394 { 395 icon = (XMLElement) children.get(i); 396 url = InstallerFrame.class.getResource(icon.getAttribute("res")); 397 img = new ImageIcon (url); 398 UIManager.put(icon.getAttribute("id"), img); 399 } 400 } 401 402 407 protected void loadCustomIcons() throws Exception { 408 InputStream inXML = null; 410 try { 411 inXML = ResourceManager.getInstance().getInputStream( 412 CUSTOM_ICONS_RESOURCEFILE); 413 } catch (Throwable exception) { 414 Debug.trace("Resource " + CUSTOM_ICONS_RESOURCEFILE + " not defined. No custom icons available."); 415 return; 416 } 417 Debug.trace("Custom icons available."); 418 URL url; 419 ImageIcon img; 420 XMLElement icon; 421 422 StdXMLParser parser = new StdXMLParser(); 424 parser.setBuilder(new StdXMLBuilder()); 425 parser.setReader(new StdXMLReader(inXML)); 426 parser.setValidator(new NonValidator()); 427 428 XMLElement data = (XMLElement) parser.parse(); 430 431 Vector children = data.getChildrenNamed("icon"); 433 int size = children.size(); 434 for (int i = 0; i < size; i++) { 435 icon = (XMLElement) children.get(i); 436 url = InstallerFrame.class.getResource(icon.getAttribute("res")); 437 img = new ImageIcon (url); 438 Debug.trace("Icon with id found: " + icon.getAttribute("id")); 439 icons.put(icon.getAttribute("id"), img); 440 } 441 442 children = data.getChildrenNamed("sysicon"); 444 size = children.size(); 445 for (int i = 0; i < size; i++) { 446 icon = (XMLElement) children.get(i); 447 url = InstallerFrame.class.getResource(icon.getAttribute("res")); 448 img = new ImageIcon (url); 449 UIManager.put(icon.getAttribute("id"), img); 450 } 451 } 452 453 456 private void buildGUI() 457 { 458 this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); setIconImage(icons.getImageIcon("JFrameIcon").getImage()); 462 463 JPanel glassPane = (JPanel ) getGlassPane(); 465 glassPane.addMouseListener(new MouseAdapter () { 466 }); 467 glassPane.addMouseMotionListener(new MouseMotionAdapter () { 468 }); 469 glassPane.addKeyListener(new KeyAdapter () { 470 }); 471 glassPane.addFocusListener(new FocusAdapter () { 472 }); 473 474 contentPane = (JPanel ) getContentPane(); 476 contentPane.setLayout(new BorderLayout ()); 478 panelsContainer = new JPanel (); 480 panelsContainer.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); 481 panelsContainer.setLayout(new GridLayout (1, 1)); 482 contentPane.add(panelsContainer, BorderLayout.CENTER); 483 484 installdata.curPanelNumber = 0; 486 IzPanel panel_0 = (IzPanel) installdata.panels.get(0); 487 panelsContainer.add(panel_0); 488 489 491 NavigationHandler navHandler = new NavigationHandler(); 492 493 JPanel navPanel = new JPanel (); 494 navPanel.setLayout(new BoxLayout (navPanel, BoxLayout.X_AXIS)); 495 navPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(8, 8, 496 8, 8), BorderFactory.createTitledBorder(new EtchedLineBorder(), langpack 497 .getString("installer.madewith") 498 + " ", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font ( 499 "Dialog", Font.PLAIN, 10)))); 500 navPanel.add(Box.createHorizontalGlue()); 501 502 prevButton = ButtonFactory.createButton(langpack.getString("installer.prev"), icons 503 .getImageIcon("stepback"), installdata.buttonsHColor); 504 navPanel.add(prevButton); 505 prevButton.addActionListener(navHandler); 506 507 navPanel.add(Box.createRigidArea(new Dimension (5, 0))); 508 509 nextButton = ButtonFactory.createButton(langpack.getString("installer.next"), icons 510 .getImageIcon("stepforward"), installdata.buttonsHColor); 511 navPanel.add(nextButton); 512 nextButton.addActionListener(navHandler); 513 514 navPanel.add(Box.createRigidArea(new Dimension (5, 0))); 515 516 quitButton = ButtonFactory.createButton(langpack.getString("installer.quit"), icons 517 .getImageIcon("stop"), installdata.buttonsHColor); 518 navPanel.add(quitButton); 519 quitButton.addActionListener(navHandler); 520 contentPane.add(navPanel, BorderLayout.SOUTH); 521 522 try 523 { 524 ImageIcon icon = loadIcon(ICON_RESOURCE, 0, true); 525 if (icon != null) 526 { 527 JPanel imgPanel = new JPanel (); 528 imgPanel.setLayout(new BorderLayout ()); 529 imgPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 0)); 530 iconLabel = new JLabel (icon); 531 iconLabel.setBorder(BorderFactory.createLoweredBevelBorder()); 532 imgPanel.add(iconLabel, BorderLayout.NORTH); 533 contentPane.add(imgPanel, BorderLayout.WEST); 534 } 535 } 536 catch (Exception e) 537 { 538 } 540 541 loadAndShowImage(0); 542 getRootPane().setDefaultButton(nextButton); 543 callGUIListener(GUIListener.GUI_BUILDED, navPanel); 544 createHeading(navPanel); 545 } 546 547 private void callGUIListener(int what) 548 { 549 callGUIListener(what, null); 550 } 551 552 private void callGUIListener(int what, Object param) 553 { 554 Iterator iter = guiListener.iterator(); 555 while (iter.hasNext()) 556 ((GUIListener) iter.next()).guiActionPerformed(what, param); 557 } 558 559 private ImageIcon loadIcon(String resPrefix, int PanelNo, boolean tryBaseIcon) 560 throws ResourceNotFoundException, IOException 561 { 562 ResourceManager rm = ResourceManager.getInstance(); 563 ImageIcon icon = null; 564 String iconext = this.getIconResourceNameExtension(); 565 if (tryBaseIcon) 566 { 567 try 568 { 569 icon = rm.getImageIconResource(resPrefix); 570 } 571 catch (Exception e) { 573 icon = rm.getImageIconResource(resPrefix + "." + PanelNo + iconext); 574 } 575 } 576 else 577 icon = rm.getImageIconResource(resPrefix + "." + PanelNo + iconext); 578 return (icon); 579 } 580 581 private ImageIcon loadIcon(String resPrefix, String panelid, boolean tryBaseIcon) 582 throws ResourceNotFoundException, IOException 583 { 584 ResourceManager rm = ResourceManager.getInstance(); 585 ImageIcon icon = null; 586 String iconext = this.getIconResourceNameExtension(); 587 if (tryBaseIcon) 588 { 589 try 590 { 591 icon = rm.getImageIconResource(resPrefix); 592 } 593 catch (Exception e) { 595 icon = rm.getImageIconResource(resPrefix + "." + panelid + iconext); 596 } 597 } 598 else 599 icon = rm.getImageIconResource(resPrefix + "." + panelid + iconext); 600 return (icon); 601 } 602 603 609 private String getIconResourceNameExtension() 610 { 611 try 612 { 613 String iconext = this.installdata.getVariable(ICON_RESOURCE_EXT_VARIABLE_NAME); 614 if (iconext == null){ 615 iconext = ""; 616 } 617 else { 618 619 if ((iconext.length() > 0) && (iconext.charAt(0) != '.')){ 620 iconext = "." + iconext; 621 } 622 } 623 iconext = iconext.trim(); 624 return iconext; 625 } 626 catch (Exception e) 627 { 628 return ""; 630 } 631 } 632 633 private void loadAndShowImage(int panelNo) 634 { 635 loadAndShowImage(iconLabel, ICON_RESOURCE, panelNo); 636 } 637 638 private void loadAndShowImage(int panelNo, String panelid) 639 { 640 loadAndShowImage(iconLabel, ICON_RESOURCE, panelNo, panelid); 641 } 642 643 private void loadAndShowImage(JLabel iLabel, String resPrefix, int panelno, String panelid) 644 { 645 ImageIcon icon = null; 646 try 647 { 648 icon = loadIcon(resPrefix, panelid, false); 649 } 650 catch (Exception e) 651 { 652 try 653 { 654 icon = loadIcon(resPrefix, panelno, false); 655 } 656 catch (Exception ex) 657 { 658 try 659 { 660 icon = loadIcon(resPrefix, panelid, true); 661 } 662 catch (Exception e1) 663 { 664 } 666 } 667 } 668 if (icon != null) 669 { 670 iLabel.setVisible(false); 671 iLabel.setIcon(icon); 672 iLabel.setVisible(true); 673 } 674 } 675 676 private void loadAndShowImage(JLabel iLabel, String resPrefix, int panelNo) 677 { 678 ImageIcon icon = null; 679 try 680 { 681 icon = loadIcon(resPrefix, panelNo, false); 682 } 683 catch (Exception e) 684 { 685 try 686 { 687 icon = loadIcon(resPrefix, panelNo, true); 688 } 689 catch (Exception e1) 690 { 691 } 693 } 694 if (icon != null) 695 { 696 iLabel.setVisible(false); 697 iLabel.setIcon(icon); 698 iLabel.setVisible(true); 699 } 700 } 701 702 705 private void showFrame() 706 { 707 pack(); 708 setSize(installdata.guiPrefs.width, installdata.guiPrefs.height); 709 setResizable(installdata.guiPrefs.resizable); 710 centerFrame(this); 711 setVisible(true); 712 } 713 714 private boolean isBack = false; 715 716 721 protected void switchPanel(int last) 722 { 723 try 724 { 725 if (installdata.curPanelNumber < last) 726 { 727 isBack = true; 728 } 729 panelsContainer.setVisible(false); 730 IzPanel panel = (IzPanel) installdata.panels.get(installdata.curPanelNumber); 731 IzPanel l_panel = (IzPanel) installdata.panels.get(last); 732 if (((Integer ) visiblePanelMapping.get(installdata.curPanelNumber)).intValue() == 0) 738 { 739 prevButton.setVisible(false); 740 lockPrevButton(); 741 unlockNextButton(); } 744 else if (((Integer ) visiblePanelMapping.get(installdata.panels.size())).intValue() == installdata.curPanelNumber) 746 { 747 prevButton.setVisible(false); 748 nextButton.setVisible(false); 749 lockNextButton(); 750 } 751 else 752 { 753 prevButton.setVisible(true); 754 nextButton.setVisible(true); 755 unlockPrevButton(); 756 unlockNextButton(); 757 } 758 SwingUtilities.invokeLater(new Runnable () { 763 764 public void run() 765 { 766 JButton cdb = null; 767 if (nextButton.isEnabled()) { 768 cdb = nextButton; 769 quitButton.setDefaultCapable(false); 770 prevButton.setDefaultCapable(false); 771 nextButton.setDefaultCapable(true); 772 } else if (quitButton.isEnabled()) { 773 cdb = quitButton; 774 quitButton.setDefaultCapable(true); 775 prevButton.setDefaultCapable(false); 776 nextButton.setDefaultCapable(false); 777 } 778 getRootPane().setDefaultButton(cdb); 779 } 780 }); 781 782 panelsContainer.remove(l_panel); 784 l_panel.panelDeactivate(); 785 panelsContainer.add(panel); 786 787 if (panel.getInitialFocus() != null) 788 { final Component inFoc = panel.getInitialFocus(); 793 if (JAVA_SPECIFICATION_VERSION < 1.35) 794 { 795 inFoc.requestFocus(); 796 } 797 else 798 { SwingUtilities.invokeLater(new Runnable () { 801 802 public void run() 803 { 804 inFoc.requestFocusInWindow(); 805 } 806 }); 807 } 808 812 if (inFoc instanceof JTextComponent ) 813 { 814 JTextComponent inText = (JTextComponent ) inFoc; 815 if (inText.isEditable() && inText.getDocument() != null) 816 { 817 inText.setCaretPosition(inText.getDocument().getLength()); 818 } 819 } 820 } 821 performHeading(panel); 822 performHeadingCounter(panel); 823 panel.panelActivate(); 824 panelsContainer.setVisible(true); 825 Panel metadata = panel.getMetadata(); 826 if ((metadata != null) && (!"UNKNOWN".equals(metadata.getPanelid()))) 827 { 828 loadAndShowImage(((Integer ) visiblePanelMapping.get(installdata.curPanelNumber)) 829 .intValue(), metadata.getPanelid()); 830 } 831 else 832 { 833 loadAndShowImage(((Integer ) visiblePanelMapping.get(installdata.curPanelNumber)) 834 .intValue()); 835 } 836 isBack = false; 837 callGUIListener(GUIListener.PANEL_SWITCHED); 838 } 839 catch (Exception err) 840 { 841 err.printStackTrace(); 842 } 843 } 844 845 848 private void writeUninstallData() 849 { 850 String logfile = installdata.getVariable("InstallerFrame.logfilePath"); 852 BufferedWriter extLogWriter = null; 853 if (logfile != null) 854 { 855 if (logfile.toLowerCase().startsWith("default")) 856 logfile = "$INSTALL_PATH/Uninstaller/install.log"; 857 logfile = IoHelper.translatePath(logfile, new VariableSubstitutor(installdata 858 .getVariables())); 859 File outFile = new File (logfile); 860 if (!outFile.getParentFile().exists()) outFile.getParentFile().mkdirs(); 861 FileOutputStream out = null; 862 try 863 { 864 out = new FileOutputStream (outFile); 865 } 866 catch (FileNotFoundException e) 867 { 868 Debug.trace("Cannot create logfile!"); 869 Debug.error(e); 870 } 871 if (out != null) extLogWriter = new BufferedWriter (new OutputStreamWriter (out)); 872 } 873 try 874 { 875 UninstallData udata = UninstallData.getInstance(); 877 List files = udata.getFilesList(); 878 ZipOutputStream outJar = installdata.uninstallOutJar; 879 880 if (outJar == null) return; 881 882 outJar.putNextEntry(new ZipEntry ("install.log")); 884 BufferedWriter logWriter = new BufferedWriter (new OutputStreamWriter (outJar)); 885 logWriter.write(installdata.getInstallPath()); 886 logWriter.newLine(); 887 Iterator iter = files.iterator(); 888 if (extLogWriter != null) 889 { while (iter.hasNext()) 891 { 892 String txt = (String ) iter.next(); 893 logWriter.write(txt); 894 extLogWriter.write(txt); 895 if (iter.hasNext()) 896 { 897 logWriter.newLine(); 898 extLogWriter.newLine(); 899 } 900 } 901 logWriter.flush(); 902 extLogWriter.flush(); 903 extLogWriter.close(); 904 } 905 else 906 { 907 while (iter.hasNext()) 908 { 909 logWriter.write((String ) iter.next()); 910 if (iter.hasNext()) logWriter.newLine(); 911 } 912 logWriter.flush(); 913 } 914 outJar.closeEntry(); 915 916 outJar.putNextEntry(new ZipEntry ("jarlocation.log")); 918 logWriter = new BufferedWriter (new OutputStreamWriter (outJar)); 919 logWriter.write(udata.getUninstallerJarFilename()); 920 logWriter.newLine(); 921 logWriter.write(udata.getUninstallerPath()); 922 logWriter.flush(); 923 outJar.closeEntry(); 924 925 outJar.putNextEntry(new ZipEntry ("executables")); 927 ObjectOutputStream execStream = new ObjectOutputStream (outJar); 928 iter = udata.getExecutablesList().iterator(); 929 execStream.writeInt(udata.getExecutablesList().size()); 930 while (iter.hasNext()) 931 { 932 ExecutableFile file = (ExecutableFile) iter.next(); 933 execStream.writeObject(file); 934 } 935 execStream.flush(); 936 outJar.closeEntry(); 937 938 Map additionalData = udata.getAdditionalData(); 943 if (additionalData != null && !additionalData.isEmpty()) 944 { 945 Iterator keys = additionalData.keySet().iterator(); 946 HashSet exist = new HashSet (); 947 while (keys != null && keys.hasNext()) 948 { 949 String key = (String ) keys.next(); 950 Object contents = additionalData.get(key); 951 if ("__uninstallLibs__".equals(key)) 952 { 953 Iterator nativeLibIter = ((List ) contents).iterator(); 954 while (nativeLibIter != null && nativeLibIter.hasNext()) 955 { 956 String nativeLibName = (String ) ((List ) nativeLibIter.next()).get(0); 957 byte[] buffer = new byte[5120]; 958 long bytesCopied = 0; 959 int bytesInBuffer; 960 outJar.putNextEntry(new ZipEntry ("native/" + nativeLibName)); 961 InputStream in = getClass().getResourceAsStream( 962 "/native/" + nativeLibName); 963 while ((bytesInBuffer = in.read(buffer)) != -1) 964 { 965 outJar.write(buffer, 0, bytesInBuffer); 966 bytesCopied += bytesInBuffer; 967 } 968 outJar.closeEntry(); 969 } 970 } 971 else if ("uninstallerListeners".equals(key) || "uninstallerJars".equals(key)) 972 { ArrayList subContents = new ArrayList (); 979 980 Iterator listenerIter = ((List ) contents).iterator(); 982 while (listenerIter.hasNext()) 983 { 984 byte[] buffer = new byte[5120]; 985 long bytesCopied = 0; 986 int bytesInBuffer; 987 CustomData customData = (CustomData) listenerIter.next(); 988 if (customData.listenerName != null) 992 subContents.add(customData.listenerName); 993 Iterator liClaIter = customData.contents.iterator(); 994 while (liClaIter.hasNext()) 995 { 996 String contentPath = (String ) liClaIter.next(); 997 if (exist.contains(contentPath)) continue; 998 exist.add(contentPath); 999 try 1000 { 1001 outJar.putNextEntry(new ZipEntry (contentPath)); 1002 } 1003 catch (ZipException ze) 1004 { Debug.trace("ZipException in writing custom data: " 1009 + ze.getMessage()); 1010 continue; 1011 } 1012 InputStream in = getClass().getResourceAsStream("/" + contentPath); 1013 if (in != null) 1014 { 1015 while ((bytesInBuffer = in.read(buffer)) != -1) 1016 { 1017 outJar.write(buffer, 0, bytesInBuffer); 1018 bytesCopied += bytesInBuffer; 1019 } 1020 } 1021 else 1022 Debug.trace("custom data not found: " + contentPath); 1023 outJar.closeEntry(); 1024 1025 } 1026 } 1027 outJar.putNextEntry(new ZipEntry (key)); 1030 ObjectOutputStream objOut = new ObjectOutputStream (outJar); 1031 objOut.writeObject(subContents); 1032 objOut.flush(); 1033 outJar.closeEntry(); 1034 1035 } 1036 else 1037 { 1038 outJar.putNextEntry(new ZipEntry (key)); 1039 if (contents instanceof ByteArrayOutputStream ) 1040 { 1041 ((ByteArrayOutputStream ) contents).writeTo(outJar); 1042 } 1043 else 1044 { 1045 ObjectOutputStream objOut = new ObjectOutputStream (outJar); 1046 objOut.writeObject(contents); 1047 objOut.flush(); 1048 } 1049 outJar.closeEntry(); 1050 } 1051 } 1052 } 1053 1055 outJar.putNextEntry(new ZipEntry (UninstallData.ROOTSCRIPT)); 1056 ObjectOutputStream rootStream = new ObjectOutputStream (outJar); 1057 1058 String rootScript = udata.getRootScript(); 1059 1060 rootStream.writeUTF(rootScript); 1061 1062 rootStream.flush(); 1063 outJar.closeEntry(); 1064 1065 outJar.flush(); 1067 outJar.close(); 1068 } 1069 catch (Exception err) 1070 { 1071 err.printStackTrace(); 1072 } 1073 } 1074 1075 1082 public InputStream getResource(String res) throws Exception 1083 { 1084 InputStream result; 1085 String basePath = ""; 1086 ResourceManager rm = null; 1087 1088 try 1089 { 1090 rm = ResourceManager.getInstance(); 1091 basePath = rm.resourceBasePath; 1092 } 1093 catch (Exception e) 1094 { 1095 e.printStackTrace(); 1096 } 1097 1098 result = this.getClass().getResourceAsStream(basePath + res); 1099 1100 if (result == null) { throw new ResourceNotFoundException("Warning: Resource not found: " 1101 + res); } 1102 return result; 1103 } 1104 1105 1110 public void centerFrame(Window frame) 1111 { 1112 Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); 1113 Dimension frameSize = frame.getSize(); 1114 frame.setLocation(center.x - frameSize.width / 2, center.y - frameSize.height / 2 - 10); 1115 } 1116 1117 1122 public Dimension getPanelsContainerSize() 1123 { 1124 return panelsContainer.getSize(); 1125 } 1126 1127 1138 public void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, double wx, 1139 double wy) 1140 { 1141 gbc.gridx = gx; 1142 gbc.gridy = gy; 1143 gbc.gridwidth = gw; 1144 gbc.gridheight = gh; 1145 gbc.weightx = wx; 1146 gbc.weighty = wy; 1147 } 1148 1149 1152 public void exit() 1153 { 1154 if (installdata.canClose) 1155 { 1156 writeUninstallData(); 1158 Housekeeper.getInstance().shutDown(0); 1159 } 1160 else 1161 { 1162 if (Unpacker.isDiscardInterrupt() && interruptCount < MAX_INTERRUPT) 1164 { interruptCount++; 1166 return; 1167 } 1168 final String mkey = "installer.quit.reversemessage"; 1170 final String tkey = "installer.quit.reversetitle"; 1171 String message = langpack.getString(mkey); 1172 String title = langpack.getString(tkey); 1173 if (message.indexOf(mkey) > -1) message = langpack.getString("installer.quit.message"); 1175 if (title.indexOf(tkey) > -1) title = langpack.getString("installer.quit.title"); 1177 VariableSubstitutor vs = new VariableSubstitutor(installdata.getVariables()); 1179 message = vs.substitute(message, null); 1180 title = vs.substitute(title, null); 1181 int res = JOptionPane 1182 .showConfirmDialog(this, message, title, JOptionPane.YES_NO_OPTION); 1183 if (res == JOptionPane.YES_OPTION) 1184 { 1185 wipeAborted(); 1186 Housekeeper.getInstance().shutDown(0); 1187 } 1188 } 1189 } 1190 1191 1194 protected void wipeAborted() 1195 { 1196 Iterator it; 1197 1198 if (!Unpacker.interruptAll(40000)) return; 1201 1202 UninstallData u = UninstallData.getInstance(); 1204 it = u.getFilesList().iterator(); 1205 if (!it.hasNext()) return; 1206 while (it.hasNext()) 1207 { 1208 String p = (String ) it.next(); 1209 File f = new File (p); 1210 f.delete(); 1211 } 1212 String fullCleanup = installdata.getVariable("InstallerFrame.cleanAllAtInterrupt"); 1213 if (fullCleanup == null || !"no".equalsIgnoreCase(fullCleanup)) 1214 cleanWipe(new File (installdata.getInstallPath())); 1215 } 1216 1217 1222 private void cleanWipe(File file) 1223 { 1224 if (file.isDirectory()) 1225 { 1226 File [] files = file.listFiles(); 1227 int size = files.length; 1228 for (int i = 0; i < size; i++) 1229 cleanWipe(files[i]); 1230 } 1231 file.delete(); 1232 } 1233 1234 1239 public void install(AbstractUIProgressHandler listener) 1240 { 1241 IUnpacker unpacker = UnpackerFactory.getUnpacker(this.installdata.info.getUnpackerClassName(), installdata, listener); 1242 Thread unpackerthread = new Thread (unpacker, "IzPack - Unpacker thread"); 1243 unpackerthread.start(); 1244 1248 } 1249 1250 1257 public void writeXMLTree(XMLElement root, OutputStream out) throws Exception 1258 { 1259 XMLWriter writer = new XMLWriter(out); 1260 for (int i = 0; i < installdata.panels.size(); i++) 1263 { 1264 IzPanel panel = (IzPanel) installdata.panels.get(i); 1265 panel.makeXMLData(installdata.xmlData.getChildAtIndex(i)); 1266 } 1267 writer.write(installdata.xmlData); 1268 } 1269 1270 1275 public void setQuitButtonText(String text) 1276 { 1277 String text1 = text; 1278 if (text1 == null) text1 = langpack.getString("installer.quit"); 1279 quitButton.setText(text1); 1280 } 1281 1282 1287 public void setQuitButtonIcon(String iconName) 1288 { 1289 String useButtonIcons = (String ) installdata.guiPrefs.modifier.get("useButtonIcons"); 1290 1291 if (useButtonIcons == null || "yes".equalsIgnoreCase(useButtonIcons)) 1292 { 1293 quitButton.setIcon(icons.getImageIcon(iconName)); 1294 } 1295 } 1296 1297 1301 private Object usualFTP = null; 1302 1303 private Object blockFTP = null; 1304 1305 1308 public void blockGUI() 1309 { 1310 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 1311 getGlassPane().setVisible(true); 1312 getGlassPane().setEnabled(true); 1313 if (JAVA_SPECIFICATION_VERSION < 1.35) return; 1315 if (usualFTP == null) usualFTP = getFocusTraversalPolicy(); 1316 if (blockFTP == null) blockFTP = new BlockFocusTraversalPolicy(); 1317 setFocusTraversalPolicy((java.awt.FocusTraversalPolicy ) blockFTP); 1318 getGlassPane().requestFocus(); 1319 callGUIListener(GUIListener.GUI_BLOCKED); 1320 1321 } 1322 1323 1326 public void releaseGUI() 1327 { 1328 getGlassPane().setEnabled(false); 1329 getGlassPane().setVisible(false); 1330 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 1331 if (JAVA_SPECIFICATION_VERSION < 1.35) return; 1333 setFocusTraversalPolicy((java.awt.FocusTraversalPolicy ) usualFTP); 1334 callGUIListener(GUIListener.GUI_RELEASED); 1335 } 1336 1337 1340 public void lockPrevButton() 1341 { 1342 prevButton.setEnabled(false); 1343 } 1344 1345 1348 public void lockNextButton() 1349 { 1350 nextButton.setEnabled(false); 1351 } 1352 1353 1356 public void unlockPrevButton() 1357 { 1358 prevButton.setEnabled(true); 1359 } 1360 1361 1364 public void unlockNextButton() 1365 { 1366 nextButton.setEnabled(true); 1367 nextButton.requestFocus(); 1368 } 1369 1370 1373 public void skipPanel() 1374 { 1375 if (installdata.curPanelNumber < installdata.panels.size() - 1) 1376 { 1377 if (isBack) 1378 { 1379 installdata.curPanelNumber--; 1380 switchPanel(installdata.curPanelNumber + 1); 1381 } 1382 else 1383 { 1384 installdata.curPanelNumber++; 1385 switchPanel(installdata.curPanelNumber - 1); 1386 } 1387 1388 } 1389 } 1390 1391 public boolean canShow(int panelnumber) 1392 { 1393 IzPanel panel = (IzPanel) installdata.panels.get(panelnumber); 1394 String panelid = panel.getMetadata().getPanelid(); 1395 Debug.trace("Current Panel: " + panelid); 1396 1397 if (!this.getRules().canShowPanel(panelid, this.installdata.variables)) 1398 { 1399 Debug.log("Skip panel with panelid=" + panelid); 1401 return false; 1403 } 1404 else 1405 { 1406 return true; 1407 } 1408 } 1409 1410 1413 public void navigateNext() 1414 { 1415 if (!nextButton.isEnabled()) return; 1418 this.navigateNext(installdata.curPanelNumber); 1419 } 1420 1421 public void navigateNext(int last) 1422 { 1423 if ((installdata.curPanelNumber < installdata.panels.size() - 1)) 1424 { 1425 installdata.curPanelNumber++; 1426 if (!canShow(installdata.curPanelNumber)) 1427 { 1428 this.navigateNext(last); 1429 return; 1430 } 1431 else 1432 { 1433 if (((IzPanel) installdata.panels.get(last)).isValidated()) 1434 { 1435 switchPanel(last); 1436 } 1437 else { 1438 installdata.curPanelNumber--; 1439 } 1440 } 1441 } 1442 } 1443 1444 1447 public void navigatePrevious() 1448 { 1449 if (!prevButton.isEnabled()) return; 1452 this.navigatePrevious(installdata.curPanelNumber); 1453 } 1454 1455 public void navigatePrevious(int last) 1456 { 1457 if ((installdata.curPanelNumber > 0)) 1458 { 1459 installdata.curPanelNumber--; 1460 if (!canShow(installdata.curPanelNumber)) 1461 { 1462 this.navigatePrevious(last); 1463 return; 1464 } 1465 else 1466 { 1467 switchPanel(last); 1468 } 1469 } 1470 } 1471 1472 1477 class NavigationHandler implements ActionListener 1478 { 1479 1480 1485 public void actionPerformed(ActionEvent e) 1486 { 1487 Object source = e.getSource(); 1488 if (source == prevButton) 1489 { 1490 navigatePrevious(); 1491 } 1492 else if (source == nextButton) 1493 { 1494 navigateNext(); 1495 } 1496 else if (source == quitButton) exit(); 1497 1498 } 1499 } 1500 1501 1506 class WindowHandler extends WindowAdapter 1507 { 1508 1509 1514 public void windowClosing(WindowEvent e) 1515 { 1516 exit(); 1518 } 1519 1520 1532 } 1533 1534 1537 private class BlockFocusTraversalPolicy extends java.awt.DefaultFocusTraversalPolicy 1538 { 1539 1540 private static final long serialVersionUID = 3258413928261169209L; 1541 1542 1548 protected boolean accept(Component aComp) 1549 { 1550 return aComp == getGlassPane(); 1551 } 1552 } 1553 1554 1559 public List getGuiListener() 1560 { 1561 return guiListener; 1562 } 1563 1564 1569 public void addGuiListener(GUIListener listener) 1570 { 1571 guiListener.add(listener); 1572 } 1573 1574 private void createHeadingLabels(int headingLines, Color back) 1575 { 1576 headingLabels = new JLabel [headingLines + 1]; 1579 headingLabels[0] = new JLabel (""); 1580 headingLabels[0].setFont(headingLabels[0].getFont().deriveFont(Font.BOLD)); 1582 if (installdata.guiPrefs.modifier.containsKey("headingFontSize")) 1583 { 1584 float fontSize = Float.parseFloat((String ) installdata.guiPrefs.modifier 1585 .get("headingFontSize")); 1586 if (fontSize > 0.0 && fontSize <= 5.0) 1587 { 1588 float currentSize = headingLabels[0].getFont().getSize2D(); 1589 headingLabels[0].setFont(headingLabels[0].getFont().deriveFont( 1590 currentSize * fontSize)); 1591 } 1592 } 1593 for (int i = 1; i < headingLines; ++i) 1594 { 1595 headingLabels[i] = new JLabel (); 1596 headingLabels[i].setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 0)); 1598 } 1599 1600 } 1601 1602 private void createHeadingCounter(Color back, JPanel navPanel, JPanel leftHeadingPanel) 1603 { 1604 int i; 1605 String counterPos = "inHeading"; 1606 if (installdata.guiPrefs.modifier.containsKey("headingPanelCounterPos")) 1607 counterPos = (String ) installdata.guiPrefs.modifier.get("headingPanelCounterPos"); 1608 if (leftHeadingPanel == null && "inHeading".equalsIgnoreCase(counterPos)) return; 1610 if (installdata.guiPrefs.modifier.containsKey("headingPanelCounter")) 1611 { 1612 headingCounterComponent = null; 1613 if ("progressbar".equalsIgnoreCase((String ) installdata.guiPrefs.modifier 1614 .get("headingPanelCounter"))) 1615 { 1616 JProgressBar headingProgressBar = new JProgressBar (); 1617 headingProgressBar.setStringPainted(true); 1618 headingProgressBar.setString(""); 1619 headingProgressBar.setValue(0); 1620 headingCounterComponent = headingProgressBar; 1621 } 1622 else if ("text".equalsIgnoreCase((String ) installdata.guiPrefs.modifier 1623 .get("headingPanelCounter"))) 1624 { 1625 JLabel headingCountPanels = new JLabel (" "); 1626 headingCounterComponent = headingCountPanels; 1627 headingCounterComponent.setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 0)); 1628 } 1629 if ("inHeading".equals(counterPos)) 1630 { 1631 leftHeadingPanel.add(headingCounterComponent); 1632 } 1633 else if ("inNavigationPanel".equals(counterPos)) 1634 { 1635 Component [] comps = navPanel.getComponents(); 1636 for (i = 0; i < comps.length; ++i) 1637 { 1638 if (comps[i].equals(prevButton)) break; 1639 } 1640 if (i <= comps.length) 1641 { 1642 navPanel.add(Box.createHorizontalGlue(), i); 1643 navPanel.add(headingCounterComponent, i); 1644 } 1645 1646 } 1647 } 1648 } 1649 1650 private JPanel createHeadingIcon(Color back) 1651 { 1652 ImageIcon icon = null; 1654 try 1655 { 1656 icon = loadIcon(HEADING_ICON_RESOURCE, 0, true); 1657 } 1658 catch (Exception e) 1659 { 1660 } 1662 JPanel imgPanel = new JPanel (); 1663 imgPanel.setLayout(new BoxLayout (imgPanel, BoxLayout.Y_AXIS)); 1664 imgPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); 1665 if (back != null) imgPanel.setBackground(back); 1666 JLabel iconLab = new JLabel (icon); 1667 imgPanel.add(iconLab, BorderLayout.EAST); 1668 headingLabels[headingLabels.length - 1] = iconLab; 1669 return (imgPanel); 1670 1671 } 1672 1673 private void createHeading(JPanel navPanel) 1674 { 1675 headingPanel = null; 1676 int headingLines = 1; 1677 if (installdata.guiPrefs.modifier.containsKey("headingLineCount")) 1680 headingLines = Integer.parseInt((String ) installdata.guiPrefs.modifier 1681 .get("headingLineCount")); 1682 Color back = null; 1683 int i = 0; 1684 if (installdata.guiPrefs.modifier.containsKey("headingBackgroundColor")) 1686 back = Color.decode((String ) installdata.guiPrefs.modifier 1687 .get("headingBackgroundColor")); 1688 if (!isHeading(null)) 1690 { 1691 createHeadingCounter(back, navPanel, null); 1692 return; 1693 } 1694 1695 createHeadingLabels(headingLines, back); 1698 JPanel leftHeadingPanel = new JPanel (); 1700 if (back != null) leftHeadingPanel.setBackground(back); 1701 leftHeadingPanel.setLayout(new BoxLayout (leftHeadingPanel, BoxLayout.Y_AXIS)); 1702 for (i = 0; i < headingLines; ++i) 1703 leftHeadingPanel.add(headingLabels[i]); 1704 createHeadingCounter(back, navPanel, leftHeadingPanel); 1708 JPanel imgPanel = createHeadingIcon(back); 1710 1711 JPanel northPanel = new JPanel (); 1713 if (back != null) northPanel.setBackground(back); 1714 northPanel.setLayout(new BoxLayout (northPanel, BoxLayout.X_AXIS)); 1715 northPanel.setBorder(BorderFactory.createEmptyBorder(0, 12, 0, 0)); 1716 northPanel.add(leftHeadingPanel); 1717 northPanel.add(Box.createHorizontalGlue()); 1718 northPanel.add(imgPanel); 1719 headingPanel = new JPanel (new BorderLayout ()); 1720 headingPanel.add(northPanel); 1721 headingPanel.add(new JSeparator (), BorderLayout.SOUTH); 1722 1723 contentPane.add(headingPanel, BorderLayout.NORTH); 1725 1726 } 1727 1728 1738 public boolean isHeading(IzPanel caller) 1739 { 1740 if (!installdata.guiPrefs.modifier.containsKey("useHeadingPanel") 1741 || !((String ) installdata.guiPrefs.modifier.get("useHeadingPanel")) 1742 .equalsIgnoreCase("yes")) return (false); 1743 if (caller == null) return (true); 1744 return (caller.getI18nStringForClass("headline", null) != null); 1745 1746 } 1747 1748 private void performHeading(IzPanel panel) 1749 { 1750 int i; 1751 int headingLines = 1; 1752 if (installdata.guiPrefs.modifier.containsKey("headingLineCount")) 1753 headingLines = Integer.parseInt((String ) installdata.guiPrefs.modifier 1754 .get("headingLineCount")); 1755 1756 if (headingLabels == null) return; 1757 String headline = panel.getI18nStringForClass("headline"); 1758 if (headline == null) 1759 { 1760 headingPanel.setVisible(false); 1761 return; 1762 } 1763 for (i = 0; i <= headingLines; ++i) 1764 if (headingLabels[i] != null) headingLabels[i].setVisible(false); 1765 String info; 1766 for (i = 0; i < headingLines - 1; ++i) 1767 { 1768 info = panel.getI18nStringForClass("headinfo" + Integer.toString(i)); 1769 if (info == null) info = " "; 1770 if (info.endsWith(":")) 1771 { 1772 info = info.substring(0, info.length() - 1) + "."; 1773 } 1774 headingLabels[i + 1].setText(info); 1775 headingLabels[i + 1].setVisible(true); 1776 } 1777 headingLabels[0].setText(headline); 1779 headingLabels[0].setVisible(true); 1780 int curPanelNo = ((Integer ) visiblePanelMapping.get(installdata.curPanelNumber)).intValue(); 1781 if (headingLabels[headingLines] != null) 1782 { 1783 loadAndShowImage(headingLabels[headingLines], HEADING_ICON_RESOURCE, curPanelNo); 1784 headingLabels[headingLines].setVisible(true); 1785 } 1786 headingPanel.setVisible(true); 1787 1788 } 1789 1790 private void performHeadingCounter(IzPanel panel) 1791 { 1792 if (headingCounterComponent != null) 1793 { 1794 int curPanelNo = ((Integer ) visiblePanelMapping.get(installdata.curPanelNumber)) 1795 .intValue(); 1796 int visPanelsCount = ((Integer ) visiblePanelMapping.get(((Integer ) visiblePanelMapping 1797 .get(installdata.panels.size())).intValue())).intValue(); 1798 1799 StringBuffer buf = new StringBuffer (); 1800 buf.append(langpack.getString("installer.step")).append(" ").append(curPanelNo + 1) 1801 .append(" ").append(langpack.getString("installer.of")).append(" ").append( 1802 visPanelsCount + 1); 1803 if (headingCounterComponent instanceof JProgressBar ) 1804 { 1805 JProgressBar headingProgressBar = (JProgressBar ) headingCounterComponent; 1806 headingProgressBar.setMaximum(visPanelsCount + 1); 1807 headingProgressBar.setValue(curPanelNo + 1); 1808 headingProgressBar.setString(buf.toString()); 1809 } 1810 else 1811 ((JLabel ) headingCounterComponent).setText(buf.toString()); 1812 } 1813 } 1814 1815 1818 public RulesEngine getRules() 1819 { 1820 return this.rules; 1821 } 1822 1823 1826 public void setRules(RulesEngine rules) 1827 { 1828 this.rules = rules; 1829 } 1830} 1831 | Popular Tags |