Java 类javax.print.attribute.PrintRequestAttributeSet 实例源码

项目:Lernkartei_2017    文件:Printer.java   
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);
    }

}
项目:OpenDA    文件:PlotFrame.java   
/** 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);
        }
    }
}
项目:OpenJSharp    文件:PSStreamPrintJob.java   
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;
    }
}
项目:OpenJSharp    文件:WPrinterJob.java   
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);
    }
}
项目:jdk8u-jdk    文件:PSStreamPrintJob.java   
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;
    }
}
项目:jdk8u-jdk    文件:CPrinterJob.java   
@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);
        }
    }
}
项目:jdk8u-jdk    文件:WPrinterJob.java   
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);
    }
}
项目:jdk8u-jdk    文件:ImageableAreaTest.java   
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);
        }
    }
项目:openjdk-jdk10    文件:PSStreamPrintJob.java   
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;
    }
}
项目:openjdk-jdk10    文件:PSPrinterJob.java   
@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;
        }
    }
}
项目:openjdk-jdk10    文件:CPrinterJob.java   
@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);
        }
    }
}
项目:openjdk-jdk10    文件:WPrinterJob.java   
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);
    }
}
项目:openjdk-jdk10    文件:ImageableAreaTest.java   
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);
        }
    }
项目:openjdk-jdk10    文件:WrongPaperPrintingTest.java   
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);
        }
    }
}
项目:openjdk-jdk10    文件:PageDlgApp.java   
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");
        }
    }
项目:openjdk-jdk10    文件:TestMediaTraySelection.java   
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();
        }
    }
项目:brModelo    文件:PrintControler.java   
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);
    }

}
项目:scorekeeperfrontend    文件:EntryPanel.java   
@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);
    }
}
项目:openjdk9    文件:PSStreamPrintJob.java   
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;
    }
}
项目:openjdk9    文件:WPrinterJob.java   
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);
    }
}
项目:openjdk9    文件:ImageableAreaTest.java   
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);
        }
    }
项目:openjdk9    文件:PageDlgApp.java   
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");
        }
    }
项目:spring-boot    文件:PrintTest.java   
private void printText2Action()
{
    printStr = area.getText().trim();
    if(printStr != null && printStr.length() > 0)
    {
        PAGES = getPagesCount(printStr);
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
        DocPrintJob job = printService.createPrintJob();
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        DocAttributeSet das = new HashDocAttributeSet();
        Doc doc = new SimpleDoc(this, flavor, das);
        try
        {
            job.print(doc, pras);
        }
        catch(PrintException pe)
        {
            pe.printStackTrace();
        }
    } else
    {
        JOptionPane.showConfirmDialog(null, "Sorry, Printer Job is Empty, Print Cancelled!", "Empty", -1, 2);
    }
}
项目:jasperreports    文件:PrintServiceApp.java   
/**
 *
 */
public void print() throws JRException
{
    long start = System.currentTimeMillis();
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    printRequestAttributeSet.add(MediaSizeName.ISO_A4);

    PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
    //printServiceAttributeSet.add(new PrinterName("Epson Stylus 820 ESC/P 2", null));
    //printServiceAttributeSet.add(new PrinterName("hp LaserJet 1320 PCL 6", null));
    //printServiceAttributeSet.add(new PrinterName("PDFCreator", null));

    JRPrintServiceExporter exporter = new JRPrintServiceExporter();

    exporter.setExporterInput(new SimpleExporterInput("build/reports/PrintServiceReport.jrprint"));
    SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();
    configuration.setPrintRequestAttributeSet(printRequestAttributeSet);
    configuration.setPrintServiceAttributeSet(printServiceAttributeSet);
    configuration.setDisplayPageDialog(false);
    configuration.setDisplayPrintDialog(true);
    exporter.setConfiguration(configuration);
    exporter.exportReport();

    System.err.println("Printing time : " + (System.currentTimeMillis() - start));
}
项目:erp    文件:ImprimeLayout.java   
public boolean imprimir(boolean bMonta) {
    if (bMonta)
        montaG();

    boolean bRet = false;
    PrinterJob printJob = PrinterJob.getPrinterJob();
    PrintRequestAttributeSet aset = Funcoes.getImpAtrib();
    if (printJob.printDialog(aset)) {
        try {
            printJob.setPrintable(this, new PaginaPad(printJob.defaultPage().getPaper()));
            printJob.print(aset);
            aset.remove(Copies.class);

            Funcoes.setImpAtrib(aset);
            bRet = true;
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    return bRet;
}
项目:erp    文件:Funcoes.java   
public static void setImpAtrib(PrintRequestAttributeSet p) {
    HashPrintRequestAttributeSet pra = ( HashPrintRequestAttributeSet ) p;
    File fArq = new File("impres.cfg");
    try {
        if (!fArq.exists())
            if (!fArq.createNewFile())
                return;
        FileOutputStream foArq = new FileOutputStream(fArq);
        ObjectOutputStream obj = new ObjectOutputStream(foArq);
        obj.writeObject(pra);
        obj.flush();
        foArq.close();
    }
    catch (IOException err) {
        err.printStackTrace();
    }
}
项目:jdk8u_jdk    文件:PSStreamPrintJob.java   
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;
    }
}
项目:Camel    文件:PrinterProducer.java   
private PrintRequestAttributeSet assignPrintAttributes() throws PrintException {
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    if (config.getCopies() >= 1) {
        printRequestAttributeSet.add(new Copies(config.getCopies()));
    } else {
        throw new PrintException("Number of print copies should be greater than zero");
    }
    printRequestAttributeSet.add(config.getMediaSizeName());
    printRequestAttributeSet.add(config.getInternalSides());
    printRequestAttributeSet.add(config.getInternalOrientation());

    if (config.getMediaTray() != null) {
        MediaTray mediaTray = resolveMediaTray(config.getMediaTray());

        if (mediaTray == null) {
            throw new PrintException("mediatray not found " + config.getMediaTray());
        }

        printRequestAttributeSet.add(mediaTray);
    }

    return printRequestAttributeSet;
}
项目:jdk8u_jdk    文件:WPrinterJob.java   
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);
    }
}
项目:jdk8u_jdk    文件:ImageableAreaTest.java   
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);
        }
    }
项目:jdk8u_jdk    文件:PageDlgApp.java   
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");
        }
    }
项目:lookaside_java-1.8.0-openjdk    文件:PSStreamPrintJob.java   
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;
    }
}
项目:Maxent    文件:PlotFrame.java   
/** 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);
        }
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:WPrinterJob.java   
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);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:ImageableAreaTest.java   
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);
        }
    }
项目:rapidminer    文件:PrintingTools.java   
/**
 * @return <code>true</code> on success. <code>false</code> if user aborts printing.
 */
public static boolean print(Printable printable, PrintRequestAttributeSet printSettings) throws PrinterException {
    getPrinterJob().setPrintable(printable);
    if (getPrinterJob().printDialog(printSettings)) {
        PrintingTools.getPrinterJob().print(printSettings);
        return true;
    } else {
        return false;
    }
}
项目:JDigitalSimulator    文件:Application.java   
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) {}
}
项目:OpenJSharp    文件:PSStreamPrintJob.java   
public void printableJob(Printable printable,
                         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());
        PageFormat pf = new PageFormat();
        if (mediaSize != null) {
            Paper p = new Paper();
            p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
                      mediaSize.getY(MediaSize.INCH)*72.0);
            p.setImageableArea(72.0, 72.0, p.getWidth()-144.0,
                               p.getHeight()-144.0);
            pf.setPaper(p);
        }
        if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
            pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        } else if (orient == OrientationRequested.LANDSCAPE) {
            pf.setOrientation(PageFormat.LANDSCAPE);
        }
        job.setPrintable(printable, pf);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
项目:OpenJSharp    文件:RasterPrinterJob.java   
protected boolean isSupportedValue(Attribute attrval,
                                 PrintRequestAttributeSet attrset) {
    PrintService ps = getPrintService();
    return
        (attrval != null && ps != null &&
         ps.isAttributeValueSupported(attrval,
                                      DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                      attrset));
}
项目:OpenJSharp    文件:CPrinterJob.java   
@Override
protected void setAttributes(PrintRequestAttributeSet attributes) throws PrinterException {
    super.setAttributes(attributes);

    if (attributes == null) {
        return;
    }

    // See if this has an NSPrintInfo in it.
    NSPrintInfo nsPrintInfo = (NSPrintInfo)attributes.get(NSPrintInfo.class);
    if (nsPrintInfo != null) {
        fNSPrintInfo = nsPrintInfo.getValue();
    }

    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);
        }
    }
}