1 /*
   2  * Copyright (c) 2007, 2014, 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 
  24 
  25 /*
  26  * @test
  27  * @bug 8055836 8057694 8055752
  28  * @summary Check if Print and Page Setup dialogs lock other windows;
  29  *          check also correctness of modal behavior for other dialogs.
  30  *
  31  * @run applet/manual=yesno PrintDialogsTest.html
  32  */
  33 
  34 
  35 import java.applet.Applet;
  36 import java.awt.*;
  37 
  38 import java.awt.event.ActionEvent;
  39 import java.awt.event.ActionListener;
  40 
  41 
  42 public class PrintDialogsTest extends Applet implements ActionListener {
  43 
  44     private Button btnTest;
  45     private Checkbox  cbPage, cbPrint,
  46         cbNullDlg, cbNullFrm, cbHiddDlg, cbHiddFrm, cbDlg, cbFrm,
  47         cbModal, cbAppModal, cbTKModal, cbDocModal, cbModeless, cbNonModal;
  48 
  49     private CheckboxGroup groupDialog, groupParent, groupModType;
  50 
  51 
  52     public void actionPerformed(ActionEvent e) {
  53 
  54         if (!btnTest.equals(e.getSource())) { return; }
  55 
  56         boolean isPrintDlg = groupDialog.getSelectedCheckbox().equals(cbPrint);
  57 
  58         Test.DialogParent p = null;
  59         Checkbox cbParent = groupParent.getSelectedCheckbox();
  60         if (cbParent.equals(cbNullDlg)) {
  61             p = Test.DialogParent.NULL_DIALOG;
  62         } else if (cbParent.equals(cbNullFrm)) {
  63             p = Test.DialogParent.NULL_FRAME;
  64         } else if (cbParent.equals(cbHiddDlg)) {
  65             p = Test.DialogParent.HIDDEN_DIALOG;
  66         } else if (cbParent.equals(cbHiddFrm)) {
  67             p = Test.DialogParent.HIDDEN_FRAME;
  68         } else if (cbParent.equals(cbDlg)) {
  69             p = Test.DialogParent.DIALOG;
  70         } else if (cbParent.equals(cbFrm)) {
  71             p = Test.DialogParent.FRAME;
  72         }
  73 
  74         boolean modal = false;
  75         Dialog.ModalityType type = null;
  76         Checkbox cbModType = groupModType.getSelectedCheckbox();
  77         if (cbModType.equals(cbModal)) {
  78             modal = true;
  79         } else if (cbModType.equals(cbNonModal)) {
  80             modal = false;
  81         } else if (cbModType.equals(cbAppModal)) {
  82             type = Dialog.ModalityType.APPLICATION_MODAL;
  83         } else if (cbModType.equals(cbDocModal)) {
  84             type = Dialog.ModalityType.DOCUMENT_MODAL;
  85         } else if (cbModType.equals(cbTKModal)) {
  86             type = Dialog.ModalityType.TOOLKIT_MODAL;
  87         } else if (cbModType.equals(cbModeless)) {
  88             type = Dialog.ModalityType.MODELESS;
  89         }
  90 
  91         if (type == null) {
  92             (new Test(isPrintDlg, modal, p)).start();
  93         } else {
  94             (new Test(isPrintDlg, type,  p)).start();
  95         }
  96     }
  97 
  98     private void createGUI() {
  99 
 100         setLayout(new BorderLayout());
 101 
 102         setSize(350, 200);
 103         Panel panel = new Panel();
 104         panel.setLayout(new GridLayout(18, 1));
 105 
 106         btnTest = new Button("Start test");
 107         btnTest.addActionListener(this);
 108         panel.add(btnTest);
 109 
 110 
 111         panel.add(new Label("Dialog parent:"));
 112         groupParent = new CheckboxGroup();
 113         cbNullDlg = new Checkbox("NULL Dialog"  , groupParent, true );
 114         cbNullFrm = new Checkbox("NULL Frame"   , groupParent, false);
 115         cbHiddDlg = new Checkbox("Hidden Dialog", groupParent, false);
 116         cbHiddFrm = new Checkbox("Hidden Frame" , groupParent, false);
 117         cbDlg     = new Checkbox("Dialog"       , groupParent, false);
 118         cbFrm     = new Checkbox("Frame"        , groupParent, false);
 119 
 120         panel.add(cbNullDlg);
 121         panel.add(cbNullFrm);
 122         panel.add(cbHiddDlg);
 123         panel.add(cbHiddFrm);
 124         panel.add(cbDlg);
 125         panel.add(cbFrm);
 126 
 127         panel.add(new Label("Dialog modality type:"));
 128         groupModType = new CheckboxGroup();
 129         cbModal    = new Checkbox("Modal"            , groupModType, true );
 130         cbNonModal = new Checkbox("Non-modal"        , groupModType, false);
 131         cbAppModal = new Checkbox("Application modal", groupModType, false);
 132         cbDocModal = new Checkbox("Document modal"   , groupModType, false);
 133         cbTKModal  = new Checkbox("Toolkit modal"    , groupModType, false);
 134         cbModeless = new Checkbox("Modeless"         , groupModType, false);
 135 
 136         panel.add(cbModal);
 137         panel.add(cbNonModal);
 138         panel.add(cbAppModal);
 139         panel.add(cbDocModal);
 140         panel.add(cbTKModal);
 141         panel.add(cbModeless);
 142         add(panel);
 143 
 144         panel.add(new Label("Print dialog type:"));
 145         groupDialog = new CheckboxGroup();
 146         cbPage   = new Checkbox("Page Setup", groupDialog, true);
 147         cbPrint  = new Checkbox("Print", groupDialog, false);
 148         panel.add(cbPage);
 149         panel.add(cbPrint);
 150 
 151         validate();
 152         setVisible(true);
 153     }
 154 
 155     public void start() {
 156         try {
 157             EventQueue.invokeAndWait(this::createGUI);
 158         } catch (Exception e) {}
 159     }
 160 }