Search in sources :

Example 16 with Attribute

use of javax.print.attribute.Attribute in project jdk8u_jdk by JetBrains.

the class WPrinterJob method setAttributes.

/**
     * copy the attributes to the native print job
     * Note that this method, and hence the re-initialisation
     * of the GDI values is done on each entry to the print dialog since
     * an app could redisplay the print dialog for the same job and
     * 1) the application may have changed attribute settings
     * 2) the application may have changed the printer.
     * In the event that the user changes the printer using the
      dialog, then it is up to GDI to report back all changed values.
     */
@Override
protected void setAttributes(PrintRequestAttributeSet attributes) throws PrinterException {
    // initialize attribute values
    initAttributeMembers();
    super.setAttributes(attributes);
    mAttCopies = getCopiesInt();
    mDestination = destinationAttr;
    if (attributes == null) {
        // now always use attributes, so this shouldn't happen.
        return;
    }
    Attribute[] attrs = attributes.toArray();
    for (int i = 0; i < attrs.length; i++) {
        Attribute attr = attrs[i];
        try {
            if (attr.getCategory() == Sides.class) {
                setSidesAttrib(attr);
            } else if (attr.getCategory() == Chromaticity.class) {
                setColorAttrib(attr);
            } else if (attr.getCategory() == PrinterResolution.class) {
                setResolutionAttrib(attr);
            } else if (attr.getCategory() == PrintQuality.class) {
                setQualityAttrib(attr);
            } else if (attr.getCategory() == SheetCollate.class) {
                setCollateAttrib(attr);
            } else if (attr.getCategory() == Media.class || attr.getCategory() == SunAlternateMedia.class) {
                /* SunAlternateMedia is used if its a tray, and
                     * any Media that is specified is not a tray.
                     */
                if (attr.getCategory() == SunAlternateMedia.class) {
                    Media media = (Media) attributes.get(Media.class);
                    if (media == null || !(media instanceof MediaTray)) {
                        attr = ((SunAlternateMedia) attr).getMedia();
                    }
                }
                if (attr instanceof MediaSizeName) {
                    setWin32MediaAttrib(attr);
                }
                if (attr instanceof MediaTray) {
                    setMediaTrayAttrib(attr);
                }
            }
        } catch (ClassCastException e) {
        }
    }
}
Also used : Attribute(javax.print.attribute.Attribute) MediaSizeName(javax.print.attribute.standard.MediaSizeName) 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)

Example 17 with Attribute

use of javax.print.attribute.Attribute in project jdk8u_jdk by JetBrains.

the class PSStreamPrintJob method initializeAttributeSets.

/* There's some inefficiency here as the job set is created even though
     * it may never be requested.
     */
private synchronized void initializeAttributeSets(Doc doc, PrintRequestAttributeSet reqSet) {
    reqAttrSet = new HashPrintRequestAttributeSet();
    jobAttrSet = new HashPrintJobAttributeSet();
    Attribute[] attrs;
    if (reqSet != null) {
        reqAttrSet.addAll(reqSet);
        attrs = reqSet.toArray();
        for (int i = 0; i < attrs.length; i++) {
            if (attrs[i] instanceof PrintJobAttribute) {
                jobAttrSet.add(attrs[i]);
            }
        }
    }
    DocAttributeSet docSet = doc.getAttributes();
    if (docSet != null) {
        attrs = docSet.toArray();
        for (int i = 0; i < attrs.length; i++) {
            if (attrs[i] instanceof PrintRequestAttribute) {
                reqAttrSet.add(attrs[i]);
            }
            if (attrs[i] instanceof PrintJobAttribute) {
                jobAttrSet.add(attrs[i]);
            }
        }
    }
    /* add the user name to the job */
    String userName = "";
    try {
        userName = System.getProperty("user.name");
    } catch (SecurityException se) {
    }
    if (userName == null || userName.equals("")) {
        RequestingUserName ruName = (RequestingUserName) reqSet.get(RequestingUserName.class);
        if (ruName != null) {
            jobAttrSet.add(new JobOriginatingUserName(ruName.getValue(), ruName.getLocale()));
        } else {
            jobAttrSet.add(new JobOriginatingUserName("", null));
        }
    } else {
        jobAttrSet.add(new JobOriginatingUserName(userName, null));
    }
    /* if no job name supplied use doc name (if supplied), if none and
         * its a URL use that, else finally anything .. */
    if (jobAttrSet.get(JobName.class) == null) {
        JobName jobName;
        if (docSet != null && docSet.get(DocumentName.class) != null) {
            DocumentName docName = (DocumentName) docSet.get(DocumentName.class);
            jobName = new JobName(docName.getValue(), docName.getLocale());
            jobAttrSet.add(jobName);
        } else {
            String str = "JPS Job:" + doc;
            try {
                Object printData = doc.getPrintData();
                if (printData instanceof URL) {
                    str = ((URL) (doc.getPrintData())).toString();
                }
            } catch (IOException e) {
            }
            jobName = new JobName(str, null);
            jobAttrSet.add(jobName);
        }
    }
    jobAttrSet = AttributeSetUtilities.unmodifiableView(jobAttrSet);
}
Also used : PrintJobAttribute(javax.print.attribute.PrintJobAttribute) PrintJobAttribute(javax.print.attribute.PrintJobAttribute) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) Attribute(javax.print.attribute.Attribute) HashPrintJobAttributeSet(javax.print.attribute.HashPrintJobAttributeSet) JobName(javax.print.attribute.standard.JobName) IOException(java.io.IOException) java.awt.print(java.awt.print) URL(java.net.URL) DocAttributeSet(javax.print.attribute.DocAttributeSet) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) RequestingUserName(javax.print.attribute.standard.RequestingUserName) JobOriginatingUserName(javax.print.attribute.standard.JobOriginatingUserName) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) DocumentName(javax.print.attribute.standard.DocumentName)

Example 18 with Attribute

use of javax.print.attribute.Attribute in project jdk8u_jdk by JetBrains.

the class PSStreamPrintService method getUnsupportedAttributes.

public AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes) {
    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException("flavor " + flavor + "is not supported");
    }
    if (attributes == null) {
        return null;
    }
    Attribute attr;
    AttributeSet unsupp = new HashAttributeSet();
    Attribute[] attrs = attributes.toArray();
    for (int i = 0; i < attrs.length; i++) {
        try {
            attr = attrs[i];
            if (!isAttributeCategorySupported(attr.getCategory())) {
                unsupp.add(attr);
            } else if (!isAttributeValueSupported(attr, flavor, attributes)) {
                unsupp.add(attr);
            }
        } catch (ClassCastException e) {
        }
    }
    if (unsupp.isEmpty()) {
        return null;
    } else {
        return unsupp;
    }
}
Also used : PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) Attribute(javax.print.attribute.Attribute) AttributeSet(javax.print.attribute.AttributeSet) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashAttributeSet(javax.print.attribute.HashAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) HashAttributeSet(javax.print.attribute.HashAttributeSet)

Example 19 with Attribute

use of javax.print.attribute.Attribute 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 20 with Attribute

use of javax.print.attribute.Attribute in project jdk8u_jdk by JetBrains.

the class UnixPrintService method getUpdatedAttributes.

public PrintServiceAttributeSet getUpdatedAttributes() {
    PrintServiceAttributeSet currSet = getDynamicAttributes();
    if (lastSet == null) {
        lastSet = currSet;
        return AttributeSetUtilities.unmodifiableView(currSet);
    } else {
        PrintServiceAttributeSet updates = new HashPrintServiceAttributeSet();
        Attribute[] attrs = currSet.toArray();
        Attribute attr;
        for (int i = 0; i < attrs.length; i++) {
            attr = attrs[i];
            if (!lastSet.containsValue(attr)) {
                updates.add(attr);
            }
        }
        lastSet = currSet;
        return AttributeSetUtilities.unmodifiableView(updates);
    }
}
Also used : PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) Attribute(javax.print.attribute.Attribute) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet)

Aggregations

Attribute (javax.print.attribute.Attribute)26 PrintServiceAttribute (javax.print.attribute.PrintServiceAttribute)13 PrintRequestAttribute (javax.print.attribute.PrintRequestAttribute)10 MediaSizeName (javax.print.attribute.standard.MediaSizeName)9 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)8 JobName (javax.print.attribute.standard.JobName)8 HashPrintServiceAttributeSet (javax.print.attribute.HashPrintServiceAttributeSet)7 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)7 PrintServiceAttributeSet (javax.print.attribute.PrintServiceAttributeSet)7 Fidelity (javax.print.attribute.standard.Fidelity)7 OrientationRequested (javax.print.attribute.standard.OrientationRequested)7 RequestingUserName (javax.print.attribute.standard.RequestingUserName)7 java.awt.print (java.awt.print)6 PrintJobAttribute (javax.print.attribute.PrintJobAttribute)6 Media (javax.print.attribute.standard.Media)6 File (java.io.File)5 IOException (java.io.IOException)5 URI (java.net.URI)5 Chromaticity (javax.print.attribute.standard.Chromaticity)5 Destination (javax.print.attribute.standard.Destination)5