当前位置: 首页>>代码示例>>Java>>正文


Java PrinterName类代码示例

本文整理汇总了Java中javax.print.attribute.standard.PrinterName的典型用法代码示例。如果您正苦于以下问题:Java PrinterName类的具体用法?Java PrinterName怎么用?Java PrinterName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PrinterName类属于javax.print.attribute.standard包,在下文中一共展示了PrinterName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAttribute

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
public <T extends PrintServiceAttribute>
    T getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }

    if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:UnixPrintService.java

示例2: getAttribute

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
@Override
public <T extends PrintServiceAttribute>T getAttribute(Class<T> category){
    if(category == null){
        throw new NullPointerException("category");
    }
    if(!(PrintServiceAttribute.class.isAssignableFrom(category))){
        throw new IllegalArgumentException("The categhory '" + category + "' is not a valid PrintServiceAttribute");
    }
    if(category == ColorSupported.class){
    	// works better than settings.get_SupportsColor();
        if(settings.get_DefaultPageSettings().get_Color()){
            return (T)ColorSupported.SUPPORTED;
        }else{
            return (T)ColorSupported.NOT_SUPPORTED;
        }
    }else if(category == PrinterName.class){
        return (T)getPrinterName();
    } else {
        // QueuedJobCount and PrinterIsAcceptingJobs
        return (T)peer.getPrinterStatus(printer, category);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:Win32PrintService.java

示例3: PrintServiceStub

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:PrintServiceStub.java

示例4: getAttribute

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends PrintServiceAttribute>
    T getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }

    if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:UnixPrintService.java

示例5: main

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:GetPrintServices.java

示例6: create

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
@Override
public void create(String filename) {
	// find the printing service
	//http://www.coderanch.com/t/385989/java/java/send-raw-data-printer
	AttributeSet attributeSet = new HashAttributeSet();  
	attributeSet.add(new PrinterName(filename, null));
	PrintService[] services = PrintServiceLookup.lookupPrintServices(null, attributeSet);
	if(services.length > 0){
		if(printFile != null){
			printFile.deleteOnExit();
			printFile = null;
		}
		try {
			printFile = File.createTempFile("printer_"+name,".redirect");
		} catch (IOException e) {
			e.printStackTrace();
		}
		printService = services[0];
	}
	
}
 
开发者ID:thshdw,项目名称:lixia-javardp,代码行数:22,代码来源:Printer.java

示例7: printZpl

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
/**
 * Function to print code Zpl to local zebra(usb)
 * 
 * @param zpl
 *            code Zpl to print
 * @param ip
 *            ip adress
 * @param port
 *            port
 * @throws ZebraPrintException
 *             if zpl could not be printed
 */
public static void printZpl(String zpl, String printerName) throws ZebraPrintException {
	try {

		PrintService psZebra = null;
		String sPrinterName = null;
		PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);

		for (int i = 0; i < services.length; i++) {
			PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
			sPrinterName = ((PrinterName) attr).getValue();
			if (sPrinterName.toLowerCase().indexOf(printerName) >= 0) {
				psZebra = services[i];
				break;
			}
		}

		if (psZebra == null) {
			throw new ZebraPrintNotFoundException("Zebra printer not found : " + printerName);
		}
		DocPrintJob job = psZebra.createPrintJob();

		byte[] by = zpl.getBytes();
		DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
		Doc doc = new SimpleDoc(by, flavor, null);
		job.print(doc, null);

	} catch (PrintException e) {
		throw new ZebraPrintException("Cannot print label on this printer : " + printerName, e);
	}
}
 
开发者ID:w3blogfr,项目名称:zebra-zpl,代码行数:43,代码来源:ZebraUtils.java

示例8: endDoc

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
/**
 * Invoked by the RasterPrintJob super class
 * this method is called after that last page
 * has been imaged.
 */
protected void endDoc() throws PrinterException {
    if (mPSStream != null) {
        mPSStream.println(EOF_COMMENT);
        mPSStream.flush();
        if (mDestType != RasterPrinterJob.STREAM) {
            mPSStream.close();
        }
    }
    if (mDestType == RasterPrinterJob.PRINTER) {
        PrintService pServ = getPrintService();
        if (pServ != null) {
            mDestination = pServ.getName();
           if (isMac) {
                PrintServiceAttributeSet psaSet = pServ.getAttributes();
                if (psaSet != null) {
                    mDestination = psaSet.get(PrinterName.class).toString() ;
                }
            }
        }
        PrinterSpooler spooler = new PrinterSpooler();
        java.security.AccessController.doPrivileged(spooler);
        if (spooler.pex != null) {
            throw spooler.pex;
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:PSPrinterJob.java

示例9: getAttribute

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
public <T extends PrintServiceAttribute> T
    getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }
    if (category == ColorSupported.class) {
        int caps = getPrinterCapabilities();
        if ((caps & DEVCAP_COLOR) != 0) {
            return (T)ColorSupported.SUPPORTED;
        } else {
            return (T)ColorSupported.NOT_SUPPORTED;
        }
    } else if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:Win32PrintService.java

示例10: getServiceByName

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
private PrintService getServiceByName(PrinterName nameAttr) {
    String name = nameAttr.getValue();
    if (name == null || name.equals("") || !checkPrinterName(name)) {
        return null;
    }
    /* check if all printers are already available */
    if (printServices != null) {
        for (PrintService printService : printServices) {
            PrinterName printerName =
                (PrinterName)printService.getAttribute(PrinterName.class);
            if (printerName.getValue().equals(name)) {
                return printService;
            }
        }
    }
    /* take CUPS into account first */
    if (CUPSPrinter.isCupsRunning()) {
        try {
            return new IPPPrintService(name,
                                       new URL("http://"+
                                               CUPSPrinter.getServer()+":"+
                                               CUPSPrinter.getPort()+"/"+
                                               name));
        } catch (Exception e) {
            IPPPrintService.debug_println(debugPrefix+
                                          " getServiceByName Exception "+
                                          e);
        }
    }
    /* fallback if nothing not having a printer at this point */
    PrintService printer = null;
    if (isMac() || isSysV()) {
        printer = getNamedPrinterNameSysV(name);
    } else if (isAIX()) {
        printer = getNamedPrinterNameAIX(name);
    } else {
        printer = getNamedPrinterNameBSD(name);
    }
    return printer;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:UnixPrintServiceLookup.java

示例11: lookupByName

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:GetPrintServices.java

示例12: endDoc

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
/**
 * Invoked by the RasterPrintJob super class
 * this method is called after that last page
 * has been imaged.
 */
protected void endDoc() throws PrinterException {
    if (mPSStream != null) {
        mPSStream.println(EOF_COMMENT);
        mPSStream.flush();
        if (mPSStream.checkError()) {
            abortDoc();
            throw new PrinterException("Error while writing to file");
        }
        if (mDestType != RasterPrinterJob.STREAM) {
            mPSStream.close();
        }
    }
    if (mDestType == RasterPrinterJob.PRINTER) {
        PrintService pServ = getPrintService();
        if (pServ != null) {
            mDestination = pServ.getName();
           if (isMac) {
                PrintServiceAttributeSet psaSet = pServ.getAttributes();
                if (psaSet != null) {
                    mDestination = psaSet.get(PrinterName.class).toString() ;
                }
            }
        }
        PrinterSpooler spooler = new PrinterSpooler();
        java.security.AccessController.doPrivileged(spooler);
        if (spooler.pex != null) {
            throw spooler.pex;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:PSPrinterJob.java

示例13: getServiceByName

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
private PrintService getServiceByName(PrinterName nameAttr) {
    String name = nameAttr.getValue();
    if (name == null || name.equals("") || !checkPrinterName(name)) {
        return null;
    }
    /* check if all printers are already available */
    if (printServices != null) {
        for (PrintService printService : printServices) {
            PrinterName printerName = printService.getAttribute(PrinterName.class);
            if (printerName.getValue().equals(name)) {
                return printService;
            }
        }
    }
    /* take CUPS into account first */
    if (CUPSPrinter.isCupsRunning()) {
        try {
            return new IPPPrintService(name,
                                       new URL("http://"+
                                               CUPSPrinter.getServer()+":"+
                                               CUPSPrinter.getPort()+"/"+
                                               name));
        } catch (Exception e) {
            IPPPrintService.debug_println(debugPrefix+
                                          " getServiceByName Exception "+
                                          e);
        }
    }
    /* fallback if nothing not having a printer at this point */
    PrintService printer = null;
    if (isMac() || isSysV()) {
        printer = getNamedPrinterNameSysV(name);
    } else if (isAIX()) {
        printer = getNamedPrinterNameAIX(name);
    } else {
        printer = getNamedPrinterNameBSD(name);
    }
    return printer;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:PrintServiceLookupProvider.java

示例14: getAttribute

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends PrintServiceAttribute> T
    getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }
    if (category == ColorSupported.class) {
        int caps = getPrinterCapabilities();
        if ((caps & DEVCAP_COLOR) != 0) {
            return (T)ColorSupported.SUPPORTED;
        } else {
            return (T)ColorSupported.NOT_SUPPORTED;
        }
    } else if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:Win32PrintService.java

示例15: DummyPrintService

import javax.print.attribute.standard.PrinterName; //导入依赖的package包/类
public DummyPrintService(String name) {
    _name = name;
    _supportedFlavors = new HashSet<DocFlavor>();
    _supportedFlavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _supportedFlavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _printServiceAttributeSet = new HashPrintServiceAttributeSet();
    _printServiceAttributeSet.add(new PrinterName(name, null));
    _printServiceAttributeSet.add(PrinterState.IDLE);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:DummyPrintTest.java


注:本文中的javax.print.attribute.standard.PrinterName类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。