JTwain v9 - Lab Asprise! All Rights Reserved.

com.asprise.util.jtwain.lowlevel
Class Control

java.lang.Object
  extended bycom.asprise.util.jtwain.lowlevel.Control
All Implemented Interfaces:
JTwainConstants

public class Control
extends Object
implements JTwainConstants

Utility class to control TWAIN operations.


Field Summary
static int ACTION_CLOSE_DS
           
static int ACTION_CLOSE_SM
           
static int ACTION_LOAD_SM
           
static int ACTION_OPEN_DS
           
static int ACTION_OPEN_SM
           
static int ACTION_SELECT_DS
           
static int ACTION_UNLOAD_SM
           
static int STATE_DS_ENABLED
           
static int STATE_DS_NOT_IN_USE
           
static int STATE_DS_OPEN
           
static int STATE_SM_LOADED
           
static int STATE_SM_NOT_LOADED
           
static int STATE_SM_OPEN
           
static int STATE_TRANSFER_READY
           
static int STATE_TRANSFERING
           
static int STATE_UNKNOWN
           
 
Fields inherited from interface com.asprise.util.jtwain.JTwainConstants
ACAP_AUDIOFILEFORMAT, ACAP_XFERMECH, CAP_ALARMS, CAP_ALARMVOLUME, CAP_AUTHOR, CAP_AUTOFEED, CAP_AUTOMATICCAPTURE, CAP_AUTOSCAN, CAP_BATTERYMINUTES, CAP_BATTERYPERCENTAGE, CAP_CAMERAPREVIEWUI, CAP_CAPTION, CAP_CLEARBUFFERS, CAP_CLEARPAGE, CAP_CUSTOMBASE, CAP_CUSTOMDSDATA, CAP_DEVICEEVENT, CAP_DEVICEONLINE, CAP_DEVICETIMEDATE, CAP_DUPLEX, CAP_DUPLEXENABLED, CAP_ENABLEDSUIONLY, CAP_ENDORSER, CAP_EXTENDEDCAPS, CAP_FEEDERALIGNMENT, CAP_FEEDERENABLED, CAP_FEEDERLOADED, CAP_FEEDERORDER, CAP_FEEDPAGE, CAP_INDICATORS, CAP_JOBCONTROL, CAP_LANGUAGE, CAP_MAXBATCHBUFFERS, CAP_PAPERDETECTABLE, CAP_POWERSUPPLY, CAP_PRINTER, CAP_PRINTERENABLED, CAP_PRINTERINDEX, CAP_PRINTERMODE, CAP_PRINTERSTRING, CAP_PRINTERSUFFIX, CAP_REACQUIREALLOWED, CAP_REWINDPAGE, CAP_SERIALNUMBER, CAP_SUPPORTEDCAPS, CAP_SUPPORTEDCAPSEXT, CAP_THUMBNAILSENABLED, CAP_TIMEBEFOREFIRSTCAPTURE, CAP_TIMEBETWEENCAPTURES, CAP_TIMEDATE, CAP_UICONTROLLABLE, CAP_XFERCOUNT, DAT_AUDIOFILEXFER, DAT_AUDIOINFO, DAT_AUDIONATIVEXFER, DAT_CAPABILITY, DAT_CIECOLOR, DAT_CUSTOMBASE, DAT_CUSTOMDSDATA, DAT_DEVICEEVENT, DAT_EVENT, DAT_EXTIMAGEINFO, DAT_FILESYSTEM, DAT_GRAYRESPONSE, DAT_IDENTITY, DAT_IMAGEFILEXFER, DAT_IMAGEINFO, DAT_IMAGELAYOUT, DAT_IMAGEMEMXFER, DAT_IMAGENATIVEXFER, DAT_JPEGCOMPRESSION, DAT_NULL, DAT_PALETTE8, DAT_PARENT, DAT_PASSTHRU, DAT_PENDINGXFERS, DAT_RGBRESPONSE, DAT_SETUPFILEXFER, DAT_SETUPFILEXFER2, DAT_SETUPMEMXFER, DAT_STATUS, DAT_TWUNKIDENTITY, DAT_USERINTERFACE, DAT_XFERGROUP, DEBUG, ICAP_AUTOBRIGHT, ICAP_AUTOMATICBORDERDETECTION, ICAP_AUTOMATICDESKEW, ICAP_AUTOMATICROTATE, ICAP_BARCODEDETECTIONENABLED, ICAP_BARCODEMAXRETRIES, ICAP_BARCODEMAXSEARCHPRIORITIES, ICAP_BARCODESEARCHMODE, ICAP_BARCODESEARCHPRIORITIES, ICAP_BARCODETIMEOUT, ICAP_BITDEPTH, ICAP_BITDEPTHREDUCTION, ICAP_BITORDER, ICAP_BITORDERCODES, ICAP_BRIGHTNESS, ICAP_CCITTKFACTOR, ICAP_COMPRESSION, ICAP_CONTRAST, ICAP_CUSTHALFTONE, ICAP_EXPOSURETIME, ICAP_EXTIMAGEINFO, ICAP_FILTER, ICAP_FLASHUSED, ICAP_FLASHUSED2, ICAP_FLIPROTATION, ICAP_FRAMES, ICAP_GAMMA, ICAP_HALFTONES, ICAP_HIGHLIGHT, ICAP_IMAGEDATASET, ICAP_IMAGEFILEFORMAT, ICAP_IMAGEFILTER, ICAP_JPEGPIXELTYPE, ICAP_JPEGQUALITY, ICAP_LAMPSTATE, ICAP_LIGHTPATH, ICAP_LIGHTSOURCE, ICAP_MAXFRAMES, ICAP_MINIMUMHEIGHT, ICAP_MINIMUMWIDTH, ICAP_NOISEFILTER, ICAP_ORIENTATION, ICAP_OVERSCAN, ICAP_PATCHCODEDETECTIONENABLED, ICAP_PATCHCODEMAXRETRIES, ICAP_PATCHCODEMAXSEARCHPRIORITIES, ICAP_PATCHCODESEARCHMODE, ICAP_PATCHCODESEARCHPRIORITIES, ICAP_PATCHCODETIMEOUT, ICAP_PHYSICALHEIGHT, ICAP_PHYSICALWIDTH, ICAP_PIXELFLAVOR, ICAP_PIXELFLAVORCODES, ICAP_PIXELTYPE, ICAP_PLANARCHUNKY, ICAP_ROTATION, ICAP_SHADOW, ICAP_SUPPORTEDBARCODETYPES, ICAP_SUPPORTEDPATCHCODETYPES, ICAP_SUPPORTEDSIZES, ICAP_THRESHOLD, ICAP_TILES, ICAP_TIMEFILL, ICAP_UNDEFINEDIMAGESIZE, ICAP_UNITS, ICAP_XFERMECH, ICAP_XNATIVERESOLUTION, ICAP_XRESOLUTION, ICAP_XSCALING, ICAP_YNATIVERESOLUTION, ICAP_YRESOLUTION, ICAP_YSCALING, ICAP_ZOOMFACTOR, JT_ACTION_CLOSE_DS, JT_ACTION_CLOSE_SM, JT_ACTION_LOAD_SM, JT_ACTION_OPEN_DS, JT_ACTION_OPEN_SM, JT_ACTION_SELECT_DS, JT_ACTION_UNLOAD_SM, JT_STATE_DS_ENABLED, JT_STATE_DS_NOT_IN_USE, JT_STATE_DS_OPEN, JT_STATE_SM_LOADED, JT_STATE_SM_NOT_LOADED, JT_STATE_SM_OPEN, JT_STATE_TRANSFER_READY, JT_STATE_TRANSFERING, JT_STATE_UNKNOWN, MSG_GET, MSG_GETCURRENT, MSG_GETDEFAULT, MSG_GETFIRST, MSG_GETNEXT, MSG_QUERYSUPPORT, MSG_RESET, MSG_SET, TWAIN_STATE_DS_ENABLED, TWAIN_STATE_DS_OPEN, TWAIN_STATE_PRESESSION, TWAIN_STATE_SM_LOADED, TWAIN_STATE_SM_OPEN, TWAIN_STATE_TRANSFER_READY, TWAIN_STATE_TRANSFERING, TWBO_LSBFIRST, TWBO_MSBFIRST, TWCC_BADCAP, TWCC_BADDEST, TWCC_BADPROTOCOL, TWCC_BADVALUE, TWCC_BUMMER, TWCC_CAPBADOPERATION, TWCC_CAPSEQERROR, TWCC_CAPUNSUPPORTED, TWCC_CHECKDEVICEONLINE, TWCC_CUSTOMBASE, TWCC_DENIED, TWCC_FILEEXISTS, TWCC_FILENOTFOUND, TWCC_FILEWRITEERROR, TWCC_LOWMEMORY, TWCC_MAXCONNECTIONS, TWCC_NODS, TWCC_NOTEMPTY, TWCC_OPERATIONERROR, TWCC_PAPERDOUBLEFEED, TWCC_PAPERJAM, TWCC_SEQERROR, TWCC_SUCCESS, TWCP_BITFIELDS, TWCP_GROUP31D, TWCP_GROUP31DEOL, TWCP_GROUP32D, TWCP_GROUP4, TWCP_JBIG, TWCP_JPEG, TWCP_LZW, TWCP_NONE, TWCP_PACKBITS, TWCP_PNG, TWCP_RLE4, TWCP_RLE8, TWFF_BMP, TWFF_EXIF, TWFF_FPX, TWFF_JFIF, TWFF_PICT, TWFF_PNG, TWFF_SPIFF, TWFF_TIFF, TWFF_TIFFMULTI, TWFF_XBM, TWFT_BLACK, TWFT_BLUE, TWFT_CYAN, TWFT_GREEN, TWFT_MAGENTA, TWFT_NONE, TWFT_RED, TWFT_WHITE, TWFT_YELLOW, TWLP_REFLECTIVE, TWLP_TRANSMISSIVE, TWLS_BLUE, TWLS_GREEN, TWLS_IR, TWLS_NONE, TWLS_RED, TWLS_UV, TWLS_WHITE, TWON_ARRAY, TWON_DONTCARE16, TWON_DONTCARE32, TWON_DONTCARE8, TWON_DSMCODEID, TWON_DSMID, TWON_ENUMERATION, TWON_ICONID, TWON_ONEVALUE, TWON_RANGE, TWOR_LANDSCAPE, TWOR_PORTRAIT, TWOR_ROT0, TWOR_ROT180, TWOR_ROT270, TWOR_ROT90, TWPC_CHUNKY, TWPC_PLANAR, TWPF_CHOCOLATE, TWPF_VANILLA, TWPT_BW, TWPT_CIEXYZ, TWPT_CMY, TWPT_CMYK, TWPT_GRAY, TWPT_PALETTE, TWPT_RGB, TWPT_YUV, TWPT_YUVK, TWQC_GET, TWQC_GETCURRENT, TWQC_GETDEFAULT, TWQC_RESET, TWQC_SET, TWRC_CANCEL, TWRC_CHECKSTATUS, TWRC_CUSTOMBASE, TWRC_DATANOTAVAILABLE, TWRC_DSEVENT, TWRC_ENDOFLIST, TWRC_FAILURE, TWRC_INFONOTSUPPORTED, TWRC_NOTDSEVENT, TWRC_SUCCESS, TWRC_XFERDONE, TWSS_2A0, TWSS_4A0, TWSS_A0, TWSS_A1, TWSS_A10, TWSS_A2, TWSS_A3, TWSS_A4, TWSS_A4LETTER, TWSS_A5, TWSS_A6, TWSS_A7, TWSS_A8, TWSS_A9, TWSS_B3, TWSS_B4, TWSS_B5LETTER, TWSS_B6, TWSS_BUSINESSCARD, TWSS_C0, TWSS_C1, TWSS_C10, TWSS_C2, TWSS_C3, TWSS_C4, TWSS_C5, TWSS_C6, TWSS_C7, TWSS_C8, TWSS_C9, TWSS_ISOB0, TWSS_ISOB1, TWSS_ISOB10, TWSS_ISOB2, TWSS_ISOB3, TWSS_ISOB4, TWSS_ISOB5, TWSS_ISOB6, TWSS_ISOB7, TWSS_ISOB8, TWSS_ISOB9, TWSS_JISB0, TWSS_JISB1, TWSS_JISB10, TWSS_JISB2, TWSS_JISB3, TWSS_JISB4, TWSS_JISB5, TWSS_JISB6, TWSS_JISB7, TWSS_JISB8, TWSS_JISB9, TWSS_NONE, TWSS_USEXECUTIVE, TWSS_USLEDGER, TWSS_USLEGAL, TWSS_USLETTER, TWSS_USSTATEMENT, TWSX_FILE, TWSX_FILE2, TWSX_MEMORY, TWSX_NATIVE, TWTY_BOOL, TWTY_FIX32, TWTY_FRAME, TWTY_INT16, TWTY_INT32, TWTY_INT8, TWTY_STR1024, TWTY_STR128, TWTY_STR255, TWTY_STR32, TWTY_STR64, TWTY_UINT16, TWTY_UINT32, TWTY_UINT8, TWTY_UNI512, TWUN_CENTIMETERS, TWUN_INCHES, TWUN_PICAS, TWUN_PIXELS, TWUN_POINTS, TWUN_TWIPS
 
Constructor Summary
Control()
           
 
Method Summary
static boolean abortAllPendingImages()
          Instructs the Source to abort all pending images.
static String acquireOneImage(Source source)
          Acquires an image from a Source.
static void assertState(Source source, int requiredState)
          Asserts the current state is the required one.
static void assertStateAtLeast(Source source, int requiredStateAtLeast)
          Asserts the current state is the required state or above it.
static boolean assertStateNoException(Source source, int requiredState)
          Asserts the current state is the required one.
static OperationResult CapabilityMsg(int messageType, Capability capability)
          Performs capability operations - MSG_GET, MSG_GETCURRENT, MSG_GETDEFAULT, MSG_RESET, MSG_SET.
static OperationResult CapabilityMsgReset(Capability capability)
           
static OperationResult CapabilityMsgSet(Capability capability)
           
static void closeSource()
          Closes the current active source.
static void closeSourceManager()
          Closes the source manager.
static int getConditionCode()
          Gets the condition code of an operation.
static Source getCurrentSource()
          Gets the current active source.
static String getLastScannedFile()
           
static int getNumberOfPendingImages()
          Gets number of pending images of the current active source.
static int getReturnCode()
          Gets the return code of an operation.
static int getState(Source source)
          Gets the status of a Source.
static String getStateRepresentation(int code)
          Gets a String representation of a TWAIN state.
static OperationResult ImageLayoutGet()
          Added on Jan 05, 2006 to provide partial scanning.
static OperationResult ImageLayoutSet(DataTypeImageLayout layout)
           
static void loadLibrary()
          Loads JTWAIN library.
static void loadSourceManager()
          Loads source manager.
static void openDataSource(Source source)
          Opens the specified data source.
static void openSourceManager()
          Opens the source manager.
static void selectDataSource(String sourceName)
          Selects the data source for this session.
static boolean skipNextImage()
          Instructs the Source to skip next pending image.
static void unloadSourceManager()
          Unloads source manager.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_UNKNOWN

public static final int STATE_UNKNOWN
See Also:
Constant Field Values

STATE_SM_NOT_LOADED

public static final int STATE_SM_NOT_LOADED
See Also:
Constant Field Values

STATE_SM_LOADED

public static final int STATE_SM_LOADED
See Also:
Constant Field Values

STATE_SM_OPEN

public static final int STATE_SM_OPEN
See Also:
Constant Field Values

STATE_DS_OPEN

public static final int STATE_DS_OPEN
See Also:
Constant Field Values

STATE_DS_ENABLED

public static final int STATE_DS_ENABLED
See Also:
Constant Field Values

STATE_TRANSFER_READY

public static final int STATE_TRANSFER_READY
See Also:
Constant Field Values

STATE_TRANSFERING

public static final int STATE_TRANSFERING
See Also:
Constant Field Values

STATE_DS_NOT_IN_USE

public static final int STATE_DS_NOT_IN_USE
See Also:
Constant Field Values

ACTION_LOAD_SM

public static final int ACTION_LOAD_SM
See Also:
Constant Field Values

ACTION_OPEN_SM

public static final int ACTION_OPEN_SM
See Also:
Constant Field Values

ACTION_SELECT_DS

public static final int ACTION_SELECT_DS
See Also:
Constant Field Values

ACTION_OPEN_DS

public static final int ACTION_OPEN_DS
See Also:
Constant Field Values

ACTION_CLOSE_DS

public static final int ACTION_CLOSE_DS
See Also:
Constant Field Values

ACTION_CLOSE_SM

public static final int ACTION_CLOSE_SM
See Also:
Constant Field Values

ACTION_UNLOAD_SM

public static final int ACTION_UNLOAD_SM
See Also:
Constant Field Values
Constructor Detail

Control

public Control()
Method Detail

CapabilityMsg

public static OperationResult CapabilityMsg(int messageType,
                                            Capability capability)
Performs capability operations - MSG_GET, MSG_GETCURRENT, MSG_GETDEFAULT, MSG_RESET, MSG_SET.

Parameters:
messageType - type of the message: MSG_GET, MSG_GETCURRENT, MSG_GETDEFAULT, MSG_RESET or MSG_SET.
capability - the target capability represented by a Capability object
Returns:
the operation result

CapabilityMsgReset

public static OperationResult CapabilityMsgReset(Capability capability)

CapabilityMsgSet

public static OperationResult CapabilityMsgSet(Capability capability)

ImageLayoutGet

public static OperationResult ImageLayoutGet()
Added on Jan 05, 2006 to provide partial scanning.

Returns:

ImageLayoutSet

public static OperationResult ImageLayoutSet(DataTypeImageLayout layout)

getLastScannedFile

public static String getLastScannedFile()

unloadSourceManager

public static void unloadSourceManager()
                                throws JTwainException
Unloads source manager. Load TWAIN_32.DLL.

Throws:
JTwainException

loadSourceManager

public static void loadSourceManager()
                              throws JTwainException
Loads source manager. Load TWAIN_32.DLL.

Throws:
JTwainException

openSourceManager

public static void openSourceManager()
                              throws JTwainException
Opens the source manager. If SM has not been loaded, load it automatically.

Throws:
JTwainException

selectDataSource

public static void selectDataSource(String sourceName)
                             throws JTwainException
Selects the data source for this session. Automatically open SM if it has not been opened yet.

Parameters:
sourceName - the name of the source to be opened
Throws:
JTwainException

openDataSource

public static void openDataSource(Source source)
                           throws JTwainException
Opens the specified data source. Close previous open source if any; automatically open source manager if it has not been opened yet.

Parameters:
source - the source to be opened
Throws:
JTwainException

closeSource

public static void closeSource()
                        throws JTwainException
Closes the current active source. If the source if in state 5 (enabled), disable it automatically. If the active source has been closed, the state backs to state 3 (SM open). Otherwise, state untouched.

Throws:
JTwainException

closeSourceManager

public static void closeSourceManager()
Closes the source manager. If any source is open, it will be closed automatically. It does not throw any exception. State should backs to state 2 (SM loaded).


getState

public static int getState(Source source)
Gets the status of a Source.

Parameters:
source - the specific Source
Returns:

getCurrentSource

public static Source getCurrentSource()
Gets the current active source.

Returns:
null if there is no source opened, otherwised, the opened Source will be returned.

acquireOneImage

public static String acquireOneImage(Source source)
Acquires an image from a Source.

Parameters:
source - the source from which the image is going to be acquired.
Returns:

getConditionCode

public static int getConditionCode()
Gets the condition code of an operation.

Returns:
condition code

getReturnCode

public static int getReturnCode()
Gets the return code of an operation.

Returns:
return code

getNumberOfPendingImages

public static int getNumberOfPendingImages()
Gets number of pending images of the current active source.

Returns:
number of pending images

skipNextImage

public static boolean skipNextImage()
Instructs the Source to skip next pending image.

Returns:

abortAllPendingImages

public static boolean abortAllPendingImages()
Instructs the Source to abort all pending images.

Returns:

loadLibrary

public static void loadLibrary()
Loads JTWAIN library.


assertState

public static void assertState(Source source,
                               int requiredState)
                        throws InvalidStateException
Asserts the current state is the required one.

Parameters:
source - the target data source
Throws:
InvalidStateException - if current state is not the desired one

assertStateAtLeast

public static void assertStateAtLeast(Source source,
                                      int requiredStateAtLeast)
                               throws InvalidStateException
Asserts the current state is the required state or above it.

Parameters:
source - the target data source
Throws:
InvalidStateException - if current state is not appropriate.

assertStateNoException

public static boolean assertStateNoException(Source source,
                                             int requiredState)
Asserts the current state is the required one. Perfom the same task with assertState, exception it does not throw any exception.

Parameters:
source - the target data source
requiredState - the required state
Returns:
true if current state is the required; false otherwise.

getStateRepresentation

public static String getStateRepresentation(int code)
Gets a String representation of a TWAIN state.

Parameters:
code - state code
Returns:
a String representation

JTwain v9 - Lab Asprise! All Rights Reserved.