javax.print.attribute.standard.Media Java Examples
The following examples show how to use
javax.print.attribute.standard.Media.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrintServiceStub.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public PrintServiceStub(String name) { _name = name; _flavors = new HashSet<DocFlavor>(); _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE); _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE); _attributes = new HashMap<>(); _attributes.put(PrinterName.class, new PrinterName(name, null)); _attributes.put(PrinterState.class, PrinterState.IDLE); _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location", null)); _attributes.put(PrinterIsAcceptingJobs.class, PrinterIsAcceptingJobs.ACCEPTING_JOBS); _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel( "Custom printer", null)); _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 }); }
Example #2
Source File: PrintServiceStub.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public PrintServiceStub(String name) { _name = name; _flavors = new HashSet<DocFlavor>(); _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE); _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE); _attributes = new HashMap<>(); _attributes.put(PrinterName.class, new PrinterName(name, null)); _attributes.put(PrinterState.class, PrinterState.IDLE); _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location", null)); _attributes.put(PrinterIsAcceptingJobs.class, PrinterIsAcceptingJobs.ACCEPTING_JOBS); _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel( "Custom printer", null)); _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 }); }
Example #3
Source File: PrintServiceStub.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public PrintServiceStub(String name) { _name = name; _flavors = new HashSet<DocFlavor>(); _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE); _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE); _attributes = new HashMap<>(); _attributes.put(PrinterName.class, new PrinterName(name, null)); _attributes.put(PrinterState.class, PrinterState.IDLE); _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location", null)); _attributes.put(PrinterIsAcceptingJobs.class, PrinterIsAcceptingJobs.ACCEPTING_JOBS); _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel( "Custom printer", null)); _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 }); }
Example #4
Source File: UnixPrintService.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private MediaPrintableArea[] getAllPrintableAreas() { if (mpas == null) { Media[] media = (Media[])getSupportedAttributeValues(Media.class, null, null); mpas = new MediaPrintableArea[media.length]; for (int i=0; i< mpas.length; i++) { if (media[i] instanceof MediaSizeName) { MediaSizeName msn = (MediaSizeName)media[i]; MediaSize mediaSize = MediaSize.getMediaSizeForName(msn); if (mediaSize == null) { mpas[i] = (MediaPrintableArea) getDefaultAttributeValue(MediaPrintableArea.class); } else { mpas[i] = new MediaPrintableArea(0.25f, 0.25f, mediaSize.getX(MediaSize.INCH)-0.5f, mediaSize.getY(MediaSize.INCH)-0.5f, MediaSize.INCH); } } } } MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length]; System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length); return mpasCopy; }
Example #5
Source File: WPrinterJob.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** MediaSizeName / dmPaper */ private final int[] getWin32MediaAttrib() { int wid_ht[] = {0, 0}; if (attributes != null) { Media media = (Media)attributes.get(Media.class); if (media instanceof MediaSizeName) { MediaSizeName msn = (MediaSizeName)media; MediaSize ms = MediaSize.getMediaSizeForName(msn); if (ms != null) { wid_ht[0] = (int)(ms.getX(MediaSize.INCH) * 72.0); wid_ht[1] = (int)(ms.getY(MediaSize.INCH) * 72.0); } } } return wid_ht; }
Example #6
Source File: WPrinterJob.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** MediaSizeName / dmPaper */ private final int[] getWin32MediaAttrib() { int wid_ht[] = {0, 0}; if (attributes != null) { Media media = (Media)attributes.get(Media.class); if (media instanceof MediaSizeName) { MediaSizeName msn = (MediaSizeName)media; MediaSize ms = MediaSize.getMediaSizeForName(msn); if (ms != null) { wid_ht[0] = (int)(ms.getX(MediaSize.INCH) * 72.0); wid_ht[1] = (int)(ms.getY(MediaSize.INCH) * 72.0); } } } return wid_ht; }
Example #7
Source File: UnixPrintService.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private MediaPrintableArea[] getAllPrintableAreas() { if (mpas == null) { Media[] media = (Media[])getSupportedAttributeValues(Media.class, null, null); mpas = new MediaPrintableArea[media.length]; for (int i=0; i< mpas.length; i++) { if (media[i] instanceof MediaSizeName) { MediaSizeName msn = (MediaSizeName)media[i]; MediaSize mediaSize = MediaSize.getMediaSizeForName(msn); if (mediaSize == null) { mpas[i] = (MediaPrintableArea) getDefaultAttributeValue(MediaPrintableArea.class); } else { mpas[i] = new MediaPrintableArea(0.25f, 0.25f, mediaSize.getX(MediaSize.INCH)-0.5f, mediaSize.getY(MediaSize.INCH)-0.5f, MediaSize.INCH); } } } } MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length]; System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length); return mpasCopy; }
Example #8
Source File: PrintServiceStub.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public PrintServiceStub(String name) { _name = name; _flavors = new HashSet<DocFlavor>(); _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE); _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE); _attributes = new HashMap<>(); _attributes.put(PrinterName.class, new PrinterName(name, null)); _attributes.put(PrinterState.class, PrinterState.IDLE); _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location", null)); _attributes.put(PrinterIsAcceptingJobs.class, PrinterIsAcceptingJobs.ACCEPTING_JOBS); _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel( "Custom printer", null)); _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 }); }
Example #9
Source File: UnixPrintService.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private MediaPrintableArea[] getAllPrintableAreas() { if (mpas == null) { Media[] media = (Media[])getSupportedAttributeValues(Media.class, null, null); mpas = new MediaPrintableArea[media.length]; for (int i=0; i< mpas.length; i++) { if (media[i] instanceof MediaSizeName) { MediaSizeName msn = (MediaSizeName)media[i]; MediaSize mediaSize = MediaSize.getMediaSizeForName(msn); if (mediaSize == null) { mpas[i] = (MediaPrintableArea) getDefaultAttributeValue(MediaPrintableArea.class); } else { mpas[i] = new MediaPrintableArea(0.25f, 0.25f, mediaSize.getX(MediaSize.INCH)-0.5f, mediaSize.getY(MediaSize.INCH)-0.5f, MediaSize.INCH); } } } } MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length]; System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length); return mpasCopy; }
Example #10
Source File: UnixPrintService.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private MediaPrintableArea[] getAllPrintableAreas() { if (mpas == null) { Media[] media = (Media[])getSupportedAttributeValues(Media.class, null, null); mpas = new MediaPrintableArea[media.length]; for (int i=0; i< mpas.length; i++) { if (media[i] instanceof MediaSizeName) { MediaSizeName msn = (MediaSizeName)media[i]; MediaSize mediaSize = MediaSize.getMediaSizeForName(msn); if (mediaSize == null) { mpas[i] = (MediaPrintableArea) getDefaultAttributeValue(MediaPrintableArea.class); } else { mpas[i] = new MediaPrintableArea(0.25f, 0.25f, mediaSize.getX(MediaSize.INCH)-0.5f, mediaSize.getY(MediaSize.INCH)-0.5f, MediaSize.INCH); } } } } MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length]; System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length); return mpasCopy; }
Example #11
Source File: GetMediasTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); for(final PrintService service: services) { Thread thread = new Thread() { public void run() { service.getSupportedAttributeValues(Media.class, null, null); } }; thread.start(); } }
Example #12
Source File: GetMediasTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); for(final PrintService service: services) { Thread thread = new Thread() { public void run() { service.getSupportedAttributeValues(Media.class, null, null); } }; thread.start(); } }
Example #13
Source File: CPrinterJob.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override protected MediaSize getMediaSize(Media media, PrintService service, PageFormat page) { if (media == null || !(media instanceof MediaSizeName)) { return getDefaultMediaSize(page); } MediaSize size = MediaSize.getMediaSizeForName((MediaSizeName) media); return size != null ? size : getDefaultMediaSize(page); }
Example #14
Source File: CPrinterJob.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override protected MediaSize getMediaSize(Media media, PrintService service, PageFormat page) { if (media == null || !(media instanceof MediaSizeName)) { return getDefaultMediaSize(page); } MediaSize size = MediaSize.getMediaSizeForName((MediaSizeName) media); return size != null ? size : getDefaultMediaSize(page); }
Example #15
Source File: CPrinterJob.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override protected MediaSize getMediaSize(Media media, PrintService service, PageFormat page) { if (media == null || !(media instanceof MediaSizeName)) { return getDefaultMediaSize(page); } MediaSize size = MediaSize.getMediaSizeForName((MediaSizeName) media); return size != null ? size : getDefaultMediaSize(page); }
Example #16
Source File: CPrinterJob.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override protected MediaSize getMediaSize(Media media, PrintService service, PageFormat page) { if (media == null || !(media instanceof MediaSizeName)) { return getDefaultMediaSize(page); } MediaSize size = MediaSize.getMediaSizeForName((MediaSizeName) media); return size != null ? size : getDefaultMediaSize(page); }
Example #17
Source File: PrintJob2D.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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); }
Example #18
Source File: SunAlternateMedia.java From Bytecoder with Apache License 2.0 | 4 votes |
public SunAlternateMedia(Media altMedia) { media = altMedia; }
Example #19
Source File: CustomMediaSizeName.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Returns the string table for super class MediaSizeName. */ public Media[] getSuperEnumTable() { return (Media[])super.getEnumValueTable(); }
Example #20
Source File: CustomMediaSizeName.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Returns closest matching MediaSizeName among given array of Media */ public static MediaSizeName findMedia(Media[] media, float x, float y, int units) { if (x <= 0.0f || y <= 0.0f || units < 1) { throw new IllegalArgumentException("args must be +ve values"); } if (media == null || media.length == 0) { throw new IllegalArgumentException("args must have valid array of media"); } int size =0; MediaSizeName[] msn = new MediaSizeName[media.length]; for (int i=0; i<media.length; i++) { if (media[i] instanceof MediaSizeName) { msn[size++] = (MediaSizeName)media[i]; } } if (size == 0) { return null; } int match = 0; double ls = x * x + y * y; double tmp_ls; float []dim; float diffx = x; float diffy = y; for (int i=0; i < size ; i++) { MediaSize mediaSize = MediaSize.getMediaSizeForName(msn[i]); if (mediaSize == null) { continue; } dim = mediaSize.getSize(units); if (x == dim[0] && y == dim[1]) { match = i; break; } else { diffx = x - dim[0]; diffy = y - dim[1]; tmp_ls = diffx * diffx + diffy * diffy; if (tmp_ls < ls) { ls = tmp_ls; match = i; } } } return msn[match]; }
Example #21
Source File: CustomMediaTray.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Returns the string table for super class MediaTray. */ public Media[] getSuperEnumTable() { return (Media[])super.getEnumValueTable(); }
Example #22
Source File: UnixPrintJob.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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 == 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 { mDestType = DESTFILE; 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 == JobSheets.class) { if ((JobSheets)attr == JobSheets.NONE) { mNoJobSheet = true; } } 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; IPPPrintService.debug_println(debugPrefix+ "mediaName "+mediaName); if (!service.isAttributeValueSupported(attr, null, null)) { mediaSize = MediaSize.getMediaSizeForName(mediaName); } } else if (attr instanceof CustomMediaTray) { customTray = (CustomMediaTray)attr; } } else if (category == OrientationRequested.class) { orient = (OrientationRequested)attr; } else if (category == NumberUp.class) { nUp = (NumberUp)attr; } else if (category == Sides.class) { sides = (Sides)attr; } } }
Example #23
Source File: PSStreamPrintService.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public boolean isAttributeValueSupported(Attribute attr, DocFlavor flavor, AttributeSet attributes) { if (attr == null) { throw new NullPointerException("null attribute"); } if (flavor != null && !isDocFlavorSupported(flavor)) { throw new IllegalArgumentException(flavor + " is an unsupported flavor"); } Class category = attr.getCategory(); if (!isAttributeCategorySupported(category)) { return false; } else if (attr.getCategory() == Chromaticity.class) { return attr == Chromaticity.COLOR; } else if (attr.getCategory() == Copies.class) { return isSupportedCopies((Copies)attr); } else if (attr.getCategory() == Media.class && attr instanceof MediaSizeName) { return isSupportedMedia((MediaSizeName)attr); } else if (attr.getCategory() == OrientationRequested.class) { if (attr == OrientationRequested.REVERSE_PORTRAIT || (flavor != null) && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { return false; } } else if (attr.getCategory() == PageRanges.class) { if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { return false; } } else if (attr.getCategory() == SheetCollate.class) { if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { return false; } } else if (attr.getCategory() == Sides.class) { if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { return false; } } return true; }
Example #24
Source File: UnixPrintService.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public boolean isAttributeValueSupported(Attribute attr, DocFlavor flavor, AttributeSet attributes) { if (attr == null) { throw new NullPointerException("null attribute"); } if (flavor != null) { if (!isDocFlavorSupported(flavor)) { throw new IllegalArgumentException(flavor + " is an unsupported flavor"); } else if (isAutoSense(flavor)) { return false; } } Class category = attr.getCategory(); if (!isAttributeCategorySupported(category)) { return false; } else if (attr.getCategory() == Chromaticity.class) { if (flavor == null || isServiceFormattedFlavor(flavor)) { return attr == Chromaticity.COLOR; } else { return false; } } else if (attr.getCategory() == Copies.class) { return (flavor == null || !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) || flavor.equals(DocFlavor.URL.POSTSCRIPT) || flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) && isSupportedCopies((Copies)attr); } else if (attr.getCategory() == Destination.class) { URI uri = ((Destination)attr).getURI(); if ("file".equals(uri.getScheme()) && !(uri.getSchemeSpecificPart().equals(""))) { return true; } else { return false; } } else if (attr.getCategory() == Media.class) { if (attr instanceof MediaSizeName) { return isSupportedMedia((MediaSizeName)attr); } else { return false; } } else if (attr.getCategory() == OrientationRequested.class) { if (attr == OrientationRequested.REVERSE_PORTRAIT || (flavor != null) && !isServiceFormattedFlavor(flavor)) { return false; } } else if (attr.getCategory() == PageRanges.class) { if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { return false; } } else if (attr.getCategory() == SheetCollate.class) { if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { return false; } } else if (attr.getCategory() == Sides.class) { if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { return false; } } return true; }
Example #25
Source File: SunAlternateMedia.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public Media getMedia() { return media; }
Example #26
Source File: SunAlternateMedia.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public SunAlternateMedia(Media altMedia) { media = altMedia; }
Example #27
Source File: UnixPrintService.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public boolean isAttributeValueSupported(Attribute attr, DocFlavor flavor, AttributeSet attributes) { if (attr == null) { throw new NullPointerException("null attribute"); } if (flavor != null) { if (!isDocFlavorSupported(flavor)) { throw new IllegalArgumentException(flavor + " is an unsupported flavor"); } else if (isAutoSense(flavor)) { return false; } } Class category = attr.getCategory(); if (!isAttributeCategorySupported(category)) { return false; } else if (attr.getCategory() == Chromaticity.class) { if (flavor == null || isServiceFormattedFlavor(flavor)) { return attr == Chromaticity.COLOR; } else { return false; } } else if (attr.getCategory() == Copies.class) { return (flavor == null || !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) || flavor.equals(DocFlavor.URL.POSTSCRIPT) || flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) && isSupportedCopies((Copies)attr); } else if (attr.getCategory() == Destination.class) { URI uri = ((Destination)attr).getURI(); if ("file".equals(uri.getScheme()) && !(uri.getSchemeSpecificPart().equals(""))) { return true; } else { return false; } } else if (attr.getCategory() == Media.class) { if (attr instanceof MediaSizeName) { return isSupportedMedia((MediaSizeName)attr); } else { return false; } } else if (attr.getCategory() == OrientationRequested.class) { if (attr == OrientationRequested.REVERSE_PORTRAIT || (flavor != null) && !isServiceFormattedFlavor(flavor)) { return false; } } else if (attr.getCategory() == PageRanges.class) { if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { return false; } } else if (attr.getCategory() == SheetCollate.class) { if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { return false; } } else if (attr.getCategory() == Sides.class) { if (flavor != null && !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) { return false; } } return true; }
Example #28
Source File: UnixPrintJob.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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 == 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 { mDestType = DESTFILE; 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 == JobSheets.class) { if ((JobSheets)attr == JobSheets.NONE) { mNoJobSheet = true; } } 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; IPPPrintService.debug_println(debugPrefix+ "mediaName "+mediaName); if (!service.isAttributeValueSupported(attr, null, null)) { mediaSize = MediaSize.getMediaSizeForName(mediaName); } } else if (attr instanceof CustomMediaTray) { customTray = (CustomMediaTray)attr; } } else if (category == OrientationRequested.class) { orient = (OrientationRequested)attr; } else if (category == NumberUp.class) { nUp = (NumberUp)attr; } else if (category == Sides.class) { sides = (Sides)attr; } } }
Example #29
Source File: CustomMediaSizeName.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Returns closest matching MediaSizeName among given array of Media */ public static MediaSizeName findMedia(Media[] media, float x, float y, int units) { if (x <= 0.0f || y <= 0.0f || units < 1) { throw new IllegalArgumentException("args must be +ve values"); } if (media == null || media.length == 0) { throw new IllegalArgumentException("args must have valid array of media"); } int size =0; MediaSizeName[] msn = new MediaSizeName[media.length]; for (int i=0; i<media.length; i++) { if (media[i] instanceof MediaSizeName) { msn[size++] = (MediaSizeName)media[i]; } } if (size == 0) { return null; } int match = 0; double ls = x * x + y * y; double tmp_ls; float []dim; float diffx = x; float diffy = y; for (int i=0; i < size ; i++) { MediaSize mediaSize = MediaSize.getMediaSizeForName(msn[i]); if (mediaSize == null) { continue; } dim = mediaSize.getSize(units); if (x == dim[0] && y == dim[1]) { match = i; break; } else { diffx = x - dim[0]; diffy = y - dim[1]; tmp_ls = diffx * diffx + diffy * diffy; if (tmp_ls < ls) { ls = tmp_ls; match = i; } } } return msn[match]; }
Example #30
Source File: PrintJob2D.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public boolean printDialog() { boolean proceedWithPrint = false; printerJob = PrinterJob.getPrinterJob(); if (printerJob == null) { return false; } DialogType d = this.jobAttributes.getDialog(); PrintService pServ = printerJob.getPrintService(); if ((pServ == null) && (d == DialogType.NONE)){ return false; } copyAttributes(pServ); DefaultSelectionType select = this.jobAttributes.getDefaultSelection(); if (select == DefaultSelectionType.RANGE) { attributes.add(SunPageSelection.RANGE); } else if (select == DefaultSelectionType.SELECTION) { attributes.add(SunPageSelection.SELECTION); } else { attributes.add(SunPageSelection.ALL); } if (frame != null) { attributes.add(new DialogOwner(frame)); } if ( d == DialogType.NONE) { proceedWithPrint = true; } else { if (d == DialogType.NATIVE) { attributes.add(DialogTypeSelection.NATIVE); } else { // (d == DialogType.COMMON) attributes.add(DialogTypeSelection.COMMON); } if (proceedWithPrint = printerJob.printDialog(attributes)) { if (pServ == null) { // Windows gives an option to install a service // when it detects there are no printers so // we make sure we get the updated print service. pServ = printerJob.getPrintService(); if (pServ == null) { return false; } } updateAttributes(); translateOutputProps(); } } if (proceedWithPrint) { JobName jname = (JobName)attributes.get(JobName.class); if (jname != null) { printerJob.setJobName(jname.toString()); } pageFormat = new PageFormat(); Media media = (Media)attributes.get(Media.class); MediaSize mediaSize = null; if (media != null && media instanceof MediaSizeName) { mediaSize = MediaSize.getMediaSizeForName((MediaSizeName)media); } Paper p = pageFormat.getPaper(); if (mediaSize != null) { p.setSize(mediaSize.getX(MediaSize.INCH)*72.0, mediaSize.getY(MediaSize.INCH)*72.0); } if (pageAttributes.getOrigin()==OriginType.PRINTABLE) { // AWT uses 1/4" borders by default p.setImageableArea(18.0, 18.0, p.getWidth()-36.0, p.getHeight()-36.0); } else { p.setImageableArea(0.0,0.0,p.getWidth(),p.getHeight()); } pageFormat.setPaper(p); OrientationRequested orient = (OrientationRequested)attributes.get(OrientationRequested.class); if (orient!= null && orient == OrientationRequested.REVERSE_LANDSCAPE) { pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE); } else if (orient == OrientationRequested.LANDSCAPE) { pageFormat.setOrientation(PageFormat.LANDSCAPE); } else { pageFormat.setOrientation(PageFormat.PORTRAIT); } printerJob.setPrintable(this, pageFormat); } return proceedWithPrint; }