1 24 package org.objectweb.clif.console.lib.gui; 25 26 import java.awt.*; 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import java.awt.event.ComponentListener ; 30 import java.awt.event.ComponentEvent ; 31 import java.awt.event.ContainerListener ; 32 import java.awt.event.ContainerEvent ; 33 import java.util.Map ; 34 import java.util.Iterator ; 35 import javax.swing.JButton ; 36 import javax.swing.JComboBox ; 37 import javax.swing.JLabel ; 38 import javax.swing.JPanel ; 39 import javax.swing.JScrollPane ; 40 import javax.swing.JSplitPane ; 41 import javax.swing.JTable ; 42 import javax.swing.JTextField ; 43 import javax.swing.Timer ; 44 import javax.swing.event.TableModelEvent ; 45 import javax.swing.event.TableModelListener ; 46 import org.objectweb.clif.supervisor.api.TestControl; 47 import org.objectweb.clif.datacollector.lib.InjectorDataCollector; 48 49 54 public class GuiPanelBothMonitor 55 extends JPanel 56 implements ActionListener , ComponentListener , ContainerListener , TableModelListener 57 { 58 private JTextField intervalField = new JTextField ("1", 4); 59 private JTextField timeframeField = new JTextField (4); 60 61 private JButton refreshButton = new JButton ("Set/Draw"); 62 private JButton stopButton = new JButton ("Stop"); 63 private JButton resetButton = new JButton ("Reset"); 64 65 private JPanel panelInjectors = new JPanel (); 66 private JPanel panelHosts = new JPanel (); 67 private JPanel panelGraph = new JPanel (); 68 private JPanel panelControl = new JPanel (); 69 private JPanel panelTop = new JPanel (); 70 private JPanel panelMain = new JPanel (); 71 72 private JComboBox viewComboInjectors = null; 73 74 private ActionTestReport updateTestReport = null; 75 private Timer testReportTimer = null; 76 77 private String [] cname = { "Display", "Collect", "Blade" }; 78 79 private GraphTableModel tModelInjectors = new GraphTableModel(cname); 80 private JTable tableInjectors = new JTable (tModelInjectors); 81 82 private JScrollPane scrollPaneInjectors = new JScrollPane (tableInjectors); 83 84 private Graph graphTestReport = null; 85 86 private GridBagLayout gb = new GridBagLayout(); 87 private GridBagConstraints c = new GridBagConstraints(); 88 89 private JSplitPane splitPane = null; 90 91 private GraphCellRenderer cellRendererInjector; 92 93 private int lastNbPoints; 94 private int nbPoints; 95 private int interval; 96 97 101 public GuiPanelBothMonitor(Map testPlan, TestControl testCtrl) 102 { 103 tModelInjectors.setId(1); 104 105 tModelInjectors.addTableModelListener(this); 106 this.setBackground(Color.white); 107 this.setLayout(new GridLayout(1, 1)); 108 String arbitraryBladeId = (String )testPlan.keySet().iterator().next(); 109 graphTestReport = new Graph(new String [0], InjectorDataCollector.LABELS.length, true); 110 createInjectorsPanel(testCtrl, arbitraryBladeId); 111 createHostsPanel(); 112 createGraphPanel(); 113 createTopPanel(); 114 createControlPanel(); 115 createMainPanel(); 116 117 Iterator iter = testPlan.keySet().iterator(); 118 while (iter.hasNext()) 119 { 120 String name = (String )iter.next(); 121 graphTestReport.addInjector(name); 122 cellRendererInjector = 123 new GraphCellRenderer(graphTestReport.allHosts); 124 tableInjectors.getColumnModel().getColumn(2).setCellRenderer( 125 cellRendererInjector); 126 tModelInjectors.addInjector(name); 127 } 128 add(panelMain); 129 addComponentListener(this); 130 updateTestReport = 132 new ActionTestReport(testCtrl, graphTestReport, tModelInjectors); 133 } 134 135 139 private void createInjectorsPanel(TestControl testCtl, String bladeId) 140 { 141 String [] comboElements = testCtl.getStatLabels(bladeId); 142 viewComboInjectors = new JComboBox (comboElements); 143 viewComboInjectors.setSelectedIndex(0); 144 graphTestReport.setView(viewComboInjectors.getSelectedIndex()); 145 146 panelInjectors.setLayout(gb); 147 148 c.gridx = 0; 149 c.gridy = 0; 150 c.gridheight = 1; 151 c.gridwidth = 1; 152 c.weightx = 100; 153 c.weighty = 100; 154 c.fill = GridBagConstraints.BOTH; 155 c.anchor = GridBagConstraints.NORTH; 156 157 scrollPaneInjectors.setSize(100, 50); 158 panelInjectors.add(scrollPaneInjectors, c); 159 160 c.gridx = 0; 161 c.gridy = 1; 162 c.gridheight = 1; 163 c.gridwidth = 1; 164 c.weightx = 100; 165 c.weighty = 0; 166 c.fill = GridBagConstraints.NONE; 167 c.anchor = GridBagConstraints.WEST; 168 169 viewComboInjectors.addActionListener(this); 170 panelInjectors.add(viewComboInjectors, c); 171 } 172 173 174 178 private void createHostsPanel() { 179 panelHosts.setLayout(gb); 180 181 c.gridx = 0; 182 c.gridy = 0; 183 c.gridheight = 1; 184 c.gridwidth = 1; 185 c.weightx = 100; 186 c.weighty = 100; 187 c.fill = GridBagConstraints.BOTH; 188 c.anchor = GridBagConstraints.NORTH; 189 panelHosts.add(panelInjectors, c); 190 } 191 192 195 private void createControlPanel() { 196 panelControl.setLayout(gb); 197 198 c.gridheight = 1; 200 c.gridwidth = 1; 201 c.weightx = 100; 202 c.weighty = 100; 203 c.gridy = 0; 204 205 c.gridx = 0; 207 c.fill = GridBagConstraints.NONE; 208 c.anchor = GridBagConstraints.EAST; 209 panelControl.add(new JLabel ("Drawing timeframe:"), c); 210 211 c.gridx = 1; 212 c.fill = GridBagConstraints.HORIZONTAL; 213 panelControl.add(timeframeField, c); 214 215 c.gridx = 2; 216 c.fill = GridBagConstraints.NONE; 217 c.anchor = GridBagConstraints.WEST; 218 panelControl.add(new JLabel ("sec."), c); 219 220 c.gridx = 3; 222 c.fill = GridBagConstraints.NONE; 223 c.anchor = GridBagConstraints.EAST; 224 panelControl.add(new JLabel ("Polling period:"), c); 225 226 c.gridx = 4; 227 c.fill = GridBagConstraints.HORIZONTAL; 228 panelControl.add(intervalField, c); 229 230 c.gridx = 5; 231 c.fill = GridBagConstraints.NONE; 232 c.anchor = GridBagConstraints.WEST; 233 panelControl.add(new JLabel ("sec."), c); 234 235 c.fill = GridBagConstraints.NONE; 237 c.anchor = GridBagConstraints.CENTER; 238 239 c.gridx = 6; 241 refreshButton.setActionCommand("REFRESH"); 242 refreshButton.addActionListener(this); 243 panelControl.add(refreshButton, c); 244 245 c.gridx = 7; 247 stopButton.setActionCommand("STOP"); 248 stopButton.addActionListener(this); 249 stopButton.setEnabled(false); 250 panelControl.add(stopButton, c); 251 252 c.gridx = 8; 254 resetButton.setActionCommand("RESET"); 255 resetButton.addActionListener(this); 256 panelControl.add(resetButton, c); 257 } 258 259 262 private void createTopPanel() { 263 panelTop.setLayout(gb); 264 265 splitPane = 266 new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, panelHosts, panelGraph); 267 splitPane.setDividerLocation(panelHosts.getMinimumSize().width); 268 splitPane.setOneTouchExpandable(true); 269 270 c.gridx = 0; 271 c.gridy = 0; 272 c.gridheight = 1; 273 c.gridwidth = 1; 274 c.weightx = 100; 275 c.weighty = 100; 276 c.fill = GridBagConstraints.BOTH; 277 c.anchor = GridBagConstraints.NORTH; 278 panelTop.add(splitPane, c); 279 } 280 281 285 private void createGraphPanel() { 286 panelGraph.setLayout(gb); 287 288 c.gridx = 0; 289 c.gridy = 0; 290 c.gridheight = 1; 291 c.gridwidth = 1; 292 c.weightx = 100; 293 c.weighty = 100; 294 c.fill = GridBagConstraints.BOTH; 295 c.anchor = GridBagConstraints.NORTH; 296 panelGraph.add(graphTestReport, c); 297 } 298 299 302 private void createMainPanel() { 303 panelMain.setLayout(gb); 304 305 c.gridx = 0; 306 c.gridy = 0; 307 c.gridheight = 1; 308 c.gridwidth = 1; 309 c.weightx = 100; 310 c.weighty = 100; 311 c.fill = GridBagConstraints.BOTH; 312 c.anchor = GridBagConstraints.NORTH; 313 panelMain.add(panelTop, c); 314 315 c.gridx = 0; 316 c.gridy = 1; 317 c.gridheight = 1; 318 c.gridwidth = 1; 319 c.weightx = 100; 320 c.weighty = 0; 321 c.fill = GridBagConstraints.HORIZONTAL; 322 c.anchor = GridBagConstraints.CENTER; 323 panelMain.add(panelControl, c); 324 } 325 326 327 331 332 public void componentHidden(ComponentEvent e) 333 { 334 } 335 336 337 public void componentMoved(ComponentEvent e) 338 { 339 } 340 341 342 public void componentResized(ComponentEvent e) 343 { 344 if (timeframeField.getText().length() == 0) 345 { 346 timeframeField.setText(String.valueOf(graphTestReport.getGraphAreaWidth())); 347 } 348 } 349 350 351 public void componentShown(ComponentEvent e) 352 { 353 } 354 355 356 360 361 public void componentAdded(ContainerEvent ev) 362 { 363 } 364 365 366 public void componentRemoved(ContainerEvent ev) 367 { 368 if (ev.getChild() == this && testReportTimer != null) 369 { 370 testReportTimer.removeActionListener(updateTestReport); 371 testReportTimer.stop(); 372 } 373 } 374 375 376 380 385 public void actionPerformed(ActionEvent e) 386 { 387 Object source = e.getSource(); 388 if (source == this.refreshButton) { 390 resetButton.setEnabled(false); 391 try 392 { 393 interval = Integer.parseInt(intervalField.getText()); 394 nbPoints = 1 + Integer.parseInt(timeframeField.getText()) / interval; 395 if (nbPoints != lastNbPoints) 396 { 397 lastNbPoints = nbPoints; 398 graphTestReport.setNbPoints(lastNbPoints); 399 } 400 updateTestReport.setTime(interval); 402 if (testReportTimer == null) 403 { 404 testReportTimer = new Timer (interval * 1000, updateTestReport); 405 } 406 else 407 { 408 testReportTimer.stop(); 409 testReportTimer.setDelay(interval * 1000); 410 } 411 testReportTimer.start(); 412 stopButton.setEnabled(true); 413 } 414 catch (Exception ex) 415 { 416 System.err.println("unexpected non-integer values in period fields"); 417 } 418 } 419 else if (source == this.stopButton) { 421 if (testReportTimer != null) 422 { 423 testReportTimer.stop(); 424 } 425 stopButton.setEnabled(false); 426 resetButton.setEnabled(true); 427 } 428 else if (source == this.resetButton) { 430 updateTestReport.reset(); 431 graphTestReport.setView(viewComboInjectors.getSelectedIndex()); 432 graphTestReport.clear(); 433 } 434 else if (source == this.viewComboInjectors) { 436 graphTestReport.setView(viewComboInjectors.getSelectedIndex()); 438 graphTestReport.removeAllPointsFromDisplay( 439 tModelInjectors.getInjectorsToDisplay()); 440 graphTestReport.addAllPointsOnDisplay( 441 tModelInjectors.getInjectorsToDisplay()); 442 graphTestReport.updateGraph(); 443 } 444 } 445 446 447 451 452 457 public void tableChanged(TableModelEvent e) { 458 459 if (e.getType() == TableModelEvent.UPDATE) { 461 int row = e.getFirstRow(); 462 int column = e.getColumn(); 463 Boolean data; 464 465 if (((GraphTableModel) e.getSource()).getId() == 1) { 467 data = (Boolean ) tModelInjectors.getValueAt(row, column); 469 if (column == 0) { 471 474 if (data.booleanValue()) { 475 graphTestReport.addPointsOnDisplay( 476 (String ) tModelInjectors.getValueAt( 477 row, 478 column + 2)); 479 graphTestReport.updateGraph(); 480 } else { 481 graphTestReport.removePointsFromDisplay( 482 (String ) tModelInjectors.getValueAt( 483 row, 484 column + 2)); 485 graphTestReport.updateGraph(); 486 } 487 } 488 } 489 } 490 } 491 } | Popular Tags |