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.mail;
25
26 import javax.swing.table.*;
27 import java.util.*;
28 import zeus.concepts.Performative;
29 import zeus.actors.event.*;
30 import zeus.actors.*;
31
32
33 public class MailOutTableModel extends AbstractTableModel implements MessageMonitor {
34
35 private String RECEPIENT = "To";
36 private String TYPE = "Type";
37 private String SUBJECT = "Subject";
38 private String CONTENT = "Content";
39 private int BUFFER_CAPACITY = 50;
40 private int REMOVE_INDEX = 0;
41
42
43
44 private String[] header = {RECEPIENT,SUBJECT,TYPE};
45 private Vector data ;
46 private MailBox mb;
47 //---------------------------------------------------------------------------
48 public MailOutTableModel(AgentContext context){
49 data = new Vector();
50 mb = context.MailBox();
51 mb.addMessageMonitor(this, MessageEvent.DISPATCH_MASK);
52 }
53
54
55 //---------------------------------------------------------------------------
56 public int getRowCount() {
57 return data.size();
58 }
59 //---------------------------------------------------------------------------
60 public int getColumnCount(){
61 return header.length;
62 }
63 //---------------------------------------------------------------------------
64 public Object getValueAt(int row, int col) {
65 Performative msg = (Performative) data.elementAt(row);
66 if (getColumnName(col).equals(RECEPIENT)) {
67 return msg.getReceiver();
68 }
69 else if (getColumnName(col).equals(SUBJECT)) {
70 return null; //
71 }
72 else if (getColumnName(col).equals(TYPE)) {
73 return msg.getType();
74 }
75 else{
76 return new String("Error in MailOutTableModel at getValueAt");
77 }
78 }
79 //---------------------------------------------------------------------------
80 Performative getMessage(int row){
81 Performative msg = (Performative) data.elementAt(row);
82 return (msg);
83 }
84 //---------------------------------------------------------------------------
85 public String getColumnName(int col) {
86 return header[col];
87 }
88 //---------------------------------------------------------------------------
89 public void addMail(Performative msg){
90 if ( data.contains(msg) )
91 return;
92
93 if (data.size() > BUFFER_CAPACITY )
94 data.removeElementAt(REMOVE_INDEX);
95 data.addElement(msg);
96 fireTableDataChanged();
97 }
98 //---------------------------------------------------------------------------
99 public String getMailContent(int row){
100 Performative msg = (Performative) data.elementAt(row);
101 return (msg.getContent());
102
103 }
104 //---------------------------------------------------------------------------
105 public void messageReceivedEvent(MessageEvent event){
106 }
107 //---------------------------------------------------------------------------
108 public void messageQueuedEvent(MessageEvent event){
109
110 }
111 //---------------------------------------------------------------------------
112 public void messageDispatchedEvent(MessageEvent event){
113 addMail((Performative) event.getObject());
114 }
115 //---------------------------------------------------------------------------
116 public void messageNotDispatchedEvent(MessageEvent event){}
117 //---------------------------------------------------------------------------
118 public void removeZeusEventMonitors(){
119 mb.removeMessageMonitor(this, MessageEvent.DISPATCH_MASK);
120
121 }
122 }