KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > tracing > server > viewer > TraceViewerFrame


1 /*
2  * TraceViewer.java
3  *
4  * Created on March 17, 2003, 8:05 PM
5  */

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 /**
20  *
21  * @author harold
22  */

23 public class TraceViewerFrame extends javax.swing.JFrame JavaDoc {
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 JavaDoc updateTimer;
30     private long eventCount = 0;
31     private EventDataBase eventDB;
32     
33     /** Creates new form TraceViewer */
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 JavaDoc(1000, updateAction);
59         updateTimer.start();
60     }
61     
62     /** This method is called from within the constructor to
63      * initialize the form.
64      * WARNING: Do NOT modify this code. The content of this method is
65      * always regenerated by the Form Editor.
66      */

67     private void initComponents() {//GEN-BEGIN:initComponents
68
viewModebuttonGroup = new javax.swing.ButtonGroup JavaDoc();
69         statusPanel = new javax.swing.JPanel JavaDoc();
70         eventsLabel = new javax.swing.JLabel JavaDoc();
71         eventsTextField = new javax.swing.JTextField JavaDoc();
72         messagesLabel = new javax.swing.JLabel JavaDoc();
73         messagesTextField = new javax.swing.JTextField JavaDoc();
74         unmatchedEventsLabel = new javax.swing.JLabel JavaDoc();
75         unmatchedEventsTextField = new javax.swing.JTextField JavaDoc();
76         buttonPanel = new javax.swing.JPanel JavaDoc();
77         clearButton = new javax.swing.JButton JavaDoc();
78         uncolorButton = new javax.swing.JButton JavaDoc();
79         trailLabelButton = new javax.swing.JButton JavaDoc();
80         zoomInButton = new javax.swing.JButton JavaDoc();
81         zoomOutButton = new javax.swing.JButton JavaDoc();
82         unhideButton = new javax.swing.JButton JavaDoc();
83         identitiesButton = new javax.swing.JButton JavaDoc();
84         diagramMainPanel = new javax.swing.JPanel JavaDoc();
85         diagramVerticalScrollBar = new javax.swing.JScrollBar JavaDoc();
86         diagramScrollPanel = new javax.swing.JScrollPane JavaDoc();
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 JavaDoc();
91         fileMenu = new javax.swing.JMenu JavaDoc();
92         connectMenuItem = new javax.swing.JMenuItem JavaDoc();
93         openMenuItem = new javax.swing.JMenuItem JavaDoc();
94         saveAsMenuItem = new javax.swing.JMenuItem JavaDoc();
95         exitMenuItem = new javax.swing.JMenuItem JavaDoc();
96         optionsMenu = new javax.swing.JMenu JavaDoc();
97         threadViewRadioButtonMenuItem = new javax.swing.JRadioButtonMenuItem JavaDoc();
98         objectViewRadioButtonMenuItem = new javax.swing.JRadioButtonMenuItem JavaDoc();
99         helpMenu = new javax.swing.JMenu JavaDoc();
100         contentsMenuItem = new javax.swing.JMenuItem JavaDoc();
101         aboutMenuItem = new javax.swing.JMenuItem JavaDoc();
102
103         setTitle("COACH TracingViewer");
104         addComponentListener(new java.awt.event.ComponentAdapter JavaDoc() {
105             public void componentResized(java.awt.event.ComponentEvent JavaDoc evt) {
106                 formComponentResized(evt);
107             }
108         });
109
110         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
111             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
112                 exitForm(evt);
113             }
114         });
115
116         statusPanel.setBorder(new javax.swing.border.BevelBorder JavaDoc(javax.swing.border.BevelBorder.RAISED));
117         eventsLabel.setText("events");
118         statusPanel.add(eventsLabel);
119
120         eventsTextField.setBackground(new java.awt.Color JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc(javax.swing.border.BevelBorder.RAISED));
142         clearButton.setText("clear");
143         clearButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
144             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
145                 clearButtonActionPerformed(evt);
146             }
147         });
148
149         buttonPanel.add(clearButton);
150
151         uncolorButton.setText("uncolor");
152         uncolorButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
153             public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc() {
162             public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc() {
171             public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc() {
180             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
181                 zoomOutButtonActionPerformed(evt);
182             }
183         });
184
185         buttonPanel.add(zoomOutButton);
186
187         unhideButton.setText("unhide");
188         unhideButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
189             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
190                 unhideButtonActionPerformed(evt);
191             }
192         });
193
194         buttonPanel.add(unhideButton);
195
196         identitiesButton.setText("identities");
197         identitiesButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
198             public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc());
208
209         diagramVerticalScrollBar.setMinimumSize(new java.awt.Dimension JavaDoc(17, 400));
210         diagramVerticalScrollBar.setPreferredSize(new java.awt.Dimension JavaDoc(17, 400));
211         diagramVerticalScrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener JavaDoc() {
212             public void adjustmentValueChanged(java.awt.event.AdjustmentEvent JavaDoc 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 // fileMenu.setText("File");
225
// connectMenuItem.setText("connect");
226
// connectMenuItem.addActionListener(new java.awt.event.ActionListener() {
227
// public void actionPerformed(java.awt.event.ActionEvent evt) {
228
// connectMenuItemActionPerformed(evt);
229
// }
230
// });
231
// fileMenu.add(connectMenuItem);
232
//
233
// openMenuItem.setText("Open");
234
// openMenuItem.addActionListener(new java.awt.event.ActionListener() {
235
// public void actionPerformed(java.awt.event.ActionEvent evt) {
236
// openMenuItemActionPerformed(evt);
237
// }
238
// });
239
// fileMenu.add(openMenuItem);
240

241 // saveAsMenuItem.setText("Save As ...");
242
// saveAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
243
// public void actionPerformed(java.awt.event.ActionEvent evt) {
244
// saveAsMenuItemActionPerformed(evt);
245
// }
246
// });
247
//
248
// fileMenu.add(saveAsMenuItem);
249

250         exitMenuItem.setText("Exit");
251         exitMenuItem.addActionListener(new java.awt.event.ActionListener JavaDoc() {
252             public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc() {
265             public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc() {
275             public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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     }//GEN-END:initComponents
297

298 // private void connectMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectMenuItemActionPerformed
299
// try {
300
// updateTimer.stop();
301
// if (currentConnection != null) {
302
// dbFacet.close(currentConnection);
303
// }
304
// diagramPanel.setEventDB(eventDB);
305
// IdentityNode.setEventDB(eventDB);
306
// ThreadNode.clear();
307
// EventRecord.setEventDB(eventDB);
308
// int units = (int)(scaleManager.getScale() * Diagram.space_between);
309
// int range = getHeight() / units;
310
// diagramPanel.setRange(range);
311
// eventCount = 0;
312
// updateTimer.start();
313
// } catch (Exception ex) {
314
// javax.swing.JOptionPane.showMessageDialog(null, ex.toString());
315
// ex.printStackTrace();
316
// }
317
// }//GEN-LAST:event_connectMenuItemActionPerformed
318

319 // private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuItemActionPerformed
320
// try {
321
// dbFacet.save("test");
322
// } catch (Exception ex) {
323
// javax.swing.JOptionPane.showMessageDialog(null, ex.toString());
324
// }
325
// }//GEN-LAST:event_saveAsMenuItemActionPerformed
326

327 // private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
328
// try {
329
// updateTimer.stop();
330
// if (currentConnection != null) {
331
// dbFacet.close(currentConnection);
332
// }
333
// currentConnection = dbFacet.open("test");
334
// diagramPanel.setEventDB(currentConnection);
335
// IdentityNode.setEventDB(currentConnection);
336
// ThreadNode.clear();
337
// EventRecord.setEventDB(currentConnection);
338
// int units = (int)(scaleManager.getScale() * Diagram.space_between);
339
// int range = getHeight() / units;
340
// diagramPanel.setRange(range);
341
// diagramPanel.updateStatus(currentConnection.getEventCount());
342
// diagramPanel.repaintEvents();
343
// } catch (Exception ex) {
344
// javax.swing.JOptionPane.showMessageDialog(null, ex.toString());
345
// ex.printStackTrace();
346
// }
347
// }//GEN-LAST:event_openMenuItemActionPerformed
348

349     private void objectViewRadioButtonMenuItemActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_objectViewRadioButtonMenuItemActionPerformed
350
diagramPanel.setThreadViewMode(false);
351     }//GEN-LAST:event_objectViewRadioButtonMenuItemActionPerformed
352

353     private void threadViewRadioButtonMenuItemActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_threadViewRadioButtonMenuItemActionPerformed
354
diagramPanel.setThreadViewMode(true);
355     }//GEN-LAST:event_threadViewRadioButtonMenuItemActionPerformed
356

357     private void identitiesButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_identitiesButtonActionPerformed
358
IdentityTreeFrame f = new IdentityTreeFrame();
359         f.show();
360     }//GEN-LAST:event_identitiesButtonActionPerformed
361

362     private void unhideButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_unhideButtonActionPerformed
363
IdentityNode.unhideAll();
364         ThreadNode.unhideAll();
365         diagramPanel.repaintEvents();
366     }//GEN-LAST:event_unhideButtonActionPerformed
367

368     private void zoomOutButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_zoomOutButtonActionPerformed
369
scaleManager.scaleDown();
370         int units = (int)(scaleManager.getScale() * Diagram.space_between);
371         int range = getHeight() / units;
372         diagramPanel.setRange(range);
373         diagramScrollPanel.repaint();
374     }//GEN-LAST:event_zoomOutButtonActionPerformed
375

376     private void zoomInButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_zoomInButtonActionPerformed
377
scaleManager.scaleUp();
378         int units = (int)(scaleManager.getScale() * Diagram.space_between);
379         int range = getHeight() / units;
380         diagramPanel.setRange(range);
381         diagramScrollPanel.repaint();
382     }//GEN-LAST:event_zoomInButtonActionPerformed
383

384     private void formComponentResized(java.awt.event.ComponentEvent JavaDoc evt) {//GEN-FIRST:event_formComponentResized
385
int units = (int)(scaleManager.getScale() * Diagram.space_between);
386         int range = getHeight() / units;
387         diagramPanel.setRange(range);
388         diagramScrollPanel.repaint();
389     }//GEN-LAST:event_formComponentResized
390

391     private void trailLabelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_trailLabelButtonActionPerformed
392
String JavaDoc[] 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     }//GEN-LAST:event_trailLabelButtonActionPerformed
420

421     private void uncolorButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_uncolorButtonActionPerformed
422
diagramPanel.uncolour();
423         repaint();
424     }//GEN-LAST:event_uncolorButtonActionPerformed
425

426     private void clearButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_clearButtonActionPerformed
427
// diagramPanel.clear();
428
repaint();
429     }//GEN-LAST:event_clearButtonActionPerformed
430

431     private void diagramVerticalScrollBarAdjustmentValueChanged(java.awt.event.AdjustmentEvent JavaDoc evt) {//GEN-FIRST:event_diagramVerticalScrollBarAdjustmentValueChanged
432
long start = (long)diagramVerticalScrollBar.getValue();
433         if (start != prevStart) {
434             prevStart = start;
435             diagramPanel.paintEvents(start);
436             diagramScrollPanel.repaint();
437             repaint();
438         }
439     }//GEN-LAST:event_diagramVerticalScrollBarAdjustmentValueChanged
440

441     private void exitMenuItemActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
442

443     }//GEN-LAST:event_exitMenuItemActionPerformed
444

445     /** Exit the Application */
446     private void exitForm(java.awt.event.WindowEvent JavaDoc evt) {//GEN-FIRST:event_exitForm
447

448     }//GEN-LAST:event_exitForm
449

450     /**
451      * @param args the command line arguments
452      */

453     public static void main(String JavaDoc 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         //open a property browser frame
463
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     // Variables declaration - do not modify//GEN-BEGIN:variables
484
private javax.swing.JLabel JavaDoc eventsLabel;
485     private javax.swing.JRadioButtonMenuItem JavaDoc objectViewRadioButtonMenuItem;
486     private javax.swing.JScrollPane JavaDoc diagramScrollPanel;
487     private javax.swing.JMenu JavaDoc fileMenu;
488     private javax.swing.JLabel JavaDoc messagesLabel;
489     private javax.swing.JTextField JavaDoc eventsTextField;
490     private javax.swing.JMenu JavaDoc optionsMenu;
491     private javax.swing.JTextField JavaDoc unmatchedEventsTextField;
492     private javax.swing.JMenuItem JavaDoc exitMenuItem;
493     private javax.swing.JMenuItem JavaDoc saveAsMenuItem;
494     private javax.swing.JScrollBar JavaDoc diagramVerticalScrollBar;
495     private javax.swing.JRadioButtonMenuItem JavaDoc threadViewRadioButtonMenuItem;
496     private javax.swing.JButton JavaDoc unhideButton;
497     private javax.swing.JPanel JavaDoc diagramMainPanel;
498     private javax.swing.JMenuItem JavaDoc connectMenuItem;
499     private javax.swing.JButton JavaDoc uncolorButton;
500     private javax.swing.JMenuItem JavaDoc openMenuItem;
501     private javax.swing.JMenuBar JavaDoc menuBar;
502     private javax.swing.JButton JavaDoc clearButton;
503     private javax.swing.JButton JavaDoc identitiesButton;
504     private javax.swing.JPanel JavaDoc statusPanel;
505     private javax.swing.JPanel JavaDoc buttonPanel;
506     private javax.swing.JButton JavaDoc trailLabelButton;
507     private javax.swing.JButton JavaDoc zoomInButton;
508     private javax.swing.JTextField JavaDoc messagesTextField;
509     private javax.swing.JMenuItem JavaDoc aboutMenuItem;
510     private javax.swing.JMenuItem JavaDoc contentsMenuItem;
511     private javax.swing.JMenu JavaDoc helpMenu;
512     private javax.swing.JButton JavaDoc zoomOutButton;
513     private javax.swing.JLabel JavaDoc unmatchedEventsLabel;
514     private javax.swing.ButtonGroup JavaDoc viewModebuttonGroup;
515     // End of variables declaration//GEN-END:variables
516

517 }
518
Popular Tags