| 1 17 18 package org.apache.tools.ant.taskdefs.optional.ide; 19 20 21 import java.awt.BorderLayout ; 22 import java.awt.Button ; 23 import java.awt.Choice ; 24 import java.awt.Dialog ; 25 import java.awt.FileDialog ; 26 import java.awt.FlowLayout ; 27 import java.awt.Font ; 28 import java.awt.Frame ; 29 import java.awt.GridBagConstraints ; 30 import java.awt.GridBagLayout ; 31 import java.awt.Insets ; 32 import java.awt.Label ; 33 import java.awt.List ; 34 import java.awt.Menu ; 35 import java.awt.MenuBar ; 36 import java.awt.MenuItem ; 37 import java.awt.Panel ; 38 import java.awt.SystemColor ; 39 import java.awt.TextArea ; 40 import java.awt.TextField ; 41 import java.awt.Toolkit ; 42 import java.awt.event.ActionEvent ; 43 import java.awt.event.ActionListener ; 44 import java.awt.event.ItemEvent ; 45 import java.awt.event.ItemListener ; 46 import java.awt.event.TextEvent ; 47 import java.awt.event.TextListener ; 48 import java.awt.event.WindowEvent ; 49 import java.awt.event.WindowListener ; 50 import java.beans.PropertyChangeListener ; 51 import java.util.Vector ; 52 import org.apache.tools.ant.BuildEvent; 53 import org.apache.tools.ant.BuildException; 54 import org.apache.tools.ant.BuildListener; 55 import org.apache.tools.ant.Project; 56 import org.apache.tools.ant.util.DateUtils; 57 import org.apache.tools.ant.util.StringUtils; 58 59 73 public class VAJAntToolGUI extends Frame { 74 77 private VAJBuildLogger logger = new VAJBuildLogger(); 78 private static final String lineSeparator = "\r\n"; 79 private PrivateEventHandler iEventHandler = new PrivateEventHandler(); 80 81 84 private VAJBuildInfo iBuildInfo = null; 86 private MenuBar iAntMakeMenuBar = null; 88 private Menu iFileMenu = null; 89 private MenuItem iSaveMenuItem = null; 90 private MenuItem iMenuSeparator = null; 91 private MenuItem iShowLogMenuItem = null; 92 private Menu iHelpMenu = null; 93 private MenuItem iAboutMenuItem = null; 94 private Panel iContentsPane = null; 96 private Panel iOptionenPanel = null; 97 private Panel iCommandButtonPanel = null; 98 private Label iProjectLabel = null; 100 private Label iProjectText = null; 101 private Label iBuildFileLabel = null; 103 private TextField iBuildFileTextField = null; 104 private boolean iConnPtoP2Aligning = false; 105 private Button iBrowseButton = null; 106 private FileDialog iFileDialog = null; 107 private Choice iMessageOutputLevelChoice = null; 109 private Label iMessageOutputLevelLabel = null; 110 private Label iTargetLabel = null; 111 private List iTargetList = null; 112 private Button iBuildButton = null; 114 private Button iReloadButton = null; 115 private Button iCloseButton = null; 116 119 private Frame iMessageFrame = null; 121 private Panel iMessageCommandPanel = null; 122 private Panel iMessageContentPanel = null; 123 private TextArea iMessageTextArea = null; 125 private Button iMessageOkButton = null; 126 private Button iMessageClearLogButton = null; 127 130 private Dialog iAboutDialog = null; 132 private Panel iAboutDialogContentPanel = null; 133 private Panel iAboutInfoPanel = null; 134 private Panel iAboutCommandPanel = null; 135 private Label iAboutTitleLabel = null; 137 private Label iAboutDevLabel = null; 138 private Label iAboutContactLabel = null; 139 private Button iAboutOkButton = null; 141 142 146 private class VAJBuildLogger implements BuildListener { 147 private long startTime = System.currentTimeMillis(); 148 149 152 public VAJBuildLogger() { 153 super(); 154 } 155 156 162 public void buildFinished(BuildEvent event) { 163 getStopButton().setEnabled(false); 164 getBuildButton().setEnabled(true); 165 getBuildButton().requestFocus(); 166 167 Throwable error = event.getException(); 168 169 if (error == null) { 170 getMessageTextArea().append(lineSeparator + "BUILD SUCCESSFUL"); 171 } else { 172 logException(error); 173 } 174 175 getMessageTextArea().append(lineSeparator + "Total time: " 176 + DateUtils.formatElapsedTime(System.currentTimeMillis() - startTime)); 177 } 178 179 180 183 public void logException(Throwable error) { 184 getMessageTextArea().append(lineSeparator + "BUILD FAILED" + lineSeparator); 185 186 if (error instanceof BuildException) { 187 getMessageTextArea().append(error.toString()); 188 189 Throwable nested = ((BuildException) error).getException(); 190 if (nested != null) { 191 nested.printStackTrace(System.err); 192 } 193 } else { 194 error.printStackTrace(System.err); 195 } 196 } 197 198 201 public void buildStarted(BuildEvent event) { 202 getStopButton().setEnabled(true); 203 getBuildButton().setEnabled(false); 204 getStopButton().requestFocus(); 205 206 startTime = System.currentTimeMillis(); 207 getMessageTextArea().append(lineSeparator); 208 } 209 210 216 public void messageLogged(BuildEvent event) { 217 if (event.getPriority() <= getBuildInfo().getOutputMessageLevel()) { 218 String msg = ""; 219 if (event.getTask() != null) { 220 msg = "[" + event.getTask().getTaskName() + "] "; 221 } 222 getMessageTextArea().append(lineSeparator + msg + event.getMessage()); 223 } 224 } 225 226 232 public void targetFinished(BuildEvent event) { 233 } 234 235 240 public void targetStarted(BuildEvent event) { 241 if (getBuildInfo().getOutputMessageLevel() <= Project.MSG_INFO) { 242 getMessageTextArea().append(lineSeparator + event.getTarget().getName() + ":"); 243 } 244 } 245 246 252 public void taskFinished(BuildEvent event) { 253 } 254 255 260 public void taskStarted(BuildEvent event) { 261 } 262 } 263 264 267 private class PrivateEventHandler 268 implements ActionListener , ItemListener , TextListener , 269 WindowListener , PropertyChangeListener { 270 273 public void actionPerformed(ActionEvent e) { 274 try { 275 276 if (e.getSource() == VAJAntToolGUI.this.getBrowseButton()) { 278 getFileDialog().setDirectory(getBuildFileTextField().getText().substring(0, getBuildFileTextField().getText().lastIndexOf('\\') + 1)); 279 getFileDialog().setFile("*.xml"); 280 getFileDialog().show(); 281 if (!getFileDialog().getFile().equals("")) { 282 getBuildFileTextField().setText(getFileDialog().getDirectory() 283 + getFileDialog().getFile()); 284 } 285 } 286 if (e.getSource() == VAJAntToolGUI.this.getCloseButton()) { 288 dispose(); 289 System.exit(0); 290 } 291 if (e.getSource() == VAJAntToolGUI.this.getBuildButton()) { 293 executeTarget(); 294 } 295 if (e.getSource() == VAJAntToolGUI.this.getStopButton()) { 296 getBuildInfo().cancelBuild(); 297 } 298 if (e.getSource() == VAJAntToolGUI.this.getReloadButton()) { 299 try { 300 getBuildInfo().updateTargetList(); 301 fillList(); 302 } catch (Throwable fileNotFound) { 303 handleException(fileNotFound); 304 getTargetList().removeAll(); 305 getBuildButton().setEnabled(false); 306 } 307 } 308 if (e.getSource() == VAJAntToolGUI.this.getSaveMenuItem()) { 310 saveBuildInfo(); 311 } 312 if (e.getSource() == VAJAntToolGUI.this.getAboutMenuItem()) { 313 getAboutDialog().show(); 314 } 315 if (e.getSource() == VAJAntToolGUI.this.getShowLogMenuItem()) { 316 getMessageFrame().show(); 317 } 318 319 if (e.getSource() == VAJAntToolGUI.this.getAboutOkButton()) { 320 getAboutDialog().dispose(); 321 } 322 323 if (e.getSource() == VAJAntToolGUI.this.getMessageOkButton()) { 324 getMessageFrame().dispose(); 325 } 326 if (e.getSource() == VAJAntToolGUI.this.getMessageClearLogButton()) { 327 getMessageTextArea().setText(""); 328 } 329 if (e.getSource() == VAJAntToolGUI.this.getMessageOkButton()) { 330 getMessageFrame().dispose(); 331 } 332 } catch (Throwable exc) { 333 handleException(exc); 334 } 335 } 336 337 340 public void itemStateChanged(ItemEvent e) { 341 try { 342 if (e.getSource() == VAJAntToolGUI.this.getTargetList()) { 343 getBuildButton().setEnabled(true); 344 } 345 if (e.getSource() == VAJAntToolGUI.this.getMessageOutputLevelChoice()) { 346 getBuildInfo().setOutputMessageLevel(getMessageOutputLevelChoice().getSelectedIndex()); 347 } 348 if (e.getSource() == VAJAntToolGUI.this.getTargetList()) { 349 getBuildInfo().setTarget(getTargetList().getSelectedItem()); 350 } 351 } catch (Throwable exc) { 352 handleException(exc); 353 } 354 } 355 356 359 public void propertyChange(java.beans.PropertyChangeEvent evt) { 360 if (evt.getSource() == VAJAntToolGUI.this.getBuildInfo() 361 && (evt.getPropertyName().equals("projectName"))) { 362 connectProjectNameToLabel(); 363 } 364 if (evt.getSource() == VAJAntToolGUI.this.getBuildInfo() 365 && (evt.getPropertyName().equals("buildFileName"))) { 366 connectBuildFileNameToTextField(); 367 } 368 } 369 370 373 public void textValueChanged(TextEvent e) { 374 if (e.getSource() == VAJAntToolGUI.this.getBuildFileTextField()) { 375 connectTextFieldToBuildFileName(); 376 } 377 } 378 379 382 public void windowClosing(WindowEvent e) { 383 try { 384 if (e.getSource() == VAJAntToolGUI.this) { 385 dispose(); 386 System.exit(0); 387 } 388 if (e.getSource() == VAJAntToolGUI.this.getAboutDialog()) { 389 getAboutDialog().dispose(); 390 } 391 if (e.getSource() == VAJAntToolGUI.this.getMessageFrame()) { 392 getMessageFrame().dispose(); 393 } 394 } catch (Throwable exc) { 395 handleException(exc); 396 } 397 } 398 public void windowActivated(WindowEvent e) { 399 } 400 public void windowClosed(WindowEvent e) { 401 } 402 public void windowDeactivated(WindowEvent e) { 403 } 404 public void windowDeiconified(WindowEvent e) { 405 } 406 public void windowIconified(WindowEvent e) { 407 } 408 public void windowOpened(WindowEvent e) { 409 } 410 } 411 412 415 private VAJAntToolGUI() { 416 super(); 417 initialize(); 418 } 419 423 public VAJAntToolGUI(VAJBuildInfo newBuildInfo) { 424 super(); 425 setBuildInfo(newBuildInfo); 426 initialize(); 427 } 428 431 public static void centerDialog(Dialog dialog) { 432 dialog.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width / 2) - (dialog.getSize().width / 2), (java.awt.Toolkit.getDefaultToolkit().getScreenSize().height / 2) - (dialog.getSize().height / 2)); 433 } 434 437 private void connectBuildFileNameToTextField() { 438 439 try { 440 if (iConnPtoP2Aligning == false) { 441 iConnPtoP2Aligning = true; 442 if ((getBuildInfo() != null)) { 443 getBuildFileTextField().setText(getBuildInfo().getBuildFileName()); 444 } 445 iConnPtoP2Aligning = false; 446 } 447 } catch (Throwable iExc) { 448 iConnPtoP2Aligning = false; 449 handleException(iExc); 450 } 451 } 452 455 private void connectProjectNameToLabel() { 456 457 try { 458 if ((getBuildInfo() != null)) { 459 getProjectText().setText(getBuildInfo().getVAJProjectName()); 460 } 461 } catch (Throwable iExc) { 462 handleException(iExc); 463 } 464 } 465 468 private void connectTextFieldToBuildFileName() { 469 470 try { 471 if (iConnPtoP2Aligning == false) { 472 iConnPtoP2Aligning = true; 473 if ((getBuildInfo() != null)) { 474 getBuildInfo().setBuildFileName(getBuildFileTextField().getText()); 475 } 476 iConnPtoP2Aligning = false; 477 } 478 } catch (Throwable iExc) { 479 iConnPtoP2Aligning = false; 480 handleException(iExc); 481 } 482 } 483 486 private void executeTarget() { 487 try { 488 getMessageFrame().show(); 489 getBuildInfo().executeProject(logger); 490 } catch (Throwable exc) { 491 logger.logException(exc); 492 } 493 return; 494 } 495 498 private void fillList() { 499 getTargetList().removeAll(); 500 Vector targets = getBuildInfo().getProjectTargets(); 501 for (int i = 0; i < targets.size(); i++) { 502 getTargetList().add(targets.elementAt(i).toString()); 503 } 504 getTargetList().select(iBuildInfo.getProjectTargets().indexOf(iBuildInfo.getTarget())); 505 if (getTargetList().getSelectedIndex() >= 0) { 506 getBuildButton().setEnabled(true); 507 } 508 } 509 510 514 private Panel getAboutCommandPanel() { 515 if (iAboutCommandPanel == null) { 516 try { 517 iAboutCommandPanel = new Panel (); 518 iAboutCommandPanel.setName("AboutCommandPanel"); 519 iAboutCommandPanel.setLayout(new java.awt.FlowLayout ()); 520 getAboutCommandPanel().add(getAboutOkButton(), getAboutOkButton().getName()); 521 } catch (Throwable iExc) { 522 handleException(iExc); 523 } 524 } 525 return iAboutCommandPanel; 526 } 527 531 private Label getAboutContactLabel() { 532 if (iAboutContactLabel == null) { 533 try { 534 iAboutContactLabel = new Label (); 535 iAboutContactLabel.setName("AboutContactLabel"); 536 iAboutContactLabel.setAlignment(java.awt.Label.CENTER); 537 iAboutContactLabel.setText("contact: wolf.siberski@tui.de or " 538 + "christoph.wilhelms@tui.de"); 539 } catch (Throwable iExc) { 540 handleException(iExc); 541 } 542 } 543 return iAboutContactLabel; 544 } 545 549 private Label getAboutDevLabel() { 550 if (iAboutDevLabel == null) { 551 try { 552 iAboutDevLabel = new Label (); 553 iAboutDevLabel.setName("AboutDevLabel"); 554 iAboutDevLabel.setAlignment(java.awt.Label.CENTER); 555 iAboutDevLabel.setText("developed by Wolf Siberski & Christoph Wilhelms"); 556 } catch (Throwable iExc) { 557 handleException(iExc); 558 } 559 } 560 return iAboutDevLabel; 561 } 562 566 private Dialog getAboutDialog() { 567 if (iAboutDialog == null) { 568 try { 569 iAboutDialog = new Dialog (this); 570 iAboutDialog.setName("AboutDialog"); 571 iAboutDialog.setResizable(false); 572 iAboutDialog.setLayout(new java.awt.BorderLayout ()); 573 iAboutDialog.setBounds(550, 14, 383, 142); 574 iAboutDialog.setModal(true); 575 iAboutDialog.setTitle("About..."); 576 getAboutDialog().add(getAboutDialogContentPanel(), "Center"); 577 iAboutDialog.pack(); 578 centerDialog(iAboutDialog); 579 } catch (Throwable iExc) { 580 handleException(iExc); 581 } 582 } 583 return iAboutDialog; 584 } 585 589 private Panel getAboutDialogContentPanel() { 590 if (iAboutDialogContentPanel == null) { 591 try { 592 iAboutDialogContentPanel = new Panel (); 593 iAboutDialogContentPanel.setName("AboutDialogContentPanel"); 594 iAboutDialogContentPanel.setLayout(new java.awt.BorderLayout ()); 595 getAboutDialogContentPanel().add(getAboutCommandPanel(), "South"); 596 getAboutDialogContentPanel().add(getAboutInfoPanel(), "Center"); 597 } catch (Throwable iExc) { 598 handleException(iExc); 599 } 600 } 601 return iAboutDialogContentPanel; 602 } 603 607 private Panel getAboutInfoPanel() { 608 if (iAboutInfoPanel == null) { 609 try { 610 iAboutInfoPanel = new Panel (); 611 iAboutInfoPanel.setName("AboutInfoPanel"); 612 iAboutInfoPanel.setLayout(new GridBagLayout ()); 613 614 GridBagConstraints constraintsAboutTitleLabel = new GridBagConstraints (); 615 constraintsAboutTitleLabel.gridx = 0; constraintsAboutTitleLabel.gridy = 0; 616 constraintsAboutTitleLabel.fill = GridBagConstraints.HORIZONTAL; 617 constraintsAboutTitleLabel.weightx = 1.0; 618 constraintsAboutTitleLabel.weighty = 1.0; 619 constraintsAboutTitleLabel.insets = new Insets (4, 0, 4, 0); 620 getAboutInfoPanel().add(getAboutTitleLabel(), constraintsAboutTitleLabel); 621 622 GridBagConstraints constraintsAboutDevLabel = new GridBagConstraints (); 623 constraintsAboutDevLabel.gridx = 0; constraintsAboutDevLabel.gridy = 1; 624 constraintsAboutDevLabel.fill = GridBagConstraints.HORIZONTAL; 625 constraintsAboutDevLabel.weightx = 1.0; 626 constraintsAboutDevLabel.insets = new Insets (4, 0, 0, 0); 627 getAboutInfoPanel().add(getAboutDevLabel(), constraintsAboutDevLabel); 628 629 GridBagConstraints constraintsAboutContactLabel = new GridBagConstraints (); 630 constraintsAboutContactLabel.gridx = 0; constraintsAboutContactLabel.gridy = 2; 631 constraintsAboutContactLabel.fill = GridBagConstraints.HORIZONTAL; 632 constraintsAboutContactLabel.weightx = 1.0; 633 constraintsAboutContactLabel.insets = new Insets (2, 0, 4, 0); 634 getAboutInfoPanel().add(getAboutContactLabel(), constraintsAboutContactLabel); 635 } catch (Throwable iExc) { 636 handleException(iExc); 637 } 638 } 639 return iAboutInfoPanel; 640 } 641 645 private MenuItem getAboutMenuItem() { 646 if (iAboutMenuItem == null) { 647 try { 648 iAboutMenuItem = new MenuItem (); 649 iAboutMenuItem.setLabel("About..."); 650 } catch (Throwable iExc) { 651 handleException(iExc); 652 } 653 } 654 return iAboutMenuItem; 655 } 656 660 private Button getAboutOkButton() { 661 if (iAboutOkButton == null) { 662 try { 663 iAboutOkButton = new Button (); 664 iAboutOkButton.setName("AboutOkButton"); 665 iAboutOkButton.setLabel("OK"); 666 } catch (Throwable iExc) { 667 handleException(iExc); 668 } 669 } 670 return iAboutOkButton; 671 } 672 676 private Label getAboutTitleLabel() { 677 if (iAboutTitleLabel == null) { 678 try { 679 iAboutTitleLabel = new Label (); 680 iAboutTitleLabel.setName("AboutTitleLabel"); 681 iAboutTitleLabel.setFont(new Font ("Arial", 1, 12)); 682 iAboutTitleLabel.setAlignment(Label.CENTER); 683 iAboutTitleLabel.setText("Ant VisualAge for Java Tool-Integration"); 684 } catch (Throwable iExc) { 685 handleException(iExc); 686 } 687 } 688 return iAboutTitleLabel; 689 } 690 694 private MenuBar getAntMakeMenuBar() { 695 if (iAntMakeMenuBar == null) { 696 try { 697 iAntMakeMenuBar = new MenuBar (); 698 iAntMakeMenuBar.add(getFileMenu()); 699 iAntMakeMenuBar.add(getHelpMenu()); 700 &
|