2
|
1 |
/*
|
|
2 |
* Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/**
|
|
25 |
* @test
|
|
26 |
* @bug 6359283
|
|
27 |
* @summary pagedialog needs to update based on change of printer.
|
|
28 |
* @run main/manual PageFormatChange
|
|
29 |
*/
|
|
30 |
|
|
31 |
import java.awt.print.*;
|
|
32 |
import javax.print.*;
|
|
33 |
|
|
34 |
public class PageFormatChange {
|
|
35 |
|
|
36 |
static String[] text = {
|
|
37 |
"This is is a manual test intended to be run on Windows, and you",
|
|
38 |
"must have at least two printers installed, and ideally the second",
|
|
39 |
"printer should support large paper sizes. When the pageDialog appears",
|
|
40 |
"first change printers, then choose a large paper size, then OK",
|
|
41 |
"the dialog. The test will throw an Exception if it fails",
|
|
42 |
};
|
|
43 |
|
|
44 |
public static void main(String[] args) {
|
|
45 |
if (!System.getProperty("os.name","").startsWith("Windows")) {
|
|
46 |
System.out.println("Not Windows, so test is not applicable");
|
|
47 |
return;
|
|
48 |
}
|
|
49 |
for (String s : text) {
|
|
50 |
System.out.println(s);
|
|
51 |
}
|
|
52 |
PrinterJob job = PrinterJob.getPrinterJob();
|
|
53 |
PrintService service1 = job.getPrintService();
|
|
54 |
PageFormat pf1 = job.defaultPage();
|
|
55 |
PageFormat pf2 = job.pageDialog(pf1);
|
|
56 |
PrintService service2 = job.getPrintService();
|
|
57 |
if (service1.equals(service2)) {
|
|
58 |
System.err.println("You must select a different printer!");
|
|
59 |
System.err.println("Test cannot continue");
|
|
60 |
}
|
|
61 |
if (pf1.equals(pf2)) {
|
|
62 |
System.err.println("You must select a different paper size!");
|
|
63 |
}
|
|
64 |
/* Assume uniform margins, and test if imageable area matches
|
|
65 |
* imageable height.
|
|
66 |
*/
|
|
67 |
int pw = (int)(pf2.getWidth()+0.5);
|
|
68 |
int ph = (int)(pf2.getHeight()+0.5);
|
|
69 |
int iw = (int)(pf2.getImageableWidth()+0.5);
|
|
70 |
int ih = (int)(pf2.getImageableHeight()+0.5);
|
|
71 |
int ix = (int)(pf2.getImageableX()+0.5);
|
|
72 |
int iy = (int)(pf2.getImageableY()+0.5);
|
|
73 |
int expectedWidth = ix*2+iw;
|
|
74 |
int expectedHeight = iy*2+ih;
|
|
75 |
if (expectedWidth != pw || expectedHeight != ph) {
|
|
76 |
throw new RuntimeException("Unexpected size");
|
|
77 |
}
|
|
78 |
displayPageFormat(pf2);
|
|
79 |
}
|
|
80 |
|
|
81 |
public static void displayPageFormat(PageFormat pf)
|
|
82 |
{
|
|
83 |
System.out.println("------- Page Format -------");
|
|
84 |
System.out.println("ImageableX = " + pf.getImageableX());
|
|
85 |
System.out.println("ImageableY = " + pf.getImageableY());
|
|
86 |
System.out.println("ImageableWidth = " + pf.getImageableWidth());
|
|
87 |
System.out.println("ImageableHeight = " + pf.getImageableHeight());
|
|
88 |
System.out.println("Width = " + pf.getWidth());
|
|
89 |
System.out.println("Height = " + pf.getHeight());
|
|
90 |
}
|
|
91 |
|
|
92 |
}
|