Windows 2000 に導入された新しい機能の 1 つは、メニュー項目またはダイアログコントロールのキーボードニーモニックを Alt キーが押されるまで表示しないようにする、表示のプロパティです。つまり、ユーザがマウスでなくキーボードを使用してコマンドを呼び出すことを示すまで、Alt キーと組み合わせてメニューやコントロールを呼び出せることを示す、すべての下線付き文字が表示されません。この結果、マウスでユーザインタフェースをナビゲートすることを選択したユーザに、下線付き文字で視覚的な混乱を与えないインタフェースが提供されます。
キーボードナビゲーションの非表示機能は、アプリケーションで Windows Look & Feel が使用され、かつ Windows 2000 の [画面のプロパティ] コントロールパネルアプレット内で「Alt キーを押さないときはキーボートのナビゲーションインジケータを表示しない」プロパティが有効にされた場合に、Windows 2000 で自動的に有効になります。
実装の詳細は、Look & Feel 機能を拡張している開発者向けのものです。キーボードナビゲーションの非表示機能は、Windows Look & Feel が使用される Java アプリケーションが Windows 2000 で実行されるときに、自動的に有効になります。
WindowsLookAndFeel がインスタンス化されていると、DesktopProperty の「win.menu.keyboardCuesOn」が読み込まれます。この値は UIManager に格納され、「Button.isMnemonicHidingEnabled」キーを使用して参照できます。WindowsLookAndFeel 内の static メソッドである setMnemonicHidden および isMnemonicHidden で、この値にアクセスします。
既存の BasicMenuItemUI.paintMenuItem() メソッドは、メニュー項目のバックグラウンド、テキスト、アイコン、およびニーモニックのレンダリングがその役目です。新規 protected メソッドである paintText() は、BasicButtonUI 階層内での同様なメソッドに名前とシグニチャーの面で一貫性のある paintMenuItem() から抽出されました。
paintText() メソッドは、WindowsMenuItemUI および WindowsMenuUI 内でオーバーロードされます。オーバーロードされた paintText メソッドの本体は、WindowsLookAndFeel クラス内の isMnemonicEnabled フラグをチェックして、テキストを適切に描画するためにニーモニックを非表示する必要があるかどうかを判断します。
BasicButtonUI では、すでに protected メソッドの paintText が定義されています。WindowsButtonUI および類似したクラスが、ほぼ同じ方法でこのメソッドをオーバーロードしました。新しいクラスの WindowsGraphicsUtils が導入され、すべての paintText が統合されました。Windows...UI クラスが Basic..UI クラスと同じ継承の階層に従わないため、この統合が行われました。
WindowsRootPaneUI と呼ばれる新規 RootPaneUI 委譲は、Windows Look & Feel 用に作成されました。このクラスには、Alt キーが押されたときにニーモニック非表示ビットをリセットして UI を再描画するための、登録済みのアクションがあります。
この新機能の実装の結果として、以下のすべてのメソッドが追加されました。これらのメソッドは、Look & Feel を拡張または作成したい開発者にのみ非常に有用です。
/**
* Renders the text of the current menu item.
*
* @param g graphics context
* @param menuItem menu item to render
* @param textRect bounding rectangle for rendering the text
* @param text String to render
* @since 1.4
*/
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text)
/**
* Windows implementation of RootPaneUI.One WindowsRootPaneUI
* object is shared between all JRootPane instances.
*
* @version 1.1 08/16/00
* @author Mark Davidson
* @since 1.4
*/
public class WindowsRootPaneUI extends BasicRootPaneUI
/**
* A collection of static utility methods used for rendering the
* Windows look and feel.
*
* @Version 1.1 08/16/00
* @author Mark Davidson
* @since 1.4
*/
public class WindowsGraphicsUtils
/**
* Sets the state of the hide mnemonic flag.This flag is used by the
* component UI delegates to determine if the mnemonic should be rendered.
* This method is a non operation if the underlying operating system
* does not support the mnemonic hiding feature.
*
* @param hide true if mnemonics should be hidden
* @since 1.4
*/
public static void setMnemonicHidden(boolean hide)
/**
* Gets the state of the hide mnemonic flag.This only has meaning
* if this feature is supported by the underlying OS.
*
* @return true if mnemonics are hidden, otherwise, false
* @see #setMnemonicHidden
* @since 1.4
*/
public static Boolean isMnemonicHidden()
/**
* Gets the state of the flag which indicates if the old Windows
* look and feel should be rendered.This flag is used by the
* component UI delegates as a hint to determine which style the component
* should be rendered.
*
* @return true if Windows 95 and Windows NT 4 look and feel should
* be rendered
* @since 1.4
*/
public static Boolean isClassicWindows()