001 /**
002 * This library is free software; you can redistribute it and/or modify it
003 * under the terms of the GNU Lesser General Public License (LGPL) as
004 * published by the Free Software Foundation; either version 3.0 of the
005 * License, or (at your option) any later version.
006 *
007 * This library is distributed in the hope that it will be useful, but
008 * WITHOUT ANY WARRANTY; without even the implied warranty of
009 * MERCHANTABILITY of FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010 * Lesser General Public License for more details.
011 */
012
013 /**
014 * Title: JBarcodeBean
015 * Description: Barcode JavaBeans Component
016 * Copyright: Copyright (C) 2004
017 * Company: Dafydd Walters
018 */
019 package net.sourceforge.jbarcodebean.model;
020
021 import net.sourceforge.jbarcodebean.BarcodeException;
022
023 /**
024 * This class, which implements the {@link BarcodeStrategy} interface,
025 * knows how to encode the 3:1 (wide)
026 * variant of the Codabar barcode type.
027 */
028 public class Codabar extends AbstractBarcodeStrategy implements java.io.Serializable {
029
030 private static CharacterCode[] codes = {
031 new CharacterCode('0', new byte[] {1,1,1,1,1,3,3,1}, 0),
032 new CharacterCode('1', new byte[] {1,1,1,1,3,3,1,1}, 1),
033 new CharacterCode('2', new byte[] {1,1,1,3,1,1,3,1}, 2),
034 new CharacterCode('3', new byte[] {3,3,1,1,1,1,1,1}, 3),
035 new CharacterCode('4', new byte[] {1,1,3,1,1,3,1,1}, 4),
036 new CharacterCode('5', new byte[] {3,1,1,1,1,3,1,1}, 5),
037 new CharacterCode('6', new byte[] {1,3,1,1,1,1,3,1}, 6),
038 new CharacterCode('7', new byte[] {1,3,1,1,3,1,1,1}, 7),
039 new CharacterCode('8', new byte[] {1,3,3,1,1,1,1,1}, 8),
040 new CharacterCode('9', new byte[] {3,1,1,3,1,1,1,1}, 9),
041 new CharacterCode('-', new byte[] {1,1,1,3,3,1,1,1}, 10),
042 new CharacterCode('$', new byte[] {1,1,3,3,1,1,1,1}, 11),
043 new CharacterCode(':', new byte[] {3,1,1,1,3,1,3,1}, 12),
044 new CharacterCode('/', new byte[] {3,1,3,1,1,1,3,1}, 13),
045 new CharacterCode('.', new byte[] {3,1,3,1,3,1,1,1}, 14),
046 new CharacterCode('+', new byte[] {1,1,3,1,3,1,3,1}, 15),
047 new CharacterCode('A', new byte[] {1,1,3,3,1,3,1,1}, 16), // Start
048 new CharacterCode('B', new byte[] {1,3,1,3,1,1,3,1}, 17) // Stop
049 };
050
051 /**
052 * Always returns {@link BarcodeStrategy#NO_CHECKSUM}.
053 */
054 public int requiresChecksum() {
055 // No checksum
056 return NO_CHECKSUM;
057 }
058
059 /**
060 * This implementation of <tt>getCodes</tt> returns an array of
061 * {@link AbstractBarcodeStrategy.CharacterCode CharacterCode} objects
062 * for the wide Codabar format.
063 */
064 protected CharacterCode[] getCodes() {
065 return Codabar.codes;
066 }
067
068 /**
069 * Codabar does not have a checksum, so this function should never be called.
070 * This implementation simply throws an exception.
071 */
072 protected String augmentWithChecksum(String text) throws BarcodeException {
073 throw new BarcodeException("No checksum in Codabar");
074 }
075
076 /**
077 * This implementation of <tt>postprocess</tt> does nothing except return
078 * the text passed to the method.
079 */
080 protected String postprocess(String text) {
081 return text;
082 }
083
084 /**
085 * This implementation of <tt>preprocess</tt> does nothing except return
086 * the text passed to the method.
087 */
088 protected String preprocess(String text) {
089 return text;
090 }
091
092 /**
093 * Always returns <tt>false</tt>
094 */
095 protected boolean isInterleaved() {
096 return false;
097 }
098
099 /**
100 * Always returns 'A'.
101 */
102 protected char getStartSentinel() {
103 return 'A';
104 }
105
106 /**
107 * Always returns 'B'.
108 */
109 protected char getStopSentinel() {
110 return 'B';
111 }
112
113 /**
114 * Always returns 11 (eleven).
115 */
116 protected byte getMarginWidth() {
117 return 11;
118 }
119
120 /**
121 * This implementation of <tt>getBarcodeLabelText</tt> does nothing except return
122 * the text passed to the method.
123 */
124 protected String getBarcodeLabelText(String text) {
125 return text;
126 }
127 }