481 PrintService[] svcs = PrintServiceLookup.lookupPrintServices(
482 DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
483 if (svcs.length > 0) {
484 try {
485 setPrintService(svcs[0]);
486 myService = svcs[0];
487 } catch (PrinterException e) {
488 }
489 }
490 }
491 }
492 return myService;
493 }
494
495 /**
496 * Associate this PrinterJob with a new PrintService.
497 *
498 * Throws <code>PrinterException</code> if the specified service
499 * cannot support the <code>Pageable</code> and
500 * <code>Printable</code> interfaces necessary to support 2D printing.
501 * @param a print service which supports 2D printing.
502 *
503 * @throws PrinterException if the specified service does not support
504 * 2D printing or no longer available.
505 */
506 public void setPrintService(PrintService service)
507 throws PrinterException {
508 if (service == null) {
509 throw new PrinterException("Service cannot be null");
510 } else if (!(service instanceof StreamPrintService) &&
511 service.getName() == null) {
512 throw new PrinterException("Null PrintService name.");
513 } else {
514 // Check the list of services. This service may have been
515 // deleted already
516 PrinterState prnState = service.getAttribute(PrinterState.class);
517 if (prnState == PrinterState.STOPPED) {
518 PrinterStateReasons prnStateReasons =
519 service.getAttribute(PrinterStateReasons.class);
520 if ((prnStateReasons != null) &&
521 (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
1007 mDestination = (new File(defaultDest.getURI())).getPath();
1008 }
1009 }
1010 }
1011 } else {
1012 mDestType = RasterPrinterJob.PRINTER;
1013 PrintService ps = getPrintService();
1014 if (ps != null) {
1015 mDestination = ps.getName();
1016 }
1017 }
1018 }
1019
1020 return doPrint;
1021 }
1022
1023 /**
1024 * The pages in the document to be printed by this PrinterJob
1025 * are drawn by the Printable object 'painter'. The PageFormat
1026 * for each page is the default page format.
1027 * @param Printable Called to render each page of the document.
1028 */
1029 public void setPrintable(Printable painter) {
1030 setPageable(new OpenBook(defaultPage(new PageFormat()), painter));
1031 }
1032
1033 /**
1034 * The pages in the document to be printed by this PrinterJob
1035 * are drawn by the Printable object 'painter'. The PageFormat
1036 * of each page is 'format'.
1037 * @param Printable Called to render each page of the document.
1038 * @param PageFormat The size and orientation of each page to
1039 * be printed.
1040 */
1041 public void setPrintable(Printable painter, PageFormat format) {
1042 setPageable(new OpenBook(format, painter));
1043 updatePageAttributes(getPrintService(), format);
1044 }
1045
1046 /**
1047 * The pages in the document to be printed are held by the
1048 * Pageable instance 'document'. 'document' will be queried
1049 * for the number of pages as well as the PageFormat and
1050 * Printable for each page.
1051 * @param Pageable The document to be printed. It may not be null.
1052 * @exception NullPointerException the Pageable passed in was null.
1053 * @see PageFormat
1054 * @see Printable
1055 */
1056 public void setPageable(Pageable document) throws NullPointerException {
1057 if (document != null) {
1058 mDocument = document;
1059
1060 } else {
1061 throw new NullPointerException();
1062 }
1063 }
1064
1065 protected void initPrinter() {
1066 return;
1067 }
1068
1069 protected boolean isSupportedValue(Attribute attrval,
1070 PrintRequestAttributeSet attrset) {
1071 PrintService ps = getPrintService();
|
481 PrintService[] svcs = PrintServiceLookup.lookupPrintServices(
482 DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
483 if (svcs.length > 0) {
484 try {
485 setPrintService(svcs[0]);
486 myService = svcs[0];
487 } catch (PrinterException e) {
488 }
489 }
490 }
491 }
492 return myService;
493 }
494
495 /**
496 * Associate this PrinterJob with a new PrintService.
497 *
498 * Throws <code>PrinterException</code> if the specified service
499 * cannot support the <code>Pageable</code> and
500 * <code>Printable</code> interfaces necessary to support 2D printing.
501 * @param service print service which supports 2D printing.
502 *
503 * @throws PrinterException if the specified service does not support
504 * 2D printing or no longer available.
505 */
506 public void setPrintService(PrintService service)
507 throws PrinterException {
508 if (service == null) {
509 throw new PrinterException("Service cannot be null");
510 } else if (!(service instanceof StreamPrintService) &&
511 service.getName() == null) {
512 throw new PrinterException("Null PrintService name.");
513 } else {
514 // Check the list of services. This service may have been
515 // deleted already
516 PrinterState prnState = service.getAttribute(PrinterState.class);
517 if (prnState == PrinterState.STOPPED) {
518 PrinterStateReasons prnStateReasons =
519 service.getAttribute(PrinterStateReasons.class);
520 if ((prnStateReasons != null) &&
521 (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
1007 mDestination = (new File(defaultDest.getURI())).getPath();
1008 }
1009 }
1010 }
1011 } else {
1012 mDestType = RasterPrinterJob.PRINTER;
1013 PrintService ps = getPrintService();
1014 if (ps != null) {
1015 mDestination = ps.getName();
1016 }
1017 }
1018 }
1019
1020 return doPrint;
1021 }
1022
1023 /**
1024 * The pages in the document to be printed by this PrinterJob
1025 * are drawn by the Printable object 'painter'. The PageFormat
1026 * for each page is the default page format.
1027 * @param painter Called to render each page of the document.
1028 */
1029 public void setPrintable(Printable painter) {
1030 setPageable(new OpenBook(defaultPage(new PageFormat()), painter));
1031 }
1032
1033 /**
1034 * The pages in the document to be printed by this PrinterJob
1035 * are drawn by the Printable object 'painter'. The PageFormat
1036 * of each page is 'format'.
1037 * @param painter Called to render each page of the document.
1038 * @param format The size and orientation of each page to
1039 * be printed.
1040 */
1041 public void setPrintable(Printable painter, PageFormat format) {
1042 setPageable(new OpenBook(format, painter));
1043 updatePageAttributes(getPrintService(), format);
1044 }
1045
1046 /**
1047 * The pages in the document to be printed are held by the
1048 * Pageable instance 'document'. 'document' will be queried
1049 * for the number of pages as well as the PageFormat and
1050 * Printable for each page.
1051 * @param document The document to be printed. It may not be null.
1052 * @exception NullPointerException the Pageable passed in was null.
1053 * @see PageFormat
1054 * @see Printable
1055 */
1056 public void setPageable(Pageable document) throws NullPointerException {
1057 if (document != null) {
1058 mDocument = document;
1059
1060 } else {
1061 throw new NullPointerException();
1062 }
1063 }
1064
1065 protected void initPrinter() {
1066 return;
1067 }
1068
1069 protected boolean isSupportedValue(Attribute attrval,
1070 PrintRequestAttributeSet attrset) {
1071 PrintService ps = getPrintService();
|