|
| 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.Checkbox; |
| 25 | +import java.awt.Dialog; |
| 26 | +import java.awt.FlowLayout; |
| 27 | +import java.awt.Frame; |
| 28 | +import java.awt.Panel; |
| 29 | +import java.awt.TextArea; |
| 30 | +import java.awt.event.ComponentEvent; |
| 31 | +import java.awt.event.ComponentListener; |
| 32 | +import java.awt.event.ItemEvent; |
| 33 | +import java.awt.event.ItemListener; |
| 34 | +import java.lang.Exception; |
| 35 | +import java.lang.String; |
| 36 | +import java.lang.System; |
| 37 | + |
| 38 | +/* |
| 39 | + * @test |
| 40 | + * @bug 4115213 |
| 41 | + * @summary Test to verify Checks that with resizable set to false, |
| 42 | + * dialog can not be resized |
| 43 | + * @library /java/awt/regtesthelpers |
| 44 | + * @build PassFailJFrame |
| 45 | + * @run main/manual DialogResizeTest |
| 46 | + */ |
| 47 | + |
| 48 | +public class DialogResizeTest { |
| 49 | + public static void main(String[] args) throws Exception { |
| 50 | + String INSTRUCTIONS = """ |
| 51 | + 1. When this test is run a dialog will display (setResizable Test) |
| 52 | + Click on the checkbox to change the dialog resizable state |
| 53 | + 2. For both dialog resizable states (resizable, non-resizable) try to |
| 54 | + change the size of the dialog. When isResizable is true the dialog |
| 55 | + is resizable. When isResizable is false the dialog is non-resizable |
| 56 | + 3. If this is the behavior that you observe, the test has passed, Press |
| 57 | + the Pass button. Otherwise the test has failed, Press the Fail button |
| 58 | + """; |
| 59 | + PassFailJFrame.builder() |
| 60 | + .title("Test Instructions") |
| 61 | + .instructions(INSTRUCTIONS) |
| 62 | + .rows((int) INSTRUCTIONS.lines().count() + 2) |
| 63 | + .columns(40) |
| 64 | + .testUI(initialize()) |
| 65 | + .logArea(8) |
| 66 | + .build() |
| 67 | + .awaitAndCheck(); |
| 68 | + } |
| 69 | + |
| 70 | + public static Dialog initialize() { |
| 71 | + Frame f = new Frame("Owner Frame"); |
| 72 | + MyDialog ld = new MyDialog(f); |
| 73 | + ld.setBounds(100, 100, 400, 150); |
| 74 | + ld.setResizable(false); |
| 75 | + System.out.println("isResizable is set to: " + ld.isResizable()); |
| 76 | + return ld; |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +class MyDialog extends Dialog implements ItemListener { |
| 81 | + String sText = "Tests java.awt.Dialog.setResizable method"; |
| 82 | + TextArea ta = new TextArea(sText, 2, 40, TextArea.SCROLLBARS_NONE); |
| 83 | + |
| 84 | + public MyDialog(Frame f) { |
| 85 | + |
| 86 | + super(f, "setResizable test", false); |
| 87 | + |
| 88 | + Panel cbPanel = new Panel(); |
| 89 | + cbPanel.setLayout(new FlowLayout()); |
| 90 | + |
| 91 | + Panel taPanel = new Panel(); |
| 92 | + taPanel.setLayout(new FlowLayout()); |
| 93 | + taPanel.add(ta); |
| 94 | + |
| 95 | + Checkbox cb = new Checkbox("Check this box to change the dialog's " + |
| 96 | + "resizable state", null, isResizable()); |
| 97 | + cb.setState(false); |
| 98 | + cb.addItemListener(this); |
| 99 | + cbPanel.add(cb); |
| 100 | + |
| 101 | + add("North", taPanel); |
| 102 | + add("South", cbPanel); |
| 103 | + pack(); |
| 104 | + } |
| 105 | + |
| 106 | + public void itemStateChanged(ItemEvent evt) { |
| 107 | + setResizable(evt.getStateChange() == ItemEvent.SELECTED); |
| 108 | + |
| 109 | + boolean bResizeState = isResizable(); |
| 110 | + PassFailJFrame.log("isResizable is set to: " + bResizeState); |
| 111 | + |
| 112 | + if (isResizable()) { |
| 113 | + ta.setText("dialog is resizable (isResizable = " + bResizeState + ")"); |
| 114 | + } else { |
| 115 | + ta.setText("dialog is NOT resizable (isResizable = " + bResizeState + ")"); |
| 116 | + } |
| 117 | + } |
| 118 | +} |
0 commit comments