net.sourceforge.barbecue
Class Barcode

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended bynet.sourceforge.barbecue.Barcode
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable
Direct Known Subclasses:
LinearBarcode

public abstract class Barcode
extends javax.swing.JComponent
implements java.awt.print.Printable

Abstract barcode class that provides functionality that is common to all barcodes. Specific barcode implementations must subclass this and provide information specific to the barcode type they are implementing.

Author:
Ian Bourke
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int barHeight
           
protected  int barWidth
           
protected  java.lang.String data
           
protected  boolean drawingQuietSection
           
protected  boolean drawingText
           
protected  java.lang.String label
           
 
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.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
protected Barcode(java.lang.String data)
           
 
Method Summary
protected  java.lang.String beautify(java.lang.String s)
           
protected abstract  Module calculateChecksum()
           
protected  int calculateMinimumBarHeight(int resolution)
           
 void draw(java.awt.Graphics2D g, int x, int y)
          Renders this Barcode at the specified location in the specified Graphics2D context.
protected abstract  java.awt.Dimension draw(Output output, int x, int y, int barWidth, int barHeight)
           
protected  int drawModule(Module module, Output output, int x, int y, int barWidth, int barHeight)
           
protected abstract  Module[] encodeData()
           
 java.awt.Rectangle getBounds()
          From JComponent.
 java.awt.Rectangle getBounds(java.awt.Rectangle rv)
          From JComponent.
 java.lang.String getData()
          Returns the data that the barcode is coding for.
 int getHeight()
          From JComponent.
 java.lang.String getLabel()
          Returns the text that will be displayed underneath the barcode (if requested).
 java.awt.Dimension getMaximumSize()
          From JComponent.
 java.awt.Dimension getMinimumSize()
          From JComponent.
protected abstract  Module getPostAmble()
           
protected abstract  Module getPreAmble()
           
 java.awt.Dimension getPreferredSize()
          From JComponent.
protected  int getResolution()
           
 java.awt.Dimension getSize()
          From JComponent.
 int getWidth()
          From JComponent.
 int getX()
          From JComponent.
 int getY()
          From JComponent.
 boolean isDrawingQuietSection()
          Indicates whether the barcode is drawing leading and trailing white space/quiet area.
 boolean isDrawingText()
          Indicates whether the barcode is drawing a text label underneath the barcode or not.
 void output(Output output)
           
protected  void paintComponent(java.awt.Graphics g)
          From JComponent.
 int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex)
           
 void setBarHeight(int barHeight)
          Sets the desired height for the bars in the barcode (in pixels).
 void setBarWidth(int barWidth)
          Sets the desired bar width for the barcode.
 void setDrawingQuietSection(boolean drawingQuietSection)
          Indicates whether the leading and trailing white space should be rendered.
 void setDrawingText(boolean drawingText)
          Indicates whether the barcode data should be shown as a string underneath the barcode or not.
 void setFont(java.awt.Font font)
          Sets the font to use when drawing the barcode data string underneath the barcode.
 void setLabel(java.lang.String label)
          Sets the human readable text to be displayed underneath the barcode.
 void setResolution(int resolution)
          Sets the desired output resolution for the barcode.
 java.lang.String toString()
           
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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

data

protected java.lang.String data

label

protected java.lang.String label

drawingText

protected boolean drawingText

drawingQuietSection

protected boolean drawingQuietSection

barWidth

protected int barWidth

barHeight

protected int barHeight
Constructor Detail

Barcode

protected Barcode(java.lang.String data)
           throws BarcodeException
Method Detail

getData

public java.lang.String getData()
Returns the data that the barcode is coding for.

Returns:
The barcode raw data

setFont

public void setFont(java.awt.Font font)
Sets the font to use when drawing the barcode data string underneath the barcode.

Note that changing this setting after a barcode has been drawn will invalidate the component and may force a refresh.

Parameters:
font - The font to use

setDrawingText

public void setDrawingText(boolean drawingText)
Indicates whether the barcode data should be shown as a string underneath the barcode or not.

Note that changing this setting after a barcode has been drawn will invalidate the component and may force a refresh.

Parameters:
drawingText - True if the text should be shown, false if not

isDrawingText

public boolean isDrawingText()
Indicates whether the barcode is drawing a text label underneath the barcode or not.

Returns:
True if the text is drawn, false otherwise

setDrawingQuietSection

public void setDrawingQuietSection(boolean drawingQuietSection)
Indicates whether the leading and trailing white space should be rendered.

Note that changing this setting after a barcode has been drawn will invalidate the component and may force a refresh.

Parameters:
drawingQuietSection - True if the quiet area/white space should be shown, false if not

isDrawingQuietSection

public boolean isDrawingQuietSection()
Indicates whether the barcode is drawing leading and trailing white space/quiet area.

Returns:
True if the quiet area/white space is drawn, false otherwise

setBarWidth

public void setBarWidth(int barWidth)
Sets the desired bar width for the barcode. This is the width (in pixels) of the thinnest bar in the barcode. Other bars will change their size relative to this.

Note that changing this setting after a barcode has been drawn will invalidate the component and may force a refresh.

Parameters:
barWidth - The desired width of the thinnest bar in pixels

setBarHeight

public void setBarHeight(int barHeight)
Sets the desired height for the bars in the barcode (in pixels). Note that some barcode implementations will not allow the height to go below a minimum size. This is not the height of the component as a whole, as it does not specify the height of any text that may be drawn and does not include borders.

Note that changing this setting after a barcode has been drawn will invalidate the component and may force a refresh.

Parameters:
barHeight - The desired height of the barcode bars in pixels

setResolution

public void setResolution(int resolution)
Sets the desired output resolution for the barcode. This method should be used in cases where the barcode is either being outputted to a device other than the screen, or the barcode is being generated on a headless machine (e.g. a rack mounted server) and the screen resolution cannot be determined. Note that is the barcode is generated in either of these situations and this method has not been called, the resolution is assumed to be 72 dots per inch.

Parameters:
resolution - The desired output resolution (in dots per inch)

getX

public int getX()
From JComponent.

Returns:
The X co-ordinate of the component's origin

getY

public int getY()
From JComponent.

Returns:
The Y co-ordinate of the component's origin

getWidth

public int getWidth()
From JComponent.

Returns:
The width of this component

getHeight

public int getHeight()
From JComponent.

Returns:
The height of this component

getBounds

public java.awt.Rectangle getBounds()
From JComponent.

Returns:
The bounds of this component

getBounds

public java.awt.Rectangle getBounds(java.awt.Rectangle rv)
From JComponent.

Parameters:
rv - The rectangle to set the bounds on
Returns:
The updated rv

getPreferredSize

public java.awt.Dimension getPreferredSize()
From JComponent.

Returns:
The preferred size of this component

getMinimumSize

public java.awt.Dimension getMinimumSize()
From JComponent.

Returns:
The minimum size of this component

getMaximumSize

public java.awt.Dimension getMaximumSize()
From JComponent.

Returns:
The maximum size of this component

getSize

public java.awt.Dimension getSize()
From JComponent.

Returns:
The actual size of this component

draw

public void draw(java.awt.Graphics2D g,
                 int x,
                 int y)
          throws OutputException
Renders this Barcode at the specified location in the specified Graphics2D context. The origin of the layout is placed at x, y. Rendering may touch any point within getBounds() of this position. This leaves the g2 unchanged.

Parameters:
g - The graphics context
x - The horizontal value of the upper left co-ordinate of the bounding box
y - The vertical value of the upper left co-ordinate of the bounding box
Throws:
OutputException

output

public void output(Output output)
            throws OutputException
Throws:
OutputException

encodeData

protected abstract Module[] encodeData()

calculateChecksum

protected abstract Module calculateChecksum()

getPreAmble

protected abstract Module getPreAmble()

getPostAmble

protected abstract Module getPostAmble()

draw

protected abstract java.awt.Dimension draw(Output output,
                                           int x,
                                           int y,
                                           int barWidth,
                                           int barHeight)
                                    throws OutputException
Throws:
OutputException

getLabel

public java.lang.String getLabel()
Returns the text that will be displayed underneath the barcode (if requested).

Returns:
The text label for the barcode

setLabel

public void setLabel(java.lang.String label)
Sets the human readable text to be displayed underneath the barcode. If set to null then the text will automaticaly be generated.

Parameters:
label - the human readable barcode text
See Also:
getLabel()

calculateMinimumBarHeight

protected int calculateMinimumBarHeight(int resolution)

paintComponent

protected void paintComponent(java.awt.Graphics g)
From JComponent.

Parameters:
g - The graphics to paint the component onto

getResolution

protected int getResolution()

drawModule

protected int drawModule(Module module,
                         Output output,
                         int x,
                         int y,
                         int barWidth,
                         int barHeight)
                  throws OutputException
Throws:
OutputException

beautify

protected java.lang.String beautify(java.lang.String s)

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
          throws java.awt.print.PrinterException
Specified by:
print in interface java.awt.print.Printable
Throws:
java.awt.print.PrinterException

toString

public java.lang.String toString()


Copyright © 2003-2007 barbecue.sourceforge.net. All Rights Reserved.