net.sourceforge.jbarcodebean
Class JBarcodeBean

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by net.sourceforge.jbarcodebean.JBarcodeBean
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
JBarcodeBean

public class JBarcodeBean
extends javax.swing.JComponent
implements java.io.Serializable, javax.accessibility.Accessible

JFC Swing-compatible JavaBeans TM component that renders barcodes in a variety of different formats.

[skip over license and copyright]


LICENSE INFORMATION

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 3.0 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY of FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

See http://www.gnu.org/licenses/lgpl.html.


JBarcodeBean employs the Strategy design pattern* to abstract the encoding algorithm. The codeType property can be set to any class that implements the BarcodeStrategy interface to determine how the code property is encoded. This version of JBarcodeBean is bundled with the following concrete implementations of BarcodeStrategy:

*See "Design Patterns Elements of Reusable Object-Oriented Software", Erich Gamma et al. for more information about design patterns.

Version:
1.1
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int ALIGN_CENTER
          Constant indicating that the barcode should be centered along the x-axis.
static int ALIGN_LEFT
          Constant indicating that the barcode should be left aligned along the x-axis.
static int ALIGN_RIGHT
          Constant indicating that the barcode should be right aligned along the x-axis.
static int LABEL_BOTTOM
          Constant indicating that the human readable barcode text should be printed at the bottom of the barcode.
static int LABEL_NONE
          Constant indicating that the human readable barcode text should not be printed at all.
static int LABEL_TOP
          Constant indicating that the human readable barcode text should be printed at the top of the barcode.
 
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
JBarcodeBean()
           Parameterless constructor.
JBarcodeBean(java.lang.String code, BarcodeStrategy codeType)
          Contructor that allows an initial barcode and code type to be specified.
 
Method Summary
 java.awt.image.BufferedImage draw(java.awt.image.BufferedImage image)
          Draws the current barcode into the given image and returns it.
 javax.accessibility.AccessibleContext getAccessibleContext()
          Returns a simple subclass of AccessibleContext.
 double getAngleDegrees()
          Accessor method for the angleDegrees property, which determines the angle (from horizontal) at which the barcode is rendered.
 java.awt.Color getBackground()
          Accessor method for the background property, which determines the control background color (the space around the barcode, and behind the text caption).
 java.awt.Color getBarcodeBackground()
          Accessor method for the barcodeBackground property, which determines the color of the spaces between the bars in the barcode (typically white).
 int getBarcodeHeight()
          Accessor method for the barcodeHeight property, which determines the height of the barcode (excluding caption text) in pixels.
 javax.swing.border.Border getBorder()
          Accessor methor for the border property.
 java.lang.String getCode()
          Accessor method for the code property, which is the text encoded in the barcode.
 BarcodeStrategy getCodeType()
          Accessor method for the codeType property, which is the barcode type.
 java.awt.Font getFont()
          Accessor method for the font property.
 java.awt.Color getForeground()
          Accessor method for the foreground property, which determines the color of the bars and caption text (typically black).
 int getHorizontalAlignment()
          Returns the alignment of the barcode along the X axis.
 int getLabelPosition()
          Returns the label position of the human readable barcode text.
 java.awt.Dimension getMinimumSize()
          Accessor method for minimumSize property.
 int getNarrowestBarWidth()
          Accessor method for the narrowestBarWidth property, which determines the width (in pixels) of the narrowest bar in the barcode.
 java.awt.Dimension getPreferredSize()
          Accessor method for the preferredSize property.
static java.lang.String getVersion()
          Returns the version of this JBarcodeBean implementation.
 boolean isCheckDigit()
          Accessor method for the checkDigit property, which determines whether a check digit is encoded in the barcode.
 boolean isFocusTraversable()
          Always returns false, as this control cannot receive focus.
 boolean isOpaque()
          Always returns true, as this component renders its entire drawing area.
 boolean isShowText()
          Deprecated. As of 1.2.0, replaced by getLabelPosition(). This will return true if label position is LABEL_BOTTOM and false otherwise.
 java.awt.Dimension minimumSize()
          Deprecated. Use getMinimumSize().
protected  void paintComponent(java.awt.Graphics graphics)
          Component paint method.
protected  java.lang.String paramString()
          Always returns the value of the code property.
 java.awt.Dimension preferredSize()
          Deprecated. Use getPreferredSize().
 void setAngleDegrees(double angleDegrees)
          Mutator method for the angleDegrees property, which determines the angle (from horizontal) at which the barcode is rendered.
 void setBackground(java.awt.Color c)
          Mutator method for the background property, which determines the control background color (the space around the barcode, and behind the text caption).
 void setBarcodeBackground(java.awt.Color barcodeBackground)
          Mutator method for the barcodeBackground property, which determines the color of the spaces between the bars in the barcode (typically white).
 void setBarcodeHeight(int barcodeHeight)
          Mutator method for the barcodeHeight property, which determines the height of the barcode (excluding caption text) in pixels.
 void setBorder(javax.swing.border.Border border)
          Mutator methor for the border property.
 void setCheckDigit(boolean checkDigit)
          Mutator method for the checkDigit property, which determines whether a check digit is encoded in the barcode.
 void setCode(java.lang.String code)
          Mutator method for the code property, which is the text encoded in the barcode.
 void setCodeType(BarcodeStrategy codeType)
          Mutator method for the codeType property, which is the barcode type.
 void setFont(java.awt.Font font)
          Mutator method for the font property.
 void setForeground(java.awt.Color c)
          Mutator method for the foreground property, which determines the color of the bars and caption text (typically black).
 void setHorizontalAlignment(int horizontalAlignment)
          Sets the alignment of the barcode along the X axis.
 void setLabelPosition(int labelPosition)
          Sets the label position of the human readable bacode text.
 void setMinimumSize(java.awt.Dimension minimumSize)
          Mutator method for the minimumSize property.
 void setNarrowestBarWidth(int narrowestBarWidth)
          Mutator method for the narrowestBarWidth property, which determines the width (in pixels) of the narrowest bar in the barcode.
 void setPreferredSize(java.awt.Dimension preferredSize)
          Mutator method for the preferredSize property.
 void setShowText(boolean showText)
          Deprecated. As of 1.2.0, replaced by setLabelPosition(int). When setting this property to true the label position will be set to LABEL_BOTTOM, setting the property to false will set the label position to LABEL_NONE.
 java.lang.String toString()
          Always returns the value of the code property.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, paintComponents, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ALIGN_LEFT

public static final int ALIGN_LEFT
Constant indicating that the barcode should be left aligned along the x-axis.

See Also:
Constant Field Values

ALIGN_CENTER

public static final int ALIGN_CENTER
Constant indicating that the barcode should be centered along the x-axis. (This is the default behaviour)

See Also:
Constant Field Values

ALIGN_RIGHT

public static final int ALIGN_RIGHT
Constant indicating that the barcode should be right aligned along the x-axis.

See Also:
Constant Field Values

LABEL_TOP

public static final int LABEL_TOP
Constant indicating that the human readable barcode text should be printed at the top of the barcode.

See Also:
Constant Field Values

LABEL_BOTTOM

public static final int LABEL_BOTTOM
Constant indicating that the human readable barcode text should be printed at the bottom of the barcode. (This is the default behaviour)

See Also:
Constant Field Values

LABEL_NONE

public static final int LABEL_NONE
Constant indicating that the human readable barcode text should not be printed at all.

See Also:
Constant Field Values
Constructor Detail

JBarcodeBean

public JBarcodeBean(java.lang.String code,
                    BarcodeStrategy codeType)

Contructor that allows an initial barcode and code type to be specified.

Parameters:
code - The text to encode.
codeType - The type of barcode.

JBarcodeBean

public JBarcodeBean()

Parameterless constructor. Creates a JBarcodeBean object with default property values, so that the bean will render as a typical barcode when initially added to a GUI with a GUI Builder.

Defaulat values are:

code = "1234"
codeType = new Code39()

See Also:
Code39
Method Detail

getAngleDegrees

public double getAngleDegrees()
Accessor method for the angleDegrees property, which determines the angle (from horizontal) at which the barcode is rendered.


setAngleDegrees

public void setAngleDegrees(double angleDegrees)
Mutator method for the angleDegrees property, which determines the angle (from horizontal) at which the barcode is rendered.


isShowText

public boolean isShowText()
Deprecated. As of 1.2.0, replaced by getLabelPosition(). This will return true if label position is LABEL_BOTTOM and false otherwise.

Accessor method for the showText property, which determines whether or not the text caption is visible below the barcode. true = visible, false = not visible.


setShowText

public void setShowText(boolean showText)
Deprecated. As of 1.2.0, replaced by setLabelPosition(int). When setting this property to true the label position will be set to LABEL_BOTTOM, setting the property to false will set the label position to LABEL_NONE.

Mutator method for the showText property, which determines whether or not the text caption is visible below the barcode. true = visible, false = not visible.


isOpaque

public boolean isOpaque()
Always returns true, as this component renders its entire drawing area.

Overrides:
isOpaque in class javax.swing.JComponent

getForeground

public java.awt.Color getForeground()
Accessor method for the foreground property, which determines the color of the bars and caption text (typically black).

Overrides:
getForeground in class java.awt.Component

setForeground

public void setForeground(java.awt.Color c)
Mutator method for the foreground property, which determines the color of the bars and caption text (typically black).

Overrides:
setForeground in class javax.swing.JComponent

getBackground

public java.awt.Color getBackground()
Accessor method for the background property, which determines the control background color (the space around the barcode, and behind the text caption). Note that this is not the same as the barcodeBackground property (which is the color of the spaces between the bars in the barcode).

Overrides:
getBackground in class java.awt.Component

setBackground

public void setBackground(java.awt.Color c)
Mutator method for the background property, which determines the control background color (the space around the barcode, and behind the text caption). Note that this is not the same as the barcodeBackground property (which is the color of the spaces between the bars in the barcode).

Overrides:
setBackground in class javax.swing.JComponent

getBarcodeBackground

public java.awt.Color getBarcodeBackground()
Accessor method for the barcodeBackground property, which determines the color of the spaces between the bars in the barcode (typically white).

See Also:
setBackground(java.awt.Color)

setBarcodeBackground

public void setBarcodeBackground(java.awt.Color barcodeBackground)
Mutator method for the barcodeBackground property, which determines the color of the spaces between the bars in the barcode (typically white).

See Also:
setBackground(java.awt.Color)

getBorder

public javax.swing.border.Border getBorder()
Accessor methor for the border property.

Overrides:
getBorder in class javax.swing.JComponent

setBorder

public void setBorder(javax.swing.border.Border border)
Mutator methor for the border property.

Overrides:
setBorder in class javax.swing.JComponent

getPreferredSize

public java.awt.Dimension getPreferredSize()
Accessor method for the preferredSize property.

Overrides:
getPreferredSize in class javax.swing.JComponent

setPreferredSize

public void setPreferredSize(java.awt.Dimension preferredSize)
Mutator method for the preferredSize property.

Overrides:
setPreferredSize in class javax.swing.JComponent

preferredSize

public java.awt.Dimension preferredSize()
Deprecated. Use getPreferredSize().

Returns the preferred size of the component.

Overrides:
preferredSize in class java.awt.Container

getMinimumSize

public java.awt.Dimension getMinimumSize()
Accessor method for minimumSize property.

Overrides:
getMinimumSize in class javax.swing.JComponent

setMinimumSize

public void setMinimumSize(java.awt.Dimension minimumSize)
Mutator method for the minimumSize property.

Overrides:
setMinimumSize in class javax.swing.JComponent

minimumSize

public java.awt.Dimension minimumSize()
Deprecated. Use getMinimumSize().

Returns the minimum size of the component.

Overrides:
minimumSize in class java.awt.Container

getFont

public java.awt.Font getFont()
Accessor method for the font property.

Specified by:
getFont in interface java.awt.MenuContainer
Overrides:
getFont in class java.awt.Component

setFont

public void setFont(java.awt.Font font)
Mutator method for the font property.

Overrides:
setFont in class javax.swing.JComponent

getBarcodeHeight

public int getBarcodeHeight()
Accessor method for the barcodeHeight property, which determines the height of the barcode (excluding caption text) in pixels.


setBarcodeHeight

public void setBarcodeHeight(int barcodeHeight)
Mutator method for the barcodeHeight property, which determines the height of the barcode (excluding caption text) in pixels.


getNarrowestBarWidth

public int getNarrowestBarWidth()
Accessor method for the narrowestBarWidth property, which determines the width (in pixels) of the narrowest bar in the barcode.


setNarrowestBarWidth

public void setNarrowestBarWidth(int narrowestBarWidth)
Mutator method for the narrowestBarWidth property, which determines the width (in pixels) of the narrowest bar in the barcode.


isFocusTraversable

public boolean isFocusTraversable()
Always returns false, as this control cannot receive focus.

Overrides:
isFocusTraversable in class java.awt.Component

paramString

protected java.lang.String paramString()
Always returns the value of the code property.

Overrides:
paramString in class javax.swing.JComponent

toString

public java.lang.String toString()
Always returns the value of the code property.

Overrides:
toString in class java.awt.Component

getCode

public java.lang.String getCode()
Accessor method for the code property, which is the text encoded in the barcode.


setCode

public void setCode(java.lang.String code)
Mutator method for the code property, which is the text encoded in the barcode.


getCodeType

public BarcodeStrategy getCodeType()
Accessor method for the codeType property, which is the barcode type.


setCodeType

public void setCodeType(BarcodeStrategy codeType)
Mutator method for the codeType property, which is the barcode type.


isCheckDigit

public boolean isCheckDigit()
Accessor method for the checkDigit property, which determines whether a check digit is encoded in the barcode. true = check digit is encoded, false = check digit is not encoded.


setCheckDigit

public void setCheckDigit(boolean checkDigit)
Mutator method for the checkDigit property, which determines whether a check digit is encoded in the barcode. true = check digit is encoded, false = check digit is not encoded.


paintComponent

protected void paintComponent(java.awt.Graphics graphics)
Component paint method.

Overrides:
paintComponent in class javax.swing.JComponent

getAccessibleContext

public javax.accessibility.AccessibleContext getAccessibleContext()
Returns a simple subclass of AccessibleContext.

Specified by:
getAccessibleContext in interface javax.accessibility.Accessible
Overrides:
getAccessibleContext in class javax.swing.JComponent

getVersion

public static java.lang.String getVersion()
Returns the version of this JBarcodeBean implementation.

Returns:
The version string in format: major.minor[.micro]

draw

public java.awt.image.BufferedImage draw(java.awt.image.BufferedImage image)
Draws the current barcode into the given image and returns it.

Parameters:
image - The image the barcode will be drawn into or null if a new image should be created using the preferred size of the barcode.
Returns:
The image containing the barcode.

getHorizontalAlignment

public int getHorizontalAlignment()
Returns the alignment of the barcode along the X axis.

Returns:
The value of the horizontalAlignment property, one of the following constants: ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER
Since:
1.2.0
See Also:
setHorizontalAlignment(int)

setHorizontalAlignment

public void setHorizontalAlignment(int horizontalAlignment)
Sets the alignment of the barcode along the X axis. This is a JavaBeans bound property.

Parameters:
horizontalAlignment - One of the following constants : ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER (the default)
Since:
1.2.0
See Also:
getHorizontalAlignment()

getLabelPosition

public int getLabelPosition()
Returns the label position of the human readable barcode text.

Returns:
The value of the labelPosition property, one of the following constants: LABEL_BOTTOM, LABEL_TOP or LABEL_NONE.
Since:
1.2.0
See Also:
setLabelPosition(int)

setLabelPosition

public void setLabelPosition(int labelPosition)
Sets the label position of the human readable bacode text. This is a JavaBeans bound property.

Parameters:
labelPosition - One of the following constants: LABEL_BOTTOM, LABEL_TOP or LABEL_NONE.
Since:
1.2.0
See Also:
getLabelPosition()


Copyright © 2004-2009 The JBarcodeBean project. All Rights Reserved.