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 MailInTableModel extends AbstractTableModel implements MessageMonitor {
34
35 private String SENDER = "From";
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 protected int messageCount = 0;
43
44
45 private String[] header = {SENDER,SUBJECT,TYPE};
46 private Vector data ;
47 private MailBox mb;
48 //---------------------------------------------------------------------------
49 public MailInTableModel(AgentContext context){
50 data = new Vector();
51 mb = context.MailBox();
52 mb.addMessageMonitor(this, MessageEvent.RECEIVE_MASK );
53 }
54
55
56 //---------------------------------------------------------------------------
57 public int getRowCount() {
58 return data.size();
59 }
60 //---------------------------------------------------------------------------
61 public int getColumnCount(){
62 return header.length;
63 }
64 //---------------------------------------------------------------------------
65 public Object getValueAt(int row, int col) {
66 Performative msg = (Performative) data.elementAt(row);
67 if (getColumnName(col).equals(SENDER)) {
68 return msg.getSender();
69 }
70 else if (getColumnName(col).equals(SUBJECT)) {
71 return null; // MORE
72 }
73 else if (getColumnName(col).equals(TYPE)) {
74 return msg.getType();
75 }
76 else{
77 return new String("Error in MailInTableModel at getValueAt");
78 }
79 }
80 //---------------------------------------------------------------------------
81 Performative getMessage(int row){
82 Performative msg = (Performative) data.elementAt(row);
83 return (msg);
84 }
85 //---------------------------------------------------------------------------
86 public String getColumnName(int col) {
87 return header[col];
88 }
89 //---------------------------------------------------------------------------
90 public void addMail(Performative msg){
91 if ( data.contains(msg) )
92 return;
93
94 if (data.size() > BUFFER_CAPACITY )
95 data.removeElementAt(REMOVE_INDEX);
96 data.addElement(msg);
97 messageCount++;
98 fireTableDataChanged();
99 }
100 //---------------------------------------------------------------------------
101 public String getMailContent(int row){
102 Performative msg = (Performative) data.elementAt(row);
103 return (msg.getContent());
104
105 }
106 //---------------------------------------------------------------------------
107 public void messageReceivedEvent(MessageEvent event){
108 addMail((Performative) event.getObject());
109 }
110 //---------------------------------------------------------------------------
111 public void messageQueuedEvent(MessageEvent event){
112
113 }
114 //---------------------------------------------------------------------------
115 public void messageDispatchedEvent(MessageEvent event){}
116 //---------------------------------------------------------------------------
117 public void messageNotDispatchedEvent(MessageEvent event){}
118 //---------------------------------------------------------------------------
119 public void removeZeusEventMonitors(){
120 mb.removeMessageMonitor(this, MessageEvent.RECEIVE_MASK );
121
122 }
123 }