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 import java.awt.Point; 25 import java.awt.Robot; 26 import java.awt.event.FocusEvent; 27 import java.awt.event.FocusListener; 28 import java.awt.event.InputEvent; 29 import java.awt.event.MouseEvent; 30 import java.awt.event.MouseListener; 31 32 import javax.swing.JFrame; 33 import javax.swing.SwingUtilities; 34 35 /** 36 * @test 37 * @bug 8080405 38 * @run main/othervm/policy=java.policy -Djava.security.manager PropertyPermissionOnEDT 39 */ 40 public final class PropertyPermissionOnEDT { 41 42 public static void main(final String[] args) throws Exception { 43 SwingUtilities.invokeAndWait(PropertyPermissionOnEDT::test); 44 45 JFrame frame = new JFrame(); 46 frame.addMouseListener(new MouseListener() { 47 @Override 48 public void mouseClicked(final MouseEvent e) { 49 test(); 50 } 51 52 @Override 53 public void mousePressed(MouseEvent e) { 54 test(); 55 } 56 57 @Override 58 public void mouseReleased(MouseEvent e) { 59 test(); 60 } 61 62 @Override 63 public void mouseEntered(MouseEvent e) { 64 test(); 65 } 66 67 @Override 68 public void mouseExited(MouseEvent e) { 69 test(); 70 } 71 }); 72 frame.addFocusListener(new FocusListener() { 73 @Override 74 public void focusGained(FocusEvent e) { 75 test(); 76 } 77 78 @Override 79 public void focusLost(FocusEvent e) { 80 test(); 81 } 82 }); 83 frame.addMouseWheelListener(e -> test()); 84 frame.addWindowStateListener(e -> test()); 85 86 frame.setSize(100, 100); 87 frame.setLocationRelativeTo(null); 88 frame.setVisible(true); 89 Robot robot = new Robot(); 90 robot.setAutoWaitForIdle(true); 91 robot.setAutoDelay(100); 92 Point loc = frame.getLocationOnScreen(); 93 robot.mouseMove(loc.x + frame.getWidth() / 2, 94 loc.y + frame.getHeight() / 2); 95 robot.mousePress(InputEvent.BUTTON1_MASK); 96 robot.mouseRelease(InputEvent.BUTTON1_MASK); 97 robot.mouseWheel(100); 98 frame.dispose(); 99 } 100 101 private static void test() { 102 String property = System.getProperty("os.name"); 103 System.out.println("property = " + property); 104 } 105 }