本文整理汇总了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;
}
示例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();
}
}
}
示例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");
}
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}
}
}
}
示例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;
}
示例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;
}
示例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());
}
}
示例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;
}
示例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;
}
示例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]);
}
}