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

📄 clabel.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.swing;

import java.awt.*;
import javax.swing.*;

import org.compiere.plaf.*;

/**
 *  Label with Mnemonics interpretation
 *
 *  @author     Jorg Janke
 *  @version    $Id: CLabel.java,v 1.6 2002/08/12 01:55:15 danb Exp $
 */
public class CLabel extends JLabel
{
	public static int   DEFAULT_ALIGNMENT = JLabel.TRAILING;

	/**
	 * Creates a <code>Label</code> instance with the specified
	 * text, image, and horizontal alignment.
	 * The label is centered vertically in its display area.
	 * The text is on the trailing edge of the image.
	 *
	 * @param text  The text to be displayed by the label.
	 * @param icon  The image to be displayed by the label.
	 * @param horizontalAlignment  One of the following constants
	 *           defined in <code>SwingConstants</code>:
	 *           <code>LEFT</code>,
	 *           <code>CENTER</code>,
	 *           <code>RIGHT</code>,
	 *           <code>LEADING</code> or
	 *           <code>TRAILING</code>.
	 */
	public CLabel (String text, Icon icon, int horizontalAlignment)
	{
		super (text, icon, horizontalAlignment);
		init();
	}

	/**
	 * Creates a <code>Label</code> instance with the specified
	 * text and horizontal alignment.
	 * The label is centered vertically in its display area.
	 *
	 * @param text  The text to be displayed by the label.
	 * @param horizontalAlignment  One of the following constants
	 *           defined in <code>SwingConstants</code>:
	 *           <code>LEFT</code>,
	 *           <code>CENTER</code>,
	 *           <code>RIGHT</code>,
	 *           <code>LEADING</code> or
	 *           <code>TRAILING</code>.
	 */
	public CLabel (String text, int horizontalAlignment)
	{
		super(text, horizontalAlignment);
		init();
	}

	/**
	 * Creates a <code>Label</code> instance with the specified text.
	 * The label is aligned against the leading edge of its display area,
	 * and centered vertically.
	 *
	 * @param text  The text to be displayed by the label.
	 */
	public CLabel (String text)
	{
		super(text, DEFAULT_ALIGNMENT);
		init();
	}

	/**
	 * Creates a <code>Label</code> instance with the specified
	 * image and horizontal alignment.
	 * The label is centered vertically in its display area.
	 *
	 * @param image  The image to be displayed by the label.
	 * @param horizontalAlignment  One of the following constants
	 *           defined in <code>SwingConstants</code>:
	 *           <code>LEFT</code>,
	 *           <code>CENTER</code>,
	 *           <code>RIGHT</code>,
	 *           <code>LEADING</code> or
	 *           <code>TRAILING</code>.
	 */
	public CLabel (Icon image, int horizontalAlignment)
	{
		super (image, horizontalAlignment);
		init();
	}

	/**
	 * Creates a <code>Label</code> instance with the specified image.
	 * The label is centered vertically and horizontally
	 * in its display area.
	 *
	 * @param image  The image to be displayed by the label.
	 */
	public CLabel (Icon image)
	{
		super (image, DEFAULT_ALIGNMENT);
		init();
	}

	/**
	 * Creates a <code>JLabel</code> instance with
	 * no image and with an empty string for the title.
	 * The label is centered vertically
	 * in its display area.
	 * The label's contents, once set, will be displayed on the leading edge
	 * of the label's display area.
	 */
	public CLabel ()
	{
		super("", DEFAULT_ALIGNMENT);
		init();
	}

	/**
	 * Creates a <code>Label</code> instance with the specified text.
	 * The label is aligned against the leading edge of its display area,
	 * and centered vertically.
	 *
	 * @param label  The text to be displayed by the label.
	 * @param toolTip   The optional Tooltip text
	 */
	public CLabel (String label, String toolTip)
	{
		super (label, DEFAULT_ALIGNMENT);
		if (toolTip != null && toolTip.length() > 0)
			super.setToolTipText(toolTip);
		init();
	}   //  CLabel

	/**
	 *  Common init
	 */
	private void init()
	{
		setFocusable (false);
		setOpaque(false);
		//
		setForeground(CompierePLAF.getTextColor_Label());
		setFont(CompierePLAF.getFont_Label());
	}   //  init


	/**
	 *  Set Background
	 *  @param bg background
	 */
	public void setBackground (Color bg)
	{
		if (bg.equals(getBackground()))
			return;
		super.setBackground(bg);
	}   //  setBackground

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

	/**
	 *  Set label text - if it includes &, the next character is the Mnemonic
	 *  @param mnemonicLabel Label containing Mnemonic
	 */
	public void setText (String mnemonicLabel)
	{
		super.setText (createMnemonic (mnemonicLabel));
	}   //  setText

	/**
	 *  Set label text directly (w/o mnemonics)
	 *  @param label    Label
	 */
	public void setTextDirect (String label)
	{
		super.setText (label);
	}   //  setTextDirect

	/**
	 *  Create Mnemonics of text containing "&".
	 *	Based on MS notation of &Help => H is Mnemonics
	 *  @param text test with Mnemonics
	 *  @return text w/o &
	 *  @see #setLabelFor
	 */
	private String createMnemonic(String text)
	{
		if (text == null)
			return text;
		int pos = text.indexOf("&");
		if (pos != -1)					//	We have a nemonic
		{
			char ch = text.charAt(pos+1);
			if (ch != ' ')              //  &_ - is the & character
			{
				setDisplayedMnemonic(ch);
				return text.substring(0, pos) + text.substring(pos+1);
			}
		}
		return text;
	}   //  createMnemonic

	/**
	 *  Set ReadWrite
	 *  @param rw enabled
	 */
	public void setReadWrite (boolean rw)
	{
		this.setEnabled(rw);
	}   //  setReadWrite

}   //  CLabel

⌨️ 快捷键说明

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