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 48 53 public class GuiMonitorCard 54 extends JPanel 55 implements ActionListener , ComponentListener , ContainerListener , TableModelListener 56 { 57 private JTextField intervalField = new JTextField ("1", 4); 58 private JTextField timeframeField = new JTextField (4); 59 60 private JButton refreshButton = new JButton ("Set/Draw"); 61 private JButton stopButton = new JButton ("Stop"); 62 private JButton resetButton = new JButton ("Reset"); 63 64 private JPanel panelInjectors = new JPanel (); 65 private JPanel panelHosts = new JPanel (); 66 private JPanel panelGraph = new JPanel (); 67 private JPanel panelControl = new JPanel (); 68 private JPanel panelTop = new JPanel (); 69 private JPanel panelMain = new JPanel (); 70 71 private JComboBox viewComboInjectors = null; 72 73 private ActionTestReport updateTestReport = null; 74 private Timer testReportTimer = null; 75 76 private String [] cname = { "Display", "Collect", "Blade" }; 77 78 private GraphTableModel tModelInjectors = new GraphTableModel(cname); 79 private JTable tableInjectors = new JTable (tModelInjectors); 80 81 private JScrollPane scrollPaneInjectors = new JScrollPane (tableInjectors); 82 83 private Graph graphTestReport = null; 84 85 private GridBagLayout gb = new GridBagLayout(); 86 private GridBagConstraints c = new GridBagConstraints(); 87 88 private JSplitPane splitPane = null; 89 90 private GraphCellRenderer cellRendererInjector; 91 92 private int lastNbPoints; 93 private int nbPoints; 94 private int interval; 95 96 100 public GuiMonitorCard(Map testPlan, String [] statLabels, TestControl testCtrl) 101 { 102 tModelInjectors.setId(1); 103 104 tModelInjectors.addTableModelListener(this); 105 this.setBackground(Color.white); 106 this.setLayout(new GridLayout(1, 1)); 107 graphTestReport = new Graph(new String [0], statLabels.length, true); 108 createInjectorsPanel(statLabels); 109 createHostsPanel(); 110 createGraphPanel(); 111 createTopPanel(); 112 createControlPanel(); 113 createMainPanel(); 114 115 Iterator iter = testPlan.keySet().iterator(); 116 while (iter.hasNext()) 117 { 118 String name = (String )iter.next(); 119 graphTestReport.addInjector(name); 120 cellRendererInjector = 121 new GraphCellRenderer(graphTestReport.allHosts); 122 tableInjectors.getColumnModel().getColumn(2).setCellRenderer( 123 cellRendererInjector); 124 tModelInjectors.addInjector(name); 125 } 126 add(panelMain); 127 addComponentListener(this); 128 updateTestReport = 130 new ActionTestReport(testCtrl, graphTestReport, tModelInjectors); 131 } 132 133 137 private void createInjectorsPanel(String [] statLabels) 138 { 139 viewComboInjectors = new JComboBox (statLabels); 140 viewComboInjectors.setSelectedIndex(0); 141 graphTestReport.setView(viewComboInjectors.getSelectedIndex()); 142 143 panelInjectors.setLayout(gb); 144 145 c.gridx = 0; 146 c.gridy = 0; 147 c.gridheight = 1; 148 c.gridwidth = 1; 149 c.weightx = 100; 150 c.weighty = 100; 151 c.fill = GridBagConstraints.BOTH; 152 c.anchor = GridBagConstraints.NORTH; 153 154 scrollPaneInjectors.setSize(100, 50); 155 panelInjectors.add(scrollPaneInjectors, c); 156 157 c.gridx = 0; 158 c.gridy = 1; 159 c.gridheight = 1; 160 c.gridwidth = 1; 161 c.weightx = 100; 162 c.weighty = 0; 163 c.fill = GridBagConstraints.NONE; 164 c.anchor = GridBagConstraints.WEST; 165 166 viewComboInjectors.addActionListener(this); 167 panelInjectors.add(viewComboInjectors, c); 168 } 169 170 171 175 private void createHostsPanel() { 176 panelHosts.setLayout(gb); 177 178 c.gridx = 0; 179 c.gridy = 0; 180 c.gridheight = 1; 181 c.gridwidth = 1; 182 c.weightx = 100; 183 c.weighty = 100; 184 c.fill = GridBagConstraints.BOTH; 185 c.anchor = GridBagConstraints.NORTH; 186 panelHosts.add(panelInjectors, c); 187 } 188 189 192 private void createControlPanel() { 193 panelControl.setLayout(gb); 194 195 c.gridheight = 1; 197 c.gridwidth = 1; 198 c.weightx = 100; 199 c.weighty = 100; 200 c.gridy = 0; 201 202 c.gridx = 0; 204 c.fill = GridBagConstraints.NONE; 205 c.anchor = GridBagConstraints.EAST; 206 panelControl.add(new JLabel ("Drawing timeframe:"), c); 207 208 c.gridx = 1; 209 c.fill = GridBagConstraints.HORIZONTAL; 210 panelControl.add(timeframeField, c); 211 212 c.gridx = 2; 213 c.fill = GridBagConstraints.NONE; 214 c.anchor = GridBagConstraints.WEST; 215 panelControl.add(new JLabel ("sec."), c); 216 217 c.gridx = 3; 219 c.fill = GridBagConstraints.NONE; 220 c.anchor = GridBagConstraints.EAST; 221 panelControl.add(new JLabel ("Polling period:"), c); 222 223 c.gridx = 4; 224 c.fill = GridBagConstraints.HORIZONTAL; 225 panelControl.add(intervalField, c); 226 227 c.gridx = 5; 228 c.fill = GridBagConstraints.NONE; 229 c.anchor = GridBagConstraints.WEST; 230 panelControl.add(new JLabel ("sec."), c); 231 232 c.fill = GridBagConstraints.NONE; 234 c.anchor = GridBagConstraints.CENTER; 235 236 c.gridx = 6; 238 refreshButton.addActionListener(this); 239 panelControl.add(refreshButton, c); 240 241 c.gridx = 7; 243 stopButton.addActionListener(this); 244 stopButton.setEnabled(false); 245 panelControl.add(stopButton, c); 246 247 c.gridx = 8; 249 resetButton.addActionListener(this); 250 panelControl.add(resetButton, c); 251 } 252 253 256 private void createTopPanel() { 257 panelTop.setLayout(gb); 258 259 splitPane = 260 new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, panelHosts, panelGraph); 261 splitPane.setDividerLocation(panelHosts.getMinimumSize().width); 262 splitPane.setOneTouchExpandable(true); 263 264 c.gridx = 0; 265 c.gridy = 0; 266 c.gridheight = 1; 267 c.gridwidth = 1; 268 c.weightx = 100; 269 c.weighty = 100; 270 c.fill = GridBagConstraints.BOTH; 271 c.anchor = GridBagConstraints.NORTH; 272 panelTop.add(splitPane, c); 273 } 274 275 279 private void createGraphPanel() { 280 panelGraph.setLayout(gb); 281 282 c.gridx = 0; 283 c.gridy = 0; 284 c.gridheight = 1; 285 c.gridwidth = 1; 286 c.weightx = 100; 287 c.weighty = 100; 288 c.fill = GridBagConstraints.BOTH; 289 c.anchor = GridBagConstraints.NORTH; 290 panelGraph.add(graphTestReport, c); 291 } 292 293 296 private void createMainPanel() { 297 panelMain.setLayout(gb); 298 299 c.gridx = 0; 300 c.gridy = 0; 301 c.gridheight = 1; 302 c.gridwidth = 1; 303 c.weightx = 100; 304 c.weighty = 100; 305 c.fill = GridBagConstraints.BOTH; 306 c.anchor = GridBagConstraints.NORTH; 307 panelMain.add(panelTop, c); 308 309 c.gridx = 0; 310 c.gridy = 1; 311 c.gridheight = 1; 312 c.gridwidth = 1; 313 c.weightx = 100; 314 c.weighty = 0; 315 c.fill = GridBagConstraints.HORIZONTAL; 316 c.anchor = GridBagConstraints.CENTER; 317 panelMain.add(panelControl, c); 318 } 319 320 321 325 326 public void componentHidden(ComponentEvent e) 327 { 328 } 329 330 331 public void componentMoved(ComponentEvent e) 332 { 333 } 334 335 336 public void componentResized(ComponentEvent e) 337 { 338 if (timeframeField.getText().length() == 0 && graphTestReport.getGraphAreaWidth() > 0) 339 { 340 timeframeField.setText(String.valueOf(graphTestReport.getGraphAreaWidth())); 341 } 342 } 343 344 345 public void componentShown(ComponentEvent e) 346 { 347 componentResized(e); 348 } 349 350 351 355 356 public void componentAdded(ContainerEvent ev) 357 { 358 } 359 360 361 public void componentRemoved(ContainerEvent ev) 362 { 363 if (ev.getChild() == this && testReportTimer != null) 364 { 365 testReportTimer.removeActionListener(updateTestReport); 366 testReportTimer.stop(); 367 } 368 } 369 370 371 375 380 public void actionPerformed(ActionEvent e) 381 { 382 Object source = e.getSource(); 383 if (source == this.refreshButton) { 385 resetButton.setEnabled(false); 386 try 387 { 388 interval = Integer.parseInt(intervalField.getText()); 389 nbPoints = 1 + Integer.parseInt(timeframeField.getText()) / interval; 390 if (nbPoints != lastNbPoints) 391 { 392 lastNbPoints = nbPoints; 393 graphTestReport.setNbPoints(lastNbPoints); 394 } 395 updateTestReport.setTime(interval); 397 if (testReportTimer == null) 398 { 399 testReportTimer = new Timer (interval * 1000, updateTestReport); 400 } 401 else 402 { 403 testReportTimer.stop(); 404 testReportTimer.setDelay(interval * 1000); 405 } 406 testReportTimer.start(); 407 stopButton.setEnabled(true); 408 } 409 catch (Exception ex) 410 { 411 System.err.println("unexpected non-integer values in period fields"); 412 } 413 } 414 else if (source == this.stopButton) { 416 if (testReportTimer != null) 417 { 418 testReportTimer.stop(); 419 } 420 stopButton.setEnabled(false); 421 resetButton.setEnabled(true); 422 } 423 else if (source == this.resetButton) { 425 updateTestReport.reset(); 426 graphTestReport.setView(viewComboInjectors.getSelectedIndex()); 427 graphTestReport.clear(); 428 } 429 else if (source == this.viewComboInjectors) { 431 graphTestReport.setView(viewComboInjectors.getSelectedIndex()); 433 graphTestReport.removeAllPointsFromDisplay( 434 tModelInjectors.getInjectorsToDisplay()); 435 graphTestReport.addAllPointsOnDisplay( 436 tModelInjectors.getInjectorsToDisplay()); 437 graphTestReport.updateGraph(); 438 } 439 } 440 441 442 446 447 452 public void tableChanged(TableModelEvent e) { 453 454 if (e.getType() == TableModelEvent.UPDATE) { 456 int row = e.getFirstRow(); 457 int column = e.getColumn(); 458 Boolean data; 459 460 if (((GraphTableModel) e.getSource()).getId() == 1) { 462 data = (Boolean ) tModelInjectors.getValueAt(row, column); 464 if (column == 0) { 466 469 if (data.booleanValue()) { 470 graphTestReport.addPointsOnDisplay( 471 (String ) tModelInjectors.getValueAt( 472 row, 473 column + 2)); 474 graphTestReport.updateGraph(); 475 } else { 476 graphTestReport.removePointsFromDisplay( 477 (String ) tModelInjectors.getValueAt( 478 row, 479 column + 2)); 480 graphTestReport.updateGraph(); 481 } 482 } 483 } 484 } 485 } 486 } | Popular Tags |