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 import java.awt.*; 25 import static jdk.testlibrary.Asserts.*; 26 27 /* 28 * @test 29 * @bug 8047367 30 * @summary Check modality settings for Window and Dialog. 31 * 32 * @library ../../../../lib/testlibrary/ 33 * @run main ModalitySettingsTest 34 */ 35 36 37 38 public class ModalitySettingsTest { 39 40 private void doTest() throws Exception { 41 42 Window w = new Window(new Frame()); 43 44 boolean unexpectedExc = false; 45 46 try { 47 Dialog d = new Dialog(w); 48 } catch (IllegalArgumentException iae) { 49 } catch (Exception e) { 50 unexpectedExc = true; 51 } 52 53 assertFalse(unexpectedExc, "unexpected exception occured when a " + 54 "Window instance was passed to Dialog constructor"); 55 56 Dialog d = new Dialog((Frame) null); 57 assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS, 58 "the default modality type returned by Dialog " + 59 "differs from Dialog.ModalityType.MODELESS"); 60 61 Frame f = new Frame(); 62 assertTrue(f.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE, 63 "the default modality exclusion type returned by Frame" + 64 "differs from Dialog.ModalExclusionType.NO_EXCLUDE"); 65 66 w = new Window((Frame) null); 67 assertTrue(w.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE, 68 "the default modality exclusion type returned by Window " + 69 "differs from Dialog.ModalExclusionType.NO_EXCLUDE"); 70 71 d = new Dialog((Frame) null); 72 assertTrue(d.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE, 73 "the default modality exclusion type returned by Dialog " + 74 "differs from Dialog.ModalExclusionType.NO_EXCLUDE"); 75 76 d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL); 77 assertTrue(d.getModalityType() == Dialog.ModalityType.TOOLKIT_MODAL, 78 "the modality type returned by Dialog " + 79 "differs from Dialog.ModalityType.TOOLKIT_MODAL " + 80 "after setting the modality type to that value"); 81 82 d.setModal(false); 83 assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS, 84 "the modality type returned by Dialog differs from " + 85 "Dialog.ModalityType.MODELESS after calling setModal(false)"); 86 87 d.setModal(true); 88 assertTrue(d.getModalityType() == Dialog.ModalityType.APPLICATION_MODAL, 89 "the modality type returned by Dialog differs from " 90 + "Dialog.ModalityType.APPLICATION_MODAL after calling setModal(true)"); 91 92 w.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); 93 assertTrue(w.getModalExclusionType() == 94 Dialog.ModalExclusionType.APPLICATION_EXCLUDE, 95 "getModalExclusionType method for Window did not return " + 96 "Dialog.ModalExclusionType.APPLICATION_EXCLUDE after " + 97 "setting it to that value"); 98 99 d = new Dialog((Frame) null); 100 d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL); 101 assertTrue(d.isModal(), "method isModal for Dialog " + 102 "returned false when the Dialog is toolkit modal"); 103 104 d.setModalityType(Dialog.ModalityType.MODELESS); 105 assertFalse(d.isModal(), "method isModal for Dialog " + 106 "returned true when the Dialog is MODELESS"); 107 108 d = new Dialog((Frame) null, (Dialog.ModalityType) null); 109 assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS, 110 "The modality type returned for a Dialog constructed " + 111 "with null modality type differs from MODELESS"); 112 113 d = new Dialog((Frame) null); 114 d.setModalityType(null); 115 assertTrue(d.getModalityType() == Dialog.ModalityType.MODELESS, 116 "the modality type returned for a Dialog set with null " + 117 "modality type differs from MODELESS"); 118 119 d.setModalExclusionType(null); 120 assertTrue(d.getModalExclusionType() == Dialog.ModalExclusionType.NO_EXCLUDE, 121 "The exlcusion type returned for a Dialog set with null " + 122 "exclusion type differs from NO_EXCLUDE"); 123 124 try { 125 Dialog.ModalityType.valueOf("invalid"); 126 } catch (IllegalArgumentException iae) { 127 } catch (Exception e) { 128 unexpectedExc = true; 129 } 130 131 assertFalse(unexpectedExc, "unexpected exception occured when an " + 132 "invalid value was passed to ModalityType.valueOf method"); 133 } 134 135 public static void main(String[] args) throws Exception { 136 ModalitySettingsTest test = new ModalitySettingsTest(); 137 test.doTest(); 138 } 139 }