Class 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)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ALIGN_CENTER
      Center alignment
      static int ALIGN_LEFT
      Left alignment
      static int ALIGN_RIGHT
      Rigth alignment
      protected int backgroundColor  
      protected int 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 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 int 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)
      protected boolean showText
      The property to show the text for barcode.
      protected int 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 int x
      The 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 Image createImage​(java.lang.String codeType, java.lang.String codeValue, int height)
      Creates a image representing a codebar using a codebar type and the codebar code
      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)
      Creates a image representing a codebar using a codebar type and the codebar code
      int getBackgroundColor()
      Gets the background color to use
      protected abstract int getBarcodeWidth()
      Gets the maximum width that the barcode will occupy.
      int getBarHeight()
      Gets the height of the bars.
      java.lang.String getCode()
      Gets the code to generate.
      int getCodeType()
      Gets the code type.
      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 getN()
      Gets the bar multiplier for wide bars.
      int getQuietZoneX()
      Get the width of the quiet zone
      int getSize()
      Gets the size of the text.
      int getTextAlignment()
      Gets the text alignment.
      int 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​(Image i, int barColor, int textColor)
      Places the barcode in a BufferedImage.
      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.
      void setBackgroundColor​(int newBackgroundColor)
      Set the backgroud color od the barcode Default color is white
      void setBarHeight​(int 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​(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​(boolean bold)
      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​(int 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​(int 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​(int 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

      • 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 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.
      • 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_INTERLEAVED2OF5

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

      • Barcode

        public Barcode()
    • 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 represent
        height - 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 represent
        barHeight - int 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
        fontBold - The style of the font to use
        newBarColor - Color Color to use in the bars
        newTextColor - 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 be Barcode.ALIGN_LEFT, Barcode.ALIGN_CENTER or Barcode.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:

        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:
        i - the BufferedImage where the barcode will be placed
        barColor - the color of the bars. It can be null
        textColor - the color of the text. It can be null
      • 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 image
        totalSize - The logical size
        coordinate - 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 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​(int x)
        Sets the minimum bar width.
        Parameters:
        x - the minimum bar width