root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / panels / FinishPanel.java @ 15280
History | View | Annotate | Download (6.61 KB)
1 |
/*
|
---|---|
2 |
* $Id: FinishPanel.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
3 |
* IzPack
|
4 |
* Copyright (C) 2001-2004 Julien Ponge
|
5 |
*
|
6 |
* File : FinishPanel.java
|
7 |
* Description : A panel to end with the installation.
|
8 |
* Author's email : julien@izforge.com
|
9 |
* Author's Website : http://www.izforge.com
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
24 |
*/
|
25 |
package com.izforge.izpack.panels; |
26 |
|
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.awt.Insets; |
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
import java.io.BufferedOutputStream; |
33 |
import java.io.File; |
34 |
import java.io.FileOutputStream; |
35 |
|
36 |
import javax.swing.Box; |
37 |
import javax.swing.BoxLayout; |
38 |
import javax.swing.JButton; |
39 |
import javax.swing.JFileChooser; |
40 |
import javax.swing.JLabel; |
41 |
import javax.swing.JOptionPane; |
42 |
import javax.swing.JPanel; |
43 |
|
44 |
import com.izforge.izpack.gui.ButtonFactory; |
45 |
import com.izforge.izpack.gui.LabelFactory; |
46 |
import com.izforge.izpack.installer.InstallData; |
47 |
import com.izforge.izpack.installer.InstallerFrame; |
48 |
import com.izforge.izpack.installer.IzPanel; |
49 |
import com.izforge.izpack.installer.VariableSubstitutor; |
50 |
|
51 |
/**
|
52 |
* The finish panel class.
|
53 |
*
|
54 |
* @author Julien Ponge
|
55 |
*/
|
56 |
public class FinishPanel extends IzPanel implements ActionListener |
57 |
{ |
58 |
/** The layout. */
|
59 |
private BoxLayout layout; |
60 |
|
61 |
/** The automated installers generation button. */
|
62 |
private JButton autoButton; |
63 |
|
64 |
/** The center panel. */
|
65 |
private JPanel centerPanel; |
66 |
|
67 |
/** The variables substitutor. */
|
68 |
private VariableSubstitutor vs;
|
69 |
|
70 |
/**
|
71 |
* The constructor.
|
72 |
*
|
73 |
* @param parent The parent.
|
74 |
* @param idata The installation data.
|
75 |
*/
|
76 |
public FinishPanel(InstallerFrame parent, InstallData idata)
|
77 |
{ |
78 |
super(parent, idata);
|
79 |
|
80 |
vs = new VariableSubstitutor(idata.getVariables());
|
81 |
|
82 |
// The 'super' layout
|
83 |
GridBagLayout superLayout = new GridBagLayout(); |
84 |
setLayout(superLayout); |
85 |
GridBagConstraints gbConstraints = new GridBagConstraints(); |
86 |
gbConstraints.insets = new Insets(0, 0, 0, 0); |
87 |
gbConstraints.fill = GridBagConstraints.NONE;
|
88 |
gbConstraints.anchor = GridBagConstraints.CENTER;
|
89 |
|
90 |
// We initialize our 'real' layout
|
91 |
centerPanel = new JPanel(); |
92 |
layout = new BoxLayout(centerPanel, BoxLayout.Y_AXIS); |
93 |
centerPanel.setLayout(layout); |
94 |
superLayout.addLayoutComponent(centerPanel, gbConstraints); |
95 |
add(centerPanel); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Indicates wether the panel has been validated or not.
|
100 |
*
|
101 |
* @return true if the panel has been validated.
|
102 |
*/
|
103 |
public boolean isValidated() |
104 |
{ |
105 |
return true; |
106 |
} |
107 |
|
108 |
/** Called when the panel becomes active. */
|
109 |
public void panelActivate() |
110 |
{ |
111 |
parent.lockNextButton(); |
112 |
parent.lockPrevButton(); |
113 |
parent.setQuitButtonText(parent.langpack.getString("FinishPanel.done"));
|
114 |
if (idata.installSuccess)
|
115 |
{ |
116 |
// We set the information
|
117 |
centerPanel.add( |
118 |
LabelFactory.create( |
119 |
parent.langpack.getString("FinishPanel.success"),
|
120 |
parent.icons.getImageIcon("information"),
|
121 |
JLabel.TRAILING));
|
122 |
centerPanel.add(Box.createVerticalStrut(20)); |
123 |
|
124 |
if (idata.uninstallOutJar != null) |
125 |
{ |
126 |
// We prepare a message for the uninstaller feature
|
127 |
String path =
|
128 |
translatePath("$INSTALL_PATH") + File.separator + "Uninstaller"; |
129 |
|
130 |
centerPanel.add( |
131 |
LabelFactory.create( |
132 |
parent.langpack.getString("FinishPanel.uninst.info"),
|
133 |
parent.icons.getImageIcon("information"),
|
134 |
JLabel.TRAILING));
|
135 |
centerPanel.add( |
136 |
LabelFactory.create( |
137 |
path, |
138 |
parent.icons.getImageIcon("empty"),
|
139 |
JLabel.TRAILING));
|
140 |
} |
141 |
|
142 |
// We add the autoButton
|
143 |
centerPanel.add(Box.createVerticalStrut(20)); |
144 |
autoButton = |
145 |
ButtonFactory.createButton( |
146 |
parent.langpack.getString("FinishPanel.auto"),
|
147 |
parent.icons.getImageIcon("edit"),
|
148 |
idata.buttonsHColor); |
149 |
autoButton.setToolTipText( |
150 |
parent.langpack.getString("FinishPanel.auto.tip"));
|
151 |
autoButton.addActionListener(this);
|
152 |
centerPanel.add(autoButton); |
153 |
} else
|
154 |
centerPanel.add( |
155 |
LabelFactory.create( |
156 |
parent.langpack.getString("FinishPanel.fail"),
|
157 |
parent.icons.getImageIcon("information"),
|
158 |
JLabel.TRAILING));
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Actions-handling method.
|
163 |
*
|
164 |
* @param e The event.
|
165 |
*/
|
166 |
public void actionPerformed(ActionEvent e) |
167 |
{ |
168 |
// Prepares the file chooser
|
169 |
JFileChooser fc = new JFileChooser(); |
170 |
fc.setCurrentDirectory(new File(idata.getInstallPath())); |
171 |
fc.setMultiSelectionEnabled(false);
|
172 |
fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); |
173 |
//fc.setCurrentDirectory(new File("."));
|
174 |
|
175 |
// Shows it
|
176 |
try
|
177 |
{ |
178 |
if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) |
179 |
{ |
180 |
// We handle the xml data writing
|
181 |
File file = fc.getSelectedFile();
|
182 |
FileOutputStream out = new FileOutputStream(file); |
183 |
BufferedOutputStream outBuff = new BufferedOutputStream(out, 5120); |
184 |
parent.writeXMLTree(idata.xmlData, outBuff); |
185 |
outBuff.flush(); |
186 |
outBuff.close(); |
187 |
|
188 |
autoButton.setEnabled(false);
|
189 |
} |
190 |
} catch (Exception err) |
191 |
{ |
192 |
err.printStackTrace(); |
193 |
JOptionPane.showMessageDialog(
|
194 |
this,
|
195 |
err.toString(), |
196 |
parent.langpack.getString("installer.error"),
|
197 |
JOptionPane.ERROR_MESSAGE);
|
198 |
} |
199 |
} |
200 |
|
201 |
/**
|
202 |
* Translates a relative path to a local system path.
|
203 |
*
|
204 |
* @param destination The path to translate.
|
205 |
* @return The translated path.
|
206 |
*/
|
207 |
private String translatePath(String destination) |
208 |
{ |
209 |
// Parse for variables
|
210 |
destination = vs.substitute(destination, null);
|
211 |
|
212 |
// Convert the file separator characters
|
213 |
return destination.replace('/', File.separatorChar); |
214 |
} |
215 |
} |