1 21 22 package com.izforge.izpack.panels; 23 24 import java.awt.BorderLayout ; 25 import java.awt.Dimension ; 26 import java.awt.Font ; 27 import java.io.IOException ; 28 29 import javax.swing.BoxLayout ; 30 import javax.swing.JLabel ; 31 import javax.swing.JPanel ; 32 import javax.swing.JProgressBar ; 33 import javax.swing.JScrollPane ; 34 import javax.swing.JTextArea ; 35 import javax.swing.SwingConstants ; 36 import javax.swing.SwingUtilities ; 37 38 import net.n3.nanoxml.XMLElement; 39 40 import com.izforge.izpack.installer.InstallData; 41 import com.izforge.izpack.installer.InstallerFrame; 42 import com.izforge.izpack.installer.IzPanel; 43 import com.izforge.izpack.installer.ProcessPanelWorker; 44 import com.izforge.izpack.util.AbstractUIProcessHandler; 45 46 56 public class ProcessPanel extends IzPanel implements AbstractUIProcessHandler 57 { 58 59 62 private static final long serialVersionUID = 3258417209583155251L; 63 64 65 protected JLabel processLabel; 66 67 68 protected JProgressBar overallProgressBar; 69 70 71 private boolean validated = false; 72 73 74 private ProcessPanelWorker worker; 75 76 77 private int noOfJobs; 78 79 private int currentJob; 80 81 82 private JTextArea outputPane; 83 84 90 public ProcessPanel(InstallerFrame parent, InstallData idata) throws IOException  91 { 92 super(parent, idata); 93 94 this.worker = new ProcessPanelWorker(idata, this); 95 96 JLabel heading = new JLabel (); 97 Font font = heading.getFont(); 98 font = font.deriveFont(Font.BOLD, font.getSize() * 2.0f); 99 heading.setFont(font); 100 heading.setHorizontalAlignment(SwingConstants.CENTER); 101 heading.setText(parent.langpack.getString("ProcessPanel.heading")); 102 heading.setVerticalAlignment(SwingConstants.TOP); 103 setLayout(new BorderLayout ()); 104 add(heading, BorderLayout.NORTH); 105 106 JPanel subpanel = new JPanel (); 109 110 subpanel.setAlignmentX(0.5f); 111 subpanel.setLayout(new BoxLayout (subpanel, BoxLayout.Y_AXIS)); 112 113 this.processLabel = new JLabel (); 114 this.processLabel.setAlignmentX(0.5f); 115 this.processLabel.setText(" "); 116 subpanel.add(this.processLabel); 117 118 this.overallProgressBar = new JProgressBar (); 119 this.overallProgressBar.setAlignmentX(0.5f); 120 this.overallProgressBar.setStringPainted(true); 121 subpanel.add(this.overallProgressBar); 122 123 this.outputPane = new JTextArea (); 124 this.outputPane.setEditable(false); 125 JScrollPane outputScrollPane = new JScrollPane (this.outputPane); 126 subpanel.add(outputScrollPane); 127 128 add(subpanel, BorderLayout.CENTER); 129 } 130 131 136 public boolean isValidated() 137 { 138 return validated; 139 } 140 141 142 public void startProcessing(int no_of_jobs) 143 { 144 this.noOfJobs = no_of_jobs; 145 overallProgressBar.setMaximum(noOfJobs); 146 parent.lockPrevButton(); 147 } 148 149 150 public void finishProcessing() 151 { 152 overallProgressBar.setValue(this.noOfJobs); 153 String no_of_jobs = Integer.toString(this.noOfJobs); 154 overallProgressBar.setString(no_of_jobs + " / " + no_of_jobs); 155 overallProgressBar.setEnabled(false); 156 157 processLabel.setText(" "); 158 processLabel.setEnabled(false); 159 160 validated = true; 161 idata.installSuccess = true; 162 if (idata.panels.indexOf(this) != (idata.panels.size() - 1)) parent.unlockNextButton(); 163 } 164 165 171 public void logOutput(String message, boolean stderr) 172 { 173 this.outputPane.append(message + '\n'); 175 176 SwingUtilities.invokeLater(new Runnable () { 177 178 public void run() 179 { 180 outputPane.setCaretPosition(outputPane.getText().length()); 181 } 182 }); 183 } 184 185 190 public void startProcess(String jobName) 191 { 192 processLabel.setText(jobName); 193 194 this.currentJob++; 195 overallProgressBar.setValue(this.currentJob); 196 overallProgressBar.setString(Integer.toString(this.currentJob) + " / " 197 + Integer.toString(this.noOfJobs)); 198 } 199 200 public void finishProcess() 201 { 202 } 203 204 205 public void panelActivate() 206 { 207 Dimension dim = parent.getPanelsContainerSize(); 209 dim.width -= (dim.width / 4); 210 dim.height = 150; 211 setMinimumSize(dim); 212 setMaximumSize(dim); 213 setPreferredSize(dim); 214 215 parent.lockNextButton(); 216 217 this.worker.startThread(); 218 } 219 220 221 public void makeXMLData(XMLElement panelRoot) 222 { 223 } 225 226 } 227
| Popular Tags
|