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

📄 adialogdialog.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 java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;
import java.util.*;

import org.compiere.*;
import org.compiere.util.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.db.*;

/**
 *  Dialog Windows
 *
 *  @author 	Jorg Janke
 *  @version 	$Id: ADialogDialog.java,v 1.17 2003/04/06 01:59:25 jjanke Exp $
 */
public final class ADialogDialog extends JDialog implements ActionListener
{
	/**
	 *	Create Dialog Window for Frame
	 *
	 * @param frame
	 * @param title
	 * @param message
	 * @param messageType
	 */
	public ADialogDialog(Frame frame, String title, String message, int messageType)
	{
		super (frame, title, frame != null);
		common (message, messageType);
		AEnv.showCenterWindow(frame, this);
	}	//	ADialogDialog

	/**
	 *	Create Dialog Window for Dialog
	 *
	 * @param dialog
	 * @param title
	 * @param message
	 * @param messageType
	 */
	public ADialogDialog(Dialog dialog, String title, String message, int messageType)
	{
		super (dialog, title, dialog != null);
		common (message, messageType);
		AEnv.showCenterWindow(dialog, this);
	}	//	ADialogDialog

	/**
	 *	Common Init
	 *  @param message
	 *  @param messageType
	 */
	private void common (String message, int messageType)
	{
	//	Log.trace(Log.l3_Util, "ADialogDialog");
		CompiereColor.setBackground(this);
		try
		{
			setInfoMessage (message);
			jbInit();
			setInfoIcon (messageType);
		}
		catch(Exception ex)
		{
			Log.error("ADialogDialog.common - " + ex.getMessage());
		}
		//  Default Button
		this.getRootPane().setDefaultButton(confirmPanel.getOKButton());
	}	//	common

	/**
	 *  Window Events - requestFocus
	 *  @param e
	 */
	protected void processWindowEvent(WindowEvent e)
	{
		super.processWindowEvent(e);
		if (e.getID() == WindowEvent.WINDOW_OPENED)
			confirmPanel.getOKButton().requestFocusInWindow();
	}   //  processWindowEvent

	/** Answer OK (0)       */
	public static int	A_OK = 0;
	/** Answer Cancel (1)   */
	public static int	A_CANCEL = 1;

	private int			m_returnCode = A_CANCEL;

	private static Icon i_inform = Env.getImageIcon("Inform32.gif");
	private static Icon i_warn = Env.getImageIcon("Warn32.gif");
	private static Icon i_question = Env.getImageIcon("Question32.gif");
	private static Icon i_error = Env.getImageIcon("Error32.gif");

	private JMenuBar menuBar = new JMenuBar();
	private JMenu mFile = AEnv.getMenu("File");
	private JMenuItem mEMail = new JMenuItem();
	private JMenuItem mPrintScreen = new JMenuItem();
	private JMenuItem mScreenShot = new JMenuItem();
	private JMenuItem mEnd = new JMenuItem();
	private JMenuItem mPreference = new JMenuItem();
	private ConfirmPanel confirmPanel = new ConfirmPanel(true);
	private CPanel westPanel = new CPanel();
	private CLabel iconLabel = new CLabel();
	private GridBagLayout westLayout = new GridBagLayout();
	private CText info = new CText (3, 40);
	private GridBagLayout infoLayout = new GridBagLayout();
	private CPanel infoPanel = new CPanel();

	/**
	 *	Static Constructor
	 *  @throws Exception
	 */
	private void jbInit() throws Exception
	{
		this.setJMenuBar(menuBar);
		//
		mEMail.setIcon(Env.getImageIcon("SendMail16.gif"));
		mEMail.setText(Msg.getMsg(Env.getCtx(), "EMail"));
		mEMail.addActionListener(this);
		mPrintScreen.setIcon(Env.getImageIcon("PrintScreen16.gif"));
		mPrintScreen.setText(Msg.getMsg(Env.getCtx(), "PrintScreen"));
		mPrintScreen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, 0));
		mPrintScreen.addActionListener(this);
		mScreenShot.setIcon(Env.getImageIcon("ScreenShot16.gif"));
		mScreenShot.setText(Msg.getMsg(Env.getCtx(), "ScreenShot"));
		mScreenShot.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, Event.SHIFT_MASK));
		mScreenShot.addActionListener(this);
		mPreference.setIcon(Env.getImageIcon("Preference16.gif"));
		mPreference.setText(Msg.getMsg(Env.getCtx(), "Preference"));
		mPreference.addActionListener(this);
		mEnd.setIcon(Env.getImageIcon("End16.gif"));
		mEnd.setText(Msg.getMsg(Env.getCtx(), "End"));
		mEnd.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.ALT_MASK));
		mEnd.addActionListener(this);
		//
		westPanel.setLayout(westLayout);
		westPanel.setName("westPanel");
		westPanel.setRequestFocusEnabled(false);
		infoPanel.setLayout(infoLayout);
		infoPanel.setName("infoPanel");
		infoPanel.setRequestFocusEnabled(false);
		this.getContentPane().add(confirmPanel, BorderLayout.SOUTH);
		this.getContentPane().add(westPanel, BorderLayout.WEST);
		westPanel.add(iconLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));
		this.getContentPane().add(infoPanel, BorderLayout.CENTER);
		infoPanel.add(info, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
			,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));
		//
		menuBar.add(mFile);
		mFile.add(mPrintScreen);
		mFile.add(mScreenShot);
		mFile.addSeparator();
		mFile.add(mEMail);
		mFile.add(mPreference);
		mFile.addSeparator();
		mFile.add(mEnd);
		//
		confirmPanel.addActionListener(this);
	}	//	jbinit

	/**
	 *	Calculate Size
	 *  @param message
	 */
	private void setInfoMessage(String message)
	{
		int rows = 0;
		int cols = 0;

		StringTokenizer st = new StringTokenizer(message, "\n", false);
		while (st.hasMoreTokens())
		{
			rows++;
			int length = st.nextToken().length();
			cols = Math.max(cols, length);
			while (length > 35)
			{
				rows++;
				length -= 35;
			}
		}

		rows = Math.max(2, rows);
		rows = Math.min(10, rows);
		cols = Math.max(30, cols);
		cols = Math.min(40, cols);

		info.setText(message);
		info.setRows(rows);
		info.setColumns(cols);
		info.setRequestFocusEnabled(false);
		info.setReadWrite(false);
		info.setOpaque(false);
		info.setLineWrap(true);
		info.setWrapStyleWord(true);
		info.setBorder(null);
		//
		info.setCaretPosition(0);
	//	Log.clear("Rows=" + info.getRows() + ", Cols=" + info.getColumns());
	}	//	calculateSize

	/*************************************************************************/

	/**
	 *	Set Info
	 *  @param messageType
	 */
	private void setInfoIcon (int messageType)
	{
		confirmPanel.getCancelButton().setVisible(false);
		//
		switch (messageType)
		{
			case JOptionPane.ERROR_MESSAGE:
				iconLabel.setIcon(i_error);
				break;
			case JOptionPane.INFORMATION_MESSAGE:
				iconLabel.setIcon(i_inform);
				break;
			case JOptionPane.QUESTION_MESSAGE:
				confirmPanel.getCancelButton().setVisible(true);
				iconLabel.setIcon(i_question);
				break;
			case JOptionPane.WARNING_MESSAGE:
				iconLabel.setIcon(i_warn);
				break;

			case JOptionPane.PLAIN_MESSAGE:
			default:
				break;
		}	//	switch
	}	//	setInfo

	/*************************************************************************/

	/**
	 *	ActionListener
	 *  @param e
	 */
	public void actionPerformed (ActionEvent e)
	{
		if (e.getActionCommand().equals(ConfirmPanel.A_OK))
		{
			m_returnCode = A_OK;
			dispose();
		}
		else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL) || e.getSource() == mEnd)
		{
			m_returnCode = A_CANCEL;
			dispose();
		}
		else if (e.getSource() == mPrintScreen)
			printScreen();
		else if (e.getSource() == mEMail)
		{
			String title = getTitle();
			String text = info.getText();
			dispose();                  //  otherwise locking
			createSupportEMail(title, text);
		}
		else if (e.getSource() == mPreference)
		{
			Preference p = new Preference(null, 0, true);
			p.show();
		}
	}	//	actionPerformed

	/**
	 *	Get Return Code
	 *  @return return code
	 */
	public int getReturnCode()
	{
		return m_returnCode;
	}	//	getReturnCode

	/**
	 *	PrintScreen
	 */
	private void printScreen()
	{
		PrintScreenPainter.printScreen(this);
	}	//	printScreen

	/**
	 *	Create Support EMail
	 *  @param subject
	 *  @param message
	 */
	public static void createSupportEMail(String subject, String message)
	{
		Log.trace(Log.l3_Util, "CreateSupportEMail");
		String to = Compiere.getSupportEMail();
		String from = EMail.getCurrentUserEMail(Env.getCtx(), false);
		//
		StringBuffer myMessage = new StringBuffer(message);
		myMessage.append("\n\n").append(AboutBox.getInfo());
		Log.getInfo(myMessage, Env.getCtx());

		EMailDialog emd = new EMailDialog
			(Msg.getMsg(Env.getCtx(), "EMailSupport"),
			from, to, "Support: " + subject, myMessage.toString());
	}	//	createEmail

}	//	ADialogDialog

⌨️ 快捷键说明

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