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

📄 statusbar.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 javax.swing.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

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

/**
 *  Status Bar
 *
 *  @author 	Jorg Janke
 *  @version 	$Id: StatusBar.java,v 1.10 2002/09/03 05:11:09 jjanke Exp $
 */
public class StatusBar extends CPanel
{
	/**
	 *	Standard Status Bar
	 */
	public StatusBar()
	{
		this(false);
	}	//	StatusBar

	/**
	 *	Status Bar with additional info
	 *  @param withInfo with info
	 */
	public StatusBar (boolean withInfo)
	{
		super();
		try
		{
			jbInit();
		}
		catch (Exception e)
		{}
		this.setName("statusBar");
		if (!withInfo)
			infoLine.setVisible(false);
	}	//	StatusBar

	private BorderLayout mainLayout = new BorderLayout();
	private JLabel statusLine = new JLabel();
	private JLabel statusDB = new JLabel();
	private JLabel infoLine = new JLabel();
	//
	private boolean		mt_error;
	private String		mt_text;
	//
	private String      m_text;
	private Timestamp   m_created;
	private Object      m_createdBy;
	private Timestamp   m_updated;
	private Object      m_updatedBy;
	private String      m_info;

	/**
	 *	Static Init
	 *  @throws Exception
	 */
	private void jbInit() throws Exception
	{
		statusLine.setBorder(BorderFactory.createEtchedBorder());
		statusLine.setText("statusLine");
		statusLine.setOpaque(false);
		statusDB.setForeground(Color.blue);
		statusDB.setBorder(BorderFactory.createEtchedBorder());
		statusDB.setText("#");
		statusDB.setOpaque(false);
		statusDB.addMouseListener(new StatusBar_mouseAdapter(this));
		this.setLayout(mainLayout);
		infoLine.setFont(CompierePLAF.getFont_Label());
		infoLine.setBorder(BorderFactory.createRaisedBevelBorder());
		infoLine.setHorizontalAlignment(SwingConstants.CENTER);
		infoLine.setHorizontalTextPosition(SwingConstants.CENTER);
		infoLine.setText("info");
		mainLayout.setHgap(2);
		mainLayout.setVgap(2);
		this.add(statusLine, BorderLayout.CENTER);
		this.add(statusDB, BorderLayout.EAST);
		this.add(infoLine, BorderLayout.NORTH);
	}	//	jbInit

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

	/**
	 *	Set Standard Status Line (non error)
	 *  @param text text
	 */
	public void setStatusLine (String text)
	{
		if (text == null)
			setStatusLine("", false);
		else
			setStatusLine(text, false);
	}	//	setStatusLine

	/**
	 *	Set Status Line
	 *  @param text text
	 *  @param error error
	 */
	public void setStatusLine (String text, boolean error)
	{
		mt_error = error;
		mt_text = text;
		if (mt_error)
			statusLine.setForeground(CompierePLAF.getTextColor_Issue());
		else
			statusLine.setForeground(CompierePLAF.getTextColor_OK());
		statusLine.setText(" " + mt_text);
		//
		Thread.yield();
	}	//	setStatusLine

	/**
	 *	Get Status Line text
	 *  @return StatusLine text
	 */
	public String getStatusLine ()
	{
		return statusLine.getText().trim();
	}	//	setStatusLine

	/**
	 *  Set ToolTip of StatusLine
	 *  @param tip tip
	 */
	public void setStatusToolTip (String tip)
	{
		statusLine.setToolTipText(tip);
	}   //  setStatusToolTip

	/**
	 *	Set Status DB Info
	 *  @param text text
	 *  @param created created
	 *  @param createdBy breated by
	 *  @param updated updated
	 *  @param updatedBy updated by
	 *  @param info info
	 */
	public void setStatusDB (String text, Timestamp created,
		Object createdBy, Timestamp updated, Object updatedBy, String info)
	{
	//	Log.trace(Log.l2_Sub, "StatusBar.setStatusDB - " + text + " - " + created + "/" + createdBy);
		if (text == null || text.length() == 0)
		{
			statusDB.setText("");
			statusDB.setVisible(false);
		}
		else
		{
			StringBuffer sb = new StringBuffer (" ");
			sb.append(text).append(" ");
			statusDB.setText(sb.toString());
			if (!statusDB.isVisible())
				statusDB.setVisible(true);
		}

		//  Save
		m_text = text;
		m_created = created;
		m_createdBy = createdBy;
		m_updated = updated;
		m_updatedBy = updatedBy;
		m_info = info;
	}	//	setStatusDB

	/**
	 *	Set Status DB Info
	 *  @param text text
	 */
	public void setStatusDB (String text)
	{
		setStatusDB (text, null, null, null, null, null);
	}   //  setStatusDB

	/**
	 *	Set Status DB Info
	 *  @param no no
	 */
	public void setStatusDB (int no)
	{
		setStatusDB (String.valueOf(no), null, null, null, null, null);
	}   //  setStatusDB

	/**
	 *	Set Info Line
	 *  @param text text
	 */
	public void setInfo (String text)
	{
		if (!infoLine.isVisible())
			infoLine.setVisible(true);
		infoLine.setText(text);
	}	//	setInfo

	/**
	 *	Add Component to East of StatusBar
	 *  @param component component
	 */
	public void addStatusComponent (JComponent component)
	{
		this.add(component, BorderLayout.EAST);
	}   //  addStatusComponent

	/**
	 *  Show WHO
	 *  @param e event
	 */
	void mouseClicked(MouseEvent e)
	{
		Log.trace(Log.l2_Sub, "StatusBar.mouseClicked - WHO");
		if (m_created == null && m_updated == null)
			return;

		//  Get Person Info
		String createdBy = null;
		String updatedBy = null;
		int createdByint = 0;
		if (m_createdBy != null)
			createdByint = Integer.parseInt(m_createdBy.toString());
		int updatedByint = 0;
		if (m_updatedBy != null)
			updatedByint = Integer.parseInt(m_updatedBy.toString());
		String SQL = "SELECT AD_User_ID, Name FROM AD_User WHERE AD_User_ID=? OR AD_User_ID=?";
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(SQL);
			pstmt.setInt(1, createdByint);
			pstmt.setInt(2, updatedByint);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
			{
				if (rs.getInt(1) == createdByint)
					createdBy = rs.getString(2);
				else
					updatedBy = rs.getString(2);
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e1)
		{
			Log.error ("StatusBar.mouseClicked", e1);
		}

		if (createdByint == updatedByint)
			updatedBy = createdBy;

		//  Format String
		StringBuffer msg = new StringBuffer();
		SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.DateTime);
		msg.append(Msg.translate(Env.getCtx(), "CreatedBy")).append(": ").append(createdBy);
		msg.append(" - ").append(format.format(m_created)).append("\n");
		if (!m_created.equals(m_updated) || createdByint != updatedByint)
		{
			msg.append(Msg.translate(Env.getCtx(), "UpdatedBy")).append(": ").append(updatedBy);
			msg.append(" - ").append(format.format(m_updated)).append("\n");
		}
		if (m_info != null && m_info.length() > 0)
			msg.append("\n(").append(m_info).append(")\n");

		//  display who
		JOptionPane.showMessageDialog(null,
				msg.toString(),	                    		//	message
				Msg.getMsg(Env.getCtx(), "Who") + m_text, 	//	title
				JOptionPane.INFORMATION_MESSAGE);
	}	//	addStatusComponent

}	//	StatusBar


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

/**
 *  Mouse Adapter for Status Bar (statusDB)
 */
class StatusBar_mouseAdapter extends java.awt.event.MouseAdapter
{
	private StatusBar adaptee;

	/**
	 *  Constructor
	 *  @param adaptee adaptee
	 */
	StatusBar_mouseAdapter(StatusBar adaptee)
	{
		this.adaptee = adaptee;
	}

	/**
	 *  Click
	 *  @param e event
	 */
	public void mouseClicked(MouseEvent e)
	{
		adaptee.mouseClicked(e);
	}
}   //  StatusBar_mouseAdapter

⌨️ 快捷键说明

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