1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 import java.awt.BorderLayout;
  24 import java.awt.Component;
  25 import java.awt.FlowLayout;
  26 import java.awt.JobAttributes;
  27 import java.awt.PageAttributes;
  28 import java.awt.PrintJob;
  29 import java.awt.Toolkit;
  30 import javax.swing.JButton;
  31 import javax.swing.JDialog;
  32 import javax.swing.JFrame;
  33 import javax.swing.JOptionPane;
  34 import javax.swing.JPanel;
  35 import javax.swing.SwingUtilities;
  36 
  37 /*
  38  * @test
  39  * @bug 8151590
  40  * @summary  All radio button should be selected when we call
  41  *            setDefaultSelection(JobAttributes.DefaultSelectionType.ALL);
  42  * @run main/manual PrintTest
  43  */
  44 public class PrintTest {
  45 
  46     public static void main(String[] args) throws Exception {
  47         SwingUtilities.invokeAndWait(new Runnable() {
  48             @Override
  49             public void run() {
  50                 doTest(PrintTest::printTest);
  51             }
  52         });
  53     }
  54 
  55     private static void printTest() {
  56         JobAttributes job = new JobAttributes();
  57         PageAttributes page = new PageAttributes();
  58         job.setDialog(JobAttributes.DialogType.NATIVE);
  59         job.setMultipleDocumentHandling(JobAttributes.MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);
  60         job.setDefaultSelection(JobAttributes.DefaultSelectionType.ALL);
  61         job.setDestination(JobAttributes.DestinationType.PRINTER);
  62         job.setCopies(2);
  63         job.setFromPage(2);
  64         job.setToPage(5);
  65         page.setMedia(PageAttributes.MediaType.A4);
  66         page.setOrientationRequested(PageAttributes.OrientationRequestedType.PORTRAIT);
  67         Toolkit tk = Toolkit.getDefaultToolkit();
  68         // seeting this dialog to native pritdialog
  69         if (tk != null) {
  70             PrintJob pj = tk.getPrintJob(new JFrame(), "testing the attribute setting ", job, page);
  71         }
  72     }
  73 
  74     private static void doTest(Runnable action) {
  75         String description
  76                 = " Visual inspection of print dialog is required.\n"
  77                 + " A print dialog wil lbe shown.\n "
  78                 + " Please verify ALL radio button is selected.\n"
  79                 + " If ALL is selected, press PASS else press FAIL";
  80 
  81         final JDialog dialog = new JDialog();
  82         dialog.setTitle("printSelectionTest");
  83         final JButton testButton = new JButton("Start Test");
  84         final JButton passButton = new JButton("PASS");
  85         passButton.setEnabled(false);
  86         passButton.addActionListener((e) -> {
  87             dialog.dispose();
  88         });
  89         final JButton failButton = new JButton("FAIL");
  90         failButton.setEnabled(false);
  91         failButton.addActionListener((e) -> {
  92             dialog.dispose();
  93             throw new RuntimeException("Correct radio button is not selected");
  94         });
  95         testButton.addActionListener((e) -> {
  96             testButton.setEnabled(false);
  97             action.run();
  98             passButton.setEnabled(true);
  99             failButton.setEnabled(true);
 100         });
 101         JPanel mainPanel = new JPanel(new BorderLayout());
 102         JPanel buttonPanel = new JPanel(new FlowLayout());
 103         buttonPanel.add(testButton);
 104         buttonPanel.add(passButton);
 105         buttonPanel.add(failButton);
 106         mainPanel.add(buttonPanel, BorderLayout.SOUTH);
 107         dialog.add(mainPanel);
 108         dialog.pack();
 109         dialog.setVisible(true);
 110     }
 111 }