1 32 33 package it.businesslogic.ireport; 34 import java.awt.*; 35 import it.businesslogic.ireport.util.*; 36 37 import java.util.*; 38 39 43 public class BarcodeReportElement extends it.businesslogic.ireport.ImageReportElement { 44 45 private String title = "Sample barcode"; 46 private boolean legend = false; 47 private boolean showText = false; 48 private String text = "\"0815\""; 49 private int type = 13; 50 private boolean checkSum = false; 51 private String lastError = null; 52 private static java.awt.Image barcodeError = null; 53 private int imageHeight = 0; 54 private int imageWidth = 0; 55 private String applicationIdentifier = "null"; 56 57 public BarcodeReportElement(int x, int y, int width, int height) { 58 super(x, y, ( width == 0 ? 1 : Math.abs(width)) , (height == 0 ? 1 : Math.abs(height)) ); 60 61 if (barcodeError == null) 62 { 63 barcodeError = Misc.loadImageFromResources("it/businesslogic/ireport/icons/barcodeerror.png"); 64 } 65 66 setBarCodeImg(type, text, showText, checkSum); 68 setImageClass("java.awt.Image"); 69 setScaleImage("RetainShape"); 70 setGraphicElementPen("None"); 71 setHyperlinkType("None"); 72 setAnchorNameExpression(""); 73 setImgDef(null); 74 setKey("barcode"); 75 } 76 77 public void setBarCodeImg(int type, String text, boolean showText, boolean checkSum){ 78 79 StringBuffer bcCall = new StringBuffer ("it.businesslogic.ireport.barcode.BcImage.getBarcodeImage("); 80 bcCall.append(type); 82 83 bcCall.append(","); 85 bcCall.append(text); 86 bcCall.append(","); 87 93 bcCall.append(showText); 94 bcCall.append(","); 95 bcCall.append(checkSum); 96 bcCall.append(","); 97 bcCall.append( applicationIdentifier); 98 bcCall.append(","); 99 bcCall.append( getImageWidth() + "," + getImageHeight()); 100 bcCall.append(")"); 101 102 super.setImageExpression(bcCall.toString()); 103 104 try{ 105 106 setImg(it.businesslogic.ireport.barcode.BcImage.getBarcodeImage(type, text, showText, checkSum,getApplicationIdentifier(),getImageWidth(),getImageHeight())); 107 lastError = null; 108 109 } catch (RuntimeException e) { 110 111 setImg(barcodeError); 113 114 115 lastError = e.getMessage(); 117 } 118 } 119 120 148 public void setImageExpression(java.lang.String imageExpression) { 149 super.setImageExpression(imageExpression); 150 final int numberOfParams = 7; 151 155 String iE = imageExpression.substring(imageExpression.indexOf("(") + 1, imageExpression.lastIndexOf(")")); 156 String [] params = iE.split(","); 157 int paramCount = params.length; 158 159 type = new Integer (params[0]).intValue(); 161 String text = ""; 162 for (int i=0; i <= paramCount - numberOfParams; i++) 163 { 164 text += params[i+1] + ","; 165 } 166 text = text.substring(0, text.length() - 1); 167 168 setText(text); 169 170 showText = new Boolean (params[2 + (paramCount - numberOfParams)]).booleanValue(); 171 checkSum = new Boolean (params[3 + (paramCount - numberOfParams)]).booleanValue(); 172 173 if (params.length > 4) 174 { 175 this.setApplicationIdentifier( params[4 + (paramCount - numberOfParams)] ); 176 this.setImageWidth( Integer.parseInt( params[5 + (paramCount - numberOfParams)]) ); 177 this.setImageHeight( Integer.parseInt( params[6 + (paramCount - numberOfParams)]) ); 178 } 179 180 update(); 181 } 182 183 184 public void setShowText(boolean showText) { 185 this.showText = showText; 186 update(); 187 } 188 189 public boolean isShowText() { 190 return this.showText; 191 } 192 193 public void update() { 194 195 setBarCodeImg(type, text, showText, checkSum); 196 197 205 this.updateBounds(); 206 } 207 208 public ReportElement cloneMe() { 209 BarcodeReportElement newReportElement = new BarcodeReportElement(position.x, position.y, width, height); 210 copyBaseReportElement(newReportElement, this); 211 newReportElement.setImageHeight( this.getImageHeight()); 212 newReportElement.setImageWidth( this.getImageWidth()); 213 newReportElement.setApplicationIdentifier( this.getApplicationIdentifier()); 214 return newReportElement; 215 } 216 217 public java.lang.String getTitle() { 218 return title; 219 } 220 221 public void setTitle(java.lang.String title) { 222 this.title = title; 223 this.setImg(null); 224 } 225 226 public String getText() { 227 return this.text; 228 } 229 230 public void setText(String text) { 231 this.text = text; 232 update(); 233 } 234 235 public int getType() { 236 return this.type; 237 } 238 239 public void setType(int type) { 240 this.type = type; 241 } 242 243 public boolean isCheckSum() { 244 return this.checkSum; 245 } 246 247 public void setCheckSum(boolean checkSum) { 248 this.checkSum = checkSum; 249 update(); 250 } 251 252 256 public String getLastError() { 257 return lastError; 258 } 259 260 261 262 public int getImageHeight() { 263 return imageHeight; 264 } 265 266 public void setImageHeight(int imageHeight) { 267 this.imageHeight = imageHeight; 268 update(); 269 } 270 271 public String getApplicationIdentifier() { 272 if (applicationIdentifier == null || applicationIdentifier.equals("null")) return ""; 273 return applicationIdentifier; 274 } 275 276 public void setApplicationIdentifier(String applicationIdentifier) { 277 if (applicationIdentifier == null || applicationIdentifier.equals("")) applicationIdentifier = "null"; 278 this.applicationIdentifier = applicationIdentifier; 279 update(); 280 } 281 282 public int getImageWidth() { 283 return imageWidth; 284 } 285 286 public void setImageWidth(int imageWidth) { 287 this.imageWidth = imageWidth; 288 update(); 289 } 290 291 } 292 | Popular Tags |