1 6 7 package org.coach.tracing.server.viewer; 8 9 import java.io.*; 10 import java.awt.*; 11 import java.awt.event.*; 12 import javax.swing.*; 13 import java.util.*; 14 import java.lang.reflect.*; 15 import java.awt.print.*; 16 import org.coach.tracing.server.EventDataBase; 17 import org.coach.tracing.server.EventRecord; 18 19 23 public class TraceViewerFrame extends javax.swing.JFrame { 24 static ScaleManager scaleManager = ScaleManager.getScaleManager(); 25 Diagram diagramPanel; 26 private long prevStart = -1; 27 private LinkedList browsers = new LinkedList(); 28 private ActionListener updateAction; 29 private javax.swing.Timer updateTimer; 30 private long eventCount = 0; 31 private EventDataBase eventDB; 32 33 34 public TraceViewerFrame() { 35 diagramPanel = new Diagram(this); 36 initComponents(); 37 } 38 39 public void setEventDB(EventDataBase db) { 40 eventDB = db; 41 diagramPanel.setEventDB(eventDB); 42 IdentityNode.setEventDB(eventDB); 43 ThreadNode.clear(); 44 EventRecord.setEventDB(eventDB); 45 int units = (int)(scaleManager.getScale() * Diagram.space_between); 46 int range = getHeight() / units; 47 diagramPanel.setRange(range); 48 updateAction = new ActionListener() { 49 public void actionPerformed(ActionEvent evt) { 50 long newEventCount = eventDB.getEventCount(); 51 if (newEventCount != eventCount) { 52 eventCount = newEventCount; 53 diagramPanel.updateStatus(eventCount); 54 diagramPanel.repaintEvents(); 55 } 56 } 57 }; 58 updateTimer = new javax.swing.Timer (1000, updateAction); 59 updateTimer.start(); 60 } 61 62 67 private void initComponents() { viewModebuttonGroup = new javax.swing.ButtonGroup (); 69 statusPanel = new javax.swing.JPanel (); 70 eventsLabel = new javax.swing.JLabel (); 71 eventsTextField = new javax.swing.JTextField (); 72 messagesLabel = new javax.swing.JLabel (); 73 messagesTextField = new javax.swing.JTextField (); 74 unmatchedEventsLabel = new javax.swing.JLabel (); 75 unmatchedEventsTextField = new javax.swing.JTextField (); 76 buttonPanel = new javax.swing.JPanel (); 77 clearButton = new javax.swing.JButton (); 78 uncolorButton = new javax.swing.JButton (); 79 trailLabelButton = new javax.swing.JButton (); 80 zoomInButton = new javax.swing.JButton (); 81 zoomOutButton = new javax.swing.JButton (); 82 unhideButton = new javax.swing.JButton (); 83 identitiesButton = new javax.swing.JButton (); 84 diagramMainPanel = new javax.swing.JPanel (); 85 diagramVerticalScrollBar = new javax.swing.JScrollBar (); 86 diagramScrollPanel = new javax.swing.JScrollPane (); 87 diagramScrollPanel.getViewport().add(diagramPanel, null); 88 diagramScrollPanel.setFont(scaleManager.getFont()); 89 diagramScrollPanel.getHorizontalScrollBar().setUnitIncrement((int)(scaleManager.getScale() * IdentityGui.min_hsize)); 90 menuBar = new javax.swing.JMenuBar (); 91 fileMenu = new javax.swing.JMenu (); 92 connectMenuItem = new javax.swing.JMenuItem (); 93 openMenuItem = new javax.swing.JMenuItem (); 94 saveAsMenuItem = new javax.swing.JMenuItem (); 95 exitMenuItem = new javax.swing.JMenuItem (); 96 optionsMenu = new javax.swing.JMenu (); 97 threadViewRadioButtonMenuItem = new javax.swing.JRadioButtonMenuItem (); 98 objectViewRadioButtonMenuItem = new javax.swing.JRadioButtonMenuItem (); 99 helpMenu = new javax.swing.JMenu (); 100 contentsMenuItem = new javax.swing.JMenuItem (); 101 aboutMenuItem = new javax.swing.JMenuItem (); 102 103 setTitle("COACH TracingViewer"); 104 addComponentListener(new java.awt.event.ComponentAdapter () { 105 public void componentResized(java.awt.event.ComponentEvent evt) { 106 formComponentResized(evt); 107 } 108 }); 109 110 addWindowListener(new java.awt.event.WindowAdapter () { 111 public void windowClosing(java.awt.event.WindowEvent evt) { 112 exitForm(evt); 113 } 114 }); 115 116 statusPanel.setBorder(new javax.swing.border.BevelBorder (javax.swing.border.BevelBorder.RAISED)); 117 eventsLabel.setText("events"); 118 statusPanel.add(eventsLabel); 119 120 eventsTextField.setBackground(new java.awt.Color (204, 204, 204)); 121 eventsTextField.setColumns(8); 122 eventsTextField.setText(" "); 123 statusPanel.add(eventsTextField); 124 125 messagesLabel.setText("messages"); 126 statusPanel.add(messagesLabel); 127 128 messagesTextField.setBackground(new java.awt.Color (204, 204, 204)); 129 messagesTextField.setColumns(8); 130 statusPanel.add(messagesTextField); 131 132 unmatchedEventsLabel.setText("unmatched events"); 133 statusPanel.add(unmatchedEventsLabel); 134 135 unmatchedEventsTextField.setBackground(new java.awt.Color (204, 204, 204)); 136 unmatchedEventsTextField.setColumns(8); 137 statusPanel.add(unmatchedEventsTextField); 138 139 getContentPane().add(statusPanel, java.awt.BorderLayout.SOUTH); 140 141 buttonPanel.setBorder(new javax.swing.border.BevelBorder (javax.swing.border.BevelBorder.RAISED)); 142 clearButton.setText("clear"); 143 clearButton.addActionListener(new java.awt.event.ActionListener () { 144 public void actionPerformed(java.awt.event.ActionEvent evt) { 145 clearButtonActionPerformed(evt); 146 } 147 }); 148 149 buttonPanel.add(clearButton); 150 151 uncolorButton.setText("uncolor"); 152 uncolorButton.addActionListener(new java.awt.event.ActionListener () { 153 public void actionPerformed(java.awt.event.ActionEvent evt) { 154 uncolorButtonActionPerformed(evt); 155 } 156 }); 157 158 buttonPanel.add(uncolorButton); 159 160 trailLabelButton.setText("trail labels"); 161 trailLabelButton.addActionListener(new java.awt.event.ActionListener () { 162 public void actionPerformed(java.awt.event.ActionEvent evt) { 163 trailLabelButtonActionPerformed(evt); 164 } 165 }); 166 167 buttonPanel.add(trailLabelButton); 168 169 zoomInButton.setText("zoom in"); 170 zoomInButton.addActionListener(new java.awt.event.ActionListener () { 171 public void actionPerformed(java.awt.event.ActionEvent evt) { 172 zoomInButtonActionPerformed(evt); 173 } 174 }); 175 176 buttonPanel.add(zoomInButton); 177 178 zoomOutButton.setText("zoom out"); 179 zoomOutButton.addActionListener(new java.awt.event.ActionListener () { 180 public void actionPerformed(java.awt.event.ActionEvent evt) { 181 zoomOutButtonActionPerformed(evt); 182 } 183 }); 184 185 buttonPanel.add(zoomOutButton); 186 187 unhideButton.setText("unhide"); 188 unhideButton.addActionListener(new java.awt.event.ActionListener () { 189 public void actionPerformed(java.awt.event.ActionEvent evt) { 190 unhideButtonActionPerformed(evt); 191 } 192 }); 193 194 buttonPanel.add(unhideButton); 195 196 identitiesButton.setText("identities"); 197 identitiesButton.addActionListener(new java.awt.event.ActionListener () { 198 public void actionPerformed(java.awt.event.ActionEvent evt) { 199 identitiesButtonActionPerformed(evt); 200 } 201 }); 202 203 buttonPanel.add(identitiesButton); 204 205 getContentPane().add(buttonPanel, java.awt.BorderLayout.NORTH); 206 207 diagramMainPanel.setLayout(new java.awt.BorderLayout ()); 208 209 diagramVerticalScrollBar.setMinimumSize(new java.awt.Dimension (17, 400)); 210 diagramVerticalScrollBar.setPreferredSize(new java.awt.Dimension (17, 400)); 211 diagramVerticalScrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener () { 212 public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) { 213 diagramVerticalScrollBarAdjustmentValueChanged(evt); 214 } 215 }); 216 217 diagramMainPanel.add(diagramVerticalScrollBar, java.awt.BorderLayout.EAST); 218 219 diagramScrollPanel.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_NEVER); 220 diagramMainPanel.add(diagramScrollPanel, java.awt.BorderLayout.CENTER); 221 222 getContentPane().add(diagramMainPanel, java.awt.BorderLayout.CENTER); 223 224 241 250 exitMenuItem.setText("Exit"); 251 exitMenuItem.addActionListener(new java.awt.event.ActionListener () { 252 public void actionPerformed(java.awt.event.ActionEvent evt) { 253 exitMenuItemActionPerformed(evt); 254 } 255 }); 256 257 fileMenu.add(exitMenuItem); 258 259 menuBar.add(fileMenu); 260 261 optionsMenu.setText("Options"); 262 threadViewRadioButtonMenuItem.setText("Thread View"); 263 viewModebuttonGroup.add(threadViewRadioButtonMenuItem); 264 threadViewRadioButtonMenuItem.addActionListener(new java.awt.event.ActionListener () { 265 public void actionPerformed(java.awt.event.ActionEvent evt) { 266 threadViewRadioButtonMenuItemActionPerformed(evt); 267 } 268 }); 269 270 optionsMenu.add(threadViewRadioButtonMenuItem); 271 272 objectViewRadioButtonMenuItem.setSelected(true); 273 objectViewRadioButtonMenuItem.setText("Object View"); 274 objectViewRadioButtonMenuItem.addActionListener(new java.awt.event.ActionListener () { 275 public void actionPerformed(java.awt.event.ActionEvent evt) { 276 objectViewRadioButtonMenuItemActionPerformed(evt); 277 } 278 }); 279 280 optionsMenu.add(objectViewRadioButtonMenuItem); 281 282 menuBar.add(optionsMenu); 283 284 helpMenu.setText("Help"); 285 contentsMenuItem.setText("Contents"); 286 helpMenu.add(contentsMenuItem); 287 288 aboutMenuItem.setText("About"); 289 helpMenu.add(aboutMenuItem); 290 291 menuBar.add(helpMenu); 292 293 setJMenuBar(menuBar); 294 295 pack(); 296 } 298 319 327 349 private void objectViewRadioButtonMenuItemActionPerformed(java.awt.event.ActionEvent evt) { diagramPanel.setThreadViewMode(false); 351 } 353 private void threadViewRadioButtonMenuItemActionPerformed(java.awt.event.ActionEvent evt) { diagramPanel.setThreadViewMode(true); 355 } 357 private void identitiesButtonActionPerformed(java.awt.event.ActionEvent evt) { IdentityTreeFrame f = new IdentityTreeFrame(); 359 f.show(); 360 } 362 private void unhideButtonActionPerformed(java.awt.event.ActionEvent evt) { IdentityNode.unhideAll(); 364 ThreadNode.unhideAll(); 365 diagramPanel.repaintEvents(); 366 } 368 private void zoomOutButtonActionPerformed(java.awt.event.ActionEvent evt) { scaleManager.scaleDown(); 370 int units = (int)(scaleManager.getScale() * Diagram.space_between); 371 int range = getHeight() / units; 372 diagramPanel.setRange(range); 373 diagramScrollPanel.repaint(); 374 } 376 private void zoomInButtonActionPerformed(java.awt.event.ActionEvent evt) { scaleManager.scaleUp(); 378 int units = (int)(scaleManager.getScale() * Diagram.space_between); 379 int range = getHeight() / units; 380 diagramPanel.setRange(range); 381 diagramScrollPanel.repaint(); 382 } 384 private void formComponentResized(java.awt.event.ComponentEvent evt) { int units = (int)(scaleManager.getScale() * Diagram.space_between); 386 int range = getHeight() / units; 387 diagramPanel.setRange(range); 388 diagramScrollPanel.repaint(); 389 } 391 private void trailLabelButtonActionPerformed(java.awt.event.ActionEvent evt) { String [] labels = diagramPanel.getTrailLabels(); 393 if (labels.length > 0) { 394 TrailLabelData[] trailLabelData = diagramPanel.getTrailLabelData(); 395 if (trailLabelData != null) { 396 if (trailLabelData.length != labels.length) { 397 TrailLabelData[] newData = new TrailLabelData[labels.length]; 398 int idx = 0; 399 for(; idx < trailLabelData.length; idx++) { 400 newData[idx] = trailLabelData[idx]; 401 } 402 for(; idx < newData.length; idx++) { 403 newData[idx] = new TrailLabelData(); 404 newData[idx].name = labels[idx]; 405 } 406 trailLabelData = newData; 407 } 408 } else { 409 trailLabelData = new TrailLabelData[labels.length]; 410 for (int i = 0; i < trailLabelData.length; i++) { 411 trailLabelData[i] = new TrailLabelData(); 412 trailLabelData[i].name = labels[i]; 413 } 414 } 415 TrailLabelDialog d = new TrailLabelDialog(this, trailLabelData); 416 trailLabelData = d.getTrailLabelData(); 417 diagramPanel.setTrailLabelData(trailLabelData); 418 } 419 } 421 private void uncolorButtonActionPerformed(java.awt.event.ActionEvent evt) { diagramPanel.uncolour(); 423 repaint(); 424 } 426 private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) { repaint(); 429 } 431 private void diagramVerticalScrollBarAdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) { long start = (long)diagramVerticalScrollBar.getValue(); 433 if (start != prevStart) { 434 prevStart = start; 435 diagramPanel.paintEvents(start); 436 diagramScrollPanel.repaint(); 437 repaint(); 438 } 439 } 441 private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) { 443 } 445 446 private void exitForm(java.awt.event.WindowEvent evt) { 448 } 450 453 public static void main(String args[]) { 454 new TraceViewerFrame().show(); 455 } 456 457 static public ScaleManager getScaleManager() { 458 return scaleManager; 459 } 460 461 public void createEventBrowser(EventRecord me, Point p) { 462 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 464 int h = 300; 465 int w = 450; 466 EventBrowser meb = new EventBrowser(me); 467 browsers.add(meb); 468 meb.setSize(w, h); 469 meb.setLocation(((screenSize.width - p.x) > w) ? (p.x + 1) : (p.x - w - 1), (int)((screenSize.height - h) / 2)); 470 meb.setVisible(true); 471 } 472 473 public void updateStatusBar(long events, long objects, long messages) { 474 eventsTextField.setText("" + events); 475 messagesTextField.setText("" + messages); 476 unmatchedEventsTextField.setText("" + (events - (2 * messages))); 477 diagramVerticalScrollBar.setMaximum((int)events); 478 diagramScrollPanel.validate(); 479 repaint(); 480 } 481 482 483 private javax.swing.JLabel eventsLabel; 485 private javax.swing.JRadioButtonMenuItem objectViewRadioButtonMenuItem; 486 private javax.swing.JScrollPane diagramScrollPanel; 487 private javax.swing.JMenu fileMenu; 488 private javax.swing.JLabel messagesLabel; 489 private javax.swing.JTextField eventsTextField; 490 private javax.swing.JMenu optionsMenu; 491 private javax.swing.JTextField unmatchedEventsTextField; 492 private javax.swing.JMenuItem exitMenuItem; 493 private javax.swing.JMenuItem saveAsMenuItem; 494 private javax.swing.JScrollBar diagramVerticalScrollBar; 495 private javax.swing.JRadioButtonMenuItem threadViewRadioButtonMenuItem; 496 private javax.swing.JButton unhideButton; 497 private javax.swing.JPanel diagramMainPanel; 498 private javax.swing.JMenuItem connectMenuItem; 499 private javax.swing.JButton uncolorButton; 500 private javax.swing.JMenuItem openMenuItem; 501 private javax.swing.JMenuBar menuBar; 502 private javax.swing.JButton clearButton; 503 private javax.swing.JButton identitiesButton; 504 private javax.swing.JPanel statusPanel; 505 private javax.swing.JPanel buttonPanel; 506 private javax.swing.JButton trailLabelButton; 507 private javax.swing.JButton zoomInButton; 508 private javax.swing.JTextField messagesTextField; 509 private javax.swing.JMenuItem aboutMenuItem; 510 private javax.swing.JMenuItem contentsMenuItem; 511 private javax.swing.JMenu helpMenu; 512 private javax.swing.JButton zoomOutButton; 513 private javax.swing.JLabel unmatchedEventsLabel; 514 private javax.swing.ButtonGroup viewModebuttonGroup; 515 517 } 518 | Popular Tags |