當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。