1 14 package org.compiere.model; 15 16 import java.awt.*; 17 import java.util.*; 18 import java.sql.*; 19 import java.math.*; 20 21 import org.compiere.util.*; 22 import org.compiere.plaf.*; 23 24 31 public class MColor extends X_AD_Color 32 { 33 38 public MColor(Properties ctx, int AD_Color_ID) 39 { 40 super (ctx, AD_Color_ID); 41 if (AD_Color_ID == 0) 42 setName("-/-"); 43 } 45 49 public String toString() 50 { 51 return "MColor[ID=" + getID() + " - " + getName() + "]"; 52 } 54 62 protected Object loadSpecial (ResultSet rs, int index) throws SQLException 63 { 64 Log.trace(Log.l4_Data, "MColor.loadSpecial", p_info.getColumnName(index)); 65 if (index == getColumnIndex("ColorType")) 66 return rs.getString(index+1); 67 return null; 68 } 70 71 78 protected String saveNewSpecial (Object value, int index) 79 { 80 String colName = p_info.getColumnName(index); 81 String colValue = value == null ? "null" : value.getClass().toString(); 82 Log.trace(Log.l5_DData, "MColor.saveNewSpecial " + colName, colValue); 83 if (value == null) 84 return "NULL"; 85 return value.toString(); 86 } 88 89 90 95 public CompiereColor getCompiereColor() 96 { 97 if (getID() == 0) 98 return null; 99 100 String ColorType = (String )getColorType(); 102 if (ColorType == null) 103 { 104 Log.error("MColor.getCompiereColor - No ColorType"); 105 return null; 106 } 107 CompiereColor cc = null; 108 if (ColorType.equals(CompiereColor.TYPE_FLAT)) 110 { 111 cc = new CompiereColor(getColor(true), true); 112 } 113 else if (ColorType.equals(CompiereColor.TYPE_GRADIENT)) 114 { 115 int RepeatDistance = getRepeatDistance(); 116 String StartPoint = getStartPoint(); 117 int startPoint = StartPoint == null ? 0 : Integer.parseInt(StartPoint); 118 cc = new CompiereColor(getColor(true), getColor(false), startPoint, RepeatDistance); 119 } 120 else if (ColorType.equals(CompiereColor.TYPE_LINES)) 121 { 122 int LineWidth = getLineWidth(); 123 int LineDistance = getLineDistance(); 124 cc = new CompiereColor(getColor(false), getColor(true), LineWidth, LineDistance); 125 } 126 else if (ColorType.equals(CompiereColor.TYPE_TEXTURE)) 127 { 128 int AD_Image_ID = getAD_Image_ID(); 129 String url = getURL(AD_Image_ID); 130 if (url == null) 131 return null; 132 BigDecimal ImageAlpha = getImageAlpha(); 133 float compositeAlpha = ImageAlpha == null ? 0.7f : ImageAlpha.floatValue(); 134 cc = new CompiereColor(url, getColor(true), compositeAlpha); 135 } 136 return cc; 137 } 139 144 private Color getColor (boolean primary) 145 { 146 int red = primary ? getRed() : getRed_1(); 147 int green = primary ? getGreen() : getGreen_1(); 148 int blue = primary ? getBlue() : getBlue_1(); 149 return new Color (red, green, blue); 151 } 153 158 private String getURL (int AD_Image_ID) 159 { 160 if (AD_Image_ID == 0) 161 return null; 162 String retValue = null; 164 String sql = "SELECT ImageURL FROM AD_Image WHERE AD_Image_ID=?"; 165 try 166 { 167 PreparedStatement pstmt = DB.prepareStatement(sql); 168 pstmt.setInt (1, AD_Image_ID); 169 ResultSet rs = pstmt.executeQuery(); 170 if (rs.next()) 171 { 172 retValue = rs.getString(1); 173 } 174 rs.close(); 175 pstmt.close(); 176 } 177 catch (SQLException e) 178 { 179 Log.error("MColor.getURL", e); 180 } 181 return retValue; 182 } 184 } | Popular Tags |