1 /* 2 * Copyright (c) 2016, 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 @test 26 @bug 8057574 27 @summary Verify that child Dialog does not inherit parent's Properties 28 @run main ChildDialogProperties 29 */ 30 import java.awt.Color; 31 import java.awt.Dialog; 32 import java.awt.Font; 33 import java.awt.Frame; 34 import java.awt.Label; 35 36 public class ChildDialogProperties { 37 38 private Dialog parentDialog; 39 private Dialog dialogChild; 40 private Frame parentFrame; 41 private Dialog frameChildDialog; 42 private Label parentLabel; 43 private Font parentFont; 44 private Label childLabel; 45 46 private static final int WIDTH = 200; 47 private static final int HEIGHT = 200; 48 49 public void testChildPropertiesWithDialogAsParent() { 50 51 parentDialog = new Dialog((Dialog) null, "parent Dialog"); 52 parentDialog.setSize(WIDTH, HEIGHT); 53 parentDialog.setLocation(100, 100); 54 parentDialog.setBackground(Color.RED); 55 56 parentLabel = new Label("ParentForegroundAndFont"); 57 parentFont = new Font("Courier New", Font.ITALIC, 15); 58 parentDialog.setForeground(Color.BLUE); 59 parentDialog.setFont(parentFont); 60 61 parentDialog.add(parentLabel); 62 parentDialog.setVisible(true); 63 64 dialogChild = new Dialog(parentDialog, "Dialog's child"); 65 dialogChild.setSize(WIDTH, HEIGHT); 66 dialogChild.setLocation(WIDTH + 200, 100); 67 childLabel = new Label("ChildForegroundAndFont"); 68 dialogChild.add(childLabel); 69 70 dialogChild.setVisible(true); 71 72 if (parentDialog.getBackground() == dialogChild.getBackground()) { 73 dispose(); 74 throw new RuntimeException("Child Dialog Should NOT Inherit " 75 + "Parent Dialog's Background Color"); 76 } 77 78 if (parentDialog.getForeground() == dialogChild.getForeground()) { 79 dispose(); 80 throw new RuntimeException("Child Dialog Should NOT Inherit " 81 + "Parent Dialog's Foreground Color"); 82 } 83 84 if (parentDialog.getFont() == dialogChild.getFont()) { 85 dispose(); 86 throw new RuntimeException("Child Dialog Should NOT Inherit " 87 + "Parent Dialog's Font Style/Color"); 88 } 89 90 } 91 92 public void testChildPropertiesWithFrameAsParent() { 93 94 parentFrame = new Frame("parent Frame"); 95 parentFrame.setSize(WIDTH, HEIGHT); 96 parentFrame.setLocation(100, 400); 97 parentFrame.setBackground(Color.BLUE); 98 parentLabel = new Label("ParentForegroundAndFont"); 99 parentFont = new Font("Courier New", Font.ITALIC, 15); 100 parentFrame.setForeground(Color.RED); 101 parentFrame.setFont(parentFont); 102 parentFrame.add(parentLabel); 103 parentFrame.setVisible(true); 104 105 frameChildDialog = new Dialog(parentFrame, "Frame's child"); 106 frameChildDialog.setSize(WIDTH, HEIGHT); 107 frameChildDialog.setLocation(WIDTH + 200, 400); 108 childLabel = new Label("ChildForegroundAndFont"); 109 frameChildDialog.add(childLabel); 110 frameChildDialog.setVisible(true); 111 112 if (parentFrame.getBackground() == frameChildDialog.getBackground()) { 113 dispose(); 114 throw new RuntimeException("Child Dialog Should NOT Inherit " 115 + "Parent Frame's Background Color"); 116 } 117 118 if (parentFrame.getForeground() == frameChildDialog.getForeground()) { 119 dispose(); 120 throw new RuntimeException("Child Dialog Should NOT Inherit " 121 + "Parent Frame's Foreground Color"); 122 } 123 124 if (parentFrame.getFont() == frameChildDialog.getFont()) { 125 dispose(); 126 throw new RuntimeException("Child Dialog Should NOT Inherit " 127 + "Parent Frame's Font Style/Color"); 128 } 129 } 130 131 private void dispose() { 132 133 if (parentDialog != null) { 134 parentDialog.dispose(); 135 } 136 if (parentFrame != null) { 137 parentFrame.dispose(); 138 } 139 } 140 141 public static void main(String[] args) throws Exception { 142 143 ChildDialogProperties obj = new ChildDialogProperties(); 144 // TestCase1: When Parent is Dialog, Child is Dialog 145 obj.testChildPropertiesWithDialogAsParent(); 146 // TestCase2: When Parent is Frame, chis is Dialog 147 obj.testChildPropertiesWithFrameAsParent(); 148 obj.dispose(); 149 } 150 151 }