當前位置: 首頁>>代碼示例>>Java>>正文


Java PrintServiceLookup.lookupDefaultPrintService方法代碼示例

本文整理匯總了Java中javax.print.PrintServiceLookup.lookupDefaultPrintService方法的典型用法代碼示例。如果您正苦於以下問題:Java PrintServiceLookup.lookupDefaultPrintService方法的具體用法?Java PrintServiceLookup.lookupDefaultPrintService怎麽用?Java PrintServiceLookup.lookupDefaultPrintService使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.print.PrintServiceLookup的用法示例。


在下文中一共展示了PrintServiceLookup.lookupDefaultPrintService方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: lookupDefaultPrintService

import javax.print.PrintServiceLookup; //導入方法依賴的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:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:RasterPrinterJob.java

示例2: getPrintService

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
/**
 *
 * @param printername
 * @return
 */
public static PrintService getPrintService(String printername) {
    
    // Initalize print service
    
    if (printername == null) {
        return PrintServiceLookup.lookupDefaultPrintService();       
    } else {
        
        if ("(Show dialog)".equals(printername)) {
            return null; // null means "you have to show the print dialog"
        } else if ("(Default)".equals(printername)) {
            return PrintServiceLookup.lookupDefaultPrintService(); 
        } else {
            PrintService[] pservices = 
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
            for (PrintService s : pservices) {    
                if (printername.equals(s.getName())) {
                    return s;
                }
            }
            return PrintServiceLookup.lookupDefaultPrintService();       
        }                
    }                 
}
 
開發者ID:gnoopy,項目名稱:wifepos,代碼行數:30,代碼來源:ReportUtils.java

示例3: main

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
public static void main(String[] args)  throws Exception {
    prservices = PrintServiceLookup.lookupDefaultPrintService();
    if (prservices == null) {
        System.out.println("No print service found");
        return;
    }
    System.out.println(" Print service " + prservices);
    SwingUtilities.invokeAndWait(() -> {
        doTest(TestMediaTraySelection::printTest);
    });
    mainThread = Thread.currentThread();
    try {
        Thread.sleep(90000);
    } 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,代碼行數:23,代碼來源:TestMediaTraySelection.java

示例4: getPrintService

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
public static PrintService getPrintService(String printername) {
    
    // Initalize print service
    
    if (printername == null) {
        return PrintServiceLookup.lookupDefaultPrintService();       
    } else {
        
        if ("(Show dialog)".equals(printername)) {
            return null; // null means "you have to show the print dialog"
        } else if ("(Default)".equals(printername)) {
            return PrintServiceLookup.lookupDefaultPrintService(); 
        } else {
            PrintService[] pservices = 
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
            for (PrintService s : pservices) {    
                if (printername.equals(s.getName())) {
                    return s;
                }
            }
            return PrintServiceLookup.lookupDefaultPrintService();       
        }                
    }                 
}
 
開發者ID:iMartinezMateu,項目名稱:openbravo-pos,代碼行數:25,代碼來源:ReportUtils.java

示例5: getPrintService

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
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 != null) {
            try {
                setNativePrintService(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:27,代碼來源:WPrinterJob.java

示例6: out

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
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;
}
 
開發者ID:cping,項目名稱:RipplePower,代碼行數:21,代碼來源:PrintImageOutput.java

示例7: getPrintService

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
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 != null) {
            try {
                setNativePrintServiceIfNeeded(myService.getName());
            } catch (Exception e) {
                myService = null;
            }
        }

      }
      return myService;
}
 
開發者ID:greghaskins,項目名稱:openjdk-jdk7u-jdk,代碼行數:27,代碼來源:WPrinterJob.java

示例8: pageSetup

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
private int pageSetup(PrintService aService, 
                      PrintRequestAttributeSet requestAttrs) 
{
    myService = (aService == null)  
            ? PrintServiceLookup.lookupDefaultPrintService() 
            : aService;
    
    if ((requestAttrs == null) || (aService == null)) {
        return SETUP_ERROR;
    }
    
    attrs = requestAttrs;
    newAttrs = new HashPrintRequestAttributeSet(attrs);
    myService = aService;
    
    prepareDialog();        // prepare dialog
    fillPageSetupFields();  // Initialize dialog fields
    firstUse = false;
    return SETUP_OK;
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:21,代碼來源:ServiceUIDialog.java

示例9: initSelection

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
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 {
			for (MediaTray mt : mediaTrays) {
				if (mt.toString().equals(selTray)) {
					cvTrays.setSelection(new StructuredSelection(mt));
				}
			}
		}
	}
}
 
開發者ID:elexis,項目名稱:elexis-3-core,代碼行數:27,代碼來源:TextTemplatePrintSettingsDialog.java

示例10: getWin32PrintLUS

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:11,代碼來源:Win32PrintServiceLookup.java

示例11: getPrintService

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
@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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:WPrinterJob.java

示例12: trial

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
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());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:16,代碼來源:TestRaceCond.java

示例13: getWin32PrintLUS

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:PrintServiceLookupProvider.java

示例14: getPrintService

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
@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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:WPrinterJob.java

示例15: printTest

import javax.print.PrintServiceLookup; //導入方法依賴的package包/類
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]);
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:ServiceDlgSheetCollateTest.java


注:本文中的javax.print.PrintServiceLookup.lookupDefaultPrintService方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。