1 /*
2 * The contents of this file are subject to the BT "ZEUS" Open Source
3 * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file
4 * except in compliance with the Licence. You may obtain a copy of the Licence
5 * from $ZEUS_INSTALL/licence.html or alternatively from
6 * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7 *
8 * Except as stated in Clause 7 of the Licence, software distributed under the
9 * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the Licence for the specific language governing rights and
11 * limitations under the Licence.
12 *
13 * The Original Code is within the package zeus.*.
14 * The Initial Developer of the Original Code is British Telecommunications
15 * public limited company, whose registered office is at 81 Newgate Street,
16 * London, EC1A 7AJ, England. Portions created by British Telecommunications
17 * public limited company are Copyright 1996-9. All Rights Reserved.
18 *
19 * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20 */
21
22
23
24 package zeus.agentviewer.protocol;
25
26 import javax.swing.table.*;
27 import java.util.*;
28 import zeus.util.OrderedHashtable;
29
30 import zeus.actors.event.*;
31 import zeus.actors.*;
32 import zeus.concepts.*;
33
34
35
36
37 public class ProtocolModel extends AbstractTableModel
38 implements ProtocolMonitor{
39
40 public final static int TYPE = 0;
41 public final static int PROTOCOL = 1;
42 public final static int STATE = 2;
43
44 private String[] columnNames = {"Type","Protocol", "State"};
45 private Vector data ;
46 private ProtocolDb protocolDb;
47
48 //------------------------------------------------------------------------------
49 public ProtocolModel(AgentContext context){
50 data = new Vector();
51 this.protocolDb = context.ProtocolDb();
52 this.protocolDb.addProtocolMonitor(this,
53 ProtocolEvent.ADD_MASK | ProtocolEvent.DELETE_MASK |
54 ProtocolEvent.MODIFY_MASK, true );
55 }
56 //------------------------------------------------------------------------------
57 public int getRowCount() {
58 return data.size();
59 }
60 //------------------------------------------------------------------------------
61 public int getColumnCount(){
62 return columnNames.length;
63 }
64 //------------------------------------------------------------------------------
65 public Object getValueAt(int row, int col) {
66 ProtocolInfo info = (ProtocolInfo) data.elementAt(row);
67 switch(col) {
68 case TYPE:
69 return info.getType();
70 case PROTOCOL:
71 return info.getName();
72 case STATE:
73 return Boolean.TRUE;
74 default:
75 return null;
76 }
77 }
78 //------------------------------------------------------------------------------
79 public String getColumnName(int col) {
80 return columnNames[col];
81 }
82 //------------------------------------------------------------------------------
83 public void protocolAddedEvent(ProtocolEvent event) {
84
85 ProtocolInfo info = event.getProtocolInfo();
86 if ( !data.contains(info)) {
87 data.addElement(info);
88 fireTableDataChanged();
89 }
90 }
91 //------------------------------------------------------------------------------
92 public void protocolDeletedEvent(ProtocolEvent event) {
93 ProtocolInfo info = event.getProtocolInfo();
94 data.removeElement(info);
95 fireTableDataChanged();
96 }
97 //------------------------------------------------------------------------------
98 public void protocolModifiedEvent(ProtocolEvent event) {
99 }
100 //------------------------------------------------------------------------------
101 public void protocolAccessedEvent(ProtocolEvent event) {}
102 //------------------------------------------------------------------------------
103 public void removeZeusEventMonitors(){
104 protocolDb.removeProtocolMonitor(this,
105 ProtocolEvent.ADD_MASK | ProtocolEvent.DELETE_MASK |
106 ProtocolEvent.MODIFY_MASK);
107 }
108 //------------------------------------------------------------------------------
109 public StrategyInfo[] getStrategyInfos(int row){
110 ProtocolInfo protocol = (ProtocolInfo)data.elementAt(row);
111 return protocol.getConstraints();
112 }
113 }