001: // $Id: Debugger.java,v 1.6 2006/01/23 13:03:09 belaban Exp $
002:
003: package org.jgroups.debug;
004:
005: import org.jgroups.JChannel;
006: import org.jgroups.stack.Protocol;
007: import org.jgroups.stack.ProtocolStack;
008:
009: import javax.swing.*;
010: import javax.swing.table.DefaultTableModel;
011: import java.awt.*;
012: import java.util.Vector;
013:
014: /**
015: * The Debugger displays a graphical view of the protocol stack by showing all the protocols and
016: * the events in them.
017: *
018: * @author Bela Ban
019: */
020: public class Debugger extends JFrame {
021: JChannel channel = null;
022: Vector prots = new Vector();
023: JButton b1, b2;
024: JPanel button_panel;
025: JTable table;
026: DefaultTableModel table_model;
027: JScrollPane scroll_pane;
028: public static final Font helvetica_12 = new Font("Helvetica",
029: Font.PLAIN, 12);
030: public boolean cummulative = false; // shows added up/down events instead of up/down queue_size
031:
032: public Debugger() {
033: super ("Debugger Window");
034: }
035:
036: public Debugger(JChannel channel) {
037: super ("Debugger Window");
038: this .channel = channel;
039: }
040:
041: public Debugger(JChannel channel, String name) {
042: super (name);
043: this .channel = channel;
044: }
045:
046: public Debugger(JChannel channel, boolean cummulative) {
047: super ("Debugger Window");
048: this .channel = channel;
049: this .cummulative = cummulative;
050: }
051:
052: public Debugger(JChannel channel, boolean cummulative, String name) {
053: super (name);
054: this .channel = channel;
055: this .cummulative = cummulative;
056: }
057:
058: public void setChannel(JChannel channel) {
059: this .channel = channel;
060: }
061:
062: public void start() {
063: Protocol prot;
064: ProtocolStack stack;
065: ProtocolView view = null;
066:
067: if (channel == null)
068: return;
069: stack = channel.getProtocolStack();
070: prots = stack.getProtocols();
071:
072: setBounds(new Rectangle(30, 30, 300, 300));
073: table_model = new DefaultTableModel();
074: table = new JTable(table_model);
075: table.setFont(helvetica_12);
076: scroll_pane = new JScrollPane(table);
077: table_model.setColumnIdentifiers(new String[] { "Index",
078: "Name", "up", "down" });
079:
080: getContentPane().add(scroll_pane);
081: show();
082:
083: for (int i = 0; i < prots.size(); i++) {
084: prot = (Protocol) prots.elementAt(i);
085: view = new ProtocolView(prot, table_model, i, cummulative);
086: prot.setObserver(view);
087: table_model.insertRow(i, new Object[] { "" + (i + 1),
088: prot.getName(), prot.getUpQueue().size() + "",
089: prot.getDownQueue().size() + "", "0", "0" });
090:
091: //prot_view=CreateProtocolView(prot.getName());
092: //if(prot_view != null) {
093: //JFrame f=new JFrame("New View for " + prot.GetName());
094: //f.getContentPane().add(prot_view);
095: //f.show();
096: //}
097: }
098: }
099:
100: public void stop() {
101: Protocol prot;
102: ProtocolStack stack;
103:
104: if (channel == null)
105: return;
106: stack = channel.getProtocolStack();
107: prots = stack.getProtocols();
108:
109: for (int i = 0; i < prots.size(); i++) {
110: prot = (Protocol) prots.elementAt(i);
111: prot.setObserver(null);
112: }
113: dispose();
114: }
115:
116: public static void main(String[] args) {
117: Debugger d = new Debugger();
118: d.start();
119: }
120: }
|