001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
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:
020: package com.izforge.izpack.panels;
021:
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.io.BufferedOutputStream;
025: import java.io.File;
026: import java.io.FileOutputStream;
027:
028: import javax.swing.JButton;
029: import javax.swing.JFileChooser;
030: import javax.swing.JOptionPane;
031:
032: import com.izforge.izpack.gui.ButtonFactory;
033: import com.izforge.izpack.gui.IzPanelLayout;
034: import com.izforge.izpack.gui.LabelFactory;
035: import com.izforge.izpack.installer.InstallData;
036: import com.izforge.izpack.installer.InstallerFrame;
037: import com.izforge.izpack.installer.IzPanel;
038: import com.izforge.izpack.util.Log;
039: import com.izforge.izpack.util.VariableSubstitutor;
040:
041: /**
042: * The finish panel class.
043: *
044: * @author Julien Ponge
045: */
046: public class FinishPanel extends IzPanel implements ActionListener {
047:
048: private static final long serialVersionUID = 3257282535107998009L;
049:
050: /** The automated installers generation button. */
051: protected JButton autoButton;
052:
053: /** The variables substitutor. */
054: protected VariableSubstitutor vs;
055:
056: /**
057: * The constructor.
058: *
059: * @param parent The parent.
060: * @param idata The installation data.
061: */
062: public FinishPanel(InstallerFrame parent, InstallData idata) {
063: super (parent, idata, new IzPanelLayout());
064:
065: vs = new VariableSubstitutor(idata.getVariables());
066: }
067:
068: /**
069: * Indicates wether the panel has been validated or not.
070: *
071: * @return true if the panel has been validated.
072: */
073: public boolean isValidated() {
074: return true;
075: }
076:
077: /** Called when the panel becomes active. */
078: public void panelActivate() {
079: parent.lockNextButton();
080: parent.lockPrevButton();
081: parent.setQuitButtonText(parent.langpack
082: .getString("FinishPanel.done"));
083: parent.setQuitButtonIcon("done");
084: if (idata.installSuccess) {
085: // We set the information
086: add(LabelFactory.create(parent.langpack
087: .getString("FinishPanel.success"), parent.icons
088: .getImageIcon("information"), LEADING), NEXT_LINE);
089: add(IzPanelLayout.createParagraphGap());
090: if (idata.uninstallOutJar != null) {
091: // We prepare a message for the uninstaller feature
092: String path = translatePath("$INSTALL_PATH")
093: + File.separator + "Uninstaller";
094:
095: add(LabelFactory.create(parent.langpack
096: .getString("FinishPanel.uninst.info"),
097: parent.icons.getImageIcon("information"),
098: LEADING), NEXT_LINE);
099: add(LabelFactory.create(path, parent.icons
100: .getImageIcon("empty"), LEADING), NEXT_LINE);
101: }
102:
103: // We add the autoButton
104: add(IzPanelLayout.createParagraphGap());
105: autoButton = ButtonFactory.createButton(parent.langpack
106: .getString("FinishPanel.auto"), parent.icons
107: .getImageIcon("edit"), idata.buttonsHColor);
108: autoButton.setToolTipText(parent.langpack
109: .getString("FinishPanel.auto.tip"));
110: autoButton.addActionListener(this );
111: add(autoButton, NEXT_LINE);
112: } else
113: add(LabelFactory.create(parent.langpack
114: .getString("FinishPanel.fail"), parent.icons
115: .getImageIcon("information"), LEADING), NEXT_LINE);
116: getLayoutHelper().completeLayout(); // Call, or call not?
117: Log.getInstance().informUser();
118: }
119:
120: /**
121: * Actions-handling method.
122: *
123: * @param e The event.
124: */
125: public void actionPerformed(ActionEvent e) {
126: // Prepares the file chooser
127: JFileChooser fc = new JFileChooser();
128: fc.setCurrentDirectory(new File(idata.getInstallPath()));
129: fc.setMultiSelectionEnabled(false);
130: fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
131: // fc.setCurrentDirectory(new File("."));
132:
133: // Shows it
134: try {
135: if (fc.showSaveDialog(this ) == JFileChooser.APPROVE_OPTION) {
136: // We handle the xml data writing
137: File file = fc.getSelectedFile();
138: FileOutputStream out = new FileOutputStream(file);
139: BufferedOutputStream outBuff = new BufferedOutputStream(
140: out, 5120);
141: parent.writeXMLTree(idata.xmlData, outBuff);
142: outBuff.flush();
143: outBuff.close();
144:
145: autoButton.setEnabled(false);
146: }
147: } catch (Exception err) {
148: err.printStackTrace();
149: JOptionPane.showMessageDialog(this , err.toString(),
150: parent.langpack.getString("installer.error"),
151: JOptionPane.ERROR_MESSAGE);
152: }
153: }
154:
155: /**
156: * Translates a relative path to a local system path.
157: *
158: * @param destination The path to translate.
159: * @return The translated path.
160: */
161: protected String translatePath(String destination) {
162: // Parse for variables
163: destination = vs.substitute(destination, null);
164:
165: // Convert the file separator characters
166: return destination.replace('/', File.separatorChar);
167: }
168: }
|