KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > panels > FinishPanel


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package com.izforge.izpack.panels;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.io.BufferedOutputStream JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.FileOutputStream JavaDoc;
27
28 import javax.swing.JButton JavaDoc;
29 import javax.swing.JFileChooser JavaDoc;
30 import javax.swing.JOptionPane JavaDoc;
31
32 import com.izforge.izpack.gui.ButtonFactory;
33 import com.izforge.izpack.gui.IzPanelLayout;
34 import com.izforge.izpack.gui.LabelFactory;
35 import com.izforge.izpack.installer.InstallData;
36 import com.izforge.izpack.installer.InstallerFrame;
37 import com.izforge.izpack.installer.IzPanel;
38 import com.izforge.izpack.util.VariableSubstitutor;
39
40 /**
41  * The finish panel class.
42  *
43  * @author Julien Ponge
44  */

45 public class FinishPanel extends IzPanel implements ActionListener JavaDoc
46 {
47
48     private static final long serialVersionUID = 3257282535107998009L;
49
50     /** The automated installers generation button. */
51     protected JButton JavaDoc autoButton;
52
53     /** The variables substitutor. */
54     protected VariableSubstitutor vs;
55
56     /**
57      * The constructor.
58      *
59      * @param parent The parent.
60      * @param idata The installation data.
61      */

62     public FinishPanel(InstallerFrame parent, InstallData idata)
63     {
64         super(parent, idata, new IzPanelLayout());
65
66         vs = new VariableSubstitutor(idata.getVariables());
67     }
68
69     /**
70      * Indicates wether the panel has been validated or not.
71      *
72      * @return true if the panel has been validated.
73      */

74     public boolean isValidated()
75     {
76         return true;
77     }
78
79     /** Called when the panel becomes active. */
80     public void panelActivate()
81     {
82         parent.lockNextButton();
83         parent.lockPrevButton();
84         parent.setQuitButtonText(parent.langpack.getString("FinishPanel.done"));
85         parent.setQuitButtonIcon("done");
86         if (idata.installSuccess)
87         {
88             // We set the information
89
add(LabelFactory.create(parent.langpack.getString("FinishPanel.success"),
90                     parent.icons.getImageIcon("information"), LEADING), NEXT_LINE);
91             add(IzPanelLayout.createParagraphGap());
92             if (idata.uninstallOutJar != null)
93             {
94                 // We prepare a message for the uninstaller feature
95
String JavaDoc path = translatePath("$INSTALL_PATH") + File.separator + "Uninstaller";
96
97                 add(LabelFactory.create(parent.langpack
98                         .getString("FinishPanel.uninst.info"), parent.icons
99                         .getImageIcon("information"), LEADING), NEXT_LINE);
100                 add(LabelFactory.create(path, parent.icons.getImageIcon("empty"),
101                         LEADING), NEXT_LINE);
102             }
103
104             // We add the autoButton
105
add(IzPanelLayout.createParagraphGap());
106             autoButton = ButtonFactory.createButton(parent.langpack.getString("FinishPanel.auto"),
107                     parent.icons.getImageIcon("edit"), idata.buttonsHColor);
108             autoButton.setToolTipText(parent.langpack.getString("FinishPanel.auto.tip"));
109             autoButton.addActionListener(this);
110             add(autoButton, NEXT_LINE);
111         }
112         else
113             add(LabelFactory.create(parent.langpack.getString("FinishPanel.fail"),
114                     parent.icons.getImageIcon("information"), LEADING), NEXT_LINE);
115         getLayoutHelper().completeLayout(); // Call, or call not?
116
}
117
118     /**
119      * Actions-handling method.
120      *
121      * @param e The event.
122      */

123     public void actionPerformed(ActionEvent JavaDoc e)
124     {
125         // Prepares the file chooser
126
JFileChooser JavaDoc fc = new JFileChooser JavaDoc();
127         fc.setCurrentDirectory(new File JavaDoc(idata.getInstallPath()));
128         fc.setMultiSelectionEnabled(false);
129         fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
130         // fc.setCurrentDirectory(new File("."));
131

132         // Shows it
133
try
134         {
135             if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
136             {
137                 // We handle the xml data writing
138
File JavaDoc file = fc.getSelectedFile();
139                 FileOutputStream JavaDoc out = new FileOutputStream JavaDoc(file);
140                 BufferedOutputStream JavaDoc outBuff = new BufferedOutputStream JavaDoc(out, 5120);
141                 parent.writeXMLTree(idata.xmlData, outBuff);
142                 outBuff.flush();
143                 outBuff.close();
144
145                 autoButton.setEnabled(false);
146             }
147         }
148         catch (Exception JavaDoc err)
149         {
150             err.printStackTrace();
151             JOptionPane.showMessageDialog(this, err.toString(), parent.langpack
152                     .getString("installer.error"), JOptionPane.ERROR_MESSAGE);
153         }
154     }
155
156     /**
157      * Translates a relative path to a local system path.
158      *
159      * @param destination The path to translate.
160      * @return The translated path.
161      */

162     protected String JavaDoc translatePath(String JavaDoc destination)
163     {
164         // Parse for variables
165
destination = vs.substitute(destination, null);
166
167         // Convert the file separator characters
168
return destination.replace('/', File.separatorChar);
169     }
170 }
171
Popular Tags