use of javax.print.attribute.standard.Copies in project jdk8u_jdk by JetBrains.
the class ImageableAreaTest method printWithCustomImageareaSize.
private static void printWithCustomImageareaSize() {
final JTable table = createAuthorTable(18);
PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
printAttributes.add(DialogTypeSelection.NATIVE);
printAttributes.add(new Copies(1));
printAttributes.add(new MediaPrintableArea(0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
Printable printable = table.getPrintable(JTable.PrintMode.NORMAL, new MessageFormat("Author Table"), new MessageFormat("Page - {0}"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog(printAttributes);
if (printAccepted) {
try {
job.print(printAttributes);
closeFrame();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("User cancels the printer job!");
}
}
use of javax.print.attribute.standard.Copies in project adempiere by adempiere.
the class ReportEngine method print.
// getView
/**************************************************************************
* Print Report
*/
public void print() {
log.info(m_info.toString());
if (m_layout == null)
layout();
// Paper Attributes: media-printable-area, orientation-requested, media
PrintRequestAttributeSet prats = m_layout.getPaper().getPrintRequestAttributeSet();
// add: copies, job-name, priority
if (m_info.isDocumentCopy() || m_info.getCopies() < 1)
prats.add(new Copies(1));
else
prats.add(new Copies(m_info.getCopies()));
Locale locale = Language.getLoginLanguage().getLocale();
prats.add(new JobName(m_printFormat.getName(), locale));
prats.add(PrintUtil.getJobPriority(m_layout.getNumberOfPages(), m_info.getCopies(), true));
try {
// PrinterJob
PrinterJob job = getPrinterJob(m_info.getPrinterName());
// job.getPrintService().addPrintServiceAttributeListener(this);
// no copy
job.setPageable(m_layout.getPageable(false));
// Dialog
try {
if (m_info.isWithDialog() && !job.printDialog(prats))
return;
} catch (Exception e) {
log.log(Level.WARNING, "Operating System Print Issue, check & try again", e);
return;
}
// submit
boolean printCopy = m_info.isDocumentCopy() && m_info.getCopies() > 1;
ArchiveEngine.get().archive(m_layout, m_info);
PrintUtil.print(job, prats, false, printCopy);
// Document: Print Copies
if (printCopy) {
log.info("Copy " + (m_info.getCopies() - 1));
prats.add(new Copies(m_info.getCopies() - 1));
job = getPrinterJob(m_info.getPrinterName());
// job.getPrintService().addPrintServiceAttributeListener(this);
// Copy
job.setPageable(m_layout.getPageable(true));
PrintUtil.print(job, prats, false, false);
}
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
}
}
use of javax.print.attribute.standard.Copies in project jdk8u_jdk by JetBrains.
the class PSPrinterJob method printDialog.
/* Instance Methods */
/**
* Presents the user a dialog for changing properties of the
* print job interactively.
* @returns false if the user cancels the dialog and
* true otherwise.
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public boolean printDialog() throws HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
if (attributes == null) {
attributes = new HashPrintRequestAttributeSet();
}
attributes.add(new Copies(getCopies()));
attributes.add(new JobName(getJobName(), null));
boolean doPrint = false;
DialogTypeSelection dts = (DialogTypeSelection) attributes.get(DialogTypeSelection.class);
if (dts == DialogTypeSelection.NATIVE) {
// Remove DialogTypeSelection.NATIVE to prevent infinite loop in
// RasterPrinterJob.
attributes.remove(DialogTypeSelection.class);
doPrint = printDialog(attributes);
// restore attribute
attributes.add(DialogTypeSelection.NATIVE);
} else {
doPrint = printDialog(attributes);
}
if (doPrint) {
JobName jobName = (JobName) attributes.get(JobName.class);
if (jobName != null) {
setJobName(jobName.getValue());
}
Copies copies = (Copies) attributes.get(Copies.class);
if (copies != null) {
setCopies(copies.getValue());
}
Destination dest = (Destination) attributes.get(Destination.class);
if (dest != null) {
try {
mDestType = RasterPrinterJob.FILE;
mDestination = (new File(dest.getURI())).getPath();
} catch (Exception e) {
mDestination = "out.ps";
}
} else {
mDestType = RasterPrinterJob.PRINTER;
PrintService pServ = getPrintService();
if (pServ != null) {
mDestination = pServ.getName();
if (isMac) {
PrintServiceAttributeSet psaSet = pServ.getAttributes();
if (psaSet != null) {
mDestination = psaSet.get(PrinterName.class).toString();
}
}
}
}
}
return doPrint;
}
use of javax.print.attribute.standard.Copies in project jdk8u_jdk by JetBrains.
the class PSStreamPrintJob 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 == JobName.class) {
jobName = ((JobName) attr).getValue();
} else if (category == Copies.class) {
copies = ((Copies) attr).getValue();
} else if (category == Media.class) {
if (attr instanceof MediaSizeName && service.isAttributeValueSupported(attr, null, null)) {
mediaSize = MediaSize.getMediaSizeForName((MediaSizeName) attr);
}
} else if (category == OrientationRequested.class) {
orient = (OrientationRequested) attr;
}
}
}
use of javax.print.attribute.standard.Copies in project jdk8u_jdk by JetBrains.
the class PrintJob2D method updateAttributes.
private void updateAttributes() {
Copies c = (Copies) attributes.get(Copies.class);
jobAttributes.setCopies(c.getValue());
SunPageSelection sel = (SunPageSelection) attributes.get(SunPageSelection.class);
if (sel == SunPageSelection.RANGE) {
jobAttributes.setDefaultSelection(DefaultSelectionType.RANGE);
} else if (sel == SunPageSelection.SELECTION) {
jobAttributes.setDefaultSelection(DefaultSelectionType.SELECTION);
} else {
jobAttributes.setDefaultSelection(DefaultSelectionType.ALL);
}
Destination dest = (Destination) attributes.get(Destination.class);
if (dest != null) {
jobAttributes.setDestination(DestinationType.FILE);
jobAttributes.setFileName(dest.getURI().getPath());
} else {
jobAttributes.setDestination(DestinationType.PRINTER);
}
PrintService serv = printerJob.getPrintService();
if (serv != null) {
jobAttributes.setPrinter(serv.getName());
}
PageRanges range = (PageRanges) attributes.get(PageRanges.class);
int[][] members = range.getMembers();
jobAttributes.setPageRanges(members);
SheetCollate collation = (SheetCollate) attributes.get(SheetCollate.class);
if (collation == SheetCollate.COLLATED) {
jobAttributes.setMultipleDocumentHandling(MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES);
} else {
jobAttributes.setMultipleDocumentHandling(MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);
}
Sides sides = (Sides) attributes.get(Sides.class);
if (sides == Sides.TWO_SIDED_LONG_EDGE) {
jobAttributes.setSides(SidesType.TWO_SIDED_LONG_EDGE);
} else if (sides == Sides.TWO_SIDED_SHORT_EDGE) {
jobAttributes.setSides(SidesType.TWO_SIDED_SHORT_EDGE);
} else {
jobAttributes.setSides(SidesType.ONE_SIDED);
}
// PageAttributes
Chromaticity color = (Chromaticity) attributes.get(Chromaticity.class);
if (color == Chromaticity.COLOR) {
pageAttributes.setColor(ColorType.COLOR);
} else {
pageAttributes.setColor(ColorType.MONOCHROME);
}
OrientationRequested orient = (OrientationRequested) attributes.get(OrientationRequested.class);
if (orient == OrientationRequested.LANDSCAPE) {
pageAttributes.setOrientationRequested(OrientationRequestedType.LANDSCAPE);
} else {
pageAttributes.setOrientationRequested(OrientationRequestedType.PORTRAIT);
}
PrintQuality qual = (PrintQuality) attributes.get(PrintQuality.class);
if (qual == PrintQuality.DRAFT) {
pageAttributes.setPrintQuality(PrintQualityType.DRAFT);
} else if (qual == PrintQuality.HIGH) {
pageAttributes.setPrintQuality(PrintQualityType.HIGH);
} else {
// NORMAL
pageAttributes.setPrintQuality(PrintQualityType.NORMAL);
}
Media msn = (Media) attributes.get(Media.class);
if (msn != null && msn instanceof MediaSizeName) {
MediaType mType = unMapMedia((MediaSizeName) msn);
if (mType != null) {
pageAttributes.setMedia(mType);
}
}
debugPrintAttributes(false, false);
}
Aggregations