Search in sources :

Example 6 with MediaSizeName

use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.

the class WPrinterJob method setWin32MediaAttrib.

private void setWin32MediaAttrib(Attribute attr) {
    if (!(attr instanceof MediaSizeName)) {
        return;
    }
    MediaSizeName msn = (MediaSizeName) attr;
    mAttMediaSizeName = ((Win32PrintService) myService).findPaperID(msn);
}
Also used : MediaSizeName(javax.print.attribute.standard.MediaSizeName)

Example 7 with MediaSizeName

use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.

the class Win32PrintJob method printableJob.

public void printableJob(Printable printable) throws PrintException {
    try {
        synchronized (this) {
            if (job != null) {
                // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies) svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        if (mediaName == null) {
            Object media = svc.getDefaultAttributeValue(Media.class);
            if (media instanceof MediaSizeName) {
                mediaName = (MediaSizeName) media;
                mediaSize = MediaSize.getMediaSizeForName(mediaName);
            }
        }
        if (orient == null) {
            orient = (OrientationRequested) svc.getDefaultAttributeValue(OrientationRequested.class);
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        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(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
Also used : PrintException(javax.print.PrintException) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Copies(javax.print.attribute.standard.Copies) PrintService(javax.print.PrintService)

Example 8 with MediaSizeName

use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.

the class Win32PrintJob method getAttributeValues.

private void getAttributeValues(DocFlavor flavor) throws PrintException {
    if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
        fidelity = true;
    } else {
        fidelity = false;
    }
    Class category;
    Attribute[] attrs = reqAttrSet.toArray();
    for (int i = 0; i < attrs.length; i++) {
        Attribute attr = attrs[i];
        category = attr.getCategory();
        if (fidelity == true) {
            if (!service.isAttributeCategorySupported(category)) {
                notifyEvent(PrintJobEvent.JOB_FAILED);
                throw new PrintJobAttributeException("unsupported category: " + category, category, null);
            } else if (!service.isAttributeValueSupported(attr, flavor, null)) {
                notifyEvent(PrintJobEvent.JOB_FAILED);
                throw new PrintJobAttributeException("unsupported attribute: " + attr, null, attr);
            }
        }
        if (category == Destination.class) {
            URI uri = ((Destination) attr).getURI();
            if (!"file".equals(uri.getScheme())) {
                notifyEvent(PrintJobEvent.JOB_FAILED);
                throw new PrintException("Not a file: URI");
            } else {
                try {
                    mDestination = (new File(uri)).getPath();
                } catch (Exception e) {
                    throw new PrintException(e);
                }
                // check write access
                SecurityManager security = System.getSecurityManager();
                if (security != null) {
                    try {
                        security.checkWrite(mDestination);
                    } catch (SecurityException se) {
                        notifyEvent(PrintJobEvent.JOB_FAILED);
                        throw new PrintException(se);
                    }
                }
            }
        } else if (category == JobName.class) {
            jobName = ((JobName) attr).getValue();
        } else if (category == Copies.class) {
            copies = ((Copies) attr).getValue();
        } else if (category == Media.class) {
            if (attr instanceof MediaSizeName) {
                mediaName = (MediaSizeName) attr;
                // be used to create a new PageFormat.
                if (!service.isAttributeValueSupported(attr, null, null)) {
                    mediaSize = MediaSize.getMediaSizeForName(mediaName);
                }
            }
        } else if (category == OrientationRequested.class) {
            orient = (OrientationRequested) attr;
        }
    }
}
Also used : Fidelity(javax.print.attribute.standard.Fidelity) Destination(javax.print.attribute.standard.Destination) PrintJobAttribute(javax.print.attribute.PrintJobAttribute) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) Attribute(javax.print.attribute.Attribute) MediaSizeName(javax.print.attribute.standard.MediaSizeName) JobName(javax.print.attribute.standard.JobName) Media(javax.print.attribute.standard.Media) URI(java.net.URI) java.awt.print(java.awt.print) IOException(java.io.IOException) PrintException(javax.print.PrintException) FileNotFoundException(java.io.FileNotFoundException) PrintException(javax.print.PrintException) File(java.io.File)

Example 9 with MediaSizeName

use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.

the class Win32MediaSize method addToUniqueList.

private boolean addToUniqueList(ArrayList msnList, MediaSizeName mediaName) {
    MediaSizeName msn;
    for (int i = 0; i < msnList.size(); i++) {
        msn = (MediaSizeName) msnList.get(i);
        if (msn == mediaName) {
            return false;
        }
    }
    msnList.add(mediaName);
    return true;
}
Also used : MediaSizeName(javax.print.attribute.standard.MediaSizeName)

Example 10 with MediaSizeName

use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.

the class Win32MediaSize method getDefaultAttributeValue.

public Object getDefaultAttributeValue(Class<? extends Attribute> category) {
    if (category == null) {
        throw new NullPointerException("null category");
    }
    if (!Attribute.class.isAssignableFrom(category)) {
        throw new IllegalArgumentException(category + " is not an Attribute");
    }
    if (!isAttributeCategorySupported(category)) {
        return null;
    }
    int[] defaults = getDefaultPrinterSettings();
    // indices must match those in WPrinterJob.cpp
    int defPaper = defaults[0];
    int defYRes = defaults[2];
    int defQuality = defaults[3];
    int defCopies = defaults[4];
    int defOrient = defaults[5];
    int defSides = defaults[6];
    int defCollate = defaults[7];
    int defColor = defaults[8];
    if (category == Copies.class) {
        if (defCopies > 0) {
            return new Copies(defCopies);
        } else {
            return new Copies(1);
        }
    } else if (category == Chromaticity.class) {
        if (defColor == DMCOLOR_COLOR) {
            return Chromaticity.COLOR;
        } else {
            return Chromaticity.MONOCHROME;
        }
    } else if (category == JobName.class) {
        return new JobName("Java Printing", null);
    } else if (category == OrientationRequested.class) {
        if (defOrient == DMORIENT_LANDSCAPE) {
            return OrientationRequested.LANDSCAPE;
        } else {
            return OrientationRequested.PORTRAIT;
        }
    } else if (category == PageRanges.class) {
        return new PageRanges(1, Integer.MAX_VALUE);
    } else if (category == Media.class) {
        MediaSizeName msn = findWin32Media(defPaper);
        if (msn != null) {
            if (!isSupportedMedia(msn) && mediaSizeNames != null) {
                msn = mediaSizeNames[0];
                defPaper = findPaperID(msn);
            }
            return msn;
        } else {
            initMedia();
            if ((mediaSizeNames != null) && (mediaSizeNames.length > 0)) {
                // cannot be null but to be safe, add a check
                if ((idList != null) && (mediaSizes != null) && (idList.size() == mediaSizes.length)) {
                    Integer defIdObj = Integer.valueOf(defPaper);
                    int index = idList.indexOf(defIdObj);
                    if (index >= 0 && index < mediaSizes.length) {
                        return mediaSizes[index].getMediaSizeName();
                    }
                }
                return mediaSizeNames[0];
            }
        }
    } else if (category == MediaPrintableArea.class) {
        /* Verify defPaper */
        MediaSizeName msn = findWin32Media(defPaper);
        if (msn != null && !isSupportedMedia(msn) && mediaSizeNames != null) {
            defPaper = findPaperID(mediaSizeNames[0]);
        }
        float[] prnArea = getMediaPrintableArea(printer, defPaper);
        if (prnArea != null) {
            MediaPrintableArea printableArea = null;
            try {
                printableArea = new MediaPrintableArea(prnArea[0], prnArea[1], prnArea[2], prnArea[3], MediaPrintableArea.INCH);
            } catch (IllegalArgumentException e) {
            }
            return printableArea;
        }
        return null;
    } else if (category == SunAlternateMedia.class) {
        return null;
    } else if (category == Destination.class) {
        try {
            return new Destination((new File("out.prn")).toURI());
        } catch (SecurityException se) {
            try {
                return new Destination(new URI("file:out.prn"));
            } catch (URISyntaxException e) {
                return null;
            }
        }
    } else if (category == Sides.class) {
        switch(defSides) {
            case DMDUP_VERTICAL:
                return Sides.TWO_SIDED_LONG_EDGE;
            case DMDUP_HORIZONTAL:
                return Sides.TWO_SIDED_SHORT_EDGE;
            default:
                return Sides.ONE_SIDED;
        }
    } else if (category == PrinterResolution.class) {
        int yRes = defYRes;
        int xRes = defQuality;
        if ((xRes < 0) || (yRes < 0)) {
            int res = (yRes > xRes) ? yRes : xRes;
            if (res > 0) {
                return new PrinterResolution(res, res, PrinterResolution.DPI);
            }
        } else {
            return new PrinterResolution(xRes, yRes, PrinterResolution.DPI);
        }
    } else if (category == ColorSupported.class) {
        int caps = getPrinterCapabilities();
        if ((caps & DEVCAP_COLOR) != 0) {
            return ColorSupported.SUPPORTED;
        } else {
            return ColorSupported.NOT_SUPPORTED;
        }
    } else if (category == PrintQuality.class) {
        if ((defQuality < 0) && (defQuality >= DMRES_HIGH)) {
            switch(defQuality) {
                case DMRES_HIGH:
                    return PrintQuality.HIGH;
                case DMRES_MEDIUM:
                    return PrintQuality.NORMAL;
                default:
                    return PrintQuality.DRAFT;
            }
        }
    } else if (category == RequestingUserName.class) {
        String userName = "";
        try {
            userName = System.getProperty("user.name", "");
        } catch (SecurityException se) {
        }
        return new RequestingUserName(userName, null);
    } else if (category == SheetCollate.class) {
        if (defCollate == DMCOLLATE_TRUE) {
            return SheetCollate.COLLATED;
        } else {
            return SheetCollate.UNCOLLATED;
        }
    } else if (category == Fidelity.class) {
        return Fidelity.FIDELITY_FALSE;
    }
    return null;
}
Also used : Destination(javax.print.attribute.standard.Destination) Fidelity(javax.print.attribute.standard.Fidelity) ColorSupported(javax.print.attribute.standard.ColorSupported) PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) Attribute(javax.print.attribute.Attribute) JobName(javax.print.attribute.standard.JobName) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) OrientationRequested(javax.print.attribute.standard.OrientationRequested) MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) PrinterResolution(javax.print.attribute.standard.PrinterResolution) Copies(javax.print.attribute.standard.Copies) Sides(javax.print.attribute.standard.Sides) PageRanges(javax.print.attribute.standard.PageRanges) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media) RequestingUserName(javax.print.attribute.standard.RequestingUserName) Chromaticity(javax.print.attribute.standard.Chromaticity) File(java.io.File)

Aggregations

MediaSizeName (javax.print.attribute.standard.MediaSizeName)31 Media (javax.print.attribute.standard.Media)16 MediaSize (javax.print.attribute.standard.MediaSize)16 OrientationRequested (javax.print.attribute.standard.OrientationRequested)14 MediaPrintableArea (javax.print.attribute.standard.MediaPrintableArea)11 Attribute (javax.print.attribute.Attribute)9 Destination (javax.print.attribute.standard.Destination)9 Chromaticity (javax.print.attribute.standard.Chromaticity)8 Copies (javax.print.attribute.standard.Copies)8 Fidelity (javax.print.attribute.standard.Fidelity)8 JobName (javax.print.attribute.standard.JobName)8 File (java.io.File)7 URI (java.net.URI)7 PrintService (javax.print.PrintService)7 PageRanges (javax.print.attribute.standard.PageRanges)7 SheetCollate (javax.print.attribute.standard.SheetCollate)7 Sides (javax.print.attribute.standard.Sides)7 RequestingUserName (javax.print.attribute.standard.RequestingUserName)5 PageFormat (java.awt.print.PageFormat)4 Paper (java.awt.print.Paper)4