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

The following examples show how to use javax.print.PrintServiceLookup#lookupDefaultPrintService() . 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-dev-jdk with GNU General Public License v2.0 7 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: WPrinterJob.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = Win32PrintServiceLookup.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
Example 3
Source File: RasterPrinterJob.java    From openjdk-8 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 4
Source File: PrintImageOutput.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public static boolean out(BufferedImage image) {
	try {
		DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
		PrintRequestAttributeSet requestAttributeSet = new HashPrintRequestAttributeSet();
		requestAttributeSet.add(MediaSizeName.ISO_A4);
		requestAttributeSet.add(new JobName(LSystem.applicationName + LSystem.getTime(), Locale.ENGLISH));
		PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, requestAttributeSet);
		PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
		PrintService service = ServiceUI.printDialog(null, 100, 100, services, defaultService, flavor,
				requestAttributeSet);
		if (service != null) {
			DocPrintJob job = service.createPrintJob();
			SimpleDoc doc = new SimpleDoc(new BufferedImagePrintable(image), flavor, null);
			job.print(doc, requestAttributeSet);
		}
	} catch (Exception e) {
		return false;
	}
	return true;
}
 
Example 5
Source File: WPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = PrintServiceLookupProvider.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
Example 6
Source File: Win32PrintServiceLookup.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static Win32PrintServiceLookup getWin32PrintLUS() {
    if (win32PrintLUS == null) {
        /* This call is internally synchronized.
         * When it returns an instance of this class will have
         * been instantiated - else there's a JDK internal error.
         */
        PrintServiceLookup.lookupDefaultPrintService();
    }
    return win32PrintLUS;
}
 
Example 7
Source File: TestRaceCond.java    From openjdk-8-source 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 8
Source File: TestRaceCond.java    From jdk8u-dev-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 9
Source File: TestRaceCond.java    From openjdk-jdk9 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 10
Source File: PrintServiceLookupProvider.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static PrintServiceLookupProvider getWin32PrintLUS() {
    if (win32PrintLUS == null) {
        /* This call is internally synchronized.
         * When it returns an instance of this class will have
         * been instantiated - else there's a JDK internal error.
         */
        PrintServiceLookup.lookupDefaultPrintService();
    }
    return win32PrintLUS;
}
 
Example 11
Source File: Win32PrintServiceLookup.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static Win32PrintServiceLookup getWin32PrintLUS() {
    if (win32PrintLUS == null) {
        /* This call is internally synchronized.
         * When it returns an instance of this class will have
         * been instantiated - else there's a JDK internal error.
         */
        PrintServiceLookup.lookupDefaultPrintService();
    }
    return win32PrintLUS;
}
 
Example 12
Source File: TestRaceCond.java    From jdk8u60 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 13
Source File: WPrinterJob.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = Win32PrintServiceLookup.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
Example 14
Source File: WPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = Win32PrintServiceLookup.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
Example 15
Source File: TestRaceCond.java    From openjdk-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 16
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 17
Source File: WPrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = PrintServiceLookupProvider.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
Example 18
Source File: PrintServiceLookupProvider.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static PrintServiceLookupProvider getWin32PrintLUS() {
    if (win32PrintLUS == null) {
        /* This call is internally synchronized.
         * When it returns an instance of this class will have
         * been instantiated - else there's a JDK internal error.
         */
        PrintServiceLookup.lookupDefaultPrintService();
    }
    return win32PrintLUS;
}
 
Example 19
Source File: TextTemplatePrintSettingsDialog.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void initSelection(){
	if (selPrinter == null) {
		PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
		if (defaultPrintService != null && printServices.contains(defaultPrintService)) {
			cvPrinters.setSelection(new StructuredSelection(defaultPrintService));
		}
	} else {
		for (PrintService ps : printServices) {
			if (ps.getName().equals(selPrinter)) {
				cvPrinters.setSelection(new StructuredSelection(ps));
			}
		}
	}
	
	if (!mediaTrays.isEmpty()) {
		if (selTray == null) {
			cvTrays.setSelection(new StructuredSelection(mediaTrays.get(0)));
		} else {
			boolean foundTray = false;
			for (MediaTray mt : mediaTrays) {
				if (mt.toString().equals(selTray)) {
					cvTrays.setSelection(new StructuredSelection(mt));
					foundTray = true;
					break;
				}
			}
			if (!foundTray) {
				addCustomMediaTray(selTray);
			}
		}
	}
}
 
Example 20
Source File: WPrinterJob.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (myService == null) {
        String printerName = getNativePrintService();

        if (printerName != null) {
            myService = Win32PrintServiceLookup.getWin32PrintLUS().
                getPrintServiceByName(printerName);
            // no need to call setNativePrintService as this name is
            // currently set in native
            if (myService != null) {
                return myService;
            }
        }

        myService = PrintServiceLookup.lookupDefaultPrintService();
        if (myService instanceof Win32PrintService) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}