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 4865976 7158366
|
|
27 |
@summary Pass if it program exits.
|
|
28 |
@run main/manual PrintDlgApp
|
|
29 |
*/
|
|
30 |
import java.awt.*;
|
|
31 |
import java.awt.print.*;
|
|
32 |
import javax.print.attribute.*;
|
|
33 |
import javax.print.attribute.standard.Copies;
|
|
34 |
import javax.print.attribute.standard.Destination;
|
|
35 |
import java.util.Locale;
|
|
36 |
|
|
37 |
import javax.print.*;
|
|
38 |
|
|
39 |
class PrintDlgApp implements Printable {
|
|
40 |
/**
|
|
41 |
* Constructor
|
|
42 |
*/
|
|
43 |
public PrintDlgApp() {
|
|
44 |
super();
|
|
45 |
}
|
|
46 |
/**
|
|
47 |
* Starts the application.
|
|
48 |
*/
|
|
49 |
public static void main(java.lang.String[] args) {
|
|
50 |
PrintDlgApp pd = new PrintDlgApp();
|
|
51 |
PrinterJob pj = PrinterJob.getPrinterJob();
|
|
52 |
System.out.println(pj);
|
|
53 |
PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
|
|
54 |
pSet.add(new Copies(1));
|
|
55 |
//PageFormat pf = pj.pageDialog(pSet);
|
|
56 |
PageFormat pf = new PageFormat();
|
|
57 |
System.out.println("Setting Printable...pf = "+pf);
|
|
58 |
if (pf == null) {
|
|
59 |
return;
|
|
60 |
}
|
|
61 |
pj.setPrintable(pd,pf);
|
|
62 |
|
|
63 |
//try { pj.setPrintService(services[0]); } catch(Exception e) { e.printStackTrace(); }
|
|
64 |
pSet.add(new Destination(new java.io.File("./out.prn").toURI()));
|
|
65 |
System.out.println("open PrintDialog..");
|
|
66 |
for (int i=0; i<2; i++) {
|
|
67 |
if (pj.printDialog(pSet)) {
|
|
68 |
try {
|
|
69 |
System.out.println("About to print the data ...");
|
|
70 |
pj.print(pSet);
|
|
71 |
System.out.println("Printed");
|
|
72 |
}
|
|
73 |
catch (PrinterException pe) {
|
|
74 |
pe.printStackTrace();
|
|
75 |
}
|
|
76 |
}
|
|
77 |
}
|
|
78 |
|
|
79 |
}
|
|
80 |
|
|
81 |
//printable interface
|
|
82 |
public int print(Graphics g, PageFormat pf, int pi) throws
|
|
83 |
PrinterException {
|
|
84 |
|
|
85 |
if (pi > 0) {
|
|
86 |
System.out.println("pi is greater than 0");
|
|
87 |
return Printable.NO_SUCH_PAGE;
|
|
88 |
}
|
|
89 |
// Simply draw two rectangles
|
|
90 |
Graphics2D g2 = (Graphics2D)g;
|
|
91 |
g2.setColor(Color.black);
|
|
92 |
g2.translate(pf.getImageableX(), pf.getImageableY());
|
|
93 |
g2.drawRect(1,1,200,300);
|
|
94 |
g2.drawRect(1,1,25,25);
|
|
95 |
System.out.println("print method called "+pi);
|
|
96 |
return Printable.PAGE_EXISTS;
|
|
97 |
}
|
|
98 |
}
|