void fillPriorityField() { boolean enabled = myService.isAttributeCategorySupported(JobPriority.class); priorityLabel.setEnabled(enabled); prtSpinner.setEnabled(enabled); if (firstUse) { if (attrs.containsKey(JobPriority.class)) { JobPriority value = (JobPriority) (attrs.get(JobPriority.class)); prtSpinner.setValue(new Integer(value.getValue())); } else { if (enabled) { JobPriority defaul = (JobPriority) ( myService.getDefaultAttributeValue(JobPriority.class)); prtSpinner.setValue (defaul == null ? new Integer(1) : new Integer(defaul.getValue())); } else { prtSpinner.setValue(new Integer(1)); } } } }
/** * Get Job Priority based on pages printed. * The more pages, the lower the priority * @param pages number of pages * @param copies number of copies * @param withDialog dialog gets lower priority than direct print * @return Job Priority */ static public JobPriority getJobPriority (int pages, int copies, boolean withDialog) { // Set priority (the more pages, the lower the priority) int priority = copies * pages; if (withDialog) // prefer direct print priority *= 2; priority = 100 - priority; // convert to 1-100 supported range if (priority < 10) priority = 10; else if (priority > 100) priority = 100; return new JobPriority(priority); }
private void updatePriority() { if (prtSpinner.isEnabled()) { int priority = ((Integer) (prtSpinner.getValue())).intValue(); newAttrs.add(new JobPriority(priority)); } else { removeAttribute(JobPriority.class); } }
/** * @see javax.print.PrintService#getDefaultAttributeValue(java.lang.Class) */ public Object getDefaultAttributeValue(Class<? extends Attribute> category) { // required attributes if (category.equals(Fidelity.class)) return Fidelity.FIDELITY_FALSE; if (category.equals(JobName.class)) return JOB_NAME; if (category.equals(RequestingUserName.class)) return REQUESTING_USER_NAME; // optional attributes if (category.equals(JobPriority.class) && printerAttr.containsKey(JobPriorityDefault.class)) return getPrinterDefaultAttribute(JobPriorityDefault.class); if (category.equals(JobHoldUntil.class) && printerAttr.containsKey(JobHoldUntilDefault.class)) return getPrinterDefaultAttribute(JobHoldUntilDefault.class); if (category.equals(JobSheets.class) && printerAttr.containsKey(JobSheetsDefault.class)) return getPrinterDefaultAttribute(JobSheetsDefault .class); if (category.equals(MultipleDocumentHandling.class) && printerAttr.containsKey(MultipleDocumentHandlingDefault.class)) return getPrinterDefaultAttribute(MultipleDocumentHandlingDefault.class); if (category.equals(Copies.class) && printerAttr.containsKey(CopiesDefault.class)) return getPrinterDefaultAttribute(CopiesDefault.class); if (category.equals(Finishings.class) && printerAttr.containsKey(FinishingsDefault.class)) return getPrinterDefaultAttribute(FinishingsDefault.class); if (category.equals(Sides.class) && printerAttr.containsKey(SidesDefault.class)) return getPrinterDefaultAttribute(SidesDefault.class); if (category.equals(NumberUp.class) && printerAttr.containsKey(NumberUpDefault.class)) return getPrinterDefaultAttribute(NumberUpDefault.class); if (category.equals(OrientationRequested.class) && printerAttr.containsKey(OrientationRequestedDefault.class)) return getPrinterDefaultAttribute(OrientationRequestedDefault.class); if (category.equals(Media.class) && printerAttr.containsKey(MediaDefault.class)) return getPrinterDefaultAttribute(MediaDefault.class); if (category.equals(PrinterResolution.class) && printerAttr.containsKey(PrinterResolutionDefault.class)) return getPrinterDefaultAttribute(PrinterResolutionDefault.class); if (category.equals(PrintQuality.class) && printerAttr.containsKey(PrintQualityDefault.class)) return getPrinterDefaultAttribute(PrintQualityDefault.class); if (category.equals(Compression.class) && printerAttr.containsKey(CompressionSupported.class)) return Compression.NONE; if (category.equals(PageRanges.class)) return new PageRanges(1, Integer.MAX_VALUE); return null; }
/** * @see javax.print.PrintService#getSupportedAttributeCategories() */ public Class<?>[] getSupportedAttributeCategories() { Set<Class<? extends Attribute>> categories = new HashSet<Class<? extends Attribute>>(); // Should only be job template attributes as of section 4.2 if (printerAttr.containsKey(JobPrioritySupported.class)) categories.add(JobPriority.class); if (printerAttr.containsKey(JobHoldUntilSupported.class)) categories.add(JobHoldUntil.class); if (printerAttr.containsKey(JobSheetsSupported.class)) categories.add(JobSheets.class); if (printerAttr.containsKey(MultipleDocumentHandlingSupported.class)) categories.add(MultipleDocumentHandling.class); if (printerAttr.containsKey(CopiesSupported.class)) categories.add(Copies.class); if (printerAttr.containsKey(FinishingsSupported.class)) { // if only none finishing is supported - it does not count as supported Set<FinishingsSupported> set = getPrinterAttributeSet(FinishingsSupported.class); if (! (set.size() == 1 && set.contains(FinishingsSupported.NONE))) categories.add(Finishings.class); } if (printerAttr.containsKey(PageRangesSupported.class)) categories.add(PageRanges.class); if (printerAttr.containsKey(SidesSupported.class)) categories.add(Sides.class); if (printerAttr.containsKey(NumberUpSupported.class)) categories.add(NumberUp.class); if (printerAttr.containsKey(OrientationRequestedSupported.class)) categories.add(OrientationRequested.class); if (printerAttr.containsKey(MediaSupported.class)) categories.add(Media.class); if (printerAttr.containsKey(PrinterResolutionSupported.class)) categories.add(PrinterResolution.class); if (printerAttr.containsKey(PrintQualitySupported.class)) categories.add(PrintQuality.class); // Chromaticity, Destination, MediaPrintableArea, // SheetCollate, PresentationDirection - not IPP attributes // attributes outside section 4.2 if (printerAttr.containsKey(CompressionSupported.class)) categories.add(Compression.class); if (printerAttr.containsKey(JobImpressionsSupported.class)) categories.add(JobImpressions.class); if (printerAttr.containsKey(JobKOctetsSupported.class)) categories.add(JobKOctets.class); if (printerAttr.containsKey(JobMediaSheetsSupported.class)) categories.add(JobMediaSheets.class); // always supported as required by IPP specification categories.add(Fidelity.class); categories.add(JobName.class); categories.add(RequestingUserName.class); return categories.toArray(new Class[categories.size()]); }
/** * @see PrintService#isAttributeValueSupported(Attribute, DocFlavor, AttributeSet) */ public boolean isAttributeValueSupported(Attribute attrval, DocFlavor flavor, AttributeSet attributes) { // just redirect to getSupportedAttributeValues Object values = getSupportedAttributeValues(attrval.getCategory(), flavor, attributes); // null means none supported if (values == null) return false; // object may be an array if (values.getClass().isArray()) return Arrays.asList((Object[]) values).contains(attrval); // may be a single instance of the category (value is irrelevant) if (values.getClass().equals(attrval.getCategory())) return true; // a single instance of another class to give the bounds // copies if (values.getClass().equals(CopiesSupported.class)) return ((CopiesSupported) values).contains((IntegerSyntax) attrval); // number up if (values.getClass().equals(NumberUpSupported.class)) return ((NumberUpSupported) values).contains((IntegerSyntax) attrval); // job priority if (values.getClass().equals(JobPrioritySupported.class)) { JobPriority priority = (JobPriority) attrval; JobPrioritySupported maxSupported = (JobPrioritySupported) values; if (priority.getValue() < maxSupported.getValue()) return true; } // I am unsure if these might also show up - not yet found a printer where // Suns implementation supports them: // JobImpressionsSupported, JobKOctetsSupported, JobMediaSheetsSupported return false; }
public void stateChanged(ChangeEvent event) { int value = ((Integer) priority.getValue()).intValue(); atts.add(new JobPriority(value)); }
/** * @see javax.print.PrintService#getDefaultAttributeValue(java.lang.Class) */ public Object getDefaultAttributeValue(Class category) { // required attributes if (category.equals(Fidelity.class)) return Fidelity.FIDELITY_FALSE; if (category.equals(JobName.class)) return JOB_NAME; if (category.equals(RequestingUserName.class)) return REQUESTING_USER_NAME; // optional attributes if (category.equals(JobPriority.class) && printerAttr.containsKey(JobPriorityDefault.class)) return getPrinterDefaultAttribute(JobPriorityDefault.class); if (category.equals(JobHoldUntil.class) && printerAttr.containsKey(JobHoldUntilDefault.class)) return getPrinterDefaultAttribute(JobHoldUntilDefault.class); if (category.equals(JobSheets.class) && printerAttr.containsKey(JobSheetsDefault.class)) return getPrinterDefaultAttribute(JobSheetsDefault .class); if (category.equals(MultipleDocumentHandling.class) && printerAttr.containsKey(MultipleDocumentHandlingDefault.class)) return getPrinterDefaultAttribute(MultipleDocumentHandlingDefault.class); if (category.equals(Copies.class) && printerAttr.containsKey(CopiesDefault.class)) return getPrinterDefaultAttribute(CopiesDefault.class); if (category.equals(Finishings.class) && printerAttr.containsKey(FinishingsDefault.class)) return getPrinterDefaultAttribute(FinishingsDefault.class); if (category.equals(Sides.class) && printerAttr.containsKey(SidesDefault.class)) return getPrinterDefaultAttribute(SidesDefault.class); if (category.equals(NumberUp.class) && printerAttr.containsKey(NumberUpDefault.class)) return getPrinterDefaultAttribute(NumberUpDefault.class); if (category.equals(OrientationRequested.class) && printerAttr.containsKey(OrientationRequestedDefault.class)) return getPrinterDefaultAttribute(OrientationRequestedDefault.class); if (category.equals(Media.class) && printerAttr.containsKey(MediaDefault.class)) return getPrinterDefaultAttribute(MediaDefault.class); if (category.equals(PrinterResolution.class) && printerAttr.containsKey(PrinterResolutionDefault.class)) return getPrinterDefaultAttribute(PrinterResolutionDefault.class); if (category.equals(PrintQuality.class) && printerAttr.containsKey(PrintQualityDefault.class)) return getPrinterDefaultAttribute(PrintQualityDefault.class); if (category.equals(Compression.class) && printerAttr.containsKey(CompressionSupported.class)) return Compression.NONE; if (category.equals(PageRanges.class)) return new PageRanges(1, Integer.MAX_VALUE); return null; }
/** * @see javax.print.PrintService#getSupportedAttributeCategories() */ public Class[] getSupportedAttributeCategories() { Set categories = new HashSet(); // Should only be job template attributes as of section 4.2 if (printerAttr.containsKey(JobPrioritySupported.class)) categories.add(JobPriority.class); if (printerAttr.containsKey(JobHoldUntilSupported.class)) categories.add(JobHoldUntil.class); if (printerAttr.containsKey(JobSheetsSupported.class)) categories.add(JobSheets.class); if (printerAttr.containsKey(MultipleDocumentHandlingSupported.class)) categories.add(MultipleDocumentHandling.class); if (printerAttr.containsKey(CopiesSupported.class)) categories.add(Copies.class); if (printerAttr.containsKey(FinishingsSupported.class)) { // if only none finishing is supported - it does not count as supported Set set = getPrinterAttributeSet(FinishingsSupported.class); if (! (set.size() == 1 && set.contains(FinishingsSupported.NONE))) categories.add(Finishings.class); } if (printerAttr.containsKey(PageRangesSupported.class)) categories.add(PageRanges.class); if (printerAttr.containsKey(SidesSupported.class)) categories.add(Sides.class); if (printerAttr.containsKey(NumberUpSupported.class)) categories.add(NumberUp.class); if (printerAttr.containsKey(OrientationRequestedSupported.class)) categories.add(OrientationRequested.class); if (printerAttr.containsKey(MediaSupported.class)) categories.add(Media.class); if (printerAttr.containsKey(PrinterResolutionSupported.class)) categories.add(PrinterResolution.class); if (printerAttr.containsKey(PrintQualitySupported.class)) categories.add(PrintQuality.class); // Chromaticity, Destination, MediaPrintableArea, // SheetCollate, PresentationDirection - not IPP attributes // attributes outside section 4.2 if (printerAttr.containsKey(CompressionSupported.class)) categories.add(Compression.class); if (printerAttr.containsKey(JobImpressionsSupported.class)) categories.add(JobImpressions.class); if (printerAttr.containsKey(JobKOctetsSupported.class)) categories.add(JobKOctets.class); if (printerAttr.containsKey(JobMediaSheetsSupported.class)) categories.add(JobMediaSheets.class); // always supported as required by IPP specification categories.add(Fidelity.class); categories.add(JobName.class); categories.add(RequestingUserName.class); return (Class[]) categories.toArray(new Class[categories.size()]); }
/** * Returns the equally enum of the standard attribute class * of this DefaultValuesAttribute enum. * * @return The enum of the standard attribute class. */ public Attribute getAssociatedAttribute() { return new JobPriority(getValue()); }