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

📄 compierecolor.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
 * 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.plaf;

import java.awt.*;
import java.awt.image.*;
import java.util.*;
import java.net.*;
import javax.swing.*;
import javax.swing.plaf.*;

import org.compiere.util.*;
import java.io.*;

/**
 *  Compiere Background Color
 *
 *  @author     Jorg Janke
 *  @version    $Id: CompiereColor.java,v 1.17 2003/01/15 05:34:03 jjanke Exp $
 */
public class CompiereColor implements Serializable
{
	/** Background type Flat            */
	public static final String  TYPE_FLAT = "F";
	/** Background type Gradient        */
	public static final String  TYPE_GRADIENT = "G";
	/** Background type Lines           */
	public static final String  TYPE_LINES = "L";
	/** Background type Texture         */
	public static final String  TYPE_TEXTURE = "T";

	/** Names   */
	private static ResourceBundle   s_res = ResourceBundle.getBundle("org.compiere.plaf.PlafRes");

	/** Type Values     */
	public static final String[]    TYPE_VALUES = new String[] {
		TYPE_FLAT, TYPE_GRADIENT, TYPE_LINES, TYPE_TEXTURE
	};
	/** Type Names      */
	public static final String[]    TYPE_NAMES = new String[] {
		s_res.getString("BackColType_Flat"),
		s_res.getString("BackColType_Gradient"),
		s_res.getString("BackColType_Lines"),
		s_res.getString("BackColType_Texture")
	};
	/** Types           */
	public static final ValueNamePair[] TYPES = new ValueNamePair[] {
		new ValueNamePair(TYPE_VALUES[0], TYPE_NAMES[0]),
		new ValueNamePair(TYPE_VALUES[1], TYPE_NAMES[1]),
		new ValueNamePair(TYPE_VALUES[2], TYPE_NAMES[2]),
		new ValueNamePair(TYPE_VALUES[3], TYPE_NAMES[3])
	};

	/** Gradient Starting Values    */
	public static final int[]       GRADIENT_SP_VALUES = new int[] {
		SwingConstants.NORTH, SwingConstants.NORTH_EAST,
		SwingConstants.EAST, SwingConstants.SOUTH_EAST,
		SwingConstants.SOUTH, SwingConstants.SOUTH_WEST,
		SwingConstants.WEST, SwingConstants.NORTH_WEST
	};
	/** Gradient Starting Names     */
	public static final String[]    GRADIENT_SP_NAMES = new String[] {
		"North",    "North-East",
		"East",     "South-East",
		"South",    "South-West",
		"West",     "North-West"
	};
	/** Gradient Starting Point    */
	public static final KeyNamePair[]   GRADIENT_SP = new KeyNamePair[] {
		new KeyNamePair(GRADIENT_SP_VALUES[0], GRADIENT_SP_NAMES[0]),
		new KeyNamePair(GRADIENT_SP_VALUES[1], GRADIENT_SP_NAMES[1]),
		new KeyNamePair(GRADIENT_SP_VALUES[2], GRADIENT_SP_NAMES[2]),
		new KeyNamePair(GRADIENT_SP_VALUES[3], GRADIENT_SP_NAMES[3]),
		new KeyNamePair(GRADIENT_SP_VALUES[4], GRADIENT_SP_NAMES[4]),
		new KeyNamePair(GRADIENT_SP_VALUES[5], GRADIENT_SP_NAMES[5]),
		new KeyNamePair(GRADIENT_SP_VALUES[6], GRADIENT_SP_NAMES[6]),
		new KeyNamePair(GRADIENT_SP_VALUES[7], GRADIENT_SP_NAMES[7])
	};
	/** Exception text              */
	private static final String     EXCEPTION_TEXT = "Arguments cannot be NULL";

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

	/**
	 *  Set Background of Component to default color
	 *  @param c component
	 */
	public static void setBackground (JComponent c)
	{
		setBackground (c, CompierePanelUI.getDefaultBackground());
	}   //  setBackground

	/**
	 *  Set Background of Component
	 *  @param c Component
	 *  @param cc Color
	 */
	public static void setBackground (JComponent c, CompiereColor cc)
	{
		c.putClientProperty(CompierePLAF.BACKGROUND, cc);
	}   //  setBackground

	/**
	 *  Get Background Color of component
	 *  @param c JComponent
	 *  @return Color
	 */
	public static CompiereColor getBackground (JComponent c)
	{
		CompiereColor bg = null;
		try
		{
			bg = (CompiereColor)c.getClientProperty(CompierePLAF.BACKGROUND);
		}
		catch (Exception e)
		{
			System.err.println("CompiereColor - ClientProperty: " + e.getMessage());
		}
		return bg;
	}   //  getBackground

	/**
	 *  Set Background of Window Content Pane to default color
	 *  @param win window
	 */
	public static void setBackground (Window win)
	{
		setBackground (win, CompierePanelUI.getDefaultBackground());
	}   //  setBackground

	/**
	 *  Set Background of Window Content Pane
	 *  @param win window
	 *  @param cc compiere color
	 */
	public static void setBackground (Window win, CompiereColor cc)
	{
		if (win instanceof JDialog)
		{
			((JPanel)((JDialog)win).getContentPane()).putClientProperty(CompierePLAF.BACKGROUND, cc);
		//	((JPanel)((JDialog)win).getContentPane()).setName("contentPane");
		}
		else if (win instanceof JFrame)
		{
			((JPanel)((JFrame)win).getContentPane()).putClientProperty(CompierePLAF.BACKGROUND, cc);
		//	((JPanel)((JFrame)win).getContentPane()).setName("contentPane");
		}
		else if (win instanceof JWindow)
		{
			((JPanel)((JWindow)win).getContentPane()).putClientProperty(CompierePLAF.BACKGROUND, cc);
		//	((JPanel)((JWindow)win).getContentPane()).setName("contentPane");
		}
	}   //  setBackground

	/**
	 *  Set Default Background
	 *  @param bg Background Color
	 *  @see CompierePanelUI#setDefaultBackground
	 */
	public static void setDefaultBackground (CompiereColor bg)
	{
		CompierePanelUI.setDefaultBackground(bg);
	}   //  setDefaultBackground

	/**
	 *  Get Default Background
	 *  @return Background
	 *  @see CompierePanelUI#getDefaultBackground
	 */
	public static CompiereColor getDefaultBackground()
	{
		return CompierePanelUI.getDefaultBackground();
	}   //  getDefaultBackground

	/**
	 *  Set Default Background
	 *  @param setDefault if true, the background will be set to the default color
	 *  @see CompierePanelUI#setSetDefault
	 */
	public static void setSetDefault (boolean setDefault)
	{
		CompierePanelUI.setSetDefault(setDefault);
	}   //  setSetDefault

	/**
	 *  Is the Default Background set by default
	 *  @return true if default background is set
	 *  @see CompierePanelUI#isSetDefault
	 */
	public static boolean isSetDefault()
	{
		return CompierePanelUI.isSetDefault();
	}   //  isSetDefault

	/**
	 *  Parse attributes and return CompiereColor
	 *  @param attributes attributes
	 *  @return CompiereColor
	 */
	public static CompiereColor parse (String attributes)
	{
		CompiereColor cc = new CompiereColor ();
		try
		{
			if (attributes != null && attributes.length() > 0)
				cc.parseAttributres (attributes);
		}
		catch (Exception e)
		{
			System.err.println("CompiereColor.parse(" + attributes + ") - " + e.toString());
		}
		return cc;
	}   //  parse

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

	/**
	 *  Create Gradient Background Color (Window System Color - White)
	 */
	public CompiereColor()
	{
		this (TYPE_GRADIENT);
	}   //  CompiereColor

	/**
	 *  Create Default Background Colors of Type
	 *  @param type Background type (see constants TYPE_*)
	 */
	public CompiereColor (String type)
	{
		if (type == null)
			new java.lang.IllegalArgumentException (EXCEPTION_TEXT);
		if (type.equals(TYPE_FLAT) || type.equals(TYPE_GRADIENT)
			|| type.equals(TYPE_TEXTURE) || type.equals(TYPE_LINES))
		{
			m_type = type;
		}
		else
			new java.lang.IllegalArgumentException ("Invalid Type");
	}	//  CompiereColor

	/**
	 *  Create Flat Background Color
	 *  @param bg background
	 */
	public CompiereColor (Color bg)
	{
		this (bg, true);
	}   //  CompiereColor

	/**
	 *  Create Background Color
	 *  @param bg Color
	 *  @param flat if true create Flat color otherwise Gradient color with white lower color
	 */
	public CompiereColor (Color bg, boolean flat)
	{
		if (bg == null)
			new java.lang.IllegalArgumentException (EXCEPTION_TEXT);
		m_type = flat ? TYPE_FLAT : TYPE_GRADIENT;
		m_primaryColor = bg;
	}   //  CompiereColor

	/**
	 *  Set Background to Gradient colors
	 *  @param upperColor upper Color
	 *  @param lowerColor lower Color
	 *  @param startPoint   Starting point - e.g. SOUTH_WEST see SwingConstants, default NORTH_WEST
	 *  @param repeatDistance   X/Y Distance to repeat gradient in points - 0 no repeats
	 */
	public CompiereColor (Color upperColor, Color lowerColor, int startPoint, int repeatDistance)
	{
		if (upperColor == null || lowerColor == null)
			new java.lang.IllegalArgumentException (EXCEPTION_TEXT);
		m_type = TYPE_GRADIENT;
		m_primaryColor = upperColor;
		m_secondaryColor = lowerColor;
		m_startPoint = startPoint;
		m_repeatDistance = repeatDistance;
	}   //  CompiereColor

	/**
	 *  Set Background to Gradient colors.
	 *  Starting in the north, repeat after 100 pt
	 *  @param upperColor upper color
	 *  @param lowerColor lower color
	 */
	public CompiereColor (Color upperColor, Color lowerColor)
	{
		this (upperColor, lowerColor, SwingConstants.NORTH_WEST, 100);
	}   //  CompiereColor

	/**
	 *  Set Background to Texture
	 *
	 *  @param textureURL URL to a *.gif or *.jpg graphic file
	 *  @param taint  Color to taint the texture (use white for not tainting it)
	 *  @param compositeAlpha Value from 0(no) to 1(full) taining
	 */
	public CompiereColor (URL textureURL, Color taint, float compositeAlpha)
	{
		if (textureURL == null || taint == null)
			new java.lang.IllegalArgumentException (EXCEPTION_TEXT);
		m_type = TYPE_TEXTURE;
		m_textureURL = textureURL;
		m_primaryColor = taint;
		m_compositeAlpha = compositeAlpha;
	}   //  CompiereColor

	/**
	 *  Set Background to Texture
	 *
	 *  @param textureURL URL to a *.gif or *.jpg graphic file
	 *  @param taint  Color to taint the texture (use white for not tainting it)
	 *  @param compositeAlpha Tainting value from 0 (no - FullGraph) to 1 (full - NoGraph)
	 */
	public CompiereColor (String textureURL, Color taint, float compositeAlpha)
	{
		if (textureURL == null || taint == null)
			new java.lang.IllegalArgumentException (EXCEPTION_TEXT);
		m_type = TYPE_TEXTURE;
		setTextureURL(textureURL);
		m_primaryColor = taint;
		m_compositeAlpha = compositeAlpha;
	}   //  CompiereColor

	/**
	 *  Set Background to Lines
	 *
	 *  @param lineColor line color
	 *  @param backColor background color
	 *  @param lineWidth Stroke width in point
	 *  @param lineDistance Distance between lines in points
	 */
	public CompiereColor (Color lineColor, Color backColor, float lineWidth, int lineDistance)
	{
		if (lineColor == null || backColor == null)
			new java.lang.IllegalArgumentException (EXCEPTION_TEXT);
		m_type = TYPE_LINES;
		m_primaryColor = backColor;
		m_secondaryColor = lineColor;
		m_lineWidth = lineWidth;
		m_lineDistance = lineDistance;
	}   //  CompiereColor

	/**
	 *  Copy Color
	 *  @param cc color
	 */
	public CompiereColor (CompiereColor cc)
	{
		if (cc == null)
			return;
		setColor(cc);
	}   //  CompiereColor

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

	/** Type - Default: Gradient    */
	private String  m_type = TYPE_GRADIENT;

	/** Primary Color - Default Panel back  */
	private Color   m_primaryColor = UIManager.getColor("Panel.background");
	/** Secondary Color - Default: white    */
	private Color   m_secondaryColor = Color.white;

	/** Texture Graph URL           */
	private URL     m_textureURL = null;
	/** Texture Graph               */
	private BufferedImage m_image = null;
	/** Texture Alpha - Default: 0.7 */
	private float   m_compositeAlpha = 0.7f;

	/** Line Width - Default: 1     */
	private float   m_lineWidth = 1.0f;
	/** Line Distance - Default: 5  */
	private int     m_lineDistance = 5;

	/** Gradient Starting point - Default: NORTH_WEST   */
	private int     m_startPoint = SwingConstants.NORTH_WEST;
	/** Gradient repeat distance in points - Default: 100   */
	private int     m_repeatDistance = 100;

	/** Background                              */
	private ColorBackground m_back = null;

	/** Diry marker for repaining Background    */
	private boolean m_dirty = true;

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

	/**
	 *  Get BackgroundType (Flat, Gradient, Lines, Texture)
	 *  @return Background Type (see TYPE_* constants)
	 */
	public String getType()
	{
		return m_type;
	}   //  getType

	/**
	 *  Flat Background Type (default)
	 *  @return true if Flat background
	 */
	public boolean isFlat()
	{
		return TYPE_FLAT.equals(getType());
	}   // isFlat

	/**
	 *  Gradient Background Type
	 *  @return true if Gradient background

⌨️ 快捷键说明

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