Example usage for javax.print.attribute PrintRequestAttributeSet containsKey

List of usage examples for javax.print.attribute PrintRequestAttributeSet containsKey

Introduction

In this page you can find the example usage for javax.print.attribute PrintRequestAttributeSet containsKey.

Prototype

public boolean containsKey(Class<?> category);

Source Link

Document

Returns true if this attribute set contains an attribute for the specified category.

Usage

From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java

/**
 * This tests, whether the given attribute set defines the same page properties as the given JFreeReport object.
 * <p/>//from   w w w. ja va  2 s . c  o  m
 * While showing the print dialog, the user has the chance to alter the page format of the print job. When that
 * happens, we have to repaginate the whole report, which may render the users page range input invalid. In that case,
 * we will have to redisplay the dialog.
 *
 * @param attributes
 * @param report
 * @return
 */
public static int isValidConfiguration(final PrintRequestAttributeSet attributes, final MasterReport report) {
    final PrintRequestAttributeSet reportAttributes = copyConfiguration(null, report);
    // now, compare that minimal set with the given attribute collection.

    final Attribute[] printAttribs = reportAttributes.toArray();
    boolean invalidConfig = false;
    for (int i = 0; i < printAttribs.length; i++) {
        final Attribute attrib = printAttribs[i];
        if (attributes.containsValue(attrib) == false) {
            invalidConfig = true;
            break;
        }
    }

    if (invalidConfig == false) {
        return CONFIGURATION_VALID;
    }
    if (attributes.containsKey(PageRanges.class)) {
        return CONFIGURATION_SHOW_DIALOG;
    }
    return CONFIGURATION_REPAGINATE;
}

From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java

public static PrintRequestAttributeSet copyAuxillaryAttributes(PrintRequestAttributeSet attributes,
        final MasterReport report) {
    if (attributes == null) {
        attributes = new HashPrintRequestAttributeSet();
    }/*  w w w  .j  a v  a 2  s.c  o m*/

    if (attributes.containsKey(JobName.class) == false) {
        final String jobName = report.getReportConfiguration().getConfigProperty(PrintUtil.PRINTER_JOB_NAME_KEY,
                report.getTitle());
        if (jobName != null) {
            attributes.add(new JobName(jobName, null));
        }
    }
    if (attributes.containsKey(Copies.class) == false) {
        final int numberOfCopies = PrintUtil.getNumberOfCopies(report.getReportConfiguration());
        attributes.add(new Copies(numberOfCopies));
    }

    return attributes;
}