public final class PrinterJob extends PrinterJobObject implements ISurface
globalFontManager, outputCanChangeMediaOrientation, printerControl, printerSelected
IMAGE_SURFACE, PRINTERJOB_SURFACE, WINDOW_SURFACE
Constructor and Description |
---|
PrinterJob() |
Modifier and Type | Method and Description |
---|---|
boolean |
canCapture()
This returns true if it is possible to read pixel data from the surface
into an Image.
|
protected void |
cancelCurrentPage(Handle h) |
boolean |
canMove()
This returns true if it is possible to move pixel within the surface.
|
boolean |
captureImage(Image dest,
int x,
int y,
int width,
int height)
Capture pixel data from the surface to an Image.
|
void |
drawImage(Image src,
int clipX,
int clipY,
int clipWidth,
int clipHeight,
int destX,
int destY,
int width,
int height)
This should always work for any surface and is the minimum functionality
expected.
|
protected boolean |
endPrinting(Handle h) |
Image |
getCompatibleImage(int width,
int height)
Get an Image that is optimized for display on the surface.
|
static String |
getDefaultPrinter(StringBuffer descriptiveName)
Get the name of the default printer.
|
FontMetrics |
getFontMetrics(Font f)
Return a FontMetrics for the surface.
|
Graphics |
getGraphics()
This returns a new Graphics for use on the surface IF it is supported.
|
Object |
getNativeDrawable()
This is used internally and should not be used.
|
static PrinterJob |
getPrinterJob(String printerName)
Get a new PrinterJob object.
|
static PrinterJob |
getPrinterJob(String printerName,
PrinterProperties properties)
Get a new PrinterJob object.
|
static String[] |
getPrinterNames(Vector descriptiveNames)
Get a list of all available printers which can be used with getPrinterJob()
to get a PrinetJob for a specific printer.
|
static PrinterProperties |
getPrinterProperties(PrinterProperties pl)
Get the PrinterProperties for the local machine.
|
protected Task |
getPrintTask(Printable toPrint,
PageFormat format,
PrintOptions options)
This starts the printing process going.
|
int |
getSurfaceType()
This returns one of the XXX_SURFACE values.
|
static boolean |
hasNativeDialog()
Returns true if the system supports a native dialog box.
|
boolean |
moveImage(int srcX,
int srcY,
int srcWidth,
int srcHeight,
int destX,
int destY)
Move pixel data within the surface.
|
protected PointGraphics |
newPage(Handle h,
PageFormat format) |
protected boolean |
printCurrentPage(Handle h) |
Handle |
printDialog(WindowSurface parent)
This displays the printer select/setup dialog box.
|
static Handle |
printerDialog(PrinterProperties pl)
This attempts to create and run a non-native printer dialog.
|
protected boolean |
startPrinting(Handle h,
String documentName) |
cancel, getCompatibleImagePoints, getCurrentPrintingHandle, getDPI, getPointDocument, isPrinting, lockIfNotPrinting, print, print, printerWasSelected, printingComplete, setPrinterProperties
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCompatibleImagePoints, getDPI
public static boolean hasNativeDialog()
public static String[] getPrinterNames(Vector descriptiveNames)
descriptiveNames
- if this is not null then a descriptive
name for each printer will be placed in the vector in the same
order as the names of the printers. If there is no descriptive name
then the printer device name is used instead.public static String getDefaultPrinter(StringBuffer descriptiveName)
descriptiveName
- if this is not null then a descriptive
name for the printer is appended to the StringBuffer.
If no descriptive name exists the printer device name (the same
one returned) is used.public static PrinterProperties getPrinterProperties(PrinterProperties pl)
pl
- a destination PrinterProperties object, or null to
create and return a new one.public static Handle printerDialog(PrinterProperties pl)
pl
- a PrinterProperties returned by getPrinterProperties().public static PrinterJob getPrinterJob(String printerName) throws IOException
printerName
- an optional printer name. This can be null for the default printer.
Note that if printDialog() is called on the PrinterJob then the
name of the selected printer may be changed.IOException
- if the job could not be created.public static PrinterJob getPrinterJob(String printerName, PrinterProperties properties) throws IOException
printerName
- an optional printer name. This can be null for the default printer.
Note that if printDialog() is called on the PrinterJob then the
name of the selected printer may be changed.properties
- and optional PrinterProperties that holds input and
output properties. To set the printer parameters (e.g. duplex printing, print quality, etc.)
use setPrinterControl() on the PrinterProperties object to pass these
parameters in a PrinterControl object. After the method returns the
PrinterControl object will be updated to reflect the actual parameters
used by the printer.IOException
- if the job could not be created.public Handle printDialog(WindowSurface parent)
Because the box may be brought up on creation on some systems, but not others the correct way to ensure that it is brought up once only is:
PrinterJob pj = PrinterJob.getPrinterJob(); if (pj != null) if (pj.printDialog(false)) pj.print(myPrinter,null);
printDialog
in interface Printer
parent
- The parent WindowSurface - which can be null.protected Task getPrintTask(Printable toPrint, PageFormat format, PrintOptions options)
getPrintTask
in class PrinterJobObject
public int getSurfaceType()
ISurface
getSurfaceType
in interface ISurface
public FontMetrics getFontMetrics(Font f)
ISurface
getFontMetrics
in interface ISurface
f
- the Font to use.public Graphics getGraphics()
ISurface
getGraphics
in interface ISurface
public Object getNativeDrawable()
ISurface
getNativeDrawable
in interface ISurface
protected boolean startPrinting(Handle h, String documentName)
startPrinting
in class PrinterJobObject
protected PointGraphics newPage(Handle h, PageFormat format)
newPage
in class PrinterJobObject
protected boolean printCurrentPage(Handle h)
printCurrentPage
in class PrinterJobObject
protected void cancelCurrentPage(Handle h)
cancelCurrentPage
in class PrinterJobObject
protected boolean endPrinting(Handle h)
endPrinting
in class PrinterJobObject
public void drawImage(Image src, int clipX, int clipY, int clipWidth, int clipHeight, int destX, int destY, int width, int height)
ISurface
Note that the image is not scaled. If width and height are smaller than the actual image dimensions, then the image is clipped.
drawImage
in interface ISurface
src
- The source image.clipX
- The x co-ordinate of the clipping rectangle within the surface.clipY
- The y co-ordinate of the clipping rectangle within the surface.clipWidth
- The width of the clipping rectangle within the surface.clipHeight
- The height of the clipping rectangle within the surface.destX
- The destination x co-ordinate for the image.destY
- The destination y co-ordinate for the image.width
- The number of pixels horizontally to draw from the image.height
- The number of pixels vertically to draw from the image.public boolean captureImage(Image dest, int x, int y, int width, int height)
ISurface
captureImage
in interface ISurface
public boolean moveImage(int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY)
ISurface
public boolean canCapture()
ISurface
canCapture
in interface ISurface
public boolean canMove()
ISurface
public Image getCompatibleImage(int width, int height) throws IllegalArgumentException
ISurface
getCompatibleImage
in interface ISurface
width
- the width of the image. This must be greater than or equal to 1.height
- the height of the image. This must be greater than or equal to 1.IllegalArgumentException
- if the width or height is less than 1.