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


Java HashPrintRequestAttributeSet.add方法代码示例

本文整理汇总了Java中javax.print.attribute.HashPrintRequestAttributeSet.add方法的典型用法代码示例。如果您正苦于以下问题:Java HashPrintRequestAttributeSet.add方法的具体用法?Java HashPrintRequestAttributeSet.add怎么用?Java HashPrintRequestAttributeSet.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.print.attribute.HashPrintRequestAttributeSet的用法示例。


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

示例1: main

import javax.print.attribute.HashPrintRequestAttributeSet; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:PrintAttributeUpdateTest.java

示例2: print

import javax.print.attribute.HashPrintRequestAttributeSet; //导入方法依赖的package包/类
/**
 * 	Print (async)
 * 	@param printerName optional printer name
 *  @param jobName optional printer job name
 * 	@param pageable pageable
 *  @param copies number of copies
 *  @param withDialog if true, shows printer dialog
 */
static public void print (Pageable pageable, String printerName, String jobName,
	int copies, boolean withDialog)
{
	if (pageable == null)
		return;
	String name = "Adempiere_";
	if (jobName != null)
		name += jobName;
	//
	PrinterJob job = CPrinter.getPrinterJob(printerName);
	job.setJobName (name);
	job.setPageable (pageable);
	//	Attributes
	HashPrintRequestAttributeSet prats = new HashPrintRequestAttributeSet();
	prats.add(new Copies(copies));
	//	Set Orientation
	if (pageable.getPageFormat(0).getOrientation() == PageFormat.PORTRAIT)
		prats.add(OrientationRequested.PORTRAIT);
	else
		prats.add(OrientationRequested.LANDSCAPE);
	prats.add(new JobName(name, Language.getLoginLanguage().getLocale()));
	prats.add(getJobPriority(pageable.getNumberOfPages(), copies, withDialog));
	//
	print (job, prats, withDialog, false);
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:34,代码来源:PrintUtil.java

示例3: main

import javax.print.attribute.HashPrintRequestAttributeSet; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:PrintCrashTest.java

示例4: printTest

import javax.print.attribute.HashPrintRequestAttributeSet; //导入方法依赖的package包/类
private static void printTest() {
    PrintService defService = null, service[] = null;
    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;

    service = PrintServiceLookup.lookupPrintServices(flavor, null);
    defService = PrintServiceLookup.lookupDefaultPrintService();

    if ((service == null) || (service.length == 0)) {
        throw new RuntimeException("No Printer services found");
    }
    File f = new File("output.ps");
    Destination d = new Destination(f.toURI());
    prSet.add(d);
    if (defService != null) {
        System.out.println("isAttrCategory Supported? " +
                defService.isAttributeCategorySupported(Destination.class));
        System.out.println("isAttrValue Supported? " +
                defService.isAttributeValueSupported(d, flavor, null));
    }

    defService = ServiceUI.printDialog(null, 100, 100, service, defService,
            flavor, prSet);

    ServiceUI.printDialog(null, 100, 100, service, defService,
            DocFlavor.SERVICE_FORMATTED.PAGEABLE,
            new HashPrintRequestAttributeSet());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ServiceDialogValidateTest.java

示例5: run

import javax.print.attribute.HashPrintRequestAttributeSet; //导入方法依赖的package包/类
public void run()
{
    HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(2)); // silly request but cuts out fax, xps, etc.
    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, aset);
    for (PrintService ps : printServices) {
        log.log(Level.INFO, "Found printer: {0}", ps);
        printers.addItem(ps);
        if (ps.getName().equals(Prefs.getDefaultPrinter()))
            printers.setSelectedItem(ps);
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:13,代码来源:EntryPanel.java

示例6: PrinterOperations

import javax.print.attribute.HashPrintRequestAttributeSet; //导入方法依赖的package包/类
public PrinterOperations() throws PrintException {        
    printService = PrintServiceLookup.lookupDefaultPrintService();
    if (printService == null) {
        throw new PrintException("Printer lookup failure. No default printer set up for this host");
    }
    flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
    printRequestAttributeSet = new HashPrintRequestAttributeSet();
    printRequestAttributeSet.add(new Copies(1));
    printRequestAttributeSet.add(MediaSizeName.NA_LETTER);
    printRequestAttributeSet.add(Sides.ONE_SIDED);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:PrinterOperations.java

示例7: getAttrsForPageFormat

import javax.print.attribute.HashPrintRequestAttributeSet; //导入方法依赖的package包/类
protected HashPrintRequestAttributeSet 
        getAttrsForPageFormat(PageFormat page) {

    HashPrintRequestAttributeSet lattrs=new HashPrintRequestAttributeSet();

    /* Add Orientation attribute */
    switch (page.getOrientation()) {
        case PageFormat.LANDSCAPE:
            lattrs.add(OrientationRequested.LANDSCAPE);
            break;
        case PageFormat.PORTRAIT:
            lattrs.add(OrientationRequested.PORTRAIT);
            break;
        case PageFormat.REVERSE_LANDSCAPE:
            lattrs.add(OrientationRequested.REVERSE_LANDSCAPE);
            break;
    }

    /* Add Media attribute */
    MediaSizeName media = MediaSize.findMedia(
            (float) (page.getWidth() / 72.0),
            (float) (page.getHeight() / 72.0), 
            Size2DSyntax.INCH);
    if (media != null) {
        lattrs.add(media);
    }

    /* Add MediaMargins attribute */
    lattrs.add(new MediaMargins((float) (page.getImageableX() / 72.0), 
            (float) (page.getImageableY() / 72.0), 
            (float) ((page.getWidth() - page.getImageableX() -
                    page.getImageableWidth()) / 72.0),
            (float) ((page.getHeight() - page.getImageableHeight() -
                    page.getImageableY()) / 72.0), 
            MediaMargins.INCH));

    return lattrs;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:39,代码来源:PSPrinterJob.java

示例8: CommonPrinter

import javax.print.attribute.HashPrintRequestAttributeSet; //导入方法依赖的package包/类
/************************************************************************
 * 按照默认配置设置打印机
 * 打印1份,按照默认的HTML格式打印
 */
public CommonPrinter(){
	attributeSet = new HashPrintRequestAttributeSet();
	attributeSet.add(new Copies(this.copyNum));
}
 
开发者ID:hanwwh,项目名称:xqres,代码行数:9,代码来源:CommonPrinter.java

示例9: PrintHelper

import javax.print.attribute.HashPrintRequestAttributeSet; //导入方法依赖的package包/类
/**
 * Creates a new <code>PrintHelper</code> instance using the specified
 * media sized and print quality.
 *
 * @param container     parent container uses to center print dialog.
 * @param pageTree      document page tree.
 * @param rotation      rotation at witch to paint document.
 * @param paperSizeName MediaSizeName constant of paper size to print to.
 * @param printQuality  quality of the print job, draft, quality etc.
 */
public PrintHelper(Container container, PageTree pageTree,
                   final float rotation,
                   final MediaSizeName paperSizeName,
                   final PrintQuality printQuality) {
    this.container = container;
    this.pageTree = pageTree;
    this.userRotation = rotation;

    // find available printers
    services = lookForPrintServices();

    // default printing properties.
    // Print and document attributes sets.
    printRequestAttributeSet =
            new HashPrintRequestAttributeSet();
    docAttributeSet = new HashDocAttributeSet();

    // assign print quality.
    printRequestAttributeSet.add(printQuality);

    // change paper
    printRequestAttributeSet.add(paperSizeName);
    docAttributeSet.add(paperSizeName);

    // setting margins to full paper size as PDF have their own margins
    MediaSize mediaSize =
            MediaSize.getMediaSizeForName(paperSizeName);
    float[] size = mediaSize.getSize(MediaSize.INCH);
    printRequestAttributeSet
            .add(new MediaPrintableArea(0, 0, size[0], size[1],
                    MediaPrintableArea.INCH));
    docAttributeSet.add(new MediaPrintableArea(0, 0, size[0], size[1],
            MediaPrintableArea.INCH));

    // default setup, all pages, shrink to fit and no dialog.
    setupPrintService(0, this.pageTree.getNumberOfPages(), 1, true, false);

    // display paper size.
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Paper Size: " + paperSizeName.getName() +
                " " + size[0] + " x " + size[1]);
    }
}
 
开发者ID:pdf4j,项目名称:icepdf,代码行数:54,代码来源:PrintHelper.java


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