use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.
the class WPrinterJob method setWin32MediaAttrib.
private void setWin32MediaAttrib(Attribute attr) {
if (!(attr instanceof MediaSizeName)) {
return;
}
MediaSizeName msn = (MediaSizeName) attr;
mAttMediaSizeName = ((Win32PrintService) myService).findPaperID(msn);
}
use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.
the class Win32PrintJob method printableJob.
public void printableJob(Printable printable) throws PrintException {
try {
synchronized (this) {
if (job != null) {
// shouldn't happen
throw new PrintException("already printing");
} else {
job = new sun.awt.windows.WPrinterJob();
}
}
PrintService svc = getPrintService();
job.setPrintService(svc);
if (copies == 0) {
Copies c = (Copies) svc.getDefaultAttributeValue(Copies.class);
copies = c.getValue();
}
if (mediaName == null) {
Object media = svc.getDefaultAttributeValue(Media.class);
if (media instanceof MediaSizeName) {
mediaName = (MediaSizeName) media;
mediaSize = MediaSize.getMediaSizeForName(mediaName);
}
}
if (orient == null) {
orient = (OrientationRequested) svc.getDefaultAttributeValue(OrientationRequested.class);
}
job.setCopies(copies);
job.setJobName(jobName);
PageFormat pf = new PageFormat();
if (mediaSize != null) {
Paper p = new Paper();
p.setSize(mediaSize.getX(MediaSize.INCH) * 72.0, mediaSize.getY(MediaSize.INCH) * 72.0);
p.setImageableArea(72.0, 72.0, p.getWidth() - 144.0, p.getHeight() - 144.0);
pf.setPaper(p);
}
if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
} else if (orient == OrientationRequested.LANDSCAPE) {
pf.setOrientation(PageFormat.LANDSCAPE);
}
job.setPrintable(printable, pf);
job.print(reqAttrSet);
notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
return;
} catch (PrinterException pe) {
notifyEvent(PrintJobEvent.JOB_FAILED);
throw new PrintException(pe);
} finally {
printReturned = true;
notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
}
}
use of javax.print.attribute.standard.MediaSizeName 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.MediaSizeName in project jdk8u_jdk by JetBrains.
the class Win32MediaSize method addToUniqueList.
private boolean addToUniqueList(ArrayList msnList, MediaSizeName mediaName) {
MediaSizeName msn;
for (int i = 0; i < msnList.size(); i++) {
msn = (MediaSizeName) msnList.get(i);
if (msn == mediaName) {
return false;
}
}
msnList.add(mediaName);
return true;
}
use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.
the class Win32MediaSize method getDefaultAttributeValue.
public Object getDefaultAttributeValue(Class<? extends Attribute> category) {
if (category == null) {
throw new NullPointerException("null category");
}
if (!Attribute.class.isAssignableFrom(category)) {
throw new IllegalArgumentException(category + " is not an Attribute");
}
if (!isAttributeCategorySupported(category)) {
return null;
}
int[] defaults = getDefaultPrinterSettings();
// indices must match those in WPrinterJob.cpp
int defPaper = defaults[0];
int defYRes = defaults[2];
int defQuality = defaults[3];
int defCopies = defaults[4];
int defOrient = defaults[5];
int defSides = defaults[6];
int defCollate = defaults[7];
int defColor = defaults[8];
if (category == Copies.class) {
if (defCopies > 0) {
return new Copies(defCopies);
} else {
return new Copies(1);
}
} else if (category == Chromaticity.class) {
if (defColor == DMCOLOR_COLOR) {
return Chromaticity.COLOR;
} else {
return Chromaticity.MONOCHROME;
}
} else if (category == JobName.class) {
return new JobName("Java Printing", null);
} else if (category == OrientationRequested.class) {
if (defOrient == DMORIENT_LANDSCAPE) {
return OrientationRequested.LANDSCAPE;
} else {
return OrientationRequested.PORTRAIT;
}
} else if (category == PageRanges.class) {
return new PageRanges(1, Integer.MAX_VALUE);
} else if (category == Media.class) {
MediaSizeName msn = findWin32Media(defPaper);
if (msn != null) {
if (!isSupportedMedia(msn) && mediaSizeNames != null) {
msn = mediaSizeNames[0];
defPaper = findPaperID(msn);
}
return msn;
} else {
initMedia();
if ((mediaSizeNames != null) && (mediaSizeNames.length > 0)) {
// cannot be null but to be safe, add a check
if ((idList != null) && (mediaSizes != null) && (idList.size() == mediaSizes.length)) {
Integer defIdObj = Integer.valueOf(defPaper);
int index = idList.indexOf(defIdObj);
if (index >= 0 && index < mediaSizes.length) {
return mediaSizes[index].getMediaSizeName();
}
}
return mediaSizeNames[0];
}
}
} else if (category == MediaPrintableArea.class) {
/* Verify defPaper */
MediaSizeName msn = findWin32Media(defPaper);
if (msn != null && !isSupportedMedia(msn) && mediaSizeNames != null) {
defPaper = findPaperID(mediaSizeNames[0]);
}
float[] prnArea = getMediaPrintableArea(printer, defPaper);
if (prnArea != null) {
MediaPrintableArea printableArea = null;
try {
printableArea = new MediaPrintableArea(prnArea[0], prnArea[1], prnArea[2], prnArea[3], MediaPrintableArea.INCH);
} catch (IllegalArgumentException e) {
}
return printableArea;
}
return null;
} else if (category == SunAlternateMedia.class) {
return null;
} else if (category == Destination.class) {
try {
return new Destination((new File("out.prn")).toURI());
} catch (SecurityException se) {
try {
return new Destination(new URI("file:out.prn"));
} catch (URISyntaxException e) {
return null;
}
}
} else if (category == Sides.class) {
switch(defSides) {
case DMDUP_VERTICAL:
return Sides.TWO_SIDED_LONG_EDGE;
case DMDUP_HORIZONTAL:
return Sides.TWO_SIDED_SHORT_EDGE;
default:
return Sides.ONE_SIDED;
}
} else if (category == PrinterResolution.class) {
int yRes = defYRes;
int xRes = defQuality;
if ((xRes < 0) || (yRes < 0)) {
int res = (yRes > xRes) ? yRes : xRes;
if (res > 0) {
return new PrinterResolution(res, res, PrinterResolution.DPI);
}
} else {
return new PrinterResolution(xRes, yRes, PrinterResolution.DPI);
}
} else if (category == ColorSupported.class) {
int caps = getPrinterCapabilities();
if ((caps & DEVCAP_COLOR) != 0) {
return ColorSupported.SUPPORTED;
} else {
return ColorSupported.NOT_SUPPORTED;
}
} else if (category == PrintQuality.class) {
if ((defQuality < 0) && (defQuality >= DMRES_HIGH)) {
switch(defQuality) {
case DMRES_HIGH:
return PrintQuality.HIGH;
case DMRES_MEDIUM:
return PrintQuality.NORMAL;
default:
return PrintQuality.DRAFT;
}
}
} else if (category == RequestingUserName.class) {
String userName = "";
try {
userName = System.getProperty("user.name", "");
} catch (SecurityException se) {
}
return new RequestingUserName(userName, null);
} else if (category == SheetCollate.class) {
if (defCollate == DMCOLLATE_TRUE) {
return SheetCollate.COLLATED;
} else {
return SheetCollate.UNCOLLATED;
}
} else if (category == Fidelity.class) {
return Fidelity.FIDELITY_FALSE;
}
return null;
}
Aggregations