1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 8061267 27 * @summary The specified page range should be displayed in the dialog 28 * @run main/manual=yesno PageRangesDlgTest 29 */ 30 31 import javax.print.*; 32 import javax.print.attribute.*; 33 import javax.print.attribute.standard.*; 34 import java.awt.*; 35 import java.awt.print.*; 36 37 public class PageRangesDlgTest implements Printable { 38 39 static String[] instr = { 40 "This test is to check that the print dialog displays the specified", 41 "page ranges. You must have a printer installed for this test.", 42 "It is valid only on dialogs which support page ranges", 43 "In each dialog, check that a page range of 2 to 3 is requested", 44 "Optionally press Print instead of Cancel, and verify that the", 45 "correct number/set of pages is printed", 46 }; 47 main(String args[])48 public static void main(String args[]) throws Exception { 49 for (int i=0;i<instr.length;i++) { 50 System.out.println(instr[i]); 51 } 52 PrinterJob job = PrinterJob.getPrinterJob(); 53 if (job.getPrintService() == null) { 54 System.out.println("No printers. Test cannot continue."); 55 return; 56 } 57 job.setPrintable(new PageRangesDlgTest()); 58 PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); 59 aset.add(new PageRanges(2,3)); 60 if (job.printDialog(aset)) { 61 job.print(aset); 62 } 63 64 job = PrinterJob.getPrinterJob(); 65 job.setPrintable(new PageRangesDlgTest()); 66 aset.add(DialogTypeSelection.NATIVE); 67 if (job.printDialog()) { 68 job.print(); 69 } 70 } 71 print(Graphics g, PageFormat pf, int pi)72 public int print(Graphics g, PageFormat pf, int pi) 73 throws PrinterException { 74 75 System.out.println("pi="+pi); 76 if (pi >= 5) { 77 return NO_SUCH_PAGE; 78 } 79 80 g.drawString("Page : " + (pi+1), 200, 200); 81 82 return PAGE_EXISTS; 83 } 84 } 85