001: /* ============================================================================
002: * GNU Lesser General Public License
003: * ============================================================================
004: *
005: * Copyright (C) 2001-2007 JasperSoft Corporation http://www.jaspersoft.com
006: *
007: * This class is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This class is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this class; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * JasperSoft Corporation
022: * 303 Second Street, Suite 450 North
023: * San Francisco, CA 94107
024: * http://www.jaspersoft.com
025: *
026: *
027: *
028: * BcImage.java
029: *
030: * Created on 20. April 2004, 13:21
031: *
032: */
033:
034: package it.businesslogic.ireport.barcode;
035:
036: /**
037: *
038: * @author Heiko
039: */
040:
041: import java.awt.image.*;
042: import net.sourceforge.barbecue.*;
043: import net.sourceforge.barbecue.linear.ean.UCCEAN128Barcode;
044:
045: public class BcImage {
046: private static net.sourceforge.barbecue.Barcode bc = null;
047:
048: public static net.sourceforge.barbecue.Barcode getBarcode() {
049: return bc;
050: }
051:
052: public static BufferedImage getBarcodeImage(int type, Object aText,
053: boolean showText, boolean checkSum) {
054: return getBarcodeImage(type, aText, showText, checkSum, "", 0,
055: 0);
056: }
057:
058: public static BufferedImage getBarcodeImage(int type, Object aText,
059: boolean showText, boolean checkSum,
060: String applicationIdentifier, int width, int height) {
061: // 2of7, 3of9, Bookland, Codabar, Code128, Code128A, Code128B, Code128C, Code39, EAN128, EAN13, GlobalTradeItemNumber, Int2of5, Int2of5, Monarch, NW7, PDF417, SCC14ShippingCode, ShipmentIdentificationNumber, SSCC18, Std2of5, Std2of5, UCC128, UPCA, USD3, USD4, USPS
062:
063: String text = new StringBuffer().append(aText).toString();
064:
065: try {
066: switch (type) {
067: case 0:
068: return null;
069: case 1:
070: bc = BarcodeFactory.create2of7(text);
071: break;
072: case 2:
073: bc = BarcodeFactory.create3of9(text, checkSum);
074: break;
075: case 3:
076: bc = BarcodeFactory.createBookland(text);
077: break;
078: case 4:
079: bc = BarcodeFactory.createCodabar(text);
080: break;
081: case 5:
082: bc = BarcodeFactory.createCode128(text);
083: break;
084: case 6:
085: bc = BarcodeFactory.createCode128A(text);
086: break;
087: case 7:
088: bc = BarcodeFactory.createCode128B(text);
089: break;
090: case 8:
091: bc = BarcodeFactory.createCode128C(text);
092: break;
093: case 9:
094: bc = BarcodeFactory.createCode39(text, checkSum);
095: break;
096: case 10:
097: bc = BarcodeFactory.createEAN128(text);
098: break;
099: case 11:
100: bc = BarcodeFactory.createEAN13(text);
101: break;
102: case 12:
103: bc = BarcodeFactory.createGlobalTradeItemNumber(text);
104: break;
105: case 13:
106: bc = BarcodeFactory.createInt2of5(text, checkSum);
107: break;
108: case 14:
109: bc = BarcodeFactory.createMonarch(text);
110: break;
111: case 15:
112: bc = BarcodeFactory.createNW7(text);
113: break;
114: case 16:
115: bc = BarcodeFactory.createPDF417(text);
116: break;
117: case 17:
118: bc = BarcodeFactory.createSCC14ShippingCode(text);
119: break;
120: case 18:
121: bc = BarcodeFactory
122: .createShipmentIdentificationNumber(text);
123: break;
124: case 19:
125: bc = new UCCEAN128Barcode(UCCEAN128Barcode.SSCC_18_AI,
126: text, checkSum);
127: break; //BarcodeFactory.createSSCC18(text); break;
128: case 20:
129: bc = BarcodeFactory.createStd2of5(text, checkSum);
130: break;
131: case 21:
132: bc = new UCCEAN128Barcode(applicationIdentifier, text,
133: checkSum);
134: break; //BarcodeFactory.createUCC128(applicationIdentifier, text); break;
135: case 22:
136: bc = BarcodeFactory.createUPCA(text);
137: break;
138: case 23:
139: bc = BarcodeFactory.createUSD3(text, checkSum);
140: break;
141: case 24:
142: bc = BarcodeFactory.createUSD4(text);
143: break;
144: case 25:
145: bc = BarcodeFactory.createUSPS(text);
146: break;
147: case 26:
148: bc = new net.sourceforge.barbecue.linear.code39.Code39Barcode(
149: text, checkSum, true);
150: break;
151: }
152:
153: if (width > 0)
154: bc.setBarWidth(width);
155: if (height > 0)
156: bc.setBarHeight(height);
157: bc.setDrawingText(showText);
158: return net.sourceforge.barbecue.BarcodeImageHandler
159: .getImage(bc);
160: } catch (Exception e) {
161: e.printStackTrace();
162: //generate a runtime exception, invalid value passed.
163: //the user must be notified if fail
164: throw new RuntimeException(e.getMessage());
165: //return null;
166: }
167: }
168: }
|