📄 mprintcolor.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-2002 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.print;
import java.awt.*;
import java.util.*;
import org.compiere.model.*;
import org.compiere.util.*;
/**
* AD_PrintColor Print Color Model
*
* @author Jorg Janke
* @version $Id: MPrintColor.java,v 1.9 2002/11/11 07:03:01 jjanke Exp $
*/
public class MPrintColor extends PO
{
/**
* Constructor
* @param ctx context
* @param AD_PrintColor_ID ID
*/
private MPrintColor(Properties ctx, int AD_PrintColor_ID)
{
super (ctx, AD_PrintColor_ID);
if (AD_PrintColor_ID == 0)
setDefault(false);
} // MPrintColor
/** Color cached */
private Color m_cacheColor = null;
/**
* Initialize and return PO_Info
* @param ctx context
* @return POInfo
*/
protected POInfo initPO (java.util.Properties ctx)
{
int AD_Table_ID = 490;
return POInfo.getPOInfo (ctx, AD_Table_ID);
} // initPO
/*************************************************************************/
/**
* Set Name
* @param name name
*/
public void setName (String name)
{
setValue("Name", name);
} // setName
/**
* Get Name
* @return name
*/
public String getName()
{
return (String)getValue("Name");
} // getName
/**
* Set Default
* @param newDefault default
*/
public void setDefault (boolean newDefault)
{
setValue("IsDefault", new Boolean(newDefault));
} // setDefault
/**
* Get Default
* @return true if default
*/
public boolean isDefault()
{
return ((Boolean)getValue("IsDefault")).booleanValue();
} // isDefault
public String getCode()
{
return (String)getValue("Code");
} // getCode
/**
* Get Color
* @return Color
*/
public Color getColor()
{
if (m_cacheColor != null)
return m_cacheColor;
String code = getCode();
if (code == null || code.equals("."))
m_cacheColor = Color.black;
try
{
if (code != null && !code.equals("."))
{
int rgba = Integer.parseInt(code);
m_cacheColor = new Color(rgba, false);
}
}
catch (Exception e)
{
Log.error("MPrintColor.getColor", e);
}
if (code == null)
m_cacheColor = Color.black;
// Log.trace(Log.l6_Database, "MPrintColor.getColor " + code, m_cacheColor);
return m_cacheColor;
} // getColor
/**
* Set Color
* @param color Color
*/
public void setColor (Color color)
{
int rgba = color.getRGB();
setValue ("Code", String.valueOf(rgba));
} // setColor
/**
* String Representation
* @return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer("MPrintColor[");
sb.append("ID=").append(getID())
.append(",Name=").append(getName())
.append(",RGB=").append(getCode())
.append(",").append(getColor())
.append("]");
return sb.toString();
} // toString
/*************************************************************************/
/**
* Create Color in Database and save
* @param color color
* @param name name
* @return MPrintColor
*/
static MPrintColor create (Color color, String name)
{
MPrintColor pc = new MPrintColor (Env.getCtx(), 0);
pc.setName(name);
pc.setColor(color);
pc.save();
return pc;
} // create
/*************************************************************************/
public static final Color darkGreen = new Color (0, 128, 0);
public static final Color blackGreen = new Color (0, 64, 0);
public static final Color darkBlue = new Color (0, 0, 128);
public static final Color blackBlue = new Color (0, 0, 64);
public static final Color whiteGray = new Color (224, 224, 224);
public static final Color brown = new Color (153, 102, 51);
public static final Color darkBrown = new Color (102, 51, 0);
/*************************************************************************/
/** Cached Colors */
static private HashMap s_colors = new HashMap();
/**
* Get Color
* @param AD_PrintColor_ID id
* @return Color
*/
static public MPrintColor get (int AD_PrintColor_ID)
{
Integer key = new Integer(AD_PrintColor_ID);
MPrintColor pc = (MPrintColor)s_colors.get(key);
if (pc == null)
{
pc = new MPrintColor (Env.getCtx(), AD_PrintColor_ID);
s_colors.put(key, pc);
}
return pc;
} // get
/*************************************************************************/
/**
* Create Standard Colors
* @param args args
*/
public static void main(String[] args)
{
org.compiere.Compiere.startupClient();
Color[] colors = new Color[]
{Color.black, Color.red, Color.green, Color.blue,
Color.darkGray, Color.gray, Color.lightGray, Color.white,
Color.cyan, Color.magenta, Color.orange, Color.pink, Color.yellow,
SystemColor.textHighlight};
String[] names = new String[]
{"Black", "Red", "Green", "Blue",
"Gray dark", "Gray", "Gray light", "White",
"Cyan", "Magenta", "Orange", "Pink", "Yellow",
"Blue dark"};
for (int i = 0; i < colors.length; i++)
System.out.println(names[i] + " = " + colors[i] + " RGB=" + colors[i].getRGB()
+ " -> " + new Color(colors[i].getRGB(), false)
+ " -> " + new Color(colors[i].getRGB(), true));
/**
// Create Colors
for (int i = 0; i < colors.length; i++)
create(colors[i], names[i]);
create(whiteGray, "Gray white");
create(darkGreen, "Green dark");
create(blackGreen, "Green black");
create(blackBlue, "Blue black");
create(brown, "Brown");
create(darkBrown, "Brown dark");
**/
// Read All Colors
int[] IDs = PO.getAllIDs ("AD_PrintColor", null);
for (int i = 0; i < IDs.length; i++)
{
MPrintColor pc = new MPrintColor(Env.getCtx(), IDs[i]);
System.out.println(IDs[i] + ": " + pc + " = " + pc.getColor() + ", RGB=" + pc.getColor().getRGB());
}
} // main
} // MPrintColor
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -