public abstract class

RasterPrinterJob

extends PrinterJob
java.lang.Object
   ↳ java.awt.print.PrinterJob
     ↳ sun.print.RasterPrinterJob
Known Direct Subclasses

Class Overview

A class which rasterizes a printer job.

Summary

Constants
int FILE
int PRINTER
int STREAM
Fields
protected PrintRequestAttributeSet attributes attributes used by no-args page and print dialog and print method to communicate state
protected boolean collateAttReq
public static boolean debugPrint
protected String destinationAttr
public static boolean forcePDL values obtained from System properties in static initialiser block
public static boolean forceRaster
protected boolean landscapeRotates270 Device rotation flag, if it support 270, this is set to true;
protected int mDestType
protected String mDestination
protected PrintService myService Service for this job
protected boolean noJobSheet
public static boolean shapeTextProp
protected Sides sidesAttr
Public Constructors
RasterPrinterJob()
Public Methods
void cancel()
If a print job is in progress, print() has been called but has not returned, then this signals that the job should be cancelled and the next chance.
boolean checkAllowedToPrintToFile()
User dialogs should disable "File" buttons if this returns false.
PageFormat defaultPage(PageFormat page)
The passed in PageFormat will be copied and altered to describe the default page size and orientation of the PrinterJob's current printer.
int getCopies()
Get the number of copies to be printed.
String getJobName()
Get the name of the document to be printed.
PrintService getPrintService()
Returns the service (printer) for this printer job.
String getUserName()
Get the name of the printing user.
boolean isCancelled()
Returns true is a print job is ongoing but will be cancelled and the next opportunity.
PageFormat pageDialog(PrintRequestAttributeSet attributes)
return a PageFormat corresponding to the updated attributes, or null if the user cancelled the dialog.
PageFormat pageDialog(PageFormat page)
Display a dialog to the user allowing the modification of a PageFormat instance.
void print()
Prints a set of pages.
void print(PrintRequestAttributeSet attributes)
Prints a set of pages using the settings in the attribute set.
boolean printDialog(PrintRequestAttributeSet attributes)
Presents the user a dialog for changing properties of the print job interactively.
boolean printDialog()
Presents the user a dialog for changing properties of the print job interactively.
void saveState(AffineTransform at, Shape clip, Rectangle2D region, double sx, double sy)
save graphics state of a PathGraphics for later redrawing of part of page represented by the region in that state
void setCopies(int copies)
Set the number of copies to be printed.
void setJobName(String jobName)
Set the name of the document to be printed.
void setPageable(Pageable document)
The pages in the document to be printed are held by the Pageable instance 'document'.
void setPrintService(PrintService service)
Associate this PrinterJob with a new PrintService.
void setPrintable(Printable painter)
The pages in the document to be printed by this PrinterJob are drawn by the Printable object 'painter'.
void setPrintable(Printable painter, PageFormat format)
The pages in the document to be printed by this PrinterJob are drawn by the Printable object 'painter'.
PageFormat validatePage(PageFormat page)
The passed in PageFormat is cloned and altered to be usable on the PrinterJob's current printer.
Protected Methods
abstract void abortDoc()
Graphics2D createPathGraphics(PeekGraphics graphics, PrinterJob printerJob, Printable painter, PageFormat pageFormat, int pageIndex)
Examine the metrics captured by the PeekGraphics instance and if capable of directly converting this print job to the printer's control language or the native OS's graphics primitives, then return a PathGraphics to perform that conversion.
PeekGraphics createPeekGraphics(Graphics2D graphics, PrinterJob printerJob)
Create and return an object that will gather and hold metrics about the print job.
void debug_println(String str)
abstract void endDoc()
Called by the print() method at the end of a print job.
abstract void endPage(PageFormat format, Printable painter, int index)
End a page.
int getCollatedCopies()
Returns how many times the entire book should be printed by the PrintJob.
int getCopiesInt()
int getFirstPage()
Return the zero based index of the first page to be printed in this job.
String getJobNameInt()
int getLastPage()
Return the zero based index of the last page to be printed in this job.
int getNoncollatedCopies()
Returns how many times each page in the book should be consecutively printed by PrintJob.
Pageable getPageable()
Return the Pageable describing the pages to be printed.
abstract double getPhysicalPageHeight(Paper p)
Must be obtained from the current printer.
abstract double getPhysicalPageWidth(Paper p)
Must be obtained from the current printer.
abstract double getPhysicalPrintableHeight(Paper p)
Must be obtained from the current printer.
abstract double getPhysicalPrintableWidth(Paper p)
Must be obtained from the current printer.
abstract double getPhysicalPrintableX(Paper p)
Must be obtained from the current printer.
abstract double getPhysicalPrintableY(Paper p)
Must be obtained from the current printer.
String getUserNameInt()
abstract double getXRes()
Returns the resolution in dots per inch across the width of the page.
abstract double getYRes()
Returns the resolution in dots per inch down the height of the page.
void initPrinter()
boolean isCollated()
Return true if collated copies will be printed as determined in an attribute set.
boolean isSupportedValue(Attribute attrval, PrintRequestAttributeSet attrset)
static PrintService lookupDefaultPrintService()
abstract void printBand(byte[] data, int x, int y, int width, int height)
Prints the contents of the array of ints, 'data' to the current page.
int printPage(Pageable document, int pageIndex)
Print a page from the provided document.
String removeControlChars(String s)
void setAttributes(PrintRequestAttributeSet attributes)
void setCollated(boolean collate)
Set whether copies should be collated or not.
void setPageRange(int firstPage, int lastPage)
Set the range of pages from a Book to be printed.
abstract void startDoc()
Called by the print() method at the start of a print job.
abstract void startPage(PageFormat format, Printable painter, int index, boolean paperChanged)
Begin a new page.
void updatePageAttributes(PrintService service, PageFormat page)
void validatePaper(Paper origPaper, Paper newPaper)
updates a Paper object to reflect the current printer's selected paper size and imageable area for that paper size.
[Expand]
Inherited Methods
From class java.awt.print.PrinterJob
From class java.lang.Object

Constants

protected static final int FILE

Constant Value: 1 (0x00000001)

protected static final int PRINTER

Constant Value: 0 (0x00000000)

protected static final int STREAM

Constant Value: 2 (0x00000002)

Fields

protected PrintRequestAttributeSet attributes

attributes used by no-args page and print dialog and print method to communicate state

protected boolean collateAttReq

public static boolean debugPrint

protected String destinationAttr

public static boolean forcePDL

values obtained from System properties in static initialiser block

public static boolean forceRaster

protected boolean landscapeRotates270

Device rotation flag, if it support 270, this is set to true;

protected int mDestType

protected String mDestination

protected PrintService myService

Service for this job

protected boolean noJobSheet

public static boolean shapeTextProp

protected Sides sidesAttr

Public Constructors

public RasterPrinterJob ()

Public Methods

public void cancel ()

If a print job is in progress, print() has been called but has not returned, then this signals that the job should be cancelled and the next chance. If there is no print job in progress then this call does nothing.

public boolean checkAllowedToPrintToFile ()

User dialogs should disable "File" buttons if this returns false.

public PageFormat defaultPage (PageFormat page)

The passed in PageFormat will be copied and altered to describe the default page size and orientation of the PrinterJob's current printer. Platform subclasses which can access the actual default paper size for a printer may override this method.

Parameters
page the PageFormat to be cloned and altered
Returns
  • clone of page, altered to describe a default PageFormat.

public int getCopies ()

Get the number of copies to be printed.

Returns
  • the number of copies to be printed.

public String getJobName ()

Get the name of the document to be printed.

Returns
  • the name of the document to be printed.

public PrintService getPrintService ()

Returns the service (printer) for this printer job. Implementations of this class which do not support print services may return null;

Returns
  • the service for this printer job.

public String getUserName ()

Get the name of the printing user. The caller must have security permission to read system properties.

Returns
  • the name of the printing user

public boolean isCancelled ()

Returns true is a print job is ongoing but will be cancelled and the next opportunity. false is returned otherwise.

Returns
  • true if the job in progress is going to be cancelled; false otherwise.

public PageFormat pageDialog (PrintRequestAttributeSet attributes)

return a PageFormat corresponding to the updated attributes, or null if the user cancelled the dialog.

Parameters
attributes on input is application supplied attributes, on output the contents are updated to reflect user choices. This parameter may not be null.
Returns
  • a page format if the user does not cancel the dialog; null otherwise.

public PageFormat pageDialog (PageFormat page)

Display a dialog to the user allowing the modification of a PageFormat instance. The page argument is used to initialize controls in the page setup dialog. If the user cancels the dialog, then the method returns the original page object unmodified. If the user okays the dialog then the method returns a new PageFormat object with the indicated changes. In either case the original page object will not be modified.

Parameters
page the default PageFormat presented to the user for modification
Returns
  • the original page object if the dialog is cancelled, or a new PageFormat object containing the format indicated by the user if the dialog is acknowledged
Throws
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
See Also

public void print ()

Prints a set of pages.

Throws
PrinterException an error in the print system caused the job to be aborted

public void print (PrintRequestAttributeSet attributes)

Prints a set of pages using the settings in the attribute set. The default implementation ignores the attribute set.

Note that some attributes may be set directly on the PrinterJob by equivalent method calls, (for example), copies: setcopies(int), job name: setJobName(String) and specifying media size and orientation though the PageFormat object.

If a supported attribute-value is specified in this attribute set, it will take precedence over the API settings for this print() operation only. The following behaviour is specified for PageFormat: If a client uses the Printable interface, then the attributes parameter to this method is examined for attributes which specify media (by size), orientation, and imageable area, and those are used to construct a new PageFormat which is passed to the Printable object's print() method. See Printable for an explanation of the required behaviour of a Printable to ensure optimal printing via PrinterJob. For clients of the Pageable interface, the PageFormat will always be as supplied by that interface, on a per page basis.

These behaviours allow an application to directly pass the user settings returned from printDialog(PrintRequestAttributeSet attributes to this print() method.

Parameters
attributes a set of attributes for the job

public boolean printDialog (PrintRequestAttributeSet attributes)

Presents the user a dialog for changing properties of the print job interactively. The services browsable here are determined by the type of service currently installed. If the application installed a StreamPrintService on this PrinterJob, only the available StreamPrintService (factories) are browsable.

Parameters
attributes to store changed properties.
Returns
  • false if the user cancels the dialog and true otherwise.
Throws
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
See Also

public boolean printDialog ()

Presents the user a dialog for changing properties of the print job interactively.

Returns
  • true if the user does not cancel the dialog; false otherwise.
Throws
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
See Also

public void saveState (AffineTransform at, Shape clip, Rectangle2D region, double sx, double sy)

save graphics state of a PathGraphics for later redrawing of part of page represented by the region in that state

public void setCopies (int copies)

Set the number of copies to be printed.

Parameters
copies the number of copies to be printed

public void setJobName (String jobName)

Set the name of the document to be printed. The document name can not be null.

Parameters
jobName the name of the document to be printed

public void setPageable (Pageable document)

The pages in the document to be printed are held by the Pageable instance 'document'. 'document' will be queried for the number of pages as well as the PageFormat and Printable for each page.

Parameters
document the pages to be printed. It can not be null.
Throws
NullPointerException the Pageable passed in was null.

public void setPrintService (PrintService service)

Associate this PrinterJob with a new PrintService. Throws PrinterException if the specified service cannot support the Pageable and Printable interfaces necessary to support 2D printing.

Parameters
service a print service that supports 2D printing
Throws
PrinterException if the specified service does not support 2D printing or no longer available.

public void setPrintable (Printable painter)

The pages in the document to be printed by this PrinterJob are drawn by the Printable object 'painter'. The PageFormat for each page is the default page format.

Parameters
painter the Printable that renders each page of the document.

public void setPrintable (Printable painter, PageFormat format)

The pages in the document to be printed by this PrinterJob are drawn by the Printable object 'painter'. The PageFormat of each page is 'format'.

Parameters
painter the Printable called to render each page of the document
format the size and orientation of each page to be printed

public PageFormat validatePage (PageFormat page)

The passed in PageFormat is cloned and altered to be usable on the PrinterJob's current printer.

Parameters
page the PageFormat that is cloned and whose settings are changed to be compatible with the current printer
Returns
  • a PageFormat that is cloned from page and whose settings are changed to conform with this PrinterJob.

Protected Methods

protected abstract void abortDoc ()

protected Graphics2D createPathGraphics (PeekGraphics graphics, PrinterJob printerJob, Printable painter, PageFormat pageFormat, int pageIndex)

Examine the metrics captured by the PeekGraphics instance and if capable of directly converting this print job to the printer's control language or the native OS's graphics primitives, then return a PathGraphics to perform that conversion. If there is not an object capable of the conversion then return null. Returning null causes the print job to be rasterized.

protected PeekGraphics createPeekGraphics (Graphics2D graphics, PrinterJob printerJob)

Create and return an object that will gather and hold metrics about the print job. This method is passed a Graphics2D object that can be used as a proxy for the object gathering the print job matrics. The method is also supplied with the instance controlling the print job, printerJob.

protected void debug_println (String str)

protected abstract void endDoc ()

Called by the print() method at the end of a print job.

protected abstract void endPage (PageFormat format, Printable painter, int index)

End a page.

protected int getCollatedCopies ()

Returns how many times the entire book should be printed by the PrintJob. If the printer itself supports collation then this method should return 1 indicating that the entire book need only be printed once and the copies will be collated and made in the printer.

protected int getCopiesInt ()

protected int getFirstPage ()

Return the zero based index of the first page to be printed in this job.

protected String getJobNameInt ()

protected int getLastPage ()

Return the zero based index of the last page to be printed in this job.

protected int getNoncollatedCopies ()

Returns how many times each page in the book should be consecutively printed by PrintJob. If the printer makes copies itself then this method should return 1.

protected Pageable getPageable ()

Return the Pageable describing the pages to be printed.

protected abstract double getPhysicalPageHeight (Paper p)

Must be obtained from the current printer. Value is in device pixels. Not adjusted for orientation of the paper.

protected abstract double getPhysicalPageWidth (Paper p)

Must be obtained from the current printer. Value is in device pixels. Not adjusted for orientation of the paper.

protected abstract double getPhysicalPrintableHeight (Paper p)

Must be obtained from the current printer. Value is in device pixels. Not adjusted for orientation of the paper.

protected abstract double getPhysicalPrintableWidth (Paper p)

Must be obtained from the current printer. Value is in device pixels. Not adjusted for orientation of the paper.

protected abstract double getPhysicalPrintableX (Paper p)

Must be obtained from the current printer. Value is in device pixels. Not adjusted for orientation of the paper.

protected abstract double getPhysicalPrintableY (Paper p)

Must be obtained from the current printer. Value is in device pixels. Not adjusted for orientation of the paper.

protected String getUserNameInt ()

protected abstract double getXRes ()

Returns the resolution in dots per inch across the width of the page.

protected abstract double getYRes ()

Returns the resolution in dots per inch down the height of the page.

protected void initPrinter ()

protected boolean isCollated ()

Return true if collated copies will be printed as determined in an attribute set.

protected boolean isSupportedValue (Attribute attrval, PrintRequestAttributeSet attrset)

protected static PrintService lookupDefaultPrintService ()

protected abstract void printBand (byte[] data, int x, int y, int width, int height)

Prints the contents of the array of ints, 'data' to the current page. The band is placed at the location (x, y) in device coordinates on the page. The width and height of the band is specified by the caller.

protected int printPage (Pageable document, int pageIndex)

Print a page from the provided document.

Returns
  • int Printable.PAGE_EXISTS if the page existed and was drawn and Printable.NO_SUCH_PAGE if the page did not exist.
See Also

protected String removeControlChars (String s)

protected void setAttributes (PrintRequestAttributeSet attributes)

protected void setCollated (boolean collate)

Set whether copies should be collated or not. Two collated copies of a three page document print in this order: 1, 2, 3, 1, 2, 3 while uncollated copies print in this order: 1, 1, 2, 2, 3, 3. This is set when request is using an attribute set.

protected void setPageRange (int firstPage, int lastPage)

Set the range of pages from a Book to be printed. Both 'firstPage' and 'lastPage' are zero based page indices. If either parameter is less than zero then the page range is set to be from the first page to the last.

protected abstract void startDoc ()

Called by the print() method at the start of a print job.

protected abstract void startPage (PageFormat format, Printable painter, int index, boolean paperChanged)

Begin a new page.

protected void updatePageAttributes (PrintService service, PageFormat page)

protected void validatePaper (Paper origPaper, Paper newPaper)

updates a Paper object to reflect the current printer's selected paper size and imageable area for that paper size. Default implementation copies settings from the original, applies applies some validity checks, changes them only if they are clearly unreasonable, then sets them into the new Paper. Subclasses are expected to override this method to make more informed decisons.