Search in sources :

Example 11 with Destination

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

the class WPrinterJob method displayNativeDialog.

private boolean displayNativeDialog() {
    // "attributes" is required for getting the updated attributes
    if (attributes == null) {
        return false;
    }
    DialogOwner dlgOwner = (DialogOwner) attributes.get(DialogOwner.class);
    Frame ownerFrame = (dlgOwner != null) ? dlgOwner.getOwner() : null;
    WPrintDialog dialog = new WPrintDialog(ownerFrame, this);
    dialog.setRetVal(false);
    dialog.setVisible(true);
    boolean prv = dialog.getRetVal();
    dialog.dispose();
    Destination dest = (Destination) attributes.get(Destination.class);
    if ((dest == null) || !prv) {
        return prv;
    } else {
        String title = null;
        String strBundle = "sun.print.resources.serviceui";
        ResourceBundle rb = ResourceBundle.getBundle(strBundle);
        try {
            title = rb.getString("dialog.printtofile");
        } catch (MissingResourceException e) {
        }
        FileDialog fileDialog = new FileDialog(ownerFrame, title, FileDialog.SAVE);
        URI destURI = dest.getURI();
        // Old code destURI.getPath() would return null for "file:out.prn"
        // so we use getSchemeSpecificPart instead.
        String pathName = (destURI != null) ? destURI.getSchemeSpecificPart() : null;
        if (pathName != null) {
            File file = new File(pathName);
            fileDialog.setFile(file.getName());
            File parent = file.getParentFile();
            if (parent != null) {
                fileDialog.setDirectory(parent.getPath());
            }
        } else {
            fileDialog.setFile("out.prn");
        }
        fileDialog.setVisible(true);
        String fileName = fileDialog.getFile();
        if (fileName == null) {
            fileDialog.dispose();
            return false;
        }
        String fullName = fileDialog.getDirectory() + fileName;
        File f = new File(fullName);
        File pFile = f.getParentFile();
        while ((f.exists() && (!f.isFile() || !f.canWrite())) || ((pFile != null) && (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
            (new PrintToFileErrorDialog(ownerFrame, ServiceDialog.getMsg("dialog.owtitle"), ServiceDialog.getMsg("dialog.writeerror") + " " + fullName, ServiceDialog.getMsg("button.ok"))).setVisible(true);
            fileDialog.setVisible(true);
            fileName = fileDialog.getFile();
            if (fileName == null) {
                fileDialog.dispose();
                return false;
            }
            fullName = fileDialog.getDirectory() + fileName;
            f = new File(fullName);
            pFile = f.getParentFile();
        }
        fileDialog.dispose();
        attributes.add(new Destination(f.toURI()));
        return true;
    }
}
Also used : Destination(javax.print.attribute.standard.Destination) Frame(java.awt.Frame) MissingResourceException(java.util.MissingResourceException) DialogOwner(sun.print.DialogOwner) ResourceBundle(java.util.ResourceBundle) FileDialog(java.awt.FileDialog) URI(java.net.URI) File(java.io.File)

Example 12 with Destination

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

the class WPrinterJob method setNativeAttributes.

private final void setNativeAttributes(int flags, int fields, int values) {
    if (attributes == null) {
        return;
    }
    if ((flags & PD_PRINTTOFILE) != 0) {
        Destination destPrn = (Destination) attributes.get(Destination.class);
        if (destPrn == null) {
            try {
                attributes.add(new Destination(new File("./out.prn").toURI()));
            } catch (SecurityException se) {
                try {
                    attributes.add(new Destination(new URI("file:out.prn")));
                } catch (URISyntaxException e) {
                }
            }
        }
    } else {
        attributes.remove(Destination.class);
    }
    if ((flags & PD_COLLATE) != 0) {
        setCollateAttrib(SheetCollate.COLLATED, attributes);
    } else {
        setCollateAttrib(SheetCollate.UNCOLLATED, attributes);
    }
    if ((flags & PD_PAGENUMS) != 0) {
        attributes.add(SunPageSelection.RANGE);
    } else if ((flags & PD_SELECTION) != 0) {
        attributes.add(SunPageSelection.SELECTION);
    } else {
        attributes.add(SunPageSelection.ALL);
    }
    if ((fields & DM_ORIENTATION) != 0) {
        if ((values & SET_ORIENTATION) != 0) {
            setOrientAttrib(OrientationRequested.LANDSCAPE, attributes);
        } else {
            setOrientAttrib(OrientationRequested.PORTRAIT, attributes);
        }
    }
    if ((fields & DM_COLOR) != 0) {
        if ((values & SET_COLOR) != 0) {
            setColorAttrib(Chromaticity.COLOR, attributes);
        } else {
            setColorAttrib(Chromaticity.MONOCHROME, attributes);
        }
    }
    if ((fields & DM_PRINTQUALITY) != 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;
        }
        setQualityAttrib(quality, attributes);
    }
    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;
        }
        setSidesAttrib(sides, attributes);
    }
}
Also used : Destination(javax.print.attribute.standard.Destination) PrintQuality(javax.print.attribute.standard.PrintQuality) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI) Sides(javax.print.attribute.standard.Sides)

Example 13 with Destination

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

the class UnixPrintJob method getAttributeValues.

private void getAttributeValues(DocFlavor flavor) throws PrintException {
    Attribute attr;
    Class category;
    if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
        fidelity = true;
    } else {
        fidelity = false;
    }
    Attribute[] attrs = reqAttrSet.toArray();
    for (int i = 0; i < attrs.length; i++) {
        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 {
                    mDestType = DESTFILE;
                    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 == JobSheets.class) {
            if ((JobSheets) attr == JobSheets.NONE) {
                mNoJobSheet = true;
            }
        } 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;
                IPPPrintService.debug_println(debugPrefix + "mediaName " + mediaName);
                if (!service.isAttributeValueSupported(attr, null, null)) {
                    mediaSize = MediaSize.getMediaSizeForName(mediaName);
                }
            } else if (attr instanceof CustomMediaTray) {
                customTray = (CustomMediaTray) attr;
            }
        } else if (category == OrientationRequested.class) {
            orient = (OrientationRequested) attr;
        } else if (category == NumberUp.class) {
            nUp = (NumberUp) attr;
        } else if (category == Sides.class) {
            sides = (Sides) 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) JobSheets(javax.print.attribute.standard.JobSheets) URI(java.net.URI) java.awt.print(java.awt.print) PrintException(javax.print.PrintException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) OrientationRequested(javax.print.attribute.standard.OrientationRequested) PrintException(javax.print.PrintException) Copies(javax.print.attribute.standard.Copies) File(java.io.File) Sides(javax.print.attribute.standard.Sides)

Example 14 with Destination

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

the class UnixPrintService method getSupportedAttributeValues.

public Object getSupportedAttributeValues(Class<? extends Attribute> category, DocFlavor flavor, AttributeSet attributes) {
    if (category == null) {
        throw new NullPointerException("null category");
    }
    if (!Attribute.class.isAssignableFrom(category)) {
        throw new IllegalArgumentException(category + " does not implement Attribute");
    }
    if (flavor != null) {
        if (!isDocFlavorSupported(flavor)) {
            throw new IllegalArgumentException(flavor + " is an unsupported flavor");
        } else if (isAutoSense(flavor)) {
            return null;
        }
    }
    if (!isAttributeCategorySupported(category)) {
        return null;
    }
    if (category == Chromaticity.class) {
        if (flavor == null || isServiceFormattedFlavor(flavor)) {
            Chromaticity[] arr = new Chromaticity[1];
            arr[0] = Chromaticity.COLOR;
            return (arr);
        } else {
            return null;
        }
    } else if (category == Destination.class) {
        try {
            return new Destination((new File("out.ps")).toURI());
        } catch (SecurityException se) {
            try {
                return new Destination(new URI("file:out.ps"));
            } catch (URISyntaxException e) {
                return null;
            }
        }
    } else if (category == JobName.class) {
        return new JobName("Java Printing", null);
    } else if (category == JobSheets.class) {
        JobSheets[] arr = new JobSheets[2];
        arr[0] = JobSheets.NONE;
        arr[1] = JobSheets.STANDARD;
        return arr;
    } else if (category == RequestingUserName.class) {
        String userName = "";
        try {
            userName = System.getProperty("user.name", "");
        } catch (SecurityException se) {
        }
        return new RequestingUserName(userName, null);
    } else if (category == OrientationRequested.class) {
        if (flavor == null || isServiceFormattedFlavor(flavor)) {
            OrientationRequested[] arr = new OrientationRequested[3];
            arr[0] = OrientationRequested.PORTRAIT;
            arr[1] = OrientationRequested.LANDSCAPE;
            arr[2] = OrientationRequested.REVERSE_LANDSCAPE;
            return arr;
        } else {
            return null;
        }
    } else if ((category == Copies.class) || (category == CopiesSupported.class)) {
        if (flavor == null || !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) || flavor.equals(DocFlavor.URL.POSTSCRIPT) || flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) {
            return new CopiesSupported(1, MAXCOPIES);
        } else {
            return null;
        }
    } else if (category == Media.class) {
        Media[] arr = new Media[mediaSizes.length];
        System.arraycopy(mediaSizes, 0, arr, 0, mediaSizes.length);
        return arr;
    } else if (category == Fidelity.class) {
        Fidelity[] arr = new Fidelity[2];
        arr[0] = Fidelity.FIDELITY_FALSE;
        arr[1] = Fidelity.FIDELITY_TRUE;
        return arr;
    } else if (category == MediaPrintableArea.class) {
        /* The code below implements the behaviour that if no Media or
             * MediaSize attribute is specified, return an array of
             * MediaPrintableArea, one for each supported Media.
             * If a MediaSize is specified, return a MPA consistent for that,
             * and if a Media is specified locate its MediaSize and return
             * its MPA, and if none is found, return an MPA for the default
             * Media for this service.
             */
        if (attributes == null) {
            return getAllPrintableAreas();
        }
        MediaSize mediaSize = (MediaSize) attributes.get(MediaSize.class);
        Media media = (Media) attributes.get(Media.class);
        MediaPrintableArea[] arr = new MediaPrintableArea[1];
        if (mediaSize == null) {
            if (media instanceof MediaSizeName) {
                MediaSizeName msn = (MediaSizeName) media;
                mediaSize = MediaSize.getMediaSizeForName(msn);
                if (mediaSize == null) {
                    /* try to get a size from the default media */
                    media = (Media) getDefaultAttributeValue(Media.class);
                    if (media instanceof MediaSizeName) {
                        msn = (MediaSizeName) media;
                        mediaSize = MediaSize.getMediaSizeForName(msn);
                    }
                    if (mediaSize == null) {
                        /* shouldn't happen, return a default */
                        arr[0] = new MediaPrintableArea(0.25f, 0.25f, 8f, 10.5f, MediaSize.INCH);
                        return arr;
                    }
                }
            } else {
                return getAllPrintableAreas();
            }
        }
        /* If reach here MediaSize is non-null */
        assert mediaSize != null;
        arr[0] = new MediaPrintableArea(0.25f, 0.25f, mediaSize.getX(MediaSize.INCH) - 0.5f, mediaSize.getY(MediaSize.INCH) - 0.5f, MediaSize.INCH);
        return arr;
    } else if (category == PageRanges.class) {
        if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            PageRanges[] arr = new PageRanges[1];
            arr[0] = new PageRanges(1, Integer.MAX_VALUE);
            return arr;
        } else {
            return null;
        }
    } else if (category == SheetCollate.class) {
        if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            SheetCollate[] arr = new SheetCollate[2];
            arr[0] = SheetCollate.UNCOLLATED;
            arr[1] = SheetCollate.COLLATED;
            return arr;
        } else {
            return null;
        }
    } else if (category == Sides.class) {
        if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            Sides[] arr = new Sides[3];
            arr[0] = Sides.ONE_SIDED;
            arr[1] = Sides.TWO_SIDED_LONG_EDGE;
            arr[2] = Sides.TWO_SIDED_SHORT_EDGE;
            return arr;
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : Destination(javax.print.attribute.standard.Destination) Fidelity(javax.print.attribute.standard.Fidelity) 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) Sides(javax.print.attribute.standard.Sides) PageRanges(javax.print.attribute.standard.PageRanges) MediaSize(javax.print.attribute.standard.MediaSize) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media) JobSheets(javax.print.attribute.standard.JobSheets) SheetCollate(javax.print.attribute.standard.SheetCollate) RequestingUserName(javax.print.attribute.standard.RequestingUserName) CopiesSupported(javax.print.attribute.standard.CopiesSupported) Chromaticity(javax.print.attribute.standard.Chromaticity) File(java.io.File)

Aggregations

Destination (javax.print.attribute.standard.Destination)14 File (java.io.File)12 URI (java.net.URI)9 MediaSizeName (javax.print.attribute.standard.MediaSizeName)9 JobName (javax.print.attribute.standard.JobName)8 Copies (javax.print.attribute.standard.Copies)7 Media (javax.print.attribute.standard.Media)7 OrientationRequested (javax.print.attribute.standard.OrientationRequested)7 Fidelity (javax.print.attribute.standard.Fidelity)6 PageRanges (javax.print.attribute.standard.PageRanges)6 Sides (javax.print.attribute.standard.Sides)6 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)5 PrintService (javax.print.PrintService)5 Attribute (javax.print.attribute.Attribute)5 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)5 MediaPrintableArea (javax.print.attribute.standard.MediaPrintableArea)5 SheetCollate (javax.print.attribute.standard.SheetCollate)5 PrinterException (java.awt.print.PrinterException)4 PrintException (javax.print.PrintException)4