1 30 31 package com.genimen.djeneric.tools.generator; 32 33 import java.awt.AWTEvent ; 34 import java.awt.BorderLayout ; 35 import java.awt.Color ; 36 import java.awt.Component ; 37 import java.awt.Dimension ; 38 import java.awt.Image ; 39 import java.awt.SystemColor ; 40 import java.awt.Toolkit ; 41 import java.awt.event.ActionEvent ; 42 import java.awt.event.InputEvent ; 43 import java.awt.event.KeyEvent ; 44 import java.awt.event.KeyListener ; 45 import java.awt.event.WindowEvent ; 46 import java.io.File ; 47 import java.io.FileNotFoundException ; 48 import java.net.URL ; 49 50 import javax.swing.ImageIcon ; 51 import javax.swing.JFileChooser ; 52 import javax.swing.JLabel ; 53 import javax.swing.JMenu ; 54 import javax.swing.JMenuBar ; 55 import javax.swing.JMenuItem ; 56 import javax.swing.JOptionPane ; 57 import javax.swing.JPanel ; 58 import javax.swing.JScrollPane ; 59 import javax.swing.JSplitPane ; 60 import javax.swing.JTextArea ; 61 62 import com.genimen.djeneric.repository.DjPersistenceManager; 63 import com.genimen.djeneric.repository.DjPersistenceManagerFactory; 64 import com.genimen.djeneric.repository.DjSession; 65 import com.genimen.djeneric.repository.DjUserContextAssociation; 66 import com.genimen.djeneric.repository.exceptions.DjenericException; 67 import com.genimen.djeneric.tools.common.AboutDialog; 68 import com.genimen.djeneric.tools.common.DjenericTool; 69 import com.genimen.djeneric.tools.generator.dialogs.OptionsDialog; 70 import com.genimen.djeneric.tools.generator.dialogs.ProjectPropertiesDialog; 71 import com.genimen.djeneric.tools.generator.ui.CloseableScrollpane; 72 import com.genimen.djeneric.tools.generator.ui.ProjectPanel; 73 import com.genimen.djeneric.tools.generator.util.ProjectProperties; 74 import com.genimen.djeneric.tools.generator.util.TemplateSetManager; 75 import com.genimen.djeneric.tools.specifier.tree.DjenericFolder; 76 import com.genimen.djeneric.ui.DjTabbedPane; 77 import com.genimen.djeneric.util.DjEnvironment; 78 import com.genimen.djeneric.util.DjFileFilter; 79 import com.genimen.djeneric.util.DjLogPrintStream; 80 import com.genimen.djeneric.util.DjLogger; 81 import com.genimen.djeneric.util.DjStatusDisplayer; 82 import com.genimen.djeneric.util.DjVersion; 83 84 public class Generator extends DjenericTool implements KeyListener , DjStatusDisplayer 85 { 86 private static final long serialVersionUID = 1L; 87 protected final String PROPERTIES_FILE_NAME = DjEnvironment.getAbsoluteFileName("generator.properties"); 88 protected final static String LOG_FILE_NAME = DjEnvironment.getAbsoluteFileName("generator.log"); 89 90 public final static String GENERATOR_CONSOLE_TITLE = "Generator log"; 91 92 public final static String OK_MSG = "Ok"; 93 public final static String KEY_TEMPLATEPATH = "path.template"; 94 public final static String KEY_INCLUDEPATH = "path.include"; 95 96 public final static String PROJECT_EXTENSION = "dgp"; 97 98 JSplitPane _splitpane = new JSplitPane (); 99 JMenuBar _menu = new JMenuBar (); 100 JMenu mnuFile = new JMenu (); 101 JMenuItem mnuExit = new JMenuItem (); 102 JMenu mnuHelp = new JMenu (); 103 JMenuItem mnuAbout = new JMenuItem (); 104 DjPersistenceManager _mgr; 105 DjSession _session; 106 DjenericFolder _root = new DjenericFolder(); 107 108 JLabel _lblStatus = new JLabel (); 109 Color _normalColor = new Color (102, 102, 153); 110 111 JPanel _desktopPanel = new JPanel (); 112 BorderLayout borderLayout2 = new BorderLayout (); 113 DjTabbedPane _tabs = new DjTabbedPane(); 114 JMenuItem mnuNewProject = new JMenuItem (); 115 JMenuItem mnuOpenProject = new JMenuItem (); 116 JMenuItem mnuProjectProperties = new JMenuItem (); 117 JMenuItem mnuOptions = new JMenuItem (); 118 JMenu mnuTools = new JMenu (); 119 TemplateSetManager _templateSetManager = new TemplateSetManager(); 120 JMenuItem mnuSaveProject = new JMenuItem (); 121 JMenuItem mnuSaveAs = new JMenuItem (); 122 ProjectProperties _projectProperties = new ProjectProperties(); 123 String _projectFileName = null; 124 ProjectPanel _pnlProject; 125 JMenu mnuTabs = new JMenu (); 126 JMenuItem mnuNextTab = new JMenuItem (); 127 JMenuItem mnuPrevTab = new JMenuItem (); 128 JMenuItem mnuCloseTab = new JMenuItem (); 129 JMenuItem mnuCloseAll = new JMenuItem (); 130 131 137 public Generator(String repositories) 138 { 139 enableEvents(AWTEvent.WINDOW_EVENT_MASK); 140 setIconImage(getImage("generator.gif")); 141 142 try 143 { 144 setStatusLabel(_lblStatus); 145 _splitpane.setVisible(false); 146 getContentPane().setBackground(SystemColor.desktop); 147 invalidate(); 148 loadProps(PROPERTIES_FILE_NAME); 149 setupWindow(); 150 151 setupPersistenceManager(repositories); 152 setupSession(); 153 setupContext(); 154 setupProjectPane(); 155 156 jbInit(); 157 158 updateTitle(); 159 setupTemplateSetManager(); 160 validate(); 161 } 162 catch (Exception e) 163 { 164 handleException(e); 165 System.exit(-1); 166 } 167 } 168 169 public void setupTemplateSetManager() 170 { 171 _templateSetManager.rescanTemplateSets(getTemplatePath()); 172 } 173 174 public void setupProjectPane() throws Exception 175 { 176 _pnlProject = new ProjectPanel(this, _projectProperties); 177 _splitpane.add(_pnlProject, JSplitPane.TOP); 178 } 179 180 public TemplateSetManager getTemplateSetManager() 181 { 182 return _templateSetManager; 183 } 184 185 protected void setupPersistenceManager(String repositories) throws DjenericException, FileNotFoundException 186 { 187 DjPersistenceManagerFactory fact = new DjPersistenceManagerFactory(this, repositories); 188 _mgr = fact.createInstance(); 189 } 190 191 protected void setupSession() throws DjenericException 192 { 193 _session = _mgr.createSession(); 194 _session.setValidateObjectsAfterLoading(false); 195 } 196 197 protected void setupContext() throws DjenericException 198 { 199 DjUserContextAssociation[] ctxt = _mgr.getCurrentUser().getContextAssociations(); 200 if (ctxt.length == 1) _mgr.getContextManager().setCurrentContext(ctxt[0].getContext()); 201 202 else 203 _mgr.determineContext(); 205 } 206 207 protected void setupWindow() 208 { 209 int divloc = Integer.parseInt(getProperty("window.dividerloc", "225")); 210 _splitpane.setDividerLocation(divloc); 211 212 int width = Integer.parseInt(getProperty("window.width", "400")); 213 int height = Integer.parseInt(getProperty("window.height", "400")); 214 setSize(new Dimension (width, height)); 215 addKeyListener(this); 216 } 217 218 protected void updateTitle() 219 { 220 String title = "Untitled"; 221 if (_projectFileName != null) title = _projectFileName; 222 223 try 224 { 225 setTitle("Djeneric Generator v" + DjVersion.getVersion() + " - " + title + " - " 226 + getManager().getConnectionTitle()); 227 } 228 catch (Exception x) 229 { 230 DjLogger.log(x); 231 } 232 } 233 234 240 protected void jbInit() throws Exception 241 { 242 mnuFile.setMnemonic('F'); 243 mnuFile.setText("File"); 244 mnuExit.setText("Exit"); 245 mnuExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(115, java.awt.event.KeyEvent.ALT_MASK, false)); 246 mnuExit.addActionListener(new java.awt.event.ActionListener () 247 { 248 public void actionPerformed(ActionEvent e) 249 { 250 mnuExit(e); 251 } 252 }); 253 mnuHelp.setMnemonic('H'); 254 mnuHelp.setText("Help"); 255 mnuAbout.setText("About"); 256 mnuAbout.addActionListener(new java.awt.event.ActionListener () 257 { 258 public void actionPerformed(ActionEvent e) 259 { 260 mnuAbout(e); 261 } 262 }); 263 this.setJMenuBar(_menu); 264 265 _lblStatus.setText("OK"); 266 _lblStatus.setOpaque(true); 267 _desktopPanel.setLayout(borderLayout2); 268 _desktopPanel.setBackground(SystemColor.desktop); 269 mnuNewProject.setMnemonic('P'); 270 mnuNewProject.setText("New Project..."); 271 mnuNewProject.setAccelerator(javax.swing.KeyStroke.getKeyStroke(78, java.awt.event.KeyEvent.CTRL_MASK, false)); 272 mnuNewProject.addActionListener(new java.awt.event.ActionListener () 273 { 274 public void actionPerformed(ActionEvent e) 275 { 276 mnuNewProject(e); 277 } 278 }); 279 mnuOpenProject.setMnemonic('O'); 280 mnuOpenProject.setText("Open Project..."); 281 mnuOpenProject.setAccelerator(javax.swing.KeyStroke.getKeyStroke(79, java.awt.event.KeyEvent.CTRL_MASK, false)); 282 mnuOpenProject.addActionListener(new java.awt.event.ActionListener () 283 { 284 public void actionPerformed(ActionEvent e) 285 { 286 mnuOpenProject(e); 287 } 288 }); 289 mnuProjectProperties.setText("Project Properties..."); 290 mnuProjectProperties.addActionListener(new java.awt.event.ActionListener () 291 { 292 public void actionPerformed(ActionEvent e) 293 { 294 mnuProjectProperties(e); 295 } 296 }); 297 mnuOptions.setText("Options..."); 298 mnuOptions.addActionListener(new java.awt.event.ActionListener () 299 { 300 public void actionPerformed(ActionEvent e) 301 { 302 mnuOptions(e); 303 } 304 }); 305 mnuTools.setMnemonic('T'); 306 mnuTools.setText("Tools"); 307 mnuSaveProject.setMnemonic('S'); 308 mnuSaveProject.setText("Save Project"); 309 mnuSaveProject.setAccelerator(javax.swing.KeyStroke.getKeyStroke(83, java.awt.event.KeyEvent.CTRL_MASK, false)); 310 mnuSaveProject.addActionListener(new java.awt.event.ActionListener () 311 { 312 public void actionPerformed(ActionEvent e) 313 { 314 mnuSaveProject(e); 315 } 316 }); 317 mnuSaveAs.setMnemonic('A'); 318 mnuSaveAs.setText("Save Project As..."); 319 mnuSaveAs.addActionListener(new java.awt.event.ActionListener () 320 { 321 public void actionPerformed(ActionEvent e) 322 { 323 mnuSaveAs(e); 324 } 325 }); 326 mnuTabs.setMnemonic('A'); 327 mnuTabs.setText("Tabs"); 328 mnuNextTab.setText("Next"); 329 mnuNextTab.setAccelerator(javax.swing.KeyStroke.getKeyStroke(117, java.awt.event.KeyEvent.CTRL_MASK, false)); 330 mnuNextTab.addActionListener(new java.awt.event.ActionListener () 331 { 332 public void actionPerformed(ActionEvent e) 333 { 334 mnuNextTab(e); 335 } 336 }); 337 mnuPrevTab.setText("Previous"); 338 mnuPrevTab.setAccelerator(javax.swing.KeyStroke.getKeyStroke(117, java.awt.event.KeyEvent.CTRL_MASK, false)); 339 mnuPrevTab.addActionListener(new java.awt.event.ActionListener () 340 { 341 public void actionPerformed(ActionEvent e) 342 { 343 mnuPrevTab(e); 344 } 345 }); 346 mnuCloseTab.setText("Close"); 347 mnuCloseTab.setAccelerator(javax.swing.KeyStroke.getKeyStroke(115, java.awt.event.KeyEvent.CTRL_MASK, false)); 348 mnuCloseTab.addActionListener(new java.awt.event.ActionListener () 349 { 350 public void actionPerformed(ActionEvent e) 351 { 352 mnuCloseTab(e); 353 } 354 }); 355 mnuCloseAll.setText("Close All"); 356 mnuCloseAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke(115, java.awt.event.KeyEvent.CTRL_MASK 357 | java.awt.event.KeyEvent.SHIFT_MASK, false)); 358 mnuCloseAll.addActionListener(new java.awt.event.ActionListener () 359 { 360 public void actionPerformed(ActionEvent e) 361 { 362 mnuCloseAll(e); 363 } 364 }); 365 _splitpane.setOneTouchExpandable(true); 366 this.getContentPane().add(_splitpane, BorderLayout.CENTER); 367 _splitpane.add(_desktopPanel, JSplitPane.BOTTOM); 368 _desktopPanel.add(_tabs, BorderLayout.CENTER); 369 this.getContentPane().add(_lblStatus, BorderLayout.SOUTH); 370 _menu.add(mnuFile); 371 _menu.add(mnuTools); 372 _menu.add(mnuTabs); 373 _menu.add(mnuHelp); 374 mnuFile.add(mnuNewProject); 375 mnuFile.add(mnuOpenProject); 376 mnuFile.add(mnuSaveProject); 377 mnuFile.add(mnuSaveAs); 378 mnuFile.addSeparator(); 379 mnuFile.add(mnuProjectProperties); 380 mnuFile.addSeparator(); 381 mnuFile.add(mnuExit); 382 mnuHelp.add(mnuAbout); 383 mnuTools.add(mnuOptions); 384 mnuTabs.add(mnuNextTab); 385 mnuTabs.add(mnuPrevTab); 386 mnuTabs.add(mnuCloseTab); 387 mnuTabs.add(mnuCloseAll); 388 _splitpane.setDividerLocation(270); 389 390 setTabsVisible(false); 391 392 } 393 394 400 protected void processWindowEvent(WindowEvent e) 401 { 402 if (e.getID() == WindowEvent.WINDOW_CLOSING) 403 { 404 try 405 { 406 if (canExit()) exitProgram(); 407 } 408 catch (Exception iox) 409 { 410 setStatusMessage(iox); 411 } 412 } 413 else super.processWindowEvent(e); 414 415 } 416 417 protected void exitProgram() 418 { 419 _pnlProject.close(); 420 super.exitProgram(); 421 } 422 423 protected boolean canExit() throws Exception 424 { 425 return isOkToAbandon(); 426 } 427 428 protected void updateProperties() 429 { 430 setProperty("window.width", "" + getWidth()); 431 setProperty("window.height", "" + getHeight()); 432 setProperty("window.dividerloc", "" + _splitpane.getDividerLocation()); 433 if (_projectFileName != null) setProperty("lastopened", _projectFileName); 434 435 } 436 437 public static ImageIcon getImageIcon(String fileName) 438 { 439 URL url = Generator.class.getResource("images/" + fileName); 440 if (url != null) return new ImageIcon (url); 441 else return new ImageIcon (""); 442 } 444 445 public static Image getImage(String fileName) 446 { 447 URL url = Generator.class.getResource("images/" + fileName); 448 if (url != null) return Toolkit.getDefaultToolkit().getImage(url); 449 450 else return Toolkit.getDefaultToolkit().getImage(""); 451 } 452 453 public DjPersistenceManager getManager() 454 { 455 return _mgr; 456 } 457 458 public DjSession getSession() 459 { 460 return _session; 461 } 462 463 void mnuExit(ActionEvent e) 464 { 465 try 466 { 467 if (canExit()) exitProgram(); 468 } 469 catch (Exception x) 470 { 471 setStatusMessage(x); 472 } 473 } 474 475 public void closeTab(Component comp) 476 { 477 _tabs.remove(comp); 478 if (_tabs.getComponentCount() == 0) setTabsVisible(false); 479 } 480 481 public void keyTyped(KeyEvent e) 482 { 483 } 484 485 public void keyPressed(KeyEvent e) 486 { 487 if (_tabs.getComponentCount() == 0) return; 488 489 if ((e.getKeyCode() == KeyEvent.VK_F6) && ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) 490 && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0)) 491 { 492 prevTab(); 493 } 494 else if ((e.getKeyCode() == KeyEvent.VK_F6) && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0)) 495 { 496 nextTab(); 497 } 498 else if ((e.getKeyCode() == KeyEvent.VK_F4) && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0)) 499 { 500 closeTab(_tabs.getSelectedComponent()); 501 } 502 } 503 504 protected void prevTab() 505 { 506 int idx = _tabs.getSelectedIndex(); 507 if (idx == -1) return; 508 if (idx > 0) 509 { 510 idx--; 511 } 512 else 513 { 514 idx = _tabs.getComponentCount() - 1; 515 } 516 _tabs.setSelectedIndex(idx); 517 } 518 519 protected void nextTab() 520 { 521 int idx = _tabs.getSelectedIndex(); 522 if (idx == -1) return; 523 if (idx < _tabs.getComponentCount() - 1) 524 { 525 idx++; 526 } 527 else 528 { 529 idx = 0; 530 } 531 _tabs.setSelectedIndex(idx); 532 } 533 534 public void keyReleased(KeyEvent e) 535 { 536 } 537 538 public void setTabsVisible(boolean visible) 539 { 540 _tabs.setVisible(visible); 541 if (visible) 542 { 543 _desktopPanel.setBackground(new Color (212, 208, 200)); 544 } 545 else 546 { 547 _desktopPanel.setBackground(SystemColor.desktop); 548 } 549 550 } 551 552 void mnuAbout(ActionEvent e) 553 { 554 new AboutDialog(this); 555 } 556 557 void mnuNewProject(ActionEvent e) 558 { 559 try 560 { 561 if (!isOkToAbandon()) return; 562 563 ProjectProperties newProj = new ProjectProperties(); 564 565 ProjectPropertiesDialog ppd = new ProjectPropertiesDialog(this, "New Project", newProj, _templateSetManager); 566 if (!ppd.wasCancelled()) 567 { 568 newProj.copyInto(_projectProperties); 569 _projectProperties.setModified(true); 570 _projectFileName = null; 571 notifyProjectSwitched(); 572 setProjectVisible(true); 573 } 574 } 575 catch (Exception x) 576 { 577 setStatusMessage(x); 578 } 579 } 580 581 public void addTab(Component comp, String title, boolean setSelected) 582 { 583 _tabs.add(comp, title); 584 if (setSelected) _tabs.setSelectedComponent(comp); 585 setTabsVisible(true); 586 } 587 588 void mnuOptions(ActionEvent e) 589 { 590 OptionsDialog od = new OptionsDialog(this, getProperties()); 591 if (!od.wasCancelled()) rescanTemplateSets(); 592 } 593 594 void mnuProjectProperties(ActionEvent e) 595 { 596 ProjectPropertiesDialog ppd = new ProjectPropertiesDialog(this, "Project Properties", _projectProperties, 597 _templateSetManager); 598 if (!ppd.wasCancelled()) notifyProjectSwitched(); 599 } 600 601 public boolean isOkToOverwrite(File file) 602 { 603 int result = JOptionPane.showOptionDialog(this, "Do you want to overwrite " + file.getAbsolutePath() + "?", 604 "File exists", JOptionPane.DEFAULT_OPTION, 605 JOptionPane.INFORMATION_MESSAGE, null 606 , new String []{"Overwrite", "Cancel"}, null); 608 return result == 0; 609 } 610 611 boolean isOkToAbandon() throws Exception 612 { 613 if (isModified()) 614 { 615 int result = JOptionPane.showOptionDialog(this, "Do you want to save your changes?", "Changes made", 616 JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null 617 , new String []{"Save", "Discard", "Cancel"}, null); 619 if ((result != 0) && (result != 1)) 620 { 621 return false; 622 } 623 if (result == 0) 625 { 626 return saveProject(); 627 } 628 } 629 return true; 630 } 631 632 protected boolean saveProject() throws Exception 633 { 634 if (_projectFileName == null) return saveProjectAs(); 635 else return doSaveProject(); 636 } 637 638 protected boolean doSaveProject() throws Exception 639 { 640 _projectProperties.save(_projectFileName); 641 setStatusMessage("Project saved to " + _projectFileName); 642 return true; 643 } 644 645 protected void initFileChooser(JFileChooser fc) 646 { 647 fc.setCurrentDirectory(new File (getProperty("filelocation", System.getProperties().getProperty("user.dir")))); 648 } 649 650 protected void recordFileChooserSettings(JFileChooser fc) 651 { 652 setProperty("filelocation", fc.getCurrentDirectory().getAbsolutePath()); 653 } 654 655 protected boolean saveProjectAs() throws Exception 656 { 657 JFileChooser fc = new JFileChooser (); 658 initFileChooser(fc); 659 fc.setDialogTitle("Save Project As"); 660 DjFileFilter filter = new DjFileFilter(new String []{PROJECT_EXTENSION}, "Djeneric Generator Project"); 661 fc.setFileFilter(filter); 662 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 663 if (_projectFileName != null) 664 { 665 fc.setSelectedFile(new File (_projectFileName)); 666 } 667 668 if (fc.showSaveDialog(this) != JFileChooser.CANCEL_OPTION) 669 { 670 recordFileChooserSettings(fc); 671 String fileName = fc.getSelectedFile().getAbsolutePath(); 672 if (!fileName.toLowerCase().endsWith("." + PROJECT_EXTENSION)) 673 { 674 fileName += "." + PROJECT_EXTENSION; 675 } 676 File chk = new File (fileName); 677 if (chk.exists() && !isOkToOverwrite(chk)) return false; 678 _projectFileName = fileName; 679 updateTitle(); 680 return doSaveProject(); 681 } 682 return false; 683 } 684 685 void mnuSaveProject(ActionEvent e) 686 { 687 try 688 { 689 saveProject(); 690 } 691 catch (Exception x) 692 { 693 setStatusMessage(x); 694 } 695 } 696 697 void mnuSaveAs(ActionEvent e) 698 { 699 try 700 { 701 saveProjectAs(); 702 } 703 catch (Exception x) 704 { 705 setStatusMessage(x); 706 } 707 708 } 709 710 void mnuOpenProject(ActionEvent e) 711 { 712 openProject(); 713 } 714 715 public void openProject() 716 { 717 try 718 { 719 if (isOkToAbandon()) 720 { 721 JFileChooser fc = new JFileChooser (); 722 fc.setDialogTitle("Open Project"); 723 DjFileFilter filter = new DjFileFilter(new String []{PROJECT_EXTENSION}, "Djeneric Generator Project"); 724 fc.setFileFilter(filter); 725 initFileChooser(fc); 726 727 String path = ""; 728 if (_projectFileName == null) path = System.getProperties().getProperty("user.dir"); 729 fc.setCurrentDirectory(new File (path)); 730 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 731 732 fc.setSelectedFile(new File (getProperty("lastopened", ""))); 733 734 if (fc.showDialog(this, "Open Project") == JFileChooser.APPROVE_OPTION) 735 { 736 ProjectProperties newProj = new ProjectProperties(); 737 newProj.load(fc.getSelectedFile().getAbsolutePath()); 738 newProj.copyInto(_projectProperties); 739 _projectProperties.setModified(false); 740 _projectFileName = fc.getSelectedFile().getAbsolutePath(); 741 updateTitle(); 742 rescanTemplateSets(); 743 setStatusMessage("Project definitions loaded from " + _projectFileName); 744 updateProperties(); 745 setProjectVisible(true); 746 } 747 } 748 } 749 catch (Exception x) 750 { 751 setStatusMessage(x); 752 } 753 } 754 755 protected boolean isModified() 756 { 757 return _projectProperties.isModified(); 758 } 759 760 protected void setProjectVisible(boolean b) 761 { 762 _splitpane.setVisible(b); 763 invalidate(); 764 validate(); 765 } 766 767 protected void rescanTemplateSets() 768 { 769 _templateSetManager.rescanTemplateSets(getProperty(KEY_TEMPLATEPATH, ".")); 770 _pnlProject.refreshTemplates(); 771 772 } 773 774 protected void notifyProjectSwitched() 775 { 776 updateTitle(); 777 rescanTemplateSets(); 778 } 779 780 public JTextArea getTextTab(String title, boolean setSelected) 781 { 782 for (int i = 0; i < _tabs.getComponentCount(); i++) 783 { 784 if (_tabs.getTitleAt(i).equals(title)) 785 { 786 Component c = _tabs.getComponent(i); 787 if (c instanceof JScrollPane ) 788 { 789 JScrollPane scr = (JScrollPane ) c; 790 JTextArea ta = (JTextArea ) scr.getViewport().getComponent(0); 791 if (setSelected) _tabs.setSelectedIndex(i); 792 return ta; 793 } 794 } 795 } 796 return createTextTab(title, setSelected); 797 } 798 799 private JTextArea createTextTab(String title, boolean setSelected) 800 { 801 CloseableScrollpane scr = new CloseableScrollpane(this); 802 JTextArea ta = new JTextArea (); 803 ta.setFont(new java.awt.Font ("Monospaced", 0, 11)); 804 ta.setEditable(false); 805 806 scr.getViewport().add(ta); 807 addTab(scr, title, setSelected); 808 return ta; 809 } 810 811 void mnuNextTab(ActionEvent e) 812 { 813 nextTab(); 814 } 815 816 void mnuCloseTab(ActionEvent e) 817 { 818 closeTab(_tabs.getSelectedComponent()); 819 } 820 821 void mnuPrevTab(ActionEvent e) 822 { 823 prevTab(); 824 } 825 826 void mnuCloseAll(ActionEvent e) 827 { 828 while (_tabs.getSelectedComponent() != null) 829 closeTab(_tabs.getSelectedComponent()); 830 } 831 832 public String getTemplatePath() 833 { 834 return getProperties().getProperty(Generator.KEY_TEMPLATEPATH, ""); 835 } 836 837 public String getIncludePath() 838 { 839 return getProperties().getProperty(Generator.KEY_INCLUDEPATH, ""); 840 } 841 842 public static void main(String [] args) 843 { 844 try 845 { 846 DjenericTool.setLookAndFeel(); 847 848 if (args.length < 1) 849 { 850 System.out.println("Usage: java " + Generator.class.getName() + " <repositories.xml>"); 851 return; 852 } 853 String banner = Generator.class.getName() + " version " + DjVersion.getVersion(); 854 DjLogPrintStream.logAll(banner, LOG_FILE_NAME); 855 856 System.out.println("Reading " + args[0]); 857 new Generator(args[0]).startApp(); 858 } 859 catch (Exception e) 860 { 861 DjLogger.log(e); 862 } 863 } 864 865 } | Popular Tags |