root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / panels / InstallPanel.java @ 15280
History | View | Annotate | Download (8.24 KB)
1 | 15280 | rgaitan | /*
|
---|---|---|---|
2 | * $Id: InstallPanel.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
||
3 | * IzPack
|
||
4 | * Copyright (C) 2001-2004 Julien Ponge
|
||
5 | *
|
||
6 | * File : InstallPanel.java
|
||
7 | * Description : A panel to launch the installation process.
|
||
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.Dimension; |
||
28 | import java.awt.GridBagConstraints; |
||
29 | import java.awt.GridBagLayout; |
||
30 | |||
31 | import javax.swing.JLabel; |
||
32 | import javax.swing.JOptionPane; |
||
33 | import javax.swing.JProgressBar; |
||
34 | import javax.swing.JSeparator; |
||
35 | |||
36 | import com.izforge.izpack.gui.LabelFactory; |
||
37 | import com.izforge.izpack.installer.InstallData; |
||
38 | import com.izforge.izpack.installer.InstallerFrame; |
||
39 | import com.izforge.izpack.installer.IzPanel; |
||
40 | import com.izforge.izpack.util.AbstractUIProgressHandler; |
||
41 | |||
42 | /**
|
||
43 | * The install panel class. Launches the actual installation job.
|
||
44 | *
|
||
45 | * @author Julien Ponge
|
||
46 | */
|
||
47 | public class InstallPanel extends IzPanel implements AbstractUIProgressHandler |
||
48 | { |
||
49 | /** The layout. */
|
||
50 | private GridBagLayout layout; |
||
51 | |||
52 | /** The layout constraints. */
|
||
53 | private GridBagConstraints gbConstraints; |
||
54 | |||
55 | /** The tip label. */
|
||
56 | protected JLabel tipLabel; |
||
57 | |||
58 | /** The operation label . */
|
||
59 | protected JLabel packOpLabel; |
||
60 | |||
61 | /** The operation label . */
|
||
62 | protected JLabel overallOpLabel; |
||
63 | |||
64 | /** The pack progress bar. */
|
||
65 | protected JProgressBar packProgressBar; |
||
66 | |||
67 | /** The progress bar. */
|
||
68 | protected JProgressBar overallProgressBar; |
||
69 | |||
70 | /** True if the installation has been done. */
|
||
71 | private volatile boolean validated = false; |
||
72 | |||
73 | /** How many packs we are going to install. */
|
||
74 | private int noOfPacks = 0; |
||
75 | |||
76 | /**
|
||
77 | * The constructor.
|
||
78 | *
|
||
79 | * @param parent The parent window.
|
||
80 | * @param idata The installation data.
|
||
81 | */
|
||
82 | public InstallPanel(InstallerFrame parent, InstallData idata)
|
||
83 | { |
||
84 | super(parent, idata);
|
||
85 | |||
86 | // We initialize our layout
|
||
87 | layout = new GridBagLayout(); |
||
88 | gbConstraints = new GridBagConstraints(); |
||
89 | setLayout(layout); |
||
90 | |||
91 | int row = 1; |
||
92 | |||
93 | this.tipLabel =
|
||
94 | LabelFactory.create( |
||
95 | parent.langpack.getString("InstallPanel.tip"),
|
||
96 | parent.icons.getImageIcon("information"),
|
||
97 | JLabel.TRAILING);
|
||
98 | parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0); |
||
99 | gbConstraints.fill = GridBagConstraints.NONE;
|
||
100 | gbConstraints.anchor = GridBagConstraints.NORTHWEST;
|
||
101 | layout.addLayoutComponent(this.tipLabel, gbConstraints);
|
||
102 | add(this.tipLabel);
|
||
103 | |||
104 | this.packOpLabel = LabelFactory.create(" ", JLabel.TRAILING); |
||
105 | parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0); |
||
106 | gbConstraints.anchor = GridBagConstraints.SOUTHWEST;
|
||
107 | layout.addLayoutComponent(this.packOpLabel, gbConstraints);
|
||
108 | add(this.packOpLabel);
|
||
109 | |||
110 | this.packProgressBar = new JProgressBar(); |
||
111 | this.packProgressBar.setStringPainted(true); |
||
112 | this.packProgressBar.setString(
|
||
113 | parent.langpack.getString("InstallPanel.begin"));
|
||
114 | this.packProgressBar.setValue(0); |
||
115 | parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0); |
||
116 | gbConstraints.anchor = GridBagConstraints.NORTH;
|
||
117 | gbConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
118 | layout.addLayoutComponent(this.packProgressBar, gbConstraints);
|
||
119 | add(this.packProgressBar);
|
||
120 | |||
121 | // make sure there is some space between the progress bars
|
||
122 | JSeparator sep = new JSeparator(); |
||
123 | Dimension dim = new Dimension(0, 10); |
||
124 | sep.setPreferredSize(dim); |
||
125 | sep.setMinimumSize(dim); |
||
126 | sep.setMaximumSize(dim); |
||
127 | parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0); |
||
128 | layout.addLayoutComponent(sep, gbConstraints); |
||
129 | add(sep); |
||
130 | |||
131 | this.overallOpLabel =
|
||
132 | LabelFactory.create( |
||
133 | parent.langpack.getString("InstallPanel.progress"),
|
||
134 | parent.icons.getImageIcon("information"),
|
||
135 | JLabel.TRAILING);
|
||
136 | parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0); |
||
137 | gbConstraints.anchor = GridBagConstraints.NORTHWEST;
|
||
138 | gbConstraints.fill = GridBagConstraints.NONE;
|
||
139 | layout.addLayoutComponent(this.overallOpLabel, gbConstraints);
|
||
140 | add(this.overallOpLabel);
|
||
141 | |||
142 | this.overallProgressBar = new JProgressBar(); |
||
143 | this.overallProgressBar.setStringPainted(true); |
||
144 | this.overallProgressBar.setString(""); |
||
145 | this.overallProgressBar.setValue(0); |
||
146 | parent.buildConstraints(gbConstraints, 0, row++, 2, 1, 1.0, 0.0); |
||
147 | gbConstraints.anchor = GridBagConstraints.NORTH;
|
||
148 | gbConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
149 | layout.addLayoutComponent(this.overallProgressBar, gbConstraints);
|
||
150 | add(this.overallProgressBar);
|
||
151 | } |
||
152 | |||
153 | /**
|
||
154 | * Indicates wether the panel has been validated or not.
|
||
155 | *
|
||
156 | * @return The validation state.
|
||
157 | */
|
||
158 | public boolean isValidated() |
||
159 | { |
||
160 | return this.validated; |
||
161 | } |
||
162 | |||
163 | /** The unpacker starts. */
|
||
164 | public void startAction(String name, int noOfJobs) |
||
165 | { |
||
166 | parent.blockGUI(); |
||
167 | // figure out how many packs there are to install
|
||
168 | this.noOfPacks = noOfJobs;
|
||
169 | this.overallProgressBar.setMinimum(0); |
||
170 | this.overallProgressBar.setMaximum(this.noOfPacks); |
||
171 | this.overallProgressBar.setString(
|
||
172 | "0 / " + Integer.toString(this.noOfPacks)); |
||
173 | } |
||
174 | |||
175 | /**
|
||
176 | * An error was encountered.
|
||
177 | *
|
||
178 | * @param error The error text.
|
||
179 | */
|
||
180 | public void emitError(String title, String error) |
||
181 | { |
||
182 | this.packOpLabel.setText(error);
|
||
183 | idata.installSuccess = false;
|
||
184 | JOptionPane.showMessageDialog(
|
||
185 | this,
|
||
186 | error, |
||
187 | parent.langpack.getString("installer.error"),
|
||
188 | JOptionPane.ERROR_MESSAGE);
|
||
189 | } |
||
190 | |||
191 | /** The unpacker stops. */
|
||
192 | public void stopAction() |
||
193 | { |
||
194 | parent.releaseGUI(); |
||
195 | parent.lockPrevButton(); |
||
196 | this.overallProgressBar.setValue(this.overallProgressBar.getValue() + 1); |
||
197 | this.packProgressBar.setString(
|
||
198 | parent.langpack.getString("InstallPanel.finished"));
|
||
199 | this.packProgressBar.setEnabled(false); |
||
200 | String no_of_packs = Integer.toString(this.noOfPacks); |
||
201 | this.overallProgressBar.setString(no_of_packs + " / " + no_of_packs); |
||
202 | this.overallProgressBar.setEnabled(false); |
||
203 | this.packOpLabel.setText(" "); |
||
204 | this.packOpLabel.setEnabled(false); |
||
205 | idata.canClose = true;
|
||
206 | this.validated = true; |
||
207 | if (idata.panels.indexOf(this) != (idata.panels.size() - 1)) |
||
208 | parent.unlockNextButton(); |
||
209 | } |
||
210 | |||
211 | /**
|
||
212 | * Normal progress indicator.
|
||
213 | *
|
||
214 | * @param val The progression value.
|
||
215 | * @param msg The progression message.
|
||
216 | */
|
||
217 | public void progress(int val, String msg) |
||
218 | { |
||
219 | this.packProgressBar.setValue(val + 1); |
||
220 | packOpLabel.setText(msg); |
||
221 | } |
||
222 | |||
223 | /**
|
||
224 | * Pack changing.
|
||
225 | *
|
||
226 | * @param packName The pack name.
|
||
227 | * @param stepno The number of the pack.
|
||
228 | * @param max The new maximum progress.
|
||
229 | */
|
||
230 | public void nextStep(String packName, int stepno, int max) |
||
231 | { |
||
232 | this.packProgressBar.setValue(0); |
||
233 | this.packProgressBar.setMinimum(0); |
||
234 | this.packProgressBar.setMaximum(max);
|
||
235 | this.packProgressBar.setString(packName);
|
||
236 | this.overallProgressBar.setValue(stepno - 1); |
||
237 | this.overallProgressBar.setString(
|
||
238 | Integer.toString(stepno) + " / " + Integer.toString(this.noOfPacks)); |
||
239 | } |
||
240 | |||
241 | /** Called when the panel becomes active. */
|
||
242 | public void panelActivate() |
||
243 | { |
||
244 | // We clip the panel
|
||
245 | Dimension dim = parent.getPanelsContainerSize();
|
||
246 | dim.width = dim.width - (dim.width / 4);
|
||
247 | dim.height = 150;
|
||
248 | setMinimumSize(dim); |
||
249 | setMaximumSize(dim); |
||
250 | setPreferredSize(dim); |
||
251 | parent.lockNextButton(); |
||
252 | |||
253 | parent.install(this);
|
||
254 | } |
||
255 | |||
256 | } |