Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
c9bfda98
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
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,发现更多精彩内容 >>
提交
c9bfda98
编写于
9月 20, 2012
作者:
Z
zhouyx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7194184: JColorChooser swatch cannot accessed from keyboard
Reviewed-by: rupashka, alexsch
上级
a0fed489
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
242 addition
and
9 deletion
+242
-9
src/share/classes/javax/swing/colorchooser/DefaultSwatchChooserPanel.java
...s/javax/swing/colorchooser/DefaultSwatchChooserPanel.java
+129
-9
test/javax/swing/JColorChooser/Test7194184.java
test/javax/swing/JColorChooser/Test7194184.java
+113
-0
未找到文件。
src/share/classes/javax/swing/colorchooser/DefaultSwatchChooserPanel.java
浏览文件 @
c9bfda98
...
...
@@ -57,6 +57,8 @@ class DefaultSwatchChooserPanel extends AbstractColorChooserPanel {
RecentSwatchPanel
recentSwatchPanel
;
MouseListener
mainSwatchListener
;
MouseListener
recentSwatchListener
;
private
KeyListener
mainSwatchKeyListener
;
private
KeyListener
recentSwatchKeyListener
;
public
DefaultSwatchChooserPanel
()
{
super
();
...
...
@@ -151,10 +153,14 @@ class DefaultSwatchChooserPanel extends AbstractColorChooserPanel {
recentSwatchPanel
.
putClientProperty
(
AccessibleContext
.
ACCESSIBLE_NAME_PROPERTY
,
recentStr
);
mainSwatchKeyListener
=
new
MainSwatchKeyListener
();
mainSwatchListener
=
new
MainSwatchListener
();
swatchPanel
.
addMouseListener
(
mainSwatchListener
);
swatchPanel
.
addKeyListener
(
mainSwatchKeyListener
);
recentSwatchListener
=
new
RecentSwatchListener
();
recentSwatchKeyListener
=
new
RecentSwatchKeyListener
();
recentSwatchPanel
.
addMouseListener
(
recentSwatchListener
);
recentSwatchPanel
.
addKeyListener
(
recentSwatchKeyListener
);
JPanel
mainHolder
=
new
JPanel
(
new
BorderLayout
());
Border
border
=
new
CompoundBorder
(
new
LineBorder
(
Color
.
black
),
...
...
@@ -196,11 +202,17 @@ class DefaultSwatchChooserPanel extends AbstractColorChooserPanel {
public
void
uninstallChooserPanel
(
JColorChooser
enclosingChooser
)
{
super
.
uninstallChooserPanel
(
enclosingChooser
);
swatchPanel
.
removeMouseListener
(
mainSwatchListener
);
swatchPanel
.
removeKeyListener
(
mainSwatchKeyListener
);
recentSwatchPanel
.
removeMouseListener
(
recentSwatchListener
);
recentSwatchPanel
.
removeKeyListener
(
recentSwatchKeyListener
);
swatchPanel
=
null
;
recentSwatchPanel
=
null
;
mainSwatchListener
=
null
;
mainSwatchKeyListener
=
null
;
recentSwatchListener
=
null
;
recentSwatchKeyListener
=
null
;
removeAll
();
// strip out all the sub-components
}
...
...
@@ -209,11 +221,32 @@ class DefaultSwatchChooserPanel extends AbstractColorChooserPanel {
}
private
class
RecentSwatchKeyListener
extends
KeyAdapter
{
public
void
keyPressed
(
KeyEvent
e
)
{
if
(
KeyEvent
.
VK_SPACE
==
e
.
getKeyCode
())
{
Color
color
=
recentSwatchPanel
.
getSelectedColor
();
setSelectedColor
(
color
);
}
}
}
private
class
MainSwatchKeyListener
extends
KeyAdapter
{
public
void
keyPressed
(
KeyEvent
e
)
{
if
(
KeyEvent
.
VK_SPACE
==
e
.
getKeyCode
())
{
Color
color
=
swatchPanel
.
getSelectedColor
();
setSelectedColor
(
color
);
recentSwatchPanel
.
setMostRecentColor
(
color
);
}
}
}
class
RecentSwatchListener
extends
MouseAdapter
implements
Serializable
{
public
void
mousePressed
(
MouseEvent
e
)
{
if
(
isEnabled
())
{
Color
color
=
recentSwatchPanel
.
getColorForLocation
(
e
.
getX
(),
e
.
getY
());
recentSwatchPanel
.
setSelectedColorFromLocation
(
e
.
getX
(),
e
.
getY
());
setSelectedColor
(
color
);
recentSwatchPanel
.
requestFocusInWindow
();
}
}
}
...
...
@@ -223,7 +256,9 @@ class DefaultSwatchChooserPanel extends AbstractColorChooserPanel {
if
(
isEnabled
())
{
Color
color
=
swatchPanel
.
getColorForLocation
(
e
.
getX
(),
e
.
getY
());
setSelectedColor
(
color
);
swatchPanel
.
setSelectedColorFromLocation
(
e
.
getX
(),
e
.
getY
());
recentSwatchPanel
.
setMostRecentColor
(
color
);
swatchPanel
.
requestFocusInWindow
();
}
}
}
...
...
@@ -239,18 +274,81 @@ class SwatchPanel extends JPanel {
protected
Dimension
numSwatches
;
protected
Dimension
gap
;
private
int
selRow
;
private
int
selCol
;
public
SwatchPanel
()
{
initValues
();
initColors
();
setToolTipText
(
""
);
// register for events
setOpaque
(
true
);
setBackground
(
Color
.
white
);
set
RequestFocusEnabled
(
fals
e
);
set
Focusable
(
tru
e
);
setInheritsPopupMenu
(
true
);
addFocusListener
(
new
FocusAdapter
()
{
public
void
focusGained
(
FocusEvent
e
)
{
repaint
();
}
public
void
focusLost
(
FocusEvent
e
)
{
repaint
();
}
});
addKeyListener
(
new
KeyAdapter
()
{
public
void
keyPressed
(
KeyEvent
e
)
{
int
typed
=
e
.
getKeyCode
();
switch
(
typed
)
{
case
KeyEvent
.
VK_UP
:
if
(
selRow
>
0
)
{
selRow
--;
repaint
();
}
break
;
case
KeyEvent
.
VK_DOWN
:
if
(
selRow
<
numSwatches
.
height
-
1
)
{
selRow
++;
repaint
();
}
break
;
case
KeyEvent
.
VK_LEFT
:
if
(
selCol
>
0
&&
SwatchPanel
.
this
.
getComponentOrientation
().
isLeftToRight
())
{
selCol
--;
repaint
();
}
else
if
(
selCol
<
numSwatches
.
width
-
1
&&
!
SwatchPanel
.
this
.
getComponentOrientation
().
isLeftToRight
())
{
selCol
++;
repaint
();
}
break
;
case
KeyEvent
.
VK_RIGHT
:
if
(
selCol
<
numSwatches
.
width
-
1
&&
SwatchPanel
.
this
.
getComponentOrientation
().
isLeftToRight
())
{
selCol
++;
repaint
();
}
else
if
(
selCol
>
0
&&
!
SwatchPanel
.
this
.
getComponentOrientation
().
isLeftToRight
())
{
selCol
--;
repaint
();
}
break
;
case
KeyEvent
.
VK_HOME
:
selCol
=
0
;
selRow
=
0
;
repaint
();
break
;
case
KeyEvent
.
VK_END
:
selCol
=
numSwatches
.
width
-
1
;
selRow
=
numSwatches
.
height
-
1
;
repaint
();
break
;
}
}
});
}
public
boolean
isFocusTraversable
()
{
return
false
;
public
Color
getSelectedColor
()
{
return
getColorForCell
(
selCol
,
selRow
)
;
}
protected
void
initValues
()
{
...
...
@@ -263,11 +361,10 @@ class SwatchPanel extends JPanel {
for
(
int
row
=
0
;
row
<
numSwatches
.
height
;
row
++)
{
int
y
=
row
*
(
swatchSize
.
height
+
gap
.
height
);
for
(
int
column
=
0
;
column
<
numSwatches
.
width
;
column
++)
{
g
.
setColor
(
getColorForCell
(
column
,
row
)
);
Color
c
=
getColorForCell
(
column
,
row
);
g
.
setColor
(
c
);
int
x
;
if
((!
this
.
getComponentOrientation
().
isLeftToRight
())
&&
(
this
instanceof
RecentSwatchPanel
))
{
if
(!
this
.
getComponentOrientation
().
isLeftToRight
())
{
x
=
(
numSwatches
.
width
-
column
-
1
)
*
(
swatchSize
.
width
+
gap
.
width
);
}
else
{
x
=
column
*
(
swatchSize
.
width
+
gap
.
width
);
...
...
@@ -276,6 +373,20 @@ class SwatchPanel extends JPanel {
g
.
setColor
(
Color
.
black
);
g
.
drawLine
(
x
+
swatchSize
.
width
-
1
,
y
,
x
+
swatchSize
.
width
-
1
,
y
+
swatchSize
.
height
-
1
);
g
.
drawLine
(
x
,
y
+
swatchSize
.
height
-
1
,
x
+
swatchSize
.
width
-
1
,
y
+
swatchSize
.
height
-
1
);
if
(
selRow
==
row
&&
selCol
==
column
&&
this
.
isFocusOwner
())
{
Color
c2
=
new
Color
(
c
.
getRed
()
<
125
?
255
:
0
,
c
.
getGreen
()
<
125
?
255
:
0
,
c
.
getBlue
()
<
125
?
255
:
0
);
g
.
setColor
(
c2
);
g
.
drawLine
(
x
,
y
,
x
+
swatchSize
.
width
-
1
,
y
);
g
.
drawLine
(
x
,
y
,
x
,
y
+
swatchSize
.
height
-
1
);
g
.
drawLine
(
x
+
swatchSize
.
width
-
1
,
y
,
x
+
swatchSize
.
width
-
1
,
y
+
swatchSize
.
height
-
1
);
g
.
drawLine
(
x
,
y
+
swatchSize
.
height
-
1
,
x
+
swatchSize
.
width
-
1
,
y
+
swatchSize
.
height
-
1
);
g
.
drawLine
(
x
,
y
,
x
+
swatchSize
.
width
-
1
,
y
+
swatchSize
.
height
-
1
);
g
.
drawLine
(
x
,
y
+
swatchSize
.
height
-
1
,
x
+
swatchSize
.
width
-
1
,
y
);
}
}
}
}
...
...
@@ -296,10 +407,19 @@ class SwatchPanel extends JPanel {
return
color
.
getRed
()+
", "
+
color
.
getGreen
()
+
", "
+
color
.
getBlue
();
}
public
void
setSelectedColorFromLocation
(
int
x
,
int
y
)
{
if
(!
this
.
getComponentOrientation
().
isLeftToRight
())
{
selCol
=
numSwatches
.
width
-
x
/
(
swatchSize
.
width
+
gap
.
width
)
-
1
;
}
else
{
selCol
=
x
/
(
swatchSize
.
width
+
gap
.
width
);
}
selRow
=
y
/
(
swatchSize
.
height
+
gap
.
height
);
repaint
();
}
public
Color
getColorForLocation
(
int
x
,
int
y
)
{
int
column
;
if
((!
this
.
getComponentOrientation
().
isLeftToRight
())
&&
(
this
instanceof
RecentSwatchPanel
))
{
if
(!
this
.
getComponentOrientation
().
isLeftToRight
())
{
column
=
numSwatches
.
width
-
x
/
(
swatchSize
.
width
+
gap
.
width
)
-
1
;
}
else
{
column
=
x
/
(
swatchSize
.
width
+
gap
.
width
);
...
...
test/javax/swing/JColorChooser/Test7194184.java
0 → 100644
浏览文件 @
c9bfda98
/*
* Copyright (c) 2012, 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.
*/
/*
* Portions Copyright (c) 2012 IBM Corporation
*/
/*
* @test
* @bug 7194184
* @summary Tests JColorChooser Swatch keyboard accessibility.
* @author Sean Chou
* @library ../regtesthelpers
* @build Util
* @run main Test7194184
*/
import
java.awt.Component
;
import
java.awt.AWTException
;
import
java.awt.Color
;
import
java.awt.Robot
;
import
java.awt.Toolkit
;
import
java.awt.event.KeyEvent
;
import
javax.swing.JColorChooser
;
import
javax.swing.JFrame
;
import
javax.swing.SwingUtilities
;
import
java.util.concurrent.Callable
;
import
sun.awt.SunToolkit
;
public
class
Test7194184
implements
Runnable
{
private
static
JFrame
frame
;
private
static
JColorChooser
colorChooser
;
private
static
Color
selectedColor
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
testKeyBoardAccess
();
}
private
static
void
testKeyBoardAccess
()
throws
Exception
{
Robot
robot
=
new
Robot
();
SunToolkit
toolkit
=
(
SunToolkit
)
Toolkit
.
getDefaultToolkit
();
SwingUtilities
.
invokeLater
(
new
Test7194184
());
toolkit
.
realSync
();
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
@Override
public
void
run
()
{
selectedColor
=
colorChooser
.
getColor
();
Component
recentSwatchPanel
=
Util
.
findSubComponent
(
colorChooser
,
"RecentSwatchPanel"
);
if
(
recentSwatchPanel
==
null
)
{
throw
new
RuntimeException
(
"RecentSwatchPanel not found"
);
}
recentSwatchPanel
.
requestFocusInWindow
();
}
});
toolkit
.
realSync
();
// Tab to move the focus to MainSwatch
Util
.
hitKeys
(
robot
,
KeyEvent
.
VK_SHIFT
,
KeyEvent
.
VK_TAB
);
// Select the color on right
Util
.
hitKeys
(
robot
,
KeyEvent
.
VK_RIGHT
);
Util
.
hitKeys
(
robot
,
KeyEvent
.
VK_RIGHT
);
Util
.
hitKeys
(
robot
,
KeyEvent
.
VK_SPACE
);
toolkit
.
realSync
();
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
frame
.
dispose
();
if
(
selectedColor
==
colorChooser
.
getColor
())
{
throw
new
RuntimeException
(
"JColorChooser misses keyboard accessibility"
);
}
}
});
}
public
void
run
()
{
String
title
=
getClass
().
getName
();
frame
=
new
JFrame
(
title
);
colorChooser
=
new
JColorChooser
();
frame
.
add
(
colorChooser
);
frame
.
pack
();
frame
.
setVisible
(
true
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录