⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emaildialog.java

📁 Java写的ERP系统
💻 JAVA
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is                  Compiere  ERP & CRM  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.apps;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.beans.*;
import java.rmi.*;

import org.compiere.util.*;

/**
 *	EMail Dialog
 *
 *  @author 	Jorg Janke
 *  @version 	$Id: EMailDialog.java,v 1.5 2002/09/06 02:52:58 jjanke Exp $
 */
public class EMailDialog extends JDialog implements ActionListener
{
	/** @todo via Server */

	/**
	 *	EMail
	 */
	public EMailDialog (String title, String from, String to, String subject, String message)
	{
		super ();
		setTitle(title);
		try
		{
			jbInit();
		}
		catch(Exception ex)
		{
			Log.error("EMailDialog", ex);
		}
		set(from, to, subject, message);
		AEnv.showCenterScreen(this);
	}	//	EmailDialog

	private String  m_smtp;
	private String  m_to;
	private String  m_from;
	private String  m_subject;
	private String  m_message;


	private JPanel mainPanel = new JPanel();
	private BorderLayout mainLayout = new BorderLayout();
	private JPanel headerPanel = new JPanel();
	private GridBagLayout headerLayout = new GridBagLayout();
	private JTextField fFrom = new JTextField(20);
	private JTextField fTo = new JTextField(20);
	private JTextField fSubject = new JTextField(40);
	private	JLabel lFrom = new JLabel();
	private JLabel lTo = new JLabel();
	private JLabel lSubject = new JLabel();
	private JScrollPane messagePane = new JScrollPane();
	private JTextPane fMessage = new JTextPane();
	private ConfirmPanel confirmPanel = new ConfirmPanel(true);
	private StatusBar statusBar = new StatusBar();

	/**
	 *	Static Init
	 */
	void jbInit() throws Exception
	{
		mainPanel.setLayout(mainLayout);
		headerPanel.setLayout(headerLayout);
		lFrom.setText("From");
		lTo.setText("To");
		lSubject.setText("Subject");
		mainLayout.setHgap(5);
		mainLayout.setVgap(5);
		messagePane.setPreferredSize(new Dimension(150, 150));
		getContentPane().add(mainPanel);
		mainPanel.add(headerPanel, BorderLayout.NORTH);
		headerPanel.add(fFrom, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 10), 0, 0));
		headerPanel.add(fTo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 10), 0, 0));
		headerPanel.add(fSubject, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 10), 1, 0));
		headerPanel.add(lFrom, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 0, 5), 0, 0));
		headerPanel.add(lTo, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 0, 5), 0, 0));
		headerPanel.add(lSubject, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 10, 0, 5), 0, 0));
		mainPanel.add(messagePane, BorderLayout.CENTER);
		messagePane.getViewport().add(fMessage, null);
		//
		mainPanel.add (confirmPanel, BorderLayout.SOUTH);
		this.getContentPane().add(statusBar, BorderLayout.SOUTH);
		confirmPanel.addActionListener(this);
		statusBar.setStatusDB(null);
	}	//	jbInit

	/**
	 *	Set all properties
	 */
	public void set (String from, String to, String subject, String message)
	{
		//	Translation
		lFrom.setText(Msg.getMsg(Env.getCtx(), "From") + ":");
		lTo.setText(Msg.getMsg(Env.getCtx(), "To") + ":");
		lSubject.setText(Msg.getMsg(Env.getCtx(), "Subject") + ":");

		//	Content
		setFrom(from);
		setTo(to);
		setSubject(subject);
		setMessage(message);
		//
		m_smtp = EMail.getCurrentSmtpHost(Env.getCtx());
		statusBar.setStatusLine(m_smtp);
	}	//	set

	/**
	 *  Set Address
	 */
	public void setTo(String newTo)
	{
		m_to = newTo;
		fTo.setText(m_to);
	}

	/**
	 *  Get Address
	 */
	public String getTo()
	{
		m_to = fTo.getText();
		return m_to;
	}

	/**
	 *  Set Sender
	 */
	public void setFrom(String newFrom)
	{
		m_from = newFrom;
		fFrom.setText(m_from);
	}

	/**
	 *  Get Sender
	 */
	public String getFrom()
	{
		m_from = fFrom.getText();
		return m_from;
	}

	/**
	 *  Set Subject
	 */
	public void setSubject(String newSubject)
	{
		m_subject = newSubject;
		fSubject.setText(m_subject);
	}

	/**
	 *  Get Subject
	 */
	public String getSubject()
	{
		m_subject = fSubject.getText();
		return m_subject;
	}

	/**
	 *  Set Message
	 */
	public void setMessage(String newMessage)
	{
		m_message = newMessage;
		fMessage.setText(m_message);
		fMessage.setCaretPosition(0);
	}   //  setMessage

	/**
	 *  Get Message
	 */
	public String getMessage()
	{
		m_message = fMessage.getText();
		return m_message;
	}   //  getMessage

	/**
	 * 	Action Listener - Send email
	 */
	public void actionPerformed(ActionEvent e)
	{
		if (e.getActionCommand().equals(ConfirmPanel.A_OK))
		{
			setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
			confirmPanel.getOKButton().setEnabled(false);

			EMail em = new EMail(m_smtp, getFrom(), getTo(), getSubject(), getMessage());
			String status = em.send();
			if (status.equals(EMail.SENT_OK))
			{
				ADialog.info(0, this, "MessageSent");
				dispose();
			}
			else
				ADialog.error(0, this, "MessageNotSent", status);
			setCursor(Cursor.getDefaultCursor());
		}
		else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
			dispose();

	}	//	actionPerformed

}	//	VEMailDialog

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -