キーボードナビゲーションの非表示

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 内の静的メソッドである 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 を再描画するための、登録済みのアクションがあります。

新規 API

この新機能の実装の結果として、以下のすべてのメソッドが追加されました。これらのメソッドは、Look & Feel を拡張または作成したい開発者にのみ非常に有用です。

BasicMenuItemUI の新規メソッド

    /**
     * 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)

新規クラスの WindowsRootPaneUI

    /**
     * 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

新規クラスの WindowsGraphicsUtils

    /**
     * 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 

WindowsLookAndFeel の新規メソッド

    /**
     * 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()