1 14 package org.compiere.print; 15 16 import java.awt.*; 17 import java.util.*; 18 19 import org.compiere.model.*; 20 import org.compiere.util.*; 21 22 28 public class MPrintColor extends X_AD_PrintColor 29 { 30 35 private MPrintColor(Properties ctx, int AD_PrintColor_ID) 36 { 37 super (ctx, AD_PrintColor_ID); 38 if (AD_PrintColor_ID == 0) 39 setIsDefault(false); 40 } 42 43 private Color m_cacheColor = null; 44 45 46 47 51 public Color getColor() 52 { 53 if (m_cacheColor != null) 54 return m_cacheColor; 55 String code = getCode(); 56 if (code == null || code.equals(".")) 57 m_cacheColor = Color.black; 58 try 59 { 60 if (code != null && !code.equals(".")) 61 { 62 int rgba = Integer.parseInt(code); 63 m_cacheColor = new Color(rgba, false); 64 } 65 } 66 catch (Exception e) 67 { 68 Log.error("MPrintColor.getColor", e); 69 } 70 if (code == null) 71 m_cacheColor = Color.black; 72 return m_cacheColor; 74 } 76 80 public void setColor (Color color) 81 { 82 int rgba = color.getRGB(); 83 super.setCode(String.valueOf(rgba)); 84 } 86 90 public String toString() 91 { 92 StringBuffer sb = new StringBuffer ("MPrintColor["); 93 sb.append("ID=").append(getID()) 94 .append(",Name=").append(getName()) 95 .append(",RGB=").append(getCode()) 96 .append(",").append(getColor()) 97 .append("]"); 98 return sb.toString(); 99 } 101 102 103 104 110 static MPrintColor create (Color color, String name) 111 { 112 MPrintColor pc = new MPrintColor (Env.getCtx(), 0); 113 pc.setName(name); 114 pc.setColor(color); 115 pc.save(); 116 return pc; 117 } 119 120 121 public static final Color darkGreen = new Color (0, 128, 0); 122 public static final Color blackGreen = new Color (0, 64, 0); 123 124 public static final Color darkBlue = new Color (0, 0, 128); 125 public static final Color blackBlue = new Color (0, 0, 64); 126 127 public static final Color whiteGray = new Color (224, 224, 224); 128 129 public static final Color brown = new Color (153, 102, 51); 130 public static final Color darkBrown = new Color (102, 51, 0); 131 132 133 134 135 static private CCache s_colors = new CCache("printColors", 20); 136 137 142 static public MPrintColor get (int AD_PrintColor_ID) 143 { 144 Integer key = new Integer (AD_PrintColor_ID); 145 MPrintColor pc = (MPrintColor)s_colors.get(key); 146 if (pc == null) 147 { 148 pc = new MPrintColor (Env.getCtx(), AD_PrintColor_ID); 149 s_colors.put(key, pc); 150 } 151 return pc; 152 } 154 155 156 160 public static void main(String [] args) 161 { 162 org.compiere.Compiere.startupClient(); 163 Color[] colors = new Color[] 164 {Color.black, Color.red, Color.green, Color.blue, 165 Color.darkGray, Color.gray, Color.lightGray, Color.white, 166 Color.cyan, Color.magenta, Color.orange, Color.pink, Color.yellow, 167 SystemColor.textHighlight}; 168 String [] names = new String [] 169 {"Black", "Red", "Green", "Blue", 170 "Gray dark", "Gray", "Gray light", "White", 171 "Cyan", "Magenta", "Orange", "Pink", "Yellow", 172 "Blue dark"}; 173 for (int i = 0; i < colors.length; i++) 174 System.out.println(names[i] + " = " + colors[i] + " RGB=" + colors[i].getRGB() 175 + " -> " + new Color(colors[i].getRGB(), false) 176 + " -> " + new Color(colors[i].getRGB(), true)); 177 188 189 int[] IDs = PO.getAllIDs ("AD_PrintColor", null); 191 for (int i = 0; i < IDs.length; i++) 192 { 193 MPrintColor pc = new MPrintColor(Env.getCtx(), IDs[i]); 194 System.out.println(IDs[i] + ": " + pc + " = " + pc.getColor() + ", RGB=" + pc.getColor().getRGB()); 195 } 196 } } | Popular Tags |