com.java4less.rbarcode
Class BarCode

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by com.java4less.rbarcode.BarCode
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
BarCode2D, BarCodeBean, RDataMatrix

public class BarCode
extends java.awt.Canvas

Main class. This is subclass of the java.awt.Canvas where the barcode will be painted.

 Example, how to add RBarcode to your Panel:
 
   BarCode bc= new BarCode();
   bc.setSize(400 , 200);
   bc.barType = BarCode.EAN128;
   bc.resolution=1;
   bc.leftMarginCM= 50;
   bc.topMarginCM= 50;
   bc.checkCharacter =true;
   bc.code = "1291898"+ ((char) 29)+ "293823";
   bc.barColor = java.awt.Color.black;
   bc.backColor= java.awt.Color.white;
   bc.fontColor = java.awt.Color.blue;
   bc.textFont = new java.awt.Font("Arial",java.awt.Font.BOLD,14);
   bc.X = 1;
   bc.N = 3;
   myPanel.add(bc);
 
 Example, how to create an image file:
 
   BarCode bc= new BarCode();
    
   ...
  
   bc.setSize(500,500); // set size of the canvas
   BarCodeEncoder encoder= new BarCodeEncoder(bc, "JPEG","barcode.jpg");
 
 Example, how to paint on an external Graphics object:
 
   BarCode bc= new BarCode();
   ...
   bc.setSize(500,500); // set size of the canvas
   java.awt.image.BufferedImage image2 = new java.awt.image.BufferedImage(800,800,java.awt.image.BufferedImage.TYPE_BYTE_INDEXED );
   bc.paint(image2.createGraphics());
 
 

See Also:
Serialized Form

Field Summary
 java.awt.Color backColor
          background color.
static int BAR39
          Code 39 symbology
static int BAR39EXT
          Code extended 39 symbology
 java.awt.Color barColor
          color of the bars.The default value is Color.black.
 double barHeightCM
          bar height in CM.
 int barType
          Symbology to be used.
 boolean checkCharacter
          if true, the checksum character will be calculated and appended to the code.
static int CODABAR
          Codebar symbology
 char CODABARStartChar
          start character for CODABAR.
 char CODABARStopChar
          stop character for CODABAR.
 java.lang.String code
          text to be encoded as barcode.
static int CODE11
          Code 11 symbology
static int CODE128
          Code 128 symbology
 char Code128Set
          set of character to be used in code 128.
static int CODE93
          Code 93 symbology
static int CODE93EXT
          Code 93 extended symbology
 java.lang.String codeText
          text after encoding.
static int DATAMATRIX
          Datamatrix symbology (implemented in com/java4less/rdatamatrix/RDataMatrix
static int EAN128
          EAN 128 symbology
static int EAN13
          EAN 13 symbology
static int EAN8
          EAN 8 symbology
 java.awt.Color fontColor
          color of the text.
 boolean guardBars
          if true (default), guardbars in EAN and UPC codes will be longer than data bars.
 double H
          height of bars.
 double I
          space between 2 characters (code 39).
static int IND25
          Industrial 2 of 5 symbology
static int INTERLEAVED25
          Interleaved 2 of 5 symbology
 double L
          Symbol length in CM.
 double leftMarginCM
          left margin of the barcode (also know as quite zone).
static int MAT25
          Matrix 2 of 5 symbology
static int MSI
          MSI symbology
static int MSI_CHECKSUM_10
          MSI 10 checksum algorithm
static int MSI_CHECKSUM_10_10
          MSI 10 + 10 checksum algorithm
static int MSI_CHECKSUM_11
          MSI 11 checksum algorithm
static int MSI_CHECKSUM_11_10
          MSI 11 + 10 checksum algorithm
 int MSIChecksum
          MSI checksum algorithm.
 double N
          multiplicator value for width bars.
static int PDF417
          PDF417 symbology (implemented in com/java4less/rbarcode/RBarCode2D
static int POSTNET
          Postnet symbology
 double postnetHeightShortBar
          height in CM of POSTNET's short bars.
 double postnetHeightTallBar
          height in CM of POSTNET's tall bars.
 boolean processTilde
          process ~ in code?
 int resolution
           resolution used to convert from CM to pixels.
 int rotate
          rotation angle.
 double supHeight
          height of the supplement.
 java.lang.String supplement
          user defined 2 or 5 digit supplement for EAN or UPC codes.
 double supSeparationCM
          Separation in CM between the barcode and the supplement
 java.awt.Font textFont
          font of the text.
 boolean textOnTop
          put text on the top of the barcode
 double topMarginCM
          top margin of the barcode (also know as quite zone).
static int UPCA
          UPCA symbology
static int UPCE
          UPCE symbology
 boolean UPCEANSupplement2
          2 digit supplement for EAN or UPC codes.
 boolean UPCEANSupplement5
          5 digit supplement for EAN or UPC codes.
 char UPCESytem
          system to be used in UPCE.
 double X
          size in CM of modules (narrow bars or spaces).
 
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
BarCode()
           
 
Method Summary
 int getAiLen(java.lang.String d2)
           
 java.lang.String getEAN128Text(java.lang.String code)
           
 int getFixedFieldLen(int i)
           
 java.awt.Dimension getPaintedArea()
          return the size of the barcode after it has been painted
 void paint(java.awt.Graphics g2)
          paints the barcode and rotates it if necessary
 void print(java.awt.Graphics g2)
           
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, preferredSize, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BAR39

public static final int BAR39
Code 39 symbology

See Also:
Constant Field Values

BAR39EXT

public static final int BAR39EXT
Code extended 39 symbology

See Also:
Constant Field Values

INTERLEAVED25

public static final int INTERLEAVED25
Interleaved 2 of 5 symbology

See Also:
Constant Field Values

CODE11

public static final int CODE11
Code 11 symbology

See Also:
Constant Field Values

CODABAR

public static final int CODABAR
Codebar symbology

See Also:
Constant Field Values

MSI

public static final int MSI
MSI symbology

See Also:
Constant Field Values

UPCA

public static final int UPCA
UPCA symbology

See Also:
Constant Field Values

IND25

public static final int IND25
Industrial 2 of 5 symbology

See Also:
Constant Field Values

MAT25

public static final int MAT25
Matrix 2 of 5 symbology

See Also:
Constant Field Values

CODE93

public static final int CODE93
Code 93 symbology

See Also:
Constant Field Values

EAN13

public static final int EAN13
EAN 13 symbology

See Also:
Constant Field Values

EAN8

public static final int EAN8
EAN 8 symbology

See Also:
Constant Field Values

UPCE

public static final int UPCE
UPCE symbology

See Also:
Constant Field Values

CODE128

public static final int CODE128
Code 128 symbology

See Also:
Constant Field Values

CODE93EXT

public static final int CODE93EXT
Code 93 extended symbology

See Also:
Constant Field Values

POSTNET

public static final int POSTNET
Postnet symbology

See Also:
Constant Field Values

EAN128

public static final int EAN128
EAN 128 symbology

See Also:
Constant Field Values

PDF417

public static final int PDF417
PDF417 symbology (implemented in com/java4less/rbarcode/RBarCode2D

See Also:
Constant Field Values

DATAMATRIX

public static final int DATAMATRIX
Datamatrix symbology (implemented in com/java4less/rdatamatrix/RDataMatrix

See Also:
Constant Field Values

MSI_CHECKSUM_10

public static final int MSI_CHECKSUM_10
MSI 10 checksum algorithm

See Also:
Constant Field Values

MSI_CHECKSUM_11

public static final int MSI_CHECKSUM_11
MSI 11 checksum algorithm

See Also:
Constant Field Values

MSI_CHECKSUM_11_10

public static final int MSI_CHECKSUM_11_10
MSI 11 + 10 checksum algorithm

See Also:
Constant Field Values

MSI_CHECKSUM_10_10

public static final int MSI_CHECKSUM_10_10
MSI 10 + 10 checksum algorithm

See Also:
Constant Field Values

textOnTop

public boolean textOnTop
put text on the top of the barcode


barType

public int barType
Symbology to be used. Default is BAR39


code

public java.lang.String code
text to be encoded as barcode.


checkCharacter

public boolean checkCharacter
if true, the checksum character will be calculated and appended to the code. Default value is true.


postnetHeightTallBar

public double postnetHeightTallBar
height in CM of POSTNET's tall bars. The default is 0.25


postnetHeightShortBar

public double postnetHeightShortBar
height in CM of POSTNET's short bars. The default is 0.125


leftMarginCM

public double leftMarginCM
left margin of the barcode (also know as quite zone). The default is 0.5 CM.


topMarginCM

public double topMarginCM
top margin of the barcode (also know as quite zone). The default is 0.5 CM.


supplement

public java.lang.String supplement
user defined 2 or 5 digit supplement for EAN or UPC codes.


guardBars

public boolean guardBars
if true (default), guardbars in EAN and UPC codes will be longer than data bars.


backColor

public java.awt.Color backColor
background color.


codeText

public java.lang.String codeText
text after encoding. It will contain the appenden checksum, if calculated.


resolution

public int resolution
 
 resolution used to convert from CM to pixels. The value is pixels/CM. The default is 96 dpi.
 If you set the resolution to 1 then all units are pixels.
 


barHeightCM

public double barHeightCM
bar height in CM. If 0 it will be calculated using H.


textFont

public java.awt.Font textFont
font of the text. The default is Arial, size 11.


fontColor

public java.awt.Color fontColor
color of the text. The default value is Color.black.


barColor

public java.awt.Color barColor
color of the bars.The default value is Color.black.


UPCESytem

public char UPCESytem
system to be used in UPCE. It can be "0" or "1". The default is "1".


CODABARStartChar

public char CODABARStartChar
start character for CODABAR. The default is A.


CODABARStopChar

public char CODABARStopChar
stop character for CODABAR. The default is B.


UPCEANSupplement2

public boolean UPCEANSupplement2
2 digit supplement for EAN or UPC codes.


UPCEANSupplement5

public boolean UPCEANSupplement5
5 digit supplement for EAN or UPC codes.


Code128Set

public char Code128Set
set of character to be used in code 128. Possible values are 'A', 'B' or 'C' (only for numeric codes). The default is 'B'


MSIChecksum

public int MSIChecksum
MSI checksum algorithm. The default value is MSI_CHECKSUM_10


X

public double X
size in CM of modules (narrow bars or spaces). The resolution is used to converto to pixels.


N

public double N
multiplicator value for width bars. A value of 2 (default) means that wide bars will be 2*N CM width.


I

public double I
space between 2 characters (code 39). This a multiplicator of X. The default is 1.


H

public double H
height of bars. This a multiplicator of X. The default is 0.45.


L

public double L
Symbol length in CM. This is calculated by RBarcode and the user can read it.


rotate

public int rotate
rotation angle. Valid values are 0 (default),90,180 and 270.


supSeparationCM

public double supSeparationCM
Separation in CM between the barcode and the supplement


supHeight

public double supHeight
height of the supplement. This is a multiplicator of the height of the code. The default is 0.8 (80%).


processTilde

public boolean processTilde
process ~ in code?
 the string ~dNNN will be replace by the character for the ascii value NNN. For example d065 stands for A
 

Constructor Detail

BarCode

public BarCode()
Method Detail

getPaintedArea

public java.awt.Dimension getPaintedArea()
return the size of the barcode after it has been painted

Returns:

print

public void print(java.awt.Graphics g2)
Overrides:
print in class java.awt.Component

paint

public void paint(java.awt.Graphics g2)
paints the barcode and rotates it if necessary

Overrides:
paint in class java.awt.Canvas

getEAN128Text

public java.lang.String getEAN128Text(java.lang.String code)

getFixedFieldLen

public int getFixedFieldLen(int i)

getAiLen

public int getAiLen(java.lang.String d2)