KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > EMailDialog


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps;
15
16 import java.awt.*;
17 import javax.swing.*;
18 import java.awt.event.*;
19 import java.beans.*;
20 import java.rmi.*;
21
22 import org.compiere.util.*;
23 import org.compiere.swing.*;
24
25 /**
26  * EMail Dialog
27  *
28  * @author Jorg Janke
29  * @version $Id: EMailDialog.java,v 1.7 2003/11/01 02:32:21 jjanke Exp $
30  */

31 public class EMailDialog extends CDialog implements ActionListener
32 {
33     /** @todo via Server */
34
35     /**
36      * EMail Dialog
37      * @param owner calling window
38      * @param title title
39      * @param from from
40      * @param to to
41      * @param subject subject
42      * @param message message
43      */

44     public EMailDialog (Dialog owner, String JavaDoc title, String JavaDoc from, String JavaDoc to,
45         String JavaDoc subject, String JavaDoc message)
46     {
47         super (owner, title, true);
48         commonInit(from, to, subject, message);
49     } // EmailDialog
50

51     /**
52      * EMail Dialog
53      * @param owner calling window
54      * @param title title
55      * @param from from
56      * @param to to
57      * @param subject subject
58      * @param message message
59      */

60     public EMailDialog (Frame owner, String JavaDoc title, String JavaDoc from, String JavaDoc to,
61         String JavaDoc subject, String JavaDoc message)
62     {
63         super (owner, title, true);
64         commonInit(from, to, subject, message);
65     } // EmailDialog
66

67     /**
68      * Common Init
69      * @param from from
70      * @param to to
71      * @param subject subject
72      * @param message message
73      */

74     private void commonInit (String JavaDoc from, String JavaDoc to,
75         String JavaDoc subject, String JavaDoc message)
76     {
77         try
78         {
79             jbInit();
80         }
81         catch(Exception JavaDoc ex)
82         {
83             Log.error("EMailDialog", ex);
84         }
85         set(from, to, subject, message);
86         AEnv.showCenterScreen(this);
87     } // commonInit
88

89
90     private String JavaDoc m_smtp;
91     private String JavaDoc m_to;
92     private String JavaDoc m_from;
93     private String JavaDoc m_subject;
94     private String JavaDoc m_message;
95
96
97     private CPanel mainPanel = new CPanel();
98     private BorderLayout mainLayout = new BorderLayout();
99     private CPanel headerPanel = new CPanel();
100     private GridBagLayout headerLayout = new GridBagLayout();
101     private CTextField fFrom = new CTextField(20);
102     private CTextField fTo = new CTextField(20);
103     private CTextField fSubject = new CTextField(40);
104     private CLabel lFrom = new CLabel();
105     private CLabel lTo = new CLabel();
106     private CLabel lSubject = new CLabel();
107     private JScrollPane messagePane = new JScrollPane();
108     private JTextPane fMessage = new JTextPane();
109     private ConfirmPanel confirmPanel = new ConfirmPanel(true);
110     private StatusBar statusBar = new StatusBar();
111
112     /**
113      * Static Init
114      */

115     void jbInit() throws Exception JavaDoc
116     {
117         mainPanel.setLayout(mainLayout);
118         headerPanel.setLayout(headerLayout);
119         lFrom.setText("From");
120         lTo.setText("To");
121         lSubject.setText("Subject");
122         mainLayout.setHgap(5);
123         mainLayout.setVgap(5);
124         messagePane.setPreferredSize(new Dimension(150, 150));
125         getContentPane().add(mainPanel);
126         mainPanel.add(headerPanel, BorderLayout.NORTH);
127         headerPanel.add(fFrom, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
128             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 10), 0, 0));
129         headerPanel.add(fTo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
130             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 10), 0, 0));
131         headerPanel.add(fSubject, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
132             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 10), 1, 0));
133         headerPanel.add(lFrom, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
134             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 0, 5), 0, 0));
135         headerPanel.add(lTo, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
136             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 0, 5), 0, 0));
137         headerPanel.add(lSubject, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
138             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 10, 0, 5), 0, 0));
139         mainPanel.add(messagePane, BorderLayout.CENTER);
140         messagePane.getViewport().add(fMessage, null);
141         //
142
mainPanel.add (confirmPanel, BorderLayout.SOUTH);
143         this.getContentPane().add(statusBar, BorderLayout.SOUTH);
144         confirmPanel.addActionListener(this);
145         statusBar.setStatusDB(null);
146     } // jbInit
147

148     /**
149      * Set all properties
150      */

151     public void set (String JavaDoc from, String JavaDoc to, String JavaDoc subject, String JavaDoc message)
152     {
153         // Translation
154
lFrom.setText(Msg.getMsg(Env.getCtx(), "From") + ":");
155         lTo.setText(Msg.getMsg(Env.getCtx(), "To") + ":");
156         lSubject.setText(Msg.getMsg(Env.getCtx(), "Subject") + ":");
157
158         // Content
159
setFrom(from);
160         setTo(to);
161         setSubject(subject);
162         setMessage(message);
163         //
164
m_smtp = EMailUtil.getSmtpHost(Env.getCtx());
165         statusBar.setStatusLine(m_smtp);
166     } // set
167

168     /**
169      * Set Address
170      */

171     public void setTo(String JavaDoc newTo)
172     {
173         m_to = newTo;
174         fTo.setText(m_to);
175     }
176
177     /**
178      * Get Address
179      */

180     public String JavaDoc getTo()
181     {
182         m_to = fTo.getText();
183         return m_to;
184     }
185
186     /**
187      * Set Sender
188      */

189     public void setFrom(String JavaDoc newFrom)
190     {
191         m_from = newFrom;
192         fFrom.setText(m_from);
193     }
194
195     /**
196      * Get Sender
197      */

198     public String JavaDoc getFrom()
199     {
200         m_from = fFrom.getText();
201         return m_from;
202     }
203
204     /**
205      * Set Subject
206      */

207     public void setSubject(String JavaDoc newSubject)
208     {
209         m_subject = newSubject;
210         fSubject.setText(m_subject);
211     }
212
213     /**
214      * Get Subject
215      */

216     public String JavaDoc getSubject()
217     {
218         m_subject = fSubject.getText();
219         return m_subject;
220     }
221
222     /**
223      * Set Message
224      */

225     public void setMessage(String JavaDoc newMessage)
226     {
227         m_message = newMessage;
228         fMessage.setText(m_message);
229         fMessage.setCaretPosition(0);
230     } // setMessage
231

232     /**
233      * Get Message
234      */

235     public String JavaDoc getMessage()
236     {
237         m_message = fMessage.getText();
238         return m_message;
239     } // getMessage
240

241     /**
242      * Action Listener - Send email
243      */

244     public void actionPerformed(ActionEvent e)
245     {
246         if (e.getActionCommand().equals(ConfirmPanel.A_OK))
247         {
248             setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
249             confirmPanel.getOKButton().setEnabled(false);
250
251             EMail em = new EMail(m_smtp, getFrom(), getTo(), getSubject(), getMessage());
252             String JavaDoc status = em.send();
253             if (status.equals(EMail.SENT_OK))
254             {
255                 ADialog.info(0, this, "MessageSent");
256                 dispose();
257             }
258             else
259                 ADialog.error(0, this, "MessageNotSent", status);
260             setCursor(Cursor.getDefaultCursor());
261         }
262         else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
263             dispose();
264
265     } // actionPerformed
266

267 } // VEMailDialog
268

269
Popular Tags