01: // $Id: ProtocolView.java,v 1.2 2004/09/23 16:29:16 belaban Exp $
02:
03: package org.jgroups.debug;
04:
05: import javax.swing.*;
06: import javax.swing.table.DefaultTableModel;
07: import org.jgroups.stack.Protocol;
08: import org.jgroups.stack.ProtocolObserver;
09: import org.jgroups.Event;
10:
11: /**
12: * Graphical view of a protocol instance
13: * @author Bela Ban, created July 22 2000
14: */
15: public class ProtocolView implements ProtocolObserver {
16: final DefaultTableModel model;
17: int my_index = -1;
18: Protocol prot = null;
19: String prot_name = null;
20: final JButton down_label = new JButton("0");
21: final JButton up_label = new JButton("0");
22: boolean cummulative = false;
23: long tot_up = 0, tot_down = 0;
24:
25: public ProtocolView(Protocol p, DefaultTableModel model,
26: int my_index) {
27: prot = p;
28: prot_name = p.getName();
29: this .model = model;
30: this .my_index = my_index;
31: }
32:
33: public ProtocolView(Protocol p, DefaultTableModel model,
34: int my_index, boolean cummulative) {
35: prot = p;
36: prot_name = p.getName();
37: this .model = model;
38: this .my_index = my_index;
39: this .cummulative = cummulative;
40: }
41:
42: /* ----------------------- ProtocolObserver interface ----------------------- */
43: public void setProtocol(Protocol prot) {
44: this .prot = prot;
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: public boolean passUp(Event evt) {
57: return true;
58: }
59:
60: public boolean down(Event evt, int num_evts) {
61: tot_down++;
62: if (cummulative)
63: model.setValueAt("" + tot_down, my_index, 3);
64: else
65: model.setValueAt("" + num_evts, my_index, 3);
66: return true;
67: }
68:
69: public boolean passDown(Event evt) {
70: return true;
71: }
72:
73: /* ------------------- End of ProtocolObserver interface ---------------------- */
74:
75: public String toString() {
76: return prot != null ? prot.getName() : "<n|a>";
77: }
78:
79: }
|