1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/*
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8055836 8057694 8055752
* @summary Check if Print and Page Setup dialogs block other windows;
* check also correctness of modal behavior for other dialogs.
* @library /java/awt/regtesthelpers
* @run main/manual PrintDialogsTest
*/
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PrintDialogsTest extends Panel implements ActionListener {
static final String INSTRUCTIONS =
"This test is free format, which means there is no enforced or guided sequence." + "\n" +
"Please select each of " + "\n" +
"(a) The dialog parent type." + "\n" +
"(b) The dialog modality type" + "\n" +
"(c) The print dialog type (Print dialog or Page Setup dialog)" + "\n" +
"Once the choices have been made click the \"Start test\" button." + "\n" +
"Three windows will appear" + "\n" +
"(1) A Frame or a Dialog - in the case you selected \"Dialog\" as the parent type" + "\n" +
"(2) a Window (ie an undecorated top-level)" + "\n" +
"(3) A dialog with two buttons \"Open\" and \"Finish\"" + "\n" +
"Now check as follows whether modal blocking works as expected." + "\n" +
"Windows (1) and (2) contain a button which you should be able to press" + "\n" +
"ONLY if you selected \"Non-modal\", or \"Modeless\" for modality type." + "\n" +
"In other cases window (3) will block input to (1) and (2)" + "\n" +
"Then push the \"Open\" button on the Dialog to show the printing dialog and check" + "\n" +
"if it blocks the rest of the application - ie all of windows (1), (2) and (3)" + "\n" +
"should ALWAYS be blocked when the print dialog is showing." + "\n" +
"Now cancel the printing dialog and check the correctness of modal blocking" + "\n" +
"behavior for the Dialog again." + "\n" +
"To close all the 3 test windows please push the \"Finish\" button." + "\n" +
"Repeat all the above for different combinations, which should include" + "\n" +
"using all of the Dialog parent choices and all of the Dialog Modality types." + "\n" +
"If any behave incorrectly, note the combination of choices and press Fail." + "\n" +
"If all behave correctly, press Pass.";
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.instructions(INSTRUCTIONS)
.rows(35)
.columns(60)
.testUI(PrintDialogsTest::createUI)
.testTimeOut(10)
.build()
.awaitAndCheck();
}
private Button btnTest;
private Checkbox cbPage, cbPrint,
cbNullDlg, cbNullFrm, cbHiddDlg, cbHiddFrm, cbDlg, cbFrm,
cbModal, cbAppModal, cbTKModal, cbDocModal, cbModeless, cbNonModal;
private CheckboxGroup groupDialog, groupParent, groupModType;
private static Frame createUI() {
Frame frame = new Frame("Dialog Modality Testing");
PrintDialogsTest test = new PrintDialogsTest();
test.createGUI();
frame.add(test);
frame.pack();
return frame;
}
public void actionPerformed(ActionEvent e) {
if (!btnTest.equals(e.getSource())) { return; }
boolean isPrintDlg = groupDialog.getSelectedCheckbox().equals(cbPrint);
Test.DialogParent p = null;
Checkbox cbParent = groupParent.getSelectedCheckbox();
if (cbParent.equals(cbNullDlg)) {
p = Test.DialogParent.NULL_DIALOG;
} else if (cbParent.equals(cbNullFrm)) {
p = Test.DialogParent.NULL_FRAME;
} else if (cbParent.equals(cbHiddDlg)) {
p = Test.DialogParent.HIDDEN_DIALOG;
} else if (cbParent.equals(cbHiddFrm)) {
p = Test.DialogParent.HIDDEN_FRAME;
} else if (cbParent.equals(cbDlg)) {
p = Test.DialogParent.DIALOG;
} else if (cbParent.equals(cbFrm)) {
p = Test.DialogParent.FRAME;
}
boolean modal = false;
Dialog.ModalityType type = null;
Checkbox cbModType = groupModType.getSelectedCheckbox();
if (cbModType.equals(cbModal)) {
modal = true;
} else if (cbModType.equals(cbNonModal)) {
modal = false;
} else if (cbModType.equals(cbAppModal)) {
type = Dialog.ModalityType.APPLICATION_MODAL;
} else if (cbModType.equals(cbDocModal)) {
type = Dialog.ModalityType.DOCUMENT_MODAL;
} else if (cbModType.equals(cbTKModal)) {
type = Dialog.ModalityType.TOOLKIT_MODAL;
} else if (cbModType.equals(cbModeless)) {
type = Dialog.ModalityType.MODELESS;
}
if (type == null) {
(new Test(isPrintDlg, modal, p)).start();
} else {
(new Test(isPrintDlg, type, p)).start();
}
}
private void createGUI() {
setLayout(new BorderLayout());
Panel panel = new Panel();
panel.setLayout(new GridLayout(21, 1));
btnTest = new Button("Start test");
btnTest.addActionListener(this);
panel.add(btnTest);
panel.add(new Label(" ")); // spacing
panel.add(new Label("Dialog parent:"));
groupParent = new CheckboxGroup();
cbNullDlg = new Checkbox("NULL Dialog" , groupParent, true );
cbNullFrm = new Checkbox("NULL Frame" , groupParent, false);
cbHiddDlg = new Checkbox("Hidden Dialog", groupParent, false);
cbHiddFrm = new Checkbox("Hidden Frame" , groupParent, false);
cbDlg = new Checkbox("Dialog" , groupParent, false);
cbFrm = new Checkbox("Frame" , groupParent, false);
panel.add(cbNullDlg);
panel.add(cbNullFrm);
panel.add(cbHiddDlg);
panel.add(cbHiddFrm);
panel.add(cbDlg);
panel.add(cbFrm);
panel.add(new Label(" ")); // spacing
panel.add(new Label("Dialog modality type:"));
groupModType = new CheckboxGroup();
cbModal = new Checkbox("Modal" , groupModType, true );
cbNonModal = new Checkbox("Non-modal" , groupModType, false);
cbAppModal = new Checkbox("Application modal", groupModType, false);
cbDocModal = new Checkbox("Document modal" , groupModType, false);
cbTKModal = new Checkbox("Toolkit modal" , groupModType, false);
cbModeless = new Checkbox("Modeless" , groupModType, false);
panel.add(cbModal);
panel.add(cbNonModal);
panel.add(cbAppModal);
panel.add(cbDocModal);
panel.add(cbTKModal);
panel.add(cbModeless);
panel.add(new Label(" ")); // spacing
panel.add(new Label("Print dialog type:"));
groupDialog = new CheckboxGroup();
cbPage = new Checkbox("Page Setup", groupDialog, true);
cbPrint = new Checkbox("Print", groupDialog, false);
panel.add(cbPage);
panel.add(cbPrint);
add(panel);
}
}
|