1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package zeus.agentviewer.msghandler;
25
26 import javax.swing.*;
27 import javax.swing.table.*;
28 import javax.swing.event.*;
29 import javax.swing.border.* ;
30 import java.awt.*;
31 import java.awt.event.*;
32 import java.util.*;
33
34 import zeus.agentviewer.*;
35 import zeus.util.*;
36 import zeus.concepts.Performative;
37
38
39 /***
40 the message hander gui for the agentviewer
41 */
42 public class MsgHandlerTableUI extends ZeusInternalFrame
43 implements ListSelectionListener {
44
45 private JPanel contentPane;
46 private JTable table;
47 private JTextArea bottomPane;
48 private JScrollPane topPane;
49 private JSplitPane splitPane;
50
51 final int TOP_PANE_MIN_HEIGHT = 120;
52 final int TOP_PANE_MIN_WIDTH = 500;
53 final int BOTTOM_PANE_MIN_WIDTH = 500;
54 final int BOTTOM_PANE_MIN_HEIGHT = 100;
55
56
57 private static int NUMBER_DISPLAYED = 0;
58 private InternalFramesPanel deskTop;
59 MsgHandlerTableModel msgHandlerBuffer;
60 JTextArea replyWithTF, inReplyToTF, sendTimeTF,
61 ontologyTF, languageTF, contentTF, receiveTimeTF,numberSoFar;
62
63
64
65
66
67 public MsgHandlerTableUI(InternalFramesPanel deskTop,
68 MsgHandlerTableModel msgHandlerBuffer)
69 {
70 super(" ",true,true,true,true);
71 setTitle("Message Handler:" + (++NUMBER_DISPLAYED));
72 String sep = System.getProperty("file.separator");
73 String gifpath = SystemProps.getProperty("gif.dir") + "agentviewer" + sep;
74 ImageIcon icon = new ImageIcon(gifpath + ViewerNames.MSGHANDLER_IMG);
75 setFrameIcon(icon);
76 this.deskTop = deskTop;
77 this.msgHandlerBuffer =msgHandlerBuffer;
78 buildUI();
79 deskTop.addInternalFrame(this);
80 setVisible(true);
81 }
82
83
84 private void buildUI(){
85
86 table = new JTable(msgHandlerBuffer);
87 table.setPreferredScrollableViewportSize(new Dimension(TOP_PANE_MIN_WIDTH,
88 TOP_PANE_MIN_HEIGHT));
89 topPane = new JScrollPane(table);
90 table.getSelectionModel().addListSelectionListener(this );
91 table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
92 table.setShowGrid(false);
93
94 bottomPane = new JTextArea();
95 bottomPane.setEditable(false);
96 bottomPane.setLineWrap(true);
97 bottomPane.setWrapStyleWord(true);
98 bottomPane.setPreferredSize(new Dimension(BOTTOM_PANE_MIN_WIDTH,
99 BOTTOM_PANE_MIN_HEIGHT));
100
101 JScrollPane bottomSP = new JScrollPane(getBottomPanel());
102 bottomSP.setBorder(BorderFactory.createEtchedBorder(Color.black,Color.gray));
103
104 contentPane = (JPanel) getContentPane();
105 contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
106 contentPane.add(topPane);
107 contentPane.add(bottomSP);
108 pack();
109
110 }
111
112 private TitledBorder makeBorder(String title){
113 TitledBorder border = (BorderFactory.createTitledBorder(title));
114 border.setTitlePosition(TitledBorder.TOP);
115 border.setTitleJustification(TitledBorder.RIGHT);
116 border.setTitleFont(new Font("Helvetica", Font.BOLD, 12));
117 border.setTitleColor(Color.black);
118
119 return border;
120
121 }
122
123 JPanel getBottomPanel(){
124 JLabel label;
125 JScrollPane sp;
126
127 GridBagLayout gb = new GridBagLayout();
128 GridBagConstraints gbc = new GridBagConstraints();
129
130 JPanel panel = new JPanel();
131 panel.setLayout(gb);
132
133 label = new JLabel("Reply With ");
134 gbc.anchor = GridBagConstraints.NORTHWEST;
135 gbc.insets = new Insets(0,5,0,0);
136 gbc.gridwidth = 1;
137 gbc.weightx = 0;
138 gbc.fill = GridBagConstraints.NONE;
139 gb.setConstraints(label,gbc);
140 panel.add(label);
141
142 replyWithTF = new JTextArea();
143 replyWithTF.setEditable(false);
144 replyWithTF.setLineWrap(true);
145 replyWithTF.setWrapStyleWord(true);
146 replyWithTF.setBorder(BorderFactory.createEtchedBorder(Color.lightGray,Color.gray));
147 gbc.insets = new Insets(0,5,0,0);
148 gbc.gridwidth = GridBagConstraints.REMAINDER;
149 gbc.weightx = gbc.weighty= 1;
150 gbc.fill = GridBagConstraints.HORIZONTAL;
151 sp = new JScrollPane(replyWithTF);
152 sp.setPreferredSize(new Dimension(10,35));
153 gb.setConstraints(sp,gbc);
154 panel.add(sp);
155
156 label = new JLabel("In Reply To ");
157 gbc.gridwidth = 1;
158 gbc.weightx = 0;
159 gbc.fill = GridBagConstraints.NONE;
160 gbc.insets = new Insets(5,5,0,0);
161 gb.setConstraints(label,gbc);
162 panel.add(label);
163
164 inReplyToTF = new JTextArea();
165 inReplyToTF.setEditable(false);
166 inReplyToTF.setLineWrap(true);
167 inReplyToTF.setWrapStyleWord(true);
168 inReplyToTF.setBorder(BorderFactory.createEtchedBorder(Color.lightGray,Color.gray));
169 gbc.insets = new Insets(5,5,0,0);
170 gbc.gridwidth = GridBagConstraints.REMAINDER;
171 gbc.weightx = gbc.weighty= 1;
172 gbc.fill = GridBagConstraints.HORIZONTAL;
173 sp = new JScrollPane(inReplyToTF);
174 sp.setPreferredSize(new Dimension(10,35));
175 gb.setConstraints(sp,gbc);
176 panel.add(sp);
177
178 label = new JLabel("Content ");
179 gbc.gridwidth = 1;
180 gbc.weightx = 0;
181 gbc.fill = GridBagConstraints.NONE;
182 gbc.insets = new Insets(5,5,0,0);
183 gb.setConstraints(label,gbc);
184 panel.add(label);
185
186 contentTF = new JTextArea();
187 contentTF.setEditable(false);
188 contentTF.setLineWrap(true);
189 contentTF.setWrapStyleWord(true);
190 contentTF.setBorder(BorderFactory.createEtchedBorder(Color.lightGray,Color.gray));
191 gbc.gridwidth = GridBagConstraints.REMAINDER;
192 gbc.weightx = gbc.weighty= 1;
193 gbc.fill = GridBagConstraints.BOTH;
194 gbc.insets = new Insets(5,5,0,0);
195 sp = new JScrollPane(contentTF);
196 sp.setPreferredSize(new Dimension(10,70));
197 gb.setConstraints(sp,gbc);
198 panel.add(sp);
199
200 label = new JLabel("Sent ");
201 gbc.anchor = GridBagConstraints.NORTHWEST;
202 gbc.insets = new Insets(5,5,0,0);
203 gbc.gridwidth = 1;
204 gbc.weightx = 0;
205 gbc.fill = GridBagConstraints.NONE;
206 gb.setConstraints(label,gbc);
207 panel.add(label);
208
209 sendTimeTF = new JTextArea();
210 sendTimeTF.setEditable(false);
211 sendTimeTF.setLineWrap(true);
212 sendTimeTF.setWrapStyleWord(true);
213 sendTimeTF.setBorder(BorderFactory.createEtchedBorder(Color.lightGray,Color.gray));
214 gbc.insets = new Insets(5,5,0,0);
215 gbc.gridwidth = GridBagConstraints.REMAINDER;
216 gbc.weightx = gbc.weighty= 1;
217 gbc.fill = GridBagConstraints.HORIZONTAL;
218 sp = new JScrollPane(sendTimeTF);
219 sp.setPreferredSize(new Dimension(10,35));
220 gb.setConstraints(sp,gbc);
221 panel.add(sp);
222
223 label = new JLabel("Recieved ");
224 gbc.gridwidth = 1;
225 gbc.weightx = 0;
226 gbc.insets = new Insets(5,5,0,0);
227 gbc.fill = GridBagConstraints.NONE;
228 gb.setConstraints(label,gbc);
229 panel.add(label);
230
231 receiveTimeTF = new JTextArea();
232 receiveTimeTF.setEditable(false);
233 receiveTimeTF.setLineWrap(true);
234 receiveTimeTF.setWrapStyleWord(true);
235 receiveTimeTF.setBorder(BorderFactory.createEtchedBorder(Color.lightGray,Color.gray));
236 gbc.insets = new Insets(5,5,0,0);
237 gbc.gridwidth = GridBagConstraints.REMAINDER;
238 gbc.weightx = gbc.weighty= 1;
239 gbc.fill = GridBagConstraints.HORIZONTAL;
240 sp = new JScrollPane(receiveTimeTF);
241 sp.setPreferredSize(new Dimension(10,35));
242 gb.setConstraints(sp,gbc);
243 panel.add(sp);
244
245
246
247 label = new JLabel("Ontology ");
248 gbc.gridwidth = 1;
249 gbc.weightx = 0;
250 gbc.fill = GridBagConstraints.NONE;
251 gbc.insets = new Insets(5,5,0,0);
252 gb.setConstraints(label,gbc);
253
254
255 ontologyTF = new JTextArea();
256 ontologyTF.setEditable(false);
257 ontologyTF.setLineWrap(true);
258 ontologyTF.setWrapStyleWord(true);
259 ontologyTF.setBorder(BorderFactory.createEtchedBorder(Color.lightGray,Color.gray));
260 gbc.insets = new Insets(5,5,0,0);
261 gbc.gridwidth = GridBagConstraints.REMAINDER;
262 gbc.weightx = gbc.weighty= 1;
263 gbc.fill = GridBagConstraints.HORIZONTAL;
264 sp = new JScrollPane(ontologyTF);
265 sp.setPreferredSize(new Dimension(10,35));
266 gb.setConstraints(sp,gbc);
267
268
269 label = new JLabel("Language ");
270 gbc.gridwidth = 1;
271 gbc.weightx = 0;
272 gbc.fill = GridBagConstraints.NONE;
273 gbc.insets = new Insets(5,5,0,0);
274 gb.setConstraints(label,gbc);
275
276
277 languageTF = new JTextArea();
278 languageTF.setEditable(false);
279 languageTF.setLineWrap(true);
280 languageTF.setWrapStyleWord(true);
281 languageTF.setBorder(BorderFactory.createEtchedBorder(Color.lightGray,Color.gray));
282 gbc.gridwidth = GridBagConstraints.REMAINDER;
283 gbc.insets = new Insets(5,5,0,0);
284 gbc.weightx = gbc.weighty= 1;
285 gbc.fill = GridBagConstraints.HORIZONTAL;
286 sp = new JScrollPane(languageTF);
287 sp.setPreferredSize(new Dimension(10,35));
288 gb.setConstraints(sp,gbc);
289
290
291 return panel;
292 }
293
294
295 void setMailFields(int row){
296 Performative msg = msgHandlerBuffer.getMessage(row);
297
298 replyWithTF.setText(msg.getReplyWith());
299 inReplyToTF.setText(msg.getInReplyTo());
300 contentTF.setText(msg.getContent());
301
302
303
304
305 Object obj = msg.getSendTime();
306 if ( obj != null )
307 sendTimeTF.setText(obj.toString());
308 else
309 sendTimeTF.setText(null);
310
311 obj = msg.getReceiveTime();
312 if ( obj != null )
313 receiveTimeTF.setText(obj.toString());
314 else
315 receiveTimeTF.setText(null);
316 }
317
318
319
320 public void valueChanged(ListSelectionEvent e) {
321 int selectedRow;
322 if (e.getSource() == table.getSelectionModel() ) {
323
324 selectedRow = table.getSelectedRow();
325 if (selectedRow >= 0 && selectedRow < msgHandlerBuffer.getRowCount()) {
326 setMailFields(selectedRow);
327 validate();
328
329 }
330 }
331
332 }
333
334
335
336 void reSize(){
337 setSize(getWidth()+1,getHeight());
338 setSize(getWidth()-1,getHeight());
339 }
340
341 }