java.awt.print.PrinterIOException#javax.print.PrintService源码实例Demo

下面列出了java.awt.print.PrinterIOException#javax.print.PrintService 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u-dev-jdk   文件: RasterPrinterJob.java
protected static PrintService lookupDefaultPrintService() {
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();

    /* Pageable implies Printable so checking both isn't strictly needed */
    if (service != null &&
        service.isDocFlavorSupported(
                            DocFlavor.SERVICE_FORMATTED.PAGEABLE) &&
        service.isDocFlavorSupported(
                            DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
        return service;
    } else {
       PrintService []services =
         PrintServiceLookup.lookupPrintServices(
                            DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
       if (services.length > 0) {
           return services[0];
       }
    }
    return null;
}
 
源代码2 项目: openjdk-jdk9   文件: BannerTest.java
public static void main(String[] args)  throws Exception {
    job = PrinterJob.getPrinterJob();
    PrintService prtSrv = job.getPrintService();
    if (job.getPrintService() == null) {
        System.out.println("No printers. Test cannot continue");
        return;
    }
    if (!prtSrv.isAttributeCategorySupported(JobSheets.class)) {
        return;
    }
    SwingUtilities.invokeAndWait(() -> {
        doTest(BannerTest::printTest);
    });
    mainThread = Thread.currentThread();
    try {
        Thread.sleep(180000);
    } catch (InterruptedException e) {
        if (!testPassed && testGeneratedInterrupt) {
            throw new RuntimeException("Banner page did not print");
        }
    }
    if (!testGeneratedInterrupt) {
        throw new RuntimeException("user has not executed the test");
    }
}
 
源代码3 项目: hottub   文件: GetPrintServices.java
public static void main(String[] args) throws Exception {
  for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) {
    String serviceName = service.getName();
    PrintService serviceByName = lookupByName(serviceName);
    if (!service.equals(serviceByName)) {
      throw new RuntimeException("NOK " + serviceName
                                 + " expected: " + service.getClass().getName()
                                 + " got: " + serviceByName.getClass().getName());
    }
  }
  System.out.println("Test PASSED");
}
 
源代码4 项目: Bytecoder   文件: RasterPrinterJob.java
synchronized PrinterGraphicsConfig getPrinterGraphicsConfig() {
    if (pgConfig != null) {
        return pgConfig;
    }
    String deviceID = "Printer Device";
    PrintService service = getPrintService();
    if (service != null) {
        deviceID = service.toString();
    }
    pgConfig = new PrinterGraphicsConfig(deviceID,
                                         defaultDeviceTransform,
                                         deviceWidth, deviceHeight);
    return pgConfig;
}
 
源代码5 项目: hottub   文件: Win32PrintService.java
public PrintRequestAttributeSet
    showDocumentProperties(PrinterJob job,
                           Window owner,
                           PrintService service,
                           PrintRequestAttributeSet aset) {

    if (!(job instanceof WPrinterJob)) {
        return null;
    }
    WPrinterJob wJob = (WPrinterJob)job;
    return wJob.showDocumentProperties(owner, service, aset);
}
 
源代码6 项目: jdk8u60   文件: RasterPrinterJob.java
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 2D printing or no longer available.
 */
public void setPrintService(PrintService service)
    throws PrinterException {
    if (service == null) {
        throw new PrinterException("Service cannot be null");
    } else if (!(service instanceof StreamPrintService) &&
               service.getName() == null) {
        throw new PrinterException("Null PrintService name.");
    } else {
        // Check the list of services.  This service may have been
        // deleted already
        PrinterState prnState = (PrinterState)service.getAttribute(
                                              PrinterState.class);
        if (prnState == PrinterState.STOPPED) {
            PrinterStateReasons prnStateReasons =
                (PrinterStateReasons)service.getAttribute(
                                             PrinterStateReasons.class);
            if ((prnStateReasons != null) &&
                (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
            {
                throw new PrinterException("PrintService is no longer available.");
            }
        }


        if (service.isDocFlavorSupported(
                                         DocFlavor.SERVICE_FORMATTED.PAGEABLE) &&
            service.isDocFlavorSupported(
                                         DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            myService = service;
        } else {
            throw new PrinterException("Not a 2D print service: " + service);
        }
    }
}
 
源代码7 项目: openjdk-8   文件: PSPrinterJob.java
/**
 * Invoked by the RasterPrintJob super class
 * this method is called after that last page
 * has been imaged.
 */
protected void endDoc() throws PrinterException {
    if (mPSStream != null) {
        mPSStream.println(EOF_COMMENT);
        mPSStream.flush();
        if (mDestType != RasterPrinterJob.STREAM) {
            mPSStream.close();
        }
    }
    if (mDestType == RasterPrinterJob.PRINTER) {
        PrintService pServ = getPrintService();
        if (pServ != null) {
            mDestination = pServ.getName();
           if (isMac) {
                PrintServiceAttributeSet psaSet = pServ.getAttributes();
                if (psaSet != null) {
                    mDestination = psaSet.get(PrinterName.class).toString() ;
                }
            }
        }
        PrinterSpooler spooler = new PrinterSpooler();
        java.security.AccessController.doPrivileged(spooler);
        if (spooler.pex != null) {
            throw spooler.pex;
        }
    }
}
 
源代码8 项目: jdk8u60   文件: UnixPrintServiceLookup.java
private PrintService getNamedPrinterNameSysV(String name) {

        String command = "/usr/bin/lpstat -v " + name;
        String []result = execCmd(command);

        if (result == null || result[0].indexOf("unknown printer") > 0) {
            return null;
        } else {
            return new UnixPrintService(name);
        }
    }
 
源代码9 项目: jdk8u-jdk   文件: RasterPrinterJob.java
protected boolean isSupportedValue(Attribute attrval,
                                 PrintRequestAttributeSet attrset) {
    PrintService ps = getPrintService();
    return
        (attrval != null && ps != null &&
         ps.isAttributeValueSupported(attrval,
                                      DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                      attrset));
}
 
源代码10 项目: hottub   文件: RasterPrinterJob.java
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}
 
源代码11 项目: jdk8u-dev-jdk   文件: UnixPrintServiceLookup.java
public void run() {
    PrintService[] services = getPrintServices();
    synchronized (this) {
        BackgroundLookupListener listener;
        for (int i=0; i<lookupListeners.size(); i++) {
            listener =
                (BackgroundLookupListener)lookupListeners.elementAt(i);
            listener.notifyServices(copyOf(services));
        }
        lookupListeners = null;
    }
}
 
public synchronized PrintService[] getPrintServices() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    if (printServices == null) {
        refreshServices();
    }
    return printServices;
}
 
源代码13 项目: ramus   文件: AbstractRamusPrintable.java
@Override
public PrintService getPrintService() {
    if (printService == null) {
        PrintService[] lookupPrintServices = PrinterJob
                .lookupPrintServices();
        if (lookupPrintServices.length > 0)
            printService = lookupPrintServices[0];
    }
    return printService;
}
 
源代码14 项目: jdk8u-dev-jdk   文件: Win32PrintService.java
public PrintRequestAttributeSet
    showDocumentProperties(PrinterJob job,
                           Window owner,
                           PrintService service,
                           PrintRequestAttributeSet aset) {

    if (!(job instanceof WPrinterJob)) {
        return null;
    }
    WPrinterJob wJob = (WPrinterJob)job;
    return wJob.showDocumentProperties(owner, service, aset);
}
 
源代码15 项目: openjdk-8   文件: UnixPrintServiceLookup.java
private boolean matchesAttributes(PrintService service,
                                  PrintServiceAttributeSet attributes) {

    Attribute [] attrs =  attributes.toArray();
    Attribute serviceAttr;
    for (int i=0; i<attrs.length; i++) {
        serviceAttr
            = service.getAttribute((Class<PrintServiceAttribute>)attrs[i].getCategory());
        if (serviceAttr == null || !serviceAttr.equals(attrs[i])) {
            return false;
        }
    }
    return true;
}
 
源代码16 项目: TencentKona-8   文件: PrintToDir.java
public static void doPrinterJob(String fileStr, OrientationRequested o) {
    PrinterJob  pj = PrinterJob.getPrinterJob();
    PrintService ps = pj.getPrintService();
    if (ps == null) {
      System.out.println("No print service found.");
      return;
    }
    pj.setPrintable(new PrintToDir());
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(o);
    File f = new File(fileStr);
    //      f.deleteOnExit();
    URI dest = f.toURI();
    Destination d = new Destination(dest);
    if (ps.isAttributeValueSupported(d, null, null)) {
        aset.add(d);
        try {
            pj.print(aset);
        } catch (PrinterException e) {
            System.out.println("PrinterJob passed.");
            return;
        }
        throw new RuntimeException("PrinterJob:PrinterException expected but not thrown. \nTEST FAILED");
    } else {
        System.out.println("Destination attribute is not a supported value.  PrinterJob passed.");
    }
}
 
源代码17 项目: openjdk-8-source   文件: UnixPrintJob.java
UnixPrintJob(PrintService service) {
    this.service = service;
    mDestination = service.getName();
    if (UnixPrintServiceLookup.isMac()) {
        mDestination = ((IPPPrintService)service).getDest();
    }
    mDestType = UnixPrintJob.DESTPRINTER;
}
 
源代码18 项目: dragonwell8_jdk   文件: Win32PrintService.java
public PrintRequestAttributeSet
    showDocumentProperties(PrinterJob job,
                           Window owner,
                           PrintService service,
                           PrintRequestAttributeSet aset) {

    if (!(job instanceof WPrinterJob)) {
        return null;
    }
    WPrinterJob wJob = (WPrinterJob)job;
    return wJob.showDocumentProperties(owner, service, aset);
}
 
源代码19 项目: Bytecoder   文件: RasterPrinterJob.java
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}
 
源代码20 项目: jdk8u_jdk   文件: WPrinterJob.java
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * </code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 2D printing.
 */
@Override
public void setPrintService(PrintService service)
    throws PrinterException {
    super.setPrintService(service);
    if (!(service instanceof Win32PrintService)) {
        return;
    }
    driverDoesMultipleCopies = false;
    driverDoesCollation = false;
    setNativePrintServiceIfNeeded(service.getName());
}
 
public synchronized PrintService[] getPrintServices() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    if (printServices == null) {
        refreshServices();
    }
    return printServices;
}
 
private List<MediaTray> loadAvailableTrays(PrintService printService){
	mediaTrays = new ArrayList<MediaTray>();
	Object attributes =
		printService.getSupportedAttributeValues(Media.class,
			DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
	if (attributes != null && attributes.getClass().isArray()) {
		for (Media media : (Media[]) attributes) {
			if (media instanceof MediaTray) {
				mediaTrays.add((MediaTray) media);
			}
		}
	}
	return mediaTrays;
}
 
public synchronized PrintService getPrintServiceByName(String name) {

        if (name == null || name.equals("")) {
            return null;
        } else {
            /* getPrintServices() is now very fast. */
            PrintService[] printServices = getPrintServices();
            for (int i=0; i<printServices.length; i++) {
                if (printServices[i].getName().equals(name)) {
                    return printServices[i];
                }
            }
            return null;
        }
    }
 
源代码24 项目: jdk8u-dev-jdk   文件: RasterPrinterJob.java
synchronized PrinterGraphicsConfig getPrinterGraphicsConfig() {
    if (pgConfig != null) {
        return pgConfig;
    }
    String deviceID = "Printer Device";
    PrintService service = getPrintService();
    if (service != null) {
        deviceID = service.toString();
    }
    pgConfig = new PrinterGraphicsConfig(deviceID,
                                         defaultDeviceTransform,
                                         deviceWidth, deviceHeight);
    return pgConfig;
}
 
源代码25 项目: TencentKona-8   文件: RemotePrinterStatusRefresh.java
private static List<ServiceItem> collectPrinterList() {
    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
    List<ServiceItem> list = new ArrayList<>(printServices.length);
    for (PrintService service : printServices) {
        list.add(new ServiceItem(service.getName()));
    }
    return list;
}
 
源代码26 项目: jdk8u60   文件: Win32PrintServiceLookup.java
public synchronized PrintService getDefaultPrintService() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
      security.checkPrintJobAccess();
    }


    // Windows does not have notification for a change in default
    // so we always get the latest.
    defaultPrinter = getDefaultPrinterName();
    if (defaultPrinter == null) {
        return null;
    }

    if ((defaultPrintService != null) &&
        defaultPrintService.getName().equals(defaultPrinter)) {

        return defaultPrintService;
    }

     // Not the same as default so proceed to get new PrintService.

    // clear defaultPrintService
    defaultPrintService = null;

    if (printServices != null) {
        for (int j=0; j<printServices.length; j++) {
            if (defaultPrinter.equals(printServices[j].getName())) {
                defaultPrintService = printServices[j];
                break;
            }
        }
    }

    if (defaultPrintService == null) {
        defaultPrintService = new Win32PrintService(defaultPrinter);
    }
    return defaultPrintService;
}
 
源代码27 项目: TencentKona-8   文件: TestRaceCond.java
static void trial() {
    PrintService pserv1 = PrintServiceLookup.lookupDefaultPrintService();
    PrintService[] pservs = PrintServiceLookup.lookupPrintServices(null, null);
    PrintService pserv2 = PrintServiceLookup.lookupDefaultPrintService();

    if ((pserv1 == null) || (pserv2==null)) {
        return;
    }

    if (pserv1.hashCode() != pserv2.hashCode()) {
        throw new RuntimeException("Different hashCodes for equal print "
                        + "services: " + pserv1.hashCode() + " "
                        + pserv2.hashCode());
    }
}
 
源代码28 项目: jdk8u60   文件: RasterPrinterJob.java
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}
 
源代码29 项目: jdk8u-jdk   文件: UnixPrintServiceLookup.java
private PrintService getNamedPrinterNameSysV(String name) {

        String command = "/usr/bin/lpstat -v " + name;
        String []result = execCmd(command);

        if (result == null || result[0].indexOf("unknown printer") > 0) {
            return null;
        } else {
            return new UnixPrintService(name);
        }
    }
 
源代码30 项目: jdk8u-jdk   文件: Win32PrintServiceLookup.java
public synchronized PrintService getDefaultPrintService() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
      security.checkPrintJobAccess();
    }


    // Windows does not have notification for a change in default
    // so we always get the latest.
    defaultPrinter = getDefaultPrinterName();
    if (defaultPrinter == null) {
        return null;
    }

    if ((defaultPrintService != null) &&
        defaultPrintService.getName().equals(defaultPrinter)) {

        return defaultPrintService;
    }

     // Not the same as default so proceed to get new PrintService.

    // clear defaultPrintService
    defaultPrintService = null;

    if (printServices != null) {
        for (int j=0; j<printServices.length; j++) {
            if (defaultPrinter.equals(printServices[j].getName())) {
                defaultPrintService = printServices[j];
                break;
            }
        }
    }

    if (defaultPrintService == null) {
        defaultPrintService = new Win32PrintService(defaultPrinter);
    }
    return defaultPrintService;
}