|
| 1 | +/* |
| 2 | + * Copyright (c) 1999, 2024, 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 4255230 4191946 |
| 27 | + * @summary Tests to verify Dialog inherits background from its owner |
| 28 | + * @requires (os.family == "windows") |
| 29 | + * @library /java/awt/regtesthelpers |
| 30 | + * @build PassFailJFrame |
| 31 | + * @run main/manual DialogBackgroundTest |
| 32 | + */ |
| 33 | + |
| 34 | +import java.awt.Button; |
| 35 | +import java.awt.Color; |
| 36 | +import java.awt.Dialog; |
| 37 | +import java.awt.FlowLayout; |
| 38 | +import java.awt.Frame; |
| 39 | +import java.awt.Label; |
| 40 | +import java.awt.Menu; |
| 41 | +import java.awt.MenuBar; |
| 42 | +import java.awt.MenuItem; |
| 43 | +import java.awt.TextField; |
| 44 | +import java.awt.Window; |
| 45 | +import java.awt.event.ActionEvent; |
| 46 | +import java.awt.event.ActionListener; |
| 47 | +import java.awt.event.WindowAdapter; |
| 48 | +import java.awt.event.WindowEvent; |
| 49 | + |
| 50 | +public class DialogBackgroundTest { |
| 51 | + public static void main(String[] args) throws Exception { |
| 52 | + String INSTRUCTIONS = """ |
| 53 | + Perform the following steps: |
| 54 | + 1) Select "New Frame" from the "File" menu of the |
| 55 | + "TreeCopy Frame #1" frame. |
| 56 | + 2) Select "Configure" from the "File" menu in the |
| 57 | + *new* frame. |
| 58 | + If label text "This is a label:" in the appeared |
| 59 | + "Configuration Dialog" dialog has a grey background |
| 60 | + test PASSES, otherwise it FAILS |
| 61 | + """; |
| 62 | + TreeCopy treeCopy = new TreeCopy(++TreeCopy.windowCount, null); |
| 63 | + PassFailJFrame.builder() |
| 64 | + .title("Test Instructions") |
| 65 | + .instructions(INSTRUCTIONS) |
| 66 | + .rows((int) INSTRUCTIONS.lines().count() + 2) |
| 67 | + .columns(35) |
| 68 | + .testUI(treeCopy) |
| 69 | + .logArea(8) |
| 70 | + .build() |
| 71 | + .awaitAndCheck(); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +class TreeCopy extends Frame implements ActionListener { |
| 76 | + TextField tfRoot; |
| 77 | + ConfigDialog configDlg; |
| 78 | + MenuItem miConfigure = new MenuItem("Configure..."); |
| 79 | + MenuItem miNewWindow = new MenuItem("New Frame"); |
| 80 | + static int windowCount = 0; |
| 81 | + Window parent; |
| 82 | + |
| 83 | + public TreeCopy(int windowNum, Window myParent) { |
| 84 | + super(); |
| 85 | + setTitle("TreeCopy Frame #" + windowNum); |
| 86 | + MenuBar mb = new MenuBar(); |
| 87 | + Menu m = new Menu("File"); |
| 88 | + configDlg = new ConfigDialog(this); |
| 89 | + parent = myParent; |
| 90 | + |
| 91 | + m.add(miConfigure); |
| 92 | + m.add(miNewWindow); |
| 93 | + miConfigure.addActionListener(this); |
| 94 | + miNewWindow.addActionListener(this); |
| 95 | + mb.add(m); |
| 96 | + setMenuBar(mb); |
| 97 | + m.addActionListener(this); |
| 98 | + |
| 99 | + tfRoot = new TextField(); |
| 100 | + tfRoot.setEditable(false); |
| 101 | + add(tfRoot); |
| 102 | + |
| 103 | + addWindowListener(new WindowAdapter() { |
| 104 | + public void windowClosing(WindowEvent we) { |
| 105 | + dispose(); |
| 106 | + } |
| 107 | + }); |
| 108 | + |
| 109 | + setSize(200, 100); |
| 110 | + setLocationRelativeTo(parent); |
| 111 | + } |
| 112 | + |
| 113 | + public void actionPerformed(ActionEvent ae) { |
| 114 | + Object source = ae.getSource(); |
| 115 | + |
| 116 | + if (source == miConfigure) { |
| 117 | + configDlg.setVisible(true); |
| 118 | + if (configDlg.getBackground() != configDlg.labelColor) |
| 119 | + PassFailJFrame.log("FAIL: Test failed!!!"); |
| 120 | + } else if (source == miNewWindow) { |
| 121 | + new TreeCopy(++windowCount, this).setVisible(true); |
| 122 | + } |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +class ConfigDialog extends Dialog implements ActionListener { |
| 127 | + public Button okButton; |
| 128 | + public Button cancelButton; |
| 129 | + public Label l2; |
| 130 | + public Color labelColor; |
| 131 | + |
| 132 | + public ConfigDialog(Frame parent) { |
| 133 | + super(parent, "Configuration Dialog"); |
| 134 | + okButton = new Button("OK"); |
| 135 | + cancelButton = new Button("Cancel"); |
| 136 | + l2 = new Label("This is a label:"); |
| 137 | + |
| 138 | + setLayout(new FlowLayout()); |
| 139 | + add(l2); |
| 140 | + add(okButton); |
| 141 | + add(cancelButton); |
| 142 | + |
| 143 | + okButton.addActionListener(this); |
| 144 | + cancelButton.addActionListener(this); |
| 145 | + |
| 146 | + pack(); |
| 147 | + labelColor = l2.getBackground(); |
| 148 | + } |
| 149 | + |
| 150 | + public void actionPerformed(ActionEvent ae) { |
| 151 | + dispose(); |
| 152 | + } |
| 153 | +} |
0 commit comments