Windows 2000に導入された新しい機能の1つは、メニュー項目またはダイアログ・コントロールのキーボード・ニーモニックをAltキーが押されるまで表示しないようにする、表示のプロパティです。つまり、ユーザーがマウスでなくキーボードを使用してコマンドを呼び出すことを示すまで、Altキーと組み合わせてメニューやコントロールを呼び出せることを示す、すべての下線付き文字が表示されません。この結果、マウスでユーザー・インタフェースをナビゲートすることを選択したユーザーに、下線付き文字で視覚的な混乱を与えないインタフェースが提供されます。
キーボード・ナビゲーションの非表示機能は、アプリケーションでWindowsルック・アンド・フィールが使用され、かつWindows 2000の「画面のプロパティ」コントロール・パネル・アプレット内で「Altキーを押さないときはキーボードのナビゲーション・インジケータを表示しない」プロパティが有効にされた場合に、Windows 2000で自動的に有効になります。
実装の詳細は、ルック・アンド・フィール機能を拡張している開発者向けのものです。キーボード・ナビゲーションの非表示機能は、Windowsルック・アンド・フィールが使用される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ルック・アンド・フィール用に作成されました。このクラスには、Altキーが押されたときにニーモニック非表示ビットをリセットしてUIを再描画するための、登録済みのアクションがあります。
この新機能の実装の結果として、以下のすべてのメソッドが追加されました。これらのメソッドは、ルック・アンド・フィールを拡張または作成したい開発者にのみ非常に有用です。
/** * 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()