net.sourceforge.barbecue.linear.code128
Class Code128Barcode

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended bynet.sourceforge.barbecue.Barcode
                  extended bynet.sourceforge.barbecue.linear.code128.Code128Barcode
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
UCCEAN128Barcode

public class Code128Barcode
extends Barcode

This is a concrete implementation of the Code 128 barcode. It fully supports all three available character sets (A, B and C), and also fully supports code shifts and set changes on-the-fly, providing an automatic optimisation mode.

Author:
Ian Bourke
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int A
          Character set A flag
static int B
          Character set B flag
protected static int[] BUF_SIZES
           
static int C
          Character set c flag
static java.lang.String CHANGE_TO_A
          Code set change from current to A character
static java.lang.String CHANGE_TO_B
          Code set change from current to B character
static java.lang.String CHANGE_TO_C
          Code set change from current to c character
static java.lang.String FNC_1
          FNC1 start character
protected  int mode
           
static int O
          Auto character set flag
protected static Module QUIET_SECTION
           
static java.lang.String SHIFT
          Code shift character
protected static Module START_A
           
protected static Module START_B
           
protected static Module START_C
           
protected static int[] START_INDICES
           
protected  int startIndex
           
protected static Module STOP
           
 
Fields inherited from class net.sourceforge.barbecue.Barcode
barHeight, barWidth, data, drawingText
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Code128Barcode(java.lang.String data)
          Create a new Code 128 barcode using character set B.
Code128Barcode(java.lang.String data, int mode)
          Creates a new Coded 128 barcode with the specified data and the specified character set.
 
Method Summary
protected  Module calculateChecksum()
          Calculates the check sum digit for the barcode.
protected  double calculateMinimumBarHeight(int resolution)
          Calculates the minimum allowed barcode height for the barcode.
protected  Module[] encodeData()
          Encodes the data of the barcode into bars.
protected  double getBarcodeWidth(int resolution)
          Returns the total width of the barcode in pixels at the given resolution.
 int getCharacterSet()
          Returns the current character set being used in this barcode.
protected  java.lang.String getLabel()
          Returns the text label to be displayed underneath the barcode/
protected  Module getPostAmble()
          Returns the post amble for the barcode.
protected  Module getPreAmble()
          Returns the pre-amble for the barcode.
protected  double getQuietZoneWidth()
          Returns the width of the quiet zone.
protected  double getSymbolWidth(int resolution)
          Returns the width of the encoded symbol portion of the barcode in pixels for the given resolution.
 
Methods inherited from class net.sourceforge.barbecue.Barcode
beautify, draw, drawModule, getBounds, getBounds, getData, getHeight, getMaximumSize, getMinimumSize, getPreferredSize, getResolution, getSize, getSVG, getWidth, getX, getY, isDrawingText, outputSVG, paintComponent, setBarHeight, setBarWidth, setDrawingText, setFont, setResolution, setSVGScalar
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

A

public static final int A
Character set A flag

See Also:
Constant Field Values

B

public static final int B
Character set B flag

See Also:
Constant Field Values

C

public static final int C
Character set c flag

See Also:
Constant Field Values

O

public static final int O
Auto character set flag

See Also:
Constant Field Values

SHIFT

public static final java.lang.String SHIFT
Code shift character

See Also:
Constant Field Values

CHANGE_TO_A

public static final java.lang.String CHANGE_TO_A
Code set change from current to A character

See Also:
Constant Field Values

CHANGE_TO_B

public static final java.lang.String CHANGE_TO_B
Code set change from current to B character

See Also:
Constant Field Values

CHANGE_TO_C

public static final java.lang.String CHANGE_TO_C
Code set change from current to c character

See Also:
Constant Field Values

FNC_1

public static final java.lang.String FNC_1
FNC1 start character

See Also:
Constant Field Values

START_A

protected static final Module START_A

START_B

protected static final Module START_B

START_C

protected static final Module START_C

STOP

protected static final Module STOP

QUIET_SECTION

protected static final Module QUIET_SECTION

START_INDICES

protected static final int[] START_INDICES

BUF_SIZES

protected static final int[] BUF_SIZES

startIndex

protected int startIndex

mode

protected int mode
Constructor Detail

Code128Barcode

public Code128Barcode(java.lang.String data)
               throws BarcodeException
Create a new Code 128 barcode using character set B.

Parameters:
data - The data to encode
Throws:
BarcodeException - If the data to be encoded is invalid

Code128Barcode

public Code128Barcode(java.lang.String data,
                      int mode)
               throws BarcodeException
Creates a new Coded 128 barcode with the specified data and the specified character set.

Parameters:
data - The data to encode
mode - The character set to use for encoding
Throws:
BarcodeException - If the data to be encoded is invalid
Method Detail

getCharacterSet

public int getCharacterSet()
Returns the current character set being used in this barcode.

Returns:
The flag indicating the current character set

getLabel

protected java.lang.String getLabel()
Returns the text label to be displayed underneath the barcode/

Overrides:
getLabel in class Barcode
Returns:
The text label for the barcode

getBarcodeWidth

protected double getBarcodeWidth(int resolution)
Returns the total width of the barcode in pixels at the given resolution.

Specified by:
getBarcodeWidth in class Barcode
Parameters:
resolution - The resolution to calculate the width for
Returns:
The width of the barcode in pixels

getSymbolWidth

protected double getSymbolWidth(int resolution)
Returns the width of the encoded symbol portion of the barcode in pixels for the given resolution.

Parameters:
resolution - The resolution to calculate the width for
Returns:
The width of the encoded portion of the barcode

calculateMinimumBarHeight

protected double calculateMinimumBarHeight(int resolution)
Calculates the minimum allowed barcode height for the barcode. The height must be at least .15 times the length of the symbol (excluding quiet zones) and .25 inches (whichever is larger).

Overrides:
calculateMinimumBarHeight in class Barcode
Parameters:
resolution - The output resolution (for calculating the width)
Returns:
The minimum height

encodeData

protected Module[] encodeData()
Encodes the data of the barcode into bars.

Specified by:
encodeData in class Barcode
Returns:
The encoded bar data

calculateChecksum

protected Module calculateChecksum()
Calculates the check sum digit for the barcode.

Specified by:
calculateChecksum in class Barcode
Returns:
The check sum digit

getPreAmble

protected Module getPreAmble()
Returns the pre-amble for the barcode. This is a combination of a quiet section and the start character for the character set that the barcode was constructed with.

Specified by:
getPreAmble in class Barcode
Returns:
The pre-amble

getPostAmble

protected Module getPostAmble()
Returns the post amble for the barcode. This is the combination of the stop character anda quiet section.

Specified by:
getPostAmble in class Barcode
Returns:
The post amble

getQuietZoneWidth

protected double getQuietZoneWidth()
Returns the width of the quiet zone.

Returns:
The quiet zone width