jdk/test/javax/print/DialogMargins.java
author jgodinez
Fri, 26 Jul 2013 15:25:12 -0700
changeset 19013 7854d8c8ec5a
parent 9035 1255eb81cc2f
child 21596 0e3a39f29dbc
permissions -rw-r--r--
8016343: [macosx] Print job goes to default printer regardless of chosen printer Reviewed-by: jchen, prr
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
19013
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 9035
diff changeset
    28
 * @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
    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
19013
7854d8c8ec5a 8016343: [macosx] Print job goes to default printer regardless of chosen printer
jgodinez
parents: 9035
diff changeset
    33
 *          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
    34
 * @author prr
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    35
 * @run main/manual DialogMargins
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    38
import java.awt.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    39
import java.awt.event.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    40
import java.awt.print.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    41
import javax.print.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    42
import javax.print.attribute.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    43
import javax.print.attribute.standard.*;
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 class DialogMargins extends Frame {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    46
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    47
  public DialogMargins() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    48
     super("Dialog Margins Test");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    49
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    50
    Button printButton = new Button ("Print ...");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    51
    add("Center", printButton);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    52
    printButton.addActionListener(new ActionListener() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    53
                public void actionPerformed (ActionEvent e) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    54
                     new MarginsPrinter();
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    58
    addWindowListener (new WindowAdapter() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    59
         public void windowClosing (WindowEvent e) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    60
            dispose();
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    65
     pack();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    66
     setVisible (true);
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    69
class MarginsPrinter implements Printable {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    70
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    71
  PrinterJob myPrinterJob;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    72
  PageFormat myPageFormat;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    73
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    74
  public MarginsPrinter() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    75
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    76
      //aset.add(MediaSizeName.ISO_A4);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    77
      //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
    78
      myPrinterJob = PrinterJob.getPrinterJob();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    79
      myPageFormat = myPrinterJob.pageDialog(aset);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    80
      myPrinterJob.setPrintable(this, myPageFormat);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    81
      //myPrinterJob.setPrintable(this);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    82
      if (myPrinterJob.printDialog(aset)) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    83
          try {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    84
             //PrintRequestAttributeSet newaset =
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    85
                   //new HashPrintRequestAttributeSet();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    86
              myPrinterJob.print(aset);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    87
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    88
          } catch (PrinterException pe ) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    89
              System.out.println("DialogMargins Exception caught:" + pe);
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    94
  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
    95
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    96
     if (pageIndex > 0) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    97
        return Printable.NO_SUCH_PAGE;
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   100
     Graphics2D g2d = (Graphics2D)graphics;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   101
     g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   102
     g2d.drawString("ORIGIN("+pageFormat.getImageableX()+","+
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   103
                             pageFormat.getImageableY()+")", 20, 20);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   104
     g2d.drawString("X THIS WAY", 200, 50);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   105
     g2d.drawString("Y THIS WAY", 60 , 200);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   106
     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
   107
     g2d.drawRect(0,0,(int)pageFormat.getImageableWidth(),
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   108
                      (int)pageFormat.getImageableHeight());
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   109
     g2d.setColor(Color.black);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   110
     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
   111
                      (int)pageFormat.getImageableHeight()-2);
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
     return  Printable.PAGE_EXISTS;
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
}
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   117
  public static void main( String[] args) {
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
  String[] instructions =
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   120
        {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   121
         "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
   122
         "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
   123
         "request."
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   124
       };
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   125
      Sysout.createDialog( );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   126
      Sysout.printInstructions( instructions );
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
     new DialogMargins();
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   133
class Sysout {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   134
   private static TestDialog dialog;
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
   public static void createDialogWithInstructions( String[] instructions )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   137
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   138
      dialog = new TestDialog( new Frame(), "Instructions" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   139
      dialog.printInstructions( instructions );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   140
      dialog.show();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   141
      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
   142
    }
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
   public static void createDialog( )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   145
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   146
      dialog = new TestDialog( new Frame(), "Instructions" );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   147
      String[] defInstr = { "Instructions will appear here. ", "" } ;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   148
      dialog.printInstructions( defInstr );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   149
      dialog.show();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   150
      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
   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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   154
   public static void printInstructions( String[] 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
      dialog.printInstructions( instructions );
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   160
   public static void println( String 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
      dialog.displayMessage( messageIn );
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   165
}// Sysout  class
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
/**
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   168
  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
   169
   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
   170
   to the user to be displayed.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   171
  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
   172
  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
   173
  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
   174
  */
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   175
class TestDialog extends Dialog {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   176
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   177
   TextArea instructionsText;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   178
   TextArea messageText;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   179
   int maxStringLength = 80;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   180
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   181
   //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
   182
   public TestDialog( Frame frame, String name )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   183
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   184
      super( frame, name );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   185
      int scrollBoth = TextArea.SCROLLBARS_BOTH;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   186
      instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   187
      add( "North", instructionsText );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   188
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   189
      messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   190
      add("Center", messageText);
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
      pack();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   193
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   194
      show();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   195
    }// TestDialog()
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   196
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   197
   //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
   198
   public void printInstructions( String[] instructions )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   199
    {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   200
      //Clear out any current instructions
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   201
      instructionsText.setText( "" );
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
      //Go down array of instruction strings
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   204
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   205
      String printStr, remainingStr;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   206
      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
   207
       {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   208
         //chop up each into pieces maxSringLength long
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   209
         remainingStr = instructions[ i ];
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   210
         while( remainingStr.length() > 0 )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   211
          {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   212
            //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
   213
            if( remainingStr.length() >= maxStringLength )
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   214
             {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   215
               //Try to chop on a word boundary
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   216
               int posOfSpace = remainingStr.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   217
                  lastIndexOf( ' ', 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
               if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   220
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   221
               printStr = remainingStr.substring( 0, posOfSpace + 1 );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   222
               remainingStr = remainingStr.substring( posOfSpace + 1 );
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   223
             }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   224
            //else just print
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   225
            else
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   226
             {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   227
               printStr = remainingStr;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   228
               remainingStr = "";
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   231
            instructionsText.append( printStr + "\n" );
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
          }// while
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
       }// for
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
    }//printInstructions()
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   238
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   239
   //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
   240
   public void displayMessage( String messageIn )
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
      messageText.append( messageIn + "\n" );
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
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   245
 }// TestDialog  class