1 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 31 public class EMailDialog extends CDialog implements ActionListener 32 { 33 34 35 44 public EMailDialog (Dialog owner, String title, String from, String to, 45 String subject, String message) 46 { 47 super (owner, title, true); 48 commonInit(from, to, subject, message); 49 } 51 60 public EMailDialog (Frame owner, String title, String from, String to, 61 String subject, String message) 62 { 63 super (owner, title, true); 64 commonInit(from, to, subject, message); 65 } 67 74 private void commonInit (String from, String to, 75 String subject, String message) 76 { 77 try 78 { 79 jbInit(); 80 } 81 catch(Exception ex) 82 { 83 Log.error("EMailDialog", ex); 84 } 85 set(from, to, subject, message); 86 AEnv.showCenterScreen(this); 87 } 89 90 private String m_smtp; 91 private String m_to; 92 private String m_from; 93 private String m_subject; 94 private String 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 115 void jbInit() throws Exception 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 mainPanel.add (confirmPanel, BorderLayout.SOUTH); 143 this.getContentPane().add(statusBar, BorderLayout.SOUTH); 144 confirmPanel.addActionListener(this); 145 statusBar.setStatusDB(null); 146 } 148 151 public void set (String from, String to, String subject, String message) 152 { 153 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 setFrom(from); 160 setTo(to); 161 setSubject(subject); 162 setMessage(message); 163 m_smtp = EMailUtil.getSmtpHost(Env.getCtx()); 165 statusBar.setStatusLine(m_smtp); 166 } 168 171 public void setTo(String newTo) 172 { 173 m_to = newTo; 174 fTo.setText(m_to); 175 } 176 177 180 public String getTo() 181 { 182 m_to = fTo.getText(); 183 return m_to; 184 } 185 186 189 public void setFrom(String newFrom) 190 { 191 m_from = newFrom; 192 fFrom.setText(m_from); 193 } 194 195 198 public String getFrom() 199 { 200 m_from = fFrom.getText(); 201 return m_from; 202 } 203 204 207 public void setSubject(String newSubject) 208 { 209 m_subject = newSubject; 210 fSubject.setText(m_subject); 211 } 212 213 216 public String getSubject() 217 { 218 m_subject = fSubject.getText(); 219 return m_subject; 220 } 221 222 225 public void setMessage(String newMessage) 226 { 227 m_message = newMessage; 228 fMessage.setText(m_message); 229 fMessage.setCaretPosition(0); 230 } 232 235 public String getMessage() 236 { 237 m_message = fMessage.getText(); 238 return m_message; 239 } 241 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 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 } 267 } 269 | Popular Tags |