author | pchelko |
Thu, 06 Mar 2014 12:18:31 +0400 | |
changeset 23623 | 72e320903ab9 |
child 26750 | d0d6c64a2e2b |
permissions | -rw-r--r-- |
23623
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
1 |
/* |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
4 |
* |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
8 |
* |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
13 |
* accompanied this code). |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
14 |
* |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
18 |
* |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
21 |
* questions. |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
22 |
*/ |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
23 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
24 |
/* |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
25 |
test |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
26 |
@bug 6284070 |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
27 |
@summary Tests that ActionEvent is generated when a tray icon is double-clicked |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
28 |
@library ../../regtesthelpers |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
29 |
@build Sysout |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
30 |
@author artem.ananiev: area=awt.tray |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
31 |
@run applet/manual=yesno DblClickActionEventTest.html |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
32 |
*/ |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
33 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
34 |
import java.applet.*; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
35 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
36 |
import java.awt.*; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
37 |
import java.awt.event.*; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
38 |
import java.awt.image.*; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
39 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
40 |
import sun.awt.OSInfo; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
41 |
import test.java.awt.regtesthelpers.Sysout; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
42 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
43 |
public class DblClickActionEventTest extends Applet { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
44 |
boolean traySupported; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
45 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
46 |
public void init() { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
47 |
this.setLayout(new BorderLayout()); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
48 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
49 |
String[] instructions; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
50 |
traySupported = SystemTray.isSupported(); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
51 |
if (traySupported) { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
52 |
String clickInstruction; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
53 |
if (OSInfo.getOSType().equals(OSInfo.OSType.MACOSX)) { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
54 |
clickInstruction = "right"; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
55 |
} else { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
56 |
clickInstruction = "left"; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
57 |
} |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
58 |
instructions = new String[]{ |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
59 |
"When the test starts an icon is added to the SystemTray area.", |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
60 |
" Double-click on it with a " + clickInstruction + " button and make sure that", |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
61 |
" ACTION_PERFORMED event is sent to Java (all the clicks and", |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
62 |
" action events are shown below these instructions).", |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
63 |
"Then, if your system allows the tray icon to get focus (for", |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
64 |
" example, windows 2000 or windows XP), double-click on the", |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
65 |
" icon with SPACE button and single-click with RETURN button.", |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
66 |
" Both of them must also trigger ACTION_PERFORMED event.", |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
67 |
"If you see ACTION_PERFORMED events after each of your actions", |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
68 |
" (either mouse clicks or key presses), press PASS, else FAIL" |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
69 |
}; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
70 |
} else { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
71 |
instructions = new String[]{ |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
72 |
"The test cannot be run because SystemTray is not supported.", |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
73 |
"Simply press PASS button." |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
74 |
}; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
75 |
} |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
76 |
Sysout.createDialogWithInstructions(instructions); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
77 |
} |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
78 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
79 |
public void start() { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
80 |
setSize(200, 200); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
81 |
setVisible(true); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
82 |
validate(); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
83 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
84 |
if (!traySupported) { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
85 |
return; |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
86 |
} |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
87 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
88 |
BufferedImage img = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
89 |
Graphics g = img.createGraphics(); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
90 |
g.setColor(Color.WHITE); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
91 |
g.fillRect(0, 0, 32, 32); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
92 |
g.setColor(Color.RED); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
93 |
g.fillRect(6, 6, 20, 20); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
94 |
g.dispose(); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
95 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
96 |
SystemTray tray = SystemTray.getSystemTray(); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
97 |
TrayIcon icon = new TrayIcon(img); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
98 |
icon.setImageAutoSize(true); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
99 |
icon.addActionListener(ev -> Sysout.println(ev.toString())); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
100 |
icon.addMouseListener(new MouseAdapter() { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
101 |
@Override |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
102 |
public void mouseClicked(MouseEvent ev) { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
103 |
Sysout.println(ev.toString()); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
104 |
} |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
105 |
} |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
106 |
); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
107 |
|
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
108 |
try { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
109 |
tray.add(icon); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
110 |
} catch (AWTException e) { |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
111 |
Sysout.println(e.toString()); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
112 |
Sysout.println("!!! The test coudn't be performed !!!"); |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
113 |
} |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
114 |
} |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
115 |
} |
72e320903ab9
7158615: [macosx] Some TrayIcon tests presume action trigger on BUTTON1
pchelko
parents:
diff
changeset
|
116 |