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