private static void doTest() { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Chromaticity.MONOCHROME); MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5); float[] size = isoA5Size.getSize(Size2DSyntax.INCH); Paper paper = new Paper(); paper.setSize(size[0] * 72.0, size[1] * 72.0); paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0); PageFormat pf = new PageFormat(); pf.setPaper(paper); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf)); if (job.printDialog()) { try { job.print(aset); } catch (PrinterException pe) { throw new RuntimeException(pe); } } }
public void setAttribute(final Attribute attr) { final Class<? extends Attribute> category = attr.getCategory(); if (OrientationRequested.class.equals(category)) { setOrientation((OrientationRequested) attr); } else if (MediaSize.class.equals(category)) { setPaper((MediaSize) attr); } else if (Media.class.equals(category)) { setPaper((MediaSizeName) attr); } else if (Paper.class.equals(category)) { setPaper((Paper) attr); } else if (Copies.class.equals(category)) { setCopies((Copies) attr); } else if (PrintQuality.class.equals(category)) { setPrintQuality((PrintQuality) attr); } else if (Sides.class.equals(category)) { setSides((Sides) attr); } else if (SheetCollate.class.equals(category)) { setCollate((SheetCollate) attr); } else if (PrinterResolution.class.equals(category)) { setPrinterResolution((PrinterResolution) attr); } else if (Chromaticity.class.equals(category)) { setChromaticity((Chromaticity) attr); } }
void fillColorFields() { boolean lastIsMonochrome = getLastColor(); monoBtn.setEnabled(false); colorBtn.setEnabled(false); if (myService.isAttributeCategorySupported(Chromaticity.class)) { Chromaticity [] supported = (Chromaticity []) (myService .getSupportedAttributeValues(Chromaticity.class, flavor, attrs)); if (supported != null) { if (supported.length == 1) { lastIsMonochrome = setMonochrome( (supported[0]).equals(Chromaticity.MONOCHROME)); } else if (supported.length > 1) { monoBtn.setEnabled(true); colorBtn.setEnabled(true); } } } if (lastIsMonochrome) { monoBtn.setSelected(true); } else { colorBtn.setSelected(true); } }
private boolean getLastColor() { if (firstUse) { if (attrs.containsKey(Chromaticity.class)) { Attribute value = attrs.get(Chromaticity.class); return value.equals(Chromaticity.MONOCHROME); } Object defaul = myService.getDefaultAttributeValue(Chromaticity.class); return (myService.isAttributeCategorySupported(Chromaticity.class) && (defaul != null)) ? defaul.equals(Chromaticity.MONOCHROME) : true; } return monoBtn.isSelected(); }
private void createChromaticityCombo(PrintRequestAttributeSet set) { Chromaticity[] chromacities = (Chromaticity[]) mService.getSupportedAttributeValues(Chromaticity.class, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); if (chromacities != null && chromacities.length > 0) { HashSet<Chromaticity> possible = new HashSet<>(); for (Chromaticity one : chromacities) { possible.add(one); } ArrayList<InkChromaticity> choices = new ArrayList<>(); for (InkChromaticity chromaticity : InkChromaticity.values()) { if (possible.contains(chromaticity.getChromaticity())) { choices.add(chromaticity); } } mChromaticity = new JComboBox<>(choices.toArray(new InkChromaticity[0])); mChromaticity.setSelectedItem(PrintUtilities.getChromaticity(mService, set, true)); UIUtilities.setOnlySize(mChromaticity, mChromaticity.getPreferredSize()); LinkedLabel label = new LinkedLabel(CHROMATICITY, mChromaticity); add(label, new PrecisionLayoutData().setEndHorizontalAlignment()); add(mChromaticity); } else { mChromaticity = null; } }
public static void printComponent(Component c) { // Get a list of all printers that can handle Printable objects. DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null); // Set some define printing attributes PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet(); //printAttributes.add(OrientationRequested.LANDSCAPE); // landscape mode printAttributes.add(OrientationRequested.PORTRAIT); // PORTRAIT mode printAttributes.add(Chromaticity.MONOCHROME); // print in mono printAttributes.add(javax.print.attribute.standard.PrintQuality.HIGH); // highest resolution // Display a dialog that allows the user to select one of the // available printers and to edit the default attributes PrintService service = ServiceUI.printDialog(null, 100, 100, services, null, null, printAttributes); // If the user canceled, don't do anything if(service==null) { return; } // Now call a method defined below to finish the printing printToService(c, service, printAttributes); }
private void setColorAttrib(Attribute attr) { if (attr == Chromaticity.COLOR) { mAttChromaticity = 2; // DMCOLOR_COLOR } else { mAttChromaticity = 1; // DMCOLOR_MONOCHROME } }
@Override final public void actionPerformed(ActionEvent objPactionEvent) { final Object objLsourceObject = objPactionEvent.getSource(); if (this.objGmonochromePrintIconJRadioButton.isSameAs(objLsourceObject)) { this.objGprintJDialog.getAttributes().add(Chromaticity.MONOCHROME); } else if (this.objGcolorPrintIconJRadioButton.isSameAs(objLsourceObject)) { this.objGprintJDialog.getAttributes().add(Chromaticity.COLOR); } }
public void actionPerformed(ActionEvent e) { if (e.getSource() == bw) atts.add(Chromaticity.MONOCHROME); else atts.add(Chromaticity.COLOR); }
/** * Called to update for new selected * print service. Tests if currently * selected attributes are supported. */ void updateForSelectedService() { if (categorySupported(Chromaticity.class)) { bw.setEnabled(true); color.setEnabled(true); Object defaultValue = defaultValue(Chromaticity.class); Attribute chromaticity = attribute(Chromaticity.class); if (chromaticity != null) { if (chromaticity.equals(Chromaticity.MONOCHROME)) bw.setSelected(true); else color.setSelected(true); } else { if (defaultValue.equals(Chromaticity.MONOCHROME)) bw.setSelected(true); else color.setSelected(true); } } else { bw.setEnabled(false); color.setEnabled(false); } }
public Object getDefaultAttributeValue( final Class<? extends Attribute> category) { checkArgs(category, null); final DevmodeStructWrapper dm = getDefaultPrinterProps(); if (JobName.class.equals(category)) { return DEFAULT_JOB_NAME; } else if (RequestingUserName.class.equals(category)) { return new RequestingUserName(getSystemProperty("user.name"), //$NON-NLS-1$ null); } else if (Destination.class.equals(category)) { File file = new File(getSystemProperty("user.dir") //$NON-NLS-1$ + File.separator + "output.prn"); //$NON-NLS-1$ return new Destination(file.toURI()); } else if (OrientationRequested.class.equals(category)) { return dm.getOrientation(); } else if (Paper.class.equals(category)) { return getDefaultPaper(); } else if (Media.class.equals(category)) { return getDefaultPaper().getSize().getMediaSizeName(); } else if (MediaSize.class.equals(category)) { return getDefaultPaper().getSize(); } else if (PrintQuality.class.equals(category)) { return dm.getPrintQuality(); } else if (Sides.class.equals(category)) { return dm.getSides(); } else if (Copies.class.equals(category)) { return dm.getCopies(); } else if (SheetCollate.class.equals(category)) { return dm.getCollate(); } else if (PrinterResolution.class.equals(category)) { return dm.getPrinterResolution(); } else if (Chromaticity.class.equals(category)) { return dm.getChromaticity(); } return null; }
public void setChromaticity(final Chromaticity chromaticity) { if (Chromaticity.COLOR.equals(chromaticity)) { setDmColor(structPtr, DMCOLOR_COLOR); } else if (Chromaticity.MONOCHROME.equals(chromaticity)) { setDmColor(structPtr, DMCOLOR_MONOCHROME); } }
public Class[] getSupportedAttributeCategories() { ArrayList supportedCategories = new ArrayList(); if (getCopiesSupported(serviceName) >= 1) { supportedCategories.add(Copies.class); } if (getSidesSupported(serviceName)) { supportedCategories.add(Sides.class); } if (getSupportedMediaSizeNames() != null) { supportedCategories.add(Media.class); } if (getResolutionsSupported(serviceName) != null) { supportedCategories.add(PrinterResolution.class); } if (getOrientationSupported(serviceName)) { supportedCategories.add(OrientationRequested.class); } if (getCollateSupported(serviceName)) { supportedCategories.add(SheetCollate.class); } supportedCategories.add(Chromaticity.class); supportedCategories.add(JobName.class); supportedCategories.add(RequestingUserName.class); supportedCategories.add(Destination.class); Class[] categories = new Class[supportedCategories.size()]; supportedCategories.toArray(categories); return categories; }
private void updateColor() { if (monoBtn.isEnabled() && monoBtn.isSelected()) { newAttrs.add(Chromaticity.MONOCHROME); } else if (colorBtn.isEnabled() && colorBtn.isSelected()) { newAttrs.add(Chromaticity.COLOR); } else { removeAttribute(Chromaticity.class); } }