use of javax.print.attribute.standard.CopiesSupported 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.CopiesSupported 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.CopiesSupported in project jdk8u_jdk by JetBrains.
the class UnixPrintService 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");
} else if (isAutoSense(flavor)) {
return null;
}
}
if (!isAttributeCategorySupported(category)) {
return null;
}
if (category == Chromaticity.class) {
if (flavor == null || isServiceFormattedFlavor(flavor)) {
Chromaticity[] arr = new Chromaticity[1];
arr[0] = Chromaticity.COLOR;
return (arr);
} else {
return null;
}
} else if (category == Destination.class) {
try {
return new Destination((new File("out.ps")).toURI());
} catch (SecurityException se) {
try {
return new Destination(new URI("file:out.ps"));
} catch (URISyntaxException e) {
return null;
}
}
} else if (category == JobName.class) {
return new JobName("Java Printing", null);
} else if (category == JobSheets.class) {
JobSheets[] arr = new JobSheets[2];
arr[0] = JobSheets.NONE;
arr[1] = JobSheets.STANDARD;
return arr;
} else if (category == RequestingUserName.class) {
String userName = "";
try {
userName = System.getProperty("user.name", "");
} catch (SecurityException se) {
}
return new RequestingUserName(userName, null);
} else if (category == OrientationRequested.class) {
if (flavor == null || isServiceFormattedFlavor(flavor)) {
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)) {
if (flavor == null || !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) || flavor.equals(DocFlavor.URL.POSTSCRIPT) || flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) {
return new CopiesSupported(1, MAXCOPIES);
} else {
return null;
}
} 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) {
/* The code below implements the behaviour that if no Media or
* MediaSize attribute is specified, return an array of
* MediaPrintableArea, one for each supported Media.
* If a MediaSize is specified, return a MPA consistent for that,
* and if a Media is specified locate its MediaSize and return
* its MPA, and if none is found, return an MPA for the default
* Media for this service.
*/
if (attributes == null) {
return getAllPrintableAreas();
}
MediaSize mediaSize = (MediaSize) attributes.get(MediaSize.class);
Media media = (Media) attributes.get(Media.class);
MediaPrintableArea[] arr = new MediaPrintableArea[1];
if (mediaSize == null) {
if (media instanceof MediaSizeName) {
MediaSizeName msn = (MediaSizeName) media;
mediaSize = MediaSize.getMediaSizeForName(msn);
if (mediaSize == null) {
/* try to get a size from the default media */
media = (Media) getDefaultAttributeValue(Media.class);
if (media instanceof MediaSizeName) {
msn = (MediaSizeName) media;
mediaSize = MediaSize.getMediaSizeForName(msn);
}
if (mediaSize == null) {
/* shouldn't happen, return a default */
arr[0] = new MediaPrintableArea(0.25f, 0.25f, 8f, 10.5f, MediaSize.INCH);
return arr;
}
}
} else {
return getAllPrintableAreas();
}
}
/* If reach here MediaSize is non-null */
assert mediaSize != null;
arr[0] = new MediaPrintableArea(0.25f, 0.25f, mediaSize.getX(MediaSize.INCH) - 0.5f, mediaSize.getY(MediaSize.INCH) - 0.5f, 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 {
return null;
}
} 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;
}
}
Aggregations