public abstract class Printer
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Printer.ExtraSettings
This class defines extra settings that may be required for creating
an object of a concrete subclass of Printer.
|
Modifier and Type | Method and Description |
---|---|
void |
addPrintProgressListener(PrintProgressListener aHandler)
Adds the specified listener to receive print progress events from the
concrete class object.
|
void |
close()
Closes the existing printer connection and releases the resources this
object uses.
|
void |
connect()
Opens a connection to the printer identified in the concrete class
constructor.
|
boolean |
disconnect()
Closes the existing printer connection.
|
void |
endDoc()
Indicates the end of the document and causes one or more
PrintProgressEvent events to be fired. |
void |
flush()
Sends all the data in the internal print buffer to the printer via the
transport medium.
|
void |
formFeed()
Sends the printer FormFeed command to the printer, causing it to feed
paper.
|
int |
getBytesWritten()
Gets the number of bytes sent to the printer since the last
connect() call. |
void |
removePrintProgressListener(PrintProgressListener aHandler)
Removes the specified listener so that it no longer receives print
progress events from the concrete class object.
|
void |
sendCustomCommand(java.lang.String aCommandID)
Sends a custom command identified by the specified command identifier
to the internal print buffer.
|
void |
setSettingBool(java.lang.String aSettingName,
boolean aBoolValue)
Adds the specified boolean setting to the current printer settings if
the setting name does not already exists; otherwise, the existing
setting value will be overridden.
|
void |
setSettingBytes(java.lang.String aSettingName,
byte[] aBytesValue)
Adds the specified byte array setting to the current printer settings
if the setting name does not already exists; otherwise, the existing
setting value will be overridden.
|
void |
setSettingNum(java.lang.String aSettingName,
int aIntValue)
Adds the specified integer setting to the current printer settings if
the setting name does not already exists; otherwise, the existing
setting value will be overridden.
|
void |
setSettingString(java.lang.String aSettingName,
java.lang.String aStrValue)
Adds the specified string setting to the current printer settings if
the setting name does not already exists; otherwise, the existing
setting value will be overridden.
|
void |
startFileEcho(java.lang.String aFilePath,
boolean clearFile)
Enables the file echo feature.
|
void |
stopFileEcho()
Disables the file echo feature.
|
void |
write(byte[] bytes)
Writes an array of bytes to the internal print buffer.
|
void |
write(java.lang.String aStr)
Writes a string to the internal print buffer.
|
public void addPrintProgressListener(PrintProgressListener aHandler)
aHandler
- An object that implements the PrintProgressListener
interface.removePrintProgressListener(PrintProgressListener)
,
PrintProgressEvent
,
PrintProgressListener
public void close() throws PrinterException
PrinterException
- if an error occurs in closing the connection
to the printer.public void connect() throws PrinterException
PrintProgressEvent
with a message type
of PrintProgressEvent.MessageTypes.STARTDOC
.
The application must call this method to connect to the printer before invoking other methods to interact with the printer; otherwise, a PrinterException will be thrown.
PrinterException
- if an error occurs in opening the connection
to the printer.public boolean disconnect() throws PrinterException
PrintProgressEvent
events with different message types.
If the endDoc()
method has not been called since the document
was started, the events are fired in the the following order:
PrintProgressEvent.MessageTypes.ENDDOC
PrintProgressEvent.MessageTypes.FINISHED
PrintProgressEvent.MessageTypes.COMPLETE
Note: The event with the PrintProgressEvent.MessageTypes.COMPLETE
message type is only fired if the document has been completely printed
without errors or being cancelled.
If the endDoc()
method was called to indicate the end of the
document and a new document has not been started, only one event is fired
with the PrintProgressEvent.MessageTypes.FINISHED
message type.
PrinterException
- if an error occurs in closing the connection
to the printer.public void endDoc() throws PrinterException
PrintProgressEvent
events to be fired. The events are fired in
the following order:
Note: The event with the PrintProgressEvent.MessageTypes.COMPLETE
message type is only fired if the document has been completely printed
without errors or being cancelled.
If the application does not close the printer connection via the
disconnect()
method after this method call, the next command or
data sent to the printer would trigger a PrintProgressEvent
with
a message type of PrintProgressEvent.MessageTypes.STARTDOC
.
PrinterException
- if an unexpected error occurs or if an
active connection to the printer does not exist.public void flush() throws PrinterException
PrinterException
- if an error occurs in sending the text to
the printer or if an active connection to the printer does not exist.public void formFeed() throws PrinterException
PrinterException
- if an error occurs in sending the command to
the printer or if an active connection to the printer does not exist.public int getBytesWritten() throws PrinterException
connect()
call.connect
call.PrinterException
- if an unexpected error occurs or if an
active connection to the printer does not exist.public void removePrintProgressListener(PrintProgressListener aHandler)
aHandler
- An object that implements the PrintProgressListener
interface.addPrintProgressListener(PrintProgressListener)
,
PrintProgressEvent
,
PrintProgressListener
public void sendCustomCommand(java.lang.String aCommandID) throws PrinterException
flush()
or LinePrinter.newLine(int)
is made.
The aCommandID
parameter specifies a setting name defined
in the current printer settings. The command setting value must be a
string or a byte array. For example, the following setting defines a
slogan with a bold-on sequence in the front and a bold-off sequence at
the end.
"MySlogan" : "\u001bwmSave Time and Money at MYSTORE.com\u001bw!"When you call
sendCustomCommand("MySlogan")
, it sends
"\u001bwmSave Time and Money at MYSTORE.com\u001bw!" to the
internal print buffer to be printed.
You may define custom commands in the commands and attributes file or
string specified in the concrete class constructor, or add custom commands
via the setSettingBytes
and setSettingString
methods.
aCommandID
- A string containing the name of a setting in the
current printer settings.PrinterException
- if the specified command identifier is
null or does not exist in the current printer setting, or if an active
connection to the printer does not exist.setSettingBytes(java.lang.String, byte[])
,
setSettingString(java.lang.String, java.lang.String)
public void setSettingBool(java.lang.String aSettingName, boolean aBoolValue) throws PrinterException
aSettingName
- A string containing the setting name.aBoolValue
- A Boolean setting value.PrinterException
- if an unexpected error occurs.public void setSettingBytes(java.lang.String aSettingName, byte[] aBytesValue) throws PrinterException
aSettingName
- A string containing the setting name.aBytesValue
- A byte array for the setting value.PrinterException
- if an unexpected error occurs.public void setSettingNum(java.lang.String aSettingName, int aIntValue) throws PrinterException
aSettingName
- A string containing the setting name.aIntValue
- An integer setting value.PrinterException
- if an unexpected error occurs.public void setSettingString(java.lang.String aSettingName, java.lang.String aStrValue) throws PrinterException
aSettingName
- A string containing the setting name.aStrValue
- A string containing the setting value.PrinterException
- if an unexpected error occurs.public void startFileEcho(java.lang.String aFilePath, boolean clearFile) throws PrinterException
aFilePath
- A string containing the file path of the file that will
receive the echoed commands.clearFile
- A Boolean 'true' value indicates that the file should be
deleted if it already exists or 'false' to append to the existing file.PrinterException
- if an unexpected error occurs.public void stopFileEcho() throws PrinterException
PrinterException
- if an unexpected error occurs.public void write(byte[] bytes) throws PrinterException
flush()
or LinePrinter.newLine(int)
is made.bytes
- An array of bytes to be written to the internal print
buffer.PrinterException
- if an unexpected error occurs or if an
active connection to the printer does not exist.public void write(java.lang.String aStr) throws PrinterException
flush()
or
LinePrinter.newLine(int)
is made.aStr
- A string to be written to the internal print buffer.PrinterException
- if an unexpected error occurs or if an
active connection to the printer does not exist.Copyright (c) 2013-2015 Honeywell International Inc. All rights reserved.