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