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

📄 compierecoloreditor.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 * 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 javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import org.compiere.util.*;
import org.compiere.swing.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyEditor;
import java.util.ResourceBundle;

/**
 *  Compiere Color Editor
 *
 *  @author     Jorg Janke
 *  @version    $Id: CompiereColorEditor.java,v 1.9 2002/09/01 22:34:37 jjanke Exp $
 */
public class CompiereColorEditor extends JDialog
	implements ActionListener, PropertyEditor
{
	/**
	 *  Get Background CompiereColor
	 *  @param owner owner
	 *  @param color optional initial color
	 *  @return CompiereColor
	 */
	public static CompiereColor showDialog (Frame owner, CompiereColor color)
	{
		CompiereColorEditor cce = new CompiereColorEditor (owner, color);
		if (cce.isSaved())
			return cce.getColor();
		return color;
	}   //  showDialog

	/**
	 *  Get Background CompiereColor
	 *  @param owner owner
	 *  @param color optional initial color
	 *  @return CompiereColor
	 */
	public static CompiereColor showDialog (Dialog owner, CompiereColor color)
	{
		CompiereColorEditor cce = new CompiereColorEditor (owner, color);
		if (cce.isSaved())
			return cce.getColor();
		return color;
	}   //  showIt

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

	/**
	 *  Create CompiereColor Dialog with color
	 *  @param owner owner
	 *  @param color Start Color
	 */
	public CompiereColorEditor (Frame owner, CompiereColor color)
	{
		super(owner, "", true);
		init (color);
	}   //  CompiereColorEditor

	/**
	 *  Create CompiereColor Dialog with color
	 *  @param owner owner
	 *  @param color Start Color
	 */
	public CompiereColorEditor (Dialog owner, CompiereColor color)
	{
		super(owner, "", true);
		init (color);
	}   //  CompiereColorEditor

	/**
	 *  Init Dialog
	 *  @param color Start Color
	 */
	private void init (CompiereColor color)
	{
		try
		{
			jbInit();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}

		bOK.addActionListener(this);
		bCancel.addActionListener(this);
		typeField.addActionListener(this);
		flatField.addActionListener(this);
		gradientUpper.addActionListener(this);
		gradientLower.addActionListener(this);
		urlField.addActionListener(this);
		alphaField.addActionListener(this);
		taintColor.addActionListener(this);
		lineColor.addActionListener(this);
		backColor.addActionListener(this);
		widthField.addActionListener(this);
		distanceField.addActionListener(this);
		gradientStartField.addActionListener(this);
		gradientDistanceField.addActionListener(this);

		if (color == null)
			setColor (m_cc);
		else
			setColor (new CompiereColor(color));
		CompierePLAF.showCenterScreen(this);
	}   //  init


	private static ResourceBundle res = ResourceBundle.getBundle("org.compiere.plaf.PlafRes");
	private CompiereColor   m_cc = null;
	private boolean         m_saved = false;
	private boolean         m_setting = false;

	//
	private CPanel northPanel = new CPanel();
	private CPanel southPanel = new CPanel();
	private CButton bOK = CompierePLAF.getOKButton();
	private CButton bCancel = CompierePLAF.getCancelButton();
	private FlowLayout southLayout = new FlowLayout();
	private GridBagLayout northLayout = new GridBagLayout();
	private CLabel typeLabel = new CLabel();
	private CComboBox typeField = new CComboBox(CompiereColor.TYPES);
	private CButton gradientUpper = new CButton();
	private CButton gradientLower = new CButton();
	private CLabel urlLabel = new CLabel();
	private CTextField urlField = new CTextField(30);
	private CLabel alphaLabel = new CLabel();
	private CTextField alphaField = new CTextField(10);
	private CButton taintColor = new CButton();
	private CButton lineColor = new CButton();
	private CButton backColor = new CButton();
	private CLabel widthLabel = new CLabel();
	private CTextField widthField = new CTextField(10);
	private CLabel distanceLabel = new CLabel();
	private CTextField distanceField = new CTextField(10);
	private CPanel centerPanel = new CPanel();
	private CButton flatField = new CButton();
	private CComboBox gradientStartField = new CComboBox(CompiereColor.GRADIENT_SP);
	private CTextField gradientDistanceField = new CTextField(10);
	private CLabel gradientStartLabel = new CLabel();
	private CLabel gradientDistanceLabel = new CLabel();

	/**
	 *  Static Layout.
	 *  <pre>
	 *      - northPanel
	 *          - labels & fields
	 *      - centerPanel
	 *      - southPanel
	 *  </pre>
	 *  @throws Exception
	 */
	private void jbInit() throws Exception
	{
		this.setTitle(res.getString("CompiereColorEditor"));
		CompiereColor.setBackground (this);
		southPanel.setLayout(southLayout);
		southLayout.setAlignment(FlowLayout.RIGHT);
		northPanel.setLayout(northLayout);
		typeLabel.setText(res.getString("CompiereType"));
		gradientUpper.setText(res.getString("GradientUpperColor"));
		gradientLower.setText(res.getString("GradientLowerColor"));
		gradientStartLabel.setText(res.getString("GradientStart"));
		gradientDistanceLabel.setText(res.getString("GradientDistance"));
		urlLabel.setText(res.getString("TextureURL"));
		alphaLabel.setText(res.getString("TextureAlpha"));
		taintColor.setText(res.getString("TextureTaintColor"));
		lineColor.setText(res.getString("LineColor"));
		backColor.setText(res.getString("LineBackColor"));
		widthLabel.setText(res.getString("LineWidth"));
		distanceLabel.setText(res.getString("LineDistance"));
		flatField.setText(res.getString("FlatColor"));
		centerPanel.setBorder(BorderFactory.createRaisedBevelBorder());
		centerPanel.setPreferredSize(new Dimension(400, 200));
		centerPanel.setOpaque(true);
		northPanel.setPreferredSize(new Dimension(400, 150));
		southPanel.add(bCancel, null);
		this.getContentPane().add(northPanel,  BorderLayout.NORTH);
		southPanel.add(bOK, null);
		this.getContentPane().add(southPanel, BorderLayout.SOUTH);
		this.getContentPane().add(centerPanel, BorderLayout.CENTER);
		northPanel.add(typeLabel,            new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(typeField,           new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
		northPanel.add(gradientLower,              new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(urlField,               new GridBagConstraints(1, 5, 2, 1, 1.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(alphaLabel,            new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(alphaField,              new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(taintColor,            new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(backColor,            new GridBagConstraints(1, 8, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(widthLabel,            new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(widthField,             new GridBagConstraints(1, 9, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(distanceLabel,            new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(distanceField,             new GridBagConstraints(1, 10, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(flatField,          new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(gradientStartField,           new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(gradientDistanceField,          new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(urlLabel,      new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(gradientStartLabel,    new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(gradientDistanceLabel,     new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(gradientUpper,    new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
		northPanel.add(lineColor,   new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
	}   //  jbInit

	/**
	 *  Action Listener
	 *  @param e event
	 */
	public void actionPerformed(ActionEvent e)
	{
		if (m_setting)
			return;
		if (e.getSource() == bOK)
		{
			m_saved = true;
			dispose();
			return;
		}
		else if (e.getSource() == bCancel)
		{
			dispose();
			return;
		}

		/**** Field Changes  ****/
		try
		{
		//  Type
		if (e.getSource() == typeField)
			cmd_type();
		//  Flat
		else if (e.getSource() == flatField)
			m_cc.setFlatColor(JColorChooser.showDialog
				(this, flatField.getText(), m_cc.getFlatColor()));
		//  Gradient
		else if (e.getSource() == gradientUpper)
			m_cc.setGradientUpperColor(JColorChooser.showDialog
				(this, gradientUpper.getText(), m_cc.getGradientUpperColor()));
		else if (e.getSource() == gradientLower)
			m_cc.setGradientLowerColor(JColorChooser.showDialog
				(this, gradientLower.getText(), m_cc.getGradientLowerColor()));
		else if (e.getSource() == gradientStartField)
			m_cc.setGradientStartPoint
				(((KeyNamePair)gradientStartField.getSelectedItem()).getKey());
		else if (e.getSource() == gradientDistanceField)
			m_cc.setGradientRepeatDistance(gradientDistanceField.getText());
		//  Texture
		else if (e.getSource() == urlField)
			m_cc.setTextureURL(urlField.getText());
		else if (e.getSource() == alphaField)
			m_cc.setTextureCompositeAlpha(alphaField.getText());
		else if (e.getSource() == taintColor)
			m_cc.setTextureTaintColor(JColorChooser.showDialog
				(this, taintColor.getText(), m_cc.getTextureTaintColor()));
		//  Lines
		else if (e.getSource() == lineColor)
			m_cc.setLineColor(JColorChooser.showDialog
				(this, lineColor.getText(), m_cc.getLineColor()));
		else if (e.getSource() == backColor)
			m_cc.setLineBackColor(JColorChooser.showDialog
				(this, backColor.getText(), m_cc.getLineBackColor()));
		else if (e.getSource() == widthField)
			m_cc.setLineWidth(widthField.getText());
		else if (e.getSource() == distanceField)
			m_cc.setLineDistance(distanceField.getText());
		}
		catch (Exception ee)
		{
		}
		setColor (m_cc);
	}   //  actionPerformed

	/**
	 *  Set Type with default values
	 */
	private void cmd_type()
	{
		ValueNamePair vp = (ValueNamePair)typeField.getSelectedItem();
		if (vp.getValue().equals(CompiereColor.TYPE_FLAT))
			m_cc = new CompiereColor(CompiereColor.TYPE_FLAT);
		else if (vp.getValue().equals(CompiereColor.TYPE_GRADIENT))
			m_cc = new CompiereColor(CompiereColor.TYPE_GRADIENT);
		else if (vp.getValue().equals(CompiereColor.TYPE_TEXTURE))
			m_cc = new CompiereColor(CompiereColor.TYPE_TEXTURE);
		else if (vp.getValue().equals(CompiereColor.TYPE_LINES))
			m_cc = new CompiereColor(CompiereColor.TYPE_LINES);
		setColor (m_cc);
	}   //  cmd_type

	/**
	 *  Set Color and update UI
	 *  @param color color
	 */
	public void setColor (CompiereColor color)
	{

⌨️ 快捷键说明

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