Java Code Examples for java.awt.JobAttributes#setDialog()
The following examples show how to use
java.awt.JobAttributes#setDialog() .
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: NullFrameTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JobAttributes ja = new JobAttributes(); ja.setDialog(JobAttributes.DialogType.COMMON); boolean npeThrown = false; try { Toolkit.getDefaultToolkit().getPrintJob(null, "test Printing", ja, null); } catch (NullPointerException ex) { npeThrown = true; } if (!npeThrown) { throw new RuntimeException("getPrintJob didn't throw NPE for null Frame"); } }
Example 2
Source File: PrintTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void printTest() { JobAttributes job = new JobAttributes(); PageAttributes page = new PageAttributes(); job.setDialog(JobAttributes.DialogType.NATIVE); job.setDefaultSelection(JobAttributes.DefaultSelectionType.ALL); job.setFromPage(2); job.setToPage(5); Toolkit tk = Toolkit.getDefaultToolkit(); // setting this dialog to native printdialog if (tk != null) { PrintJob pj = tk.getPrintJob(new JFrame(), "testing the attribute setting ", job, page); } }
Example 3
Source File: HighResTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void init() { String[] instructions = { "To be able to run this test it is required to have a default", "printer configured in your user environment.", "If no default printer exists, then test passes.", " ", "There will be 2 print dialogs. The first dialog should show", "portrait as the selected orientation. The 2nd dialog should show", "landscape as the selected orientation.", " ", "Visual inspection of the printed pages is needed. A passing", "test will print 2 pages in portrait and 2 pages in landscape.", "The pages have on the center of the page the text \"Center\"", "2 rectangles will appear above and below it, the one below is", "filled." }; Sysout.createDialog(); Sysout.printInstructions(instructions); PrintJob job = null; Dimension dim = null; JobAttributes jobAttributes = new JobAttributes(); PageAttributes pageAttributes = new PageAttributes(); String center = "Center"; Font font = new Font("SansSerif", Font.PLAIN, 200); FontMetrics metrics = null; int width = 0; Graphics g = null; jobAttributes.setDialog(DialogType.NATIVE); pageAttributes.setOrigin(OriginType.PRINTABLE); pageAttributes.setPrinterResolution(new int[]{1200, 1200, 3}); pageAttributes.setOrientationRequested( OrientationRequestedType.PORTRAIT); jobAttributes.setSides(SidesType.TWO_SIDED_LONG_EDGE); job = f.getToolkit().getPrintJob(f, "Portrait Test", jobAttributes, pageAttributes); if (job != null) { dim = job.getPageDimension(); for (int i = 0; i < 2; i++) { g = job.getGraphics(); g.drawLine(0, 0, dim.width, 0); g.drawLine(dim.width, 0, dim.width, dim.height); g.drawLine(dim.width, dim.height, 0, dim.height); g.drawLine(0, dim.height, 0, 0); g.drawRect(dim.width / 2 - 200, dim.height / 3 - 300, 400, 600); g.fillRect(dim.width / 2 - 200, 2 * dim.height / 3 - 300, 400, 600); g.setFont(font); metrics = g.getFontMetrics(); width = metrics.stringWidth(center); g.setColor(Color.black); g.drawString(center, (dim.width / 2) - (width / 2), dim.height / 2); g.dispose(); } job.end(); job = null; } pageAttributes.setOrientationRequested( OrientationRequestedType.LANDSCAPE); job = f.getToolkit().getPrintJob(f, "Landscape Test", jobAttributes, pageAttributes); if (job != null) { dim = job.getPageDimension(); for (int i = 0; i < 2; i++) { g = job.getGraphics(); g.drawLine(0, 0, dim.width, 0); g.drawLine(dim.width, 0, dim.width, dim.height); g.drawLine(dim.width, dim.height, 0, dim.height); g.drawLine(0, dim.height, 0, 0); g.drawRect(dim.width / 2 - 200, dim.height / 3 - 300, 400, 600); g.fillRect(dim.width / 2 - 200, 2 * dim.height / 3 - 300, 400, 600); g.setFont(font); metrics = g.getFontMetrics(); width = metrics.stringWidth(center); g.setColor(Color.black); g.drawString(center, (dim.width / 2) - (width / 2), dim.height / 2); g.dispose(); } job.end(); job = null; } System.out.println("done"); }