Search in sources :

Example 1 with SunPageSelection

use of sun.print.SunPageSelection in project jdk8u_jdk by JetBrains.

the class PrintJob2D method updateAttributes.

private void updateAttributes() {
    Copies c = (Copies) attributes.get(Copies.class);
    jobAttributes.setCopies(c.getValue());
    SunPageSelection sel = (SunPageSelection) attributes.get(SunPageSelection.class);
    if (sel == SunPageSelection.RANGE) {
        jobAttributes.setDefaultSelection(DefaultSelectionType.RANGE);
    } else if (sel == SunPageSelection.SELECTION) {
        jobAttributes.setDefaultSelection(DefaultSelectionType.SELECTION);
    } else {
        jobAttributes.setDefaultSelection(DefaultSelectionType.ALL);
    }
    Destination dest = (Destination) attributes.get(Destination.class);
    if (dest != null) {
        jobAttributes.setDestination(DestinationType.FILE);
        jobAttributes.setFileName(dest.getURI().getPath());
    } else {
        jobAttributes.setDestination(DestinationType.PRINTER);
    }
    PrintService serv = printerJob.getPrintService();
    if (serv != null) {
        jobAttributes.setPrinter(serv.getName());
    }
    PageRanges range = (PageRanges) attributes.get(PageRanges.class);
    int[][] members = range.getMembers();
    jobAttributes.setPageRanges(members);
    SheetCollate collation = (SheetCollate) attributes.get(SheetCollate.class);
    if (collation == SheetCollate.COLLATED) {
        jobAttributes.setMultipleDocumentHandling(MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES);
    } else {
        jobAttributes.setMultipleDocumentHandling(MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);
    }
    Sides sides = (Sides) attributes.get(Sides.class);
    if (sides == Sides.TWO_SIDED_LONG_EDGE) {
        jobAttributes.setSides(SidesType.TWO_SIDED_LONG_EDGE);
    } else if (sides == Sides.TWO_SIDED_SHORT_EDGE) {
        jobAttributes.setSides(SidesType.TWO_SIDED_SHORT_EDGE);
    } else {
        jobAttributes.setSides(SidesType.ONE_SIDED);
    }
    // PageAttributes
    Chromaticity color = (Chromaticity) attributes.get(Chromaticity.class);
    if (color == Chromaticity.COLOR) {
        pageAttributes.setColor(ColorType.COLOR);
    } else {
        pageAttributes.setColor(ColorType.MONOCHROME);
    }
    OrientationRequested orient = (OrientationRequested) attributes.get(OrientationRequested.class);
    if (orient == OrientationRequested.LANDSCAPE) {
        pageAttributes.setOrientationRequested(OrientationRequestedType.LANDSCAPE);
    } else {
        pageAttributes.setOrientationRequested(OrientationRequestedType.PORTRAIT);
    }
    PrintQuality qual = (PrintQuality) attributes.get(PrintQuality.class);
    if (qual == PrintQuality.DRAFT) {
        pageAttributes.setPrintQuality(PrintQualityType.DRAFT);
    } else if (qual == PrintQuality.HIGH) {
        pageAttributes.setPrintQuality(PrintQualityType.HIGH);
    } else {
        // NORMAL
        pageAttributes.setPrintQuality(PrintQualityType.NORMAL);
    }
    Media msn = (Media) attributes.get(Media.class);
    if (msn != null && msn instanceof MediaSizeName) {
        MediaType mType = unMapMedia((MediaSizeName) msn);
        if (mType != null) {
            pageAttributes.setMedia(mType);
        }
    }
    debugPrintAttributes(false, false);
}
Also used : Destination(javax.print.attribute.standard.Destination) PageRanges(javax.print.attribute.standard.PageRanges) MediaSizeName(javax.print.attribute.standard.MediaSizeName) PrintQuality(javax.print.attribute.standard.PrintQuality) Media(javax.print.attribute.standard.Media) OrientationRequested(javax.print.attribute.standard.OrientationRequested) PrintService(javax.print.PrintService) SheetCollate(javax.print.attribute.standard.SheetCollate) Copies(javax.print.attribute.standard.Copies) SunPageSelection(sun.print.SunPageSelection) Chromaticity(javax.print.attribute.standard.Chromaticity) Sides(javax.print.attribute.standard.Sides)

Example 2 with SunPageSelection

use of sun.print.SunPageSelection in project jdk8u_jdk by JetBrains.

the class ServiceDialog method initPrintDialog.

/**
     * Initialize print dialog.
     */
void initPrintDialog(int x, int y, PrintService[] services, int defaultServiceIndex, DocFlavor flavor, PrintRequestAttributeSet attributes) {
    this.services = services;
    this.defaultServiceIndex = defaultServiceIndex;
    this.asOriginal = attributes;
    this.asCurrent = new HashPrintRequestAttributeSet(attributes);
    this.psCurrent = services[defaultServiceIndex];
    this.docFlavor = flavor;
    SunPageSelection pages = (SunPageSelection) attributes.get(SunPageSelection.class);
    if (pages != null) {
        isAWT = true;
    }
    if (attributes.get(DialogOnTop.class) != null) {
        setAlwaysOnTop(true);
    }
    Container c = getContentPane();
    c.setLayout(new BorderLayout());
    tpTabs = new JTabbedPane();
    tpTabs.setBorder(new EmptyBorder(5, 5, 5, 5));
    String gkey = getMsg("tab.general");
    int gmnemonic = getVKMnemonic("tab.general");
    pnlGeneral = new GeneralPanel();
    tpTabs.add(gkey, pnlGeneral);
    tpTabs.setMnemonicAt(0, gmnemonic);
    String pkey = getMsg("tab.pagesetup");
    int pmnemonic = getVKMnemonic("tab.pagesetup");
    pnlPageSetup = new PageSetupPanel();
    tpTabs.add(pkey, pnlPageSetup);
    tpTabs.setMnemonicAt(1, pmnemonic);
    String akey = getMsg("tab.appearance");
    int amnemonic = getVKMnemonic("tab.appearance");
    pnlAppearance = new AppearancePanel();
    tpTabs.add(akey, pnlAppearance);
    tpTabs.setMnemonicAt(2, amnemonic);
    c.add(tpTabs, BorderLayout.CENTER);
    updatePanels();
    JPanel pnlSouth = new JPanel(new FlowLayout(FlowLayout.TRAILING));
    btnApprove = createExitButton("button.print", this);
    pnlSouth.add(btnApprove);
    getRootPane().setDefaultButton(btnApprove);
    btnCancel = createExitButton("button.cancel", this);
    handleEscKey(btnCancel);
    pnlSouth.add(btnCancel);
    c.add(pnlSouth, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent event) {
            dispose(CANCEL);
        }
    });
    getAccessibleContext().setAccessibleDescription(getMsg("dialog.printtitle"));
    setResizable(false);
    setLocation(x, y);
    pack();
}
Also used : FlowLayout(java.awt.FlowLayout) WindowAdapter(java.awt.event.WindowAdapter) javax.print(javax.print) Container(java.awt.Container) BorderLayout(java.awt.BorderLayout) WindowEvent(java.awt.event.WindowEvent) SunPageSelection(sun.print.SunPageSelection) EmptyBorder(javax.swing.border.EmptyBorder)

Example 3 with SunPageSelection

use of sun.print.SunPageSelection in project jdk8u_jdk by JetBrains.

the class RasterPrinterJob method print.

public void print(PrintRequestAttributeSet attributes) throws PrinterException {
    /*
         * In the future PrinterJob will probably always dispatch
         * the print job to the PrintService.
         * This is how third party 2D Print Services will be invoked
         * when applications use the PrinterJob API.
         * However the JRE's concrete PrinterJob implementations have
         * not yet been re-worked to be implemented as standalone
         * services, and are implemented only as subclasses of PrinterJob.
         * So here we dispatch only those services we do not recognize
         * as implemented through platform subclasses of PrinterJob
         * (and this class).
         */
    PrintService psvc = getPrintService();
    debug_println("psvc = " + psvc);
    if (psvc == null) {
        throw new PrinterException("No print service found.");
    }
    // Check the list of services.  This service may have been
    // deleted already
    PrinterState prnState = (PrinterState) psvc.getAttribute(PrinterState.class);
    if (prnState == PrinterState.STOPPED) {
        PrinterStateReasons prnStateReasons = (PrinterStateReasons) psvc.getAttribute(PrinterStateReasons.class);
        if ((prnStateReasons != null) && (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN))) {
            throw new PrinterException("PrintService is no longer available.");
        }
    }
    if ((PrinterIsAcceptingJobs) (psvc.getAttribute(PrinterIsAcceptingJobs.class)) == PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS) {
        throw new PrinterException("Printer is not accepting job.");
    }
    if ((psvc instanceof SunPrinterJobService) && ((SunPrinterJobService) psvc).usesClass(getClass())) {
        setAttributes(attributes);
        // throw exception for invalid destination
        if (destinationAttr != null) {
            validateDestination(destinationAttr);
        }
    } else {
        spoolToService(psvc, attributes);
        return;
    }
    /* We need to make sure that the collation and copies
         * settings are initialised */
    initPrinter();
    int numCollatedCopies = getCollatedCopies();
    int numNonCollatedCopies = getNoncollatedCopies();
    debug_println("getCollatedCopies()  " + numCollatedCopies + " getNoncollatedCopies() " + numNonCollatedCopies);
    /* Get the range of pages we are to print. If the
         * last page to print is unknown, then we print to
         * the end of the document. Note that firstPage
         * and lastPage are 0 based page indices.
         */
    int numPages = mDocument.getNumberOfPages();
    if (numPages == 0) {
        return;
    }
    int firstPage = getFirstPage();
    int lastPage = getLastPage();
    if (lastPage == Pageable.UNKNOWN_NUMBER_OF_PAGES) {
        int totalPages = mDocument.getNumberOfPages();
        if (totalPages != Pageable.UNKNOWN_NUMBER_OF_PAGES) {
            lastPage = mDocument.getNumberOfPages() - 1;
        }
    }
    try {
        synchronized (this) {
            performingPrinting = true;
            userCancelled = false;
        }
        startDoc();
        if (isCancelled()) {
            cancelDoc();
        }
        // PageRanges can be set even if RANGE is not selected
        // so we need to check if it is selected.
        boolean rangeIsSelected = true;
        if (attributes != null) {
            SunPageSelection pages = (SunPageSelection) attributes.get(SunPageSelection.class);
            if ((pages != null) && (pages != SunPageSelection.RANGE)) {
                rangeIsSelected = false;
            }
        }
        debug_println("after startDoc rangeSelected? " + rangeIsSelected + " numNonCollatedCopies " + numNonCollatedCopies);
        /* Three nested loops iterate over the document. The outer loop
             * counts the number of collated copies while the inner loop
             * counts the number of nonCollated copies. Normally, one of
             * these two loops will only execute once; that is we will
             * either print collated copies or noncollated copies. The
             * middle loop iterates over the pages.
             * If a PageRanges attribute is used, it constrains the pages
             * that are imaged. If a platform subclass (though a user dialog)
             * requests a page range via setPageRange(). it too can
             * constrain the page ranges that are imaged.
             * It is expected that only one of these will be used in a
             * job but both should be able to co-exist.
             */
        for (int collated = 0; collated < numCollatedCopies; collated++) {
            for (int i = firstPage, pageResult = Printable.PAGE_EXISTS; (i <= lastPage || lastPage == Pageable.UNKNOWN_NUMBER_OF_PAGES) && pageResult == Printable.PAGE_EXISTS; i++) {
                if ((pageRangesAttr != null) && rangeIsSelected) {
                    int nexti = pageRangesAttr.next(i);
                    if (nexti == -1) {
                        break;
                    } else if (nexti != i + 1) {
                        continue;
                    }
                }
                for (int nonCollated = 0; nonCollated < numNonCollatedCopies && pageResult == Printable.PAGE_EXISTS; nonCollated++) {
                    if (isCancelled()) {
                        cancelDoc();
                    }
                    debug_println("printPage " + i);
                    pageResult = printPage(mDocument, i);
                }
            }
        }
        if (isCancelled()) {
            cancelDoc();
        }
    } finally {
        // reset previousPaper in case this job is invoked again.
        previousPaper = null;
        synchronized (this) {
            if (performingPrinting) {
                endDoc();
            }
            performingPrinting = false;
            notify();
        }
    }
}
Also used : PrinterState(javax.print.attribute.standard.PrinterState) PrinterStateReasons(javax.print.attribute.standard.PrinterStateReasons) SunPrinterJobService(sun.print.SunPrinterJobService) SunPageSelection(sun.print.SunPageSelection) PrinterException(java.awt.print.PrinterException) PrinterIsAcceptingJobs(javax.print.attribute.standard.PrinterIsAcceptingJobs) PrintService(javax.print.PrintService) StreamPrintService(javax.print.StreamPrintService)

Aggregations

SunPageSelection (sun.print.SunPageSelection)3 PrintService (javax.print.PrintService)2 BorderLayout (java.awt.BorderLayout)1 Container (java.awt.Container)1 FlowLayout (java.awt.FlowLayout)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 PrinterException (java.awt.print.PrinterException)1 javax.print (javax.print)1 StreamPrintService (javax.print.StreamPrintService)1 Chromaticity (javax.print.attribute.standard.Chromaticity)1 Copies (javax.print.attribute.standard.Copies)1 Destination (javax.print.attribute.standard.Destination)1 Media (javax.print.attribute.standard.Media)1 MediaSizeName (javax.print.attribute.standard.MediaSizeName)1 OrientationRequested (javax.print.attribute.standard.OrientationRequested)1 PageRanges (javax.print.attribute.standard.PageRanges)1 PrintQuality (javax.print.attribute.standard.PrintQuality)1 PrinterIsAcceptingJobs (javax.print.attribute.standard.PrinterIsAcceptingJobs)1 PrinterState (javax.print.attribute.standard.PrinterState)1