|
 |
|
|
org.eclipse.swt.printing
Class Printer
java.lang.Object
org.eclipse.swt.graphics.Device
org.eclipse.swt.printing.Printer
-
All Implemented Interfaces:
-
Drawable
-
public final class Printer
- extends
Device
Instances of this class are used to print to a printer.
Applications create a GC on a printer using 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.
-
See Also:
-
PrinterData ,
PrintDialog ,
Printing snippets,
Sample code and further information
Field Summary
|
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. |
Constructor Summary
|
Printer
()
Constructs a new printer representing the default printer. |
Printer
(
PrinterData data)
Constructs a new printer given a PrinterData
object representing the desired printer. |
Method Summary
|
void
|
cancelJob
()
Cancels a print job in progress. |
protected void
|
checkDevice
()
Checks the validity of this device. |
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
(
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. |
Methods inherited from class org.eclipse.swt.graphics.
Device
|
dispose,
getDepth,
getDeviceData,
getFontList,
getSystemColor,
getSystemFont,
getWarnings,
init,
isDisposed,
loadFont,
setWarnings
|
Methods inherited from class java.lang.
Object
|
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
|
handle
public 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. 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.
Printer
public Printer()
- Constructs a new printer representing the default printer.
Note: You must dispose the printer when it is no longer required.
-
Throws:
-
SWTError
-
- ERROR_NO_HANDLES - if there are no valid printers
-
See Also:
-
Device.dispose()
Printer
public Printer(
PrinterData data)
- Constructs a new printer given a
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.
-
Parameters:
-
data - the printer data for the specified printer, or null to use the default printer
-
Throws:
-
IllegalArgumentException
-
- ERROR_INVALID_ARGUMENT - if the specified printer data does not represent a valid printer
-
SWTError
-
- ERROR_NO_HANDLES - if there are no valid printers
-
See Also:
-
Device.dispose()
getPrinterList
public static
PrinterData[] getPrinterList()
- Returns an array of
PrinterData objects
representing all available printers. If there are no
printers, the array will be empty.
-
-
Returns:
- an array of PrinterData objects representing the available printers
getDefaultPrinterData
public static
PrinterData getDefaultPrinterData()
- Returns a
PrinterData object representing
the default printer or null if there is no
default printer.
-
-
Returns:
- the default printer data or null
-
Since:
- 2.1
create
protected void create(
DeviceData deviceData)
- Creates the printer handle.
This method is called internally by the instance creation
mechanism of the
Device class.
-
-
Overrides:
-
create
in class
Device
-
-
Parameters:
-
deviceData - the device data -
See Also:
-
Device.init()
internal_new_GC
public int internal_new_GC(
GCData data)
- Invokes platform specific functionality to allocate a new GC handle.
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.
-
-
Specified by:
-
internal_new_GC
in interface
Drawable
-
Specified by:
-
internal_new_GC
in class
Device
-
-
Parameters:
-
data - the platform specific GC data
-
Returns:
- the platform specific GC handle
internal_dispose_GC
public void internal_dispose_GC(int hDC,
GCData data)
- Invokes platform specific functionality to dispose a GC handle.
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.
-
-
Specified by:
-
internal_dispose_GC
in interface
Drawable
-
Specified by:
-
internal_dispose_GC
in class
Device
-
-
Parameters:
-
hDC - the platform specific GC handle -
data - the platform specific GC data
startJob
public boolean startJob(
String jobName)
- Starts a print job and returns true if the job started successfully
and false otherwise.
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.
-
-
Parameters:
-
jobName - the name of the print job to start
-
Returns:
- true if the job started successfully and false otherwise.
-
Throws:
-
SWTException
-
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
-
See Also:
-
startPage() ,
endPage() ,
endJob()
endJob
public void endJob()
- Ends the current print job.
-
-
Throws:
-
SWTException
-
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
-
See Also:
-
startJob(java.lang.String) ,
startPage() ,
endPage()
cancelJob
public void cancelJob()
- Cancels a print job in progress.
-
-
Throws:
-
SWTException
-
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
startPage
public boolean startPage()
- Starts a page and returns true if the page started successfully
and false otherwise.
After calling startJob, this method may be called any number of times
along with a matching endPage.
-
-
Returns:
- true if the page started successfully and false otherwise.
-
Throws:
-
SWTException
-
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
-
See Also:
-
endPage() ,
startJob(java.lang.String) ,
endJob()
endPage
public void endPage()
- Ends the current page.
-
-
Throws:
-
SWTException
-
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
-
See Also:
-
startPage() ,
startJob(java.lang.String) ,
endJob()
getDPI
public
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.
-
-
Overrides:
-
getDPI
in class
Device
-
-
Returns:
- the horizontal and vertical DPI
-
Throws:
-
SWTException
-
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
getBounds
public
Rectangle getBounds()
- Returns a rectangle describing the receiver's size and location.
For a printer, this is the size of the physical page, in pixels.
-
-
Overrides:
-
getBounds
in class
Device
-
-
Returns:
- the bounding rectangle
-
Throws:
-
SWTException
-
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
-
See Also:
-
getClientArea() ,
computeTrim(int, int, int, int)
getClientArea
public
Rectangle getClientArea()
- Returns a rectangle which describes the area of the
receiver which is capable of displaying data.
For a printer, this is the size of the printable area
of the page, in pixels.
-
-
Overrides:
-
getClientArea
in class
Device
-
-
Returns:
- the client area
-
Throws:
-
SWTException
-
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
-
See Also:
-
getBounds() ,
computeTrim(int, int, int, int)
computeTrim
public
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).
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:
- The left trim width is -x pixels
- The top trim height is -y pixels
- The right trim width is (x + width) pixels
- The bottom trim height is (y + height) pixels
-
-
Parameters:
-
x - the x coordinate of the client area -
y - the y coordinate of the client area -
width - the width of the client area -
height - the height of the client area
-
Returns:
- a rectangle, relative to the client area's coordinates, that is
the client area expanded by the printer's trim (or minimum margins)
-
Throws:
-
SWTException
-
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
-
See Also:
-
getBounds() ,
getClientArea()
getPrinterData
public
PrinterData getPrinterData()
- Returns a
PrinterData object representing the
target printer for this print job.
-
-
Returns:
- a PrinterData object describing the receiver
checkDevice
protected void checkDevice()
- Checks the validity of this device.
-
-
Overrides:
-
checkDevice
in class
Device
-
-
Throws:
-
SWTException
-
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed
release
protected void release()
- Releases any internal state prior to destroying this printer.
This method is called internally by the dispose
mechanism of the
Device class.
-
-
Overrides:
-
release
in class
Device
-
-
See Also:
-
Device.dispose() ,
Device.destroy()
destroy
protected void destroy()
- Destroys the printer handle.
This method is called internally by the dispose
mechanism of the
Device class.
-
-
Overrides:
-
destroy
in class
Device
-
-
See Also:
-
Device.dispose() ,
Device.release()
Guidelines for using Eclipse APIs.
Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.
|
|
|