KickJava   Java API By Example, From Geeks To Geeks.

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


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

3 package org.jgroups.debug;
4
5 import javax.swing.*;
6 import javax.swing.table.DefaultTableModel JavaDoc;
7 import org.jgroups.stack.Protocol;
8 import org.jgroups.stack.ProtocolObserver;
9 import org.jgroups.Event;
10
11
12
13 /**
14  * Graphical view of a protocol instance
15  * @author Bela Ban, created July 22 2000
16  */

17 public class ProtocolView implements ProtocolObserver {
18     final DefaultTableModel JavaDoc model;
19     int my_index=-1;
20     Protocol prot=null;
21     String JavaDoc prot_name=null;
22     final JButton down_label=new JButton("0");
23     final JButton up_label=new JButton("0");
24     boolean cummulative=false;
25     long tot_up=0, tot_down=0;
26
27
28
29     public ProtocolView(Protocol p, DefaultTableModel JavaDoc model, int my_index) {
30     prot=p; prot_name=p.getName(); this.model=model; this.my_index=my_index;
31     }
32
33
34     public ProtocolView(Protocol p, DefaultTableModel JavaDoc model, int my_index, boolean cummulative) {
35     prot=p; prot_name=p.getName(); this.model=model; this.my_index=my_index; this.cummulative=cummulative;
36     }
37
38     
39
40
41     /* ----------------------- ProtocolObserver interface ----------------------- */
42     public void setProtocol(Protocol prot) {
43     this.prot=prot;
44     }
45
46     
47     public boolean up(Event evt, int num_evts) {
48     tot_up++;
49     if(cummulative)
50         model.setValueAt("" + tot_up, my_index, 2);
51     else
52         model.setValueAt("" + num_evts, my_index, 2);
53     return true;
54     }
55
56
57     public boolean passUp(Event evt) {
58     return true;
59     }
60     
61     
62     public boolean down(Event evt, int num_evts) {
63     tot_down++;
64     if(cummulative)
65         model.setValueAt("" + tot_down, my_index, 3);
66     else
67         model.setValueAt("" + num_evts, my_index, 3);
68     return true;
69     }
70
71     public boolean passDown(Event evt) {
72     return true;
73     }
74
75     /* ------------------- End of ProtocolObserver interface ---------------------- */
76
77
78
79     public String JavaDoc toString() {
80     return prot != null ? prot.getName() : "<n|a>";
81     }
82
83
84 }
85
Popular Tags