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

Windows 2000に導入された新しい機能の1つは、メニュー項目またはダイアログ・コントロールのキーボード・ニーモニックをAltキーが押されるまで表示しないようにする、表示のプロパティです。つまり、ユーザーがマウスでなくキーボードを使用してコマンドを呼び出すことを示すまで、Altキーと組み合わせてメニューやコントロールを呼び出せることを示す、すべての下線付き文字が表示されません。この結果、マウスでユーザー・インタフェースをナビゲートすることを選択したユーザーに、下線付き文字で視覚的な混乱を与えないインタフェースが提供されます。

キーボード・ナビゲーションの非表示機能は、アプリケーションでWindowsルック・アンド・フィールが使用され、かつWindows 2000の「画面のプロパティ」コントロール・パネル・アプレット内で「Altキーを押さないときはキーボードのナビゲーション・インジケータを表示しない」プロパティが有効にされた場合に、Windows 2000で自動的に有効になります。

実装の詳細

実装の詳細は、ルック・アンド・フィール機能を拡張している開発者向けのものです。キーボード・ナビゲーションの非表示機能は、Windowsルック・アンド・フィールが使用されるJavaアプリケーションがWindows 2000で実行されるときに、自動的に有効になります。

WindowsLookAndFeelがインスタンス化されていると、DesktopPropertywin.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を再描画するための、登録済みのアクションがあります。

新規API

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

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

Copyright © 1993, 2020, Oracle and/or its affiliates. All rights reserved.