Package totalcross.barcode
Class Barcode
- java.lang.Object
-
- totalcross.barcode.Barcode
-
- Direct Known Subclasses:
Barcode128,Barcode93,BarcodeInter25
public abstract class Barcode extends java.lang.ObjectBase 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)
-
-
Field Summary
Fields Modifier and Type Field Description static intALIGN_CENTERCenter alignmentstatic intALIGN_LEFTLeft alignmentstatic intALIGN_RIGHTRigth alignmentprotected intbackgroundColorprotected intbarHeightThe height of the bars.protected booleanchecksumTextShows the generated checksum in the the text.static intCODABARA type of barcodeprotected java.lang.StringcodeThe code to generate.static intCODE128A type of barcodestatic intCODE128_RAWA type of barcodestatic intCODE128_UCCA type of barcodestatic intCODE93A type of barcodeprotected intcodeTypeThe code type.static intEAN13A type of barcodestatic intEAN8A type of barcodeprotected booleanextendedGenerates extended barcode 39.protected FontfontThe font to use in the text of the codebarprotected booleangenerateChecksumThe optional checksum generation.protected booleanguardBarsShow the guard bars for barcode EAN.protected intnThe bar multiplier for wide bars or the distance between bars for Postnet and Planet.static intPLANETA type of barcodestatic intPOSTNETA type of barcodeprotected booleanquietZoneThe option to generate a starting and ending quiet zoneprotected intquietZoneXThe width of the quiet zone expressed in multiples of x(the minimun width of the bar)protected booleanshowTextThe property to show the text for barcode.protected intsizeThe size of the text or the height of the shorter bar in Postnet.protected booleanstartStopTextShow the start and stop character '*' in the text for the barcode 39 or 'ABCD' for codabar.static intSUPP2A type of barcodestatic intSUPP5A type of barcodeprotected inttextAlignmentThe text alignment.protected booleantransparentstatic java.lang.StringTYPE_CODE128static java.lang.StringTYPE_CODE93static java.lang.StringTYPE_INTERLEAVED2OF5static intUPCAA type of barcodestatic intUPCEA type of barcodeprotected intxThe minimum bar width.
-
Constructor Summary
Constructors Constructor Description Barcode()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ImagecreateImage(java.lang.String codeType, java.lang.String codeValue, int height)Creates a image representing a codebar using a codebar type and the codebar codestatic ImagecreateImage(java.lang.String codeType, java.lang.String codeValue, int barHeight, java.lang.String fontName, int fontSize, boolean transparent, int alignment, boolean fontBold, int newBarColor, int newTextColor, int x, int n)Creates a image representing a codebar using a codebar type and the codebar codeintgetBackgroundColor()Gets the background color to useprotected abstract intgetBarcodeWidth()Gets the maximum width that the barcode will occupy.intgetBarHeight()Gets the height of the bars.java.lang.StringgetCode()Gets the code to generate.intgetCodeType()Gets the code type.FontgetFont()Gets the font to use in the text of the barcodejava.lang.StringgetFontName()Gets name of the font to use in the text of the barcode Return null if no text is displayedintgetFontSize()Gets size of the font to use in the text of the barcode Return -1 if no text is displayedintgetN()Gets the bar multiplier for wide bars.intgetQuietZoneX()Get the width of the quiet zoneintgetSize()Gets the size of the text.intgetTextAlignment()Gets the text alignment.intgetX()Gets the minimum bar width.booleanisChecksumText()Gets the property to show the generated checksum in the the text.booleanisExtended()Gets the property to generate extended barcode 39.booleanisGenerateChecksum()Gets the optional checksum generation.booleanisGuardBars()Gets the property to show the guard bars for barcode EAN.booleanisQuietZone()Gets the property to show the quiet zone at start and end of the bars.booleanisShowText()Gets the property to show the text for barcode.booleanisStartStopText()Sets the property to show the start and stop character '*' in the text for the barcode 39.booleanisTransparent()Get the tranaparent background propertyabstract voidplaceBarcode(Image i, int barColor, int textColor)Places the barcode in a BufferedImage.intscale(int imageSize, int totalSize, int coordinate)Scales a logical coordinate to fit a physical image coordinate Example: Having the logical dimension 200, and the logical coordinate 20.5 we want to scale the coordinate to a 300 pixel physical dimension.voidsetBackgroundColor(int newBackgroundColor)Set the backgroud color od the barcode Default color is whitevoidsetBarHeight(int barHeight)Sets the height of the bars.voidsetChecksumText(boolean checksumText)Sets the property to show the generated checksum in the the text.voidsetCode(java.lang.String code)Sets the code to generate.voidsetCodeType(int codeType)Sets the code type.voidsetExtended(boolean extended)Sets the property to generate extended barcode 39.voidsetFont(Font newFont)Sets the font to use null font prints no text.voidsetFontName(java.lang.String newFontName)Modifies the font namevoidsetFontSize(int newFontSize)Modifies the font sizevoidsetFontStyle(boolean bold)Modifies the font stylevoidsetGenerateChecksum(boolean generateChecksum)Setter for property generateChecksum.voidsetGuardBars(boolean guardBars)Sets the property to show the guard bars for barcode EAN.voidsetN(int n)Sets the bar multiplier for wide bars.voidsetQuietZone(boolean newQuietZone)Enables/Disables quiet zone usagevoidsetQuietZoneX(int newQuietZoneX)Set the width of the quiet zonevoidsetShowText(boolean newShowText)Sets the property to show the text for barcode.voidsetSize(int size)Sets the size of the text.voidsetStartStopText(boolean startStopText)Gets the property to show the start and stop character '*' in the text for the barcode 39.voidsetTextAlignment(int textAlignment)Sets the text alignment.voidsetTransparent(boolean newTransparent)Sets the tranaparent background property Default tranparency is falsevoidsetX(int x)Sets the minimum bar width.
-
-
-
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
-
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
-
CODE128_RAW
public static final int CODE128_RAW
A type of barcode- See Also:
- Constant Field Values
-
x
protected int x
The minimum bar width.
-
n
protected int n
The bar multiplier for wide bars or the distance between bars for Postnet and Planet.
-
size
protected int size
The size of the text or the height of the shorter bar in Postnet.
-
barHeight
protected int barHeight
The height of the bars.
-
textAlignment
protected int textAlignment
The text alignment. Can beCoderBar.ALIGN_LEFT,Codebar.ALIGN_CENTERorCodebar.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 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 int backgroundColor
-
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
-
-
Method Detail
-
createImage
public static Image createImage(java.lang.String codeType, java.lang.String codeValue, int height) throws ImageException
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 representheight- the Image's height- Throws:
ImageException
-
createImage
public static Image createImage(java.lang.String codeType, java.lang.String codeValue, int barHeight, java.lang.String fontName, int fontSize, boolean transparent, int alignment, boolean fontBold, int newBarColor, int newTextColor, int x, int n) throws java.lang.Exception
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 representbarHeight- int The bar height in pixelsfontName- String The name of the font to usefontSize- int The size of the font to usetransparent- boolean Use transparent backgroundalignment- int Text alignment :use Barcode.ALIGN_CENTER, Barcode.ALIGN_LEFT, Barcode.ALIGN_RIGHTfontBold- The style of the font to usenewBarColor- Color Color to use in the barsnewTextColor- Color Color to use in the text- Throws:
java.lang.Exception
-
getBackgroundColor
public int getBackgroundColor()
Gets the background color to use- Returns:
- Color
-
getBarcodeWidth
protected abstract int 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 int 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 Font getFont()
Gets the font to use in the text of the barcode- Returns:
- 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
-
getN
public int 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 int getSize()
Gets the size of the text.- Returns:
- the size of the text
-
getTextAlignment
public int getTextAlignment()
Gets the text alignment. Can beBarcode.ALIGN_LEFT,Barcode.ALIGN_CENTERorBarcode.ALIGN_RIGHT.- Returns:
- the text alignment
-
getX
public int 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(Image i, int barColor, int textColor)
Places the barcode in a BufferedImage. The The bars and text are written in the following colors:barColortextColorResult
nullnullbars and text painted with current fill color
barColornullbars and text painted with
barColornulltextColorbars painted with current color
text painted withtextColorbarColortextColorbars painted with
barColor
text painted withtextColor- Parameters:
i- theBufferedImagewhere the barcode will be placedbarColor- the color of the bars. It can benulltextColor- the color of the text. It can benull
-
scale
public int scale(int imageSize, int totalSize, int coordinate)Scales a logical coordinate to fit a physical image coordinate 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 imagetotalSize- The logical sizecoordinate- The logical coordinate- Returns:
- int
-
setBackgroundColor
public void setBackgroundColor(int newBackgroundColor)
Set the backgroud color od the barcode Default color is white- Parameters:
newBackgroundColor- Color
-
setBarHeight
public void setBarHeight(int 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(Font newFont)
Sets the font to use null font prints no text. default value is Helvetica,Plain, size 20- Parameters:
newFont- Font
-
setFontName
public void setFontName(java.lang.String newFontName)
Modifies the font name- Parameters:
newFontName- int
-
setFontSize
public void setFontSize(int newFontSize)
Modifies the font size- Parameters:
newFontSize- int
-
setFontStyle
public void setFontStyle(boolean bold)
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(int 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(int 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 beElement.ALIGN_LEFT,Element.ALIGN_CENTERorElement.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(int x)
Sets the minimum bar width.- Parameters:
x- the minimum bar width
-
-