jdk/test/javax/print/DialogMargins.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7939 4b122be94252
child 19013 7854d8c8ec5a
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7939
diff changeset
     2
 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     4
 *
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    10
 *
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    15
 * accompanied this code).
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    16
 *
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    23
 * questions.
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    24
 */
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    25
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    26
/**
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    27
 * @test
7939
4b122be94252 6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers
jgodinez
parents: 5506
diff changeset
    28
 * @bug 4485755 6361370 6448717 5080051 6939417
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    29
 * @summary dialog doesn't have way to specify margins
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    30
 *          for 6361370, verify exception for offline printer in Windows
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    31
 *          for 6448717, faster display of print dialog
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    32
 *          for 6500903, verify status of printer if accepting jobs or not
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    33
 * @author prr
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    34
 * @run main/manual DialogMargins
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    35
 */
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    36
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    37
import java.awt.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    38
import java.awt.event.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    39
import java.awt.print.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    40
import javax.print.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    41
import javax.print.attribute.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    42
import javax.print.attribute.standard.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    43
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    44
public class DialogMargins extends Frame {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    45
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    46
  public DialogMargins() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    47
     super("Dialog Margins Test");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    48
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    49
    Button printButton = new Button ("Print ...");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    50
    add("Center", printButton);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    51
    printButton.addActionListener(new ActionListener() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    52
                public void actionPerformed (ActionEvent e) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    53
                     new MarginsPrinter();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    54
                }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    55
    });
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    56
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    57
    addWindowListener (new WindowAdapter() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    58
         public void windowClosing (WindowEvent e) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    59
            dispose();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    60
         }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    61
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    62
     });
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    63
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    64
     pack();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    65
     setVisible (true);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    66
  }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    67
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    68
class MarginsPrinter implements Printable {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    69
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    70
  PrinterJob myPrinterJob;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    71
  PageFormat myPageFormat;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    72
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    73
  public MarginsPrinter() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    74
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    75
      //aset.add(MediaSizeName.ISO_A4);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    76
      //aset.add(new MediaPrintableArea(0f,0f,210f,297f,MediaPrintableArea.MM));
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    77
      myPrinterJob = PrinterJob.getPrinterJob();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    78
      myPageFormat = myPrinterJob.pageDialog(aset);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    79
      myPrinterJob.setPrintable(this, myPageFormat);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    80
      //myPrinterJob.setPrintable(this);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    81
      if (myPrinterJob.printDialog(aset)) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    82
          try {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    83
             //PrintRequestAttributeSet newaset =
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    84
                   //new HashPrintRequestAttributeSet();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    85
              myPrinterJob.print(aset);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    86
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    87
          } catch (PrinterException pe ) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    88
              System.out.println("DialogMargins Exception caught:" + pe);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    89
          }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    90
      }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    91
   }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    92
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    93
  public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    94
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    95
     if (pageIndex > 0) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    96
        return Printable.NO_SUCH_PAGE;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    97
     }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    98
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    99
     Graphics2D g2d = (Graphics2D)graphics;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   100
     g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   101
     g2d.drawString("ORIGIN("+pageFormat.getImageableX()+","+
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   102
                             pageFormat.getImageableY()+")", 20, 20);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   103
     g2d.drawString("X THIS WAY", 200, 50);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   104
     g2d.drawString("Y THIS WAY", 60 , 200);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   105
     g2d.drawString("Graphics is " + g2d.getClass().getName(), 100, 100);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   106
     g2d.drawRect(0,0,(int)pageFormat.getImageableWidth(),
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   107
                      (int)pageFormat.getImageableHeight());
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   108
     g2d.setColor(Color.black);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   109
     g2d.drawRect(1,1,(int)pageFormat.getImageableWidth()-2,
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   110
                      (int)pageFormat.getImageableHeight()-2);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   111
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   112
     return  Printable.PAGE_EXISTS;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   113
  }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   114
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   115
}
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   116
  public static void main( String[] args) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   117
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   118
  String[] instructions =
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   119
        {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   120
         "You must have a printer available to perform this test",
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   121
         "Specify various pageformats and compare the printed results with the",
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   122
         "request."
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   123
       };
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   124
      Sysout.createDialog( );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   125
      Sysout.printInstructions( instructions );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   126
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   127
     new DialogMargins();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   128
  }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   129
}
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   130
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   131
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   132
class Sysout {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   133
   private static TestDialog dialog;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   134
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   135
   public static void createDialogWithInstructions( String[] instructions )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   136
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   137
      dialog = new TestDialog( new Frame(), "Instructions" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   138
      dialog.printInstructions( instructions );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   139
      dialog.show();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   140
      println( "Any messages for the tester will display here." );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   141
    }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   142
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   143
   public static void createDialog( )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   144
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   145
      dialog = new TestDialog( new Frame(), "Instructions" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   146
      String[] defInstr = { "Instructions will appear here. ", "" } ;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   147
      dialog.printInstructions( defInstr );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   148
      dialog.show();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   149
      println( "Any messages for the tester will display here." );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   150
    }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   151
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   152
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   153
   public static void printInstructions( String[] instructions )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   154
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   155
      dialog.printInstructions( instructions );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   156
    }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   157
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   158
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   159
   public static void println( String messageIn )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   160
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   161
      dialog.displayMessage( messageIn );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   162
    }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   163
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   164
}// Sysout  class
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   165
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   166
/**
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   167
  This is part of the standard test machinery.  It provides a place for the
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   168
   test instructions to be displayed, and a place for interactive messages
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   169
   to the user to be displayed.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   170
  To have the test instructions displayed, see Sysout.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   171
  To have a message to the user be displayed, see Sysout.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   172
  Do not call anything in this dialog directly.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   173
  */
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   174
class TestDialog extends Dialog {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   175
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   176
   TextArea instructionsText;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   177
   TextArea messageText;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   178
   int maxStringLength = 80;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   179
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   180
   //DO NOT call this directly, go through Sysout
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   181
   public TestDialog( Frame frame, String name )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   182
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   183
      super( frame, name );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   184
      int scrollBoth = TextArea.SCROLLBARS_BOTH;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   185
      instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   186
      add( "North", instructionsText );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   187
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   188
      messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   189
      add("Center", messageText);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   190
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   191
      pack();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   192
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   193
      show();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   194
    }// TestDialog()
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   195
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   196
   //DO NOT call this directly, go through Sysout
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   197
   public void printInstructions( String[] instructions )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   198
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   199
      //Clear out any current instructions
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   200
      instructionsText.setText( "" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   201
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   202
      //Go down array of instruction strings
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   203
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   204
      String printStr, remainingStr;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   205
      for( int i=0; i < instructions.length; i++ )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   206
       {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   207
         //chop up each into pieces maxSringLength long
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   208
         remainingStr = instructions[ i ];
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   209
         while( remainingStr.length() > 0 )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   210
          {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   211
            //if longer than max then chop off first max chars to print
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   212
            if( remainingStr.length() >= maxStringLength )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   213
             {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   214
               //Try to chop on a word boundary
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   215
               int posOfSpace = remainingStr.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   216
                  lastIndexOf( ' ', maxStringLength - 1 );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   217
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   218
               if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   219
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   220
               printStr = remainingStr.substring( 0, posOfSpace + 1 );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   221
               remainingStr = remainingStr.substring( posOfSpace + 1 );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   222
             }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   223
            //else just print
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   224
            else
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   225
             {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   226
               printStr = remainingStr;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   227
               remainingStr = "";
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   228
             }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   229
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   230
            instructionsText.append( printStr + "\n" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   231
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   232
          }// while
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   233
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   234
       }// for
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   235
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   236
    }//printInstructions()
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   237
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   238
   //DO NOT call this directly, go through Sysout
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   239
   public void displayMessage( String messageIn )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   240
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   241
      messageText.append( messageIn + "\n" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   242
    }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   243
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   244
 }// TestDialog  class