KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > debug > Debugger


1 // $Id: Debugger.java,v 1.3 2004/09/23 16:29:16 belaban Exp $
2

3 package org.jgroups.debug;
4
5 import org.jgroups.JChannel;
6 import org.jgroups.stack.Protocol;
7 import org.jgroups.stack.ProtocolStack;
8
9 import javax.swing.*;
10 import javax.swing.table.DefaultTableModel JavaDoc;
11 import java.awt.*;
12 import java.util.Vector JavaDoc;
13
14
15 /**
16  * The Debugger displays a graphical view of the protocol stack by showing all the protocols and
17  * the events in them.
18  *
19  * @author Bela Ban
20  */

21 public class Debugger extends JFrame {
22     JChannel channel=null;
23     Vector JavaDoc prots=new Vector JavaDoc();
24     JButton b1, b2;
25     JPanel button_panel;
26     JTable table;
27     DefaultTableModel JavaDoc table_model;
28     JScrollPane scroll_pane;
29     public static final Font helvetica_12=new Font("Helvetica", Font.PLAIN, 12);;
30     public boolean cummulative=false; // shows added up/down events instead of up/down queue_size
31

32
33
34     public Debugger() {
35         super("Debugger Window");
36     }
37
38
39     public Debugger(JChannel channel) {
40         super("Debugger Window");
41         this.channel=channel;
42     }
43
44
45     public Debugger(JChannel channel, String JavaDoc name) {
46         super(name);
47         this.channel=channel;
48     }
49
50     public Debugger(JChannel channel, boolean cummulative) {
51         super("Debugger Window");
52         this.channel=channel;
53         this.cummulative=cummulative;
54     }
55
56
57     public Debugger(JChannel channel, boolean cummulative, String JavaDoc name) {
58         super(name);
59         this.channel=channel;
60         this.cummulative=cummulative;
61     }
62
63
64     public void setChannel(JChannel channel) {
65         this.channel=channel;
66     }
67
68
69     public void start() {
70         Protocol prot;
71         ProtocolStack stack;
72         ProtocolView view=null;
73
74         if(channel == null) return;
75         stack=channel.getProtocolStack();
76         prots=stack.getProtocols();
77
78         setBounds(new Rectangle(30, 30, 300, 300));
79         table_model=new DefaultTableModel JavaDoc();
80         table=new JTable(table_model);
81         table.setFont(helvetica_12);
82         scroll_pane=new JScrollPane(table);
83         table_model.setColumnIdentifiers(new String JavaDoc[]{"Index", "Name", "up", "down"});
84
85         getContentPane().add(scroll_pane);
86         show();
87
88         for(int i=0; i < prots.size(); i++) {
89             prot=(Protocol)prots.elementAt(i);
90             view=new ProtocolView(prot, table_model, i, cummulative);
91             prot.setObserver(view);
92             table_model.insertRow(i, new Object JavaDoc[]{"" + (i + 1),
93                                                   prot.getName(), prot.getUpQueue().size() + "",
94                                                   prot.getDownQueue().size() + "", "0", "0"});
95
96             //prot_view=CreateProtocolView(prot.getName());
97
//if(prot_view != null) {
98
//JFrame f=new JFrame("New View for " + prot.GetName());
99
//f.getContentPane().add(prot_view);
100
//f.show();
101
//}
102
}
103     }
104
105     public void stop() {
106         Protocol prot;
107         ProtocolStack stack;
108
109         if(channel == null) return;
110         stack=channel.getProtocolStack();
111         prots=stack.getProtocols();
112
113         for(int i=0; i < prots.size(); i++) {
114             prot=(Protocol)prots.elementAt(i);
115             prot.setObserver(null);
116         }
117         dispose();
118     }
119
120
121     JComponent createProtocolView(String JavaDoc protname) {
122         String JavaDoc classname="org.jgroups.debug." + protname + "View";
123         try {
124             ClassLoader JavaDoc loader=Thread.currentThread().getContextClassLoader();
125             return (JComponent)loader.loadClass(classname).newInstance();
126         }
127         catch(Exception JavaDoc e) { // ClassNotFoundException
128
return null;
129         }
130     }
131
132
133     public static void main(String JavaDoc[] args) {
134         Debugger d=new Debugger();
135         d.start();
136     }
137 }
138
139
Popular Tags