Java Code Examples for javax.print.attribute.standard.OrientationRequested#LANDSCAPE
The following examples show how to use
javax.print.attribute.standard.OrientationRequested#LANDSCAPE .
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: UnixPrintJob.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public void printableJob(Printable printable) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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); } }
Example 2
Source File: UnixPrintJob.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void printableJob(Printable printable) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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); } }
Example 3
Source File: ExportConfig.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
public ExportConfig(String fontFamily, String fontSize, String orientation) { super(); this.fontFamily = fontFamily; if(fontSize!=null){ try { this.fontSize = new Integer(fontSize); } catch (Exception e) { this.fontSize = null; logger.error("Invalid export fontSize. It has to be a number, but fount ["+fontSize+"]"); } } if(orientation.equals("PORTRAIT")){ this.orientation =OrientationRequested.PORTRAIT; } if(orientation.equals("LANDSCAPE")){ this.orientation =OrientationRequested.LANDSCAPE; } if(orientation.equals("REVERSE_LANDSCAPE")){ this.orientation =OrientationRequested.REVERSE_LANDSCAPE; } if(orientation.equals("REVERSE_PORTRAIT")){ this.orientation =OrientationRequested.REVERSE_PORTRAIT; } }
Example 4
Source File: PSStreamPrintJob.java From Bytecoder with Apache License 2.0 | 5 votes |
public void printableJob(Printable printable, PrintRequestAttributeSet attributes) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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(attributes); notifyEvent(PrintJobEvent.JOB_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; } }
Example 5
Source File: PSStreamPrintJob.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void printableJob(Printable printable, PrintRequestAttributeSet attributes) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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(attributes); notifyEvent(PrintJobEvent.JOB_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; } }
Example 6
Source File: PSStreamPrintJob.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void printableJob(Printable printable, PrintRequestAttributeSet attributes) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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(attributes); notifyEvent(PrintJobEvent.JOB_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; } }
Example 7
Source File: PSStreamPrintJob.java From hottub with GNU General Public License v2.0 | 5 votes |
public void printableJob(Printable printable, PrintRequestAttributeSet attributes) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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(attributes); notifyEvent(PrintJobEvent.JOB_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; } }
Example 8
Source File: UnixPrintJob.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public void printableJob(Printable printable) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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); } }
Example 9
Source File: PSStreamPrintJob.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public void printableJob(Printable printable, PrintRequestAttributeSet attributes) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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(attributes); notifyEvent(PrintJobEvent.JOB_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; } }
Example 10
Source File: UnixPrintJob.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void printableJob(Printable printable) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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); } }
Example 11
Source File: UnixPrintJob.java From hottub with GNU General Public License v2.0 | 5 votes |
public void printableJob(Printable printable) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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); } }
Example 12
Source File: UnixPrintJob.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void printableJob(Printable printable) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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); } }
Example 13
Source File: UnixPrintJob.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void printableJob(Printable printable) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); 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); } }
Example 14
Source File: PrintJob2D.java From openjdk-8-source 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 15
Source File: PrintJob2D.java From openjdk-jdk8u-backup 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; }
Example 16
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; }
Example 17
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; }
Example 18
Source File: PrintJob2D.java From openjdk-8 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 19
Source File: PrintJob2D.java From dragonwell8_jdk 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 20
Source File: PrintJob2D.java From jdk8u-jdk 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); }