javax.print.PrintServiceLookup Java Examples
The following examples show how to use
javax.print.PrintServiceLookup.
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 |
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 Bytecoder with Apache License 2.0 | 6 votes |
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: RasterPrinterJob.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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: RasterPrinterJob.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 #5
Source File: RasterPrinterJob.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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 #6
Source File: GetPrintServices.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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"); }
Example #7
Source File: RasterPrinterJob.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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 #8
Source File: ServiceDlgPageRangeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Starts the application. */ public static void main(java.lang.String[] args) throws Exception { services = PrintServiceLookup.lookupPrintServices(flavor, null); if (services.length == 0) { System.out.println("No print service found!!"); return; } SwingUtilities.invokeAndWait(() -> { doTest(ServiceDlgPageRangeTest::printTest); }); mainThread = Thread.currentThread(); try { Thread.sleep(600000); } catch (InterruptedException e) { if (!testPassed && testGeneratedInterrupt) { throw new RuntimeException("PageRanges option is not disabled " + "for for Non serv-formatted flvrs"); } } if (!testGeneratedInterrupt) { throw new RuntimeException("user has not executed the test"); } }
Example #9
Source File: RasterPrinterJob.java From hottub with GNU General Public License v2.0 | 6 votes |
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 #10
Source File: WPrinterJob.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 #11
Source File: PrintImageOutput.java From RipplePower with Apache License 2.0 | 6 votes |
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 #12
Source File: RasterPrinterJob.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 #13
Source File: GetMediasTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 #14
Source File: Java14PrintUtil.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public static boolean print( final MasterReport report, final ReportProgressListener progressListener ) throws PrintException, ReportProcessingException { final PrintService[] services = PrintServiceLookup.lookupPrintServices( DocFlavor.SERVICE_FORMATTED.PAGEABLE, null ); if ( services.length == 0 ) { throw new PrintException( "Unable to find a matching print service implementation." ); } PrintRequestAttributeSet attributes = Java14PrintUtil.copyConfiguration( null, report ); attributes = Java14PrintUtil.copyAuxillaryAttributes( attributes, report ); final PrintService service = ServiceUI.printDialog( null, 50, 50, services, lookupPrintService(), DocFlavor.SERVICE_FORMATTED.PAGEABLE, attributes ); if ( service == null ) { return false; } final PrintReportProcessor reportPane = new PrintReportProcessor( report ); if ( progressListener != null ) { reportPane.addReportProgressListener( progressListener ); } try { reportPane.fireProcessingStarted(); final DocPrintJob job = service.createPrintJob(); final SimpleDoc document = new SimpleDoc( reportPane, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null ); job.print( document, attributes ); } finally { reportPane.fireProcessingFinished(); reportPane.close(); if ( progressListener != null ) { reportPane.removeReportProgressListener( progressListener ); } } return true; }
Example #15
Source File: PreferredDefaultsImpl.java From swingsane with Apache License 2.0 | 5 votes |
private boolean isA4PaperSize() { String timezone = System.getProperty("user.timezone"); if ((timezone != null) && (timezone.length() > 0)) { return !System.getProperty("user.timezone").startsWith("America"); } try { PrintService pservice = PrintServiceLookup.lookupDefaultPrintService(); Object obj = pservice.getDefaultAttributeValue(Media.class); if (obj instanceof MediaSizeName) { MediaSizeName mediaSizeName = (MediaSizeName) obj; return mediaSizeName.equals(MediaSizeName.ISO_A4); } } catch (Exception ex) { LOG.info(ex.getLocalizedMessage()); } String country = Locale.getDefault().getCountry(); if ((country.equals("US")) || (country.equals("CA"))) { return false; } // default to true return true; }
Example #16
Source File: GetPrintServices.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static PrintService lookupByName(String name) { AttributeSet attributes = new HashAttributeSet(); attributes.add(new PrinterName(name, null)); for (PrintService service : PrintServiceLookup.lookupPrintServices(null, attributes)) { return service; } return null; }
Example #17
Source File: Win32PrintServiceLookup.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 #18
Source File: RemotePrinterStatusRefresh.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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 #19
Source File: WPrinterJob.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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 #20
Source File: GetPrintServices.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 #21
Source File: GetMediasTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 #22
Source File: PrintDialog.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // instruction dialog Frame instruction = new Frame("Verify that no native print dialog is showed"); instruction.add(new TextArea(instructions)); instruction.pack(); instruction.show(); // test begin PrintServiceStub service = new PrintServiceStub("test"); PrintServiceLookup.registerService(service); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintService(service); job.printDialog(); System.out.println("test passed"); }
Example #23
Source File: CountPrintServices.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 #24
Source File: GetPrintServices.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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 #25
Source File: GetPrintServices.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private static PrintService lookupByName(String name) { AttributeSet attributes = new HashAttributeSet(); attributes.add(new PrinterName(name, null)); for (PrintService service : PrintServiceLookup.lookupPrintServices(null, attributes)) { return service; } return null; }
Example #26
Source File: GetPrintServices.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static PrintService lookupByName(String name) { AttributeSet attributes = new HashAttributeSet(); attributes.add(new PrinterName(name, null)); for (PrintService service : PrintServiceLookup.lookupPrintServices(null, attributes)) { return service; } return null; }
Example #27
Source File: GetPrintServices.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static PrintService lookupByName(String name) { AttributeSet attributes = new HashAttributeSet(); attributes.add(new PrinterName(name, null)); for (PrintService service : PrintServiceLookup.lookupPrintServices(null, attributes)) { return service; } return null; }
Example #28
Source File: Win32PrintServiceLookup.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 #29
Source File: RemotePrinterStatusRefresh.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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 #30
Source File: GetMediasTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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(); } }