1 28 package net.sf.jasperreports.engine.fill; 29 30 import java.awt.Color ; 31 import java.io.Serializable ; 32 import java.util.Random ; 33 34 import net.sf.jasperreports.engine.JRConstants; 35 import net.sf.jasperreports.engine.JRDefaultStyleProvider; 36 import net.sf.jasperreports.engine.JRElement; 37 import net.sf.jasperreports.engine.JRStyle; 38 import net.sf.jasperreports.engine.JRStyleContainer; 39 import net.sf.jasperreports.engine.util.JRStyleResolver; 40 41 42 46 public abstract class JRTemplateElement implements JRStyleContainer, Serializable 47 { 48 49 50 53 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 54 55 private static final Random randomId = new Random (); 56 57 60 private String key; 61 private Byte mode = null; 62 private Color forecolor = null; 63 private Color backcolor = null; 64 65 protected JRDefaultStyleProvider defaultStyleProvider; 66 protected JRStyle parentStyle = null; 67 68 private final String id; 69 70 73 protected JRTemplateElement(JRDefaultStyleProvider defaultStyleProvider) 74 { 75 this.defaultStyleProvider = defaultStyleProvider; 76 id = createId(); 77 } 78 79 82 protected JRTemplateElement(JRElement element) 83 { 84 setElement(element); 85 id = createId(); 86 } 87 88 protected JRTemplateElement(String id) 89 { 90 this.id = id; 91 } 92 93 private String createId() 94 { 95 return System.identityHashCode(this) + "_" + System.currentTimeMillis() + "_" + randomId.nextInt(); 96 } 97 98 99 102 protected void setElement(JRElement element) 103 { 104 parentStyle = element.getStyle(); 105 106 setKey(element.getKey()); 107 108 mode = element.getOwnMode(); 109 forecolor = element.getOwnForecolor(); 110 backcolor = element.getOwnBackcolor(); 111 } 112 113 116 public JRDefaultStyleProvider getDefaultStyleProvider() 117 { 118 return defaultStyleProvider; 119 } 120 121 124 public JRStyle getStyle() 125 { 126 return parentStyle; 127 } 128 129 132 protected JRStyle getBaseStyle() 133 { 134 if (parentStyle != null) 135 return parentStyle; 136 if (defaultStyleProvider != null) 137 return defaultStyleProvider.getDefaultStyle(); 138 return null; 139 } 140 141 144 public byte getMode() 145 { 146 return JRStyleResolver.getMode(this, JRElement.MODE_OPAQUE); 147 } 148 149 152 public Byte getOwnMode() 153 { 154 return mode; 155 } 156 157 160 protected void setMode(byte mode) 161 { 162 this.mode = new Byte (mode); 163 } 164 165 168 protected void setMode(Byte mode) 169 { 170 this.mode = mode; 171 } 172 173 176 public Color getForecolor() 177 { 178 return JRStyleResolver.getForecolor(this); 179 } 180 181 184 public Color getOwnForecolor() 185 { 186 return this.forecolor; 187 } 188 189 192 protected void setForecolor(Color forecolor) 193 { 194 this.forecolor = forecolor; 195 } 196 197 200 public Color getBackcolor() 201 { 202 return JRStyleResolver.getBackcolor(this); 203 } 204 205 208 public Color getOwnBackcolor() 209 { 210 return this.backcolor; 211 } 212 213 216 protected void setBackcolor(Color backcolor) 217 { 218 this.backcolor = backcolor; 219 } 220 221 224 public String getId() 225 { 226 return id; 227 } 228 229 230 public String getKey() 231 { 232 return key; 233 } 234 235 236 public void setKey(String key) 237 { 238 this.key = key; 239 } 240 } 241 | Popular Tags |