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.Dimension;
023:
024: import javax.swing.JLabel;
025: import javax.swing.JOptionPane;
026: import javax.swing.JProgressBar;
027: import javax.swing.SwingUtilities;
028:
029: import com.izforge.izpack.gui.IzPanelLayout;
030: import com.izforge.izpack.gui.LabelFactory;
031: import com.izforge.izpack.installer.InstallData;
032: import com.izforge.izpack.installer.InstallerFrame;
033: import com.izforge.izpack.installer.IzPanel;
034: import com.izforge.izpack.util.AbstractUIProgressHandler;
035:
036: /**
037: * The install panel class. Launches the actual installation job.
038: *
039: * @author Julien Ponge
040: */
041: public class InstallPanel extends IzPanel implements
042: AbstractUIProgressHandler {
043:
044: private static final long serialVersionUID = 3257282547959410992L;
045:
046: /** The tip label. */
047: protected JLabel tipLabel;
048:
049: /** The operation label . */
050: protected JLabel packOpLabel;
051:
052: /** The operation label . */
053: protected JLabel overallOpLabel;
054:
055: /** The pack progress bar. */
056: protected JProgressBar packProgressBar;
057:
058: /** The progress bar. */
059: protected JProgressBar overallProgressBar;
060:
061: /** True if the installation has been done. */
062: private volatile boolean validated = false;
063:
064: /** How many packs we are going to install. */
065: private int noOfPacks = 0;
066:
067: /**
068: * The constructor.
069: *
070: * @param parent The parent window.
071: * @param idata The installation data.
072: */
073: public InstallPanel(InstallerFrame parent, InstallData idata) {
074: super (parent, idata, new IzPanelLayout());
075: this .tipLabel = LabelFactory.create(parent.langpack
076: .getString("InstallPanel.tip"), parent.icons
077: .getImageIcon("information"), LEADING);
078: add(this .tipLabel, IzPanelLayout
079: .getDefaultConstraint(FULL_LINE_CONTROL_CONSTRAINT));
080: packOpLabel = LabelFactory.create(" ", LEADING);
081: add(packOpLabel, IzPanelLayout
082: .getDefaultConstraint(FULL_LINE_CONTROL_CONSTRAINT));
083:
084: packProgressBar = new JProgressBar();
085: packProgressBar.setStringPainted(true);
086: packProgressBar.setString(parent.langpack
087: .getString("InstallPanel.begin"));
088: packProgressBar.setValue(0);
089: add(packProgressBar, IzPanelLayout
090: .getDefaultConstraint(FULL_LINE_CONTROL_CONSTRAINT));
091: // make sure there is some space between the progress bars
092: add(IzPanelLayout.createParagraphGap());
093:
094: overallOpLabel = LabelFactory.create(parent.langpack
095: .getString("InstallPanel.progress"), parent.icons
096: .getImageIcon("information"), LEADING);
097: add(this .overallOpLabel, IzPanelLayout
098: .getDefaultConstraint(FULL_LINE_CONTROL_CONSTRAINT));
099:
100: overallProgressBar = new JProgressBar();
101: overallProgressBar.setStringPainted(true);
102: overallProgressBar.setString("");
103: overallProgressBar.setValue(0);
104: add(this .overallProgressBar, IzPanelLayout
105: .getDefaultConstraint(FULL_LINE_CONTROL_CONSTRAINT));
106: getLayoutHelper().completeLayout();
107:
108: }
109:
110: /**
111: * Indicates wether the panel has been validated or not.
112: *
113: * @return The validation state.
114: */
115: public boolean isValidated() {
116: return this .validated;
117: }
118:
119: /** The unpacker starts. */
120: public void startAction(String name, int noOfJobs) {
121: this .noOfPacks = noOfJobs;
122: SwingUtilities.invokeLater(new Runnable() {
123: public void run() {
124: parent.blockGUI();
125:
126: // figure out how many packs there are to install
127: overallProgressBar.setMinimum(0);
128: overallProgressBar.setMaximum(noOfPacks);
129: overallProgressBar.setString("0 / "
130: + Integer.toString(noOfPacks));
131: }
132: });
133: }
134:
135: /**
136: * An error was encountered.
137: *
138: * @param error The error text.
139: */
140: public void emitError(String title, String error) {
141: this .packOpLabel.setText(error);
142: idata.installSuccess = false;
143: JOptionPane.showMessageDialog(this , error, parent.langpack
144: .getString("installer.error"),
145: JOptionPane.ERROR_MESSAGE);
146: }
147:
148: /** The unpacker stops. */
149: public void stopAction() {
150: SwingUtilities.invokeLater(new Runnable() {
151: public void run() {
152: parent.releaseGUI();
153: parent.lockPrevButton();
154:
155: // With custom actions it is possible, that the current value
156: // is not max - 1. Therefore we use always max for both
157: // progress bars to signal finish state.
158: overallProgressBar.setValue(overallProgressBar
159: .getMaximum());
160: int ppbMax = packProgressBar.getMaximum();
161: if (ppbMax < 1) {
162: ppbMax = 1;
163: packProgressBar.setMaximum(ppbMax);
164: }
165: packProgressBar.setValue(ppbMax);
166:
167: packProgressBar.setString(parent.langpack
168: .getString("InstallPanel.finished"));
169: packProgressBar.setEnabled(false);
170: String no_of_packs = Integer.toString(noOfPacks);
171: overallProgressBar.setString(no_of_packs + " / "
172: + no_of_packs);
173: overallProgressBar.setEnabled(false);
174: packOpLabel.setText(" ");
175: packOpLabel.setEnabled(false);
176: idata.canClose = true;
177: validated = true;
178: if (idata.panels.indexOf(this ) != (idata.panels.size() - 1))
179: parent.unlockNextButton();
180: }
181: });
182: }
183:
184: /**
185: * Normal progress indicator.
186: *
187: * @param val The progression value.
188: * @param msg The progression message.
189: */
190: public void progress(final int val, final String msg) {
191: SwingUtilities.invokeLater(new Runnable() {
192: public void run() {
193: packProgressBar.setValue(val + 1);
194: packOpLabel.setText(msg);
195: }
196: });
197: }
198:
199: /**
200: * Pack changing.
201: *
202: * @param packName The pack name.
203: * @param stepno The number of the pack.
204: * @param max The new maximum progress.
205: */
206: public void nextStep(final String packName, final int stepno,
207: final int max) {
208: SwingUtilities.invokeLater(new Runnable() {
209: public void run() {
210: packProgressBar.setValue(0);
211: packProgressBar.setMinimum(0);
212: packProgressBar.setMaximum(max);
213: packProgressBar.setString(packName);
214: overallProgressBar.setValue(stepno - 1);
215: overallProgressBar.setString(Integer.toString(stepno)
216: + " / " + Integer.toString(noOfPacks));
217: }
218: });
219: }
220:
221: /**
222: * {@inheritDoc}
223: */
224: public void setSubStepNo(final int no_of_substeps) {
225: SwingUtilities.invokeLater(new Runnable() {
226: public void run() {
227: packProgressBar.setMaximum(no_of_substeps);
228: }
229: });
230: }
231:
232: /** Called when the panel becomes active. */
233: public void panelActivate() {
234: // We clip the panel
235: Dimension dim = parent.getPanelsContainerSize();
236: dim.width -= (dim.width / 4);
237: dim.height = 150;
238: setMinimumSize(dim);
239: setMaximumSize(dim);
240: setPreferredSize(dim);
241: parent.lockNextButton();
242:
243: parent.install(this);
244: }
245:
246: }
|