1 package net.sourceforge.barbecue.linear; 2 3 import net.sourceforge.barbecue.Barcode; 4 import net.sourceforge.barbecue.BarcodeException; 5 import net.sourceforge.barbecue.Module; 6 import net.sourceforge.barbecue.output.LabelLayoutFactory; 7 import net.sourceforge.barbecue.output.Output; 8 import net.sourceforge.barbecue.output.OutputException; 9 10 import java.awt.*; 11 12 public abstract class LinearBarcode extends Barcode { 13 14 protected LinearBarcode(String data) throws BarcodeException { 15 super(data); 16 } 17 18 protected Dimension draw(Output output, int x, int y, int barWidth, int barHeight) throws OutputException { 19 int currentX = x; 20 Module preAmble = getPreAmble(); 21 Module postAmble = getPostAmble(); 22 output.beginDraw(); 23 24 if (preAmble != null) { 25 currentX += drawModule(getPreAmble(), output, currentX, y, barWidth, barHeight); 26 } 27 28 Module[] modules = encodeData(); 29 for (int i = 0; i < modules.length; i++) { 30 Module module = modules[i]; 31 currentX += drawModule(module, output, currentX, y, barWidth, barHeight); 32 } 33 34 currentX += drawModule(calculateChecksum(), output, currentX, y, barWidth, barHeight); 35 36 if (postAmble != null) { 37 currentX += drawModule(postAmble, output, currentX, y, barWidth, barHeight); 38 } 39 40 int currentY = this.barHeight + y; 41 42 if (drawingText) { 43 currentY += drawTextLabel(output, x, currentY, currentX); 44 } 45 46 Dimension size = new Dimension(currentX - x, currentY - y); 47 output.endDraw((int) size.getWidth(), (int) size.getHeight()); 48 return size; 49 } 50 51 protected int drawTextLabel(Output params, int x, int y, int width) throws OutputException { 52 return params.drawText(getLabel(), LabelLayoutFactory.createCenteredLayout(x, y, width)); 53 } 54 }