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.*; 25 import java.awt.event.*; 26 import java.awt.image.BufferedImage; 27 28 /* 29 * @test 30 * @key headful 31 * @bug 7153700 32 * @summary Check for mouseMoved event for java.awt.TrayIcon 33 * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com) 34 * @library ../../../../lib/testlibrary ../ 35 * @build ExtendedRobot SystemTrayIconHelper 36 * @run main MouseMovedTest 37 */ 38 39 public class MouseMovedTest { 40 static volatile boolean moved; 41 42 public static void main(String[] args) throws Exception { 43 if (!SystemTray.isSupported()) { 44 return; 45 } 46 47 if (SystemTrayIconHelper.isOel7()) { 48 return; 49 } 50 51 moved = false; 52 53 TrayIcon icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), "Test icon"); 54 icon.addMouseMotionListener(new MouseMotionAdapter() { 55 public void mouseMoved(MouseEvent event) { 56 moved = true; 57 System.out.println("Mouse moved"); 58 } 59 }); 60 SystemTray.getSystemTray().add(icon); 61 62 ExtendedRobot robot = new ExtendedRobot(); 63 Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); 64 if (System.getProperty("os.name").toLowerCase().startsWith("win")) 65 robot.glide(size.width / 2, size.height-15, size.width, size.height-15, 1, 3); 66 else 67 robot.glide(size.width / 2, 13, size.width, 13, 1, 3); 68 robot.mouseMove(size.width/2, size.height/2); 69 70 if (!moved) 71 throw new RuntimeException("Mouse moved action did not trigger"); 72 } 73 }