root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / panels / ProcessPanel.java @ 15280
History | View | Annotate | Download (6.53 KB)
1 |
/*
|
---|---|
2 |
* $Id: ProcessPanel.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
3 |
* IzPack
|
4 |
* Copyright (C) 2001-2004 Julien Ponge, Tino Schwarze
|
5 |
*
|
6 |
* File : ProcessPanel.java
|
7 |
* Description : A panel to execute processes during 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.BorderLayout; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.Font; |
30 |
import java.io.IOException; |
31 |
|
32 |
import javax.swing.BoxLayout; |
33 |
import javax.swing.JLabel; |
34 |
import javax.swing.JPanel; |
35 |
import javax.swing.JProgressBar; |
36 |
import javax.swing.JScrollPane; |
37 |
import javax.swing.JTextArea; |
38 |
import javax.swing.SwingConstants; |
39 |
import javax.swing.SwingUtilities; |
40 |
|
41 |
import net.n3.nanoxml.XMLElement; |
42 |
|
43 |
import com.izforge.izpack.installer.InstallData; |
44 |
import com.izforge.izpack.installer.InstallerFrame; |
45 |
import com.izforge.izpack.installer.IzPanel; |
46 |
import com.izforge.izpack.installer.ProcessPanelWorker; |
47 |
import com.izforge.izpack.util.AbstractUIProcessHandler; |
48 |
|
49 |
/**
|
50 |
* The process panel class.
|
51 |
*
|
52 |
* This class allows external processes to be executed during installation.
|
53 |
*
|
54 |
* Parts of the code have been taken from CompilePanel.java and
|
55 |
* modified a lot.
|
56 |
*
|
57 |
* @author Tino Schwarze
|
58 |
* @author Julien Ponge
|
59 |
*/
|
60 |
public class ProcessPanel extends IzPanel implements AbstractUIProcessHandler |
61 |
{ |
62 |
/** The operation label . */
|
63 |
protected JLabel processLabel; |
64 |
|
65 |
/** The overall progress bar. */
|
66 |
protected JProgressBar overallProgressBar; |
67 |
|
68 |
/** True if the compilation has been done. */
|
69 |
private boolean validated = false; |
70 |
|
71 |
/** The processing worker. Does all the work. */
|
72 |
private ProcessPanelWorker worker;
|
73 |
|
74 |
/** Number of jobs to process. Used for progress indication. */
|
75 |
private int noOfJobs; |
76 |
|
77 |
private int currentJob; |
78 |
|
79 |
/** Where the output is displayed */
|
80 |
private JTextArea outputPane; |
81 |
|
82 |
private JScrollPane outputScrollPane; |
83 |
|
84 |
/**
|
85 |
* The constructor.
|
86 |
*
|
87 |
* @param parent The parent window.
|
88 |
* @param idata The installation data.
|
89 |
*/
|
90 |
public ProcessPanel(InstallerFrame parent, InstallData idata)
|
91 |
throws IOException |
92 |
{ |
93 |
super(parent, idata);
|
94 |
|
95 |
this.worker = new ProcessPanelWorker(idata, this); |
96 |
|
97 |
JLabel heading = new JLabel(); |
98 |
Font font = heading.getFont();
|
99 |
font = font.deriveFont(Font.BOLD, font.getSize() * 2.0f); |
100 |
heading.setFont(font); |
101 |
heading.setHorizontalAlignment(SwingConstants.CENTER);
|
102 |
heading.setText(parent.langpack.getString("ProcessPanel.heading"));
|
103 |
heading.setVerticalAlignment(SwingConstants.TOP);
|
104 |
setLayout(new BorderLayout()); |
105 |
add(heading, BorderLayout.NORTH);
|
106 |
|
107 |
// put everything but the heading into it's own panel
|
108 |
// (to center it vertically)
|
109 |
JPanel subpanel = new JPanel(); |
110 |
|
111 |
subpanel.setAlignmentX(0.5f);
|
112 |
subpanel.setLayout(new BoxLayout(subpanel, BoxLayout.Y_AXIS)); |
113 |
|
114 |
this.processLabel = new JLabel(); |
115 |
this.processLabel.setAlignmentX(0.5f); |
116 |
this.processLabel.setText(" "); |
117 |
subpanel.add(this.processLabel);
|
118 |
|
119 |
this.overallProgressBar = new JProgressBar(); |
120 |
this.overallProgressBar.setAlignmentX(0.5f); |
121 |
this.overallProgressBar.setStringPainted(true); |
122 |
subpanel.add(this.overallProgressBar);
|
123 |
|
124 |
this.outputPane = new JTextArea(); |
125 |
this.outputPane.setEditable(false); |
126 |
this.outputScrollPane = new JScrollPane(this.outputPane); |
127 |
subpanel.add(this.outputScrollPane);
|
128 |
|
129 |
add(subpanel, BorderLayout.CENTER);
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* Indicates wether the panel has been validated or not.
|
134 |
*
|
135 |
* @return The validation state.
|
136 |
*/
|
137 |
public boolean isValidated() |
138 |
{ |
139 |
return validated;
|
140 |
} |
141 |
|
142 |
/** The compiler starts. */
|
143 |
public void startProcessing(int no_of_jobs) |
144 |
{ |
145 |
this.noOfJobs = no_of_jobs;
|
146 |
overallProgressBar.setMaximum(noOfJobs); |
147 |
parent.lockPrevButton(); |
148 |
} |
149 |
|
150 |
/** The compiler stops. */
|
151 |
public void finishProcessing() |
152 |
{ |
153 |
overallProgressBar.setValue(this.noOfJobs);
|
154 |
String no_of_jobs = Integer.toString(this.noOfJobs); |
155 |
overallProgressBar.setString(no_of_jobs + " / " + no_of_jobs);
|
156 |
overallProgressBar.setEnabled(false);
|
157 |
|
158 |
processLabel.setText(" ");
|
159 |
processLabel.setEnabled(false);
|
160 |
|
161 |
validated = true;
|
162 |
idata.installSuccess = true;
|
163 |
if (idata.panels.indexOf(this) != (idata.panels.size() - 1)) |
164 |
parent.unlockNextButton(); |
165 |
} |
166 |
|
167 |
/**
|
168 |
* Log a message.
|
169 |
*
|
170 |
* @param message The message.
|
171 |
* @param stderr Whether the message came from stderr or stdout.
|
172 |
*/
|
173 |
public void logOutput(String message, boolean stderr) |
174 |
{ |
175 |
// TODO: make it colored
|
176 |
this.outputPane.append(message + '\n'); |
177 |
|
178 |
SwingUtilities.invokeLater(new Runnable() |
179 |
{ |
180 |
public void run() |
181 |
{ |
182 |
outputPane.setCaretPosition(outputPane.getText().length()); |
183 |
} |
184 |
} |
185 |
); |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Next job starts.
|
190 |
*
|
191 |
* @param jobName The job name.
|
192 |
*/
|
193 |
public void startProcess(String jobName) |
194 |
{ |
195 |
processLabel.setText(jobName); |
196 |
|
197 |
this.currentJob++;
|
198 |
overallProgressBar.setValue(this.currentJob);
|
199 |
overallProgressBar.setString( |
200 |
Integer.toString(this.currentJob) |
201 |
+ " / "
|
202 |
+ Integer.toString(this.noOfJobs)); |
203 |
} |
204 |
|
205 |
public void finishProcess() |
206 |
{ |
207 |
} |
208 |
|
209 |
/** Called when the panel becomes active. */
|
210 |
public void panelActivate() |
211 |
{ |
212 |
// We clip the panel
|
213 |
Dimension dim = parent.getPanelsContainerSize();
|
214 |
dim.width = dim.width - (dim.width / 4);
|
215 |
dim.height = 150;
|
216 |
setMinimumSize(dim); |
217 |
setMaximumSize(dim); |
218 |
setPreferredSize(dim); |
219 |
|
220 |
parent.lockNextButton(); |
221 |
|
222 |
this.worker.startThread();
|
223 |
} |
224 |
|
225 |
/** Create XML data for automated installation. */
|
226 |
public void makeXMLData(XMLElement panelRoot) |
227 |
{ |
228 |
// does nothing (no state to save)
|
229 |
} |
230 |
|
231 |
} |