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 4846344 4851365 4851321 4851316 4863656 5046198 6293139
27  * @summary Confirm that cancelling the dialog will not prompt for file.
28  * @run main/manual DestinationTest
29  */
30 import java.awt.*;
31 import java.awt.event.*;
32 import java.util.*;
33 import java.io.*;
34 
35 public class DestinationTest extends Frame implements ActionListener {
36     //Declare things used in the test, like buttons and labels here
37 
38     DisplayImages images;
39     Button nativeDlg, nativeDlg2, commonSelectionDlg, commonRangeDlg, fileDlg;
40 
DestinationTest()41     public DestinationTest() {
42 
43         images = new DisplayImages();
44         images.setSize(530, 480);
45         add(images, "Center");
46 
47         Panel printpanel = new Panel();
48 
49         nativeDlg = new Button("Native");
50         nativeDlg.addActionListener(this);
51         printpanel.add(nativeDlg);
52 
53         nativeDlg2 = new Button("Native 2");
54         nativeDlg2.addActionListener(this);
55         printpanel.add(nativeDlg2);
56 
57         commonSelectionDlg = new Button("Common Selection");
58         commonSelectionDlg.addActionListener(this);
59         printpanel.add(commonSelectionDlg);
60 
61         commonRangeDlg = new Button("Common Range");
62         commonRangeDlg.addActionListener(this);
63         printpanel.add(commonRangeDlg);
64 
65         fileDlg = new Button("Print To File - Common Dialog");
66         fileDlg.addActionListener(this);
67         printpanel.add(fileDlg);
68 
69         add(printpanel, "South");
70         setSize(900, 300);
71         setVisible(true);
72     }
73 
main(String args[])74     public static void main (String args[]) {
75         DestinationTest test = new DestinationTest();
76     }
77 
78 
actionPerformed(ActionEvent e)79     public void actionPerformed(ActionEvent e) {
80 
81         JobAttributes  ja = new JobAttributes();
82         PageAttributes pa = new PageAttributes();
83         ja.setDestination(JobAttributes.DestinationType.FILE);
84         ja.setFileName("test_file_name.prn");
85 
86         if(e.getSource()== nativeDlg) {
87             ja.setDefaultSelection(JobAttributes.DefaultSelectionType.SELECTION);
88             ja.setPageRanges(new int[][] {new int[] {2,3}, new int[] {5,6}});
89             ja.setDialog(JobAttributes.DialogType.NATIVE);
90         }
91 
92         if(e.getSource()== nativeDlg2) {
93             ja.setFileName("");
94             ja.setDialog(JobAttributes.DialogType.NATIVE);
95         }
96 
97         if(e.getSource()== commonRangeDlg) {
98             ja = new JobAttributes();
99             ja.setDefaultSelection(JobAttributes.DefaultSelectionType.RANGE);
100             ja.setPageRanges(new int[][] {new int[] {1,3}, new int[] {5,6}});
101             ja.setDialog(JobAttributes.DialogType.COMMON);
102         }
103 
104         if (e.getSource() == fileDlg) {
105             ja = new JobAttributes();
106             ja.setDestination(JobAttributes.DestinationType.FILE);
107             ja.setDialog(JobAttributes.DialogType.COMMON);
108         }
109 
110         if(e.getSource()== commonSelectionDlg) {
111             ja.setDefaultSelection(JobAttributes.DefaultSelectionType.SELECTION);
112             ja.setDialog(JobAttributes.DialogType.COMMON);
113         }
114 
115         PrintJob pjob = getToolkit().getPrintJob(this,"Printing Test",ja,pa);
116         System.out.println("6293139: Chosen printer is: "+ja.getPrinter());
117         if(pjob != null) {
118 
119             Graphics pg = pjob.getGraphics();
120 
121             if(pg != null) {
122                 //images.printAll(pg);
123                 this.printAll(pg);
124                 pg.dispose();
125             }
126             pjob.end();
127         }
128     }
129 }
130 
131 class DisplayImages extends Canvas {
132 
paint(Graphics g)133     public void paint(Graphics g) {
134 
135         g.setFont(new Font("Helvetica", Font.BOLD, 12));
136         g.drawString("PRINTING TEST", 1, 10);
137         g.drawString(" 4846344: Confirm that cancelling the native dialog will not prompt for file.", 1, 25);
138         g.drawString(" 4851365: Confirm that printing in native dialog shows test_file_name.prn as default.", 1, 40);
139         g.drawString(" 4851321: Confirm that in the Common Range dialog, page ranges is set to 1-6.", 1, 55);
140         g.drawString(" 4851316: Confirm that NPE is not thrown upon selecting Common Selection dialog.", 1, 70);
141         g.drawString(" 4863656: Confirm that no IAE is thrown when printing in native dialog.", 1, 85);
142         g.drawString(" 4864444: Confirm that the default directory in Native 2 is same as current one with no filename set.", 1, 100);
143         g.drawString(" 5046198: Confirm that the default filename in Common Range dialog when printing to a file is same as that of PrintToFile dialog.", 1, 115);
144         g.drawString(" 6293139: In Common Range dialog, change printer before printing then confirm the chosen printer.", 1, 130);
145     }
146 }
147