Path: blob/master/test/jdk/javax/swing/JMenuItem/ClickMenuTestManual/ClickMenuTestManual.java
41153 views
/*1* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @key headful26* @bug 815823027* @summary Verify menu item option apple.laf.useScreenMenuBar implementation28* @requires (os.family=="mac")29* @run main ClickMenuTestManual30*/3132import java.awt.Color;33import java.awt.GridBagConstraints;34import java.awt.GridBagLayout;35import java.awt.event.ActionEvent;36import java.awt.event.ActionListener;37import java.util.logging.Level;38import java.util.logging.Logger;39import javax.swing.BorderFactory;40import javax.swing.JButton;41import javax.swing.JFrame;42import javax.swing.JMenu;43import javax.swing.JMenuBar;44import javax.swing.JMenuItem;45import javax.swing.JPanel;46import javax.swing.JTextArea;47import static javax.swing.WindowConstants.EXIT_ON_CLOSE;4849public class ClickMenuTestManual implements50ActionListener {5152public static final String TEST_STRING = "STRING";5354private static GridBagLayout layout;55private static JPanel mainControlPanel;56private static JPanel instructionPanel;57private static JPanel testPanel;5859private static JPanel resultButtonPanel;60private static JPanel controlPanel;61private static JTextArea instructionTextArea;62private static JTextArea testTextArea;63private static JButton passButton;64private static JButton failButton;65private static JMenu menu;66private static JMenuBar menuBar;67private static JMenuItem menuItem;68private static JFrame mainFrame;6970public static void main(String[] args) throws Exception {71System.setProperty("apple.laf.useScreenMenuBar", "true");72ClickMenuTestManual test73= new ClickMenuTestManual();74}7576public ClickMenuTestManual() throws Exception {77createControlPanelUI();78}7980public final void createControlPanelUI() throws Exception {81layout = new GridBagLayout();82mainControlPanel = new JPanel(layout);83instructionPanel = new JPanel(layout);84testPanel = new JPanel(layout);85resultButtonPanel = new JPanel(layout);86controlPanel = new JPanel(layout);8788GridBagConstraints gbc = new GridBagConstraints();89String instructions90= "1) Click on MENU using mouse "91+ "\n2) Click on MENU ITEM using mouse "92+ "\n3) Check output on textArea if equal to STRING "93+ "\n\n If correct string, press \"Pass\" "94+ "\n Otherwise, press \"Fail\" ";95instructionTextArea = new JTextArea();96instructionTextArea.setText(instructions);97instructionTextArea.setEnabled(false);98instructionTextArea.setDisabledTextColor(Color.black);99instructionTextArea.setBackground(Color.white);100instructionTextArea.setBorder(101BorderFactory.createLineBorder(Color.black));102gbc.gridx = 0;103gbc.gridy = 0;104gbc.fill = GridBagConstraints.HORIZONTAL;105instructionPanel.add(instructionTextArea, gbc);106testTextArea = new JTextArea();107testTextArea.setEnabled(true);108testTextArea.setDisabledTextColor(Color.black);109testTextArea.setBackground(Color.white);110testTextArea.setBorder(111BorderFactory.createLineBorder(Color.black));112gbc.gridx = 0;113gbc.gridy = 0;114gbc.fill = GridBagConstraints.HORIZONTAL;115testPanel.add(testTextArea, gbc);116passButton = new JButton("Pass");117passButton.setActionCommand("Pass");118passButton.addActionListener(this);119failButton = new JButton("Fail");120failButton.setActionCommand("Fail");121failButton.addActionListener(this);122gbc.gridx = 0;123gbc.gridy = 0;124resultButtonPanel.add(passButton, gbc);125gbc.gridx = 1;126gbc.gridy = 0;127resultButtonPanel.add(failButton, gbc);128gbc.gridx = 0;129gbc.gridy = 0;130mainControlPanel.add(instructionPanel, gbc);131gbc.gridx = 0;132gbc.gridy = 1;133mainControlPanel.add(testPanel, gbc);134gbc.gridx = 0;135gbc.gridy = 2;136mainControlPanel.add(resultButtonPanel, gbc);137gbc.gridx = 0;138gbc.gridy = 3;139mainControlPanel.add(controlPanel, gbc);140mainFrame = new JFrame("Control Panel");141mainFrame.add(mainControlPanel);142menuBar = new JMenuBar();143menu = new JMenu("MENU");144menuItem = new JMenuItem("MENU ITEM");145menuItem.addActionListener((e) -> {146testTextArea.setText(TEST_STRING);147});148menu.add(menuItem);149menuBar.add(menu);150mainFrame.setJMenuBar(menuBar);151mainFrame.pack();152mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);153mainFrame.setVisible(true);154155}156157@Override158public void actionPerformed(ActionEvent evt) {159if (evt.getSource() instanceof JButton) {160JButton btn = (JButton) evt.getSource();161if (btn.getActionCommand().equals("Pass")) {162try {163cleanUp();164} catch (Exception ex) {165Logger.getLogger(ClickMenuTestManual.class166.getName()).log(Level.SEVERE, null, ex);167}168} else if (btn.getActionCommand().equals("Fail")) {169try {170cleanUp();171} catch (Exception ex) {172Logger.getLogger(ClickMenuTestManual.class173.getName()).log(Level.SEVERE, null, ex);174}175throw new AssertionError("Test case has failed");176177}178}179}180181private static void cleanUp() {182mainFrame.dispose();183}184185}186187188