com.twainconnect.core
Class TwainConnect

java.lang.Object
  extended by com.twainconnect.core.TwainConnect
All Implemented Interfaces:
com.jimageconnect.core.JImageconnect

public class TwainConnect
extends java.lang.Object
implements com.jimageconnect.core.JImageconnect

JNI Bridge class. Java methods act as thin wrappers over native calls to JNI. Class also responsible for loading the DLL.

Since:
3.0.0
Version:
5.7.1
Author:
twainconnect.com

Field Summary
(package private) static java.lang.String tc_loader
           
 
Fields inherited from interface com.jimageconnect.core.JImageconnect
error_image_not_captured
 
Constructor Summary
TwainConnect()
          Once the source manager has been loaded, it is not normally unloaded until your application is destroyed.
 
Method Summary
 void acquire(java.lang.String sourcename)
          Opens and enables the named source.
 void acquireImagesFileIo(java.lang.String sourcename)
          Opens and enables the named source.
 void acquireImagesMemory(java.lang.String sourcename)
          Opens and enables the named source.
static java.awt.Image acquireNativeMemory(java.lang.String pSourceName)
           
 void addTwainListener(TwainEventListener l)
          Add a TwainEventListener instance and inform all the listeners of the Image acquisition event
 boolean closeSource(java.lang.String sourcename)
          Used internally to close the source
protected  void fireTwainCapabilityNotSet(Capability c)
          Notify all listeners that have registered interest for notification on not being able to set the particular capability for this device.
protected  void fireTwainCapabilitySet(Capability c)
          Notify all listeners that have registered interest for notification on being able to set the particular capability for this device.
protected  void fireTwainImageCaptured()
          Notify all listeners that have registered interest for notification on this event type.
protected  void fireTwainImageFailed(java.lang.Exception e)
          Notify all listeners that have registered interest for notification on a failed image acquisition.
 java.lang.String[] getAvailableSources()
          Returns the names of all the available TAWAIN devices.
 java.lang.String getClassLoaderName()
          The name of the class to use for reading the images.
protected  ImageLoader getLoader()
          Load the default image io class as defined by either the property file or set at run-time.
 boolean isCancelScanning()
           
 boolean isEngineAvailble()
           
 boolean isTwainAvailble()
          true if the TWAIN DataSource Manager is available and can be loaded.
 boolean isUseMemoryForAcquisition()
           
 boolean moreImagesAvailable()
           
 boolean openSource(java.lang.String sourcename)
          Used internally to explicitly open source
 void removeTwainListener(TwainEventListener l)
          Remove a TwainEventListener instance from the list
 void setBitDepth(BitDepth bitDepth)
          Set the requested Bit Depth.
 void setCancelScanning(boolean cancelScanning)
          cancel scanning is a multi document environment Does not stop the device.
 void setClassLoaderName(java.lang.String classLoaderName)
          Set the name of the class to use for reading the images
 boolean setDeviceXResolution(Dpi resolution)
          Set the DPI for the scan.
 boolean setDeviceXResolution(int resolution)
          allows the developer more explicit control
 boolean setDeviceXScale(short percent)
          All the X-axis scaling values available.
 boolean setDeviceYResolution(Dpi resolution)
          Set the DPI for the scan.
 boolean setDeviceYResolution(int resolution)
          allows the developer more explicit control
 boolean setDeviceYScale(short percent)
          All the Y-axis scaling values available.
 boolean setRegionOfInterest(RegionOfInterest roi)
          Not all device honor this setting.
 void setUseMemoryForAcquisition(boolean useMemoryForAcquisition)
           
 void showUi(boolean show)
          Should the Vendor's UI be display.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tc_loader

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

TwainConnect

public TwainConnect()
             throws TwainConnectException
Once the source manager has been loaded, it is not normally unloaded until your application is destroyed. This makes normal TWAIN operations quite a bit faster. Since the JRE will not release the JNI DLL regardless keeping the DLL in memory is not an issue.

Throws:
TwainConnectException
Method Detail

addTwainListener

public void addTwainListener(TwainEventListener l)
Add a TwainEventListener instance and inform all the listeners of the Image acquisition event

Parameters:
l - - listener for Twain Events

removeTwainListener

public void removeTwainListener(TwainEventListener l)
Remove a TwainEventListener instance from the list

Parameters:
l -

fireTwainImageCaptured

protected void fireTwainImageCaptured()
Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.


fireTwainImageFailed

protected void fireTwainImageFailed(java.lang.Exception e)
Notify all listeners that have registered interest for notification on a failed image acquisition. The event instance is lazily created using the parameters passed into the fire method.


fireTwainCapabilityNotSet

protected void fireTwainCapabilityNotSet(Capability c)
Notify all listeners that have registered interest for notification on not being able to set the particular capability for this device. The event instance is lazily created using the parameters passed into the fire method.


fireTwainCapabilitySet

protected void fireTwainCapabilitySet(Capability c)
Notify all listeners that have registered interest for notification on being able to set the particular capability for this device. The event instance is lazily created using the parameters passed into the fire method.


getClassLoaderName

public java.lang.String getClassLoaderName()
The name of the class to use for reading the images. The IO class needs to be set once. TwainConnect uses the default JRE Image IO classes now rather than the a TwainConnect proprietary one.

Returns:
The fully qualified class name to use for loading Bitmaps

setClassLoaderName

public void setClassLoaderName(java.lang.String classLoaderName)
Set the name of the class to use for reading the images

Parameters:
classLoaderName -

isTwainAvailble

public boolean isTwainAvailble()
true if the TWAIN DataSource Manager is available and can be loaded. Does not actually load the devices's datasources. But normally, the presence of the DSM means that at least one datasource has been installed. isTwainAvailble() is fast after the first call It can be used to enable or disable menu items in UI code.

Returns:
Determines if the underlying WIN32 OS has a TWAIN32 implementation installed. Either a device or the TWAIN Groups Sample DS must be installed for this method to return true

isUseMemoryForAcquisition

public boolean isUseMemoryForAcquisition()
Returns:
the useMemoryForAcquisition

setUseMemoryForAcquisition

public void setUseMemoryForAcquisition(boolean useMemoryForAcquisition)
Parameters:
useMemoryForAcquisition - the useMemoryForAcquisition to set

isCancelScanning

public boolean isCancelScanning()
Returns:
the cancelScanning

setCancelScanning

public void setCancelScanning(boolean cancelScanning)
cancel scanning is a multi document environment Does not stop the device. this merely stops the engine from reading more images from the device. the device may continue. This method is more for the UI

Parameters:
cancelScanning - to stop the UI from polling for more images

getAvailableSources

public java.lang.String[] getAvailableSources()
Returns the names of all the available TAWAIN devices. These names are vendor specific and perhaps not localized. The names are not guaranteed to be unique, and sometimes the names are not very descriptive. Worst case scenario the name is just wrong.

Specified by:
getAvailableSources in interface com.jimageconnect.core.JImageconnect
Returns:
String[] of all device names found on the workstation

getLoader

protected ImageLoader getLoader()
                         throws TwainConnectException
Load the default image io class as defined by either the property file or set at run-time. The default ImageLoader is a 8 bit and 24 bit only bitmap loader. More complex and scable loaders can used instead if performance or large images are an isssue. The other Java IO class loaders though will require a more complex distribution and deployment issues.

Returns:
ImageLoader
Throws:
TwainConnectException

acquire

public void acquire(java.lang.String sourcename)
             throws TwainConnectException
Opens and enables the named source. depending on if the engine is using Memory or File IO for the transfer, twainconnect will acquire 1..n images. By default ADF or multiple images are supported as the TwainConnect engine will keep scanning images until requested to stop or until images are finished scanning Note if acquire is called again the previous image is lost forever. Clients are encouraged to make a local copy if the image must persist.

Specified by:
acquire in interface com.jimageconnect.core.JImageconnect
Parameters:
sourcename - The name of the source. Preferably this name is a value derived from the getAvailbleSources method.
Throws:
TwainConnectException

acquireImagesMemory

public void acquireImagesMemory(java.lang.String sourcename)
                         throws TwainConnectException
Opens and enables the named source. By default ADF or multiple images are supported as the TwainConnect engine will keep scanning images until requested to stop or until images are finished scanning Note if acquire is called again the previous image is lost forever. Clients are encouraged to make a local copy if the image must persist.

Specified by:
acquireImagesMemory in interface com.jimageconnect.core.JImageconnect
Parameters:
sourcename - The name of the source. Preferably this name is a value derived from the getAvailbleSources method.
Throws:
TwainConnectException

acquireImagesFileIo

public void acquireImagesFileIo(java.lang.String sourcename)
                         throws TwainConnectException
Opens and enables the named source. If successful the filename is returned. This file is temporarily saved on the user.home directory If the file is empty or for some reason can not be loaded an exception is thrown. By default ADF or multiple images are supported as the TwainConnect engine will keep scanning images until requested to stop or until images are finished scanning Note if acquire is called again the previous image is lost forever. Clients are encouraged to make a local copy if the image must persist.

Parameters:
sourcename - The name of the source. Preferably this name is a value derived from the getAvailbleSources method.
Throws:
TwainConnectException

showUi

public void showUi(boolean show)
Should the Vendor's UI be display. Make the best attempt to control the behavior

Parameters:
show - true to show

openSource

public boolean openSource(java.lang.String sourcename)
Used internally to explicitly open source

Parameters:
sourcename -
Returns:
boolean

setDeviceXResolution

public boolean setDeviceXResolution(Dpi resolution)
Set the DPI for the scan. These settings are a bit more controlled

Parameters:
resolution -
Returns:
boolean if the value has been set by the device

setDeviceYResolution

public boolean setDeviceYResolution(Dpi resolution)
Set the DPI for the scan. These settings are a bit more controlled

Parameters:
resolution -
Returns:
boolean if the value has been set by the device

setDeviceXResolution

public boolean setDeviceXResolution(int resolution)
allows the developer more explicit control

Parameters:
resolution -
Returns:
boolean

setDeviceYResolution

public boolean setDeviceYResolution(int resolution)
allows the developer more explicit control

Parameters:
resolution -
Returns:
boolean

setDeviceXScale

public boolean setDeviceXScale(short percent)
                        throws java.lang.UnsupportedOperationException
All the X-axis scaling values available. A value of '100' is equivalent to 100% scaling. Do not use values less than or equal to zero. There is no unit inherent with this data as it is normalized to 100 being "unscaled". Applications will want to ensure that the values set for this ICAP match those set for ICAP_YSCALING.

Parameters:
percent - value must 0 to 100
Returns:
boolean
Throws:
java.lang.UnsupportedOperationException - if you pass a value = 0 or greater than 100

setDeviceYScale

public boolean setDeviceYScale(short percent)
All the Y-axis scaling values available. A value of '100' is equivalent to 100% scaling. Do not use values less than or equal to zero. There is no unit inherent with this data as it is normalized to 100 being "unscaled". Applications will want to ensure that the values set for this ICAP match those set for ICAP_YSCALING.

Parameters:
percent - value must 0 to 100
Returns:
boolean
Throws:
java.lang.UnsupportedOperationException - if you pass a value = 0 or greater than 100

closeSource

public boolean closeSource(java.lang.String sourcename)
Used internally to close the source

Parameters:
sourcename -
Returns:
boolean

setBitDepth

public void setBitDepth(BitDepth bitDepth)
Set the requested Bit Depth. Most application will want to acquire in color and need not call this methods as 24 bit color is the default. Normally called to acquire a b/w or 1 bit pure black/white image

Parameters:
bitDepth - color, b/w or gray scale image

setRegionOfInterest

public boolean setRegionOfInterest(RegionOfInterest roi)
Not all device honor this setting. You will need to verify that the settings have taken DO NOT ASSUME.

Parameters:
roi -

isEngineAvailble

public boolean isEngineAvailble()
Specified by:
isEngineAvailble in interface com.jimageconnect.core.JImageconnect

acquireNativeMemory

public static java.awt.Image acquireNativeMemory(java.lang.String pSourceName)
                                          throws TwainConnectException
Throws:
TwainConnectException

moreImagesAvailable

public boolean moreImagesAvailable()
Specified by:
moreImagesAvailable in interface com.jimageconnect.core.JImageconnect