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