|
| 1 | +/* |
| 2 | + * Copyright (c) 1998, 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 | + * @test |
| 25 | + * @bug 4145193 |
| 26 | + * @summary Mouse event activates multiple pull-down menus when testing Oracle app |
| 27 | + * @library /java/awt/regtesthelpers |
| 28 | + * @build PassFailJFrame |
| 29 | + * @run main/manual PopupHangTest |
| 30 | +*/ |
| 31 | + |
| 32 | +import java.awt.BorderLayout; |
| 33 | +import java.awt.Component; |
| 34 | +import java.awt.Color; |
| 35 | +import java.awt.Dimension; |
| 36 | +import java.awt.Frame; |
| 37 | +import java.awt.Graphics; |
| 38 | +import java.awt.Label; |
| 39 | +import java.awt.MenuItem; |
| 40 | +import java.awt.PopupMenu; |
| 41 | +import java.awt.event.FocusEvent; |
| 42 | +import java.awt.event.KeyEvent; |
| 43 | +import java.awt.event.MouseEvent; |
| 44 | +import java.awt.event.FocusListener; |
| 45 | +import java.awt.event.KeyListener; |
| 46 | +import java.awt.event.MouseListener; |
| 47 | +import java.awt.event.MouseMotionListener; |
| 48 | + |
| 49 | +public class PopupHangTest { |
| 50 | + private static final String INSTRUCTIONS = """ |
| 51 | + 2 areas yellow and red should be seen. |
| 52 | +
|
| 53 | + Clicking in these areas should cause a menu to popup. See if you can |
| 54 | + get the menu to stay up and grab all input. One way to do this is to |
| 55 | + click and hold the mouse to popup the menu, move away/outside of the |
| 56 | + menu and release the mouse. At that point, the input is grabbed and |
| 57 | + the *only* way out is to hit the escape key. Try this on both areas. |
| 58 | +
|
| 59 | + To make things worse, when the popup menu is up, click repeatedly on |
| 60 | + the LightWeight component area. Hit escape. Do you see multiple menus appearing ? |
| 61 | +
|
| 62 | + If you do not see either of the two problems above, the problem is fixed. |
| 63 | + Press pass, else press Fail"""; |
| 64 | + |
| 65 | + static Frame frame; |
| 66 | + |
| 67 | + public static void main(String[] args) throws Exception { |
| 68 | + PassFailJFrame.builder() |
| 69 | + .title("PopupHangTest") |
| 70 | + .instructions(INSTRUCTIONS) |
| 71 | + .rows((int) INSTRUCTIONS.lines().count() + 2) |
| 72 | + .columns(45) |
| 73 | + .testUI(PopupHangTest::createUI) |
| 74 | + .logArea() |
| 75 | + .build() |
| 76 | + .awaitAndCheck(); |
| 77 | + } |
| 78 | + |
| 79 | + private static Frame createUI() { |
| 80 | + TestMenuButton m1; |
| 81 | + TestHeavyButton m2; |
| 82 | + frame = new Frame(); |
| 83 | + |
| 84 | + frame.setLayout (new BorderLayout ()); |
| 85 | + |
| 86 | + m1 = new TestMenuButton("LightWeight component"); |
| 87 | + m1.setBackground(Color.yellow); |
| 88 | + |
| 89 | + m2 = new TestHeavyButton("HeavyWeight component"); |
| 90 | + m2.setBackground(Color.red); |
| 91 | + |
| 92 | + frame.add("North", m1); |
| 93 | + frame.add("South", m2); |
| 94 | + |
| 95 | + m1.requestFocus(); |
| 96 | + frame.setSize(200, 110); |
| 97 | + return frame; |
| 98 | + } |
| 99 | + |
| 100 | +} |
| 101 | + |
| 102 | +class TestMenuButton extends Component implements MouseListener, |
| 103 | + MouseMotionListener, |
| 104 | + KeyListener, |
| 105 | + FocusListener { |
| 106 | + |
| 107 | + PopupMenu popupMenu = null; |
| 108 | + String name; |
| 109 | + |
| 110 | + TestMenuButton(String name) { |
| 111 | + PopupMenu menu = popupMenu = new PopupMenu("Popup"); |
| 112 | + menu.add(new MenuItem("item 1")); |
| 113 | + menu.add(new MenuItem("item 2")); |
| 114 | + menu.add(new MenuItem("item 3")); |
| 115 | + this.add(menu); |
| 116 | + this.name = name; |
| 117 | + addMouseListener(this); |
| 118 | + addMouseMotionListener(this); |
| 119 | + addKeyListener(this); |
| 120 | + addFocusListener(this); |
| 121 | + } |
| 122 | + |
| 123 | + void println(String messageIn) { |
| 124 | + PassFailJFrame.log(messageIn); |
| 125 | + } |
| 126 | + |
| 127 | + public void mouseClicked(MouseEvent event) { |
| 128 | + /* |
| 129 | + popupMenu.show(this, event.getX(), event.getY()); |
| 130 | + */ |
| 131 | + } |
| 132 | + public void mousePressed(MouseEvent event) { |
| 133 | + println("TestMenuButton.mousePressed() called !!"); |
| 134 | + popupMenu.show(this, event.getX(), event.getY()); |
| 135 | + } |
| 136 | + public void mouseReleased(MouseEvent event) { |
| 137 | + println("TestMenuButton.mouseReleased() called !!"); |
| 138 | + } |
| 139 | + public void mouseEntered(MouseEvent event) { |
| 140 | + println("TestMenuButton.mouseEntered() called !!"); |
| 141 | + requestFocus(); |
| 142 | + } |
| 143 | + public void mouseExited(MouseEvent event) { |
| 144 | + } |
| 145 | + |
| 146 | + public void mouseDragged(MouseEvent event) { |
| 147 | + println("TestMenuButton.mouseDragged() called !!"); |
| 148 | + } |
| 149 | + public void mouseMoved(MouseEvent event) { |
| 150 | + println("TestMenuButton.mouseMoved() called !!"); |
| 151 | + } |
| 152 | + |
| 153 | + public void keyPressed(KeyEvent event) { |
| 154 | + println("TestMenuButton.keyPressed() called !!"); |
| 155 | + } |
| 156 | + public void keyReleased(KeyEvent event) { |
| 157 | + println("TestMenuButton.keyReleased() called !!"); |
| 158 | + } |
| 159 | + public void keyTyped(KeyEvent event) { |
| 160 | + println("TestMenuButton.keyTyped() called !!"); |
| 161 | + } |
| 162 | + |
| 163 | + |
| 164 | + public void focusGained(FocusEvent e){ |
| 165 | + println("TestMenuButton.focusGained():" + e); |
| 166 | + } |
| 167 | + public void focusLost(FocusEvent e){ |
| 168 | + println("TestMenuButton.focusLost():" + e); |
| 169 | + } |
| 170 | + |
| 171 | + |
| 172 | + public void paint(Graphics g) { |
| 173 | + Dimension d = getSize(); |
| 174 | + |
| 175 | + g.setColor(getBackground()); |
| 176 | + g.fillRect(0, 0, d.width-1, d.height-1); |
| 177 | + |
| 178 | + g.setColor(Color.black); |
| 179 | + g.drawString(name, 15, 15); |
| 180 | + } |
| 181 | + |
| 182 | + public Dimension getPreferredSize() { |
| 183 | + return (new Dimension(200, 50)); |
| 184 | + } |
| 185 | + |
| 186 | +} |
| 187 | + |
| 188 | +class TestHeavyButton extends Label implements MouseListener, |
| 189 | + MouseMotionListener, |
| 190 | + KeyListener, |
| 191 | + FocusListener { |
| 192 | + |
| 193 | + PopupMenu popupMenu = null; |
| 194 | + String name; |
| 195 | + |
| 196 | + TestHeavyButton(String name) { |
| 197 | + super(name); |
| 198 | + PopupMenu menu = popupMenu = new PopupMenu("Popup"); |
| 199 | + menu.add(new MenuItem("item 1")); |
| 200 | + menu.add(new MenuItem("item 2")); |
| 201 | + menu.add(new MenuItem("item 3")); |
| 202 | + this.add(menu); |
| 203 | + this.name = name; |
| 204 | + addMouseListener(this); |
| 205 | + addMouseMotionListener(this); |
| 206 | + addKeyListener(this); |
| 207 | + addFocusListener(this); |
| 208 | + } |
| 209 | + |
| 210 | + void println(String messageIn) { |
| 211 | + PassFailJFrame.log(messageIn); |
| 212 | + } |
| 213 | + |
| 214 | + public void mouseClicked(MouseEvent event) { |
| 215 | + /* |
| 216 | + popupMenu.show(this, event.getX(), event.getY()); |
| 217 | + */ |
| 218 | + } |
| 219 | + public void mousePressed(MouseEvent event) { |
| 220 | + println("TestHeavyButton.mousePressed() called !!"); |
| 221 | + popupMenu.show(this, event.getX(), event.getY()); |
| 222 | + } |
| 223 | + public void mouseReleased(MouseEvent event) { |
| 224 | + println("TestHeavyButton.mouseReleased() called !!"); |
| 225 | + } |
| 226 | + public void mouseEntered(MouseEvent event) { |
| 227 | + println("TestHeavyButton.mouseEntered() called !!"); |
| 228 | + requestFocus(); |
| 229 | + } |
| 230 | + public void mouseExited(MouseEvent event) { |
| 231 | + } |
| 232 | + |
| 233 | + public void mouseDragged(MouseEvent event) { |
| 234 | + println("TestHeavyButton.mouseDragged() called !!"); |
| 235 | + } |
| 236 | + public void mouseMoved(MouseEvent event) { |
| 237 | + println("TestHeavyButton.mouseMoved() called !!"); |
| 238 | + } |
| 239 | + |
| 240 | + public void keyPressed(KeyEvent event) { |
| 241 | + println("TestHeavyButton.keyPressed() called !!"); |
| 242 | + } |
| 243 | + public void keyReleased(KeyEvent event) { |
| 244 | + println("TestHeavyButton.keyReleased() called !!"); |
| 245 | + } |
| 246 | + public void keyTyped(KeyEvent event) { |
| 247 | + println("TestHeavyButton.keyTyped() called !!"); |
| 248 | + } |
| 249 | + |
| 250 | + public void focusGained(FocusEvent e){ |
| 251 | + println("TestHeavyButton.focusGained():" + e); |
| 252 | + } |
| 253 | + public void focusLost(FocusEvent e){ |
| 254 | + println("TestHeavyButton.focusLost():" + e); |
| 255 | + } |
| 256 | + |
| 257 | +} |
| 258 | + |
0 commit comments