|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjavax.swing.LookAndFeel
javax.swing.plaf.basic.BasicLookAndFeel
public abstract class BasicLookAndFeel
为 Swing 创建外观时要使用的基类。
BasicLookAndFeel 提供的每个 ComponentUI 根据默认表派生其行为。除非另行说明,否则此包中的每个 ComponentUI 将记录他们所使用的默认值集合。除非另行说明,否则在调用 installUI 时将安装该默认值,并在安装默认值时遵循 LookAndFeel 中所描述的建议。
警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder。
| 构造方法摘要 | |
|---|---|
BasicLookAndFeel()
|
|
| 方法摘要 | |
|---|---|
protected Action |
createAudioAction(Object key)
创建并返回用于播放音频的 Action。 |
protected ActionMap |
getAudioActionMap()
返回包含此外观音频动作的 ActionMap。 |
UIDefaults |
getDefaults()
返回外观默认值。 |
protected void |
initClassDefaults(UIDefaults table)
用从 uiClassID 到 ui 类的完全限定名称的映射关系填充 table。 |
protected void |
initComponentDefaults(UIDefaults table)
用基本外观的默认值填充 table。 |
void |
initialize()
初始化外观。 |
protected void |
initSystemColorDefaults(UIDefaults table)
用系统颜色填充 table。 |
protected void |
loadSystemColors(UIDefaults table,
String[] systemColors,
boolean useNative)
用 systemColors 中的 name-color 对填充 table。 |
protected void |
playSound(Action audioAction)
如有必要,在 audioAction 上调用 actionPerformed 以播放声音。 |
void |
uninitialize()
取消初始化外观。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 构造方法详细信息 |
|---|
public BasicLookAndFeel()
| 方法详细信息 |
|---|
public UIDefaults getDefaults()
initClassDefaults、initSystemColorDefaults 和 initComponentDefaults 填充返回的 UIDefaults。
尽管此方法是公共的,但它只有在外观被设置为当前外观并在调用 initialize 之后时才由 UIManager 调用。
LookAndFeel 中的 getDefaultsinitClassDefaults(javax.swing.UIDefaults),
initSystemColorDefaults(javax.swing.UIDefaults),
initComponentDefaults(javax.swing.UIDefaults)public void initialize()
UIManager 调用。在 UIManager 调用 getDefaults 之前调用此方法。此方法用于执行外观的任何初始化。子类应该用此方法而不是静态初始化程序来执行它们需要的任何一次设置,因为也可能只是为了发现 isSupportedLookAndFeel() 返回 false 而加载外观类对象。
LookAndFeel 中的 initializeLookAndFeel.uninitialize(),
UIManager.setLookAndFeel(javax.swing.LookAndFeel)public void uninitialize()
UIManager 调用。例如,外观更改时 UIManager.setLookAndFeel 调用此方法。
子类在此处可以选择释放一些资源。
LookAndFeel 中的 uninitializeLookAndFeel.initialize(),
UIManager.setLookAndFeel(javax.swing.LookAndFeel)protected void initClassDefaults(UIDefaults table)
uiClassID 到 ui 类的完全限定名称的映射关系填充 table。特定 uiClassID 的值为 "javax.swing.plaf.basic.Basic + uiClassID"。例如,uiClassID TreeUI 的值为 "javax.swing.plaf.basic.BasicTreeUI"。
table - 要添加项的 UIDefaults 实例
NullPointerException - 如果 table 为 nullLookAndFeel,
getDefaults()protected void initSystemColorDefaults(UIDefaults table)
table。此方法创建一个 name-color 对的数组并调用 loadSystemColors。
该名称是对应于 SystemColor 类中一个静态 SystemColor 字段名称的 String。名称-颜色对用于创建每个这样的 SystemColor 字段。
color 对应于 Color.decode 所理解的十六进制 String。例如,一个 name-color 对是 "desktop"-"#005C5C"。这对应于 SystemColor 字段 desktop,其颜色值为 new Color(0x005C5C)。
以下显示了两个 name-color 对:
String[] nameColorPairs = new String[] {
"desktop", "#005C5C",
"activeCaption", "#000080" };
loadSystemColors(table, nameColorPairs, isNativeLookAndFeel());
如前所述,此方法使用提供的 table 和 name-color 对数组调用 loadSystemColors。loadSystemColors 的最后一个参数指示是否应该使用 SystemColor 中字段的值。此方法将 isNativeLookAndFeel() 的值作为最后一个参数传递给 loadSystemColors。
table - 要添加值的 UIDefaults 对象
NullPointerException - 如果 table 为 nullSystemColor,
getDefaults(),
loadSystemColors(javax.swing.UIDefaults, java.lang.String[], boolean)
protected void loadSystemColors(UIDefaults table,
String[] systemColors,
boolean useNative)
systemColors 中的 name-color 对填充 table。有关 systemColors 格式的详细信息,请参阅 initSystemColorDefaults(UIDefaults)。
为 systemColors 中的每个 name-color 对添加一个项到 table。该项键是 name-color 对的 name。
该项的值对应于 name-color 对的 color。该项的值以两种方式之一进行计算。无论使用哪种方法,该值始终是 ColorUIResource。
如果 useNative 为 false,则通过使用 Color.decode 将 String 转换为 Color 来创建 color。如果 decode 不能将 String 转换为 Color(抛出 NumberFormatException),则使用黑色的 ColorUIResource。
如果 useNative 为 true,则 color 是 SystemColor 中字段的值,其名称与 name-color 对的 name 相同。如果该字段无效,则使用黑色的 ColorUIResource。
table - 要添加值的 UIDefaults 对象systemColors - initSystemColorDefaults(UIDefaults) 中所述的 name-color 对数组useNative - 该颜色是否可以从 SystemColor 或 Color.decode 获得
NullPointerException - 如果 systemColors 为 null;或者 systemColors 不为空,并且 table 为 null;或者 name-color 对的 name 之一为 null;或者 useNative 为 false ,并且 name-color 对的 color 之一为 null
ArrayIndexOutOfBoundsException - 如果 useNative 为 false ,并且 systemColors.length 为奇数initSystemColorDefaults(javax.swing.UIDefaults),
SystemColor,
Color.decode(String)protected void initComponentDefaults(UIDefaults table)
table。
table - 要添加值的 UIDefaults
NullPointerException - 如果 table 为 nullprotected ActionMap getAudioActionMap()
ActionMap。
返回的 ActionMap 包含具有呈现听觉提示能力的 Action。这些听觉提示映射到用户和可能帮助最终用户了解的系统活动(如对话框的出现)。
在适当时间,ComponentUI 负责从 ActionMap 获得 Action 并将它传递给 playSound。
此方法首先使用 "AuditoryCues.actionMap" 键从默认值中查找 ActionMap。
如果值为非 null,则返回该值。如果默认 "AuditoryCues.actionMap" 的值为 null ,并且默认 "AuditoryCues.cueList" 的值为非 null,则创建一个 ActionMapUIResource 并进行填充。通过对 "AuditoryCues.cueList" 数组中的每个元素进行迭代来完成填充,通过调用 createAudioAction() 为每个元素创建 Action。以数组元素为键将所得的 Action 置于 ActionMapUIResource 中。例如,如果 "AuditoryCues.cueList" 数组包含单个元素("audioKey"),则创建一个 ActionMapUIResource,然后通过 actionMap.put(cueList[0],
createAudioAction(cueList[0])) 填充。
如果默认 "AuditoryCues.actionMap" 的值为 null ,并且默认 "AuditoryCues.cueList" 的值为 null,则创建一个空 ActionMapUIResource。
Action 的 ActionMap
ClassCastException - 如果默认 "AuditoryCues.actionMap" 的值不为 ActionMap,或者默认 "AuditoryCues.cueList" 的值不为 Object[]createAudioAction(java.lang.Object),
playSound(Action)protected Action createAudioAction(Object key)
Action。
如果 key 为非 null,则使用取自带有 key 键的默认值的值创建 Action。当在 Action 上调用 actionPerformed 时,该值标识要加载的音源。通过 getClass().getResourceAsStream() 将音源加载到 byte[]。
key - 标识音频动作的键
Action;如果 key 为 null,则返回 nullplaySound(Action)protected void playSound(Action audioAction)
audioAction 上调用 actionPerformed 以播放声音。如果 "AuditoryCues.playList" 默认的值为非 null Object[](包含与 audioAction 的名称相等的 String 项),则调用 actionPerformed 方法。
audioAction - 知道如何呈现与系统或用户活动关联的正在发生的 Action;忽略 null 值
ClassCastException - 如果 audioAction 为非 null ,并且默认 "AuditoryCues.playList" 的值不为 Object[]
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。