当前位置: 首页>>代码示例>>Java>>正文


Java PrintService类代码示例

本文整理汇总了Java中javax.print.PrintService的典型用法代码示例。如果您正苦于以下问题:Java PrintService类的具体用法?Java PrintService怎么用?Java PrintService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PrintService类属于javax.print包,在下文中一共展示了PrintService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: thirdPartyPrintLogic

import javax.print.PrintService; //导入依赖的package包/类
static void thirdPartyPrintLogic(String printerName) throws Exception {
    PrinterJob printerjob = PrinterJob.getPrinterJob();
    printerjob.setCopies(2);
    printerjob.setJobName("myJobName");
    printerjob.setPrintable(new DummyPrintable());
    for (PrintService printService : PrinterJob.lookupPrintServices()) {
        System.out.println("check printer name of service " + printService);
        if (printerName.equals(printService.getName())) {
            System.out.println("correct printer service do print...");
            printerjob.setPrintService(printService);
            printerjob.print();
            break;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:DummyPrintTest.java

示例2: main

import javax.print.PrintService; //导入依赖的package包/类
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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:BannerTest.java

示例3: addPrintServiceToList

import javax.print.PrintService; //导入依赖的package包/类
private int addPrintServiceToList(ArrayList<PrintService> printerList, PrintService ps) {
    int index = printerList.indexOf(ps);
    // Check if PrintService with same name is already in the list.
    if (CUPSPrinter.isCupsRunning() && index != -1) {
        // Bug in Linux: Duplicate entry of a remote printer
        // and treats it as local printer but it is returning wrong
        // information when queried using IPP. Workaround is to remove it.
        // Even CUPS ignores these entries as shown in lpstat or using
        // their web configuration.
        PrinterURI uri = ps.getAttribute(PrinterURI.class);
        if (uri.getURI().getHost().equals("localhost")) {
            IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, ignoring the new local printer: "+ps);
            return index;  // Do not add this.
        }
        PrintService oldPS = printerList.get(index);
        uri = oldPS.getAttribute(PrinterURI.class);
        if (uri.getURI().getHost().equals("localhost")) {
            IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, removing existing local printer: "+oldPS);
            printerList.remove(oldPS);
        } else {
            return index;
        }
    }
    printerList.add(ps);
    return (printerList.size() - 1);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:PrintServiceLookupProvider.java

示例4: printTest

import javax.print.PrintService; //导入依赖的package包/类
/**
 * Starts the application.
 */
public static void printTest() {

    System.out.println("\nDefault print service: " +
                          PrintServiceLookup.lookupDefaultPrintService());
    System.out.println("is flavor: "+flavor+" supported? "+
                                 services[0].isDocFlavorSupported(flavor));
    System.out.println("is Page Ranges category supported? "+
               services[0].isAttributeCategorySupported(PageRanges.class));
    System.out.println("is PageRanges[2] value supported ? "+
               services[0].isAttributeValueSupported(
                                         new PageRanges(2), flavor, null));

    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    //prSet.add(new PageRanges(2));
    PrintService selService = ServiceUI.printDialog(null, 200, 200,
                                      services, services[0], flavor, prSet);

    System.out.println("\nSelected Values\n");
    Attribute attr[] = prSet.toArray();
    for (int x = 0; x < attr.length; x ++) {
        System.out.println("Attribute: " + attr[x].getName() +
                                                    " Value: " + attr[x]);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:ServiceDlgPageRangeTest.java

示例5: lookupDefaultPrintService

import javax.print.PrintService; //导入依赖的package包/类
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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:RasterPrinterJob.java

示例6: setPrinterNameAttrib

import javax.print.PrintService; //导入依赖的package包/类
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:WPrinterJob.java

示例7: matchingService

import javax.print.PrintService; //导入依赖的package包/类
@SuppressWarnings("unchecked") // Cast to Class<PrintServiceAttribute>
boolean matchingService(PrintService service,
                        PrintServiceAttributeSet serviceSet) {
    if (serviceSet != null) {
        Attribute [] attrs =  serviceSet.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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:PrintServiceLookupProvider.java

示例8: updatePageAttributes

import javax.print.PrintService; //导入依赖的package包/类
protected void updatePageAttributes(PrintService service,
                                    PageFormat page) {
    if (this.attributes == null) {
        this.attributes = new HashPrintRequestAttributeSet();
    }

    updateAttributesWithPageFormat(service, page, this.attributes);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:RasterPrinterJob.java

示例9: main

import javax.print.PrintService; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) {
        String serviceName = service.getName();
        PrinterName name = service.getAttribute(PrinterName.class);
        String printerName = name.getValue();

        PrintService serviceByName = lookupByName(printerName);
        System.out.println("service " + service);
        System.out.println("serviceByName " + serviceByName);
        if (!service.equals(serviceByName)) {
            throw new RuntimeException("NOK " + serviceName
                               + " expected: " + service.getClass().getName()
                               + " got: " + serviceByName.getClass().getName());
        }
    }
    System.out.println("Test PASSED");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:GetPrintServices.java

示例10: main

import javax.print.PrintService; //导入依赖的package包/类
public static void main(String[] args) {
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    for(final PrintService service: services) {
        Thread thread = new Thread() {
            public void run() {
                service.getSupportedAttributeValues(Media.class, null, null);
            }
        };
        thread.start();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:GetMediasTest.java

示例11: main

import javax.print.PrintService; //导入依赖的package包/类
public static void main (String[] args) throws Exception {

        job = PrinterJob.getPrinterJob();
        PrintService prtSrv = job.getPrintService();
        if (prtSrv == null) {
            System.out.println("No printers. Test cannot continue");
            return;
        }
        // do not run the test if JobSheet category is not supported
        if (!prtSrv.isAttributeCategorySupported(JobSheets.class)) {
            return;
        }
        // check system default banner option and let user know what to expect
        JobSheets js = (JobSheets)job.getPrintService().
                getDefaultAttributeValue(JobSheets.class);
        if (js != null && js.equals(JobSheets.NONE)) {
            noJobSheet = true;
        }
        SwingUtilities.invokeAndWait(() -> {
            doTest(TestCheckSystemDefaultBannerOption::printTest);
        });
        mainThread = Thread.currentThread();
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            if (!testPassed && testGeneratedInterrupt) {
                String banner = noJobSheet ? "Banner page" : " No Banner page";
                throw new RuntimeException(banner + " is printed");
            }
        }
        if (!testGeneratedInterrupt) {
            throw new RuntimeException("user has not executed the test");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:TestCheckSystemDefaultBannerOption.java

示例12: doPrinterJob

import javax.print.PrintService; //导入依赖的package包/类
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.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:PrintToDir.java

示例13: setPrintService

import javax.print.PrintService; //导入依赖的package包/类
/**
 * 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);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:46,代码来源:RasterPrinterJob.java

示例14: isSupportedValue

import javax.print.PrintService; //导入依赖的package包/类
protected boolean isSupportedValue(Attribute attrval,
                                 PrintRequestAttributeSet attrset) {
    PrintService ps = getPrintService();
    return
        (attrval != null && ps != null &&
         ps.isAttributeValueSupported(attrval,
                                      DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                      attrset));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:RasterPrinterJob.java

示例15: getPrinterGraphicsConfig

import javax.print.PrintService; //导入依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:RasterPrinterJob.java


注:本文中的javax.print.PrintService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。