PrinterJob
class is the principal class that controls
printing. An application calls methods in this class to set up a job,
optionally to invoke a print dialog with the user, and then to print
the pages of the job.PrinterJob
object should be created using the
static getPrinterJob
method.PageFormat
instance and
sets it to a default size and orientation.PageFormat
argument and alters the
clone to describe a default page size and orientation.
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y) consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.
PrinterJob
which is initially
associated with the default printer.
If no printers are available on the system, a PrinterJob will still
be returned from this method, but getPrintService()
will return null
, and calling
print
with this PrinterJob
might
generate an exception. Applications that need to determine if
there are suitable printers before creating a PrinterJob
should ensure that the array returned from
lookupPrintServices
is not empty.java.util.Hashtable
.
The general contract of hashCode
is:
hashCode
method on each of
the two objects must produce the same integer result.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
true
if a print job is
in progress, but is going to be cancelled
at the next opportunity; otherwise returns
false
.PrinterJob
s which support print services.
Calling this method is equivalent to calling
PrintServiceLookup.lookupPrintServices()
and specifying a Pageable DocFlavor.FileOutputStream outstream; StreamPrintService psPrinter; String psMimeType = "application/postscript"; StreamPrintServiceFactory[] factories = PrinterJob.lookupStreamPrintServices(psMimeType); if (factories.length > 0) { try { outstream = new File("out.ps"); psPrinter = factories[0].getPrintService(fos); // psPrinter can now be set as the service on a PrinterJob } catch (FileNotFoundException e) { } }Services returned from this method may be installed on
PrinterJob
instances which support print services.
Calling this method is equivalent to calling
StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
and specifying a Pageable DocFlavor.wait
methods.
The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:
synchronized
statement
that synchronizes on the object.
Class,
by executing a
synchronized static method of that class.
Only one thread at a time can own an object's monitor.
wait
methods.
The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
PageFormat
instance.
The page
argument is used to initialize controls
in the page setup dialog.
If the user cancels the dialog then this method returns the
original page
object unmodified.
If the user okays the dialog then this method returns a new
PageFormat
object with the indicated changes.
In either case, the original page
object is
not modified.The attributes parameter on input will reflect the client's required initial selections in the user dialog. Attributes which are not specified display using the default for the service. On return it will reflect the user's choices. Selections may be updated by the implementation to be consistent with the supported values for the currently selected print service.
The return value will be a PageFormat equivalent to the selections in the PrintRequestAttributeSet. If the user cancels the dialog, the attributes will not reflect any changes made by the user, and the return value will be null.
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.
printDialog(PrintRequestAttributeSet)
.
PrinterJob implementations which can use PrintService's will update the PrintService for this PrinterJob to reflect the new service selected by the user.
Pageable
interface. The selected printer when the
dialog is initially displayed will reflect the print service currently
attached to this print job.
If the user changes the print service, the PrinterJob will be
updated to reflect this, unless the user cancels the dialog.
As well as allowing the user to select the destination printer,
the user can also select values of various print request attributes.
The attributes parameter on input will reflect the applications required initial selections in the user dialog. Attributes not specified display using the default for the service. On return it will reflect the user's choices. Selections may be updated by the implementation to be consistent with the supported values for the currently selected print service.
As the user scrolls to a new print service selection, the values copied are based on the settings for the previous service, together with any user changes. The values are not based on the original settings supplied by the client.
With the exception of selected printer, the PrinterJob state is
not updated to reflect the user's changes.
For the selections to affect a printer job, the attributes must
be specified in the call to the
print(PrintRequestAttributeSet)
method. If using
the Pageable interface, clients which intend to use media selected
by the user must create a PageFormat derived from the user's
selections.
If the user cancels the dialog, the attributes will not reflect
any changes made by the user.
null
.document
for the number of pages and
the PageFormat
and Printable
for each
page held in the Pageable
instance,
document
.painter
to render the pages. The pages in the
document to be printed by this
PrinterJob
are rendered by the Printable
object, painter
. The PageFormat
for each page
is the default page format.painter
to render the pages in the specified
format
. The pages in the document to be printed by
this PrinterJob
are rendered by the
Printable
object, painter
. The
PageFormat
of each page is format
.PrinterException
if the specified service
cannot support the Pageable
and
Printable
interfaces necessary to support 2D printing.toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
page
with its settings
adjusted to be compatible with the current printer of this
PrinterJob
. For example, the returned
PageFormat
could have its imageable area
adjusted to fit within the physical area of the paper that
is used by the current printer.
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until another thread
notifies threads waiting on this object's monitor to wake up
either through a call to the notify
method or the
notifyAll
method. The thread then waits until it can
re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.The current thread must own this object's monitor.
This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops, like this one:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout); ... // Perform action appropriate to condition }(For more information on this topic, see Section 3.2.3 in Doug Lea's "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or Item 50 in Joshua Bloch's "Effective Java Programming Language Guide" (Addison-Wesley, 2001).
If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.
Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
This method is similar to the wait
method of one
argument, but it allows finer control over the amount of time to
wait for a notification before giving up. The amount of real time,
measured in nanoseconds, is given by:
1000000*timeout+nanos
In all other respects, this method does the same thing as the method of one argument. In particular, wait(0, 0) means the same thing as wait(0).
The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:
notify
method
or the notifyAll
method.
timeout
milliseconds plus nanos
nanoseconds arguments, has
elapsed.
The thread then waits until it can re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout, nanos); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.