Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
5ef7f5c0
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看板
提交
5ef7f5c0
编写于
1月 27, 2012
作者:
A
alexsch
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7105040: [macosx] closed/javax/swing/JPopupMenu/4966112/bug4966112.java deadlocks on MacOS
Reviewed-by: rupashka
上级
d1abdf68
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
312 addition
and
0 deletion
+312
-0
test/javax/swing/JPopupMenu/4966112/bug4966112.java
test/javax/swing/JPopupMenu/4966112/bug4966112.java
+312
-0
未找到文件。
test/javax/swing/JPopupMenu/4966112/bug4966112.java
0 → 100644
浏览文件 @
5ef7f5c0
/*
* Copyright (c) 2011, 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 4966112
* @summary Some Composite components does not show the Context Popup.
* @library ../../regtesthelpers
* @build Util
* @author Alexander Zuev
* @run main bug4966112
*/
import
javax.swing.*
;
import
javax.swing.event.PopupMenuListener
;
import
javax.swing.event.PopupMenuEvent
;
import
java.awt.*
;
import
java.awt.event.*
;
import
sun.awt.SunToolkit
;
public
class
bug4966112
{
private
static
final
int
NO_MOUSE_BUTTON
=
-
1
;
private
static
volatile
boolean
shown
=
false
;
private
static
volatile
int
popupButton
=
NO_MOUSE_BUTTON
;
private
static
volatile
JButton
testButton
;
private
static
volatile
JSplitPane
jsp
;
private
static
volatile
JSpinner
spin
;
private
static
volatile
JFileChooser
filec
;
private
static
int
buttonMask
;
private
static
Robot
robot
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SunToolkit
toolkit
=
(
SunToolkit
)
Toolkit
.
getDefaultToolkit
();
robot
=
new
Robot
();
robot
.
setAutoDelay
(
100
);
createAndShowButton
();
toolkit
.
realSync
();
setClickPoint
(
testButton
);
clickMouse
(
InputEvent
.
BUTTON1_MASK
);
clickMouse
(
InputEvent
.
BUTTON2_MASK
);
clickMouse
(
InputEvent
.
BUTTON3_MASK
);
toolkit
.
realSync
();
closeFrame
();
if
(
popupButton
==
NO_MOUSE_BUTTON
)
{
System
.
out
.
println
(
"Test can't identify the popup trigger button. Test skipped"
);
return
;
}
setButtonMask
();
// Test Split Pane
createAndShowSplitPane
();
toolkit
.
realSync
();
clickMouse
(
jsp
);
toolkit
.
realSync
();
closeFrame
();
if
(!
shown
)
{
throw
new
RuntimeException
(
"Popup was not shown on splitpane"
);
}
// Test Spinner
createAndShowSpinner
();
toolkit
.
realSync
();
clickMouse
(
spin
);
toolkit
.
realSync
();
closeFrame
();
if
(!
shown
)
{
throw
new
RuntimeException
(
"Popup was not shown on spinner"
);
}
// Test File Chooser
createAndShowFileChooser
();
toolkit
.
realSync
();
clickMouse
(
filec
);
toolkit
.
realSync
();
Util
.
hitKeys
(
robot
,
KeyEvent
.
VK_ESCAPE
);
toolkit
.
realSync
();
Util
.
hitKeys
(
robot
,
KeyEvent
.
VK_ESCAPE
);
toolkit
.
realSync
();
closeFrame
();
if
(!
shown
)
{
throw
new
RuntimeException
(
"Popup was not shown on filechooser"
);
}
}
private
static
void
clickMouse
(
JComponent
c
)
throws
Exception
{
setClickPoint
(
c
);
clickMouse
(
buttonMask
);
}
private
static
void
clickMouse
(
int
buttons
)
{
robot
.
mousePress
(
buttons
);
robot
.
mouseRelease
(
buttons
);
}
private
static
void
setButtonMask
()
{
switch
(
popupButton
)
{
case
MouseEvent
.
BUTTON1
:
buttonMask
=
InputEvent
.
BUTTON1_MASK
;
break
;
case
MouseEvent
.
BUTTON2
:
buttonMask
=
InputEvent
.
BUTTON2_MASK
;
break
;
case
MouseEvent
.
BUTTON3
:
buttonMask
=
InputEvent
.
BUTTON3_MASK
;
break
;
}
}
private
static
void
setClickPoint
(
final
JComponent
c
)
throws
Exception
{
final
Point
[]
result
=
new
Point
[
1
];
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
Point
p
=
c
.
getLocationOnScreen
();
Dimension
size
=
c
.
getSize
();
result
[
0
]
=
new
Point
(
p
.
x
+
size
.
width
/
2
,
p
.
y
+
size
.
height
/
2
);
}
});
robot
.
mouseMove
(
result
[
0
].
x
,
result
[
0
].
y
);
}
private
static
JPopupMenu
createJPopupMenu
()
{
JPopupMenu
jpm
=
new
JPopupMenu
();
jpm
.
add
(
"One"
);
jpm
.
add
(
"Two"
);
jpm
.
add
(
"Three"
);
jpm
.
addPopupMenuListener
(
new
PopupMenuListener
()
{
public
void
popupMenuWillBecomeVisible
(
PopupMenuEvent
e
)
{
shown
=
true
;
}
public
void
popupMenuWillBecomeInvisible
(
PopupMenuEvent
e
)
{
}
public
void
popupMenuCanceled
(
PopupMenuEvent
e
)
{
}
});
AutoClosable
.
INSTANCE
.
setPopup
(
jpm
);
return
jpm
;
}
private
static
void
createAndShowButton
()
throws
Exception
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
JFrame
frame
=
new
JFrame
(
"Button Frame"
);
frame
.
setLayout
(
new
BorderLayout
());
testButton
=
new
JButton
(
"Popup Tester"
);
testButton
.
addMouseListener
(
new
MouseAdapter
()
{
void
setPopupTrigger
(
MouseEvent
e
)
{
if
(
e
.
isPopupTrigger
())
{
popupButton
=
e
.
getButton
();
}
}
public
void
mouseClicked
(
MouseEvent
e
)
{
setPopupTrigger
(
e
);
}
public
void
mousePressed
(
MouseEvent
e
)
{
setPopupTrigger
(
e
);
}
public
void
mouseReleased
(
MouseEvent
e
)
{
setPopupTrigger
(
e
);
}
});
frame
.
add
(
testButton
,
BorderLayout
.
CENTER
);
frame
.
pack
();
frame
.
setVisible
(
true
);
AutoClosable
.
INSTANCE
.
setFrame
(
frame
);
}
});
}
private
static
void
createAndShowSplitPane
()
throws
Exception
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
JFrame
frame
=
new
JFrame
(
"Test SplitPane"
);
frame
.
setSize
(
250
,
200
);
frame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
frame
.
setLayout
(
new
BorderLayout
());
shown
=
false
;
jsp
=
new
JSplitPane
();
jsp
.
setRightComponent
(
new
JPanel
());
jsp
.
setLeftComponent
(
new
JPanel
());
jsp
.
setComponentPopupMenu
(
createJPopupMenu
());
frame
.
add
(
jsp
,
BorderLayout
.
CENTER
);
jsp
.
setDividerLocation
(
150
);
frame
.
setLocation
(
400
,
300
);
frame
.
setVisible
(
true
);
AutoClosable
.
INSTANCE
.
setFrame
(
frame
);
}
});
}
private
static
void
createAndShowSpinner
()
throws
Exception
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
JFrame
frame
=
new
JFrame
(
"JSpinner Test"
);
frame
.
setLayout
(
new
BorderLayout
());
frame
.
setSize
(
200
,
100
);
shown
=
false
;
spin
=
new
JSpinner
();
spin
.
setComponentPopupMenu
(
createJPopupMenu
());
frame
.
add
(
spin
,
BorderLayout
.
CENTER
);
frame
.
setVisible
(
true
);
AutoClosable
.
INSTANCE
.
setFrame
(
frame
);
}
});
}
private
static
void
createAndShowFileChooser
()
throws
Exception
{
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
@Override
public
void
run
()
{
JFrame
frame
=
new
JFrame
(
"FileChooser test dialog"
);
frame
.
setSize
(
100
,
100
);
shown
=
false
;
filec
=
new
JFileChooser
();
filec
.
setComponentPopupMenu
(
createJPopupMenu
());
filec
.
showOpenDialog
(
frame
);
frame
.
setVisible
(
true
);
AutoClosable
.
INSTANCE
.
setFrame
(
frame
);
}
});
}
private
static
void
closeFrame
()
{
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
@Override
public
void
run
()
{
AutoClosable
.
INSTANCE
.
close
();
}
});
}
private
static
class
AutoClosable
{
static
final
AutoClosable
INSTANCE
=
new
AutoClosable
();
private
JFrame
frame
;
private
JPopupMenu
popup
;
public
void
setFrame
(
JFrame
frame
)
{
this
.
frame
=
frame
;
}
public
void
setPopup
(
JPopupMenu
popup
)
{
this
.
popup
=
popup
;
}
public
void
close
()
{
frame
.
dispose
();
if
(
popup
!=
null
)
{
popup
.
setVisible
(
false
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录