public final class Printer extends Device
new GC(printer)
and then draw on the printer GC using the usual graphics calls.
A Printer
object may be constructed by providing
a PrinterData
object which identifies the printer.
A PrintDialog
presents a print dialog to the user
and returns an initialized instance of PrinterData
.
Alternatively, calling new Printer()
will construct a
printer object for the user's default printer.
Application code must explicitly invoke the Printer.dispose()
method to release the operating system resources managed by each instance
when those instances are no longer required.
Modifier and Type | Field and Description |
---|---|
(package private) static TCHAR |
appName |
(package private) PrinterData |
data
the printer data describing this printer
|
int |
handle
the handle to the printer DC
(Warning: This field is platform dependent)
IMPORTANT: This field is not part of the SWT
public API.
|
(package private) boolean |
isGCCreated
whether or not a GC was created for this printer
|
(package private) static TCHAR |
keyName |
(package private) static TCHAR |
profile
strings used to access the Windows registry
|
CurrentDevice, DEBUG, DeviceFinder, hPalette
Constructor and Description |
---|
Printer()
Constructs a new printer representing the default printer.
|
Printer(PrinterData data)
Constructs a new printer given a
PrinterData
object representing the desired printer. |
Modifier and Type | Method and Description |
---|---|
void |
cancelJob()
Cancels a print job in progress.
|
protected void |
checkDevice()
Checks the validity of this device.
|
(package private) static DeviceData |
checkNull(PrinterData data) |
Rectangle |
computeTrim(int x,
int y,
int width,
int height)
Given a client area (as described by the arguments),
returns a rectangle, relative to the client area's coordinates,
that is the client area expanded by the printer's trim (or minimum margins).
|
protected void |
create(DeviceData deviceData)
Creates the printer handle.
|
protected void |
destroy()
Destroys the printer handle.
|
void |
endJob()
Ends the current print job.
|
void |
endPage()
Ends the current page.
|
Rectangle |
getBounds()
Returns a rectangle describing the receiver's size and location.
|
Rectangle |
getClientArea()
Returns a rectangle which describes the area of the
receiver which is capable of displaying data.
|
static PrinterData |
getDefaultPrinterData()
Returns a
PrinterData object representing
the default printer or null if there is no
default printer. |
Point |
getDPI()
Returns a point whose x coordinate is the horizontal
dots per inch of the printer, and whose y coordinate
is the vertical dots per inch of the printer.
|
PrinterData |
getPrinterData()
Returns a
PrinterData object representing the
target printer for this print job. |
static PrinterData[] |
getPrinterList()
Returns an array of
PrinterData objects
representing all available printers. |
void |
internal_dispose_GC(int hDC,
GCData data)
Invokes platform specific functionality to dispose a GC handle.
|
int |
internal_new_GC(GCData data)
Invokes platform specific functionality to allocate a new GC handle.
|
protected void |
release()
Releases any internal state prior to destroying this printer.
|
boolean |
startJob(java.lang.String jobName)
Starts a print job and returns true if the job started successfully
and false otherwise.
|
boolean |
startPage()
Starts a page and returns true if the page started successfully
and false otherwise.
|
dispose, getDepth, getDeviceData, getFontList, getSystemColor, getSystemFont, getWarnings, init, isDisposed, loadFont, setWarnings
public int handle
IMPORTANT: This field is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms and should never be accessed from application code.
PrinterData data
boolean isGCCreated
static TCHAR profile
static TCHAR appName
static TCHAR keyName
public Printer()
Note: You must dispose the printer when it is no longer required.
SWTError
- Device.dispose()
public Printer(PrinterData data)
PrinterData
object representing the desired printer. If the argument
is null, then the default printer will be used.
Note: You must dispose the printer when it is no longer required.
data
- the printer data for the specified printer, or null to use the default printerjava.lang.IllegalArgumentException
- SWTError
- Device.dispose()
public static PrinterData[] getPrinterList()
PrinterData
objects
representing all available printers. If there are no
printers, the array will be empty.public static PrinterData getDefaultPrinterData()
PrinterData
object representing
the default printer or null
if there is no
default printer.static DeviceData checkNull(PrinterData data)
protected void create(DeviceData deviceData)
Device
class.create
in class Device
deviceData
- the device dataDevice.init()
public int internal_new_GC(GCData data)
IMPORTANT: This method is not part of the public
API for Printer
. It is marked public only so that it
can be shared within the packages provided by SWT. It is not
available on all platforms, and should never be called from
application code.
internal_new_GC
in interface Drawable
internal_new_GC
in class Device
data
- the platform specific GC datapublic void internal_dispose_GC(int hDC, GCData data)
IMPORTANT: This method is not part of the public
API for Printer
. It is marked public only so that it
can be shared within the packages provided by SWT. It is not
available on all platforms, and should never be called from
application code.
internal_dispose_GC
in interface Drawable
internal_dispose_GC
in class Device
hDC
- the platform specific GC handledata
- the platform specific GC datapublic boolean startJob(java.lang.String jobName)
This must be the first method called to initiate a print job, followed by any number of startPage/endPage calls, followed by endJob. Calling startPage, endPage, or endJob before startJob will result in undefined behavior.
jobName
- the name of the print job to startSWTException
- startPage()
,
endPage()
,
endJob()
public void endJob()
SWTException
- startJob(java.lang.String)
,
startPage()
,
endPage()
public void cancelJob()
SWTException
- public boolean startPage()
After calling startJob, this method may be called any number of times along with a matching endPage.
SWTException
- endPage()
,
startJob(java.lang.String)
,
endJob()
public void endPage()
SWTException
- startPage()
,
startJob(java.lang.String)
,
endJob()
public Point getDPI()
getDPI
in class Device
SWTException
- public Rectangle getBounds()
For a printer, this is the size of the physical page, in pixels.
getBounds
in class Device
SWTException
- getClientArea()
,
computeTrim(int, int, int, int)
public Rectangle getClientArea()
For a printer, this is the size of the printable area of the page, in pixels.
getClientArea
in class Device
SWTException
- getBounds()
,
computeTrim(int, int, int, int)
public Rectangle computeTrim(int x, int y, int width, int height)
Most printers have a minimum margin on each edge of the paper where the printer device is unable to print. This margin is known as the "trim." This method can be used to calculate the printer's minimum margins by passing in a client area of 0, 0, 0, 0 and then using the resulting x and y coordinates (which will be <= 0) to determine the minimum margins for the top and left edges of the paper, and the resulting width and height (offset by the resulting x and y) to determine the minimum margins for the bottom and right edges of the paper, as follows:
x
- the x coordinate of the client areay
- the y coordinate of the client areawidth
- the width of the client areaheight
- the height of the client areaSWTException
- getBounds()
,
getClientArea()
public PrinterData getPrinterData()
PrinterData
object representing the
target printer for this print job.protected void checkDevice()
checkDevice
in class Device
SWTException
- protected void release()
Device
class.release
in class Device
Device.dispose()
,
Device.destroy()
protected void destroy()
Device
class.destroy
in class Device
Device.dispose()
,
Device.release()