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


Java PrintRequestAttributeSet類代碼示例

本文整理匯總了Java中javax.print.attribute.PrintRequestAttributeSet的典型用法代碼示例。如果您正苦於以下問題:Java PrintRequestAttributeSet類的具體用法?Java PrintRequestAttributeSet怎麽用?Java PrintRequestAttributeSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: printDocument

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
public static void printDocument() throws IOException, PrinterException
{	
	
	PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

    pras.add(Sides.TWO_SIDED_SHORT_EDGE);
	PDDocument input = PDDocument.load(new File("Karteikarten.pdf"));
	
	PrinterJob job = PrinterJob.getPrinterJob();
	job.setPageable(new PDFPageable(input));
	if (job.printDialog(pras)) {
	    job.print(pras);
	}
	
}
 
開發者ID:CoffeeCodeSwitzerland,項目名稱:Lernkartei_2017,代碼行數:16,代碼來源:Printer.java

示例2: printWorksheetLevel

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
public void printWorksheetLevel() {
	PrinterJob print = PrinterJob.getPrinterJob();
	PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
	set.add(OrientationRequested.LANDSCAPE);
	print.setPrintable(oscilloscope);
	if(print.printDialog(set))
		try { print.print(); }
	catch(PrinterException e) {}
}
 
開發者ID:kristian,項目名稱:JDigitalSimulator,代碼行數:10,代碼來源:Application.java

示例3: _printCrossPlatform

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
/** Print using the cross platform dialog.
 *  FIXME: this dialog is slow and is often hidden
 *  behind other windows.  However, it does honor
 *  the user's choice of portrait vs. landscape
 */
protected void _printCrossPlatform() {
    // Build a set of attributes
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(plot);
    if (job.printDialog(aset)) {
        try {
            job.print(aset);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,
                    "Printing failed:\n" + ex.toString(),
                    "Print Error", JOptionPane.WARNING_MESSAGE);
        }
    }
}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:21,代碼來源:PlotFrame.java

示例4: pageableJob

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
public void pageableJob(Pageable pageable,
                        PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setPageable(pageable);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:PSStreamPrintJob.java

示例5: addPaperSize

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
private void addPaperSize(PrintRequestAttributeSet aset,
                          int dmIndex, int width, int length) {

    if (aset == null) {
        return;
    }
    MediaSizeName msn =
       ((Win32PrintService)myService).findWin32Media(dmIndex);
    if (msn == null) {
        msn = ((Win32PrintService)myService).
            findMatchingMediaSizeNameMM((float)width, (float)length);
    }

    if (msn != null) {
        aset.add(msn);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:WPrinterJob.java

示例6: setAttributes

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
@Override
protected void setAttributes(PrintRequestAttributeSet attributes) throws PrinterException {
    super.setAttributes(attributes);

    if (attributes == null) {
        return;
    }

    PageRanges pageRangesAttr =  (PageRanges)attributes.get(PageRanges.class);
    if (isSupportedValue(pageRangesAttr, attributes)) {
        SunPageSelection rangeSelect = (SunPageSelection)attributes.get(SunPageSelection.class);
        // If rangeSelect is not null, we are using AWT's print dialog that has
        // All, Selection, and Range radio buttons
        if (rangeSelect == null || rangeSelect == SunPageSelection.RANGE) {
            int[][] range = pageRangesAttr.getMembers();
            // setPageRange will set firstPage and lastPage as called in getFirstPage
            // and getLastPage
            setPageRange(range[0][0] - 1, range[0][1] - 1);
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:CPrinterJob.java

示例7: printWithoutPrintDialog

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
private static void printWithoutPrintDialog() {

        final JTable table = createAuthorTable(42);
        PrintRequestAttributeSet pras
                = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));

        try {

            boolean printAccepted = table.print(JTable.PrintMode.FIT_WIDTH,
                    new MessageFormat("Author Table"),
                    new MessageFormat("Page - {0}"),
                    false, pras, false);

            closeFrame();
            if (!printAccepted) {
                throw new RuntimeException("User cancels the printer job!");
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:ImageableAreaTest.java

示例8: setAttributes

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
@Override
protected void setAttributes(PrintRequestAttributeSet attributes)
                             throws PrinterException {
    super.setAttributes(attributes);
    if (attributes == null) {
        return; // now always use attributes, so this shouldn't happen.
    }
    Attribute attr = attributes.get(Media.class);
    if (attr instanceof CustomMediaTray) {
        CustomMediaTray customTray = (CustomMediaTray)attr;
        String choice = customTray.getChoiceName();
        if (choice != null) {
            mOptions = " InputSlot="+ choice;
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:PSPrinterJob.java

示例9: setAttributes

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
@Override
protected void setAttributes(PrintRequestAttributeSet attributes) throws PrinterException {
    super.setAttributes(attributes);

    if (attributes == null) {
        return;
    }

    PageRanges pageRangesAttr =  (PageRanges)attributes.get(PageRanges.class);
    if (isSupportedValue(pageRangesAttr, attributes)) {
        SunPageSelection rangeSelect = (SunPageSelection)attributes.get(SunPageSelection.class);
        // If rangeSelect is not null, we are using AWT's print dialog that has
        // All, Selection, and Range radio buttons
        if (rangeSelect == null || rangeSelect == SunPageSelection.RANGE) {
            int[][] range = pageRangesAttr.getMembers();
            // setPageRange will set firstPage and lastPage as called in getFirstPage
            // and getLastPage
            setPageRange(range[0][0] - 1, range[0][1] - 1);
        } else {
            // if rangeSelect is SunPageSelection.ALL
            // then setPageRange appropriately
            setPageRange(-1, -1);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:CPrinterJob.java

示例10: printWithoutPrintDialog

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
private static void printWithoutPrintDialog() {

        final JTable table = createAuthorTable(50);
        PrintRequestAttributeSet pras
                = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));

        try {

            boolean printAccepted = table.print(JTable.PrintMode.FIT_WIDTH,
                    new MessageFormat("Author Table"),
                    new MessageFormat("Page - {0}"),
                    false, pras, false);

            closeFrame();
            if (!printAccepted) {
                throw new RuntimeException("User cancels the printer job!");
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:ImageableAreaTest.java

示例11: doTest

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:WrongPaperPrintingTest.java

示例12: main

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
public static void main(String[] args) throws Exception {

        String[] instructions =
         {
             "Visual inspection of the dialog is needed. ",
             "It should be a Printer Job Setup Dialog",
             "Do nothing except Cancel",
             "You must NOT press OK",
         };
        SwingUtilities.invokeAndWait(() -> {
            JOptionPane.showMessageDialog(
                    (Component) null,
                    instructions,
                    "information", JOptionPane.INFORMATION_MESSAGE);
        });
        PrinterJob pj = PrinterJob.getPrinterJob();
        PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
        pSet.add(DialogTypeSelection.NATIVE);
        if ((pj.pageDialog(pSet)) != null) {
            throw
            new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)"
                        + " does not return null when dialog is cancelled");
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:PageDlgApp.java

示例13: printTest

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
private static void printTest() {

        MediaTray tray = null;
        //tray = getMediaTray( prservices, "Bypass Tray" );
        tray = getMediaTray( prservices, "Tray 4" );
        PrintRequestAttributeSet atrset = new HashPrintRequestAttributeSet();
        //atrset.add( MediaSizeName.ISO_A4 );
        atrset.add(tray);
        PrinterJob pjob = PrinterJob.getPrinterJob();
        pjob.setPrintable(new TestMediaTraySelection());
        try {
            pjob.print(atrset);
        } catch (PrinterException e) {
            e.printStackTrace();
            fail();
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:TestMediaTraySelection.java

示例14: print

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
public void print() {
    getPrintJob().setPrintable(this, getPage());

    boolean res;
    PrintRequestAttributeSet attr_set
            = new HashPrintRequestAttributeSet();
    if (page_range.x == 0) {
        res = getPrintJob().printDialog();
    } else {
        PrintRequestAttributeSet attr_set2
                = new HashPrintRequestAttributeSet();
        attr_set2.add(new PageRanges(page_range.x, page_range.y));
        res = getPrintJob().printDialog(attr_set2);
    }
    if (res) {
        try {
            getPrintJob().print(attr_set);
        } catch (PrinterException pe) {
            System.out.println("Error printing: " + pe);
        }
        //page = getPrintJob().getPageFormat(null);
    }

}
 
開發者ID:chcandido,項目名稱:brModelo,代碼行數:25,代碼來源:PrintControler.java

示例15: actionPerformed

import javax.print.attribute.PrintRequestAttributeSet; //導入依賴的package包/類
@Override
public void actionPerformed(ActionEvent e)
{
    try {
        if (selectedDriver == null)
            return;

        PrintService ps = (PrintService)printers.getSelectedItem();
        PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();

        attr.add(new Copies(1));
        attr.add((Media)ps.getDefaultAttributeValue(Media.class)); // set to default paper from printer
        attr.add(OrientationRequested.LANDSCAPE);

        SimpleDoc doc = new SimpleDoc(activeLabel, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
        ps.createPrintJob().print(doc, attr);
    }  catch (PrintException ex) {
        log.log(Level.SEVERE, "\bBarcode print failed: " + ex.getMessage(), ex);
    }
}
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:21,代碼來源:EntryPanel.java


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