1 package com.genimen.djeneric.tools.menu; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Dimension ; 5 import java.awt.Rectangle ; 6 import java.awt.event.ActionEvent ; 7 import java.io.File ; 8 import java.io.IOException ; 9 import java.io.InputStreamReader ; 10 import java.net.URL ; 11 import java.sql.Connection ; 12 import java.sql.DriverManager ; 13 import java.sql.SQLException ; 14 import java.util.ArrayList ; 15 import java.util.Collections ; 16 import java.util.Iterator ; 17 import java.util.Properties ; 18 import java.util.StringTokenizer ; 19 20 import javax.swing.ImageIcon ; 21 import javax.swing.JButton ; 22 import javax.swing.JLabel ; 23 import javax.swing.JPanel ; 24 import javax.swing.JTabbedPane ; 25 26 import com.genimen.djeneric.language.Messages; 27 import com.genimen.djeneric.tools.administrator.Administrator; 28 import com.genimen.djeneric.tools.console.Console; 29 import com.genimen.djeneric.tools.logbrowser.LogBrowser; 30 import com.genimen.djeneric.tools.modeler.ModelEditor; 31 import com.genimen.djeneric.tools.specifier.Specifier; 32 import com.genimen.djeneric.tools.strongtyper.StrongTyper; 33 import com.genimen.djeneric.ui.DjSwingWorker; 34 import com.genimen.djeneric.ui.Util; 35 import com.genimen.djeneric.util.DjFileFilter; 36 import com.genimen.djeneric.util.DjLogger; 37 import com.genimen.djeneric.util.DjStringComparator; 38 39 public class MenuPanel extends JPanel 40 { 41 private static final long serialVersionUID = 1L; 42 BorderLayout borderLayout1 = new BorderLayout (); 43 JTabbedPane jTabbedPane1 = new JTabbedPane (); 44 JPanel mainPanel = new JPanel (); 45 JPanel adminPanel = new JPanel (); 46 JPanel hsqlPanel = new JPanel (); 47 JButton _butModeler = new JButton (); 48 JButton _butSpecifier = new JButton (); 49 JButton _butStrongTyper = new JButton (); 50 JButton _butAdministrator = new JButton (); 51 JButton _butLogbrowser = new JButton (); 52 JLabel lblModelerDescr = new JLabel (); 53 JLabel lblModeler = new JLabel (); 54 JLabel lblSpecifierDescr = new JLabel (); 55 JLabel lblSpecifier = new JLabel (); 56 JLabel lblStrongTyper = new JLabel (); 57 JLabel lblStrongTyperDescr = new JLabel (); 58 JLabel lblAdminDescr = new JLabel (); 59 JLabel lblAdmin = new JLabel (); 60 JLabel lblLogBrowser = new JLabel (); 61 JLabel lblLogBrowserDescr = new JLabel (); 62 JLabel lblStartDb = new JLabel (); 63 JButton _butStartdb = new JButton (); 64 JButton _butStopdb = new JButton (); 65 JLabel lblStartDbDescr = new JLabel (); 66 JLabel lblStopDb = new JLabel (); 67 JLabel lblStopDbDescr = new JLabel (); 68 69 String _repositoriesFile; 70 JLabel lblConsoleDescr = new JLabel (); 71 JButton _butConsole = new JButton (); 72 JLabel lblConsole = new JLabel (); 73 JPanel codingPanel = new JPanel (); 74 JLabel lblOptions = new JLabel (); 75 JButton _butOptions = new JButton (); 76 JLabel lblOptionsDescr = new JLabel (); 77 78 Properties _props; 79 JLabel _lblDbOnOff = new JLabel (); 80 JLabel _lblDbStatus = new JLabel (); 81 82 public MenuPanel() 83 { 84 try 85 { 86 jbInit(); 87 updateDbStatus(); 88 } 89 catch (Exception ex) 90 { 91 DjLogger.log(ex); 92 } 93 } 94 95 public void updateDbStatus() 96 { 97 98 boolean dbUp = isDbUp(); 99 if (dbUp) 100 { 101 _lblDbStatus.setText(Messages.getString("MenuPanel.DatabaseIsUp")); 102 _lblDbOnOff.setIcon(getImageIcon("com/genimen/djeneric/tools/menu/images/dbup.gif")); 103 } 104 else 105 { 106 _lblDbStatus.setText(Messages.getString("MenuPanel.DatabaseIsDown")); 107 _lblDbOnOff.setIcon(getImageIcon("com/genimen/djeneric/tools/menu/images/dbdown.gif")); 108 } 109 _butStartdb.setEnabled(!dbUp); 110 _butStopdb.setEnabled(dbUp); 111 } 112 113 private boolean isDbUp() 114 { 115 try 116 { 117 Class.forName("org.hsqldb.jdbcDriver"); 118 Connection conn = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost", "sa", ""); 119 conn.close(); 120 return true; 121 } 122 catch (SQLException e) 123 { 124 if (e.getErrorCode() == -80) return false; 125 } 126 catch (ClassNotFoundException e) 127 { 128 } 130 return false; 132 } 133 134 void jbInit() throws Exception 135 { 136 _butModeler.setIcon(getImageIcon("com/genimen/djeneric/tools/modeler/images/modeler.gif")); _butSpecifier.setIcon(getImageIcon("com/genimen/djeneric/tools/specifier/images/specifier.gif")); _butStrongTyper.setIcon(getImageIcon("com/genimen/djeneric/tools/strongtyper/images/strongtyper.gif")); _butAdministrator.setIcon(getImageIcon("com/genimen/djeneric/tools/administrator/images/admin.gif")); _butLogbrowser.setIcon(getImageIcon("com/genimen/djeneric/tools/logbrowser/images/logbrowser.gif")); _butStartdb.setIcon(getImageIcon("com/genimen/djeneric/tools/administrator/images/schema.gif")); _butStopdb.setIcon(getImageIcon("com/genimen/djeneric/tools/administrator/images/down.gif")); _butConsole.setIcon(getImageIcon("com/genimen/djeneric/tools/console/nodes/images/console.gif")); _butConsole.addActionListener(new MenuPanel__butConsole_actionAdapter(this)); _butOptions.setIcon(getImageIcon("com/genimen/djeneric/tools/menu/images/options.gif")); 146 147 _butStrongTyper.addActionListener(new MenuPanel__butStrongTyper_actionAdapter(this)); 148 _butSpecifier.addActionListener(new MenuPanel__butSpecifier_actionAdapter(this)); 149 _butModeler.addActionListener(new MenuPanel__butModeler_actionAdapter(this)); 150 _butLogbrowser.addActionListener(new MenuPanel__butLogbrowser_actionAdapter(this)); 151 _butAdministrator.addActionListener(new MenuPanel__butAdministrator_actionAdapter(this)); 152 153 this.setLayout(borderLayout1); 154 mainPanel.setLayout(null); 155 adminPanel.setLayout(null); 156 hsqlPanel.setLayout(null); 157 158 _butAdministrator.setBounds(new Rectangle (9, 7, 24, 24)); 159 _butLogbrowser.setBounds(new Rectangle (9, 40, 24, 24)); 160 _butModeler.setBounds(new Rectangle (9, 7, 24, 24)); 161 _butSpecifier.setBounds(new Rectangle (9, 40, 24, 24)); 162 _butStrongTyper.setBounds(new Rectangle (9, 7, 24, 24)); 163 164 lblModeler.setText(Messages.getString("MenuPanel.Modeler")); lblModeler.setBounds(new Rectangle (46, 4, 234, 16)); 166 lblModelerDescr.setFont(new java.awt.Font ("Dialog", 0, 12)); lblModelerDescr.setText(Messages.getString("MenuPanel.ModelerDescr")); lblModelerDescr.setBounds(new Rectangle (46, 15, 313, 22)); 169 170 lblSpecifierDescr.setBounds(new Rectangle (46, 48, 313, 22)); 171 lblSpecifierDescr.setFont(new java.awt.Font ("Dialog", 0, 12)); lblSpecifierDescr.setText(Messages.getString("MenuPanel.SpecifierDescr")); lblSpecifier.setBounds(new Rectangle (46, 37, 234, 16)); 174 lblSpecifier.setText(Messages.getString("MenuPanel.Specfier")); 176 lblStrongTyper.setText(Messages.getString("MenuPanel.StrongTyper")); lblStrongTyper.setBounds(new Rectangle (46, 4, 234, 16)); 178 lblStrongTyperDescr.setFont(new java.awt.Font ("Dialog", 0, 12)); lblStrongTyperDescr.setText(Messages.getString("MenuPanel.StrongTyperDescr")); lblStrongTyperDescr.setBounds(new Rectangle (46, 15, 313, 22)); 181 182 lblAdminDescr.setBounds(new Rectangle (46, 15, 313, 22)); 183 lblAdminDescr.setText(Messages.getString("MenuPanel.AdminDescr")); lblAdminDescr.setFont(new java.awt.Font ("Dialog", 0, 12)); lblAdmin.setBounds(new Rectangle (46, 4, 234, 16)); 186 lblAdmin.setText(Messages.getString("MenuPanel.Admin")); lblLogBrowser.setText(Messages.getString("MenuPanel.LogBrowser")); lblLogBrowser.setBounds(new Rectangle (46, 37, 234, 16)); 189 lblLogBrowserDescr.setFont(new java.awt.Font ("Dialog", 0, 12)); lblLogBrowserDescr.setText(Messages.getString("MenuPanel.LogBrowserDescr")); lblLogBrowserDescr.setBounds(new Rectangle (46, 48, 313, 22)); 192 lblStartDb.setText(Messages.getString("MenuPanel.StartDb")); lblStartDb.setBounds(new Rectangle (46, 4, 234, 16)); 194 _butStartdb.setBounds(new Rectangle (9, 7, 24, 24)); 195 _butStartdb.addActionListener(new MenuPanel__butStartdb_actionAdapter(this)); 196 _butStopdb.setBounds(new Rectangle (9, 40, 24, 24)); 197 _butStopdb.addActionListener(new MenuPanel__butStopdb_actionAdapter(this)); 198 lblStartDbDescr.setFont(new java.awt.Font ("Dialog", 0, 12)); lblStartDbDescr.setText(Messages.getString("MenuPanel.StartDbDescr")); lblStartDbDescr.setBounds(new Rectangle (46, 15, 313, 22)); 201 lblStopDb.setBounds(new Rectangle (46, 37, 234, 16)); 202 lblStopDb.setText(Messages.getString("MenuPanel.StopDb")); lblStopDbDescr.setBounds(new Rectangle (46, 48, 313, 22)); 204 lblStopDbDescr.setText(Messages.getString("MenuPanel.StopDbDescr")); lblStopDbDescr.setFont(new java.awt.Font ("Dialog", 0, 12)); lblConsoleDescr.setBounds(new Rectangle (46, 81, 313, 22)); 207 lblConsoleDescr.setText(Messages.getString("MenuPanel.ConsoleDescr")); lblConsoleDescr.setFont(new java.awt.Font ("Dialog", 0, 12)); _butConsole.setBounds(new Rectangle (9, 73, 24, 24)); 210 211 lblConsole.setBounds(new Rectangle (46, 70, 234, 16)); 212 lblConsole.setText(Messages.getString("MenuPanel.Console")); codingPanel.setLayout(null); 214 lblOptions.setText(Messages.getString("MenuPanel.Options")); 215 lblOptions.setBounds(new Rectangle (46, 70, 234, 16)); 216 _butOptions.setBounds(new Rectangle (9, 73, 24, 24)); 217 _butOptions.addActionListener(new MenuPanel__butOptions_actionAdapter(this)); 218 lblOptionsDescr.setFont(new java.awt.Font ("Dialog", 0, 12)); 219 lblOptionsDescr.setText(Messages.getString("MenuPanel.OptionsDescr")); 220 lblOptionsDescr.setBounds(new Rectangle (46, 81, 313, 22)); 221 _lblDbOnOff.setPreferredSize(new Dimension (16, 16)); 222 _lblDbOnOff.setBounds(new Rectangle (13, 88, 16, 16)); 223 _lblDbStatus.setFont(new java.awt.Font ("Dialog", 0, 12)); _lblDbStatus.setBounds(new Rectangle (46, 85, 313, 22)); 225 this.add(jTabbedPane1, BorderLayout.CENTER); 226 jTabbedPane1.add(mainPanel, Messages.getString("MenuPanel.Main")); jTabbedPane1.add(codingPanel, Messages.getString("MenuPanel.Coding")); jTabbedPane1.add(adminPanel, Messages.getString("MenuPanel.Administration")); jTabbedPane1.add(hsqlPanel, Messages.getString("MenuPanel.Hypersonic")); hsqlPanel.add(lblStartDbDescr, null); 231 hsqlPanel.add(_butStopdb, null); 232 hsqlPanel.add(lblStopDb, null); 233 hsqlPanel.add(lblStopDbDescr, null); 234 hsqlPanel.add(_butStartdb, null); 235 hsqlPanel.add(lblStartDb, null); 236 hsqlPanel.add(_lblDbOnOff); 237 hsqlPanel.add(_lblDbStatus); 238 mainPanel.add(_butModeler, null); 239 mainPanel.add(lblModelerDescr, null); 240 mainPanel.add(lblModeler, null); 241 mainPanel.add(lblSpecifier, null); 242 mainPanel.add(lblSpecifierDescr, null); 243 mainPanel.add(_butSpecifier, null); 244 codingPanel.add(lblStrongTyperDescr, null); 245 codingPanel.add(_butStrongTyper, null); 246 codingPanel.add(lblStrongTyper, null); 247 mainPanel.add(lblConsole, null); 248 mainPanel.add(lblConsoleDescr, null); 249 mainPanel.add(_butConsole, null); 250 adminPanel.add(lblAdminDescr, null); 251 adminPanel.add(lblAdmin, null); 252 adminPanel.add(_butAdministrator, null); 253 adminPanel.add(_butLogbrowser, null); 254 adminPanel.add(lblLogBrowserDescr, null); 255 adminPanel.add(lblLogBrowser, null); 256 adminPanel.add(lblOptionsDescr, null); 257 adminPanel.add(_butOptions, null); 258 adminPanel.add(lblOptions, null); 259 } 260 261 public static ImageIcon getImageIcon(String fileName) 262 { 263 URL url = MenuPanel.class.getClassLoader().getResource(fileName); 264 if (url != null) 265 { 266 return new ImageIcon (url); 267 } 268 else 269 { 270 return new ImageIcon (""); } 272 } 274 275 void _butModeler_actionPerformed(ActionEvent e) 276 { 277 try 278 { 279 startTool(ModelEditor.class); 280 } 281 catch (IOException e1) 282 { 283 DjLogger.log(e1); 284 } 285 } 286 287 void _butSpecifier_actionPerformed(ActionEvent e) 288 { 289 try 290 { 291 startTool(Specifier.class); 292 } 293 catch (IOException e1) 294 { 295 DjLogger.log(e1); 296 } 297 } 298 299 void _butStrongTyper_actionPerformed(ActionEvent e) 300 { 301 try 302 { 303 startTool(StrongTyper.class); 304 } 305 catch (IOException e1) 306 { 307 DjLogger.log(e1); 308 } 309 310 } 311 312 void _butAdministrator_actionPerformed(ActionEvent e) 313 { 314 try 315 { 316 startTool(Administrator.class); 317 } 318 catch (IOException e1) 319 { 320 DjLogger.log(e1); 321 } 322 323 } 324 325 void _butLogbrowser_actionPerformed(ActionEvent e) 326 { 327 try 328 { 329 startTool(LogBrowser.class); 330 } 331 catch (IOException e1) 332 { 333 DjLogger.log(e1); 334 } 335 336 } 337 338 void _butStartdb_actionPerformed(ActionEvent e) 339 { 340 try 341 { 342 String workingDir = System.getProperty("user.dir"); File dbDir = new File (workingDir + "/db"); 345 if (!dbDir.isDirectory()) 346 { 347 dbDir = new File (workingDir + "/../db"); if (!dbDir.isDirectory()) dbDir = new File ("db"); } 350 351 ArrayList lst = fetchDatabaseNames(dbDir); 352 ArrayList ext = fetchExternalDbs(); 353 Iterator it = ext.iterator(); 354 while (it.hasNext()) 355 { 356 String nm = it.next().toString(); 357 if (!lst.contains(nm)) lst.add(nm); 358 } 359 Collections.sort(lst, new DjStringComparator(false)); 360 361 if (lst.isEmpty()) 362 { 363 lst.add(dbDir.getCanonicalPath() + File.separator + Messages.getString("MenuPanel.myNewDb")); } 365 DatabaseSelector dbsel = new DatabaseSelector(Util.findFrame(this), lst); 366 367 if (!dbsel.wasCancelled()) 368 { 369 startDb(dbsel.getSelectedName()); 370 updateRecentDbList(dbsel.getSelectedName()); 371 } 372 373 } 374 catch (IOException e1) 375 { 376 DjLogger.log(e1); 377 } 378 } 379 380 private void updateRecentDbList(String selectedName) 381 { 382 ArrayList current = fetchExternalDbs(); 383 if (!current.contains(selectedName)) current.add(selectedName); 384 StringBuffer sb = new StringBuffer (100); 385 Iterator it = current.iterator(); 386 while (it.hasNext()) 387 { 388 if (sb.length() != 0) sb.append(","); 389 sb.append(it.next().toString()); 390 } 391 _props.setProperty(Menu.MENU_RECENTDBS, sb.toString()); 392 } 393 394 private ArrayList fetchExternalDbs() 395 { 396 ArrayList result = new ArrayList (); 397 398 String externalDbs = _props.getProperty(Menu.MENU_RECENTDBS); 399 if (externalDbs != null) 400 { 401 StringTokenizer stok = new StringTokenizer (externalDbs, ","); 402 while (stok.hasMoreElements()) 403 { 404 String dbName = stok.nextToken().trim(); 405 if (!result.contains(dbName)) 406 { 407 File testDb = new File (dbName + ".data"); 408 if (testDb.exists()) result.add(dbName); 409 else 410 { 411 testDb = new File (dbName + ".properties"); 412 if (testDb.exists()) result.add(dbName); 413 } 414 } 415 } 416 } 417 return result; 418 } 419 420 private ArrayList fetchDatabaseNames(File dbDir) throws IOException 421 { 422 ArrayList lst = new ArrayList (); 423 if (dbDir.isDirectory()) 424 { 425 File [] dbs = dbDir.listFiles(new DjFileFilter("data")); for (int i = 0; i < dbs.length; i++) 427 { 428 String nm = dbs[i].getCanonicalPath(); 429 if (!dbs[i].isDirectory() && nm.toLowerCase().endsWith(".data")) { 431 nm = nm.substring(0, nm.length() - 5); 432 lst.add(nm); 433 } 434 } 435 Collections.sort(lst, new DjStringComparator(false)); 436 } 437 return lst; 438 } 439 440 protected void startDb(String dbName) 441 { 442 ArrayList args = new ArrayList (); 443 args.add("java"); 445 addClassPath(args); 446 447 args.add("org.hsqldb.Server"); args.add("-database"); args.add(dbName); 450 451 new ToolRunner((String []) args.toArray(new String [0])); 452 try 453 { 454 for (int i = 0; i < 5; i++) 455 { 456 Thread.sleep(200); 457 if (isDbUp()) 458 { 459 updateDbStatus(); 460 break; 461 } 462 } 463 } 464 catch (InterruptedException e) 465 { 466 DjLogger.log(e); 467 } 468 } 469 470 void _butStopdb_actionPerformed(ActionEvent e) 471 { 472 try 473 { 474 stopDB(); 475 } 476 catch (IOException e1) 477 { 478 DjLogger.log(e1); 479 } 480 481 } 482 483 public void setRepositoriesFile(String repositoriesFile) 484 { 485 _repositoriesFile = repositoriesFile; 486 } 487 488 private void startTool(Class clazz) throws IOException 489 { 490 ArrayList args = new ArrayList (); 491 args.add("java"); 493 String vmArg = _props.getProperty(Menu.TOOL_VM_OPTIONS); 494 if (vmArg != null && vmArg.trim().length() > 0) 495 { 496 StringTokenizer st = new StringTokenizer (vmArg, " \t\n\r"); 497 while (st.hasMoreElements()) 498 args.add(st.nextToken()); 499 } 500 addPrototypingOption(args); 501 addStripSpacesOption(args); 502 addLanguageOption(args); 503 addUserHomeOption(args); 504 addClassPath(args); 505 args.add(clazz.getName()); 506 args.add(_repositoriesFile); 507 508 new ToolRunner((String []) args.toArray(new String [0])); 509 } 510 511 private void stopDB() throws IOException 512 { 513 ArrayList args = new ArrayList (); 514 args.add("java"); 516 addClassPath(args); 517 args.add("org.hsqldb.util.ShutdownServer"); args.add("-user"); args.add("sa"); args.add("-shutdownarg"); args.add("COMPACT"); 523 new ToolRunner((String []) args.toArray(new String [0]), this); 524 } 525 526 protected void addClassPath(ArrayList args) 527 { 528 args.add("-cp"); args.add(System.getProperty("java.class.path")); } 531 532 protected void addPrototypingOption(ArrayList args) 533 { 534 String proto = _props.getProperty(Menu.TOOL_PROTOTYPING, "true"); if ("true".equalsIgnoreCase(proto)) args.add("-Ddjeneric.prototyping=" + proto); } 537 538 protected void addStripSpacesOption(ArrayList args) 539 { 540 String strip = _props.getProperty(Menu.TOOL_STRIPSPACES, "true"); if (strip != null && strip.trim().length() > 0) args.add("-Ddjeneric.stripspaces=" + strip); } 543 544 protected void addLanguageOption(ArrayList args) 545 { 546 String lang = _props.getProperty(Menu.TOOL_LANGUAGE); if (lang != null && lang.trim().length() > 0) args.add("-Ddjeneric.language=" + lang); } 549 550 protected void addUserHomeOption(ArrayList args) 551 { 552 String home = System.getProperty("user.home"); if (home == null) return; 554 555 args.add("-Duser.home=" + home); } 557 558 void _butConsole_actionPerformed(ActionEvent e) 559 { 560 try 561 { 562 startTool(Console.class); 563 } 564 catch (IOException e1) 565 { 566 DjLogger.log(e1); 567 } 568 } 569 570 void _butOptions_actionPerformed(ActionEvent e) 571 { 572 new OptionsDialog(Util.findFrame(this), _props); 573 } 574 575 public void setProps(Properties props) 576 { 577 _props = props; 578 } 579 580 public void toolExited() 581 { 582 updateDbStatus(); 583 } 584 585 } 586 587 class MenuPanel__butModeler_actionAdapter implements java.awt.event.ActionListener 588 { 589 MenuPanel adaptee; 590 591 MenuPanel__butModeler_actionAdapter(MenuPanel adaptee) 592 { 593 this.adaptee = adaptee; 594 } 595 596 public void actionPerformed(ActionEvent e) 597 { 598 adaptee._butModeler_actionPerformed(e); 599 } 600 } 601 602 class MenuPanel__butSpecifier_actionAdapter implements java.awt.event.ActionListener 603 { 604 MenuPanel adaptee; 605 606 MenuPanel__butSpecifier_actionAdapter(MenuPanel adaptee) 607 { 608 this.adaptee = adaptee; 609 } 610 611 public void actionPerformed(ActionEvent e) 612 { 613 adaptee._butSpecifier_actionPerformed(e); 614 } 615 } 616 617 class MenuPanel__butStrongTyper_actionAdapter implements java.awt.event.ActionListener 618 { 619 MenuPanel adaptee; 620 621 MenuPanel__butStrongTyper_actionAdapter(MenuPanel adaptee) 622 { 623 this.adaptee = adaptee; 624 } 625 626 public void actionPerformed(ActionEvent e) 627 { 628 adaptee._butStrongTyper_actionPerformed(e); 629 } 630 } 631 632 class MenuPanel__butAdministrator_actionAdapter implements java.awt.event.ActionListener 633 { 634 MenuPanel adaptee; 635 636 MenuPanel__butAdministrator_actionAdapter(MenuPanel adaptee) 637 { 638 this.adaptee = adaptee; 639 } 640 641 public void actionPerformed(ActionEvent e) 642 { 643 adaptee._butAdministrator_actionPerformed(e); 644 } 645 } 646 647 class MenuPanel__butLogbrowser_actionAdapter implements java.awt.event.ActionListener 648 { 649 MenuPanel adaptee; 650 651 MenuPanel__butLogbrowser_actionAdapter(MenuPanel adaptee) 652 { 653 this.adaptee = adaptee; 654 } 655 656 public void actionPerformed(ActionEvent e) 657 { 658 adaptee._butLogbrowser_actionPerformed(e); 659 } 660 } 661 662 class MenuPanel__butStartdb_actionAdapter implements java.awt.event.ActionListener 663 { 664 MenuPanel adaptee; 665 666 MenuPanel__butStartdb_actionAdapter(MenuPanel adaptee) 667 { 668 this.adaptee = adaptee; 669 } 670 671 public void actionPerformed(ActionEvent e) 672 { 673 adaptee._butStartdb_actionPerformed(e); 674 } 675 } 676 677 class MenuPanel__butStopdb_actionAdapter implements java.awt.event.ActionListener 678 { 679 MenuPanel adaptee; 680 681 MenuPanel__butStopdb_actionAdapter(MenuPanel adaptee) 682 { 683 this.adaptee = adaptee; 684 } 685 686 public void actionPerformed(ActionEvent e) 687 { 688 adaptee._butStopdb_actionPerformed(e); 689 } 690 } 691 692 class ToolRunner extends Thread 693 { 694 String [] _args; 695 MenuPanel _menu; 696 697 public void run() 698 { 699 try 700 { 701 for (int i = 0; i < _args.length; i++) 702 System.out.print(_args[i] + " "); 703 System.out.println(); 704 705 Process child = Runtime.getRuntime().exec(_args); 706 707 InputStreamReader inReader = new InputStreamReader (child.getInputStream()); 708 InputStreamReader errReader = new InputStreamReader (child.getErrorStream()); 709 710 final int EXIT_CHECK_COUNT = 50; 711 712 int someByte = 0; 713 int exitedCheck = EXIT_CHECK_COUNT; 714 while (someByte != -1) 715 { 716 while (inReader.ready()) 717 { 718 someByte = inReader.read(); 719 System.out.write(someByte); 720 } 721 722 while (errReader.ready()) 723 { 724 someByte = errReader.read(); 725 System.err.write(someByte); 726 } 727 try 728 { 729 Thread.sleep(100); 730 } 731 catch (InterruptedException e1) 732 { 733 DjLogger.log(e1); 734 } 735 736 if (exitedCheck-- == 0) 737 { 738 exitedCheck = EXIT_CHECK_COUNT; 739 try 740 { 741 child.exitValue(); 742 someByte = -1; 743 } 744 catch (IllegalThreadStateException is) 745 { 746 } 748 } 749 } 750 System.err.flush(); 751 System.out.flush(); 752 753 inReader.close(); 754 errReader.close(); 755 756 callBack(); 757 DjLogger.log(Messages.getString("MenuPanel.ToolExited")); } 759 catch (IOException e) 760 { 761 DjLogger.log(Messages.getString("MenuPanel.ExecFailure") + e.getMessage()); } 763 } 764 765 private void callBack() 766 { 767 if (_menu != null) 768 { 769 DjSwingWorker worker = new DjSwingWorker() 770 { 771 public Object construct() 772 { 773 _menu.toolExited(); 774 return null; 775 } 776 777 public void finished() 778 { 779 } 780 }; 781 worker.start(); 782 } 783 } 784 785 public ToolRunner(String [] args) 786 { 787 _args = args; 788 start(); 789 } 790 791 public ToolRunner(String [] args, MenuPanel menu) 792 { 793 _args = args; 794 _menu = menu; 795 start(); 796 } 797 } 798 799 class MenuPanel__butConsole_actionAdapter implements java.awt.event.ActionListener 800 { 801 MenuPanel adaptee; 802 803 MenuPanel__butConsole_actionAdapter(MenuPanel adaptee) 804 { 805 this.adaptee = adaptee; 806 } 807 808 public void actionPerformed(ActionEvent e) 809 { 810 adaptee._butConsole_actionPerformed(e); 811 } 812 } 813 814 class MenuPanel__butOptions_actionAdapter implements java.awt.event.ActionListener 815 { 816 MenuPanel adaptee; 817 818 MenuPanel__butOptions_actionAdapter(MenuPanel adaptee) 819 { 820 this.adaptee = adaptee; 821 } 822 823 public void actionPerformed(ActionEvent e) 824 { 825 adaptee._butOptions_actionPerformed(e); 826 } 827 } 828 | Popular Tags |