jbars
Class Barcode

java.lang.Object
  |
  +--jbars.Barcode
Direct Known Subclasses:
Barcode128, Barcode93, BarcodeInter25

public abstract class Barcode
extends java.lang.Object

Base class containing properties and methods commom to all barcode types. This class is based on iText "A Free Java-PDF library by Bruno Lowagie and Paulo Soares" using the Mozilla Public License(MPL)

Author:
Andres Ederra, Paulo Soares

Field Summary
static int ALIGN_CENTER
          Center alignment
static int ALIGN_LEFT
          Left alignment
static int ALIGN_RIGHT
          Rigth alignment
protected  java.awt.Color backgroundColor
           
protected  float barHeight
          The height of the bars.
protected  boolean checksumText
          Shows the generated checksum in the the text.
static int CODABAR
          A type of barcode
protected  java.lang.String code
          The code to generate.
static int CODE128
          A type of barcode
static int CODE128_RAW
          A type of barcode
static int CODE128_UCC
          A type of barcode
static int CODE93
          A type of barcode
protected  int codeType
          The code type.
static int EAN13
          A type of barcode
static int EAN8
          A type of barcode
protected  boolean extended
          Generates extended barcode 39.
protected  java.awt.Font font
          The font to use in the text of the codebar
protected  boolean generateChecksum
          The optional checksum generation.
protected  boolean guardBars
          Show the guard bars for barcode EAN.
protected  float n
          The bar multiplier for wide bars or the distance between bars for Postnet and Planet.
static int PLANET
          A type of barcode
static int POSTNET
          A type of barcode
protected  boolean quietZone
          The option to generate a starting and ending quiet zone
protected  int quietZoneX
          The width of the quiet zone expressed in multiples of x(the minimun width of the bar)
static double ROTATE_0
           
static double ROTATE_180
           
static double ROTATE_270
           
static double ROTATE_90
           
protected  boolean showText
          The property to show the text for barcode.
protected  float size
          The size of the text or the height of the shorter bar in Postnet.
protected  boolean startStopText
          Show the start and stop character '*' in the text for the barcode 39 or 'ABCD' for codabar.
static int SUPP2
          A type of barcode
static int SUPP5
          A type of barcode
protected  int textAlignment
          The text alignment.
protected  boolean transparent
           
static java.lang.String TYPE_CODE128
           
static java.lang.String TYPE_CODE93
           
static java.lang.String TYPE_INTERLEAVED2OF5
           
static int UPCA
          A type of barcode
static int UPCE
          A type of barcode
protected  float x
          The minimum bar width.
 
Constructor Summary
Barcode()
           
 
Method Summary
static java.awt.Image createImage(java.lang.String codeType, java.lang.String codeValue)
          Creates a image representing a codebar using a codebar type and the codebar code
static java.awt.Image createImage(java.lang.String codeType, java.lang.String codeValue, float barHeight, java.lang.String fontName, int fontSize, boolean transparent, int alignment, int fontStyle, java.awt.Color newBarColor, java.awt.Color newTextColor, int orientacion)
          Creates a image representing a codebar using a codebar type and the codebar code
 byte[] createPNG(int y, java.awt.Color barColor, java.awt.Color textColor)
          Creates a PNG image data that represents the barcode.
 byte[] createPNG(int y, java.awt.Color barColor, java.awt.Color textColor, double angle)
          Creates a PNG image data that represents the barcode.
 byte[] createPNG(int y, java.awt.Color barColor, java.awt.Color textColor, int colorspace)
          Creates a PNG image data that represents the barcode.
 byte[] createPNG(int y, java.awt.Color barColor, java.awt.Color textColor, int colorspace, double angle)
          Creates a PNG image data that represents the barcode.
 byte[] createPNG(int x, int y, int colorspace, java.awt.Color barColor, java.awt.Color textColor)
          Creates a PNG image data that represents the barcode.
 byte[] createPNG(int x, int y, int colorspace, java.awt.Color barColor, java.awt.Color textColor, double angle)
          Creates a PNG image data that represents the barcode,and rotates the image.
protected  byte[] encodePNG(java.awt.image.BufferedImage image)
          Encodes an image into a PNG according to the barcode parameters
 java.awt.Color getBackgroundColor()
          Gets the background color to use
protected abstract  float getBarcodeWidth()
          Gets the maximum width that the barcode will occupy.
 float getBarHeight()
          Gets the height of the bars.
 java.lang.String getCode()
          Gets the code to generate.
 int getCodeType()
          Gets the code type.
 java.awt.Font getFont()
          Gets the font to use in the text of the barcode
 java.lang.String getFontName()
          Gets name of the font to use in the text of the barcode Return null if no text is displayed
 int getFontSize()
          Gets size of the font to use in the text of the barcode Return -1 if no text is displayed
 int getFontStyle()
          Gets style of the font to use in the text of the barcode Return -1 if no text is displayed
 float getN()
          Gets the bar multiplier for wide bars.
 int getQuietZoneX()
          Get the width of the quiet zone
 float getSize()
          Gets the size of the text.
 int getTextAlignment()
          Gets the text alignment.
 float getX()
          Gets the minimum bar width.
 boolean isChecksumText()
          Gets the property to show the generated checksum in the the text.
 boolean isExtended()
          Gets the property to generate extended barcode 39.
 boolean isGenerateChecksum()
          Gets the optional checksum generation.
 boolean isGuardBars()
          Gets the property to show the guard bars for barcode EAN.
 boolean isQuietZone()
          Gets the property to show the quiet zone at start and end of the bars.
 boolean isShowText()
          Gets the property to show the text for barcode.
 boolean isStartStopText()
          Sets the property to show the start and stop character '*' in the text for the barcode 39.
 boolean isTransparent()
          Get the tranaparent background property
abstract  void placeBarcode(java.awt.image.BufferedImage i, java.awt.Color barColor, java.awt.Color textColor)
          Places the barcode in a BufferedImage.
 int scale(int imageSize, float totalSize, float coordinate)
          Scales a logical coordinate to fit a physical image corrdinate Example: Having the logical dimension 200, and the logical coordinate 20.5 we want to scale the coordinate to a 300 pixel physical dimension.
 void setBackgroundColor(java.awt.Color newBackgroundColor)
          Set the backgroud color od the barcode Default color is white
 void setBarHeight(float barHeight)
          Sets the height of the bars.
 void setChecksumText(boolean checksumText)
          Sets the property to show the generated checksum in the the text.
 void setCode(java.lang.String code)
          Sets the code to generate.
 void setCodeType(int codeType)
          Sets the code type.
 void setExtended(boolean extended)
          Sets the property to generate extended barcode 39.
 void setFont(java.awt.Font newFont)
          Sets the font to use null font prints no text.
 void setFontName(java.lang.String newFontName)
          Modifies the font name
 void setFontSize(int newFontSize)
          Modifies the font size
 void setFontStyle(int newFontStyle)
          Modifies the font style
 void setGenerateChecksum(boolean generateChecksum)
          Setter for property generateChecksum.
 void setGuardBars(boolean guardBars)
          Sets the property to show the guard bars for barcode EAN.
 void setN(float n)
          Sets the bar multiplier for wide bars.
 void setQuietZone(boolean newQuietZone)
          Enables/Disables quiet zone usage
 void setQuietZoneX(int newQuietZoneX)
          Set the width of the quiet zone
 void setShowText(boolean newShowText)
          Sets the property to show the text for barcode.
 void setSize(float size)
          Sets the size of the text.
 void setStartStopText(boolean startStopText)
          Gets the property to show the start and stop character '*' in the text for the barcode 39.
 void setTextAlignment(int textAlignment)
          Sets the text alignment.
 void setTransparent(boolean newTransparent)
          Sets the tranaparent background property Default tranparency is false
 void setX(float x)
          Sets the minimum bar width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EAN13

public static final int EAN13
A type of barcode

See Also:
Constant Field Values

EAN8

public static final int EAN8
A type of barcode

See Also:
Constant Field Values

UPCA

public static final int UPCA
A type of barcode

See Also:
Constant Field Values

UPCE

public static final int UPCE
A type of barcode

See Also:
Constant Field Values

SUPP2

public static final int SUPP2
A type of barcode

See Also:
Constant Field Values

SUPP5

public static final int SUPP5
A type of barcode

See Also:
Constant Field Values

POSTNET

public static final int POSTNET
A type of barcode

See Also:
Constant Field Values

PLANET

public static final int PLANET
A type of barcode

See Also:
Constant Field Values

CODE128

public static final int CODE128
A type of barcode

See Also:
Constant Field Values

CODE128_UCC

public static final int CODE128_UCC
A type of barcode

See Also:
Constant Field Values

CODE128_RAW

public static final int CODE128_RAW
A type of barcode

See Also:
Constant Field Values

CODABAR

public static final int CODABAR
A type of barcode

See Also:
Constant Field Values

CODE93

public static final int CODE93
A type of barcode

See Also:
Constant Field Values

x

protected float x
The minimum bar width.


n

protected float n
The bar multiplier for wide bars or the distance between bars for Postnet and Planet.


size

protected float size
The size of the text or the height of the shorter bar in Postnet.


barHeight

protected float barHeight
The height of the bars.


textAlignment

protected int textAlignment
The text alignment. Can be CoderBar.ALIGN_LEFT, Codebar.ALIGN_CENTER or Codebar.ALIGN_RIGHT.


generateChecksum

protected boolean generateChecksum
The optional checksum generation.


checksumText

protected boolean checksumText
Shows the generated checksum in the the text.


startStopText

protected boolean startStopText
Show the start and stop character '*' in the text for the barcode 39 or 'ABCD' for codabar.


extended

protected boolean extended
Generates extended barcode 39.


code

protected java.lang.String code
The code to generate.


guardBars

protected boolean guardBars
Show the guard bars for barcode EAN.


codeType

protected int codeType
The code type.


ALIGN_LEFT

public static final int ALIGN_LEFT
Left alignment

See Also:
Constant Field Values

ALIGN_RIGHT

public static final int ALIGN_RIGHT
Rigth alignment

See Also:
Constant Field Values

ALIGN_CENTER

public static final int ALIGN_CENTER
Center alignment

See Also:
Constant Field Values

quietZone

protected boolean quietZone
The option to generate a starting and ending quiet zone


font

protected java.awt.Font font
The font to use in the text of the codebar


quietZoneX

protected int quietZoneX
The width of the quiet zone expressed in multiples of x(the minimun width of the bar)


showText

protected boolean showText
The property to show the text for barcode.


transparent

protected boolean transparent

backgroundColor

protected java.awt.Color backgroundColor

ROTATE_90

public static final double ROTATE_90
See Also:
Constant Field Values

ROTATE_180

public static final double ROTATE_180
See Also:
Constant Field Values

ROTATE_270

public static final double ROTATE_270
See Also:
Constant Field Values

ROTATE_0

public static final double ROTATE_0
See Also:
Constant Field Values

TYPE_CODE128

public static final java.lang.String TYPE_CODE128
See Also:
Constant Field Values

TYPE_CODE93

public static final java.lang.String TYPE_CODE93
See Also:
Constant Field Values

TYPE_INTERLEAVED2OF5

public static final java.lang.String TYPE_INTERLEAVED2OF5
See Also:
Constant Field Values
Constructor Detail

Barcode

public Barcode()
Method Detail

createImage

public static java.awt.Image createImage(java.lang.String codeType,
                                         java.lang.String codeValue)
Creates a image representing a codebar using a codebar type and the codebar code

Parameters:
codeType - String Codebar type(Barcode.TYPE_CODE128 or Barcode.TYPE_CODE93 or Barcode.INTERLEAVED2OF5)
codeValue - String The code to represent

createImage

public static java.awt.Image createImage(java.lang.String codeType,
                                         java.lang.String codeValue,
                                         float barHeight,
                                         java.lang.String fontName,
                                         int fontSize,
                                         boolean transparent,
                                         int alignment,
                                         int fontStyle,
                                         java.awt.Color newBarColor,
                                         java.awt.Color newTextColor,
                                         int orientacion)
Creates a image representing a codebar using a codebar type and the codebar code

Parameters:
codeType - String Codebar type(Barcode.TYPE_CODE128 or Barcode.TYPE_CODE93 or Barcode.INTERLEAVED2OF5)
codeValue - String The code to represent
barHeight - float The bar height in pixels
fontName - String The name of the font to use
fontSize - int The size of the font to use
transparent - boolean Use transparent background
alignment - int Text alignment :use Barcode.ALIGN_CENTER, Barcode.ALIGN_LEFT, Barcode.ALIGN_RIGHT
fontStyle - int The style of the font to use: BOLD, ITALIC OR PLAIN
orientacion - int rotation angle of the image in radians: 0,PI/2, PI or (3/2)*PI

createPNG

public byte[] createPNG(int y,
                        java.awt.Color barColor,
                        java.awt.Color textColor,
                        double angle)
                 throws java.lang.Exception
Creates a PNG image data that represents the barcode. The size of the barcode width will be the minimun posible but optimal for reading

Parameters:
y - The x size of the image
barColor - Color to use for the bars
textColor - Color to use for the text
angle - Rotation angle in radians
Returns:
byte[] A bytearray witht he data of the image
java.lang.Exception

createPNG

public byte[] createPNG(int y,
                        java.awt.Color barColor,
                        java.awt.Color textColor)
Creates a PNG image data that represents the barcode. The size of the barcode width will be the minimun posible but optimal for reading

Parameters:
y - The x size of the image
barColor - Color to use for the bars
textColor - Color to use for the text
Returns:
byte[] A bytearray witht he data of the image

createPNG

public byte[] createPNG(int x,
                        int y,
                        int colorspace,
                        java.awt.Color barColor,
                        java.awt.Color textColor)
Creates a PNG image data that represents the barcode.

Parameters:
x - The x size of the image
y - The x size of the image
colorspace - The type of colorspace to use
Returns:
byte[] A bytearray witht he data of the image

createPNG

public byte[] createPNG(int x,
                        int y,
                        int colorspace,
                        java.awt.Color barColor,
                        java.awt.Color textColor,
                        double angle)
                 throws java.lang.Exception
Creates a PNG image data that represents the barcode,and rotates the image.

Parameters:
x - The x size of the image
y - The x size of the image
angle - Rotation angle in radians
Returns:
byte[] A bytearray witht he data of the image
java.lang.Exception

createPNG

public byte[] createPNG(int y,
                        java.awt.Color barColor,
                        java.awt.Color textColor,
                        int colorspace)
Creates a PNG image data that represents the barcode. The size of the barcode width will be the minimun posible but optimal for reading

Parameters:
y - The x size of the image
barColor - Color to use for the bars
textColor - Color to use for the text
Returns:
byte[] A bytearray witht he data of the image

createPNG

public byte[] createPNG(int y,
                        java.awt.Color barColor,
                        java.awt.Color textColor,
                        int colorspace,
                        double angle)
                 throws java.lang.Exception
Creates a PNG image data that represents the barcode. The size of the barcode will be the minimun posible but optimal for reading

Parameters:
y - The x size of the image
barColor - Color to use for the bars
textColor - Color to use for the text
angle - Rotation angle in radians
Returns:
byte[] A bytearray witht he data of the image
java.lang.Exception

encodePNG

protected byte[] encodePNG(java.awt.image.BufferedImage image)
Encodes an image into a PNG according to the barcode parameters

Parameters:
image - java.awt.image.BufferedImage The image to encode
Returns:
byte[] bytes of the PNG image

getBackgroundColor

public java.awt.Color getBackgroundColor()
Gets the background color to use

Returns:
java.awt.Color

getBarcodeWidth

protected abstract float getBarcodeWidth()
Gets the maximum width that the barcode will occupy. The lower left corner is always (0, 0).

Returns:
the size the barcode occupies.

getBarHeight

public float getBarHeight()
Gets the height of the bars.

Returns:
the height of the bars

getCode

public java.lang.String getCode()
Gets the code to generate.

Returns:
the code to generate

getCodeType

public int getCodeType()
Gets the code type.

Returns:
the code type

getFont

public java.awt.Font getFont()
Gets the font to use in the text of the barcode

Returns:
java.awt.Font

getFontName

public java.lang.String getFontName()
Gets name of the font to use in the text of the barcode Return null if no text is displayed

Returns:
int

getFontSize

public int getFontSize()
Gets size of the font to use in the text of the barcode Return -1 if no text is displayed

Returns:
int

getFontStyle

public int getFontStyle()
Gets style of the font to use in the text of the barcode Return -1 if no text is displayed

Returns:
int

getN

public float getN()
Gets the bar multiplier for wide bars.

Returns:
the bar multiplier for wide bars

getQuietZoneX

public int getQuietZoneX()
Get the width of the quiet zone

Returns:
int

getSize

public float getSize()
Gets the size of the text.

Returns:
the size of the text

getTextAlignment

public int getTextAlignment()
Gets the text alignment. Can be Barcode.ALIGN_LEFT, Barcode.ALIGN_CENTER or Barcode.ALIGN_RIGHT.

Returns:
the text alignment

getX

public float getX()
Gets the minimum bar width.

Returns:
the minimum bar width

isChecksumText

public boolean isChecksumText()
Gets the property to show the generated checksum in the the text.

Returns:
value of property checksumText

isExtended

public boolean isExtended()
Gets the property to generate extended barcode 39.

Returns:
value of property extended.

isGenerateChecksum

public boolean isGenerateChecksum()
Gets the optional checksum generation.

Returns:
the optional checksum generation

isGuardBars

public boolean isGuardBars()
Gets the property to show the guard bars for barcode EAN.

Returns:
value of property guardBars

isQuietZone

public boolean isQuietZone()
Gets the property to show the quiet zone at start and end of the bars.

Returns:
boolean

isShowText

public boolean isShowText()
Gets the property to show the text for barcode.

Returns:
boolean

isStartStopText

public boolean isStartStopText()
Sets the property to show the start and stop character '*' in the text for the barcode 39.

Returns:
value of property startStopText

isTransparent

public boolean isTransparent()
Get the tranaparent background property

Returns:
boolean

placeBarcode

public abstract void placeBarcode(java.awt.image.BufferedImage i,
                                  java.awt.Color barColor,
                                  java.awt.Color textColor)
Places the barcode in a BufferedImage. The The bars and text are written in the following colors:

barColor

textColor

Result

null

null

bars and text painted with current fill color

barColor

null

bars and text painted with barColor

null

textColor

bars painted with current color
text painted with textColor

barColor

textColor

bars painted with barColor
text painted with textColor

Parameters:
barColor - the color of the bars. It can be null
textColor - the color of the text. It can be null
Returns:
void

scale

public int scale(int imageSize,
                 float totalSize,
                 float coordinate)
Scales a logical coordinate to fit a physical image corrdinate Example: Having the logical dimension 200, and the logical coordinate 20.5 we want to scale the coordinate to a 300 pixel physical dimension. The call should be: int physicalCoordinate=scale(300,200,20.5); Fecha de creación: (26/02/2003 12:20:14)

Parameters:
imageSize - The size of the image
totalSize - The logical size
coordinate - The logical coordinate
Returns:
int

setBackgroundColor

public void setBackgroundColor(java.awt.Color newBackgroundColor)
Set the backgroud color od the barcode Default color is white

Parameters:
newBackgroundColor - java.awt.Color

setBarHeight

public void setBarHeight(float barHeight)
Sets the height of the bars.

Parameters:
barHeight - the height of the bars

setCode

public void setCode(java.lang.String code)
Sets the code to generate.

Parameters:
code - the code to generate

setCodeType

public void setCodeType(int codeType)
Sets the code type.

Parameters:
codeType - the code type

setChecksumText

public void setChecksumText(boolean checksumText)
Sets the property to show the generated checksum in the the text.

Parameters:
checksumText - new value of property checksumText

setExtended

public void setExtended(boolean extended)
Sets the property to generate extended barcode 39.

Parameters:
extended - new value of property extended

setFont

public void setFont(java.awt.Font newFont)
Sets the font to use null font prints no text. default value is Helvetica,Plain, size 20

Parameters:
newFont - java.awt.Font

setFontName

public void setFontName(java.lang.String newFontName)
Modifies the font name


setFontSize

public void setFontSize(int newFontSize)
Modifies the font size

Parameters:
newFontSize - int

setFontStyle

public void setFontStyle(int newFontStyle)
Modifies the font style


setGenerateChecksum

public void setGenerateChecksum(boolean generateChecksum)
Setter for property generateChecksum.

Parameters:
generateChecksum - New value of property generateChecksum.

setGuardBars

public void setGuardBars(boolean guardBars)
Sets the property to show the guard bars for barcode EAN.

Parameters:
guardBars - new value of property guardBars

setN

public void setN(float n)
Sets the bar multiplier for wide bars.

Parameters:
n - the bar multiplier for wide bars

setQuietZone

public void setQuietZone(boolean newQuietZone)
Enables/Disables quiet zone usage

Parameters:
newQuietZone - boolean

setQuietZoneX

public void setQuietZoneX(int newQuietZoneX)
Set the width of the quiet zone

Parameters:
newQuietZoneX - int

setShowText

public void setShowText(boolean newShowText)
Sets the property to show the text for barcode.

Parameters:
newShowText - boolean

setSize

public void setSize(float size)
Sets the size of the text.

Parameters:
size - the size of the text

setStartStopText

public void setStartStopText(boolean startStopText)
Gets the property to show the start and stop character '*' in the text for the barcode 39.

Parameters:
startStopText - new value of property startStopText

setTextAlignment

public void setTextAlignment(int textAlignment)
Sets the text alignment. Can be Element.ALIGN_LEFT, Element.ALIGN_CENTER or Element.ALIGN_RIGHT.

Parameters:
textAlignment - the text alignment

setTransparent

public void setTransparent(boolean newTransparent)
Sets the tranaparent background property Default tranparency is false

Parameters:
newTransparent - boolean

setX

public void setX(float x)
Sets the minimum bar width.

Parameters:
x - the minimum bar width