net.sourceforge.jbarcodebean.model
Class Code128

java.lang.Object
  extended by net.sourceforge.jbarcodebean.model.AbstractBarcodeStrategy
      extended by net.sourceforge.jbarcodebean.model.Code128
All Implemented Interfaces:
BarcodeStrategy

public class Code128
extends AbstractBarcodeStrategy

Code 128 barcode strategy implementation. This format can encode the full 128 character ASCII character set (from 0 to 127 decimal), plus four special Code 128 function codes. These four codes are defined as constant class members for convenience: FNC_1 through FNC_4.


Nested Class Summary
 
Nested classes/interfaces inherited from class net.sourceforge.jbarcodebean.model.AbstractBarcodeStrategy
AbstractBarcodeStrategy.CharacterCode
 
Field Summary
protected static AbstractBarcodeStrategy.CharacterCode[] codes
          A static array of CharacterCode objects for Code 128.
static char FNC_1
          Code 128 FUNCTION CODE 1
static char FNC_2
          Code 128 FUNCTION CODE 2
static char FNC_3
          Code 128 FUNCTION CODE 3
static char FNC_4
          Code 128 FUNCTION CODE 4
 
Fields inherited from interface net.sourceforge.jbarcodebean.model.BarcodeStrategy
MANDATORY_CHECKSUM, NO_CHECKSUM, OPTIONAL_CHECKSUM
 
Constructor Summary
Code128()
           
 
Method Summary
protected  java.lang.String augmentWithChecksum(java.lang.String text)
          Returns a String containing the checksum-encoded version of the text passed to the method.
protected  java.lang.String getBarcodeLabelText(java.lang.String text)
          Returns the text parameter with function characters and control codes stripped out.
protected  AbstractBarcodeStrategy.CharacterCode[] getCodes()
          This implementation of getCodes returns an array of CharacterCode objects for the Code 128 format.
protected  byte getMarginWidth()
          Always returns 11 (eleven).
protected  char getStartSentinel()
          Always returns 0xffff, signalling to AbstractBarcodeStrategy superclass that it should not prefix a standard start character.
protected  char getStopSentinel()
          Always returns the Code 128 STOP character.
protected  boolean isInterleaved()
          Always returns false.
protected  java.lang.String postprocess(java.lang.String text)
          Does nothing except return the String passed to the method.
protected  java.lang.String preprocess(java.lang.String text)
          Inserts start character and code change characters.
 int requiresChecksum()
          Always returns BarcodeStrategy.MANDATORY_CHECKSUM.
 
Methods inherited from class net.sourceforge.jbarcodebean.model.AbstractBarcodeStrategy
computeSize, encode, getCharacterCode, getCharacterCode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FNC_1

public static final char FNC_1
Code 128 FUNCTION CODE 1

See Also:
Constant Field Values

FNC_2

public static final char FNC_2
Code 128 FUNCTION CODE 2

See Also:
Constant Field Values

FNC_3

public static final char FNC_3
Code 128 FUNCTION CODE 3

See Also:
Constant Field Values

FNC_4

public static final char FNC_4
Code 128 FUNCTION CODE 4

See Also:
Constant Field Values

codes

protected static AbstractBarcodeStrategy.CharacterCode[] codes
A static array of CharacterCode objects for Code 128. The getCodes() method returns this array. The character member of the elements in this array corresponds to the MODE B version of the character.

Constructor Detail

Code128

public Code128()
Method Detail

requiresChecksum

public int requiresChecksum()
Always returns BarcodeStrategy.MANDATORY_CHECKSUM.


getCodes

protected AbstractBarcodeStrategy.CharacterCode[] getCodes()
This implementation of getCodes returns an array of CharacterCode objects for the Code 128 format.

Specified by:
getCodes in class AbstractBarcodeStrategy
Returns:
An array of CharacterCode objects, one for each possible character that can be encoded using this strategy.

getBarcodeLabelText

protected java.lang.String getBarcodeLabelText(java.lang.String text)
Returns the text parameter with function characters and control codes stripped out.

Specified by:
getBarcodeLabelText in class AbstractBarcodeStrategy
Parameters:
text - The raw text to encode.
Returns:
A String containing the text that will appear beneath the barcode.

getMarginWidth

protected byte getMarginWidth()
Always returns 11 (eleven).

Specified by:
getMarginWidth in class AbstractBarcodeStrategy
Returns:
The space that must appear on the left and right sides of the barcode expressed as a multiple of the narrowest bar width.

getStartSentinel

protected char getStartSentinel()
Always returns 0xffff, signalling to AbstractBarcodeStrategy superclass that it should not prefix a standard start character. In Code 128 there are three possible start characters, and the preprocess method handles the insertion of the correct start code instead.

Specified by:
getStartSentinel in class AbstractBarcodeStrategy
Returns:
The character, which when encoded into bars and spaces, appears on the left edge of every barcode (immediately after the left margin).

getStopSentinel

protected char getStopSentinel()
Always returns the Code 128 STOP character.

Specified by:
getStopSentinel in class AbstractBarcodeStrategy
Returns:
The character, which when encoded into bars and spaces, appears on the right edge of every barcode (just before the right margin).

isInterleaved

protected boolean isInterleaved()
Always returns false.

Specified by:
isInterleaved in class AbstractBarcodeStrategy
Returns:
true if barcode type is interleaved, false if it is not.

preprocess

protected java.lang.String preprocess(java.lang.String text)
                               throws BarcodeException
Inserts start character and code change characters.

Specified by:
preprocess in class AbstractBarcodeStrategy
Parameters:
text - The raw text to encode.
Returns:
The string after preprocessing. If no preprocessing is required, the String passed to the method is returned.
Throws:
BarcodeException - Typically caused by passing in a String containing illegal characters (characters that cannot be encoded in this type of barcode).

postprocess

protected java.lang.String postprocess(java.lang.String text)
Does nothing except return the String passed to the method.

Specified by:
postprocess in class AbstractBarcodeStrategy
Parameters:
text - String to process (returned by AbstractBarcodeStrategy.augmentWithChecksum(java.lang.String)).
Returns:
String after postprocessing. If no postprocessing is required, the String passed to the method is returned.

augmentWithChecksum

protected java.lang.String augmentWithChecksum(java.lang.String text)
                                        throws BarcodeException
Returns a String containing the checksum-encoded version of the text passed to the method. It is assumed that the text passed to this method includes the Start character (populated by preprocess), but not the Stop character (end sentinel).

Specified by:
augmentWithChecksum in class AbstractBarcodeStrategy
Parameters:
text - The text to encode (after preprocessing - see AbstractBarcodeStrategy.preprocess(java.lang.String)).
Returns:
A String containing the text passed into the method, augmented with the checksum. For barcode types that don't support a checksum, this would simply be the text passed to the method.
Throws:
BarcodeException


Copyright © 2004-2009 The JBarcodeBean project. All Rights Reserved.