Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
7bc9ae5f
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7bc9ae5f
编写于
3月 12, 2014
作者:
P
pchelko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8007220: [macosx] Setting popupmenu on TrayIcon do not work if done *after* adding TrayIcon
Reviewed-by: anthony, serb
上级
36307640
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
312 addition
and
2 deletion
+312
-2
src/macosx/classes/sun/lwawt/macosx/CTrayIcon.java
src/macosx/classes/sun/lwawt/macosx/CTrayIcon.java
+12
-2
test/java/awt/TrayIcon/AddPopupAfterShowTest/AddPopupAfterShowTest.html
...TrayIcon/AddPopupAfterShowTest/AddPopupAfterShowTest.html
+45
-0
test/java/awt/TrayIcon/AddPopupAfterShowTest/AddPopupAfterShowTest.java
...TrayIcon/AddPopupAfterShowTest/AddPopupAfterShowTest.java
+106
-0
test/java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java
...ava/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java
+149
-0
未找到文件。
src/macosx/classes/sun/lwawt/macosx/CTrayIcon.java
浏览文件 @
7bc9ae5f
...
...
@@ -76,8 +76,9 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer {
menuPeer
=
(
CPopupMenu
)
popup
.
getPeer
();
if
(
menuPeer
==
null
)
{
popup
.
addNotify
();
menuPeer
=
(
CPopupMenu
)
popup
.
getPeer
();
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
...
...
@@ -97,7 +98,12 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer {
//invocation from the AWTTrayIcon.m
public
long
getPopupMenuModel
(){
if
(
popup
==
null
)
{
return
0L
;
PopupMenu
popupMenu
=
target
.
getPopupMenu
();
if
(
popupMenu
!=
null
)
{
popup
=
popupMenu
;
}
else
{
return
0L
;
}
}
return
checkAndCreatePopupPeer
().
getModel
();
}
...
...
@@ -134,6 +140,10 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer {
dummyFrame
.
dispose
();
if
(
popup
!=
null
)
{
popup
.
removeNotify
();
}
LWCToolkit
.
targetDisposedPeer
(
target
,
this
);
target
=
null
;
...
...
test/java/awt/TrayIcon/AddPopupAfterShowTest/AddPopupAfterShowTest.html
0 → 100644
浏览文件 @
7bc9ae5f
<!--
Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<html>
<!--
@test
@bug 8007220
@summary The popup menu is not added to the tray icon after it was added to tray
@author Petr Pchelko
@library ../../regtesthelpers
@build Sysout
@run applet/manual=yesno AddPopupAfterShowTest.html
-->
<head>
<title>
AddPopupAfterShowTest
</title>
</head>
<body>
<h1>
AddPopupAfterShowTest
<br>
Bug ID: 8007220
</h1>
<p>
See the dialog box (usually in upper left corner) for instructions
</p>
<APPLET
CODE=
"AddPopupAfterShowTest.class"
WIDTH=
200
HEIGHT=
200
></APPLET>
</body>
</html>
test/java/awt/TrayIcon/AddPopupAfterShowTest/AddPopupAfterShowTest.java
0 → 100644
浏览文件 @
7bc9ae5f
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
test.java.awt.regtesthelpers.Sysout
;
import
java.applet.Applet
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
public
class
AddPopupAfterShowTest
extends
Applet
{
@Override
public
void
init
()
{
if
(!
SystemTray
.
isSupported
())
{
Sysout
.
createDialogWithInstructions
(
new
String
[]{
"Press PASS, the System Tray is not supported"
});
return
;
}
String
[]
instructions
=
{
"1) The red circle icon was added to the system tray."
,
"2) Check that a popup menu is opened when the icon is clicked."
,
"3) If true the test is passed, otherwise failed."
};
Sysout
.
createDialogWithInstructions
(
instructions
);
}
@Override
public
void
start
()
{
setSize
(
200
,
200
);
show
();
createSystemTrayIcon
();
}
private
static
void
createSystemTrayIcon
()
{
final
TrayIcon
trayIcon
=
new
TrayIcon
(
createTrayIconImage
());
trayIcon
.
setImageAutoSize
(
true
);
try
{
// Add tray icon to system tray *before* adding popup menu to demonstrate buggy behaviour
SystemTray
.
getSystemTray
().
add
(
trayIcon
);
trayIcon
.
setPopupMenu
(
createTrayIconPopupMenu
());
}
catch
(
final
AWTException
awte
)
{
awte
.
printStackTrace
();
}
}
private
static
Image
createTrayIconImage
()
{
/**
* Create a small image of a red circle to use as the icon for the tray icon
*/
int
trayIconImageSize
=
32
;
final
BufferedImage
trayImage
=
new
BufferedImage
(
trayIconImageSize
,
trayIconImageSize
,
BufferedImage
.
TYPE_INT_ARGB
);
final
Graphics2D
trayImageGraphics
=
(
Graphics2D
)
trayImage
.
getGraphics
();
trayImageGraphics
.
setRenderingHint
(
RenderingHints
.
KEY_ANTIALIASING
,
RenderingHints
.
VALUE_ANTIALIAS_ON
);
trayImageGraphics
.
setColor
(
new
Color
(
255
,
255
,
255
,
0
));
trayImageGraphics
.
fillRect
(
0
,
0
,
trayImage
.
getWidth
(),
trayImage
.
getHeight
());
trayImageGraphics
.
setColor
(
Color
.
red
);
int
trayIconImageInset
=
4
;
trayImageGraphics
.
fillOval
(
trayIconImageInset
,
trayIconImageInset
,
trayImage
.
getWidth
()
-
2
*
trayIconImageInset
,
trayImage
.
getHeight
()
-
2
*
trayIconImageInset
);
trayImageGraphics
.
setColor
(
Color
.
darkGray
);
trayImageGraphics
.
drawOval
(
trayIconImageInset
,
trayIconImageInset
,
trayImage
.
getWidth
()
-
2
*
trayIconImageInset
,
trayImage
.
getHeight
()
-
2
*
trayIconImageInset
);
return
trayImage
;
}
private
static
PopupMenu
createTrayIconPopupMenu
()
{
final
PopupMenu
trayIconPopupMenu
=
new
PopupMenu
();
final
MenuItem
popupMenuItem
=
new
MenuItem
(
"TEST PASSED!"
);
trayIconPopupMenu
.
add
(
popupMenuItem
);
return
trayIconPopupMenu
;
}
}
test/java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java
0 → 100644
浏览文件 @
7bc9ae5f
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 8007220
@summary Reference to the popup leaks after the TrayIcon is removed
@author Petr Pchelko
@run main/othervm -Xmx50m PopupMenuLeakTest
*/
import
java.awt.*
;
import
javax.swing.SwingUtilities
;
import
sun.awt.SunToolkit
;
import
java.awt.image.BufferedImage
;
import
java.lang.ref.WeakReference
;
import
java.util.ArrayList
;
import
java.util.concurrent.atomic.AtomicReference
;
public
class
PopupMenuLeakTest
{
static
final
AtomicReference
<
WeakReference
<
TrayIcon
>>
iconWeakReference
=
new
AtomicReference
<>();
static
final
AtomicReference
<
WeakReference
<
PopupMenu
>>
popupWeakReference
=
new
AtomicReference
<>();
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SwingUtilities
.
invokeAndWait
(
PopupMenuLeakTest:
:
createSystemTrayIcon
);
sleep
();
// To make the test automatic we explicitly call addNotify on a popup to create the peer
SwingUtilities
.
invokeAndWait
(
PopupMenuLeakTest:
:
addNotifyPopup
);
sleep
();
SwingUtilities
.
invokeAndWait
(
PopupMenuLeakTest:
:
removeIcon
);
sleep
();
assertCollected
(
popupWeakReference
.
get
(),
"Failed, reference to popup not collected"
);
assertCollected
(
iconWeakReference
.
get
(),
"Failed, reference to tray icon not collected"
);
}
private
static
void
addNotifyPopup
()
{
PopupMenu
menu
=
popupWeakReference
.
get
().
get
();
if
(
menu
==
null
)
{
throw
new
RuntimeException
(
"Failed: popup collected too early"
);
}
menu
.
addNotify
();
}
private
static
void
removeIcon
()
{
TrayIcon
icon
=
iconWeakReference
.
get
().
get
();
if
(
icon
==
null
)
{
throw
new
RuntimeException
(
"Failed: TrayIcon collected too early"
);
}
SystemTray
.
getSystemTray
().
remove
(
icon
);
}
private
static
void
assertCollected
(
WeakReference
<?>
reference
,
String
message
)
{
java
.
util
.
List
<
byte
[]>
bytes
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
try
{
while
(
true
)
{
bytes
.
add
(
new
byte
[
1024
]);
}
}
catch
(
OutOfMemoryError
err
)
{
bytes
=
new
ArrayList
<>();
}
}
if
(
reference
.
get
()
!=
null
)
{
throw
new
RuntimeException
(
message
);
}
}
private
static
void
createSystemTrayIcon
()
{
final
TrayIcon
trayIcon
=
new
TrayIcon
(
createTrayIconImage
());
trayIcon
.
setImageAutoSize
(
true
);
try
{
// Add tray icon to system tray *before* adding popup menu to demonstrate buggy behaviour
trayIcon
.
setPopupMenu
(
createTrayIconPopupMenu
());
SystemTray
.
getSystemTray
().
add
(
trayIcon
);
iconWeakReference
.
set
(
new
WeakReference
<>(
trayIcon
));
popupWeakReference
.
set
(
new
WeakReference
<>(
trayIcon
.
getPopupMenu
()));
}
catch
(
final
AWTException
awte
)
{
awte
.
printStackTrace
();
}
}
private
static
Image
createTrayIconImage
()
{
/**
* Create a small image of a red circle to use as the icon for the tray icon
*/
int
trayIconImageSize
=
32
;
final
BufferedImage
trayImage
=
new
BufferedImage
(
trayIconImageSize
,
trayIconImageSize
,
BufferedImage
.
TYPE_INT_ARGB
);
final
Graphics2D
trayImageGraphics
=
(
Graphics2D
)
trayImage
.
getGraphics
();
trayImageGraphics
.
setRenderingHint
(
RenderingHints
.
KEY_ANTIALIASING
,
RenderingHints
.
VALUE_ANTIALIAS_ON
);
trayImageGraphics
.
setColor
(
new
Color
(
255
,
255
,
255
,
0
));
trayImageGraphics
.
fillRect
(
0
,
0
,
trayImage
.
getWidth
(),
trayImage
.
getHeight
());
trayImageGraphics
.
setColor
(
Color
.
red
);
int
trayIconImageInset
=
4
;
trayImageGraphics
.
fillOval
(
trayIconImageInset
,
trayIconImageInset
,
trayImage
.
getWidth
()
-
2
*
trayIconImageInset
,
trayImage
.
getHeight
()
-
2
*
trayIconImageInset
);
trayImageGraphics
.
setColor
(
Color
.
darkGray
);
trayImageGraphics
.
drawOval
(
trayIconImageInset
,
trayIconImageInset
,
trayImage
.
getWidth
()
-
2
*
trayIconImageInset
,
trayImage
.
getHeight
()
-
2
*
trayIconImageInset
);
return
trayImage
;
}
private
static
PopupMenu
createTrayIconPopupMenu
()
{
final
PopupMenu
trayIconPopupMenu
=
new
PopupMenu
();
final
MenuItem
popupMenuItem
=
new
MenuItem
(
"TEST!"
);
trayIconPopupMenu
.
add
(
popupMenuItem
);
return
trayIconPopupMenu
;
}
private
static
void
sleep
()
{
((
SunToolkit
)
Toolkit
.
getDefaultToolkit
()).
realSync
();
try
{
Thread
.
sleep
(
100
);
}
catch
(
InterruptedException
ignored
)
{
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录