1/* 2 * Copyright (c) 2014, 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 @bug 6284070 27 @summary Tests that ActionEvent is generated when a tray icon is double-clicked 28 @library ../../regtesthelpers 29 @build Sysout 30 @author artem.ananiev: area=awt.tray 31 @run applet/manual=yesno DblClickActionEventTest.html 32*/ 33 34import java.applet.*; 35 36import java.awt.*; 37import java.awt.event.*; 38import java.awt.image.*; 39 40import jdk.testlibrary.OSInfo; 41import test.java.awt.regtesthelpers.Sysout; 42 43public class DblClickActionEventTest extends Applet { 44 boolean traySupported; 45 46 public void init() { 47 this.setLayout(new BorderLayout()); 48 49 String[] instructions; 50 traySupported = SystemTray.isSupported(); 51 if (traySupported) { 52 String clickInstruction; 53 if (OSInfo.getOSType().equals(OSInfo.OSType.MACOSX)) { 54 clickInstruction = "right"; 55 } else { 56 clickInstruction = "left"; 57 } 58 instructions = new String[]{ 59 "When the test starts an icon is added to the SystemTray area.", 60 " Double-click on it with a " + clickInstruction + " button and make sure that", 61 " ACTION_PERFORMED event is sent to Java (all the clicks and", 62 " action events are shown below these instructions).", 63 "Then, if your system allows the tray icon to get focus (for", 64 " example, windows 2000 or windows XP), double-click on the", 65 " icon with SPACE button and single-click with RETURN button.", 66 " Both of them must also trigger ACTION_PERFORMED event.", 67 "If you see ACTION_PERFORMED events after each of your actions", 68 " (either mouse clicks or key presses), press PASS, else FAIL" 69 }; 70 } else { 71 instructions = new String[]{ 72 "The test cannot be run because SystemTray is not supported.", 73 "Simply press PASS button." 74 }; 75 } 76 Sysout.createDialogWithInstructions(instructions); 77 } 78 79 public void start() { 80 setSize(200, 200); 81 setVisible(true); 82 validate(); 83 84 if (!traySupported) { 85 return; 86 } 87 88 BufferedImage img = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); 89 Graphics g = img.createGraphics(); 90 g.setColor(Color.WHITE); 91 g.fillRect(0, 0, 32, 32); 92 g.setColor(Color.RED); 93 g.fillRect(6, 6, 20, 20); 94 g.dispose(); 95 96 SystemTray tray = SystemTray.getSystemTray(); 97 TrayIcon icon = new TrayIcon(img); 98 icon.setImageAutoSize(true); 99 icon.addActionListener(ev -> Sysout.println(ev.toString())); 100 icon.addMouseListener(new MouseAdapter() { 101 @Override 102 public void mouseClicked(MouseEvent ev) { 103 Sysout.println(ev.toString()); 104 } 105 } 106 ); 107 108 try { 109 tray.add(icon); 110 } catch (AWTException e) { 111 Sysout.println(e.toString()); 112 Sysout.println("!!! The test coudn't be performed !!!"); 113 } 114 } 115} 116 117