jdk/test/java/awt/print/Dialog/DestinationTest.java
author vlivanov
Wed, 02 Mar 2016 15:42:03 +0300
changeset 36349 6cc8e6f596b2
parent 24143 064337def883
permissions -rw-r--r--
8151020: [TESTBUG] UnsafeGetStableArrayElement::testL_* fail intermittently Reviewed-by: zmajo, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24143
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     1
/*
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     2
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     4
 *
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     8
 *
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    13
 * accompanied this code).
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    14
 *
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    18
 *
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    21
 * questions.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    22
 */
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    23
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    24
/**
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    25
 * @test
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    26
 * @bug 4846344 4851365 4851321 4851316 4863656 5046198 6293139
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    27
 * @summary Confirm that cancelling the dialog will not prompt for file.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    28
 * @run main/manual DestinationTest
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    29
 */
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    30
import java.awt.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    31
import java.awt.event.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    32
import java.util.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    33
import java.io.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    34
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    35
public class DestinationTest extends Frame implements ActionListener {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    36
    //Declare things used in the test, like buttons and labels here
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    37
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    38
    DisplayImages images;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    39
    Button nativeDlg, nativeDlg2, commonSelectionDlg, commonRangeDlg, fileDlg;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    40
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    41
    public DestinationTest() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    42
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    43
        images = new DisplayImages();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    44
        images.setSize(530, 480);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    45
        add(images, "Center");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    46
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    47
        Panel printpanel = new Panel();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    48
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    49
        nativeDlg = new Button("Native");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    50
        nativeDlg.addActionListener(this);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    51
        printpanel.add(nativeDlg);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    52
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    53
        nativeDlg2 = new Button("Native 2");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    54
        nativeDlg2.addActionListener(this);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    55
        printpanel.add(nativeDlg2);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    56
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    57
        commonSelectionDlg = new Button("Common Selection");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    58
        commonSelectionDlg.addActionListener(this);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    59
        printpanel.add(commonSelectionDlg);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    60
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    61
        commonRangeDlg = new Button("Common Range");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    62
        commonRangeDlg.addActionListener(this);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    63
        printpanel.add(commonRangeDlg);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    64
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    65
        fileDlg = new Button("Print To File - Common Dialog");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    66
        fileDlg.addActionListener(this);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    67
        printpanel.add(fileDlg);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    68
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    69
        add(printpanel, "South");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    70
        setSize(900, 300);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    71
        setVisible(true);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    72
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    73
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    74
    public static void main (String args[]) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    75
        DestinationTest test = new DestinationTest();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    76
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    77
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    78
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    79
    public void actionPerformed(ActionEvent e) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    80
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    81
        JobAttributes  ja = new JobAttributes();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    82
        PageAttributes pa = new PageAttributes();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    83
        ja.setDestination(JobAttributes.DestinationType.FILE);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    84
        ja.setFileName("test_file_name.prn");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    85
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    86
        if(e.getSource()== nativeDlg) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    87
            ja.setDefaultSelection(JobAttributes.DefaultSelectionType.SELECTION);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    88
            ja.setPageRanges(new int[][] {new int[] {2,3}, new int[] {5,6}});
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    89
            ja.setDialog(JobAttributes.DialogType.NATIVE);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    90
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    91
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    92
        if(e.getSource()== nativeDlg2) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    93
            ja.setFileName("");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    94
            ja.setDialog(JobAttributes.DialogType.NATIVE);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    95
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    96
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    97
        if(e.getSource()== commonRangeDlg) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    98
            ja = new JobAttributes();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    99
            ja.setDefaultSelection(JobAttributes.DefaultSelectionType.RANGE);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   100
            ja.setPageRanges(new int[][] {new int[] {1,3}, new int[] {5,6}});
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   101
            ja.setDialog(JobAttributes.DialogType.COMMON);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   102
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   103
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   104
        if (e.getSource() == fileDlg) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   105
            ja = new JobAttributes();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   106
            ja.setDestination(JobAttributes.DestinationType.FILE);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   107
            ja.setDialog(JobAttributes.DialogType.COMMON);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   108
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   109
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   110
        if(e.getSource()== commonSelectionDlg) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   111
            ja.setDefaultSelection(JobAttributes.DefaultSelectionType.SELECTION);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   112
            ja.setDialog(JobAttributes.DialogType.COMMON);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   113
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   114
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   115
        PrintJob pjob = getToolkit().getPrintJob(this,"Printing Test",ja,pa);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   116
        System.out.println("6293139: Chosen printer is: "+ja.getPrinter());
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   117
        if(pjob != null) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   118
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   119
            Graphics pg = pjob.getGraphics();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   120
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   121
            if(pg != null) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   122
                //images.printAll(pg);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   123
                this.printAll(pg);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   124
                pg.dispose();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   125
            }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   126
            pjob.end();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   127
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   128
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   129
}
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   130
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   131
class DisplayImages extends Canvas {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   132
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   133
    public void paint(Graphics g) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   134
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   135
        g.setFont(new Font("Helvetica", Font.BOLD, 12));
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   136
        g.drawString("PRINTING TEST", 1, 10);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   137
        g.drawString(" 4846344: Confirm that cancelling the native dialog will not prompt for file.", 1, 25);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   138
        g.drawString(" 4851365: Confirm that printing in native dialog shows test_file_name.prn as default.", 1, 40);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   139
        g.drawString(" 4851321: Confirm that in the Common Range dialog, page ranges is set to 1-6.", 1, 55);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   140
        g.drawString(" 4851316: Confirm that NPE is not thrown upon selecting Common Selection dialog.", 1, 70);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   141
        g.drawString(" 4863656: Confirm that no IAE is thrown when printing in native dialog.", 1, 85);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   142
        g.drawString(" 4864444: Confirm that the default directory in Native 2 is same as current one with no filename set.", 1, 100);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   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);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   144
        g.drawString(" 6293139: In Common Range dialog, change printer before printing then confirm the chosen printer.", 1, 130);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   145
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   146
}