Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
f09adb35
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f09adb35
编写于
2月 13, 2013
作者:
V
vkarnauk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
4199622: RFE: JComboBox shouldn't sending ActionEvents for keyboard navigation
Reviewed-by: alexp, alexsch
上级
175454e9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
290 addition
and
19 deletion
+290
-19
src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java
...share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java
+45
-18
src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java
...hare/classes/javax/swing/plaf/basic/BasicLookAndFeel.java
+2
-1
test/javax/swing/JComboBox/4199622/bug4199622.java
test/javax/swing/JComboBox/4199622/bug4199622.java
+243
-0
未找到文件。
src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java
浏览文件 @
f09adb35
/*
* Copyright (c) 1997, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 201
3
, 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
...
...
@@ -1120,7 +1120,9 @@ public class BasicComboBoxUI extends ComboBoxUI {
listBox
.
setSelectedIndex
(
si
+
1
);
listBox
.
ensureIndexIsVisible
(
si
+
1
);
if
(
!
isTableCellEditor
)
{
comboBox
.
setSelectedIndex
(
si
+
1
);
if
(!(
UIManager
.
getBoolean
(
"ComboBox.noActionOnKeyNavigation"
)
&&
comboBox
.
isPopupVisible
()))
{
comboBox
.
setSelectedIndex
(
si
+
1
);
}
}
comboBox
.
repaint
();
}
...
...
@@ -1144,7 +1146,9 @@ public class BasicComboBoxUI extends ComboBoxUI {
listBox
.
setSelectedIndex
(
si
-
1
);
listBox
.
ensureIndexIsVisible
(
si
-
1
);
if
(
!
isTableCellEditor
)
{
comboBox
.
setSelectedIndex
(
si
-
1
);
if
(!(
UIManager
.
getBoolean
(
"ComboBox.noActionOnKeyNavigation"
)
&&
comboBox
.
isPopupVisible
()))
{
comboBox
.
setSelectedIndex
(
si
-
1
);
}
}
comboBox
.
repaint
();
}
...
...
@@ -1490,7 +1494,13 @@ public class BasicComboBoxUI extends ComboBoxUI {
key
==
HOME
||
key
==
END
)
{
int
index
=
getNextIndex
(
comboBox
,
key
);
if
(
index
>=
0
&&
index
<
comboBox
.
getItemCount
())
{
comboBox
.
setSelectedIndex
(
index
);
if
(
UIManager
.
getBoolean
(
"ComboBox.noActionOnKeyNavigation"
)
&&
comboBox
.
isPopupVisible
())
{
ui
.
listBox
.
setSelectedIndex
(
index
);
ui
.
listBox
.
ensureIndexIsVisible
(
index
);
comboBox
.
repaint
();
}
else
{
comboBox
.
setSelectedIndex
(
index
);
}
}
}
else
if
(
key
==
DOWN
)
{
...
...
@@ -1558,22 +1568,33 @@ public class BasicComboBoxUI extends ComboBoxUI {
else
if
(
key
==
ENTER
)
{
if
(
comboBox
.
isPopupVisible
())
{
// Forces the selection of the list item
boolean
isEnterSelectablePopup
=
UIManager
.
getBoolean
(
"ComboBox.isEnterSelectablePopup"
);
if
(!
comboBox
.
isEditable
()
||
isEnterSelectablePopup
||
ui
.
isTableCellEditor
)
{
// If ComboBox.noActionOnKeyNavigation is set,
// forse selection of list item
if
(
UIManager
.
getBoolean
(
"ComboBox.noActionOnKeyNavigation"
))
{
Object
listItem
=
ui
.
popup
.
getList
().
getSelectedValue
();
if
(
listItem
!=
null
)
{
// Use the selected value from popup
// to set the selected item in combo box,
// but ensure before that JComboBox.actionPerformed()
// won't use editor's value to set the selected item
comboBox
.
getEditor
().
setItem
(
listItem
);
comboBox
.
setSelectedItem
(
listItem
);
}
comboBox
.
setPopupVisible
(
false
);
}
else
{
// Forces the selection of the list item
boolean
isEnterSelectablePopup
=
UIManager
.
getBoolean
(
"ComboBox.isEnterSelectablePopup"
);
if
(!
comboBox
.
isEditable
()
||
isEnterSelectablePopup
||
ui
.
isTableCellEditor
)
{
Object
listItem
=
ui
.
popup
.
getList
().
getSelectedValue
();
if
(
listItem
!=
null
)
{
// Use the selected value from popup
// to set the selected item in combo box,
// but ensure before that JComboBox.actionPerformed()
// won't use editor's value to set the selected item
comboBox
.
getEditor
().
setItem
(
listItem
);
comboBox
.
setSelectedItem
(
listItem
);
}
}
comboBox
.
setPopupVisible
(
false
);
}
comboBox
.
setPopupVisible
(
false
);
}
else
{
// Hide combo box if it is a table cell editor
...
...
@@ -1604,14 +1625,20 @@ public class BasicComboBoxUI extends ComboBoxUI {
}
private
int
getNextIndex
(
JComboBox
comboBox
,
String
key
)
{
int
listHeight
=
comboBox
.
getMaximumRowCount
();
int
selectedIndex
=
comboBox
.
getSelectedIndex
();
if
(
UIManager
.
getBoolean
(
"ComboBox.noActionOnKeyNavigation"
)
&&
(
comboBox
.
getUI
()
instanceof
BasicComboBoxUI
))
{
selectedIndex
=
((
BasicComboBoxUI
)
comboBox
.
getUI
()).
listBox
.
getSelectedIndex
();
}
if
(
key
==
PAGE_UP
)
{
int
listHeight
=
comboBox
.
getMaximumRowCount
();
int
index
=
comboBox
.
getSelectedIndex
()
-
listHeight
;
int
index
=
selectedIndex
-
listHeight
;
return
(
index
<
0
?
0
:
index
);
}
else
if
(
key
==
PAGE_DOWN
)
{
int
listHeight
=
comboBox
.
getMaximumRowCount
();
int
index
=
comboBox
.
getSelectedIndex
()
+
listHeight
;
int
index
=
selectedIndex
+
listHeight
;
int
max
=
comboBox
.
getItemCount
();
return
(
index
<
max
?
index:
max
-
1
);
}
...
...
src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java
浏览文件 @
f09adb35
/*
* Copyright (c) 1997, 201
0
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 201
3
, 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
...
...
@@ -861,6 +861,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel implements Serializab
"END"
,
"endPassThrough"
,
"ENTER"
,
"enterPressed"
}),
"ComboBox.noActionOnKeyNavigation"
,
Boolean
.
FALSE
,
// *** FileChooser
...
...
test/javax/swing/JComboBox/4199622/bug4199622.java
0 → 100644
浏览文件 @
f09adb35
/*
* 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 4199622
@summary RFE: JComboBox shouldn't send ActionEvents for keyboard navigation
@author Vladislav Karnaukhov
@run main bug4199622
*/
import
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
;
import
sun.awt.OSInfo
;
import
sun.awt.SunToolkit
;
import
javax.swing.*
;
import
javax.swing.plaf.metal.MetalLookAndFeel
;
import
java.awt.*
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.awt.event.KeyEvent
;
import
java.lang.reflect.InvocationTargetException
;
public
class
bug4199622
extends
JFrame
implements
ActionListener
{
static
final
int
nElems
=
20
;
static
JComboBox
<
String
>
cb
=
null
;
bug4199622
(
LookAndFeel
laf
)
{
super
();
try
{
UIManager
.
setLookAndFeel
(
laf
);
}
catch
(
UnsupportedLookAndFeelException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
setDefaultCloseOperation
(
DISPOSE_ON_CLOSE
);
cb
=
new
JComboBox
<>();
for
(
int
i
=
0
;
i
<
nElems
;
i
++)
{
cb
.
addItem
(
String
.
valueOf
(
i
+
1
));
}
cb
.
addActionListener
(
this
);
add
(
cb
);
setSize
(
300
,
300
);
pack
();
}
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
if
(
UIManager
.
getBoolean
(
"ComboBox.noActionOnKeyNavigation"
)
&&
cb
.
isPopupVisible
())
{
throw
new
RuntimeException
(
"Test failed. actionPerformed generated"
);
}
}
static
Robot
robot
=
null
;
static
SunToolkit
toolkit
=
null
;
static
void
doTest
()
{
if
(
robot
==
null
)
{
try
{
robot
=
new
Robot
();
robot
.
setAutoDelay
(
20
);
}
catch
(
AWTException
e
)
{
throw
new
RuntimeException
(
"Can't create robot. Test failed"
,
e
);
}
}
toolkit
=
(
SunToolkit
)
Toolkit
.
getDefaultToolkit
();
if
(
toolkit
==
null
)
{
throw
new
RuntimeException
(
"Can't get the toolkit. Test failed"
);
}
toolkit
.
realSync
();
doActualTest
();
try
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
cb
.
hidePopup
();
cb
.
setEditable
(
true
);
cb
.
updateUI
();
}
});
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
toolkit
.
realSync
();
doActualTest
();
}
static
void
doActualTest
()
{
UIManager
.
put
(
"ComboBox.noActionOnKeyNavigation"
,
true
);
doTestUpDown
();
UIManager
.
put
(
"ComboBox.noActionOnKeyNavigation"
,
false
);
doTestUpDown
();
UIManager
.
put
(
"ComboBox.noActionOnKeyNavigation"
,
true
);
doTestPgUpDown
();
UIManager
.
put
(
"ComboBox.noActionOnKeyNavigation"
,
false
);
doTestPgUpDown
();
UIManager
.
put
(
"ComboBox.noActionOnKeyNavigation"
,
true
);
doTestHomeEnd
();
UIManager
.
put
(
"ComboBox.noActionOnKeyNavigation"
,
false
);
doTestHomeEnd
();
}
static
void
doTestHomeEnd
()
{
try
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
cb
.
hidePopup
();
cb
.
setSelectedIndex
(
0
);
}
});
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
toolkit
.
realSync
();
robot
.
keyPress
(
KeyEvent
.
VK_END
);
toolkit
.
realSync
();
robot
.
keyPress
(
KeyEvent
.
VK_HOME
);
toolkit
.
realSync
();
}
static
void
doTestUpDown
()
{
try
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
cb
.
hidePopup
();
cb
.
setSelectedIndex
(
0
);
}
});
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
toolkit
.
realSync
();
for
(
int
i
=
0
;
i
<
nElems
;
i
++)
{
robot
.
keyPress
(
KeyEvent
.
VK_DOWN
);
toolkit
.
realSync
();
}
for
(
int
i
=
0
;
i
<
nElems
;
i
++)
{
robot
.
keyPress
(
KeyEvent
.
VK_UP
);
toolkit
.
realSync
();
}
}
static
void
doTestPgUpDown
()
{
try
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
cb
.
hidePopup
();
cb
.
setSelectedIndex
(
0
);
}
});
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
toolkit
.
realSync
();
int
listHeight
=
cb
.
getMaximumRowCount
();
for
(
int
i
=
0
;
i
<
nElems
;
i
+=
listHeight
)
{
robot
.
keyPress
(
KeyEvent
.
VK_PAGE_DOWN
);
toolkit
.
realSync
();
}
for
(
int
i
=
0
;
i
<
nElems
;
i
+=
listHeight
)
{
robot
.
keyPress
(
KeyEvent
.
VK_PAGE_UP
);
toolkit
.
realSync
();
}
}
public
static
void
main
(
String
[]
args
)
{
try
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
bug4199622
test
=
new
bug4199622
(
new
MetalLookAndFeel
());
test
.
setVisible
(
true
);
}
});
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
doTest
();
if
(
OSInfo
.
getOSType
()
==
OSInfo
.
OSType
.
WINDOWS
)
{
try
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
bug4199622
test
=
new
bug4199622
(
new
WindowsLookAndFeel
());
test
.
setVisible
(
true
);
}
});
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
new
RuntimeException
(
"Test failed"
,
e
);
}
doTest
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录