1 24 25 package org.objectweb.cjdbc.console.monitoring; 26 27 import java.awt.BorderLayout ; 28 import java.awt.Color ; 29 import java.awt.Dimension ; 30 import java.awt.Font ; 31 import java.awt.GridLayout ; 32 import java.awt.Point ; 33 import java.awt.Toolkit ; 34 import java.awt.Window ; 35 import java.awt.event.ActionEvent ; 36 import java.awt.event.ActionListener ; 37 import java.awt.event.MouseEvent ; 38 import java.awt.event.MouseListener ; 39 import java.awt.event.WindowEvent ; 40 import java.awt.event.WindowListener ; 41 import java.io.BufferedOutputStream ; 42 import java.io.File ; 43 import java.io.FileInputStream ; 44 import java.io.FileOutputStream ; 45 import java.io.IOException ; 46 import java.util.ArrayList ; 47 import java.util.Enumeration ; 48 import java.util.Hashtable ; 49 import java.util.Iterator ; 50 import java.util.PropertyResourceBundle ; 51 import java.util.StringTokenizer ; 52 import java.util.Vector ; 53 54 import javax.swing.JButton ; 55 import javax.swing.JComboBox ; 56 import javax.swing.JComponent ; 57 import javax.swing.JFrame ; 58 import javax.swing.JLabel ; 59 import javax.swing.JMenu ; 60 import javax.swing.JMenuBar ; 61 import javax.swing.JMenuItem ; 62 import javax.swing.JPanel ; 63 import javax.swing.JScrollPane ; 64 import javax.swing.JTextField ; 65 import javax.swing.JToolBar ; 66 import javax.swing.SwingConstants ; 67 68 import org.objectweb.cjdbc.common.exceptions.DataCollectorException; 69 import org.objectweb.cjdbc.common.i18n.MonitorTranslate; 70 import org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean; 71 import org.objectweb.cjdbc.common.jmx.mbeans.DataCollectorMBean; 72 import org.objectweb.cjdbc.common.jmx.mbeans.VirtualDatabaseMBean; 73 import org.objectweb.cjdbc.common.monitor.AbstractDataCollector; 74 import org.objectweb.cjdbc.common.monitor.DataCollection; 75 import org.objectweb.cjdbc.common.monitor.DataCollectionNames; 76 import org.objectweb.cjdbc.console.jmx.RmiJmxClient; 77 78 86 public class MonitoringConsole extends JFrame 87 implements 88 MouseListener , 89 ActionListener , 90 WindowListener 91 { 92 private int frameWidth = 400; 94 private int frameHeight = 700; 95 96 private JLabel label; 98 private JScrollPane jScroll; 99 100 private ControllerMBean controllerMBean; 102 private VirtualDatabaseMBean virtualDatabaseMBean; 103 private DataCollectorMBean dataCollectorMBean; 104 105 private static final String GRAPH_CONTROLLER = MonitorTranslate 107 .get("heading.controller"); 108 private static final String GRAPH_VIRTUAL_DATABASE = MonitorTranslate 109 .get("heading.virtualdatabase"); 110 private static final String GRAPH_CACHE = MonitorTranslate 111 .get("heading.cache"); 112 private static final String GRAPH_SCHEDULER = MonitorTranslate 113 .get("heading.scheduler"); 114 private static final String GRAPH_BACKENDS = MonitorTranslate 115 .get("heading.backends"); 116 117 private Hashtable windows = new Hashtable (); 118 119 private Vector comboBoxesItems = new Vector (); 120 private Hashtable comboBoxes = new Hashtable (); 121 122 private Font boxFont = new Font ("Arial", 124 Font.PLAIN, 10); 125 private Font labelFont = new Font ("Arial", 126 Font.BOLD, 10); 127 private Font headerFont = new Font ("Arial", 128 Font.BOLD, 12); 129 private Color toolBarColor = Color.white; 130 131 private int graphRepeat = -1; 133 private int graphTimeframe = 3600; 134 private int graphFrequency = 1000; 135 private int graphDisplayFrequency = 1; 136 137 private static final String COMMAND_SAVE = MonitorTranslate 139 .get("command.save"); 140 private static final String COMMAND_LOAD = MonitorTranslate 141 .get("command.load"); 142 private static final String COMMAND_CLOSE_GRAPHS = MonitorTranslate 143 .get("command.close.all"); 144 private static final String COMMAND_OPTIONS = MonitorTranslate 145 .get("command.set.options"); 146 private static final String COMMAND_CLOSE = MonitorTranslate 147 .get("command.quit"); 148 private static final String COMMAND_REFRESH = MonitorTranslate 149 .get("command.refresh"); 150 151 private static final String OPTIONS_APPLY = "OptionsApply"; 152 private static final String OPTIONS_CANCEL = "OptionsCancel"; 153 154 private static final String COMBO_HIDE = MonitorTranslate 156 .get("command.hide"); 157 private static final String COMBO_FLOATING = MonitorTranslate 158 .get("command.float"); 159 160 private boolean isLoading = false; 161 162 private JFrame options; 164 private JTextField ftimeframe; 165 private JTextField ffrequency; 166 private JTextField frepeat; 167 private JTextField displayBuffer; 168 169 private boolean displayController; 170 private boolean displayVirtualDatabase; 171 private boolean displayBackends; 172 173 184 public MonitoringConsole(String jmxUrl, ControllerMBean controllerMBean, 185 VirtualDatabaseMBean virtualDatabaseMBean, boolean backends) 186 throws IOException 187 { 188 super(MonitorTranslate.get("monitor.frame.title", jmxUrl)); 189 190 this.displayController = controllerMBean == null; 191 this.displayVirtualDatabase = virtualDatabaseMBean == null; 192 this.displayBackends = backends; 193 194 RmiJmxClient jmxClient = new RmiJmxClient(jmxUrl, null); 196 dataCollectorMBean = jmxClient.getDataCollectorProxy(); 197 this.controllerMBean = controllerMBean; 198 this.virtualDatabaseMBean = virtualDatabaseMBean; 199 200 comboBoxesItems.add(COMBO_HIDE); 202 comboBoxesItems.add(COMBO_FLOATING); 203 204 Toolkit toolkit; 205 Dimension dim; 206 int screenHeight, screenWidth; 207 208 setForeground(Color.white); 210 getContentPane().setLayout(new BorderLayout ()); 211 212 toolkit = Toolkit.getDefaultToolkit(); 214 dim = toolkit.getScreenSize(); 215 screenHeight = dim.height; 216 screenWidth = dim.width; 217 218 if (displayController && (!displayVirtualDatabase) && (!displayBackends)) 220 frameHeight = 270; 221 222 setBounds((screenWidth - frameWidth) / 2, (screenHeight - frameHeight) / 2, 223 frameWidth, frameHeight); 224 225 try 226 { 227 initConsole(); 229 } 230 catch (Exception e) 231 { 232 throw new IOException (e.getMessage()); 233 } 234 235 label = new JLabel ("Select Graphs ..."); 237 label.setFont(labelFont); 238 getContentPane().add(label, BorderLayout.SOUTH); 239 getContentPane().setBackground(toolBarColor); 240 getContentPane().setForeground(toolBarColor); 241 242 JMenuBar menuBar = new JMenuBar (); 244 JMenu menu = new JMenu (MonitorTranslate.get("monitor.menu.bar")); 245 JMenuItem item1 = new JMenuItem (COMMAND_SAVE); 246 JMenuItem item2 = new JMenuItem (COMMAND_LOAD); 247 JMenuItem item3 = new JMenuItem (COMMAND_CLOSE); 248 JMenuItem item4 = new JMenuItem (COMMAND_CLOSE_GRAPHS); 249 JMenuItem item5 = new JMenuItem (COMMAND_OPTIONS); 250 JMenuItem item6 = new JMenuItem (COMMAND_REFRESH); 251 item1.setBackground(toolBarColor); 252 item2.setBackground(toolBarColor); 253 item3.setBackground(toolBarColor); 254 item4.setBackground(toolBarColor); 255 item5.setBackground(toolBarColor); 256 item6.setBackground(toolBarColor); 257 menu.add(item1).addActionListener(this); 258 menu.add(item2).addActionListener(this); 259 menu.add(item4).addActionListener(this); 260 menu.add(item5).addActionListener(this); 261 menu.add(item6).addActionListener(this); 262 menu.addSeparator(); 263 menu.add(item3).addActionListener(this); 264 menu.setVisible(true); 265 menu.setBackground(toolBarColor); 266 menuBar.add(menu); 267 menuBar.setBackground(toolBarColor); 268 this.setJMenuBar(menuBar); 269 270 options = new JFrame (MonitorTranslate.get("options.frame.title")); 272 options.setSize(200, 200); 273 JPanel optionsPanel = new JPanel (); 274 optionsPanel.setLayout(new GridLayout (5, 2)); 275 optionsPanel.add(new JLabel (MonitorTranslate.get("options.repeat"))); 276 frepeat = new JTextField (0); 277 frepeat.setAlignmentX(RIGHT_ALIGNMENT); 278 frepeat.setText(graphRepeat + ""); 279 frepeat.addActionListener(this); 280 optionsPanel.add(frepeat); 281 282 optionsPanel 283 .add(new JLabel (MonitorTranslate.get("options.display.buffer"))); 284 displayBuffer = new JTextField (0); 285 displayBuffer.setText("" + graphDisplayFrequency); 286 displayBuffer.addActionListener(this); 287 displayBuffer.setAlignmentX(RIGHT_ALIGNMENT); 288 optionsPanel.add(displayBuffer); 289 290 optionsPanel.add(new JLabel (MonitorTranslate.get("options.frequency"))); 291 ffrequency = new JTextField (0); 292 ffrequency.setText("" + graphFrequency); 293 ffrequency.addActionListener(this); 294 ffrequency.setAlignmentX(RIGHT_ALIGNMENT); 295 optionsPanel.add(ffrequency); 296 297 optionsPanel.add(new JLabel (MonitorTranslate.get("options.timeframe"))); 298 ftimeframe = new JTextField (0); 299 ftimeframe.setText(graphTimeframe + ""); 300 ftimeframe.addActionListener(this); 301 ftimeframe.setAlignmentX(RIGHT_ALIGNMENT); 302 optionsPanel.add(ftimeframe); 303 304 JButton optionConfirm = new JButton (MonitorTranslate.get("options.ok")); 305 optionConfirm.setActionCommand(OPTIONS_APPLY); 306 optionConfirm.addActionListener(this); 307 optionsPanel.add(optionConfirm); 308 309 JButton optionCancel = new JButton (MonitorTranslate.get("options.cancel")); 310 optionCancel.setActionCommand(OPTIONS_CANCEL); 311 optionCancel.addActionListener(this); 312 optionsPanel.add(optionCancel); 313 314 options.getContentPane().add(optionsPanel); 315 options.setVisible(false); 316 options.setDefaultCloseOperation(HIDE_ON_CLOSE); 317 options.validate(); 318 319 validate(); 321 setVisible(true); 322 this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); 323 } 324 325 private void initConsole() throws Exception 326 { 327 this.setVisible(false); 329 BorderLayout layout = new BorderLayout (); 330 JPanel pane = new JPanel (layout); 331 if (displayController) 332 pane.add(initializeControllerBar(), BorderLayout.NORTH); 333 if (displayVirtualDatabase) 334 pane.add(initializaDatabaseBar(displayBackends), BorderLayout.CENTER); 335 jScroll = new JScrollPane (); 336 jScroll.getViewport().add(pane); 337 getContentPane().add(jScroll, BorderLayout.CENTER); 338 339 validate(); 340 this.setVisible(true); 341 } 342 343 private JLabel getHeaderLabel(String text) 344 { 345 JLabel headerLabel = new JLabel (text); 346 headerLabel.setFont(headerFont); 347 headerLabel.setAlignmentX(CENTER_ALIGNMENT); 348 return headerLabel; 349 } 350 351 private JLabel getSubHeaderLabel(String text) 352 { 353 JLabel subHeaderLabel = new JLabel (text); 354 subHeaderLabel.setFont(labelFont); 355 subHeaderLabel.setAlignmentX(CENTER_ALIGNMENT); 356 return subHeaderLabel; 357 } 358 359 private JToolBar initializeControllerBar() 360 { 361 JToolBar toolbar = new JToolBar (GRAPH_CONTROLLER, SwingConstants.VERTICAL); 362 toolbar.setOrientation(SwingConstants.VERTICAL); 363 toolbar.addMouseListener(this); 364 toolbar.add(getHeaderLabel(GRAPH_CONTROLLER)); 365 toolbar 366 .add(getGraphMenuItem(DataCollection.CONTROLLER_USED_MEMORY, "", "")); 367 toolbar.add(getGraphMenuItem(DataCollection.CONTROLLER_THREADS_NUMBER, "", 368 "")); 369 toolbar.add(getGraphMenuItem( 370 DataCollection.CONTROLLER_WORKER_PENDING_QUEUE, "", "")); 371 toolbar.add(getGraphMenuItem(DataCollection.CONTROLLER_IDLE_WORKER_THREADS, 372 "", "")); 373 toolbar.setVisible(true); 374 return toolbar; 375 } 376 377 private JToolBar initializeCacheBar(String vdb) 378 { 379 JToolBar toolbar = new JToolBar (GRAPH_CACHE, SwingConstants.VERTICAL); 380 381 try 382 { 383 if (virtualDatabaseMBean.hasResultCache() == false) 384 toolbar.setEnabled(false); 385 else 386 { 387 toolbar.add(getSubHeaderLabel(GRAPH_CACHE + " [" + vdb + "]")); 388 toolbar.add(getGraphMenuItem(DataCollection.CACHE_STATS_COUNT_HITS, 389 vdb, "")); 390 toolbar.add(getGraphMenuItem(DataCollection.CACHE_STATS_COUNT_INSERT, 391 vdb, "")); 392 toolbar.add(getGraphMenuItem(DataCollection.CACHE_STATS_COUNT_SELECT, 393 vdb, "")); 394 toolbar.add(getGraphMenuItem( 395 DataCollection.CACHE_STATS_HITS_PERCENTAGE, vdb, "")); 396 toolbar.add(getGraphMenuItem(DataCollection.CACHE_STATS_NUMBER_ENTRIES, 397 vdb, "")); 398 } 399 } 400 catch (Exception e) 401 { 402 toolbar.setEnabled(false); 403 } 404 return toolbar; 405 } 406 407 private JToolBar initializeSchedulerBar(String vdb) 408 { 409 JToolBar toolbar = new JToolBar (GRAPH_SCHEDULER, SwingConstants.VERTICAL); 410 toolbar.add(getSubHeaderLabel(GRAPH_SCHEDULER + " [" + vdb + "]")); 411 toolbar 412 .add(getGraphMenuItem(DataCollection.SCHEDULER_NUMBER_READ, vdb, "")); 413 toolbar.add(getGraphMenuItem(DataCollection.SCHEDULER_NUMBER_REQUESTS, vdb, 414 "")); 415 toolbar.add(getGraphMenuItem(DataCollection.SCHEDULER_NUMBER_WRITES, vdb, 416 "")); 417 toolbar.add(getGraphMenuItem(DataCollection.SCHEDULER_PENDING_TRANSACTIONS, 418 vdb, "")); 419 toolbar.add(getGraphMenuItem(DataCollection.SCHEDULER_PENDING_WRITES, vdb, 420 "")); 421 return toolbar; 422 } 423 424 private JToolBar initializaBackendBar(String vdb, String backendName) 425 { 426 JToolBar backendMenu = new JToolBar (GRAPH_BACKENDS, SwingConstants.VERTICAL); 427 backendMenu.add(getSubHeaderLabel(GRAPH_BACKENDS + " [" + backendName 428 + " on " + vdb + "]")); 429 backendMenu.add(getGraphMenuItem(DataCollection.BACKEND_ACTIVE_TRANSACTION, 430 vdb, backendName)); 431 backendMenu.add(getGraphMenuItem(DataCollection.BACKEND_PENDING_REQUESTS, 432 vdb, backendName)); 433 backendMenu.add(getGraphMenuItem( 434 DataCollection.BACKEND_TOTAL_ACTIVE_CONNECTIONS, vdb, backendName)); 435 backendMenu.add(getGraphMenuItem(DataCollection.BACKEND_TOTAL_REQUEST, vdb, 436 backendName)); 437 backendMenu.add(getGraphMenuItem(DataCollection.BACKEND_TOTAL_READ_REQUEST, 438 vdb, backendName)); 439 backendMenu.add(getGraphMenuItem( 440 DataCollection.BACKEND_TOTAL_WRITE_REQUEST, vdb, backendName)); 441 backendMenu.add(getGraphMenuItem(DataCollection.BACKEND_TOTAL_TRANSACTIONS, 442 vdb, backendName)); 443 return backendMenu; 444 } 445 446 private JToolBar initializaDatabaseBar(boolean dispBackends) throws Exception 447 { 448 JToolBar toolbar = new JToolBar (GRAPH_VIRTUAL_DATABASE, JToolBar.VERTICAL); 449 toolbar.addMouseListener(this); 450 451 ArrayList dbs = controllerMBean.getVirtualDatabaseNames(); 452 ArrayList backends; 453 String vdb = null; 454 for (int i = 0; i < dbs.size(); i++) 455 { 456 vdb = (String ) dbs.get(i); 457 toolbar.add(getHeaderLabel(GRAPH_VIRTUAL_DATABASE + " [" + vdb + "]")); 458 toolbar.add(getGraphMenuItem(DataCollection.DATABASES_ACTIVE_THREADS, 460 vdb, "")); 461 toolbar.add(getGraphMenuItem(DataCollection.DATABASES_NUMBER_OF_THREADS, 462 vdb, "")); 463 toolbar.add(getGraphMenuItem( 464 DataCollection.DATABASES_PENDING_CONNECTIONS, vdb, "")); 465 toolbar.add(initializeCacheBar(vdb)); 467 toolbar.add(initializeSchedulerBar(vdb)); 469 470 if (dispBackends) 471 { backends = virtualDatabaseMBean.getAllBackendNames(); 473 for (int j = 0; j < backends.size(); j++) 474 { 475 String backendName = (String ) backends.get(j); 476 toolbar.add(initializaBackendBar(vdb, backendName)); 477 } 478 } 479 } 480 return toolbar; 481 } 482 483 private JComponent getGraphMenuItem(int type, String virtualDbName, 484 String targetName) 485 { 486 String name = DataCollectionNames.get(type); 487 JComboBox item = new JComboBox (comboBoxesItems); 488 item.setFont(boxFont); 489 item.setName(name); 490 item.addActionListener(this); 491 item.addMouseListener(this); 492 if (virtualDbName == null) 493 virtualDbName = ""; 494 if (targetName == null) 495 targetName = ""; 496 String actionCommand = getBackendActionCommand(name, virtualDbName, 497 targetName); 498 actionCommand = actionCommand.trim(); 499 item.setActionCommand(actionCommand); 500 item.setVisible(true); 501 BorderLayout layout = new BorderLayout (); 502 JPanel panel = new JPanel (layout); 503 JLabel nameLabel = new JLabel (name); 504 nameLabel.setAlignmentX(CENTER_ALIGNMENT); 505 nameLabel.setFont(labelFont); 506 panel.add(nameLabel, BorderLayout.WEST); 507 panel.add(item, BorderLayout.EAST); 508 509 comboBoxes.put(actionCommand, item); 510 return panel; 511 } 512 513 521 public static String getBackendActionCommand(String typeName, String vdbName, 522 String backendName) 523 { 524 return "graph " + typeName.toLowerCase().replace(' ', '_') + " " + vdbName 525 + " " + backendName; 526 } 527 528 531 public void mouseClicked(MouseEvent e) 532 { 533 status(e.getComponent().getName() + " was clicked"); 534 } 535 536 539 public void mouseEntered(MouseEvent e) 540 { 541 542 } 543 544 547 public void mouseExited(MouseEvent e) 548 { 549 550 } 551 552 555 public void mousePressed(MouseEvent e) 556 { 557 558 } 559 560 563 public void mouseReleased(MouseEvent e) 564 { 565 566 } 567 568 private void doSaveConfiguration() throws IOException 569 { 570 Iterator iter = comboBoxes.keySet().iterator(); 571 File f = new File ("monitor.properties"); 572 BufferedOutputStream bof = new BufferedOutputStream (new FileOutputStream (f)); 573 String temp; 574 while (iter.hasNext()) 575 { 576 Object o = iter.next(); 577 String key = o.toString().trim().replace(' ', '.'); 578 JComboBox box = (JComboBox ) comboBoxes.get(o); 579 temp = (key + "=" + box.getSelectedItem()) 580 + System.getProperty("line.separator"); 581 bof.write(temp.getBytes()); 582 } 583 584 Iterator iter2 = windows.keySet().iterator(); 585 Window win; 586 Point p; 587 String name, winX, winY; 588 while (iter2.hasNext()) 589 { 590 win = ((Window ) windows.get(iter2.next())); 591 p = win.getLocation(); 592 name = win.getName().trim().replace(' ', '.'); 593 winX = name + ".X=" + (int) p.getX() 594 + System.getProperty("line.separator"); 595 winY = name + ".Y=" + (int) p.getY() 596 + System.getProperty("line.separator"); 597 bof.write(winX.getBytes()); 598 bof.write(winY.getBytes()); 599 } 600 bof.write(("options.repeat=" + graphRepeat + System 601 .getProperty("line.separator")).getBytes()); 602 bof.write(("options.timeframe=" + graphTimeframe + System 603 .getProperty("line.separator")).getBytes()); 604 bof.write(("options.frequency=" + graphFrequency + System 605 .getProperty("line.separator")).getBytes()); 606 bof.write(("options.displayfrequency=" + graphDisplayFrequency + System 607 .getProperty("line.separator")).getBytes()); 608 609 bof.flush(); 610 bof.close(); 611 } 612 613 private void doLoadConfiguration() throws IOException 614 { 615 closeAllWindows(); 616 isLoading = true; 617 File f = new File ("monitor.properties"); 618 PropertyResourceBundle props = new PropertyResourceBundle ( 619 new FileInputStream (f)); 620 Enumeration enume = props.getKeys(); 621 String key = "", keyr = "", value = ""; 622 JFrame frame; 623 624 try 625 { 626 graphRepeat = Integer 627 .parseInt((String ) props.getObject("options.repeat")); 628 frepeat.setText("" + graphRepeat); 629 graphFrequency = Integer.parseInt((String ) props 630 .getObject("options.frequency")); 631 ffrequency.setText("" + graphFrequency); 632 graphTimeframe = Integer.parseInt((String ) props 633 .getObject("options.timeframe")); 634 ftimeframe.setText("" + graphTimeframe); 635 graphDisplayFrequency = Integer.parseInt((String ) props 636 .getObject("options.displayfrequency")); 637 displayBuffer.setText("" + graphDisplayFrequency); 638 } 639 catch (Exception e) 640 { 641 error(e.getMessage()); 642 } 643 644 while (enume.hasMoreElements()) 645 { 646 key = (String ) enume.nextElement(); 647 value = (String ) props.getObject(key); 648 if (key.startsWith("options")) 649 { 650 } 652 else if (key.endsWith(".X") || key.endsWith(".Y")) 653 { 654 } 656 else 657 { 658 if (value.equals(COMBO_FLOATING)) 659 try 660 { 661 frame = graph(key); 662 keyr = key.trim().replace('.', ' '); 663 JComboBox box = (JComboBox ) comboBoxes.get(keyr); 665 if (box != null) 666 box.setSelectedItem(COMBO_FLOATING); 667 try 668 { 669 int x = Integer.parseInt((String ) props.getObject(key + ".X")); 670 int y = Integer.parseInt((String ) props.getObject(key + ".Y")); 671 672 frame.setLocation(x, y); 675 } 679 catch (Exception e) 680 { 681 error(e.getMessage()); 683 } 684 } 685 catch (Exception e) 686 { 687 } 689 } 690 } 691 isLoading = false; 692 } 693 694 697 public void actionPerformed(ActionEvent e) 698 { 699 if (isLoading) 700 return; 701 String actionCommand = e.getActionCommand(); 702 status("Action:" + actionCommand); 703 if (actionCommand.equals(COMMAND_SAVE)) 704 { 705 try 706 { 707 doSaveConfiguration(); 708 } 709 catch (IOException e1) 710 { 711 e1.printStackTrace(); 719 } 720 } 721 else if (actionCommand.equals(COMMAND_LOAD)) 722 { 723 try 724 { 725 doLoadConfiguration(); 726 } 727 catch (IOException e1) 728 { 729 e1.printStackTrace(); 731 } 732 } 733 else if (actionCommand.equals(OPTIONS_APPLY)) 734 { 735 736 try 737 { 738 graphRepeat = Integer.parseInt(frepeat.getText()); 739 graphTimeframe = Integer.parseInt(ftimeframe.getText()); 740 graphFrequency = Integer.parseInt(ffrequency.getText()); 741 graphDisplayFrequency = Integer.parseInt(displayBuffer.getText()); 742 options.setVisible(false); 743 } 744 catch (Exception failed) 745 { 746 error(failed.getMessage()); 747 } 748 } 749 else if (actionCommand.equals(OPTIONS_CANCEL)) 750 { 751 options.setVisible(false); 752 frepeat.setText(graphRepeat + ""); 753 ftimeframe.setText(graphTimeframe + ""); 754 ffrequency.setText(graphFrequency + ""); 755 } 756 else if (actionCommand.equals(COMMAND_REFRESH)) 757 { 758 try 759 { 760 initConsole(); 761 } 762 catch (Exception error) 763 { 764 error(error.getMessage()); 765 } 766 } 767 else if (actionCommand.equals(COMMAND_OPTIONS)) 768 { 769 options.setVisible(true); 770 } 771 else if (actionCommand.equals(COMMAND_CLOSE)) 772 { 773 closeAllWindows(); 774 this.dispose(); 775 } 776 else if (actionCommand.equals(COMMAND_CLOSE_GRAPHS)) 777 { 778 closeAllWindows(); 779 } 780 Object o = e.getSource(); 781 if (o instanceof JComboBox ) 782 { 783 JComboBox box = (JComboBox ) o; 784 String selected = (String ) box.getSelectedItem(); 785 status(selected.toString()); 786 try 787 { 788 Window win = (Window ) windows.get(e.getActionCommand().trim()); 789 if (!selected.equals(COMBO_HIDE)) 790 { 791 if (win == null) 792 { 793 graph(e.getActionCommand()); 794 } 795 } 796 else 797 { 798 windows.remove(win.getName()); 799 win.setVisible(false); 800 win.dispose(); 801 } 802 } 803 catch (Exception f) 804 { 805 error(f.getMessage()); 806 } 807 } 808 809 } 810 811 private void closeAllWindows() 812 { 813 while (true) 814 { 815 try 816 { 817 Iterator iter = windows.keySet().iterator(); 818 while (iter.hasNext()) 819 { 820 Window win = ((Window ) windows.get(iter.next())); 821 JComboBox box = (JComboBox ) comboBoxes.get(win.getName()); 822 if (box != null) 823 box.setSelectedItem(COMBO_HIDE); 824 } 825 break; 826 } 827 catch (RuntimeException e) 828 { 829 continue; 831 } 832 } 833 } 834 835 private void status(String message) 836 { 837 label.setBackground(Color.white); 838 label.setText(message); 839 } 840 841 private void error(String message) 842 { 843 label.setBackground(Color.red); 844 label.setText(message); 845 } 846 847 853 private JFrame graph(String command) throws DataCollectorException 854 { 855 856 return graph(command, dataCollectorMBean, graphRepeat, graphTimeframe, 857 graphFrequency, graphDisplayFrequency, this); 858 } 859 860 873 public static final JFrame graph(String command, 874 DataCollectorMBean dataCollectorMBean, int graphRepeat, 875 int graphTimeframe, int graphFrequency, int graphDisplayFrequency, 876 WindowListener listener) throws DataCollectorException 877 { 878 command = command.replace('.', ' '); 880 881 StringTokenizer tokenizer = new StringTokenizer (command, " "); 882 String token0 = tokenizer.nextToken(); 883 if (token0.equals("graph")) 884 { 885 String token1 = tokenizer.nextToken(); 886 int type = DataCollectionNames.getTypeFromCommand(token1); 887 String token2 = (tokenizer.hasMoreTokens()) ? tokenizer.nextToken() : ""; 888 String token3 = (tokenizer.hasMoreTokens()) ? tokenizer.nextToken() : ""; 889 AbstractDataCollector collector = dataCollectorMBean 890 .retrieveDataCollectorInstance(type, token3, token2); 891 MonitoringGraph graph = new MonitoringGraph(collector, dataCollectorMBean); 892 graph.setRepeat(graphRepeat); 893 graph.setTimeFrame(graphTimeframe); 894 graph.setFrequency(graphFrequency); 895 graph.setDisplayFrequency(graphDisplayFrequency); 896 graph.start(); 897 graph.setText(command); 898 if (listener != null) 900 graph.getFrame().addWindowListener(listener); 901 graph.getFrame().setName(command.trim()); 902 return graph.getFrame(); 903 } 904 else 905 { 906 return null; 907 } 908 } 909 910 913 public void windowActivated(WindowEvent e) 914 { 915 916 } 917 918 921 public void windowClosed(WindowEvent e) 922 { 923 924 } 925 926 929 public void windowClosing(WindowEvent e) 930 { 931 Window win = e.getWindow(); 932 JComboBox box = (JComboBox ) comboBoxes.get(win.getName()); 933 windows.remove(win.getName()); 934 if (box != null) 935 box.setSelectedIndex(0); 936 status(win.getName() + " is closing"); 937 } 938 939 942 public void windowDeactivated(WindowEvent e) 943 { 944 945 } 946 947 950 public void windowDeiconified(WindowEvent e) 951 { 952 953 } 954 955 958 public void windowIconified(WindowEvent e) 959 { 960 961 } 962 963 966 public void windowOpened(WindowEvent e) 967 { 968 Window win = e.getWindow(); 969 status(win.getName() + " has opened"); 970 windows.put(win.getName(), e.getWindow()); 971 } 972 } | Popular Tags |