Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
8df45b05
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看板
提交
8df45b05
编写于
12月 21, 2009
作者:
P
peterz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6860433: [Nimbus] Code to set a single slider's thumb background doesn't work as specified
Reviewed-by: rupashka
上级
c107a845
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
190 addition
and
18 deletion
+190
-18
src/share/classes/javax/swing/plaf/nimbus/Defaults.template
src/share/classes/javax/swing/plaf/nimbus/Defaults.template
+19
-16
src/share/classes/javax/swing/plaf/nimbus/NimbusLookAndFeel.java
...re/classes/javax/swing/plaf/nimbus/NimbusLookAndFeel.java
+6
-2
test/javax/swing/plaf/nimbus/ColorCustomizationTest.java
test/javax/swing/plaf/nimbus/ColorCustomizationTest.java
+165
-0
未找到文件。
src/share/classes/javax/swing/plaf/nimbus/Defaults.template
浏览文件 @
8df45b05
...
...
@@ -90,6 +90,10 @@ final class ${LAF_NAME}Defaults {
*/
private
Map
<
String
,
Region
>
registeredRegions
=
new
HashMap
<
String
,
Region
>();
private
Map
<
JComponent
,
Map
<
Region
,
SynthStyle
>>
overridesCache
=
new
WeakHashMap
<
JComponent
,
Map
<
Region
,
SynthStyle
>>();
/**
*
Our
fallback
style
to
avoid
NPEs
if
the
proper
style
cannot
be
found
in
*
this
class
.
Not
sure
if
relying
on
DefaultSynthStyle
is
the
best
choice
.
...
...
@@ -251,7 +255,11 @@ ${UI_DEFAULT_INIT}
}
//
return
the
style
,
if
found
,
or
the
default
style
if
not
found
return
foundStyle
==
null
?
defaultStyle
:
foundStyle
.
getStyle
(
comp
);
return
foundStyle
==
null
?
defaultStyle
:
foundStyle
.
getStyle
(
comp
,
r
);
}
public
void
clearOverridesCache
(
JComponent
c
)
{
overridesCache
.
remove
(
c
);
}
/*
...
...
@@ -457,15 +465,6 @@ ${UI_DEFAULT_INIT}
* Cached shared style.
*/
private NimbusStyle style;
/**
* A weakly referenced hash map such that if the reference JComponent
* key is garbage collected then the entry is removed from the map.
* This cache exists so that when a JComponent has nimbus overrides
* in its client map, a unique style will be created and returned
* for that JComponent instance, always. In such a situation each
* JComponent instance must have its own instance of NimbusStyle.
*/
private WeakHashMap<JComponent, WeakReference<NimbusStyle>> overridesCache;
/**
* Create a new LazyStyle.
...
...
@@ -513,17 +512,21 @@ ${UI_DEFAULT_INIT}
* Gets the style. Creates it if necessary.
* @return the style
*/
SynthStyle getStyle(JComponent c) {
SynthStyle getStyle(JComponent c
, Region r
) {
// if the component has overrides, it gets its own unique style
// instead of the shared style.
if (c.getClientProperty("Nimbus.Overrides") != null) {
if (overridesCache == null)
overridesCache = new WeakHashMap<JComponent, WeakReference<NimbusStyle>>();
WeakReference<NimbusStyle> ref = overridesCache.get(c);
NimbusStyle s = ref == null ? null : ref.get();
Map<Region, SynthStyle> map = overridesCache.get(c);
SynthStyle s = null;
if (map == null) {
map = new HashMap<Region, SynthStyle>();
overridesCache.put(c, map);
} else {
s = map.get(r);
}
if (s == null) {
s = new NimbusStyle(prefix, c);
overridesCache.put(c, new WeakReference<NimbusStyle>(s)
);
map.put(r, s
);
}
return s;
}
...
...
src/share/classes/javax/swing/plaf/nimbus/NimbusLookAndFeel.java
浏览文件 @
8df45b05
...
...
@@ -280,11 +280,15 @@ public class NimbusLookAndFeel extends SynthLookAndFeel {
protected
boolean
shouldUpdateStyleOnEvent
(
PropertyChangeEvent
ev
)
{
String
eName
=
ev
.
getPropertyName
();
// Always update when overrides or size variant change
if
(
"Nimbus.Overrides"
==
eName
||
// These properties affect style cached inside NimbusDefaults (6860433)
if
(
"name"
==
eName
||
"ancestor"
==
eName
||
"Nimbus.Overrides"
==
eName
||
"Nimbus.Overrides.InheritDefaults"
==
eName
||
"JComponent.sizeVariant"
==
eName
)
{
JComponent
c
=
(
JComponent
)
ev
.
getSource
();
defaults
.
clearOverridesCache
(
c
);
return
true
;
}
...
...
test/javax/swing/plaf/nimbus/ColorCustomizationTest.java
0 → 100644
浏览文件 @
8df45b05
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
@bug 6860433
@summary Tests variuos techniques of Nimbus color customization
@author Peter Zhelezniakov
@run main ColorCustomizationTest
*/
import
javax.swing.JLabel
;
import
javax.swing.SwingUtilities
;
import
javax.swing.UIDefaults
;
import
javax.swing.UIManager
;
import
java.awt.Color
;
import
java.awt.Graphics
;
import
java.awt.image.BufferedImage
;
import
javax.swing.UnsupportedLookAndFeelException
;
import
javax.swing.plaf.ColorUIResource
;
import
javax.swing.plaf.nimbus.NimbusLookAndFeel
;
import
javax.swing.plaf.synth.Region
;
public
class
ColorCustomizationTest
{
final
static
int
WIDTH
=
200
;
final
static
int
HEIGHT
=
100
;
static
NimbusLookAndFeel
nimbus
;
final
JLabel
label
;
final
Graphics
g
;
ColorCustomizationTest
()
{
label
=
new
JLabel
();
label
.
setSize
(
200
,
100
);
g
=
new
BufferedImage
(
WIDTH
,
HEIGHT
,
BufferedImage
.
TYPE_INT_ARGB
).
getGraphics
();
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
nimbus
=
new
NimbusLookAndFeel
();
try
{
UIManager
.
setLookAndFeel
(
nimbus
);
}
catch
(
UnsupportedLookAndFeelException
e
)
{
throw
new
Error
(
"Unable to set Nimbus LAF"
);
}
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
new
ColorCustomizationTest
().
test
();
}
});
}
void
check
(
Color
c
)
{
SwingUtilities
.
updateComponentTreeUI
(
label
);
label
.
paint
(
g
);
if
(
label
.
getBackground
().
getRGB
()
!=
c
.
getRGB
())
{
System
.
err
.
println
(
"Color mismatch!"
);
System
.
err
.
println
(
" found: "
+
label
.
getBackground
());
System
.
err
.
println
(
" expected: "
+
c
);
throw
new
RuntimeException
(
"Test failed"
);
}
}
void
test
()
{
testOverrides
();
testInheritance
();
testNames
();
testBaseColor
();
}
void
testOverrides
()
{
Color
defaultColor
=
label
.
getBackground
();
// override default background
UIDefaults
defs
=
new
UIDefaults
();
defs
.
put
(
"Label.background"
,
new
ColorUIResource
(
Color
.
RED
));
label
.
putClientProperty
(
"Nimbus.Overrides"
,
defs
);
check
(
Color
.
RED
);
// change overriding color
defs
=
new
UIDefaults
();
defs
.
put
(
"Label.background"
,
new
ColorUIResource
(
Color
.
GREEN
));
label
.
putClientProperty
(
"Nimbus.Overrides"
,
defs
);
check
(
Color
.
GREEN
);
// remove override
label
.
putClientProperty
(
"Nimbus.Overrides"
,
null
);
check
(
defaultColor
);
}
void
testInheritance
()
{
Color
defaultColor
=
label
.
getBackground
();
// more specific setting is in global defaults
UIManager
.
put
(
"Label[Enabled].background"
,
new
ColorUIResource
(
Color
.
RED
));
// less specific one is in overrides
UIDefaults
defs
=
new
UIDefaults
();
defs
.
put
(
"Label.background"
,
new
ColorUIResource
(
Color
.
GREEN
));
// global wins
label
.
putClientProperty
(
"Nimbus.Overrides"
,
defs
);
check
(
Color
.
RED
);
// now override wins
label
.
putClientProperty
(
"Nimbus.Overrides.InheritDefaults"
,
false
);
check
(
Color
.
GREEN
);
// global is back
label
.
putClientProperty
(
"Nimbus.Overrides.InheritDefaults"
,
true
);
check
(
Color
.
RED
);
// back to default color
UIManager
.
put
(
"Label[Enabled].background"
,
null
);
label
.
putClientProperty
(
"Nimbus.Overrides.InheritDefaults"
,
false
);
label
.
putClientProperty
(
"Nimbus.Overrides"
,
null
);
check
(
defaultColor
);
}
void
testNames
()
{
Color
defaultColor
=
label
.
getBackground
();
UIManager
.
put
(
"\"BlueLabel\"[Enabled].background"
,
new
ColorUIResource
(
Color
.
BLUE
));
UIManager
.
put
(
"\"RedLabel\"[Enabled].background"
,
new
ColorUIResource
(
Color
.
RED
));
nimbus
.
register
(
Region
.
LABEL
,
"\"BlueLabel\""
);
nimbus
.
register
(
Region
.
LABEL
,
"\"RedLabel\""
);
label
.
setName
(
"BlueLabel"
);
check
(
Color
.
BLUE
);
label
.
setName
(
"RedLabel"
);
check
(
Color
.
RED
);
// remove name, color goes back to default
label
.
setName
(
null
);
check
(
defaultColor
);
}
void
testBaseColor
()
{
UIManager
.
put
(
"control"
,
Color
.
GREEN
);
check
(
Color
.
GREEN
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录