Java Code Examples for javax.print.PrintServiceLookup#lookupPrintServices()

The following examples show how to use javax.print.PrintServiceLookup#lookupPrintServices() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: RasterPrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: ServiceDlgSheetCollateTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void printTest() {
    ServiceDlgSheetCollateTest pd = new ServiceDlgSheetCollateTest();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
    //DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    PrintService defService = null, service[] = null;
    defService = PrintServiceLookup.lookupDefaultPrintService();
    service = PrintServiceLookup.lookupPrintServices(flavor, null);

    if ((service == null) || (service.length == 0)) {
        throw new RuntimeException("No Printer services found");
    }
    if (defService != null) {
        System.out.println("\nDefault print service: " + service );
        System.out.println("is flavor: "+flavor+" supported? "+
                        defService.isDocFlavorSupported(flavor));
        System.out.println("is SheetCollate category supported? "+
              defService.isAttributeCategorySupported(SheetCollate.class));
        System.out.println("is SheetCollate.COLLATED value supported ? "+
              defService.isAttributeValueSupported(SheetCollate.COLLATED,
                                                        flavor, null));
    }
    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    try {
        PrintService selService = ServiceUI.printDialog(null, 200, 200, service, defService, flavor, prSet);
    } catch (IllegalArgumentException ia) {
        System.out.println("Exception thrown : " + ia);
    }

    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]);
    }

}
 
Example 4
Source File: GetMediasTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 5
Source File: CountPrintServices.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
   String os = System.getProperty("os.name").toLowerCase();
   System.out.println("OS is " + os);
   if (!os.equals("linux")) {
       System.out.println("Linux specific test. No need to continue");
       return;
   }
   PrintService services[] =
       PrintServiceLookup.lookupPrintServices(null, null);
   if (services.length > 0) {
      System.out.println("Services found. No need to test further.");
      return;
   }
   String[] lpcmd = { "lpstat", "-a" };
   Process proc = Runtime.getRuntime().exec(lpcmd);
   proc.waitFor();
   InputStreamReader ir = new InputStreamReader(proc.getInputStream());
   BufferedReader br = new BufferedReader(ir);
   int count = 0;
   String printer;
   while ((printer = br.readLine()) != null) {
      System.out.println("lpstat:: " + printer);
      count++;
   }
   if (count > 0) {
       throw new RuntimeException("Services exist, but not found by JDK.");
   }
}
 
Example 6
Source File: GetPrintServices.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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");
}
 
Example 7
Source File: CountPrintServices.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
   String os = System.getProperty("os.name").toLowerCase();
   System.out.println("OS is " + os);
   if (!os.equals("linux")) {
       System.out.println("Linux specific test. No need to continue");
       return;
   }
   PrintService services[] =
       PrintServiceLookup.lookupPrintServices(null, null);
   if (services.length > 0) {
      System.out.println("Services found. No need to test further.");
      return;
   }
   String[] lpcmd = { "lpstat", "-a" };
   Process proc = Runtime.getRuntime().exec(lpcmd);
   proc.waitFor();
   InputStreamReader ir = new InputStreamReader(proc.getInputStream());
   BufferedReader br = new BufferedReader(ir);
   int count = 0;
   String printer;
   while ((printer = br.readLine()) != null) {
      System.out.println("lpstat:: " + printer);
      count++;
   }
   if (count > 0) {
       throw new RuntimeException("Services exist, but not found by JDK.");
   }
}
 
Example 8
Source File: GetPrintServices.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
}
 
Example 9
Source File: ServiceDialogValidateTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void printTest() {
    PrintService defService = null, service[] = null;
    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;

    service = PrintServiceLookup.lookupPrintServices(flavor, null);
    defService = PrintServiceLookup.lookupDefaultPrintService();

    if ((service == null) || (service.length == 0)) {
        throw new RuntimeException("No Printer services found");
    }
    File f = new File("output.ps");
    Destination d = new Destination(f.toURI());
    prSet.add(d);
    if (defService != null) {
        System.out.println("isAttrCategory Supported? " +
                defService.isAttributeCategorySupported(Destination.class));
        System.out.println("isAttrValue Supported? " +
                defService.isAttributeValueSupported(d, flavor, null));
    }

    defService = ServiceUI.printDialog(null, 100, 100, service, defService,
            flavor, prSet);

    ServiceUI.printDialog(null, 100, 100, service, defService,
            DocFlavor.SERVICE_FORMATTED.PAGEABLE,
            new HashPrintRequestAttributeSet());
}
 
Example 10
Source File: TestRaceCond.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
}
 
Example 11
Source File: RemotePrinterStatusRefresh.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: GetPrintServices.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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");
}
 
Example 13
Source File: CountPrintServices.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
   String os = System.getProperty("os.name").toLowerCase();
   System.out.println("OS is " + os);
   if (!os.equals("linux")) {
       System.out.println("Linux specific test. No need to continue");
       return;
   }
   PrintService services[] =
       PrintServiceLookup.lookupPrintServices(null, null);
   if (services.length > 0) {
      System.out.println("Services found. No need to test further.");
      return;
   }
   String[] lpcmd = { "lpstat", "-a" };
   Process proc = Runtime.getRuntime().exec(lpcmd);
   proc.waitFor();
   InputStreamReader ir = new InputStreamReader(proc.getInputStream());
   BufferedReader br = new BufferedReader(ir);
   int count = 0;
   String printer;
   while ((printer = br.readLine()) != null) {
      System.out.println("lpstat:: " + printer);
      count++;
   }
   if (count > 0) {
       throw new RuntimeException("Services exist, but not found by JDK.");
   }
}
 
Example 14
Source File: TestRaceCond.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
}
 
Example 15
Source File: GetMediasTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 16
Source File: GetPrintServices.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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");
}
 
Example 17
Source File: GetMediasTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 18
Source File: ReportUtils.java    From nordpos with GNU General Public License v3.0 5 votes vote down vote up
public static String[] getPrintNames() {
    PrintService[] pservices = 
            PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
    
    String printers[] = new String[pservices.length];
    for (int i = 0; i < pservices.length; i++) {    
        printers[i] = pservices[i].getName();
    }
    
    return printers;
}
 
Example 19
Source File: PrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * A convenience method which looks up 2D print services.
 * Services returned from this method may be installed on
 * {@code PrinterJob}s which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.PrintServiceLookup#lookupPrintServices(
 * DocFlavor, AttributeSet)
 * PrintServiceLookup.lookupPrintServices()}
 * and specifying a Pageable DocFlavor.
 * @return a possibly empty array of 2D print services.
 * @since     1.4
 */
public static PrintService[] lookupPrintServices() {
    return PrintServiceLookup.
        lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
}
 
Example 20
Source File: PrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * A convenience method which looks up 2D print services.
 * Services returned from this method may be installed on
 * <code>PrinterJob</code>s which support print services.
 * Calling this method is equivalent to calling
 * {@link javax.print.PrintServiceLookup#lookupPrintServices(
 * DocFlavor, AttributeSet)
 * PrintServiceLookup.lookupPrintServices()}
 * and specifying a Pageable DocFlavor.
 * @return a possibly empty array of 2D print services.
 * @since     1.4
 */
public static PrintService[] lookupPrintServices() {
    return PrintServiceLookup.
        lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
}