use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.
the class Win32MediaSize 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) {
if (!isDocFlavorSupported(flavor)) {
throw new IllegalArgumentException(flavor + " is an unsupported flavor");
// if postscript & category is already specified within the
// PostScript data we return null
} else if (isAutoSense(flavor) || (isPostScriptFlavor(flavor) && (isPSDocAttr(category)))) {
return null;
}
}
if (!isAttributeCategorySupported(category)) {
return null;
}
if (category == JobName.class) {
return new JobName("Java Printing", null);
} else if (category == RequestingUserName.class) {
String userName = "";
try {
userName = System.getProperty("user.name", "");
} catch (SecurityException se) {
}
return new RequestingUserName(userName, null);
} else if (category == ColorSupported.class) {
int caps = getPrinterCapabilities();
if ((caps & DEVCAP_COLOR) != 0) {
return ColorSupported.SUPPORTED;
} else {
return ColorSupported.NOT_SUPPORTED;
}
} else if (category == Chromaticity.class) {
if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) || flavor.equals(DocFlavor.BYTE_ARRAY.GIF) || flavor.equals(DocFlavor.INPUT_STREAM.GIF) || flavor.equals(DocFlavor.URL.GIF) || flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) || flavor.equals(DocFlavor.INPUT_STREAM.JPEG) || flavor.equals(DocFlavor.URL.JPEG) || flavor.equals(DocFlavor.BYTE_ARRAY.PNG) || flavor.equals(DocFlavor.INPUT_STREAM.PNG) || flavor.equals(DocFlavor.URL.PNG)) {
int caps = getPrinterCapabilities();
if ((caps & DEVCAP_COLOR) == 0) {
Chromaticity[] arr = new Chromaticity[1];
arr[0] = Chromaticity.MONOCHROME;
return (arr);
} else {
Chromaticity[] arr = new Chromaticity[2];
arr[0] = Chromaticity.MONOCHROME;
arr[1] = Chromaticity.COLOR;
return (arr);
}
} else {
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 == OrientationRequested.class) {
if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) || flavor.equals(DocFlavor.INPUT_STREAM.GIF) || flavor.equals(DocFlavor.INPUT_STREAM.JPEG) || flavor.equals(DocFlavor.INPUT_STREAM.PNG) || flavor.equals(DocFlavor.BYTE_ARRAY.GIF) || flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) || flavor.equals(DocFlavor.BYTE_ARRAY.PNG) || flavor.equals(DocFlavor.URL.GIF) || flavor.equals(DocFlavor.URL.JPEG) || flavor.equals(DocFlavor.URL.PNG)) {
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)) {
synchronized (this) {
if (gotCopies == false) {
nCopies = getCopiesSupported(printer, getPort());
gotCopies = true;
}
}
return new CopiesSupported(1, nCopies);
} else if (category == Media.class) {
initMedia();
int len = (mediaSizeNames == null) ? 0 : mediaSizeNames.length;
MediaTray[] trays = getMediaTrays();
len += (trays == null) ? 0 : trays.length;
Media[] arr = new Media[len];
if (mediaSizeNames != null) {
System.arraycopy(mediaSizeNames, 0, arr, 0, mediaSizeNames.length);
}
if (trays != null) {
System.arraycopy(trays, 0, arr, len - trays.length, trays.length);
}
return arr;
} else if (category == MediaPrintableArea.class) {
// if getting printable area for a specific media size
Media mediaName = null;
if ((attributes != null) && ((mediaName = (Media) attributes.get(Media.class)) != null)) {
if (!(mediaName instanceof MediaSizeName)) {
// if an instance of MediaTray, fall thru returning
// all MediaPrintableAreas
mediaName = null;
}
}
MediaPrintableArea[] mpas = getMediaPrintables((MediaSizeName) mediaName);
if (mpas != null) {
MediaPrintableArea[] arr = new MediaPrintableArea[mpas.length];
System.arraycopy(mpas, 0, arr, 0, mpas.length);
return arr;
} else {
return null;
}
} else if (category == SunAlternateMedia.class) {
return new SunAlternateMedia((Media) getDefaultAttributeValue(Media.class));
} 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 == PrinterResolution.class) {
PrinterResolution[] supportedRes = getPrintResolutions();
if (supportedRes == null) {
return null;
}
PrinterResolution[] arr = new PrinterResolution[supportedRes.length];
System.arraycopy(supportedRes, 0, arr, 0, supportedRes.length);
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 if (category == PrintQuality.class) {
PrintQuality[] arr = new PrintQuality[3];
arr[0] = PrintQuality.DRAFT;
arr[1] = PrintQuality.HIGH;
arr[2] = PrintQuality.NORMAL;
return arr;
} 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.COLLATED;
arr[1] = SheetCollate.UNCOLLATED;
return arr;
} else {
return null;
}
} else if (category == Fidelity.class) {
Fidelity[] arr = new Fidelity[2];
arr[0] = Fidelity.FIDELITY_FALSE;
arr[1] = Fidelity.FIDELITY_TRUE;
return arr;
} else {
return null;
}
}
use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.
the class Win32MediaSize method getMediaPrintables.
/*
* Gets a list of MediaPrintableAreas using a call to native function.
* msn is MediaSizeName used to get a specific printable area. If null,
* it will get all the supported MediPrintableAreas.
*/
private synchronized MediaPrintableArea[] getMediaPrintables(MediaSizeName msn) {
if (msn == null) {
if (mpaListInitialized == true) {
return mediaPrintables;
}
} else {
// get from cached mapping of MPAs
if (mpaMap != null && (mpaMap.get(msn) != null)) {
MediaPrintableArea[] mpaArr = new MediaPrintableArea[1];
mpaArr[0] = (MediaPrintableArea) mpaMap.get(msn);
return mpaArr;
}
}
initMedia();
if ((mediaSizeNames == null) || (mediaSizeNames.length == 0)) {
return null;
}
MediaSizeName[] loopNames;
if (msn != null) {
loopNames = new MediaSizeName[1];
loopNames[0] = msn;
} else {
loopNames = mediaSizeNames;
}
if (mpaMap == null) {
mpaMap = new HashMap();
}
for (int i = 0; i < loopNames.length; i++) {
MediaSizeName mediaName = loopNames[i];
if (mpaMap.get(mediaName) != null) {
continue;
}
if (mediaName != null) {
int defPaper = findPaperID(mediaName);
float[] prnArea = (defPaper != 0) ? getMediaPrintableArea(printer, defPaper) : null;
MediaPrintableArea printableArea = null;
if (prnArea != null) {
try {
printableArea = new MediaPrintableArea(prnArea[0], prnArea[1], prnArea[2], prnArea[3], MediaPrintableArea.INCH);
mpaMap.put(mediaName, printableArea);
} catch (IllegalArgumentException e) {
}
} else {
// if getting MPA failed, we use MediaSize
MediaSize ms = MediaSize.getMediaSizeForName((MediaSizeName) mediaName);
if (ms != null) {
try {
printableArea = new MediaPrintableArea(0, 0, ms.getX(MediaSize.INCH), ms.getY(MediaSize.INCH), MediaPrintableArea.INCH);
mpaMap.put(mediaName, printableArea);
} catch (IllegalArgumentException e) {
}
}
}
}
//mediaName != null
}
if (mpaMap.size() == 0) {
return null;
}
if (msn != null) {
if (mpaMap.get(msn) == null) {
return null;
}
MediaPrintableArea[] mpaArr = new MediaPrintableArea[1];
// by this time, we've already gotten the desired MPA
mpaArr[0] = (MediaPrintableArea) mpaMap.get(msn);
return mpaArr;
} else {
mediaPrintables = (MediaPrintableArea[]) mpaMap.values().toArray(new MediaPrintableArea[0]);
mpaListInitialized = true;
return mediaPrintables;
}
}
use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.
the class Win32MediaSize method isAttributeValueSupported.
public boolean isAttributeValueSupported(Attribute attr, DocFlavor flavor, AttributeSet attributes) {
if (attr == null) {
throw new NullPointerException("null attribute");
}
Class category = attr.getCategory();
if (flavor != null) {
if (!isDocFlavorSupported(flavor)) {
throw new IllegalArgumentException(flavor + " is an unsupported flavor");
// if postscript & category is already specified within the PostScript data
// we return false
} else if (isAutoSense(flavor) || (isPostScriptFlavor(flavor) && (isPSDocAttr(category)))) {
return false;
}
}
if (!isAttributeCategorySupported(category)) {
return false;
} else if (category == Chromaticity.class) {
if ((flavor == null) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) || flavor.equals(DocFlavor.BYTE_ARRAY.GIF) || flavor.equals(DocFlavor.INPUT_STREAM.GIF) || flavor.equals(DocFlavor.URL.GIF) || flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) || flavor.equals(DocFlavor.INPUT_STREAM.JPEG) || flavor.equals(DocFlavor.URL.JPEG) || flavor.equals(DocFlavor.BYTE_ARRAY.PNG) || flavor.equals(DocFlavor.INPUT_STREAM.PNG) || flavor.equals(DocFlavor.URL.PNG)) {
int caps = getPrinterCapabilities();
if ((caps & DEVCAP_COLOR) != 0) {
return true;
} else {
return attr == Chromaticity.MONOCHROME;
}
} else {
return false;
}
} else if (category == Copies.class) {
return isSupportedCopies((Copies) attr);
} else if (category == Destination.class) {
URI uri = ((Destination) attr).getURI();
if ("file".equals(uri.getScheme()) && !(uri.getSchemeSpecificPart().equals(""))) {
return true;
} else {
return false;
}
} else if (category == Media.class) {
if (attr instanceof MediaSizeName) {
return isSupportedMedia((MediaSizeName) attr);
}
if (attr instanceof MediaTray) {
return isSupportedMediaTray((MediaTray) attr);
}
} else if (category == MediaPrintableArea.class) {
return isSupportedMediaPrintableArea((MediaPrintableArea) attr);
} else if (category == SunAlternateMedia.class) {
Media media = ((SunAlternateMedia) attr).getMedia();
return isAttributeValueSupported(media, flavor, attributes);
} else if (category == PageRanges.class || category == SheetCollate.class || category == Sides.class) {
if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
return false;
}
} else if (category == PrinterResolution.class) {
if (attr instanceof PrinterResolution) {
return isSupportedResolution((PrinterResolution) attr);
}
} else if (category == OrientationRequested.class) {
if (attr == OrientationRequested.REVERSE_PORTRAIT || (flavor != null) && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) || flavor.equals(DocFlavor.INPUT_STREAM.GIF) || flavor.equals(DocFlavor.INPUT_STREAM.JPEG) || flavor.equals(DocFlavor.INPUT_STREAM.PNG) || flavor.equals(DocFlavor.BYTE_ARRAY.GIF) || flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) || flavor.equals(DocFlavor.BYTE_ARRAY.PNG) || flavor.equals(DocFlavor.URL.GIF) || flavor.equals(DocFlavor.URL.JPEG) || flavor.equals(DocFlavor.URL.PNG))) {
return false;
}
} else if (category == ColorSupported.class) {
int caps = getPrinterCapabilities();
boolean isColorSup = ((caps & DEVCAP_COLOR) != 0);
if ((!isColorSup && (attr == ColorSupported.SUPPORTED)) || (isColorSup && (attr == ColorSupported.NOT_SUPPORTED))) {
return false;
}
}
return true;
}
use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.
the class Win32MediaSize method initMedia.
private synchronized void initMedia() {
if (mediaInitialized == true) {
return;
}
mediaInitialized = true;
int[] media = getAllMediaIDs(printer, getPort());
if (media == null) {
return;
}
ArrayList msnList = new ArrayList();
ArrayList<Win32MediaSize> trailingWmsList = new ArrayList<Win32MediaSize>();
ArrayList printableList = new ArrayList();
MediaSizeName mediaName;
boolean added;
boolean queryFailure = false;
float[] prnArea;
// Get all mediaSizes supported by the printer.
// We convert media to ArrayList idList and pass this to the
// function for getting mediaSizes.
// This is to ensure that mediaSizes and media IDs have 1-1 correspondence.
// We remove from ID list any invalid mediaSize. Though this is rare,
// it happens in HP 4050 German driver.
idList = new ArrayList();
for (int i = 0; i < media.length; i++) {
idList.add(Integer.valueOf(media[i]));
}
ArrayList<String> dmPaperNameList = new ArrayList<String>();
mediaSizes = getMediaSizes(idList, media, dmPaperNameList);
for (int i = 0; i < idList.size(); i++) {
// match Win ID with our predefined ID using table
mediaName = findWin32Media(((Integer) idList.get(i)).intValue());
// the driver is mis-using a standard windows paper ID.
if (mediaName != null && idList.size() == mediaSizes.length) {
MediaSize win32Size = MediaSize.getMediaSizeForName(mediaName);
MediaSize driverSize = mediaSizes[i];
// == 1/10"
int error = 2540;
if (Math.abs(win32Size.getX(1) - driverSize.getX(1)) > error || Math.abs(win32Size.getY(1) - driverSize.getY(1)) > error) {
mediaName = null;
}
}
boolean dmPaperIDMatched = (mediaName != null);
// This requires 1-1 correspondence, lengths must be checked.
if ((mediaName == null) && (idList.size() == mediaSizes.length)) {
mediaName = mediaSizes[i].getMediaSizeName();
}
// Add mediaName to the msnList
added = false;
if (mediaName != null) {
added = addToUniqueList(msnList, mediaName);
}
if ((!dmPaperIDMatched || !added) && (idList.size() == dmPaperNameList.size())) {
/* The following block allows to add such media names to the list, whose sizes
* matched with media sizes predefined in JDK, while whose paper IDs did not,
* or whose sizes and paper IDs both did not match with any predefined in JDK.
*/
Win32MediaSize wms = Win32MediaSize.findMediaName(dmPaperNameList.get(i));
if ((wms == null) && (idList.size() == mediaSizes.length)) {
wms = new Win32MediaSize(dmPaperNameList.get(i), (Integer) idList.get(i));
mediaSizes[i] = new MediaSize(mediaSizes[i].getX(MediaSize.MM), mediaSizes[i].getY(MediaSize.MM), MediaSize.MM, wms);
}
if ((wms != null) && (wms != mediaName)) {
if (!added) {
added = addToUniqueList(msnList, mediaName = wms);
} else {
trailingWmsList.add(wms);
}
}
}
}
for (Win32MediaSize wms : trailingWmsList) {
added = addToUniqueList(msnList, wms);
}
// init mediaSizeNames
mediaSizeNames = new MediaSizeName[msnList.size()];
msnList.toArray(mediaSizeNames);
}
use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.
the class Win32MediaSize method getMediaSizes.
private MediaSize[] getMediaSizes(ArrayList idList, int[] media, ArrayList<String> dmPaperNameList) {
if (dmPaperNameList == null) {
dmPaperNameList = new ArrayList<String>();
}
String prnPort = getPort();
int[] mediaSz = getAllMediaSizes(printer, prnPort);
String[] winMediaNames = getAllMediaNames(printer, prnPort);
MediaSizeName msn = null;
MediaSize ms = null;
float wid, ht;
if ((mediaSz == null) || (winMediaNames == null)) {
return null;
}
int nMedia = mediaSz.length / 2;
ArrayList msList = new ArrayList();
for (int i = 0; i < nMedia; i++, ms = null) {
wid = mediaSz[i * 2] / 10f;
ht = mediaSz[i * 2 + 1] / 10f;
// returned is not constant.
if ((wid <= 0) || (ht <= 0)) {
//Remove corresponding ID from list
if (nMedia == media.length) {
Integer remObj = Integer.valueOf(media[i]);
idList.remove(idList.indexOf(remObj));
}
continue;
}
// Find matching media using dimensions.
// This call matches only with our own predefined sizes.
msn = findMatchingMediaSizeNameMM(wid, ht);
if (msn != null) {
ms = MediaSize.getMediaSizeForName(msn);
}
if (ms != null) {
msList.add(ms);
dmPaperNameList.add(winMediaNames[i]);
} else {
Win32MediaSize wms = Win32MediaSize.findMediaName(winMediaNames[i]);
if (wms == null) {
wms = new Win32MediaSize(winMediaNames[i], media[i]);
}
try {
ms = new MediaSize(wid, ht, MediaSize.MM, wms);
msList.add(ms);
dmPaperNameList.add(winMediaNames[i]);
} catch (IllegalArgumentException e) {
if (nMedia == media.length) {
Integer remObj = Integer.valueOf(media[i]);
idList.remove(idList.indexOf(remObj));
}
}
}
}
MediaSize[] arr2 = new MediaSize[msList.size()];
msList.toArray(arr2);
return arr2;
}
Aggregations