private void createNumberUpCombo(PrintRequestAttributeSet set) { NumberUp[] numUp = (NumberUp[]) mService.getSupportedAttributeValues(NumberUp.class, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); if (numUp != null && numUp.length > 0) { NumberUp current = PrintUtilities.getNumberUp(mService, set); WrappedNumberUp[] wrappers = new WrappedNumberUp[numUp.length]; int selection = 0; for (int i = 0; i < numUp.length; i++) { wrappers[i] = new WrappedNumberUp(numUp[i].toString(), numUp[i]); if (numUp[i] == current) { selection = i; } } mNumberUp = new JComboBox<>(wrappers); mNumberUp.setSelectedIndex(selection); UIUtilities.setOnlySize(mNumberUp, mNumberUp.getPreferredSize()); LinkedLabel label = new LinkedLabel(NUMBER_UP, mNumberUp); add(label, new PrecisionLayoutData().setEndHorizontalAlignment()); add(mNumberUp); } else { mNumberUp = null; } }
public final void testHashCode2() { is1 = new Copies(5); is2 = new NumberUp(5); assertTrue(is1.hashCode() == 5); assertTrue(is2.hashCode() == 5); assertTrue(is1.hashCode() == is2.hashCode()); }
public final void testEquals1() { is1 = new Copies(99); is2 = new NumberUp(99); assertFalse(is1.equals(is2)); is2 = null; assertFalse(is1.equals(is2)); }
/** @param numberUp The new number up. */ public void setNumberUp(int numberUp) { PrintService service = getPrintService(); if (service != null) { for (NumberUp one : (NumberUp[]) service.getSupportedAttributeValues(NumberUp.class, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null)) { if (one.getValue() == numberUp) { setNumberUp(one); return; } } } }
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; } } }
private void getAttributeValues(DocFlavor flavor) throws PrintException { Attribute attr; Class<? extends Attribute> 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; } } }
/** * @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 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()]); }
WrappedNumberUp(String title, NumberUp object) { super(title, object); }
/** @return The number up. */ public NumberUp getNumberUp() { return PrintUtilities.getNumberUp(getPrintService(), mSet); }
/** @param numberUp The new number up. */ public void setNumberUp(NumberUp numberUp) { PrintUtilities.setNumberUp(mSet, numberUp); }
/** * Returns the equally enum of the standard attribute class * of this DefaultValuesAttribute enum. * <p>May return null if no value exists in JPS API.</p> * * @return The enum of the standard attribute class. */ public Attribute getAssociatedAttribute() { return new NumberUp(getValue()); }
/** * @param service The {@link PrintService} to use. * @param set The {@link PrintRequestAttributeSet} to use. * @return The number up to print. */ public static NumberUp getNumberUp(PrintService service, PrintRequestAttributeSet set) { return (NumberUp) PrintUtilities.getSetting(service, set, NumberUp.class, false); }
/** * Sets the number up to print. * * @param set The {@link PrintRequestAttributeSet} to use. * @param numberUp The new number up to print. */ public static void setNumberUp(PrintRequestAttributeSet set, NumberUp numberUp) { set.add(numberUp); }