📄 mcolor.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.model;
import java.awt.*;
import java.util.*;
import java.sql.*;
import java.math.*;
import org.compiere.util.*;
import org.compiere.plaf.*;
/**
* Color Persistent Object Model
* (DisplayType=27)
*
* @author Jorg Janke
* @version $Id: MColor.java,v 1.7 2002/08/12 01:55:12 danb Exp $
*/
public class MColor extends PO
{
/**
* Color Model
* @param ctx
* @param AD_Color_ID
*/
public MColor(Properties ctx, int AD_Color_ID)
{
super (ctx, AD_Color_ID);
if (AD_Color_ID == 0)
setValue("Name", "-/-");
} // MColor
/**
* Initialize POInfo
* @param ctx
* @return POInfo
*/
protected POInfo initPO (Properties ctx)
{
int AD_Table_ID = 457;
return POInfo.getPOInfo (ctx, AD_Table_ID);
} // initPO
/**
* String Representation
* @return string
*/
public String toString()
{
return "MColor[ID=" + getID() + " - " + getValue("Name") + "]";
} // toString
/**
* Load Special data (images, ..).
* To be extended by sub-classes
* @param rs
* @param index zero based index
* @return value
* @throws SQLException
*/
protected Object loadSpecial (ResultSet rs, int index) throws SQLException
{
Log.trace(Log.l4_Data, "MColor.loadSpecial", p_info.getColumnName(index));
if (index == getColumnIndex("ColorType"))
return rs.getString(index+1);
return null;
} // loadSpecial
/**
* Save Special Data.
* AD_Image_ID (Background)
* @param value
* @param index
* @return SQL code for INSERT VALUES clause
*/
protected String saveNewSpecial (Object value, int index)
{
String colName = p_info.getColumnName(index);
String colValue = value == null ? "null" : value.getClass().toString();
Log.trace(Log.l5_DData, "MColor.saveNewSpecial " + colName, colValue);
if (value == null)
return "NULL";
return value.toString();
} // saveNewSpecial
/*************************************************************************/
/**
* Get CompiereColor
* @return CompiereColor
* @see org.compiere.grid.ed.VColor#getCompiereColor
*/
public CompiereColor getCompiereColor()
{
if (getID() == 0)
return null;
// Color Type
String ColorType = (String)getValue("ColorType");
if (ColorType == null)
{
Log.error("MColor.getCompiereColor - No ColorType");
return null;
}
CompiereColor cc = null;
//
if (ColorType.equals(CompiereColor.TYPE_FLAT))
{
cc = new CompiereColor(getColor(true), true);
}
else if (ColorType.equals(CompiereColor.TYPE_GRADIENT))
{
Integer RepeatDistance = (Integer)getValue("RepeatDistance");
String StartPoint = (String)getValue("StartPoint");
int repeatDistance = RepeatDistance == null ? 0 : RepeatDistance.intValue();
int startPoint = StartPoint == null ? 0 : Integer.parseInt(StartPoint);
cc = new CompiereColor(getColor(true), getColor(false), startPoint, repeatDistance);
}
else if (ColorType.equals(CompiereColor.TYPE_LINES))
{
Integer LineWidth = (Integer)getValue("LineWidth");
Integer LineDistance = (Integer)getValue("LineDistance");
int lineWidth = LineWidth == null ? 0 : LineWidth.intValue();
int lineDistance = LineDistance == null ? 0 : LineDistance.intValue();
cc = new CompiereColor(getColor(false), getColor(true), lineWidth, lineDistance);
}
else if (ColorType.equals(CompiereColor.TYPE_TEXTURE))
{
Integer AD_Image_ID = (Integer)getValue("AD_Image_ID");
String url = getURL(AD_Image_ID);
if (url == null)
return null;
BigDecimal ImageAlpha = (BigDecimal)getValue("ImageAlpha");
float compositeAlpha = ImageAlpha == null ? 0.7f : ImageAlpha.floatValue();
cc = new CompiereColor(url, getColor(true), compositeAlpha);
}
return cc;
} // getCompiereColor
/**
* Get Color
* @param primary true if primary false if secondary
* @return Color
*/
private Color getColor (boolean primary)
{
String add = primary ? "" : "_1";
Integer Red = (Integer)getValue("Red" + add);
Integer Green = (Integer)getValue("Green" + add);
Integer Blue = (Integer)getValue("Blue" + add);
//
int red = Red == null ? 0 : Red.intValue();
int green = Green == null ? 0 : Green.intValue();
int blue = Blue == null ? 0 : Blue.intValue();
//
return new Color (red, green, blue);
} // getColor
/**
* Get URL from Image
* @param AD_Image_ID
* @return URL as String or null
*/
private String getURL (Integer AD_Image_ID)
{
if (AD_Image_ID == null || AD_Image_ID.intValue() == 0)
return null;
//
String retValue = null;
String sql = "SELECT ImageURL FROM AD_Image WHERE AD_Image_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt (1, AD_Image_ID.intValue());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
retValue = rs.getString(1);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("MColor.getURL", e);
}
return retValue;
} // getURL
} // MColor
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -