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