24143
|
1 |
/*
|
|
2 |
* Copyright (c) 2007, 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 4869502 4869539
|
|
27 |
* @summary Confirm that ToPage is populated for argument =2. Range is disabled for argument = 0.
|
|
28 |
* @run main/manual PrintDlgPageable
|
|
29 |
*/
|
|
30 |
import java.awt.*;
|
|
31 |
import java.awt.print.*;
|
|
32 |
import java.util.Locale;
|
|
33 |
|
|
34 |
import javax.print.*;
|
|
35 |
|
|
36 |
class PrintDlgPageable implements Printable {
|
|
37 |
public static int arg;
|
|
38 |
/**
|
|
39 |
* Constructor
|
|
40 |
*/
|
|
41 |
public PrintDlgPageable() {
|
|
42 |
super();
|
|
43 |
}
|
|
44 |
/**
|
|
45 |
* Starts the application.
|
|
46 |
*/
|
|
47 |
public static void main(java.lang.String[] args) {
|
|
48 |
if (args.length < 1) {
|
|
49 |
System.out.println("usage: java PrintDlgPageable { 0 | 2}");
|
|
50 |
return;
|
|
51 |
}
|
|
52 |
arg = Integer.parseInt(args[0]);
|
|
53 |
PrintDlgPageable pd = new PrintDlgPageable();
|
|
54 |
PrinterJob pj = PrinterJob.getPrinterJob();
|
|
55 |
PageableHandler handler = new PageableHandler();
|
|
56 |
pj.setPageable(handler);
|
|
57 |
|
|
58 |
System.out.println("open PrintDialog..");
|
|
59 |
if (pj.printDialog()) {
|
|
60 |
try {
|
|
61 |
System.out.println("About to print the data ...");
|
|
62 |
pj.print();
|
|
63 |
System.out.println("Printed");
|
|
64 |
}
|
|
65 |
catch (PrinterException pe) {
|
|
66 |
pe.printStackTrace();
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
}
|
|
71 |
|
|
72 |
//printable interface
|
|
73 |
public int print(Graphics g, PageFormat pf, int pi) throws
|
|
74 |
PrinterException {
|
|
75 |
|
|
76 |
/*if (pi > 0) {
|
|
77 |
System.out.println("pi is greater than 0");
|
|
78 |
return Printable.NO_SUCH_PAGE;
|
|
79 |
}*/
|
|
80 |
// Simply draw two rectangles
|
|
81 |
Graphics2D g2 = (Graphics2D)g;
|
|
82 |
g2.setColor(Color.black);
|
|
83 |
g2.translate(pf.getImageableX(), pf.getImageableY());
|
|
84 |
g2.drawRect(1,1,200,300);
|
|
85 |
g2.drawRect(1,1,25,25);
|
|
86 |
System.out.println("print method called "+pi + " Orientation "+pf.getOrientation());
|
|
87 |
return Printable.PAGE_EXISTS;
|
|
88 |
}
|
|
89 |
}
|
|
90 |
|
|
91 |
class PageableHandler implements Pageable {
|
|
92 |
|
|
93 |
PageFormat pf = new PageFormat();
|
|
94 |
|
|
95 |
public int getNumberOfPages() {
|
|
96 |
return PrintDlgPageable.arg;
|
|
97 |
//return 0;
|
|
98 |
}
|
|
99 |
|
|
100 |
public Printable getPrintable(int pageIndex) {
|
|
101 |
return new PrintDlgPageable();
|
|
102 |
}
|
|
103 |
|
|
104 |
public PageFormat getPageFormat(int pageIndex) {
|
|
105 |
System.out.println("getPageFormat called "+pageIndex);
|
|
106 |
if (pageIndex == 0) {
|
|
107 |
pf.setOrientation(PageFormat.PORTRAIT);
|
|
108 |
System.out.println("Orientation returned from Pageable "+findOrientation(pf.getOrientation()));
|
|
109 |
return pf;
|
|
110 |
} else {
|
|
111 |
pf.setOrientation(PageFormat.LANDSCAPE);
|
|
112 |
System.out.println("Orientation returned from Pageable "+findOrientation(pf.getOrientation()));
|
|
113 |
return pf;
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
public String findOrientation(int orient) {
|
|
118 |
if (orient == PageFormat.LANDSCAPE) {
|
|
119 |
return "LANDSCAPE";
|
|
120 |
}else if (orient == PageFormat.PORTRAIT) {
|
|
121 |
return "PORTRAIT";
|
|
122 |
} else if (orient == PageFormat.REVERSE_LANDSCAPE) {
|
|
123 |
return "REVERSE LANDSCAPE";
|
|
124 |
} else {
|
|
125 |
return null;
|
|
126 |
}
|
|
127 |
}
|
|
128 |
}
|