1 21 package com.izforge.izpack.panels; 22 23 import java.awt.Dimension ; 24 import java.awt.Font ; 25 import java.awt.GridBagConstraints ; 26 import java.awt.GridBagLayout ; 27 import java.awt.Insets ; 28 import java.awt.event.ActionEvent ; 29 import java.awt.event.ActionListener ; 30 import java.io.File ; 31 import java.io.IOException ; 32 import java.util.Iterator ; 33 34 import javax.swing.BoxLayout ; 35 import javax.swing.JButton ; 36 import javax.swing.JComboBox ; 37 import javax.swing.JDialog ; 38 import javax.swing.JFileChooser ; 39 import javax.swing.JLabel ; 40 import javax.swing.JPanel ; 41 import javax.swing.JProgressBar ; 42 import javax.swing.JScrollPane ; 43 import javax.swing.JTabbedPane ; 44 import javax.swing.JTextArea ; 45 import javax.swing.SwingConstants ; 46 47 import net.n3.nanoxml.XMLElement; 48 49 import com.izforge.izpack.gui.ButtonFactory; 50 import com.izforge.izpack.gui.LabelFactory; 51 import com.izforge.izpack.installer.CompileHandler; 52 import com.izforge.izpack.installer.CompileResult; 53 import com.izforge.izpack.installer.CompileWorker; 54 import com.izforge.izpack.installer.InstallData; 55 import com.izforge.izpack.installer.InstallerFrame; 56 import com.izforge.izpack.installer.IzPanel; 57 58 68 public class CompilePanel extends IzPanel implements ActionListener , CompileHandler 69 { 70 71 74 private static final long serialVersionUID = 3258408430669674552L; 75 76 77 protected JComboBox compilerComboBox; 78 79 80 protected JComboBox argumentsComboBox; 81 82 83 protected JButton startButton; 84 85 86 protected JButton browseButton; 87 88 89 protected JLabel tipLabel; 90 91 92 protected JLabel opLabel; 93 94 95 protected JProgressBar packProgressBar; 96 97 98 protected JLabel overallLabel; 99 100 101 protected JProgressBar overallProgressBar; 102 103 104 private boolean validated = false; 105 106 107 private CompileWorker worker; 108 109 110 private int noOfJobs; 111 112 119 public CompilePanel(InstallerFrame parent, InstallData idata) throws IOException 120 { 121 super(parent, idata); 122 123 this.worker = new CompileWorker(idata, this); 124 125 GridBagConstraints gridBagConstraints; 126 127 JLabel heading = new JLabel (); 128 JPanel subpanel = new JPanel (); 131 JLabel compilerLabel = new JLabel (); 132 compilerComboBox = new JComboBox (); 133 this.browseButton = ButtonFactory.createButton(parent.langpack 134 .getString("CompilePanel.browse"), idata.buttonsHColor); 135 JLabel argumentsLabel = new JLabel (); 136 this.argumentsComboBox = new JComboBox (); 137 this.startButton = ButtonFactory.createButton(parent.langpack 138 .getString("CompilePanel.start"), idata.buttonsHColor); 139 this.tipLabel = LabelFactory.create(parent.langpack.getString("CompilePanel.tip"), 140 parent.icons.getImageIcon("tip"), SwingConstants.TRAILING); 141 this.opLabel = new JLabel (); 142 packProgressBar = new JProgressBar (); 143 this.overallLabel = new JLabel (); 144 this.overallProgressBar = new JProgressBar (); 145 146 setLayout(new GridBagLayout ()); 147 148 Font font = heading.getFont(); 149 font = font.deriveFont(Font.BOLD, font.getSize() * 2.0f); 150 heading.setFont(font); 151 heading.setHorizontalAlignment(SwingConstants.CENTER); 152 heading.setText(parent.langpack.getString("CompilePanel.heading")); 153 heading.setVerticalAlignment(SwingConstants.TOP); 154 gridBagConstraints = new GridBagConstraints (); 155 gridBagConstraints.gridy = 0; 156 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 157 gridBagConstraints.anchor = GridBagConstraints.NORTH; 158 gridBagConstraints.weightx = 1.0; 159 gridBagConstraints.weighty = 0.1; 160 add(heading, gridBagConstraints); 161 162 gridBagConstraints = new GridBagConstraints (); 163 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 164 gridBagConstraints.anchor = GridBagConstraints.CENTER; 165 gridBagConstraints.gridy = 1; 166 gridBagConstraints.weightx = 1.0; 167 gridBagConstraints.weighty = 0.9; 168 add(subpanel, gridBagConstraints); 169 170 subpanel.setLayout(new GridBagLayout ()); 171 172 int row = 0; 173 174 compilerLabel.setHorizontalAlignment(SwingConstants.LEFT); 175 compilerLabel.setLabelFor(compilerComboBox); 176 compilerLabel.setText(parent.langpack.getString("CompilePanel.choose_compiler")); 177 gridBagConstraints = new GridBagConstraints (); 178 gridBagConstraints.gridy = row; 179 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 180 subpanel.add(compilerLabel, gridBagConstraints); 182 183 compilerComboBox.setEditable(true); 184 gridBagConstraints = new GridBagConstraints (); 185 gridBagConstraints.gridy = row++; 186 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 187 189 Iterator it = this.worker.getAvailableCompilers().iterator(); 190 191 while (it.hasNext()) 192 compilerComboBox.addItem(it.next()); 193 194 subpanel.add(compilerComboBox, gridBagConstraints); 195 196 gridBagConstraints = new GridBagConstraints (); 197 gridBagConstraints.gridy = row++; 198 gridBagConstraints.gridx = 1; 199 gridBagConstraints.anchor = GridBagConstraints.EAST; 200 browseButton.addActionListener(this); 201 subpanel.add(browseButton, gridBagConstraints); 202 203 argumentsLabel.setHorizontalAlignment(SwingConstants.LEFT); 204 argumentsLabel.setLabelFor(argumentsComboBox); 205 argumentsLabel.setText(parent.langpack.getString("CompilePanel.additional_arguments")); 206 gridBagConstraints = new GridBagConstraints (); 208 gridBagConstraints.gridy = row; 209 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 210 gridBagConstraints.weightx = 0.5; 211 subpanel.add(argumentsLabel, gridBagConstraints); 213 214 argumentsComboBox.setEditable(true); 215 gridBagConstraints = new GridBagConstraints (); 216 gridBagConstraints.gridy = row++; 217 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 218 gridBagConstraints.weightx = 0.5; 219 221 it = this.worker.getAvailableArguments().iterator(); 222 223 while (it.hasNext()) 224 argumentsComboBox.addItem(it.next()); 225 226 subpanel.add(argumentsComboBox, gridBagConstraints); 227 228 gridBagConstraints.insets = new Insets (10, 0, 0, 0); 230 gridBagConstraints = new GridBagConstraints (); 231 gridBagConstraints.gridy = row++; 232 gridBagConstraints.gridwidth = 2; 233 gridBagConstraints.fill = GridBagConstraints.NONE; 234 gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; 235 subpanel.add(tipLabel, gridBagConstraints); 236 237 opLabel.setText(" "); 238 gridBagConstraints = new GridBagConstraints (); 239 gridBagConstraints.gridy = row++; 240 gridBagConstraints.gridwidth = 2; 241 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 242 subpanel.add(opLabel, gridBagConstraints); 243 244 packProgressBar.setValue(0); 245 packProgressBar.setString(parent.langpack.getString("CompilePanel.progress.initial")); 246 packProgressBar.setStringPainted(true); 247 gridBagConstraints = new GridBagConstraints (); 248 gridBagConstraints.gridy = row++; 249 gridBagConstraints.gridwidth = 2; 250 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 251 gridBagConstraints.anchor = GridBagConstraints.SOUTH; 252 subpanel.add(packProgressBar, gridBagConstraints); 253 254 overallLabel.setText(parent.langpack.getString("CompilePanel.progress.overall")); 255 gridBagConstraints = new GridBagConstraints (); 256 gridBagConstraints.gridy = row++; 257 gridBagConstraints.gridwidth = 2; 258 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 259 subpanel.add(overallLabel, gridBagConstraints); 260 261 overallProgressBar.setValue(0); 262 overallProgressBar.setString(""); 263 overallProgressBar.setStringPainted(true); 264 gridBagConstraints = new GridBagConstraints (); 265 gridBagConstraints.gridy = row++; 266 gridBagConstraints.gridwidth = 2; 267 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 268 gridBagConstraints.anchor = GridBagConstraints.SOUTH; 269 subpanel.add(overallProgressBar, gridBagConstraints); 270 271 startButton.setText(parent.langpack.getString("CompilePanel.start")); 272 startButton.addActionListener(this); 273 gridBagConstraints = new GridBagConstraints (); 274 gridBagConstraints.gridx = 0; 275 gridBagConstraints.gridwidth = 2; 276 gridBagConstraints.gridy = row++; 277 gridBagConstraints.fill = GridBagConstraints.NONE; 278 gridBagConstraints.insets = new Insets (5, 0, 0, 0); 280 subpanel.add(startButton, gridBagConstraints); 281 } 282 283 288 public boolean isValidated() 289 { 290 return validated; 291 } 292 293 296 public void actionPerformed(ActionEvent e) 297 { 298 if (e.getSource() == this.startButton) 299 { 300 this.worker.setCompiler((String ) this.compilerComboBox.getSelectedItem()); 301 302 this.worker.setCompilerArguments((String ) this.argumentsComboBox.getSelectedItem()); 303 304 this.blockGUI(); 305 this.worker.startThread(); 306 } 307 else if (e.getSource() == this.browseButton) 308 { 309 this.parent.blockGUI(); 310 JFileChooser chooser = new JFileChooser (); 311 chooser.setCurrentDirectory(new File ((String ) this.compilerComboBox.getSelectedItem()) 312 .getParentFile()); 313 int result = chooser.showDialog(this.parent, this.parent.langpack 314 .getString("CompilePanel.browse.approve")); 315 if (result == JFileChooser.APPROVE_OPTION) 316 { 317 File file_chosen = chooser.getSelectedFile(); 318 319 if (file_chosen.isFile()) 320 { 321 this.compilerComboBox.setSelectedItem(file_chosen.getAbsolutePath()); 322 } 323 324 } 325 326 this.parent.releaseGUI(); 327 } 328 329 } 330 331 334 protected void blockGUI() 335 { 336 this.startButton.setEnabled(false); 338 this.browseButton.setEnabled(false); 339 this.compilerComboBox.setEnabled(false); 340 this.argumentsComboBox.setEnabled(false); 341 342 this.parent.blockGUI(); 343 } 344 345 350 protected void releaseGUI(boolean allowconfig) 351 { 352 if (allowconfig) 354 { 355 this.startButton.setEnabled(true); 356 this.browseButton.setEnabled(true); 357 this.compilerComboBox.setEnabled(true); 358 this.argumentsComboBox.setEnabled(true); 359 } 360 361 this.parent.releaseGUI(); 362 } 363 364 370 public void handleCompileError(CompileResult error) 371 { 372 String message = error.getMessage(); 373 opLabel.setText(message); 374 CompilerErrorDialog dialog = new CompilerErrorDialog(parent, message, idata.buttonsHColor); 375 dialog.show(error); 376 377 if (dialog.getResult() == CompilerErrorDialog.RESULT_IGNORE) 378 { 379 error.setAction(CompileResult.ACTION_CONTINUE); 380 } 381 else if (dialog.getResult() == CompilerErrorDialog.RESULT_RECONFIGURE) 382 { 383 error.setAction(CompileResult.ACTION_RECONFIGURE); 384 } 385 else 386 { 388 error.setAction(CompileResult.ACTION_ABORT); 389 } 390 391 } 392 393 396 public void startAction(String name, int noOfJobs1) 397 { 398 this.noOfJobs = noOfJobs1; 399 overallProgressBar.setMaximum(noOfJobs1); 400 parent.lockPrevButton(); 401 } 402 403 404 public void stopAction() 405 { 406 CompileResult result = this.worker.getResult(); 407 408 this.releaseGUI(result.isReconfigure()); 409 410 if (result.isContinue()) 411 { 412 parent.lockPrevButton(); 413 414 packProgressBar.setString(parent.langpack.getString("CompilePanel.progress.finished")); 415 packProgressBar.setEnabled(false); 416 packProgressBar.setValue(packProgressBar.getMaximum()); 417 418 overallProgressBar.setValue(this.noOfJobs); 419 String no_of_jobs = Integer.toString(this.noOfJobs); 420 overallProgressBar.setString(no_of_jobs + " / " + no_of_jobs); 421 overallProgressBar.setEnabled(false); 422 423 opLabel.setText(" "); 424 opLabel.setEnabled(false); 425 426 validated = true; 427 idata.installSuccess = true; 428 if (idata.panels.indexOf(this) != (idata.panels.size() - 1)) parent.unlockNextButton(); 429 } 430 else 431 { 432 idata.installSuccess = false; 433 } 434 435 } 436 437 443 public void progress(int val, String msg) 444 { 445 packProgressBar.setValue(val + 1); 447 opLabel.setText(msg); 448 } 449 450 457 public void nextStep(String jobName, int max, int jobNo) 458 { 459 packProgressBar.setValue(0); 460 packProgressBar.setMaximum(max); 461 packProgressBar.setString(jobName); 462 463 opLabel.setText(""); 464 465 overallProgressBar.setValue(jobNo); 466 overallProgressBar.setString(Integer.toString(jobNo) + " / " 467 + Integer.toString(this.noOfJobs)); 468 } 469 470 471 public void panelActivate() 472 { 473 Iterator it = this.worker.getAvailableCompilers().iterator(); 476 477 compilerComboBox.removeAllItems(); 478 479 while (it.hasNext()) 480 compilerComboBox.addItem(it.next()); 481 482 Dimension dim = parent.getPanelsContainerSize(); 484 dim.width -= (dim.width / 4); 485 dim.height = 150; 486 setMinimumSize(dim); 487 setMaximumSize(dim); 488 setPreferredSize(dim); 489 490 parent.lockNextButton(); 491 } 492 493 494 public void makeXMLData(XMLElement panelRoot) 495 { 496 XMLElement compiler = new XMLElement("compiler"); 498 compiler.setContent(this.worker.getCompiler()); 499 panelRoot.addChild(compiler); 500 501 XMLElement args = new XMLElement("arguments"); 502 args.setContent(this.worker.getCompilerArguments()); 503 panelRoot.addChild(args); 504 } 505 506 512 protected class CompilerErrorDialog extends JDialog implements ActionListener 513 { 514 515 private static final long serialVersionUID = 3762537797721995317L; 516 517 518 public static final int RESULT_NONE = 0; 519 520 521 public static final int RESULT_IGNORE = 23; 522 523 524 public static final int RESULT_ABORT = 42; 525 526 527 public static final int RESULT_RECONFIGURE = 47; 528 529 530 private java.awt.Color buttonHColor = null; 531 532 536 public CompilerErrorDialog(java.awt.Frame parent, String title, java.awt.Color buttonHColor) 537 { 538 super(parent, title, true); 539 this.buttonHColor = buttonHColor; 540 initComponents(); 541 } 542 543 548 private void initComponents() 549 { 550 JPanel errorMessagePane = new JPanel (); 551 errorMessageText = new JTextArea (); 552 JTextArea seeBelowText = new JTextArea (); 553 JTabbedPane errorDisplayPane = new JTabbedPane (); 554 JScrollPane commandScrollPane = new JScrollPane (); 555 commandText = new JTextArea (); 556 JScrollPane stdOutScrollPane = new JScrollPane (); 557 stdOutText = new JTextArea (); 558 JScrollPane stdErrScrollPane = new JScrollPane (); 559 stdErrText = new JTextArea (); 560 JPanel buttonsPanel = new JPanel (); 561 reconfigButton = ButtonFactory.createButton(parent.langpack 562 .getString("CompilePanel.error.reconfigure"), this.buttonHColor); 563 ignoreButton = ButtonFactory.createButton(parent.langpack 564 .getString("CompilePanel.error.ignore"), this.buttonHColor); 565 abortButton = ButtonFactory.createButton(parent.langpack 566 .getString("CompilePanel.error.abort"), this.buttonHColor); 567 568 addWindowListener(new java.awt.event.WindowAdapter () { 569 570 public void windowClosing(java.awt.event.WindowEvent evt) 571 { 572 closeDialog(); 573 } 574 }); 575 576 errorMessagePane.setLayout(new BoxLayout (errorMessagePane, BoxLayout.Y_AXIS)); 577 errorMessageText.setBackground(super.getBackground()); 578 errorMessageText.setEditable(false); 579 errorMessageText.setLineWrap(true); 580 errorMessageText.setWrapStyleWord(true); 584 errorMessagePane.add(errorMessageText); 585 586 seeBelowText.setBackground(super.getBackground()); 587 seeBelowText.setEditable(false); 588 seeBelowText.setLineWrap(true); 589 seeBelowText.setWrapStyleWord(true); 590 seeBelowText.setText(parent.langpack.getString("CompilePanel.error.seebelow")); 591 errorMessagePane.add(seeBelowText); 592 593 getContentPane().add(errorMessagePane, java.awt.BorderLayout.NORTH); 594 595 Font output_font = new Font ("Monospaced", Font.PLAIN, 12); 597 598 commandText.setFont(output_font); 601 commandText.setEditable(false); 602 commandText.setRows(10); 603 commandText.setColumns(82); 604 commandText.setWrapStyleWord(true); 605 commandText.setLineWrap(true); 606 commandScrollPane.setViewportView(commandText); 608 609 errorDisplayPane.addTab("Command", commandScrollPane); 610 611 stdOutText.setFont(output_font); 612 stdOutText.setEditable(false); 613 stdOutText.setWrapStyleWord(true); 614 stdOutText.setLineWrap(true); 615 stdOutScrollPane.setViewportView(stdOutText); 616 617 errorDisplayPane.addTab("Standard Output", null, stdOutScrollPane); 618 619 stdErrText.setFont(output_font); 620 stdErrText.setEditable(false); 621 stdErrText.setWrapStyleWord(true); 622 stdErrText.setLineWrap(true); 623 stdErrScrollPane.setViewportView(stdErrText); 624 625 errorDisplayPane.addTab("Standard Error", null, stdErrScrollPane); 626 627 getContentPane().add(errorDisplayPane, java.awt.BorderLayout.CENTER); 628 629 buttonsPanel.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.RIGHT)); 630 631 reconfigButton.addActionListener(this); 632 buttonsPanel.add(reconfigButton); 633 634 ignoreButton.addActionListener(this); 635 buttonsPanel.add(ignoreButton); 636 637 abortButton.addActionListener(this); 638 buttonsPanel.add(abortButton); 639 640 getContentPane().add(buttonsPanel, java.awt.BorderLayout.SOUTH); 641 642 pack(); 643 } 644 645 648 protected void closeDialog() 649 { 650 setVisible(false); 651 dispose(); 652 } 653 654 658 public void show(CompileResult error) 659 { 660 this.errorMessageText.setText(error.getMessage()); 661 this.commandText.setText(error.getCmdline()); 662 this.stdOutText.setText(error.getStdout()); 663 this.stdErrText.setText(error.getStderr()); 664 super.setVisible(true); 665 } 666 667 671 public int getResult() 672 { 673 return this.result; 674 } 675 676 public void actionPerformed(ActionEvent e) 677 { 678 boolean closenow = false; 679 680 if (e.getSource() == this.ignoreButton) 681 { 682 this.result = RESULT_IGNORE; 683 closenow = true; 684 } 685 else if (e.getSource() == this.abortButton) 686 { 687 this.result = RESULT_ABORT; 688 closenow = true; 689 } 690 else if (e.getSource() == this.reconfigButton) 691 { 692 this.result = RESULT_RECONFIGURE; 693 closenow = true; 694 } 695 696 if (closenow) 697 { 698 this.setVisible(false); 699 this.dispose(); 700 } 701 702 } 703 704 private JTextArea commandText; 706 707 private JTextArea stdErrText; 709 710 private JTextArea errorMessageText; 713 714 private JButton ignoreButton; 716 717 private JTextArea stdOutText; 718 719 private JButton abortButton; 720 721 private JButton reconfigButton; 722 723 726 private int result = RESULT_NONE; 727 } 728 } 729 | Popular Tags |