1 /* 2 * Copyright (c) 2015, 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 /** 25 * @test 26 * @key headful 27 * @bug 8158230 28 * @summary Verify menu item option apple.laf.useScreenMenuBar implementation 29 * @requires (os.family=="mac") 30 * @run main ClickMenuTestManual 31 */ 32 33 import java.awt.Color; 34 import java.awt.GridBagConstraints; 35 import java.awt.GridBagLayout; 36 import java.awt.event.ActionEvent; 37 import java.awt.event.ActionListener; 38 import java.util.logging.Level; 39 import java.util.logging.Logger; 40 import javax.swing.BorderFactory; 41 import javax.swing.JButton; 42 import javax.swing.JFrame; 43 import javax.swing.JMenu; 44 import javax.swing.JMenuBar; 45 import javax.swing.JMenuItem; 46 import javax.swing.JPanel; 47 import javax.swing.JTextArea; 48 import static javax.swing.WindowConstants.EXIT_ON_CLOSE; 49 50 public class ClickMenuTestManual implements 51 ActionListener { 52 53 public static final String TEST_STRING = "STRING"; 54 55 private static GridBagLayout layout; 56 private static JPanel mainControlPanel; 57 private static JPanel instructionPanel; 58 private static JPanel testPanel; 59 60 private static JPanel resultButtonPanel; 61 private static JPanel controlPanel; 62 private static JTextArea instructionTextArea; 63 private static JTextArea testTextArea; 64 private static JButton passButton; 65 private static JButton failButton; 66 private static JMenu menu; 67 private static JMenuBar menuBar; 68 private static JMenuItem menuItem; 69 private static JFrame mainFrame; 70 71 public static void main(String[] args) throws Exception { 72 System.setProperty("apple.laf.useScreenMenuBar", "true"); 73 ClickMenuTestManual test 74 = new ClickMenuTestManual(); 75 } 76 77 public ClickMenuTestManual() throws Exception { 78 createControlPanelUI(); 79 } 80 81 public final void createControlPanelUI() throws Exception { 82 layout = new GridBagLayout(); 83 mainControlPanel = new JPanel(layout); 84 instructionPanel = new JPanel(layout); 85 testPanel = new JPanel(layout); 86 resultButtonPanel = new JPanel(layout); 87 controlPanel = new JPanel(layout); 88 89 GridBagConstraints gbc = new GridBagConstraints(); 90 String instructions 91 = "1) Click on MENU using mouse " 92 + "\n2) Click on MENU ITEM using mouse " 93 + "\n3) Check output on textArea if equal to STRING " 94 + "\n\n If correct string, press \"Pass\" " 95 + "\n Otherwise, press \"Fail\" "; 96 instructionTextArea = new JTextArea(); 97 instructionTextArea.setText(instructions); 98 instructionTextArea.setEnabled(false); 99 instructionTextArea.setDisabledTextColor(Color.black); 100 instructionTextArea.setBackground(Color.white); 101 instructionTextArea.setBorder( 102 BorderFactory.createLineBorder(Color.black)); 103 gbc.gridx = 0; 104 gbc.gridy = 0; 105 gbc.fill = GridBagConstraints.HORIZONTAL; 106 instructionPanel.add(instructionTextArea, gbc); 107 testTextArea = new JTextArea(); 108 testTextArea.setEnabled(true); 109 testTextArea.setDisabledTextColor(Color.black); 110 testTextArea.setBackground(Color.white); 111 testTextArea.setBorder( 112 BorderFactory.createLineBorder(Color.black)); 113 gbc.gridx = 0; 114 gbc.gridy = 0; 115 gbc.fill = GridBagConstraints.HORIZONTAL; 116 testPanel.add(testTextArea, gbc); 117 passButton = new JButton("Pass"); 118 passButton.setActionCommand("Pass"); 119 passButton.addActionListener(this); 120 failButton = new JButton("Fail"); 121 failButton.setActionCommand("Fail"); 122 failButton.addActionListener(this); 123 gbc.gridx = 0; 124 gbc.gridy = 0; 125 resultButtonPanel.add(passButton, gbc); 126 gbc.gridx = 1; 127 gbc.gridy = 0; 128 resultButtonPanel.add(failButton, gbc); 129 gbc.gridx = 0; 130 gbc.gridy = 0; 131 mainControlPanel.add(instructionPanel, gbc); 132 gbc.gridx = 0; 133 gbc.gridy = 1; 134 mainControlPanel.add(testPanel, gbc); 135 gbc.gridx = 0; 136 gbc.gridy = 2; 137 mainControlPanel.add(resultButtonPanel, gbc); 138 gbc.gridx = 0; 139 gbc.gridy = 3; 140 mainControlPanel.add(controlPanel, gbc); 141 mainFrame = new JFrame("Control Panel"); 142 mainFrame.add(mainControlPanel); 143 menuBar = new JMenuBar(); 144 menu = new JMenu("MENU"); 145 menuItem = new JMenuItem("MENU ITEM"); 146 menuItem.addActionListener((e) -> { 147 testTextArea.setText(TEST_STRING); 148 }); 149 menu.add(menuItem); 150 menuBar.add(menu); 151 mainFrame.setJMenuBar(menuBar); 152 mainFrame.pack(); 153 mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE); 154 mainFrame.setVisible(true); 155 156 } 157 158 @Override 159 public void actionPerformed(ActionEvent evt) { 160 if (evt.getSource() instanceof JButton) { 161 JButton btn = (JButton) evt.getSource(); 162 if (btn.getActionCommand().equals("Pass")) { 163 try { 164 cleanUp(); 165 } catch (Exception ex) { 166 Logger.getLogger(ClickMenuTestManual.class 167 .getName()).log(Level.SEVERE, null, ex); 168 } 169 } else if (btn.getActionCommand().equals("Fail")) { 170 try { 171 cleanUp(); 172 } catch (Exception ex) { 173 Logger.getLogger(ClickMenuTestManual.class 174 .getName()).log(Level.SEVERE, null, ex); 175 } 176 throw new AssertionError("Test case has failed"); 177 178 } 179 } 180 } 181 182 private static void cleanUp() { 183 mainFrame.dispose(); 184 } 185 186 }