jdk/test/java/awt/print/PrinterJob/Collate2DPrintingTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2697 b27edaf0767e
child 17676 d76d0c992e34
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2697
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2697
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
2697
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     4
 *
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     8
 *
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    13
 * accompanied this code).
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    14
 *
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2697
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2697
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2697
diff changeset
    21
 * questions.
2697
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    22
 */
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    23
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    24
/**
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    25
 * @test
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    26
 * @bug 6362683
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    27
 * @summary Collation should work.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    28
 * @run main/manual Collate2DPrintingTest
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    29
 */
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    30
import java.awt.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    31
import java.awt.event.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    32
import java.awt.print.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    33
import javax.print.attribute.standard.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    34
import javax.print.attribute.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    35
import javax.print.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    36
import java.io.*;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    37
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    38
public class Collate2DPrintingTest
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    39
    extends Frame implements Doc, Printable, ActionListener {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    40
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    41
        Button print2D = new Button("2D Print");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    42
        Button printMerlin = new Button("PrintService");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    43
        PrinterJob pj = PrinterJob.getPrinterJob();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    44
        PrintService defService = null;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    45
        HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    46
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    47
    public Collate2DPrintingTest() {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    48
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    49
        Panel butPanel = new Panel();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    50
        butPanel.add(print2D);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    51
        butPanel.add(printMerlin);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    52
        print2D.addActionListener(this);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    53
        printMerlin.addActionListener(this);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    54
        addWindowListener (new WindowAdapter() {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    55
            public void windowClosing (WindowEvent e) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    56
                dispose();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    57
            }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    58
        });
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    59
        add("South", butPanel);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    60
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    61
        defService = PrintServiceLookup.lookupDefaultPrintService();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    62
        PrintService[] pservice;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    63
        if (defService == null) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    64
            pservice = PrintServiceLookup.lookupPrintServices(null, null);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    65
            if (pservice.length == 0) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    66
                throw new RuntimeException("No printer found.  TEST ABORTED");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    67
            }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    68
            defService = pservice[0];
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    69
        }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    70
        prSet.add(SheetCollate.COLLATED);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    71
        prSet.add(new Copies(2));
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    72
        pj.setPrintable(Collate2DPrintingTest.this);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    73
        setSize(300, 200);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    74
        setVisible(true);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    75
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    76
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    77
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    78
    public int print(Graphics g, PageFormat pf, int pageIndex)
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    79
          throws PrinterException {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    80
        g.drawString("Page: " + pageIndex, 100, 100);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    81
        if (pageIndex == 2) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    82
            return Printable.NO_SUCH_PAGE;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    83
        } else {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    84
            return Printable.PAGE_EXISTS;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    85
        }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    86
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    87
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    88
    public void actionPerformed (ActionEvent ae) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    89
        try {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    90
            if (ae.getSource() == print2D) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    91
                if (pj.printDialog(prSet)) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    92
                    pj.print(prSet);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    93
                }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    94
            } else {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    95
                DocPrintJob pj = defService.createPrintJob();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    96
                pj.print(this, prSet);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    97
            }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    98
            System.out.println ("DONE");
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
    99
        } catch (Exception e) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   100
            e.printStackTrace();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   101
        }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   102
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   103
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   104
    public DocAttributeSet getAttributes() {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   105
        return null;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   106
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   107
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   108
    public DocFlavor getDocFlavor() {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   109
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   110
        return flavor;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   111
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   112
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   113
    public Object getPrintData() {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   114
        return this;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   115
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   116
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   117
    public Reader getReaderForText() {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   118
        return null;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   119
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   120
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   121
    public InputStream getStreamForBytes() {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   122
        return null;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   123
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   124
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   125
  public static void main( String[] args) {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   126
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   127
  String[] instructions =
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   128
        {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   129
         "You must have a printer available to perform this test",
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   130
         "The print result should be collated."
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   131
       };
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   132
      Sysout.createDialog( );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   133
      Sysout.printInstructions( instructions );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   134
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   135
     new Collate2DPrintingTest();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   136
  }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   137
}
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   138
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   139
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   140
class Sysout {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   141
   private static TestDialog dialog;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   142
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   143
   public static void createDialogWithInstructions( String[] instructions )
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   144
    {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   145
      dialog = new TestDialog( new Frame(), "Instructions" );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   146
      dialog.printInstructions( instructions );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   147
      dialog.setVisible(true);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   148
      println( "Any messages for the tester will display here." );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   149
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   150
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   151
   public static void createDialog( )
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   152
    {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   153
      dialog = new TestDialog( new Frame(), "Instructions" );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   154
      String[] defInstr = { "Instructions will appear here. ", "" } ;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   155
      dialog.printInstructions( defInstr );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   156
      dialog.setVisible(true);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   157
      println( "Any messages for the tester will display here." );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   158
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   159
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   160
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   161
   public static void printInstructions( String[] instructions )
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   162
    {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   163
      dialog.printInstructions( instructions );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   164
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   165
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   166
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   167
   public static void println( String messageIn )
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   168
    {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   169
      dialog.displayMessage( messageIn );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   170
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   171
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   172
}// Sysout  class
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   173
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   174
/**
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   175
  This is part of the standard test machinery.  It provides a place for the
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   176
   test instructions to be displayed, and a place for interactive messages
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   177
   to the user to be displayed.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   178
  To have the test instructions displayed, see Sysout.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   179
  To have a message to the user be displayed, see Sysout.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   180
  Do not call anything in this dialog directly.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   181
  */
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   182
class TestDialog extends Dialog {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   183
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   184
   TextArea instructionsText;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   185
   TextArea messageText;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   186
   int maxStringLength = 80;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   187
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   188
   //DO NOT call this directly, go through Sysout
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   189
   public TestDialog( Frame frame, String name )
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   190
    {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   191
      super( frame, name );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   192
      int scrollBoth = TextArea.SCROLLBARS_BOTH;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   193
      instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   194
      add( "North", instructionsText );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   195
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   196
      messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   197
      add("Center", messageText);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   198
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   199
      pack();
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   200
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   201
      setVisible(true);
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   202
    }// TestDialog()
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   203
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   204
   //DO NOT call this directly, go through Sysout
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   205
   public void printInstructions( String[] instructions )
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   206
    {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   207
      //Clear out any current instructions
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   208
      instructionsText.setText( "" );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   209
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   210
      //Go down array of instruction strings
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   211
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   212
      String printStr, remainingStr;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   213
      for( int i=0; i < instructions.length; i++ )
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   214
       {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   215
         //chop up each into pieces maxSringLength long
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   216
         remainingStr = instructions[ i ];
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   217
         while( remainingStr.length() > 0 )
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   218
          {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   219
            //if longer than max then chop off first max chars to print
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   220
            if( remainingStr.length() >= maxStringLength )
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   221
             {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   222
               //Try to chop on a word boundary
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   223
               int posOfSpace = remainingStr.
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   224
                  lastIndexOf( ' ', maxStringLength - 1 );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   225
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   226
               if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   227
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   228
               printStr = remainingStr.substring( 0, posOfSpace + 1 );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   229
               remainingStr = remainingStr.substring( posOfSpace + 1 );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   230
             }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   231
            //else just print
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   232
            else
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   233
             {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   234
               printStr = remainingStr;
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   235
               remainingStr = "";
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   236
             }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   237
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   238
            instructionsText.append( printStr + "\n" );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   239
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   240
          }// while
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   241
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   242
       }// for
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   243
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   244
    }//printInstructions()
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   245
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   246
   //DO NOT call this directly, go through Sysout
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   247
   public void displayMessage( String messageIn )
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   248
    {
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   249
      messageText.append( messageIn + "\n" );
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   250
    }
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   251
b27edaf0767e 6821495: test/java/awt/print/PrinterJob/PrtException.java fails
jgodinez
parents:
diff changeset
   252
 }// TestDialog  class