jdk/test/java/awt/print/Dialog/PrintApplet.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 5024549
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    27
  @summary   Pass if dialogs are modal.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    28
  @run applet/manual PrintApplet.html
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.applet.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    33
import java.awt.print.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    34
import javax.swing.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    35
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    36
public class PrintApplet extends JApplet implements Printable {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    37
    private JButton jButton1 = new JButton();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    38
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    39
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    40
    public PrintApplet() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    41
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    42
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    43
    public void init() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    44
        try {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    45
            jbInit();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    46
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    47
        catch(Exception e) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    48
            e.printStackTrace();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    49
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    50
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    51
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    52
    private void jbInit() throws Exception {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    53
        jButton1.setText("PRINT");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    54
        jButton1.addActionListener(new java.awt.event.ActionListener() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    55
            public void actionPerformed(ActionEvent e) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    56
                jButton1_actionPerformed(e);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    57
            }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    58
        });
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    59
        jButton1.setBounds(new Rectangle(165, 248, 80, 30));
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    60
        this.setSize(new Dimension(400,300));
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    61
        this.getContentPane().setLayout(null);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    62
        this.getContentPane().setBackground(Color.pink);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    63
        this.getContentPane().add(jButton1, BorderLayout.SOUTH);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    64
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    65
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    66
    public void start() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    67
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    68
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    69
    public void stop() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    70
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    71
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    72
    public void destroy() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    73
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    74
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    75
    public String getAppletInfo() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    76
        return "Applet inf";
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 String[][] getParameterInfo() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    80
        return null;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    81
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    82
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    83
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    84
   public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    85
       System.out.println("Calling print");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    86
       if (page == 0) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    87
           Graphics2D g2 = (Graphics2D)g;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    88
           g2.translate(pf.getImageableX(), pf.getImageableY());
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    89
           g2.setColor(Color.black);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    90
           g2.drawString("Hello World", 20, 100);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    91
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    92
           return Printable.PAGE_EXISTS;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    93
       }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    94
       return Printable.NO_SUCH_PAGE;
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
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    98
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    99
    void jButton1_actionPerformed(ActionEvent e) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   100
      PrinterJob printJob = null;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   101
      PageFormat pageFormat = null;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   102
      Paper prtPaper = null;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   103
      boolean bPrintFlg = true;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   104
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   105
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   106
      try{
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   107
         printJob = PrinterJob.getPrinterJob();
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
      catch(SecurityException se){
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   111
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   112
         bPrintFlg = false;
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
      if (bPrintFlg) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   116
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   117
         pageFormat = printJob.pageDialog(printJob.defaultPage());
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   118
         System.out.println("PrintApplet: pageFormat = "+pageFormat.getWidth()/72.0+" x "+pageFormat.getHeight()/72.0);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   119
         if (pageFormat != null) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   120
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   121
            prtPaper = pageFormat.getPaper();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   122
            pageFormat.setPaper(prtPaper);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   123
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   124
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   125
            printJob.setPrintable(this, pageFormat);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   126
         }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   127
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   128
         if (printJob.printDialog()) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   129
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   130
             try {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   131
                 printJob.print();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   132
             }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   133
             catch (java.awt.print.PrinterException ex) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   134
                 ex.printStackTrace();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   135
             }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   136
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   137
         }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   138
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   139
      }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   140
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   141
}