|
| 1 | +/* |
| 2 | + * Copyright (c) 2003, 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.Dimension; |
| 26 | +import java.awt.Frame; |
| 27 | +import java.awt.event.ComponentEvent; |
| 28 | +import java.awt.event.ComponentListener; |
| 29 | + |
| 30 | +/* |
| 31 | + * @test |
| 32 | + * @bug 4912551 |
| 33 | + * @summary Checks that with resizable set to false before show() |
| 34 | + * dialog can not be resized. |
| 35 | + * @library /java/awt/regtesthelpers |
| 36 | + * @build PassFailJFrame |
| 37 | + * @run main/manual DialogInitialResizability |
| 38 | + */ |
| 39 | + |
| 40 | +public class DialogInitialResizability { |
| 41 | + static String instructions = """ |
| 42 | + When this test is run a dialog will display (setResizable Test). |
| 43 | + This dialog should not be resizable. |
| 44 | +
|
| 45 | + Additionally ensure that there are NO componentResized events in the log section. |
| 46 | + If the above conditions are true, then Press PASS else FAIL. |
| 47 | + """; |
| 48 | + |
| 49 | + private static final Dimension INITIAL_SIZE = new Dimension(400, 150); |
| 50 | + public static void main(String[] args) throws Exception { |
| 51 | + PassFailJFrame.builder() |
| 52 | + .title("DialogInitialResizability") |
| 53 | + .instructions(instructions) |
| 54 | + .testTimeOut(5) |
| 55 | + .rows((int) instructions.lines().count() + 2) |
| 56 | + .columns(40) |
| 57 | + .testUI(DialogInitialResizability::createGUI) |
| 58 | + .logArea() |
| 59 | + .build() |
| 60 | + .awaitAndCheck(); |
| 61 | + } |
| 62 | + |
| 63 | + public static MyDialog createGUI() { |
| 64 | + Frame f = new Frame("invisible dialog owner"); |
| 65 | + |
| 66 | + MyDialog ld = new MyDialog(f); |
| 67 | + ld.setBounds(100, 100, INITIAL_SIZE.width, INITIAL_SIZE.height); |
| 68 | + ld.setResizable(false); |
| 69 | + |
| 70 | + PassFailJFrame.log("Dialog isResizable is set to: " + ld.isResizable()); |
| 71 | + PassFailJFrame.log("Dialog Initial Size " + ld.getSize()); |
| 72 | + return ld; |
| 73 | + } |
| 74 | + |
| 75 | + private static class MyDialog extends Dialog implements ComponentListener { |
| 76 | + public MyDialog(Frame f) { |
| 77 | + super(f, "setResizable test", false); |
| 78 | + this.addComponentListener(this); |
| 79 | + } |
| 80 | + |
| 81 | + public void componentResized(ComponentEvent e) { |
| 82 | + if (!e.getComponent().getSize().equals(INITIAL_SIZE)) { |
| 83 | + PassFailJFrame.log("Component Resized. Test Failed!!"); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + public void componentMoved(ComponentEvent e) { |
| 88 | + } |
| 89 | + |
| 90 | + public void componentShown(ComponentEvent e) { |
| 91 | + } |
| 92 | + |
| 93 | + public void componentHidden(ComponentEvent e) { |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments