001/* 002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved. 003 * 004 * http://www.izforge.com/izpack/ 005 * http://developer.berlios.de/projects/izpack/ 006 * 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020package com.izforge.izpack.panels; 021 022import java.awt.GridBagConstraints; 023import java.awt.GridBagLayout; 024import java.awt.Insets; 025import java.io.File; 026 027import javax.swing.Box; 028import javax.swing.BoxLayout; 029import javax.swing.JLabel; 030import javax.swing.JPanel; 031 032import com.izforge.izpack.gui.LabelFactory; 033import com.izforge.izpack.installer.InstallData; 034import com.izforge.izpack.installer.InstallerFrame; 035import com.izforge.izpack.installer.IzPanel; 036import com.izforge.izpack.util.VariableSubstitutor; 037 038/** 039 * The simple finish panel class. 040 * 041 * @author Julien Ponge 042 */ 043public class SimpleFinishPanel extends IzPanel 044{ 045 046 /** 047 * 048 */ 049 private static final long serialVersionUID = 3689911781942572085L; 050 051 /** The layout. */ 052 private BoxLayout layout; 053 054 /** The center panel. */ 055 protected JPanel centerPanel; 056 057 /** The variables substitutor. */ 058 private VariableSubstitutor vs; 059 060 /** 061 * The constructor. 062 * 063 * @param parent The parent. 064 * @param idata The installation data. 065 */ 066 public SimpleFinishPanel(InstallerFrame parent, InstallData idata) 067 { 068 super(parent, idata); 069 070 vs = new VariableSubstitutor(idata.getVariables()); 071 072 // The 'super' layout 073 GridBagLayout superLayout = new GridBagLayout(); 074 setLayout(superLayout); 075 GridBagConstraints gbConstraints = new GridBagConstraints(); 076 gbConstraints.insets = new Insets(0, 0, 0, 0); 077 gbConstraints.fill = GridBagConstraints.NONE; 078 gbConstraints.anchor = GridBagConstraints.CENTER; 079 080 // We initialize our 'real' layout 081 centerPanel = new JPanel(); 082 layout = new BoxLayout(centerPanel, BoxLayout.Y_AXIS); 083 centerPanel.setLayout(layout); 084 superLayout.addLayoutComponent(centerPanel, gbConstraints); 085 add(centerPanel); 086 } 087 088 /** 089 * Indicates wether the panel has been validated or not. 090 * 091 * @return true if the panel has been validated. 092 */ 093 public boolean isValidated() 094 { 095 return true; 096 } 097 098 /** Called when the panel becomes active. */ 099 public void panelActivate() 100 { 101 parent.lockNextButton(); 102 parent.lockPrevButton(); 103 parent.setQuitButtonText(parent.langpack.getString("FinishPanel.done")); 104 if (idata.installSuccess) 105 { 106 // We set the information 107 centerPanel.add(LabelFactory.create(parent.icons.getImageIcon("check"))); 108 centerPanel.add(Box.createVerticalStrut(20)); 109 centerPanel.add(LabelFactory.create(parent.langpack.getString("FinishPanel.success"), 110 parent.icons.getImageIcon("information"), JLabel.TRAILING)); 111 centerPanel.add(Box.createVerticalStrut(20)); 112 113 if (idata.uninstallOutJar != null) 114 { 115 // We prepare a message for the uninstaller feature 116 String path = translatePath("$INSTALL_PATH") + File.separator + "Uninstaller"; 117 118 centerPanel.add(LabelFactory.create(parent.langpack 119 .getString("FinishPanel.uninst.info"), parent.icons 120 .getImageIcon("information"), JLabel.TRAILING)); 121 centerPanel.add(LabelFactory.create(path, parent.icons.getImageIcon("empty"), 122 JLabel.TRAILING)); 123 } 124 } 125 else 126 centerPanel.add(LabelFactory.create(parent.langpack.getString("FinishPanel.fail"), 127 parent.icons.getImageIcon("information"), JLabel.TRAILING)); 128 129 } 130 131 /** 132 * Translates a relative path to a local system path. 133 * 134 * @param destination The path to translate. 135 * @return The translated path. 136 */ 137 private String translatePath(String destination) 138 { 139 // Parse for variables 140 destination = vs.substitute(destination, null); 141 142 // Convert the file separator characters 143 return destination.replace('/', File.separatorChar); 144 } 145}