1 /*
 2  * Copyright (c) 2004, 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.Frame;
25 import java.awt.Menu;
26 import java.awt.MenuItem;
27 import java.awt.PopupMenu;
28 import java.awt.event.MouseAdapter;
29 import java.awt.event.MouseEvent;
30 
31 /*
32  * @test
33  * @bug 5090643
34  * @key headful
35  * @library /java/awt/regtesthelpers
36  * @build PassFailJFrame
37  * @summary Menus added to the popup menu are truncated on XToolkit
38  * @run main/manual TruncatedPopupMenuTest
39  */
40 
41 public class TruncatedPopupMenuTest {
42     private static final String INSTRUCTIONS =
43             "1. Right-click on the Test Window.\n\n" +
44             "2. Look at the appeared popup menu.\n\n" +
45             "3. It should consist of one menu item (\"First simple menu item\")\n" +
46             "and one submenu (\"Just simple menu for the test\").\n\n" +
47             "4. The submenu should not be truncated. The submenu title text should\n" +
48             "be followed by a triangle. On the whole, menu should be good-looking.\n\n" +
49             "5. Left-click on the submenu (\"Just simple menu for the test\").\n" +
50             "After this operation, a submenu should popup. It should consist of\n"+
51             "one menu item (\"Second simple menu item \") and one submenu (\"Other Menu\").\n\n" +
52             "6. The submenu should not be truncated. The \"Other Menu\" text should be followed by\n" +
53             "a triangle.\n\n" +
54             "On the whole, menu should be good-looking.\n";
55 
56     public static void main(String[] args) throws Exception {
57         PassFailJFrame.builder()
58                       .instructions(INSTRUCTIONS)
59                       .rows(20)
60                       .columns(55)
61                       .testUI(TruncatedPopupMenuTest::createTestUI)
62                       .build()
63                       .awaitAndCheck();
64     }
65 
66     private static Frame createTestUI() {
67         Menu subMenu = new Menu("Just simple menu for the test");
68         subMenu.add(new MenuItem("Second simple menu item"));
69         subMenu.add(new Menu("Other Menu"));
70 
71         PopupMenu popup = new PopupMenu();
72         popup.add(new MenuItem("First simple menu item"));
73         popup.add(subMenu);
74 
75         Frame testUI = new Frame("TruncatedPopupMenuTest");
76         testUI.add(popup);
77         testUI.addMouseListener(new MouseAdapter() {
78             public void mousePressed(MouseEvent me) {
79                 if (me.isPopupTrigger()) {
80                     popup.show(me.getComponent(), me.getX(), me.getY());
81                 }
82             }
83             public void mouseReleased(MouseEvent me) {
84                 if (me.isPopupTrigger()) {
85                     popup.show(me.getComponent(), me.getX(), me.getY());
86                 }
87             }
88         });
89 
90         testUI.setSize(400, 400);
91         return testUI;
92    }
93 }