jdk/test/javax/print/DialogMargins.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 19013 7854d8c8ec5a
child 23010 6dadb192ad81
permissions -rw-r--r--
8027696: Incorrect copyright header in the tests Reviewed-by: alanb, malenkov, mullan
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
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 19013
diff changeset
     7
 * published by the Free Software Foundation.
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     8
 *
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     9
 * 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
    10
 * 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
    11
 * 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
    12
 * 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
    13
 * accompanied this code).
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    14
 *
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * 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
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    21
 * questions.
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    22
 */
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    23
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
 * @test
19013
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 9035
diff changeset
    26
 * @bug 4485755 6361370 6448717 5080051 6939417 8016343
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    27
 * @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
    28
 *          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
    29
 *          for 6448717, faster display of print dialog
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    30
 *          for 6500903, verify status of printer if accepting jobs or not
19013
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 9035
diff changeset
    31
 *          for 8016343, verify printing to non-default printer
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    32
 * @author prr
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    33
 * @run main/manual DialogMargins
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    34
 */
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
import java.awt.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    37
import java.awt.event.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    38
import java.awt.print.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    39
import javax.print.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    40
import javax.print.attribute.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    41
import javax.print.attribute.standard.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    42
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    43
public class DialogMargins extends Frame {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    44
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    45
  public DialogMargins() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    46
     super("Dialog Margins Test");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    47
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    48
    Button printButton = new Button ("Print ...");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    49
    add("Center", printButton);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    50
    printButton.addActionListener(new ActionListener() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    51
                public void actionPerformed (ActionEvent e) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    52
                     new MarginsPrinter();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    53
                }
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
    addWindowListener (new WindowAdapter() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    57
         public void windowClosing (WindowEvent e) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    58
            dispose();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    59
         }
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
     pack();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    64
     setVisible (true);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    65
  }
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
class MarginsPrinter implements Printable {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    68
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    69
  PrinterJob myPrinterJob;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    70
  PageFormat myPageFormat;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    71
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    72
  public MarginsPrinter() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    73
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    74
      //aset.add(MediaSizeName.ISO_A4);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    75
      //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
    76
      myPrinterJob = PrinterJob.getPrinterJob();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    77
      myPageFormat = myPrinterJob.pageDialog(aset);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    78
      myPrinterJob.setPrintable(this, myPageFormat);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    79
      //myPrinterJob.setPrintable(this);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    80
      if (myPrinterJob.printDialog(aset)) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    81
          try {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    82
             //PrintRequestAttributeSet newaset =
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    83
                   //new HashPrintRequestAttributeSet();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    84
              myPrinterJob.print(aset);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    85
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    86
          } catch (PrinterException pe ) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    87
              System.out.println("DialogMargins Exception caught:" + pe);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    88
          }
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
  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
    93
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    94
     if (pageIndex > 0) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    95
        return Printable.NO_SUCH_PAGE;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    96
     }
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
     Graphics2D g2d = (Graphics2D)graphics;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    99
     g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   100
     g2d.drawString("ORIGIN("+pageFormat.getImageableX()+","+
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   101
                             pageFormat.getImageableY()+")", 20, 20);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   102
     g2d.drawString("X THIS WAY", 200, 50);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   103
     g2d.drawString("Y THIS WAY", 60 , 200);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   104
     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
   105
     g2d.drawRect(0,0,(int)pageFormat.getImageableWidth(),
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   106
                      (int)pageFormat.getImageableHeight());
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   107
     g2d.setColor(Color.black);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   108
     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
   109
                      (int)pageFormat.getImageableHeight()-2);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   110
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   111
     return  Printable.PAGE_EXISTS;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   112
  }
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
  public static void main( String[] args) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   116
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   117
  String[] instructions =
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   118
        {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   119
         "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
   120
         "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
   121
         "request."
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   122
       };
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   123
      Sysout.createDialog( );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   124
      Sysout.printInstructions( instructions );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   125
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   126
     new DialogMargins();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   127
  }
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
class Sysout {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   132
   private static TestDialog dialog;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   133
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   134
   public static void createDialogWithInstructions( String[] instructions )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   135
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   136
      dialog = new TestDialog( new Frame(), "Instructions" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   137
      dialog.printInstructions( instructions );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   138
      dialog.show();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   139
      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
   140
    }
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
   public static void createDialog( )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   143
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   144
      dialog = new TestDialog( new Frame(), "Instructions" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   145
      String[] defInstr = { "Instructions will appear here. ", "" } ;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   146
      dialog.printInstructions( defInstr );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   147
      dialog.show();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   148
      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
   149
    }
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
   public static void printInstructions( String[] instructions )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   153
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   154
      dialog.printInstructions( instructions );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   155
    }
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
   public static void println( String messageIn )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   159
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   160
      dialog.displayMessage( messageIn );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   161
    }
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
}// Sysout  class
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   164
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
  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
   167
   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
   168
   to the user to be displayed.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   169
  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
   170
  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
   171
  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
   172
  */
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   173
class TestDialog extends Dialog {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   174
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   175
   TextArea instructionsText;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   176
   TextArea messageText;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   177
   int maxStringLength = 80;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   178
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   179
   //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
   180
   public TestDialog( Frame frame, String name )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   181
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   182
      super( frame, name );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   183
      int scrollBoth = TextArea.SCROLLBARS_BOTH;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   184
      instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   185
      add( "North", instructionsText );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   186
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   187
      messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   188
      add("Center", messageText);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   189
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   190
      pack();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   191
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   192
      show();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   193
    }// TestDialog()
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   194
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   195
   //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
   196
   public void printInstructions( String[] instructions )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   197
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   198
      //Clear out any current instructions
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   199
      instructionsText.setText( "" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   200
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   201
      //Go down array of instruction strings
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   202
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   203
      String printStr, remainingStr;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   204
      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
   205
       {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   206
         //chop up each into pieces maxSringLength long
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   207
         remainingStr = instructions[ i ];
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   208
         while( remainingStr.length() > 0 )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   209
          {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   210
            //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
   211
            if( remainingStr.length() >= maxStringLength )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   212
             {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   213
               //Try to chop on a word boundary
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   214
               int posOfSpace = remainingStr.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   215
                  lastIndexOf( ' ', maxStringLength - 1 );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   216
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   217
               if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   218
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   219
               printStr = remainingStr.substring( 0, posOfSpace + 1 );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   220
               remainingStr = remainingStr.substring( posOfSpace + 1 );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   221
             }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   222
            //else just print
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   223
            else
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   224
             {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   225
               printStr = remainingStr;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   226
               remainingStr = "";
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   227
             }
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
            instructionsText.append( printStr + "\n" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   230
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   231
          }// while
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   232
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   233
       }// for
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   234
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   235
    }//printInstructions()
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   236
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   237
   //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
   238
   public void displayMessage( String messageIn )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   239
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   240
      messageText.append( messageIn + "\n" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   241
    }
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
 }// TestDialog  class