use of javax.print.attribute.standard.JobName 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.JobName 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.JobName in project jdk8u_jdk by JetBrains.
the class PSStreamPrintService method getSupportedAttributeValues.
public Object getSupportedAttributeValues(Class<? extends Attribute> category, DocFlavor flavor, AttributeSet attributes) {
if (category == null) {
throw new NullPointerException("null category");
}
if (!Attribute.class.isAssignableFrom(category)) {
throw new IllegalArgumentException(category + " does not implement Attribute");
}
if (flavor != null && !isDocFlavorSupported(flavor)) {
throw new IllegalArgumentException(flavor + " is an unsupported flavor");
}
if (!isAttributeCategorySupported(category)) {
return null;
}
if (category == Chromaticity.class) {
Chromaticity[] arr = new Chromaticity[1];
arr[0] = Chromaticity.COLOR;
//arr[1] = Chromaticity.MONOCHROME;
return (arr);
} else if (category == JobName.class) {
return new JobName("", null);
} else if (category == RequestingUserName.class) {
return new RequestingUserName("", null);
} else if (category == OrientationRequested.class) {
if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
OrientationRequested[] arr = new OrientationRequested[3];
arr[0] = OrientationRequested.PORTRAIT;
arr[1] = OrientationRequested.LANDSCAPE;
arr[2] = OrientationRequested.REVERSE_LANDSCAPE;
return arr;
} else {
return null;
}
} else if ((category == Copies.class) || (category == CopiesSupported.class)) {
return new CopiesSupported(1, MAXCOPIES);
} else if (category == Media.class) {
Media[] arr = new Media[mediaSizes.length];
System.arraycopy(mediaSizes, 0, arr, 0, mediaSizes.length);
return arr;
} else if (category == Fidelity.class) {
Fidelity[] arr = new Fidelity[2];
arr[0] = Fidelity.FIDELITY_FALSE;
arr[1] = Fidelity.FIDELITY_TRUE;
return arr;
} else if (category == MediaPrintableArea.class) {
if (attributes == null) {
return null;
}
MediaSize mediaSize = (MediaSize) attributes.get(MediaSize.class);
if (mediaSize == null) {
Media media = (Media) attributes.get(Media.class);
if (media != null && media instanceof MediaSizeName) {
MediaSizeName msn = (MediaSizeName) media;
mediaSize = MediaSize.getMediaSizeForName(msn);
}
}
if (mediaSize == null) {
return null;
} else {
MediaPrintableArea[] arr = new MediaPrintableArea[1];
float w = mediaSize.getX(MediaSize.INCH);
float h = mediaSize.getY(MediaSize.INCH);
/* For dimensions >= 5 inches use 0.5 inch margins.
* For smaller dimensions, use 10% margins.
*/
float xmargin = 0.5f;
float ymargin = 0.5f;
if (w < 5f) {
xmargin = w / 10;
}
if (h < 5f) {
ymargin = h / 10;
}
arr[0] = new MediaPrintableArea(xmargin, ymargin, w - 2 * xmargin, h - 2 * ymargin, MediaSize.INCH);
return arr;
}
} else if (category == PageRanges.class) {
if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
PageRanges[] arr = new PageRanges[1];
arr[0] = new PageRanges(1, Integer.MAX_VALUE);
return arr;
} else {
return null;
}
} else if (category == SheetCollate.class) {
if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
SheetCollate[] arr = new SheetCollate[2];
arr[0] = SheetCollate.UNCOLLATED;
arr[1] = SheetCollate.COLLATED;
return arr;
} else {
SheetCollate[] arr = new SheetCollate[1];
arr[0] = SheetCollate.UNCOLLATED;
return arr;
}
} else if (category == Sides.class) {
if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
Sides[] arr = new Sides[3];
arr[0] = Sides.ONE_SIDED;
arr[1] = Sides.TWO_SIDED_LONG_EDGE;
arr[2] = Sides.TWO_SIDED_SHORT_EDGE;
return arr;
} else {
return null;
}
} else {
return null;
}
}
use of javax.print.attribute.standard.JobName in project jdk8u_jdk by JetBrains.
the class Win32PrintJob method getAttributeValues.
private void getAttributeValues(DocFlavor flavor) throws PrintException {
if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
fidelity = true;
} else {
fidelity = false;
}
Class category;
Attribute[] attrs = reqAttrSet.toArray();
for (int i = 0; i < attrs.length; i++) {
Attribute 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 {
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 == 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;
// be used to create a new PageFormat.
if (!service.isAttributeValueSupported(attr, null, null)) {
mediaSize = MediaSize.getMediaSizeForName(mediaName);
}
}
} else if (category == OrientationRequested.class) {
orient = (OrientationRequested) attr;
}
}
}
use of javax.print.attribute.standard.JobName in project jdk8u_jdk by JetBrains.
the class Win32PrintJob method initializeAttributeSets.
/* There's some inefficiency here as the job set is created even though
* it may never be requested.
*/
private synchronized void initializeAttributeSets(Doc doc, PrintRequestAttributeSet reqSet) {
reqAttrSet = new HashPrintRequestAttributeSet();
jobAttrSet = new HashPrintJobAttributeSet();
Attribute[] attrs;
if (reqSet != null) {
reqAttrSet.addAll(reqSet);
attrs = reqSet.toArray();
for (int i = 0; i < attrs.length; i++) {
if (attrs[i] instanceof PrintJobAttribute) {
jobAttrSet.add(attrs[i]);
}
}
}
DocAttributeSet docSet = doc.getAttributes();
if (docSet != null) {
attrs = docSet.toArray();
for (int i = 0; i < attrs.length; i++) {
if (attrs[i] instanceof PrintRequestAttribute) {
reqAttrSet.add(attrs[i]);
}
if (attrs[i] instanceof PrintJobAttribute) {
jobAttrSet.add(attrs[i]);
}
}
}
/* add the user name to the job */
String userName = "";
try {
userName = System.getProperty("user.name");
} catch (SecurityException se) {
}
if (userName == null || userName.equals("")) {
RequestingUserName ruName = (RequestingUserName) reqSet.get(RequestingUserName.class);
if (ruName != null) {
jobAttrSet.add(new JobOriginatingUserName(ruName.getValue(), ruName.getLocale()));
} else {
jobAttrSet.add(new JobOriginatingUserName("", null));
}
} else {
jobAttrSet.add(new JobOriginatingUserName(userName, null));
}
/* if no job name supplied use doc name (if supplied), if none and
* its a URL use that, else finally anything .. */
if (jobAttrSet.get(JobName.class) == null) {
JobName jobName;
if (docSet != null && docSet.get(DocumentName.class) != null) {
DocumentName docName = (DocumentName) docSet.get(DocumentName.class);
jobName = new JobName(docName.getValue(), docName.getLocale());
jobAttrSet.add(jobName);
} else {
String str = "JPS Job:" + doc;
try {
Object printData = doc.getPrintData();
if (printData instanceof URL) {
str = ((URL) (doc.getPrintData())).toString();
}
} catch (IOException e) {
}
jobName = new JobName(str, null);
jobAttrSet.add(jobName);
}
}
jobAttrSet = AttributeSetUtilities.unmodifiableView(jobAttrSet);
}
Aggregations