KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > sendmail > MailClient


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.sendmail;
20
21 import org.lucane.client.*;
22 import org.lucane.client.widgets.*;
23 import org.lucane.common.*;
24 import org.lucane.common.net.ObjectConnection;
25
26 import java.awt.*;
27 import java.awt.event.*;
28 import java.util.HashMap JavaDoc;
29
30 import javax.swing.*;
31
32 public class MailClient extends StandalonePlugin implements ActionListener
33 {
34     /* dialog components */
35     private ManagedWindow window;
36     private JTextField from;
37     private JTextField to;
38     private JTextField cc;
39     private JTextField bcc;
40     private JTextField subject;
41     private JTextField content;
42     private JTextField attachName;
43     private JTextField attachData;
44     private JButton btnSend;
45
46     private ConnectInfo sendmail;
47
48     public MailClient()
49     {
50     }
51
52     public Plugin newInstance(ConnectInfo[] friends)
53     {
54         return new MailClient();
55     }
56
57     public void start()
58     {
59         this.sendmail = Communicator.getInstance().getConnectInfo("org.lucane.applications.sendmail");
60         
61         window = new ManagedWindow(this, getTitle());
62         window.setExitPluginOnClose(true);
63         window.getContentPane().setLayout(new GridLayout(0, 2));
64         
65         from = new JTextField();
66         to = new JTextField();
67         cc = new JTextField();
68         bcc = new JTextField();
69         subject = new JTextField();
70         content = new JTextField();
71         attachName = new JTextField();
72         attachData = new JTextField();
73         btnSend = new JButton(tr("send"));
74         btnSend.addActionListener(this);
75         
76         window.getContentPane().add(new JLabel(tr("from")));
77         window.getContentPane().add(from);
78         window.getContentPane().add(new JLabel(tr("to")));
79         window.getContentPane().add(to);
80         window.getContentPane().add(new JLabel(tr("cc")));
81         window.getContentPane().add(cc);
82         window.getContentPane().add(new JLabel(tr("bcc")));
83         window.getContentPane().add(bcc);
84         window.getContentPane().add(new JLabel(tr("subject")));
85         window.getContentPane().add(subject);
86         window.getContentPane().add(new JLabel(tr("content")));
87         window.getContentPane().add(content);
88         window.getContentPane().add(new JLabel(tr("attach.name")));
89         window.getContentPane().add(attachName);
90         window.getContentPane().add(new JLabel(tr("attach.data")));
91         window.getContentPane().add(attachData);
92         window.getContentPane().add(new JLabel(""));
93         window.getContentPane().add(btnSend);
94         window.show();
95     }
96
97     public void actionPerformed(ActionEvent ae)
98     {
99         HashMap JavaDoc map = new HashMap JavaDoc();
100         map.put("from", from.getText());
101         map.put("to", to.getText());
102         map.put("cc", cc.getText());
103         map.put("bcc", bcc.getText());
104         map.put("subject", subject.getText());
105         map.put("content", content.getText());
106         
107         if(attachName.getText().length() > 0 || attachData.getText().length() > 0)
108         {
109           HashMap JavaDoc attach = new HashMap JavaDoc();
110           attach.put(attachName.getText(), attachData.getText());
111           map.put("attach", attach);
112         }
113         
114         try
115         {
116             ObjectConnection oc = Communicator.getInstance().sendMessageTo(sendmail, "org.lucane.applications.sendmail", map);
117             String JavaDoc response = oc.readString();
118             oc.close();
119             
120             if (response.startsWith("FAILED"))
121                 DialogBox.error(tr("failed") + response.substring(7));
122                         else
123                         {
124                           DialogBox.info(tr("success"));
125                           window.dispose();
126                           exit();
127                         }
128         }
129         catch (Exception JavaDoc e)
130         {
131             DialogBox.error(tr("error") + e);
132         }
133     }
134 }
135
Popular Tags