org.hcilab.btprinter
Class Driver

java.lang.Object
  extended by org.hcilab.btprinter.Driver
All Implemented Interfaces:
java.lang.Runnable

public class Driver
extends java.lang.Object
implements java.lang.Runnable

This is the core class of the printing package. It handles the platform specific driver loading and the sequence of control codes being sent to the printer.

This driver has been tested with a Brother MW-140BT bluetooth printer. The printing is done in a parallel thread so it is not blocking.

ToDo

Version:
1.0.0
Author:
Dominik Schmidt

Field Summary
static byte STATUS_ERROR
          There was an error during printing.
static byte STATUS_PRINTING
          Driver is currently printing.
static byte STATUS_READY
          Driver is ready and waiting.
 
Constructor Summary
Driver(java.lang.String platformPackage)
          Initializes driver with the given platform specific driver package which has to provide at least the classes ImageHandlerImpl, IOHandlerImpl and LogHandlerImpl.
Driver(java.lang.String platformPackage, LogHandler logHandler)
          Initializes driver with the given platform specific driver package which has to provide at least the classes ImageHandlerImpl, IOHandlerImpl and LogHandlerImpl.
 
Method Summary
 void addObserver(Observer observer)
          Adds a observer to this driver.
 int getProgress()
          Gives information about the printing progress.
 byte getStatus()
          Provides information about the driver's status.
 java.lang.String getStatusMessage()
          Provides a human readable description of the driver's status.
 void print(java.lang.Object imgObject, java.lang.String connection)
          Prints the given image using the connection specified in the driver package and the identifier given here.
 void removeObserver(Observer observer)
          Removes a registered observer.
 void run()
          The actual printing is done here.
 void setLogHandler(LogHandler logHandler)
          Sets the log handler for this and associated objects.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATUS_ERROR

public static final byte STATUS_ERROR
There was an error during printing.

See Also:
Constant Field Values

STATUS_PRINTING

public static final byte STATUS_PRINTING
Driver is currently printing.

See Also:
Constant Field Values

STATUS_READY

public static final byte STATUS_READY
Driver is ready and waiting.

See Also:
Constant Field Values
Constructor Detail

Driver

public Driver(java.lang.String platformPackage)
       throws PlatformNotSupportedException
Initializes driver with the given platform specific driver package which has to provide at least the classes ImageHandlerImpl, IOHandlerImpl and LogHandlerImpl. A SimpleLogHandler is used for logging.

Parameters:
platformPackage - Name of platform package (e.g. org.hcilbab.btprinter.platform.j2me)
Throws:
PlatformNotSupportedException - If the necessary classes cannot be found in the given package

Driver

public Driver(java.lang.String platformPackage,
              LogHandler logHandler)
       throws PlatformNotSupportedException
Initializes driver with the given platform specific driver package which has to provide at least the classes ImageHandlerImpl, IOHandlerImpl and LogHandlerImpl. A log handler has to be specified.

Parameters:
platformPackage - Name of platform package (e.g. org.hcilbab.btprinter.platform.j2me)
logHandler - Log handler
Throws:
PlatformNotSupportedException - If the necessary classes cannot be found in the given package
Method Detail

addObserver

public void addObserver(Observer observer)
Adds a observer to this driver. The observer is notified if the status or progress of printing changes.

Parameters:
observer - Observer to add

getProgress

public int getProgress()
Gives information about the printing progress.

Returns:
Integer between 0 and 100

getStatus

public byte getStatus()
Provides information about the driver's status.

Returns:
Status of driver

getStatusMessage

public java.lang.String getStatusMessage()
Provides a human readable description of the driver's status. Can be directly displayed to the user.

Returns:
Description of status

print

public void print(java.lang.Object imgObject,
                  java.lang.String connection)
           throws java.io.IOException,
                  java.lang.IllegalArgumentException,
                  java.lang.IllegalStateException
Prints the given image using the connection specified in the driver package and the identifier given here. The necessary type depends on the selected driver package. Printing is done in a parallel thread so this method returns right after starting the printing thread.

Parameters:
imgObject - Object representing an image (depending on the selected driver package)
connection - Connection identifier (meaning depends on the selected driver package)
Throws:
java.io.IOException - If any io error occurs
java.lang.IllegalArgumentException - If printer status is not recognized
java.lang.IllegalStateException - If there is already a print job going on

removeObserver

public void removeObserver(Observer observer)
Removes a registered observer.

Parameters:
observer - Observer to remove

run

public void run()
The actual printing is done here.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

setLogHandler

public void setLogHandler(LogHandler logHandler)
Sets the log handler for this and associated objects.

Parameters:
logHandler - Log handler