Search in sources :

Example 1 with Win32PrintService

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

the class WPrinterJob method pageDialog.

/* Instance Methods */
/**
     * Display a dialog to the user allowing the modification of a
     * PageFormat instance.
     * The <code>page</code> argument is used to initialize controls
     * in the page setup dialog.
     * If the user cancels the dialog, then the method returns the
     * original <code>page</code> object unmodified.
     * If the user okays the dialog then the method returns a new
     * PageFormat object with the indicated changes.
     * In either case the original <code>page</code> object will
     * not be modified.
     * @param     page    the default PageFormat presented to the user
     *                    for modification
     * @return    the original <code>page</code> object if the dialog
     *            is cancelled, or a new PageFormat object containing
     *            the format indicated by the user if the dialog is
     *            acknowledged
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
     * returns true.
     * @see java.awt.GraphicsEnvironment#isHeadless
     * @since     JDK1.2
     */
@Override
public PageFormat pageDialog(PageFormat page) throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
    if (!(getPrintService() instanceof Win32PrintService)) {
        return super.pageDialog(page);
    }
    PageFormat pageClone = (PageFormat) page.clone();
    boolean result = false;
    /*
         * Fix for 4507585: show the native modal dialog the same way printDialog() does so
         * that it won't block event dispatching when called on EventDispatchThread.
         */
    WPageDialog dialog = new WPageDialog((Frame) null, this, pageClone, null);
    dialog.setRetVal(false);
    dialog.setVisible(true);
    result = dialog.getRetVal();
    dialog.dispose();
    // myService => current PrintService
    if (result && (myService != null)) {
        // It's possible that current printer is changed through
        // the "Printer..." button so we query again from native.
        String printerName = getNativePrintService();
        if (!myService.getName().equals(printerName)) {
            // we update the current PrintService
            try {
                setPrintService(Win32PrintServiceLookup.getWin32PrintLUS().getPrintServiceByName(printerName));
            } catch (PrinterException e) {
            }
        }
        // Update attributes, this will preserve the page settings.
        //  - same code as in RasterPrinterJob.java
        updatePageAttributes(myService, pageClone);
        return pageClone;
    } else {
        return page;
    }
}
Also used : Win32PrintService(sun.print.Win32PrintService) PageFormat(java.awt.print.PageFormat) HeadlessException(java.awt.HeadlessException) PrinterException(java.awt.print.PrinterException)

Example 2 with Win32PrintService

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

the class WPrinterJob method setMediaTrayAttrib.

private void setMediaTrayAttrib(int dmBinID) {
    mAttMediaTray = dmBinID;
    MediaTray tray = ((Win32PrintService) myService).findMediaTray(dmBinID);
}
Also used : Win32PrintService(sun.print.Win32PrintService) Win32MediaTray(sun.print.Win32MediaTray) MediaTray(javax.print.attribute.standard.MediaTray)

Example 3 with Win32PrintService

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

the class WPrinterJob method getDevModeValues.

private void getDevModeValues(PrintRequestAttributeSet aset, DevModeValues info) {
    Copies c = (Copies) aset.get(Copies.class);
    if (c != null) {
        info.dmFields |= DM_COPIES;
        info.copies = (short) c.getValue();
    }
    SheetCollate sc = (SheetCollate) aset.get(SheetCollate.class);
    if (sc != null) {
        info.dmFields |= DM_COLLATE;
        info.collate = (sc == SheetCollate.COLLATED) ? DMCOLLATE_TRUE : DMCOLLATE_FALSE;
    }
    Chromaticity ch = (Chromaticity) aset.get(Chromaticity.class);
    if (ch != null) {
        info.dmFields |= DM_COLOR;
        if (ch == Chromaticity.COLOR) {
            info.color = DMCOLOR_COLOR;
        } else {
            info.color = DMCOLOR_MONOCHROME;
        }
    }
    Sides s = (Sides) aset.get(Sides.class);
    if (s != null) {
        info.dmFields |= DM_DUPLEX;
        if (s == Sides.TWO_SIDED_LONG_EDGE) {
            info.duplex = DMDUP_VERTICAL;
        } else if (s == Sides.TWO_SIDED_SHORT_EDGE) {
            info.duplex = DMDUP_HORIZONTAL;
        } else {
            // Sides.ONE_SIDED
            info.duplex = DMDUP_SIMPLEX;
        }
    }
    OrientationRequested or = (OrientationRequested) aset.get(OrientationRequested.class);
    if (or != null) {
        info.dmFields |= DM_ORIENTATION;
        info.orient = (or == OrientationRequested.LANDSCAPE) ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
    }
    Media m = (Media) aset.get(Media.class);
    if (m instanceof MediaSizeName) {
        info.dmFields |= DM_PAPERSIZE;
        MediaSizeName msn = (MediaSizeName) m;
        info.paper = (short) ((Win32PrintService) myService).findPaperID(msn);
    }
    MediaTray mt = null;
    if (m instanceof MediaTray) {
        mt = (MediaTray) m;
    }
    if (mt == null) {
        SunAlternateMedia sam = (SunAlternateMedia) aset.get(SunAlternateMedia.class);
        if (sam != null && (sam.getMedia() instanceof MediaTray)) {
            mt = (MediaTray) sam.getMedia();
        }
    }
    if (mt != null) {
        info.dmFields |= DM_DEFAULTSOURCE;
        info.bin = (short) (((Win32PrintService) myService).findTrayID(mt));
    }
    PrintQuality q = (PrintQuality) aset.get(PrintQuality.class);
    if (q != null) {
        info.dmFields |= DM_PRINTQUALITY;
        if (q == PrintQuality.DRAFT) {
            info.xres_quality = DMRES_DRAFT;
        } else if (q == PrintQuality.HIGH) {
            info.xres_quality = DMRES_HIGH;
        } else {
            info.xres_quality = DMRES_MEDIUM;
        }
    }
    PrinterResolution r = (PrinterResolution) aset.get(PrinterResolution.class);
    if (r != null) {
        info.dmFields |= DM_PRINTQUALITY | DM_YRESOLUTION;
        info.xres_quality = (short) r.getCrossFeedResolution(PrinterResolution.DPI);
        info.yres = (short) r.getFeedResolution(PrinterResolution.DPI);
    }
}
Also used : Win32PrintService(sun.print.Win32PrintService) PrinterResolution(javax.print.attribute.standard.PrinterResolution) SheetCollate(javax.print.attribute.standard.SheetCollate) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Copies(javax.print.attribute.standard.Copies) PrintQuality(javax.print.attribute.standard.PrintQuality) Media(javax.print.attribute.standard.Media) SunAlternateMedia(sun.print.SunAlternateMedia) Chromaticity(javax.print.attribute.standard.Chromaticity) SunAlternateMedia(sun.print.SunAlternateMedia) Win32MediaTray(sun.print.Win32MediaTray) MediaTray(javax.print.attribute.standard.MediaTray) Sides(javax.print.attribute.standard.Sides) OrientationRequested(javax.print.attribute.standard.OrientationRequested)

Example 4 with Win32PrintService

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

the class WPrinterJob method setJobAttributes.

/* This method is called from native to update the values in the
     * attribute set which originates from the cross-platform dialog,
     * but updated by the native DocumentPropertiesUI which updates the
     * devmode. This syncs the devmode back in to the attributes so that
     * we can update the cross-platform dialog.
     * The attribute set here is a temporary one installed whilst this
     * happens,
     */
private final void setJobAttributes(PrintRequestAttributeSet attributes, int fields, int values, short copies, short dmPaperSize, short dmPaperWidth, short dmPaperLength, short dmDefaultSource, short xRes, short yRes) {
    if (attributes == null) {
        return;
    }
    if ((fields & DM_COPIES) != 0) {
        attributes.add(new Copies(copies));
    }
    if ((fields & DM_COLLATE) != 0) {
        if ((values & SET_COLLATED) != 0) {
            attributes.add(SheetCollate.COLLATED);
        } else {
            attributes.add(SheetCollate.UNCOLLATED);
        }
    }
    if ((fields & DM_ORIENTATION) != 0) {
        if ((values & SET_ORIENTATION) != 0) {
            attributes.add(OrientationRequested.LANDSCAPE);
        } else {
            attributes.add(OrientationRequested.PORTRAIT);
        }
    }
    if ((fields & DM_COLOR) != 0) {
        if ((values & SET_COLOR) != 0) {
            attributes.add(Chromaticity.COLOR);
        } else {
            attributes.add(Chromaticity.MONOCHROME);
        }
    }
    if ((fields & DM_PRINTQUALITY) != 0) {
        /* value < 0 indicates quality setting.
             * value > 0 indicates X resolution. In that case
             * hopefully we will also find y-resolution specified.
             * If its not, assume its the same as x-res.
             * Maybe Java code should try to reconcile this against
             * the printers claimed set of supported resolutions.
             */
        if (xRes < 0) {
            PrintQuality quality;
            if ((values & SET_RES_LOW) != 0) {
                quality = PrintQuality.DRAFT;
            } else if ((fields & SET_RES_HIGH) != 0) {
                quality = PrintQuality.HIGH;
            } else {
                quality = PrintQuality.NORMAL;
            }
            attributes.add(quality);
        } else if (xRes > 0 && yRes > 0) {
            attributes.add(new PrinterResolution(xRes, yRes, PrinterResolution.DPI));
        }
    }
    if ((fields & DM_DUPLEX) != 0) {
        Sides sides;
        if ((values & SET_DUP_VERTICAL) != 0) {
            sides = Sides.TWO_SIDED_LONG_EDGE;
        } else if ((values & SET_DUP_HORIZONTAL) != 0) {
            sides = Sides.TWO_SIDED_SHORT_EDGE;
        } else {
            sides = Sides.ONE_SIDED;
        }
        attributes.add(sides);
    }
    if ((fields & DM_PAPERSIZE) != 0) {
        addPaperSize(attributes, dmPaperSize, dmPaperWidth, dmPaperLength);
    }
    if ((fields & DM_DEFAULTSOURCE) != 0) {
        MediaTray tray = ((Win32PrintService) myService).findMediaTray(dmDefaultSource);
        attributes.add(new SunAlternateMedia(tray));
    }
}
Also used : Win32PrintService(sun.print.Win32PrintService) PrinterResolution(javax.print.attribute.standard.PrinterResolution) Copies(javax.print.attribute.standard.Copies) PrintQuality(javax.print.attribute.standard.PrintQuality) SunAlternateMedia(sun.print.SunAlternateMedia) Win32MediaTray(sun.print.Win32MediaTray) MediaTray(javax.print.attribute.standard.MediaTray) Sides(javax.print.attribute.standard.Sides)

Aggregations

Win32PrintService (sun.print.Win32PrintService)4 MediaTray (javax.print.attribute.standard.MediaTray)3 Win32MediaTray (sun.print.Win32MediaTray)3 Copies (javax.print.attribute.standard.Copies)2 PrintQuality (javax.print.attribute.standard.PrintQuality)2 PrinterResolution (javax.print.attribute.standard.PrinterResolution)2 Sides (javax.print.attribute.standard.Sides)2 SunAlternateMedia (sun.print.SunAlternateMedia)2 HeadlessException (java.awt.HeadlessException)1 PageFormat (java.awt.print.PageFormat)1 PrinterException (java.awt.print.PrinterException)1 Chromaticity (javax.print.attribute.standard.Chromaticity)1 Media (javax.print.attribute.standard.Media)1 MediaSizeName (javax.print.attribute.standard.MediaSizeName)1 OrientationRequested (javax.print.attribute.standard.OrientationRequested)1 SheetCollate (javax.print.attribute.standard.SheetCollate)1