JavaTM 2 Platform
Standard Ed. 6

javax.swing.plaf.basic
类 BasicLookAndFeel

java.lang.Object
  继承者 javax.swing.LookAndFeel
      继承者 javax.swing.plaf.basic.BasicLookAndFeel
所有已实现的接口:
Serializable
直接已知子类:
MetalLookAndFeel, SynthLookAndFeel

public abstract class BasicLookAndFeel
extends LookAndFeel
implements Serializable

为 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()
          取消初始化外观。
 
从类 javax.swing.LookAndFeel 继承的方法
getDescription, getDesktopPropertyValue, getDisabledIcon, getDisabledSelectedIcon, getID, getLayoutStyle, getName, getSupportsWindowDecorations, installBorder, installColors, installColorsAndFont, installProperty, isNativeLookAndFeel, isSupportedLookAndFeel, loadKeyBindings, makeComponentInputMap, makeIcon, makeInputMap, makeKeyBindings, provideErrorFeedback, toString, uninstallBorder
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

构造方法详细信息

BasicLookAndFeel

public BasicLookAndFeel()
方法详细信息

getDefaults

public UIDefaults getDefaults()
返回外观默认值。通过按顺序调用 initClassDefaultsinitSystemColorDefaultsinitComponentDefaults 填充返回的 UIDefaults

尽管此方法是公共的,但它只有在外观被设置为当前外观并在调用 initialize 之后时才由 UIManager 调用。

覆盖:
LookAndFeel 中的 getDefaults
返回:
外观默认值
另请参见:
initClassDefaults(javax.swing.UIDefaults), initSystemColorDefaults(javax.swing.UIDefaults), initComponentDefaults(javax.swing.UIDefaults)

initialize

public void initialize()
初始化外观。尽管此方法是公共的,但只有在外观作为当前外观安装时才能由 UIManager 调用。在 UIManager 调用 getDefaults 之前调用此方法。此方法用于执行外观的任何初始化。子类应该用此方法而不是静态初始化程序来执行它们需要的任何一次设置,因为也可能只是为了发现 isSupportedLookAndFeel() 返回 false 而加载外观类对象。

覆盖:
LookAndFeel 中的 initialize
另请参见:
LookAndFeel.uninitialize(), UIManager.setLookAndFeel(javax.swing.LookAndFeel)

uninitialize

public void uninitialize()
取消初始化外观。尽管此方法是公共的,但只有在卸载外观时才能由 UIManager 调用。例如,外观更改时 UIManager.setLookAndFeel 调用此方法。

子类在此处可以选择释放一些资源。

覆盖:
LookAndFeel 中的 uninitialize
另请参见:
LookAndFeel.initialize(), UIManager.setLookAndFeel(javax.swing.LookAndFeel)

initClassDefaults

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 - 如果 tablenull
另请参见:
LookAndFeel, getDefaults()

initSystemColorDefaults

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());
 
如前所述,此方法使用提供的 tablename-color 对数组调用 loadSystemColorsloadSystemColors 的最后一个参数指示是否应该使用 SystemColor 中字段的值。此方法将 isNativeLookAndFeel() 的值作为最后一个参数传递给 loadSystemColors

参数:
table - 要添加值的 UIDefaults 对象
抛出:
NullPointerException - 如果 tablenull
另请参见:
SystemColor, getDefaults(), loadSystemColors(javax.swing.UIDefaults, java.lang.String[], boolean)

loadSystemColors

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

如果 useNativefalse,则通过使用 Color.decodeString 转换为 Color 来创建 color。如果 decode 不能将 String 转换为 Color(抛出 NumberFormatException),则使用黑色的 ColorUIResource

如果 useNativetrue,则 colorSystemColor 中字段的值,其名称与 name-color 对的 name 相同。如果该字段无效,则使用黑色的 ColorUIResource

参数:
table - 要添加值的 UIDefaults 对象
systemColors - initSystemColorDefaults(UIDefaults) 中所述的 name-color 对数组
useNative - 该颜色是否可以从 SystemColorColor.decode 获得
抛出:
NullPointerException - 如果 systemColorsnull;或者 systemColors 不为空,并且 tablenull;或者 name-color 对的 name 之一为 null;或者 useNativefalse ,并且 name-color 对的 color 之一为 null
ArrayIndexOutOfBoundsException - 如果 useNativefalse ,并且 systemColors.length 为奇数
另请参见:
initSystemColorDefaults(javax.swing.UIDefaults), SystemColor, Color.decode(String)

initComponentDefaults

protected void initComponentDefaults(UIDefaults table)
用基本外观的默认值填充 table

参数:
table - 要添加值的 UIDefaults
抛出:
NullPointerException - 如果 tablenull

getAudioActionMap

protected 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[]
从以下版本开始:
1.4
另请参见:
createAudioAction(java.lang.Object), playSound(Action)

createAudioAction

protected Action createAudioAction(Object key)
创建并返回用于播放音频的 Action

如果 key非 null,则使用取自带有 key 键的默认值的值创建 Action。当在 Action 上调用 actionPerformed 时,该值标识要加载的音源。通过 getClass().getResourceAsStream() 将音源加载到 byte[]

参数:
key - 标识音频动作的键
返回:
用于播放该源的 Action;如果 keynull,则返回 null
从以下版本开始:
1.4
另请参见:
playSound(Action)

playSound

protected void playSound(Action audioAction)
如有必要,在 audioAction 上调用 actionPerformed 以播放声音。如果 "AuditoryCues.playList" 默认的值为非 null Object[](包含与 audioAction 的名称相等的 String 项),则调用 actionPerformed 方法。

参数:
audioAction - 知道如何呈现与系统或用户活动关联的正在发生的 Action;忽略 null
抛出:
ClassCastException - 如果 audioAction非 null ,并且默认 "AuditoryCues.playList" 的值不为 Object[]
从以下版本开始:
1.4

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only