jdk/test/java/awt/print/PrinterJob/TestCheckSystemDefaultBannerOption.java
author psadhukhan
Mon, 02 Jan 2017 15:09:52 +0530
changeset 43085 a7959201b795
parent 41397 f44bb269125c
permissions -rw-r--r--
8170579: The "Banner page" checkbox is disabled Reviewed-by: prr, pnarayanan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41397
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
     1
/*
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
     4
 *
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
     8
 *
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    13
 * accompanied this code).
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    14
 *
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    18
 *
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    21
 * questions.
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    22
 */
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    23
/*
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    24
 * @test
43085
a7959201b795 8170579: The "Banner page" checkbox is disabled
psadhukhan
parents: 41397
diff changeset
    25
 * @bug 8165947 8170579
41397
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    26
 * @summary  Verifies System default banner page option is honoured by jdk
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    27
 * @requires (os.family == "linux" | os.family == "solaris")
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    28
 * @run main/manual TestCheckSystemDefaultBannerOption
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    29
 */
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    30
import java.awt.BorderLayout;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    31
import java.awt.FlowLayout;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    32
import java.awt.Graphics;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    33
import java.awt.event.WindowAdapter;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    34
import java.awt.event.WindowEvent;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    35
import java.awt.print.PageFormat;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    36
import java.awt.print.Printable;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    37
import static java.awt.print.Printable.NO_SUCH_PAGE;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    38
import static java.awt.print.Printable.PAGE_EXISTS;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    39
import java.awt.print.PrinterException;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    40
import java.awt.print.PrinterJob;
43085
a7959201b795 8170579: The "Banner page" checkbox is disabled
psadhukhan
parents: 41397
diff changeset
    41
import javax.print.PrintService;
41397
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    42
import javax.print.attribute.standard.JobSheets;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    43
import javax.swing.JButton;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    44
import javax.swing.JDialog;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    45
import javax.swing.JPanel;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    46
import javax.swing.JTextArea;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    47
import javax.swing.SwingUtilities;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    48
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    49
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    50
public class TestCheckSystemDefaultBannerOption implements Printable {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    51
    private static Thread mainThread;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    52
    private static boolean testPassed;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    53
    private static boolean testGeneratedInterrupt;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    54
    private static boolean noJobSheet = false;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    55
    private static PrinterJob job = null;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    56
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    57
    public static void main (String[] args) throws Exception {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    58
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    59
        job = PrinterJob.getPrinterJob();
43085
a7959201b795 8170579: The "Banner page" checkbox is disabled
psadhukhan
parents: 41397
diff changeset
    60
        PrintService prtSrv = job.getPrintService();
a7959201b795 8170579: The "Banner page" checkbox is disabled
psadhukhan
parents: 41397
diff changeset
    61
        if (prtSrv == null) {
41397
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    62
            System.out.println("No printers. Test cannot continue");
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    63
            return;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    64
        }
43085
a7959201b795 8170579: The "Banner page" checkbox is disabled
psadhukhan
parents: 41397
diff changeset
    65
        // do not run the test if JobSheet category is not supported
a7959201b795 8170579: The "Banner page" checkbox is disabled
psadhukhan
parents: 41397
diff changeset
    66
        if (!prtSrv.isAttributeCategorySupported(JobSheets.class)) {
a7959201b795 8170579: The "Banner page" checkbox is disabled
psadhukhan
parents: 41397
diff changeset
    67
            return;
a7959201b795 8170579: The "Banner page" checkbox is disabled
psadhukhan
parents: 41397
diff changeset
    68
        }
41397
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    69
        // check system default banner option and let user know what to expect
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    70
        JobSheets js = (JobSheets)job.getPrintService().
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    71
                getDefaultAttributeValue(JobSheets.class);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    72
        if (js != null && js.equals(JobSheets.NONE)) {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    73
            noJobSheet = true;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    74
        }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    75
        SwingUtilities.invokeAndWait(() -> {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    76
            doTest(TestCheckSystemDefaultBannerOption::printTest);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    77
        });
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    78
        mainThread = Thread.currentThread();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    79
        try {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    80
            Thread.sleep(60000);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    81
        } catch (InterruptedException e) {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    82
            if (!testPassed && testGeneratedInterrupt) {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    83
                String banner = noJobSheet ? "Banner page" : " No Banner page";
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    84
                throw new RuntimeException(banner + " is printed");
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    85
            }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    86
        }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    87
        if (!testGeneratedInterrupt) {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    88
            throw new RuntimeException("user has not executed the test");
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    89
        }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    90
    }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    91
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    92
    private static void printTest() {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    93
        job.setPrintable(new TestCheckSystemDefaultBannerOption());
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    94
        try {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    95
            job.print();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    96
        } catch (PrinterException e) {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    97
            e.printStackTrace();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    98
        }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
    99
    }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   100
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   101
    public static synchronized void pass() {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   102
        testPassed = true;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   103
        testGeneratedInterrupt = true;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   104
        mainThread.interrupt();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   105
    }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   106
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   107
    public static synchronized void fail() {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   108
        testPassed = false;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   109
        testGeneratedInterrupt = true;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   110
        mainThread.interrupt();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   111
    }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   112
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   113
    private static void doTest(Runnable action) {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   114
        String banner = null;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   115
        if (noJobSheet) {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   116
            banner = "No Banner page";
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   117
        } else {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   118
            banner = "Banner page";
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   119
        }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   120
        String description
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   121
                = " A testpage will be sent to printer. \n"
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   122
                + " Please check if " + banner + " is printed \n"
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   123
                + " along with testpage.\n "
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   124
                + " If " + banner + " is printed, press PASS else press FAIL";
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   125
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   126
        final JDialog dialog = new JDialog();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   127
        dialog.setTitle("printSelectionTest");
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   128
        JTextArea textArea = new JTextArea(description);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   129
        textArea.setEditable(false);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   130
        final JButton testButton = new JButton("Start Test");
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   131
        final JButton passButton = new JButton("PASS");
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   132
        passButton.setEnabled(false);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   133
        passButton.addActionListener((e) -> {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   134
            dialog.dispose();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   135
            pass();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   136
        });
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   137
        final JButton failButton = new JButton("FAIL");
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   138
        failButton.setEnabled(false);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   139
        failButton.addActionListener((e) -> {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   140
            dialog.dispose();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   141
            fail();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   142
        });
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   143
        testButton.addActionListener((e) -> {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   144
            testButton.setEnabled(false);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   145
            action.run();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   146
            passButton.setEnabled(true);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   147
            failButton.setEnabled(true);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   148
        });
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   149
        JPanel mainPanel = new JPanel(new BorderLayout());
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   150
        mainPanel.add(textArea, BorderLayout.CENTER);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   151
        JPanel buttonPanel = new JPanel(new FlowLayout());
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   152
        buttonPanel.add(testButton);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   153
        buttonPanel.add(passButton);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   154
        buttonPanel.add(failButton);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   155
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   156
        dialog.add(mainPanel);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   157
        dialog.pack();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   158
        dialog.setVisible(true);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   159
        dialog.addWindowListener(new WindowAdapter() {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   160
           @Override
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   161
            public void windowClosing(WindowEvent e) {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   162
                System.out.println("main dialog closing");
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   163
                testGeneratedInterrupt = false;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   164
                mainThread.interrupt();
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   165
            }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   166
        });
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   167
    }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   168
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   169
    @Override
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   170
    public int print(Graphics g, PageFormat pf, int pi)
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   171
            throws PrinterException {
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   172
        System.out.println("pi = " + pi);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   173
        g.drawString("Testing", 100, 100);
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   174
        if (pi == 1)
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   175
            return NO_SUCH_PAGE;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   176
        return PAGE_EXISTS;
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   177
    }
f44bb269125c 8165947: One more page printed before the test page with OpenJDK
psadhukhan
parents:
diff changeset
   178
}