|
| 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 | +import java.awt.Dialog; |
| 25 | +import java.awt.Frame; |
| 26 | +import java.awt.event.WindowListener; |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | +/* |
| 30 | + * @test |
| 31 | + * @bug 4058953 4094035 |
| 32 | + * @summary Test to verify system menu of a dialog on win32 |
| 33 | + * @requires (os.family == "windows") |
| 34 | + * @library /java/awt/regtesthelpers |
| 35 | + * @build PassFailJFrame |
| 36 | + * @run main/manual DialogSystemMenu |
| 37 | + */ |
| 38 | + |
| 39 | +public class DialogSystemMenu { |
| 40 | + public static void main(String[] args) throws Exception { |
| 41 | + String INSTRUCTIONS = """ |
| 42 | + 1. Check the following on the first dialog window: |
| 43 | + Right-clicking on the title bar |
| 44 | + should bring up a system menu. |
| 45 | + The system menu should not allow any |
| 46 | + of the Maximize, Minimize and |
| 47 | + Restore actions |
| 48 | +
|
| 49 | + 2. The second dialog should be non-resizable |
| 50 | + and have no application icon. |
| 51 | + """; |
| 52 | + PassFailJFrame.builder() |
| 53 | + .title("Test Instructions") |
| 54 | + .instructions(INSTRUCTIONS) |
| 55 | + .rows((int) INSTRUCTIONS.lines().count() + 2) |
| 56 | + .columns(35) |
| 57 | + .testUI(initialize()) |
| 58 | + .build() |
| 59 | + .awaitAndCheck(); |
| 60 | + } |
| 61 | + |
| 62 | + public static List<Dialog> initialize() { |
| 63 | + Frame frame = new java.awt.Frame("Parent Frame"); |
| 64 | + String txt = """ |
| 65 | + This is a resizable dialog |
| 66 | + Right-clicking on the title bar |
| 67 | + should bring up a system menu |
| 68 | + The system menu should not |
| 69 | + allow any |
| 70 | + of the Maximize, Minimize and |
| 71 | + Restore actions |
| 72 | + """; |
| 73 | + String txt_non = """ |
| 74 | + This is a non-resizable dialog |
| 75 | + It should be really non-resizable |
| 76 | + and have no application icon |
| 77 | + """; |
| 78 | + TestApp resizable = new TestApp(frame, "Test for 4058953", txt, true); |
| 79 | + resizable.setLocation(0, 0); |
| 80 | + |
| 81 | + TestApp non_resizable = new TestApp(frame, "Test for 4094035", txt_non, false); |
| 82 | + non_resizable.setLocation(320, 0); |
| 83 | + return List.of(resizable, non_resizable); |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | + |
| 88 | +class TestApp extends Dialog implements WindowListener { |
| 89 | + public TestApp(java.awt.Frame parent, String title, String txt, boolean resize) { |
| 90 | + super(parent, title, false); |
| 91 | + |
| 92 | + java.awt.TextArea ta = new java.awt.TextArea(txt); |
| 93 | + ta.setEditable(false); |
| 94 | + this.add(ta, "Center"); |
| 95 | + this.addWindowListener(this); |
| 96 | + this.setSize(300, 200); |
| 97 | + this.setResizable(resize); |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + public void windowOpened(java.awt.event.WindowEvent myEvent) { |
| 102 | + } |
| 103 | + |
| 104 | + public void windowClosed(java.awt.event.WindowEvent myEvent) { |
| 105 | + } |
| 106 | + |
| 107 | + public void windowIconified(java.awt.event.WindowEvent myEvent) { |
| 108 | + } |
| 109 | + |
| 110 | + public void windowDeiconified(java.awt.event.WindowEvent myEvent) { |
| 111 | + } |
| 112 | + |
| 113 | + public void windowActivated(java.awt.event.WindowEvent myEvent) { |
| 114 | + } |
| 115 | + |
| 116 | + public void windowDeactivated(java.awt.event.WindowEvent myEvent) { |
| 117 | + } |
| 118 | + |
| 119 | + public void windowClosing(java.awt.event.WindowEvent myEvent) { |
| 120 | + this.dispose(); |
| 121 | + } |
| 122 | +} |
0 commit comments