|
JavaTM 2 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 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。