modules/graphics/src/main/java/javafx/print/PrinterJob.java

Print this page
rev 8895 : RT-39689: Better docs and error checking if Printing or Dialogs called from Animation


 264      * These changes will be available in the appropriate properties
 265      * after the print dialog has returned.
 266      * The print dialog is also typically used to confirm the user
 267      * wants to proceed with printing. This is not binding on the
 268      * application but generally should be obeyed.
 269      * <p>
 270      * In the case that there is no UI available then this method
 271      * returns true, with no options changed, as if the user had
 272      * confirmed to proceed with printing.
 273      * <p>
 274      * If the job is not in a state to display the dialog, such
 275      * as already printing, cancelled or done, then the dialog will
 276      * not be displayed and the method will return false.
 277      * <p>
 278      * The window <code>owner</code> may be null, but
 279      * if it is a visible Window, it will be used as the parent.
 280      * @param owner to which to block input, or null.
 281      * @return false if the user opts to cancel printing, or the job
 282      * is not in the new state. That is if it has already started,
 283      * has failed, or has been cancelled, or ended.



 284      */
 285     public synchronized boolean showPrintDialog(Window owner) {
 286         // TBD handle owner
 287         if (!isJobNew()) {
 288             return false;
 289         } else {
 290             return jobImpl.showPrintDialog(owner);
 291         }
 292     }
 293 
 294     /**
 295      * Displays a Page Setup dialog.
 296      * A page set up dialog is primarily to allow an end user
 297      * to configure the layout of a page. Paper size and orientation
 298      * are the most common and most important components of this.
 299      * <p>
 300      * This will display the most appropriate available dialog for
 301      * this purpose.
 302      * However there may be still be access to other settings,
 303      * including changing the current printer.
 304      * Therefore a side effect of this dialog display method may be to
 305      * update that and any other current job settings.
 306      * The method returns true if the user confirmed the dialog whether or
 307      * not any changes are made.
 308      * <p>
 309      * If the job is not in a state to display the dialog, such
 310      * as already printing, cancelled or done, then the dialog will
 311      * not be displayed and the method will return false.
 312      * <p>
 313      * The window <code>owner</code> may be null, but
 314      * if it is a visible Window, it will be used as the parent.
 315      * @param owner to block input, or null.
 316      * @return false if the user opts to cancel the dialog, or the job
 317      * is not in the new state. That is if it has already started,
 318      * has failed, or has been cancelled, or ended.



 319      */
 320     public synchronized boolean showPageSetupDialog(Window owner) {
 321         // TBD handle owner
 322         if (!isJobNew()) {
 323             return false;
 324         } else {
 325             return jobImpl.showPageDialog(owner);
 326         }
 327     }
 328 
 329     /**
 330      * This method can be used to check if a page configuration
 331      * is possible in the current job configuration. For example
 332      * if the specified paper size is supported. If the original
 333      * PageLayout is supported it will be returned. If not, a new PageLayout
 334      * will be returned that attempts to honour the supplied
 335      * PageLayout, but adjusted to match the current job configuration.
 336      * <p>
 337      * This method does not update the job configuration.
 338      * @param pageLayout to be validated
 339      * @return a <code>PageLayout</code> that is supported in the
 340      * current job configuration.
 341      * @throws NullPointerException if the pageLayout parameter is null.
 342      */
 343     synchronized PageLayout validatePageLayout(PageLayout pageLayout) {
 344         if (pageLayout == null) {
 345             throw new NullPointerException("pageLayout cannot be null");
 346         }
 347         return jobImpl.validatePageLayout(pageLayout);
 348     }
 349 
 350     /**
 351      * Print the specified node using the specified page layout.
 352      * The page layout will override the job default for this page only.
 353      * If the job state is CANCELED, ERROR or DONE, this method will
 354      * return false.
 355      * @param pageLayout Layout for this page.
 356      * @param node The node to print.
 357      * @return whether rendering was successful.
 358      * @throws NullPointerException if either parameter is null.



 359      */
 360     public synchronized boolean printPage(PageLayout pageLayout, Node node) {
 361         if (jobStatus.get().ordinal() > JobStatus.PRINTING.ordinal()) {
 362             return false;
 363         }
 364         if (jobStatus.get() == JobStatus.NOT_STARTED) {
 365             jobStatus.set(JobStatus.PRINTING);
 366         }
 367         if (pageLayout == null || node == null) {
 368             jobStatus.set(JobStatus.ERROR);
 369             throw new NullPointerException("Parameters cannot be null");
 370         }
 371         boolean rv = jobImpl.print(pageLayout, node);
 372         if (!rv) {
 373             jobStatus.set(JobStatus.ERROR);
 374         }
 375         return rv;
 376     }
 377 
 378      /**




 264      * These changes will be available in the appropriate properties
 265      * after the print dialog has returned.
 266      * The print dialog is also typically used to confirm the user
 267      * wants to proceed with printing. This is not binding on the
 268      * application but generally should be obeyed.
 269      * <p>
 270      * In the case that there is no UI available then this method
 271      * returns true, with no options changed, as if the user had
 272      * confirmed to proceed with printing.
 273      * <p>
 274      * If the job is not in a state to display the dialog, such
 275      * as already printing, cancelled or done, then the dialog will
 276      * not be displayed and the method will return false.
 277      * <p>
 278      * The window <code>owner</code> may be null, but
 279      * if it is a visible Window, it will be used as the parent.
 280      * @param owner to which to block input, or null.
 281      * @return false if the user opts to cancel printing, or the job
 282      * is not in the new state. That is if it has already started,
 283      * has failed, or has been cancelled, or ended.
 284      * @throws IllegalStateException if this is called on the FX application
 285      * thread, outside of an event handler. This includes animation callbacks,
 286      * properties handlers and layout processing.
 287      */
 288     public synchronized boolean showPrintDialog(Window owner) {
 289         // TBD handle owner
 290         if (!isJobNew()) {
 291             return false;
 292         } else {
 293             return jobImpl.showPrintDialog(owner);
 294         }
 295     }
 296 
 297     /**
 298      * Displays a Page Setup dialog.
 299      * A page set up dialog is primarily to allow an end user
 300      * to configure the layout of a page. Paper size and orientation
 301      * are the most common and most important components of this.
 302      * <p>
 303      * This will display the most appropriate available dialog for
 304      * this purpose.
 305      * However there may be still be access to other settings,
 306      * including changing the current printer.
 307      * Therefore a side effect of this dialog display method may be to
 308      * update that and any other current job settings.
 309      * The method returns true if the user confirmed the dialog whether or
 310      * not any changes are made.
 311      * <p>
 312      * If the job is not in a state to display the dialog, such
 313      * as already printing, cancelled or done, then the dialog will
 314      * not be displayed and the method will return false.
 315      * <p>
 316      * The window <code>owner</code> may be null, but
 317      * if it is a visible Window, it will be used as the parent.
 318      * @param owner to block input, or null.
 319      * @return false if the user opts to cancel the dialog, or the job
 320      * is not in the new state. That is if it has already started,
 321      * has failed, or has been cancelled, or ended.
 322      * @throws IllegalStateException if this is called on the FX application
 323      * thread, outside of an event handler. This includes animation callbacks,
 324      * properties handlers and layout processing.
 325      */
 326     public synchronized boolean showPageSetupDialog(Window owner) {
 327         // TBD handle owner
 328         if (!isJobNew()) {
 329             return false;
 330         } else {
 331             return jobImpl.showPageDialog(owner);
 332         }
 333     }
 334 
 335     /**
 336      * This method can be used to check if a page configuration
 337      * is possible in the current job configuration. For example
 338      * if the specified paper size is supported. If the original
 339      * PageLayout is supported it will be returned. If not, a new PageLayout
 340      * will be returned that attempts to honour the supplied
 341      * PageLayout, but adjusted to match the current job configuration.
 342      * <p>
 343      * This method does not update the job configuration.
 344      * @param pageLayout to be validated
 345      * @return a <code>PageLayout</code> that is supported in the
 346      * current job configuration.
 347      * @throws NullPointerException if the pageLayout parameter is null.
 348      */
 349     synchronized PageLayout validatePageLayout(PageLayout pageLayout) {
 350         if (pageLayout == null) {
 351             throw new NullPointerException("pageLayout cannot be null");
 352         }
 353         return jobImpl.validatePageLayout(pageLayout);
 354     }
 355 
 356     /**
 357      * Print the specified node using the specified page layout.
 358      * The page layout will override the job default for this page only.
 359      * If the job state is CANCELED, ERROR or DONE, this method will
 360      * return false.
 361      * @param pageLayout Layout for this page.
 362      * @param node The node to print.
 363      * @return whether rendering was successful.
 364      * @throws NullPointerException if either parameter is null.
 365      * @throws IllegalStateException if this is called on the FX application
 366      * thread, outside of an event handler. This includes animation callbacks,
 367      * properties handlers and layout processing.
 368      */
 369     public synchronized boolean printPage(PageLayout pageLayout, Node node) {
 370         if (jobStatus.get().ordinal() > JobStatus.PRINTING.ordinal()) {
 371             return false;
 372         }
 373         if (jobStatus.get() == JobStatus.NOT_STARTED) {
 374             jobStatus.set(JobStatus.PRINTING);
 375         }
 376         if (pageLayout == null || node == null) {
 377             jobStatus.set(JobStatus.ERROR);
 378             throw new NullPointerException("Parameters cannot be null");
 379         }
 380         boolean rv = jobImpl.print(pageLayout, node);
 381         if (!rv) {
 382             jobStatus.set(JobStatus.ERROR);
 383         }
 384         return rv;
 385     }
 386 
 387      /**