javax.print.attribute.PrintRequestAttributeSet Java Examples
The following examples show how to use
javax.print.attribute.PrintRequestAttributeSet.
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: PageDlgApp.java From TencentKona-8 with GNU General Public License v2.0 | 7 votes |
public static void main(String[] args) throws Exception { String[] instructions = { "Visual inspection of the dialog is needed. ", "It should be a Printer Job Setup Dialog", "Do nothing except Cancel", "You must NOT press OK", }; SwingUtilities.invokeAndWait(() -> { JOptionPane.showMessageDialog( (Component) null, instructions, "information", JOptionPane.INFORMATION_MESSAGE); }); PrinterJob pj = PrinterJob.getPrinterJob(); PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet(); pSet.add(DialogTypeSelection.NATIVE); if ((pj.pageDialog(pSet)) != null) { throw new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)" + " does not return null when dialog is cancelled"); } }
Example #2
Source File: PageDlgApp.java From openjdk-jdk8u with GNU General Public License v2.0 | 7 votes |
public static void main(String[] args) throws Exception { String[] instructions = { "Visual inspection of the dialog is needed. ", "It should be a Printer Job Setup Dialog", "Do nothing except Cancel", "You must NOT press OK", }; SwingUtilities.invokeAndWait(() -> { JOptionPane.showMessageDialog( (Component) null, instructions, "information", JOptionPane.INFORMATION_MESSAGE); }); PrinterJob pj = PrinterJob.getPrinterJob(); PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet(); pSet.add(DialogTypeSelection.NATIVE); if ((pj.pageDialog(pSet)) != null) { throw new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)" + " does not return null when dialog is cancelled"); } }
Example #3
Source File: WrongPaperPrintingTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void doTest() { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Chromaticity.MONOCHROME); MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5); float[] size = isoA5Size.getSize(Size2DSyntax.INCH); Paper paper = new Paper(); paper.setSize(size[0] * 72.0, size[1] * 72.0); paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0); PageFormat pf = new PageFormat(); pf.setPaper(paper); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf)); if (job.printDialog()) { try { job.print(aset); } catch (PrinterException pe) { throw new RuntimeException(pe); } } }
Example #4
Source File: WrongPaperPrintingTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void doTest() { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(Chromaticity.MONOCHROME); MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5); float[] size = isoA5Size.getSize(Size2DSyntax.INCH); Paper paper = new Paper(); paper.setSize(size[0] * 72.0, size[1] * 72.0); paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0); PageFormat pf = new PageFormat(); pf.setPaper(paper); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf)); if (job.printDialog()) { try { job.print(aset); } catch (PrinterException pe) { throw new RuntimeException(pe); } } }
Example #5
Source File: PSStreamPrintJob.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public void pageableJob(Pageable pageable, 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()); job.setPageable(pageable); 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: WPrinterJob.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private void addPaperSize(PrintRequestAttributeSet aset, int dmIndex, int width, int length) { if (aset == null) { return; } MediaSizeName msn = ((Win32PrintService)myService).findWin32Media(dmIndex); if (msn == null) { msn = ((Win32PrintService)myService). findMatchingMediaSizeNameMM((float)width, (float)length); } if (msn != null) { aset.add(msn); } }
Example #7
Source File: ImageableAreaTest.java From hottub with GNU General Public License v2.0 | 6 votes |
private static void printWithoutPrintDialog() { final JTable table = createAuthorTable(42); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); try { boolean printAccepted = table.print(JTable.PrintMode.FIT_WIDTH, new MessageFormat("Author Table"), new MessageFormat("Page - {0}"), false, pras, false); closeFrame(); if (!printAccepted) { throw new RuntimeException("User cancels the printer job!"); } } catch (Exception e) { throw new RuntimeException(e); } }
Example #8
Source File: PSStreamPrintJob.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public void pageableJob(Pageable pageable, 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()); job.setPageable(pageable); job.print(attributes); notifyEvent(PrintJobEvent.JOB_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; } }
Example #9
Source File: PageSetupPanel.java From gcs with Mozilla Public License 2.0 | 6 votes |
private void createPrintQualityCombo(PrintRequestAttributeSet set) { PrintQuality[] qualities = (PrintQuality[]) mService.getSupportedAttributeValues(PrintQuality.class, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); if (qualities != null && qualities.length > 0) { Set<PrintQuality> possible = new HashSet<>(Arrays.asList(qualities)); ArrayList<Quality> choices = new ArrayList<>(); for (Quality quality : Quality.values()) { if (possible.contains(quality.getPrintQuality())) { choices.add(quality); } } mPrintQuality = new JComboBox<>(choices.toArray(new Quality[0])); mPrintQuality.setSelectedItem(PrintUtilities.getPrintQuality(mService, set, true)); UIUtilities.setToPreferredSizeOnly(mPrintQuality); LinkedLabel label = new LinkedLabel(I18n.Text("Quality"), mPrintQuality); add(label, new PrecisionLayoutData().setEndHorizontalAlignment()); add(mPrintQuality); } else { mPrintQuality = null; } }
Example #10
Source File: WPrinterJob.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private void addPaperSize(PrintRequestAttributeSet aset, int dmIndex, int width, int length) { if (aset == null) { return; } MediaSizeName msn = ((Win32PrintService)myService).findWin32Media(dmIndex); if (msn == null) { msn = ((Win32PrintService)myService). findMatchingMediaSizeNameMM((float)width, (float)length); } if (msn != null) { aset.add(msn); } }
Example #11
Source File: TestMediaTraySelection.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void printTest() { MediaTray tray = null; //tray = getMediaTray( prservices, "Bypass Tray" ); tray = getMediaTray( prservices, "Tray 4" ); PrintRequestAttributeSet atrset = new HashPrintRequestAttributeSet(); //atrset.add( MediaSizeName.ISO_A4 ); atrset.add(tray); PrinterJob pjob = PrinterJob.getPrinterJob(); pjob.setPrintable(new TestMediaTraySelection()); try { pjob.print(atrset); } catch (PrinterException e) { e.printStackTrace(); fail(); } }
Example #12
Source File: PSStreamPrintJob.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void pageableJob(Pageable pageable, 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()); job.setPageable(pageable); job.print(attributes); notifyEvent(PrintJobEvent.JOB_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; } }
Example #13
Source File: PSPrinterJob.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override protected void setAttributes(PrintRequestAttributeSet attributes) throws PrinterException { super.setAttributes(attributes); if (attributes == null) { return; // now always use attributes, so this shouldn't happen. } Attribute attr = attributes.get(Media.class); if (attr instanceof CustomMediaTray) { CustomMediaTray customTray = (CustomMediaTray)attr; String choice = customTray.getChoiceName(); if (choice != null) { mOptions = " InputSlot="+ choice; } } }
Example #14
Source File: PSStreamPrintJob.java From openjdk-jdk8u 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 #15
Source File: PageSetupPanel.java From gcs with Mozilla Public License 2.0 | 5 votes |
private void createNumberUpCombo(PrintRequestAttributeSet set) { NumberUp[] numUp = (NumberUp[]) mService.getSupportedAttributeValues(NumberUp.class, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); if (numUp != null) { int length = numUp.length; if (length > 0) { NumberUp current = PrintUtilities.getNumberUp(mService, set); WrappedNumberUp[] wrappers = new WrappedNumberUp[length]; int selection = 0; for (int i = 0; i < length; i++) { wrappers[i] = new WrappedNumberUp(numUp[i].toString(), numUp[i]); if (numUp[i] == current) { selection = i; } } mNumberUp = new JComboBox<>(wrappers); mNumberUp.setSelectedIndex(selection); UIUtilities.setToPreferredSizeOnly(mNumberUp); LinkedLabel label = new LinkedLabel(I18n.Text("Number Up"), mNumberUp); add(label, new PrecisionLayoutData().setEndHorizontalAlignment()); add(mNumberUp); } else { mNumberUp = null; } } else { mNumberUp = null; } }
Example #16
Source File: PageDialogMarginTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static double getPrintableYFromASet(PrintRequestAttributeSet aset) { try { return ((MediaPrintableArea) aset.get( MediaPrintableArea.class)).getY(MediaPrintableArea.INCH); } catch (Exception e) { return -1.0; } }
Example #17
Source File: RasterPrinterJob.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void setParentWindowID(PrintRequestAttributeSet attrs) { parentWindowID = 0L; onTop = (DialogOnTop)attrs.get(DialogOnTop.class); if (onTop != null) { parentWindowID = onTop.getID(); } }
Example #18
Source File: RasterPrinterJob.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
protected boolean isSupportedValue(Attribute attrval, PrintRequestAttributeSet attrset) { PrintService ps = getPrintService(); return (attrval != null && ps != null && ps.isAttributeValueSupported(attrval, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attrset)); }
Example #19
Source File: PSStreamPrintJob.java From openjdk-8 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 #20
Source File: PSStreamPrintJob.java From openjdk-8-source 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 #21
Source File: RasterPrinterJob.java From hottub with GNU General Public License v2.0 | 5 votes |
protected boolean isSupportedValue(Attribute attrval, PrintRequestAttributeSet attrset) { PrintService ps = getPrintService(); return (attrval != null && ps != null && ps.isAttributeValueSupported(attrval, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attrset)); }
Example #22
Source File: PrintPanel.java From gcs with Mozilla Public License 2.0 | 5 votes |
private void createCopiesField(PrintRequestAttributeSet set) { PrintService service = getService(); if (service.isAttributeCategorySupported(Copies.class)) { mCopies = new EditorField(new DefaultFormatterFactory(new IntegerFormatter(1, 999, false)), null, SwingConstants.RIGHT, Integer.valueOf(PrintUtilities.getCopies(service, set)), Integer.valueOf(999), null); UIUtilities.setToPreferredSizeOnly(mCopies); LinkedLabel label = new LinkedLabel(I18n.Text("Copies"), mCopies); add(label, new PrecisionLayoutData().setEndHorizontalAlignment()); add(mCopies); } else { mCopies = null; } }
Example #23
Source File: RasterPrinterJob.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
protected boolean isSupportedValue(Attribute attrval, PrintRequestAttributeSet attrset) { PrintService ps = getPrintService(); return (attrval != null && ps != null && ps.isAttributeValueSupported(attrval, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attrset)); }
Example #24
Source File: RasterPrinterJob.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
protected boolean isSupportedValue(Attribute attrval, PrintRequestAttributeSet attrset) { PrintService ps = getPrintService(); return (attrval != null && ps != null && ps.isAttributeValueSupported(attrval, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attrset)); }
Example #25
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 #26
Source File: Win32PrintService.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public PrintRequestAttributeSet showDocumentProperties(PrinterJob job, Window owner, PrintService service, PrintRequestAttributeSet aset) { if (!(job instanceof WPrinterJob)) { return null; } WPrinterJob wJob = (WPrinterJob)job; return wJob.showDocumentProperties(owner, service, aset); }
Example #27
Source File: Win32PrintService.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public PrintRequestAttributeSet showDocumentProperties(PrinterJob job, Window owner, PrintService service, PrintRequestAttributeSet aset) { if (!(job instanceof WPrinterJob)) { return null; } WPrinterJob wJob = (WPrinterJob)job; return wJob.showDocumentProperties(owner, service, aset); }
Example #28
Source File: ImageableAreaTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static void printWithCustomImageareaSize() { final JTable table = createAuthorTable(18); PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet(); printAttributes.add(DialogTypeSelection.NATIVE); printAttributes.add(new Copies(1)); printAttributes.add(new MediaPrintableArea( 0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH)); Printable printable = table.getPrintable( JTable.PrintMode.NORMAL, new MessageFormat("Author Table"), new MessageFormat("Page - {0}") ); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(printable); boolean printAccepted = job.printDialog(printAttributes); if (printAccepted) { try { job.print(printAttributes); closeFrame(); } catch (Exception e) { throw new RuntimeException(e); } } else { throw new RuntimeException("User cancels the printer job!"); } }
Example #29
Source File: DlgAttrsBug.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static void printTest() { PrinterJob job = PrinterJob.getPrinterJob(); if (job.getPrintService() == null) { System.out.println("No printers. Test cannot continue"); return; } job.setPrintable(new DlgAttrsBug()); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new Copies(5)); aset.add(new PageRanges(3,4)); aset.add(DialogTypeSelection.NATIVE); job.printDialog(aset); }
Example #30
Source File: RasterPrinterJob.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
protected boolean isSupportedValue(Attribute attrval, PrintRequestAttributeSet attrset) { PrintService ps = getPrintService(); return (attrval != null && ps != null && ps.isAttributeValueSupported(attrval, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attrset)); }