1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * <p>These classes are designed to be used while the
  28  * corresponding <code>LookAndFeel</code> class has been installed
  29  * (<code>UIManager.setLookAndFeel(new <i>XXX</i>LookAndFeel())</code>).
  30  * Using them while a different <code>LookAndFeel</code> is installed
  31  * may produce unexpected results, including exceptions.
  32  * Additionally, changing the <code>LookAndFeel</code>
  33  * maintained by the <code>UIManager</code> without updating the
  34  * corresponding <code>ComponentUI</code> of any
  35  * <code>JComponent</code>s may also produce unexpected results,
  36  * such as the wrong colors showing up, and is generally not
  37  * encouraged.
  38  *
  39  */
  40 
  41 package com.sun.java.swing.plaf.windows;
  42 
  43 import java.awt.*;
  44 import java.awt.image.BufferedImage;
  45 import java.awt.image.ImageFilter;
  46 import java.awt.image.ImageProducer;
  47 import java.awt.image.FilteredImageSource;
  48 import java.awt.image.RGBImageFilter;
  49 
  50 import javax.swing.plaf.*;
  51 import javax.swing.*;
  52 import javax.swing.plaf.basic.*;
  53 import javax.swing.border.*;
  54 import javax.swing.text.DefaultEditorKit;
  55 
  56 import java.awt.Font;
  57 import java.awt.Color;
  58 import java.awt.event.KeyEvent;
  59 import java.awt.event.ActionEvent;
  60 
  61 import java.security.AccessController;
  62 
  63 import sun.awt.SunToolkit;
  64 import sun.awt.OSInfo;
  65 import sun.awt.shell.ShellFolder;
  66 import sun.font.FontUtilities;
  67 import sun.security.action.GetPropertyAction;
  68 
  69 import sun.swing.DefaultLayoutStyle;
  70 import sun.swing.ImageIconUIResource;
  71 import sun.swing.SwingLazyValue;
  72 import sun.swing.SwingUtilities2;
  73 import sun.swing.StringUIClientPropertyKey;
  74 
  75 import static com.sun.java.swing.plaf.windows.TMSchema.*;
  76 import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
  77 
  78 import com.sun.java.swing.plaf.windows.WindowsIconFactory.VistaMenuItemCheckIconFactory;
  79 
  80 /**
  81  * Implements the Windows95/98/NT/2000 Look and Feel.
  82  * UI classes not implemented specifically for Windows will
  83  * default to those implemented in Basic.
  84  * <p>
  85  * <strong>Warning:</strong>
  86  * Serialized objects of this class will not be compatible with
  87  * future Swing releases.  The current serialization support is appropriate
  88  * for short term storage or RMI between applications running the same
  89  * version of Swing.  A future release of Swing will provide support for
  90  * long term persistence.
  91  *
  92  * @author unattributed
  93  */
  94 public class WindowsLookAndFeel extends BasicLookAndFeel
  95 {
  96     /**
  97      * A client property that can be used with any JComponent that will end up
  98      * calling the LookAndFeel.getDisabledIcon method. This client property,
  99      * when set to Boolean.TRUE, will cause getDisabledIcon to use an
 100      * alternate algorithm for creating disabled icons to produce icons
 101      * that appear similar to the native Windows file chooser
 102      */
 103     static final Object HI_RES_DISABLED_ICON_CLIENT_KEY =
 104         new StringUIClientPropertyKey(
 105             "WindowsLookAndFeel.generateHiResDisabledIcon");
 106 
 107     private boolean updatePending = false;
 108 
 109     private boolean useSystemFontSettings = true;
 110     private boolean useSystemFontSizeSettings;
 111 
 112     // These properties are not used directly, but are kept as
 113     // private members to avoid being GC'd.
 114     private DesktopProperty themeActive, dllName, colorName, sizeName;
 115     private DesktopProperty aaSettings;
 116 
 117     private transient LayoutStyle style;
 118 
 119     /**
 120      * Base dialog units along the horizontal axis.
 121      */
 122     private int baseUnitX;
 123 
 124     /**
 125      * Base dialog units along the vertical axis.
 126      */
 127     private int baseUnitY;
 128 
 129     public String getName() {
 130         return "Windows";
 131     }
 132 
 133     public String getDescription() {
 134         return "The Microsoft Windows Look and Feel";
 135     }
 136 
 137     public String getID() {
 138         return "Windows";
 139     }
 140 
 141     public boolean isNativeLookAndFeel() {
 142         return OSInfo.getOSType() == OSInfo.OSType.WINDOWS;
 143     }
 144 
 145     public boolean isSupportedLookAndFeel() {
 146         return isNativeLookAndFeel();
 147     }
 148 
 149     public void initialize() {
 150         super.initialize();
 151 
 152         // Set the flag which determines which version of Windows should
 153         // be rendered. This flag only need to be set once.
 154         // if version <= 4.0 then the classic LAF should be loaded.
 155         if (OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_95) <= 0) {
 156             isClassicWindows = true;
 157         } else {
 158             isClassicWindows = false;
 159             XPStyle.invalidateStyle();
 160         }
 161 
 162         // Using the fonts set by the user can potentially cause
 163         // performance and compatibility issues, so allow this feature
 164         // to be switched off either at runtime or programmatically
 165         //
 166         String systemFonts = java.security.AccessController.doPrivileged(
 167                new GetPropertyAction("swing.useSystemFontSettings"));
 168         useSystemFontSettings = (systemFonts == null ||
 169                                  Boolean.valueOf(systemFonts).booleanValue());
 170 
 171         if (useSystemFontSettings) {
 172             Object value = UIManager.get("Application.useSystemFontSettings");
 173 
 174             useSystemFontSettings = (value == null ||
 175                                      Boolean.TRUE.equals(value));
 176         }
 177         KeyboardFocusManager.getCurrentKeyboardFocusManager().
 178             addKeyEventPostProcessor(WindowsRootPaneUI.altProcessor);
 179 
 180     }
 181 
 182     /**
 183      * Initialize the uiClassID to BasicComponentUI mapping.
 184      * The JComponent classes define their own uiClassID constants
 185      * (see AbstractComponent.getUIClassID).  This table must
 186      * map those constants to a BasicComponentUI class of the
 187      * appropriate type.
 188      *
 189      * @see BasicLookAndFeel#getDefaults
 190      */
 191     protected void initClassDefaults(UIDefaults table)
 192     {
 193         super.initClassDefaults(table);
 194 
 195         final String windowsPackageName = "com.sun.java.swing.plaf.windows.";
 196 
 197         Object[] uiDefaults = {
 198               "ButtonUI", windowsPackageName + "WindowsButtonUI",
 199             "CheckBoxUI", windowsPackageName + "WindowsCheckBoxUI",
 200     "CheckBoxMenuItemUI", windowsPackageName + "WindowsCheckBoxMenuItemUI",
 201                "LabelUI", windowsPackageName + "WindowsLabelUI",
 202          "RadioButtonUI", windowsPackageName + "WindowsRadioButtonUI",
 203  "RadioButtonMenuItemUI", windowsPackageName + "WindowsRadioButtonMenuItemUI",
 204         "ToggleButtonUI", windowsPackageName + "WindowsToggleButtonUI",
 205          "ProgressBarUI", windowsPackageName + "WindowsProgressBarUI",
 206               "SliderUI", windowsPackageName + "WindowsSliderUI",
 207            "SeparatorUI", windowsPackageName + "WindowsSeparatorUI",
 208            "SplitPaneUI", windowsPackageName + "WindowsSplitPaneUI",
 209              "SpinnerUI", windowsPackageName + "WindowsSpinnerUI",
 210           "TabbedPaneUI", windowsPackageName + "WindowsTabbedPaneUI",
 211             "TextAreaUI", windowsPackageName + "WindowsTextAreaUI",
 212            "TextFieldUI", windowsPackageName + "WindowsTextFieldUI",
 213        "PasswordFieldUI", windowsPackageName + "WindowsPasswordFieldUI",
 214             "TextPaneUI", windowsPackageName + "WindowsTextPaneUI",
 215           "EditorPaneUI", windowsPackageName + "WindowsEditorPaneUI",
 216                 "TreeUI", windowsPackageName + "WindowsTreeUI",
 217              "ToolBarUI", windowsPackageName + "WindowsToolBarUI",
 218     "ToolBarSeparatorUI", windowsPackageName + "WindowsToolBarSeparatorUI",
 219             "ComboBoxUI", windowsPackageName + "WindowsComboBoxUI",
 220          "TableHeaderUI", windowsPackageName + "WindowsTableHeaderUI",
 221        "InternalFrameUI", windowsPackageName + "WindowsInternalFrameUI",
 222          "DesktopPaneUI", windowsPackageName + "WindowsDesktopPaneUI",
 223          "DesktopIconUI", windowsPackageName + "WindowsDesktopIconUI",
 224          "FileChooserUI", windowsPackageName + "WindowsFileChooserUI",
 225                 "MenuUI", windowsPackageName + "WindowsMenuUI",
 226             "MenuItemUI", windowsPackageName + "WindowsMenuItemUI",
 227              "MenuBarUI", windowsPackageName + "WindowsMenuBarUI",
 228            "PopupMenuUI", windowsPackageName + "WindowsPopupMenuUI",
 229   "PopupMenuSeparatorUI", windowsPackageName + "WindowsPopupMenuSeparatorUI",
 230            "ScrollBarUI", windowsPackageName + "WindowsScrollBarUI",
 231             "RootPaneUI", windowsPackageName + "WindowsRootPaneUI"
 232         };
 233 
 234         table.putDefaults(uiDefaults);
 235     }
 236 
 237     /**
 238      * Load the SystemColors into the defaults table.  The keys
 239      * for SystemColor defaults are the same as the names of
 240      * the public fields in SystemColor.  If the table is being
 241      * created on a native Windows platform we use the SystemColor
 242      * values, otherwise we create color objects whose values match
 243      * the defaults Windows95 colors.
 244      */
 245     protected void initSystemColorDefaults(UIDefaults table)
 246     {
 247         String[] defaultSystemColors = {
 248                 "desktop", "#005C5C", /* Color of the desktop background */
 249           "activeCaption", "#000080", /* Color for captions (title bars) when they are active. */
 250       "activeCaptionText", "#FFFFFF", /* Text color for text in captions (title bars). */
 251     "activeCaptionBorder", "#C0C0C0", /* Border color for caption (title bar) window borders. */
 252         "inactiveCaption", "#808080", /* Color for captions (title bars) when not active. */
 253     "inactiveCaptionText", "#C0C0C0", /* Text color for text in inactive captions (title bars). */
 254   "inactiveCaptionBorder", "#C0C0C0", /* Border color for inactive caption (title bar) window borders. */
 255                  "window", "#FFFFFF", /* Default color for the interior of windows */
 256            "windowBorder", "#000000", /* ??? */
 257              "windowText", "#000000", /* ??? */
 258                    "menu", "#C0C0C0", /* Background color for menus */
 259        "menuPressedItemB", "#000080", /* LightShadow of menubutton highlight */
 260        "menuPressedItemF", "#FFFFFF", /* Default color for foreground "text" in menu item */
 261                "menuText", "#000000", /* Text color for menus  */
 262                    "text", "#C0C0C0", /* Text background color */
 263                "textText", "#000000", /* Text foreground color */
 264           "textHighlight", "#000080", /* Text background color when selected */
 265       "textHighlightText", "#FFFFFF", /* Text color when selected */
 266        "textInactiveText", "#808080", /* Text color when disabled */
 267                 "control", "#C0C0C0", /* Default color for controls (buttons, sliders, etc) */
 268             "controlText", "#000000", /* Default color for text in controls */
 269        "controlHighlight", "#C0C0C0",
 270 
 271   /*"controlHighlight", "#E0E0E0",*/ /* Specular highlight (opposite of the shadow) */
 272      "controlLtHighlight", "#FFFFFF", /* Highlight color for controls */
 273           "controlShadow", "#808080", /* Shadow color for controls */
 274         "controlDkShadow", "#000000", /* Dark shadow color for controls */
 275               "scrollbar", "#E0E0E0", /* Scrollbar background (usually the "track") */
 276                    "info", "#FFFFE1", /* ??? */
 277                "infoText", "#000000"  /* ??? */
 278         };
 279 
 280         loadSystemColors(table, defaultSystemColors, isNativeLookAndFeel());
 281     }
 282 
 283    /**
 284      * Initialize the defaults table with the name of the ResourceBundle
 285      * used for getting localized defaults.
 286      */
 287     private void initResourceBundle(UIDefaults table) {
 288         table.addResourceBundle( "com.sun.java.swing.plaf.windows.resources.windows" );
 289     }
 290 
 291     // XXX - there are probably a lot of redundant values that could be removed.
 292     // ie. Take a look at RadioButtonBorder, etc...
 293     protected void initComponentDefaults(UIDefaults table)
 294     {
 295         super.initComponentDefaults( table );
 296 
 297         initResourceBundle(table);
 298 
 299         // *** Shared Fonts
 300         Integer twelve = Integer.valueOf(12);
 301         Integer fontPlain = Integer.valueOf(Font.PLAIN);
 302         Integer fontBold = Integer.valueOf(Font.BOLD);
 303 
 304         Object dialogPlain12 = new SwingLazyValue(
 305                                "javax.swing.plaf.FontUIResource",
 306                                null,
 307                                new Object[] {Font.DIALOG, fontPlain, twelve});
 308 
 309         Object sansSerifPlain12 =  new SwingLazyValue(
 310                           "javax.swing.plaf.FontUIResource",
 311                           null,
 312                           new Object[] {Font.SANS_SERIF, fontPlain, twelve});
 313         Object monospacedPlain12 = new SwingLazyValue(
 314                           "javax.swing.plaf.FontUIResource",
 315                           null,
 316                           new Object[] {Font.MONOSPACED, fontPlain, twelve});
 317         Object dialogBold12 = new SwingLazyValue(
 318                           "javax.swing.plaf.FontUIResource",
 319                           null,
 320                           new Object[] {Font.DIALOG, fontBold, twelve});
 321 
 322         // *** Colors
 323         // XXX - some of these doens't seem to be used
 324         ColorUIResource red = new ColorUIResource(Color.red);
 325         ColorUIResource black = new ColorUIResource(Color.black);
 326         ColorUIResource white = new ColorUIResource(Color.white);
 327         ColorUIResource gray = new ColorUIResource(Color.gray);
 328         ColorUIResource darkGray = new ColorUIResource(Color.darkGray);
 329         ColorUIResource scrollBarTrackHighlight = darkGray;
 330 
 331         // Set the flag which determines which version of Windows should
 332         // be rendered. This flag only need to be set once.
 333         // if version <= 4.0 then the classic LAF should be loaded.
 334         isClassicWindows = OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_95) <= 0;
 335 
 336         // *** Tree
 337         Object treeExpandedIcon = WindowsTreeUI.ExpandedIcon.createExpandedIcon();
 338 
 339         Object treeCollapsedIcon = WindowsTreeUI.CollapsedIcon.createCollapsedIcon();
 340 
 341 
 342         // *** Text
 343         Object fieldInputMap = new UIDefaults.LazyInputMap(new Object[] {
 344                       "control C", DefaultEditorKit.copyAction,
 345                       "control V", DefaultEditorKit.pasteAction,
 346                       "control X", DefaultEditorKit.cutAction,
 347                            "COPY", DefaultEditorKit.copyAction,
 348                           "PASTE", DefaultEditorKit.pasteAction,
 349                             "CUT", DefaultEditorKit.cutAction,
 350                  "control INSERT", DefaultEditorKit.copyAction,
 351                    "shift INSERT", DefaultEditorKit.pasteAction,
 352                    "shift DELETE", DefaultEditorKit.cutAction,
 353                       "control A", DefaultEditorKit.selectAllAction,
 354              "control BACK_SLASH", "unselect"/*DefaultEditorKit.unselectAction*/,
 355                      "shift LEFT", DefaultEditorKit.selectionBackwardAction,
 356                     "shift RIGHT", DefaultEditorKit.selectionForwardAction,
 357                    "control LEFT", DefaultEditorKit.previousWordAction,
 358                   "control RIGHT", DefaultEditorKit.nextWordAction,
 359              "control shift LEFT", DefaultEditorKit.selectionPreviousWordAction,
 360             "control shift RIGHT", DefaultEditorKit.selectionNextWordAction,
 361                            "HOME", DefaultEditorKit.beginLineAction,
 362                             "END", DefaultEditorKit.endLineAction,
 363                      "shift HOME", DefaultEditorKit.selectionBeginLineAction,
 364                       "shift END", DefaultEditorKit.selectionEndLineAction,
 365                      "BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
 366                "shift BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
 367                          "ctrl H", DefaultEditorKit.deletePrevCharAction,
 368                          "DELETE", DefaultEditorKit.deleteNextCharAction,
 369                     "ctrl DELETE", DefaultEditorKit.deleteNextWordAction,
 370                 "ctrl BACK_SPACE", DefaultEditorKit.deletePrevWordAction,
 371                           "RIGHT", DefaultEditorKit.forwardAction,
 372                            "LEFT", DefaultEditorKit.backwardAction,
 373                        "KP_RIGHT", DefaultEditorKit.forwardAction,
 374                         "KP_LEFT", DefaultEditorKit.backwardAction,
 375                           "ENTER", JTextField.notifyAction,
 376                 "control shift O", "toggle-componentOrientation"/*DefaultEditorKit.toggleComponentOrientation*/
 377         });
 378 
 379         Object passwordInputMap = new UIDefaults.LazyInputMap(new Object[] {
 380                       "control C", DefaultEditorKit.copyAction,
 381                       "control V", DefaultEditorKit.pasteAction,
 382                       "control X", DefaultEditorKit.cutAction,
 383                            "COPY", DefaultEditorKit.copyAction,
 384                           "PASTE", DefaultEditorKit.pasteAction,
 385                             "CUT", DefaultEditorKit.cutAction,
 386                  "control INSERT", DefaultEditorKit.copyAction,
 387                    "shift INSERT", DefaultEditorKit.pasteAction,
 388                    "shift DELETE", DefaultEditorKit.cutAction,
 389                       "control A", DefaultEditorKit.selectAllAction,
 390              "control BACK_SLASH", "unselect"/*DefaultEditorKit.unselectAction*/,
 391                      "shift LEFT", DefaultEditorKit.selectionBackwardAction,
 392                     "shift RIGHT", DefaultEditorKit.selectionForwardAction,
 393                    "control LEFT", DefaultEditorKit.beginLineAction,
 394                   "control RIGHT", DefaultEditorKit.endLineAction,
 395              "control shift LEFT", DefaultEditorKit.selectionBeginLineAction,
 396             "control shift RIGHT", DefaultEditorKit.selectionEndLineAction,
 397                            "HOME", DefaultEditorKit.beginLineAction,
 398                             "END", DefaultEditorKit.endLineAction,
 399                      "shift HOME", DefaultEditorKit.selectionBeginLineAction,
 400                       "shift END", DefaultEditorKit.selectionEndLineAction,
 401                      "BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
 402                "shift BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
 403                          "ctrl H", DefaultEditorKit.deletePrevCharAction,
 404                          "DELETE", DefaultEditorKit.deleteNextCharAction,
 405                           "RIGHT", DefaultEditorKit.forwardAction,
 406                            "LEFT", DefaultEditorKit.backwardAction,
 407                        "KP_RIGHT", DefaultEditorKit.forwardAction,
 408                         "KP_LEFT", DefaultEditorKit.backwardAction,
 409                           "ENTER", JTextField.notifyAction,
 410                 "control shift O", "toggle-componentOrientation"/*DefaultEditorKit.toggleComponentOrientation*/
 411         });
 412 
 413         Object multilineInputMap = new UIDefaults.LazyInputMap(new Object[] {
 414                       "control C", DefaultEditorKit.copyAction,
 415                       "control V", DefaultEditorKit.pasteAction,
 416                       "control X", DefaultEditorKit.cutAction,
 417                            "COPY", DefaultEditorKit.copyAction,
 418                           "PASTE", DefaultEditorKit.pasteAction,
 419                             "CUT", DefaultEditorKit.cutAction,
 420                  "control INSERT", DefaultEditorKit.copyAction,
 421                    "shift INSERT", DefaultEditorKit.pasteAction,
 422                    "shift DELETE", DefaultEditorKit.cutAction,
 423                      "shift LEFT", DefaultEditorKit.selectionBackwardAction,
 424                     "shift RIGHT", DefaultEditorKit.selectionForwardAction,
 425                    "control LEFT", DefaultEditorKit.previousWordAction,
 426                   "control RIGHT", DefaultEditorKit.nextWordAction,
 427              "control shift LEFT", DefaultEditorKit.selectionPreviousWordAction,
 428             "control shift RIGHT", DefaultEditorKit.selectionNextWordAction,
 429                       "control A", DefaultEditorKit.selectAllAction,
 430              "control BACK_SLASH", "unselect"/*DefaultEditorKit.unselectAction*/,
 431                            "HOME", DefaultEditorKit.beginLineAction,
 432                             "END", DefaultEditorKit.endLineAction,
 433                      "shift HOME", DefaultEditorKit.selectionBeginLineAction,
 434                       "shift END", DefaultEditorKit.selectionEndLineAction,
 435                    "control HOME", DefaultEditorKit.beginAction,
 436                     "control END", DefaultEditorKit.endAction,
 437              "control shift HOME", DefaultEditorKit.selectionBeginAction,
 438               "control shift END", DefaultEditorKit.selectionEndAction,
 439                              "UP", DefaultEditorKit.upAction,
 440                            "DOWN", DefaultEditorKit.downAction,
 441                      "BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
 442                "shift BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
 443                          "ctrl H", DefaultEditorKit.deletePrevCharAction,
 444                          "DELETE", DefaultEditorKit.deleteNextCharAction,
 445                     "ctrl DELETE", DefaultEditorKit.deleteNextWordAction,
 446                 "ctrl BACK_SPACE", DefaultEditorKit.deletePrevWordAction,
 447                           "RIGHT", DefaultEditorKit.forwardAction,
 448                            "LEFT", DefaultEditorKit.backwardAction,
 449                        "KP_RIGHT", DefaultEditorKit.forwardAction,
 450                         "KP_LEFT", DefaultEditorKit.backwardAction,
 451                         "PAGE_UP", DefaultEditorKit.pageUpAction,
 452                       "PAGE_DOWN", DefaultEditorKit.pageDownAction,
 453                   "shift PAGE_UP", "selection-page-up",
 454                 "shift PAGE_DOWN", "selection-page-down",
 455              "ctrl shift PAGE_UP", "selection-page-left",
 456            "ctrl shift PAGE_DOWN", "selection-page-right",
 457                        "shift UP", DefaultEditorKit.selectionUpAction,
 458                      "shift DOWN", DefaultEditorKit.selectionDownAction,
 459                           "ENTER", DefaultEditorKit.insertBreakAction,
 460                             "TAB", DefaultEditorKit.insertTabAction,
 461                       "control T", "next-link-action",
 462                 "control shift T", "previous-link-action",
 463                   "control SPACE", "activate-link-action",
 464                 "control shift O", "toggle-componentOrientation"/*DefaultEditorKit.toggleComponentOrientation*/
 465         });
 466 
 467         Object menuItemAcceleratorDelimiter = "+";
 468 
 469         Object ControlBackgroundColor = new DesktopProperty(
 470                                                        "win.3d.backgroundColor",
 471                                                         table.get("control"));
 472         Object ControlLightColor      = new DesktopProperty(
 473                                                        "win.3d.lightColor",
 474                                                         table.get("controlHighlight"));
 475         Object ControlHighlightColor  = new DesktopProperty(
 476                                                        "win.3d.highlightColor",
 477                                                         table.get("controlLtHighlight"));
 478         Object ControlShadowColor     = new DesktopProperty(
 479                                                        "win.3d.shadowColor",
 480                                                         table.get("controlShadow"));
 481         Object ControlDarkShadowColor = new DesktopProperty(
 482                                                        "win.3d.darkShadowColor",
 483                                                         table.get("controlDkShadow"));
 484         Object ControlTextColor       = new DesktopProperty(
 485                                                        "win.button.textColor",
 486                                                         table.get("controlText"));
 487         Object MenuBackgroundColor    = new DesktopProperty(
 488                                                        "win.menu.backgroundColor",
 489                                                         table.get("menu"));
 490         Object MenuBarBackgroundColor = new DesktopProperty(
 491                                                        "win.menubar.backgroundColor",
 492                                                         table.get("menu"));
 493         Object MenuTextColor          = new DesktopProperty(
 494                                                        "win.menu.textColor",
 495                                                         table.get("menuText"));
 496         Object SelectionBackgroundColor = new DesktopProperty(
 497                                                        "win.item.highlightColor",
 498                                                         table.get("textHighlight"));
 499         Object SelectionTextColor     = new DesktopProperty(
 500                                                        "win.item.highlightTextColor",
 501                                                         table.get("textHighlightText"));
 502         Object WindowBackgroundColor  = new DesktopProperty(
 503                                                        "win.frame.backgroundColor",
 504                                                         table.get("window"));
 505         Object WindowTextColor        = new DesktopProperty(
 506                                                        "win.frame.textColor",
 507                                                         table.get("windowText"));
 508         Object WindowBorderWidth      = new DesktopProperty(
 509                                                        "win.frame.sizingBorderWidth",
 510                                                        Integer.valueOf(1));
 511         Object TitlePaneHeight        = new DesktopProperty(
 512                                                        "win.frame.captionHeight",
 513                                                        Integer.valueOf(18));
 514         Object TitleButtonWidth       = new DesktopProperty(
 515                                                        "win.frame.captionButtonWidth",
 516                                                        Integer.valueOf(16));
 517         Object TitleButtonHeight      = new DesktopProperty(
 518                                                        "win.frame.captionButtonHeight",
 519                                                        Integer.valueOf(16));
 520         Object InactiveTextColor      = new DesktopProperty(
 521                                                        "win.text.grayedTextColor",
 522                                                         table.get("textInactiveText"));
 523         Object ScrollbarBackgroundColor = new DesktopProperty(
 524                                                        "win.scrollbar.backgroundColor",
 525                                                         table.get("scrollbar"));
 526         Object buttonFocusColor = new FocusColorProperty();
 527 
 528         Object TextBackground         = new XPColorValue(Part.EP_EDIT, null, Prop.FILLCOLOR,
 529                                                          WindowBackgroundColor);
 530         //The following four lines were commented out as part of bug 4991597
 531         //This code *is* correct, however it differs from WindowsXP and is, apparently
 532         //a Windows XP bug. Until Windows fixes this bug, we shall also exhibit the same
 533         //behavior
 534         //Object ReadOnlyTextBackground = new XPColorValue(Part.EP_EDITTEXT, State.READONLY, Prop.FILLCOLOR,
 535         //                                                 ControlBackgroundColor);
 536         //Object DisabledTextBackground = new XPColorValue(Part.EP_EDITTEXT, State.DISABLED, Prop.FILLCOLOR,
 537         //                                                 ControlBackgroundColor);
 538         Object ReadOnlyTextBackground = ControlBackgroundColor;
 539         Object DisabledTextBackground = ControlBackgroundColor;
 540 
 541         Object MenuFont = dialogPlain12;
 542         Object FixedControlFont = monospacedPlain12;
 543         Object ControlFont = dialogPlain12;
 544         Object MessageFont = dialogPlain12;
 545         Object WindowFont = dialogBold12;
 546         Object ToolTipFont = sansSerifPlain12;
 547         Object IconFont = ControlFont;
 548 
 549         Object scrollBarWidth = new DesktopProperty("win.scrollbar.width", Integer.valueOf(16));
 550 
 551         Object menuBarHeight = new DesktopProperty("win.menu.height", null);
 552 
 553         Object hotTrackingOn = new DesktopProperty("win.item.hotTrackingOn", true);
 554 
 555         Object showMnemonics = new DesktopProperty("win.menu.keyboardCuesOn", Boolean.TRUE);
 556 
 557         if (useSystemFontSettings) {
 558             MenuFont = getDesktopFontValue("win.menu.font", MenuFont);
 559             FixedControlFont = getDesktopFontValue("win.ansiFixed.font", FixedControlFont);
 560             ControlFont = getDesktopFontValue("win.defaultGUI.font", ControlFont);
 561             MessageFont = getDesktopFontValue("win.messagebox.font", MessageFont);
 562             WindowFont = getDesktopFontValue("win.frame.captionFont", WindowFont);
 563             IconFont    = getDesktopFontValue("win.icon.font", IconFont);
 564             ToolTipFont = getDesktopFontValue("win.tooltip.font", ToolTipFont);
 565 
 566             /* Put the desktop AA settings in the defaults.
 567              * JComponent.setUI() retrieves this and makes it available
 568              * as a client property on the JComponent. Use the same key name
 569              * for both client property and UIDefaults.
 570              * Also need to set up listeners for changes in these settings.
 571              */
 572             Object aaTextInfo = SwingUtilities2.AATextInfo.getAATextInfo(true);
 573             table.put(SwingUtilities2.AA_TEXT_PROPERTY_KEY, aaTextInfo);
 574             this.aaSettings =
 575                 new FontDesktopProperty(SunToolkit.DESKTOPFONTHINTS);
 576         }
 577         if (useSystemFontSizeSettings) {
 578             MenuFont = new WindowsFontSizeProperty("win.menu.font.height", Font.DIALOG, Font.PLAIN, 12);
 579             FixedControlFont = new WindowsFontSizeProperty("win.ansiFixed.font.height", Font.MONOSPACED,
 580                        Font.PLAIN, 12);
 581             ControlFont = new WindowsFontSizeProperty("win.defaultGUI.font.height", Font.DIALOG, Font.PLAIN, 12);
 582             MessageFont = new WindowsFontSizeProperty("win.messagebox.font.height", Font.DIALOG, Font.PLAIN, 12);
 583             WindowFont = new WindowsFontSizeProperty("win.frame.captionFont.height", Font.DIALOG, Font.BOLD, 12);
 584             ToolTipFont = new WindowsFontSizeProperty("win.tooltip.font.height", Font.SANS_SERIF, Font.PLAIN, 12);
 585             IconFont    = new WindowsFontSizeProperty("win.icon.font.height", Font.DIALOG, Font.PLAIN, 12);
 586         }
 587 
 588 
 589         if (!(this instanceof WindowsClassicLookAndFeel) &&
 590             (OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
 591              OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) >= 0) &&
 592             AccessController.doPrivileged(new GetPropertyAction("swing.noxp")) == null) {
 593 
 594             // These desktop properties are not used directly, but are needed to
 595             // trigger realoading of UI's.
 596             this.themeActive = new TriggerDesktopProperty("win.xpstyle.themeActive");
 597             this.dllName     = new TriggerDesktopProperty("win.xpstyle.dllName");
 598             this.colorName   = new TriggerDesktopProperty("win.xpstyle.colorName");
 599             this.sizeName    = new TriggerDesktopProperty("win.xpstyle.sizeName");
 600         }
 601 
 602 
 603         Object[] defaults = {
 604             // *** Auditory Feedback
 605             // this key defines which of the various cues to render
 606             // Overridden from BasicL&F. This L&F should play all sounds
 607             // all the time. The infrastructure decides what to play.
 608             // This is disabled until sound bugs can be resolved.
 609             "AuditoryCues.playList", null, // table.get("AuditoryCues.cueList"),
 610 
 611             "Application.useSystemFontSettings", Boolean.valueOf(useSystemFontSettings),
 612 
 613             "TextField.focusInputMap", fieldInputMap,
 614             "PasswordField.focusInputMap", passwordInputMap,
 615             "TextArea.focusInputMap", multilineInputMap,
 616             "TextPane.focusInputMap", multilineInputMap,
 617             "EditorPane.focusInputMap", multilineInputMap,
 618 
 619             // Buttons
 620             "Button.font", ControlFont,
 621             "Button.background", ControlBackgroundColor,
 622             // Button.foreground, Button.shadow, Button.darkShadow,
 623             // Button.disabledForground, and Button.disabledShadow are only
 624             // used for Windows Classic. Windows XP will use colors
 625             // from the current visual style.
 626             "Button.foreground", ControlTextColor,
 627             "Button.shadow", ControlShadowColor,
 628             "Button.darkShadow", ControlDarkShadowColor,
 629             "Button.light", ControlLightColor,
 630             "Button.highlight", ControlHighlightColor,
 631             "Button.disabledForeground", InactiveTextColor,
 632             "Button.disabledShadow", ControlHighlightColor,
 633             "Button.focus", buttonFocusColor,
 634             "Button.dashedRectGapX", new XPValue(Integer.valueOf(3), Integer.valueOf(5)),
 635             "Button.dashedRectGapY", new XPValue(Integer.valueOf(3), Integer.valueOf(4)),
 636             "Button.dashedRectGapWidth", new XPValue(Integer.valueOf(6), Integer.valueOf(10)),
 637             "Button.dashedRectGapHeight", new XPValue(Integer.valueOf(6), Integer.valueOf(8)),
 638             "Button.textShiftOffset", new XPValue(Integer.valueOf(0),
 639                                                   Integer.valueOf(1)),
 640             // W2K keyboard navigation hidding.
 641             "Button.showMnemonics", showMnemonics,
 642             "Button.focusInputMap",
 643                new UIDefaults.LazyInputMap(new Object[] {
 644                             "SPACE", "pressed",
 645                    "released SPACE", "released"
 646                  }),
 647 
 648             "Caret.width",
 649                   new DesktopProperty("win.caret.width", null),
 650 
 651             "CheckBox.font", ControlFont,
 652             "CheckBox.interiorBackground", WindowBackgroundColor,
 653             "CheckBox.background", ControlBackgroundColor,
 654             "CheckBox.foreground", WindowTextColor,
 655             "CheckBox.shadow", ControlShadowColor,
 656             "CheckBox.darkShadow", ControlDarkShadowColor,
 657             "CheckBox.light", ControlLightColor,
 658             "CheckBox.highlight", ControlHighlightColor,
 659             "CheckBox.focus", buttonFocusColor,
 660             "CheckBox.focusInputMap",
 661                new UIDefaults.LazyInputMap(new Object[] {
 662                             "SPACE", "pressed",
 663                    "released SPACE", "released"
 664                  }),
 665             // margin is 2 all the way around, BasicBorders.RadioButtonBorder
 666             // (checkbox uses RadioButtonBorder) is 2 all the way around too.
 667             "CheckBox.totalInsets", new Insets(4, 4, 4, 4),
 668 
 669             "CheckBoxMenuItem.font", MenuFont,
 670             "CheckBoxMenuItem.background", MenuBackgroundColor,
 671             "CheckBoxMenuItem.foreground", MenuTextColor,
 672             "CheckBoxMenuItem.selectionForeground", SelectionTextColor,
 673             "CheckBoxMenuItem.selectionBackground", SelectionBackgroundColor,
 674             "CheckBoxMenuItem.acceleratorForeground", MenuTextColor,
 675             "CheckBoxMenuItem.acceleratorSelectionForeground", SelectionTextColor,
 676             "CheckBoxMenuItem.commandSound", "win.sound.menuCommand",
 677 
 678             "ComboBox.font", ControlFont,
 679             "ComboBox.background", WindowBackgroundColor,
 680             "ComboBox.foreground", WindowTextColor,
 681             "ComboBox.buttonBackground", ControlBackgroundColor,
 682             "ComboBox.buttonShadow", ControlShadowColor,
 683             "ComboBox.buttonDarkShadow", ControlDarkShadowColor,
 684             "ComboBox.buttonHighlight", ControlHighlightColor,
 685             "ComboBox.selectionBackground", SelectionBackgroundColor,
 686             "ComboBox.selectionForeground", SelectionTextColor,
 687             "ComboBox.editorBorder", new XPValue(new EmptyBorder(1,2,1,1),
 688                                                  new EmptyBorder(1,4,1,4)),
 689             "ComboBox.disabledBackground",
 690                         new XPColorValue(Part.CP_COMBOBOX, State.DISABLED,
 691                         Prop.FILLCOLOR, DisabledTextBackground),
 692             "ComboBox.disabledForeground",
 693                         new XPColorValue(Part.CP_COMBOBOX, State.DISABLED,
 694                         Prop.TEXTCOLOR, InactiveTextColor),
 695             "ComboBox.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] {
 696                    "ESCAPE", "hidePopup",
 697                   "PAGE_UP", "pageUpPassThrough",
 698                 "PAGE_DOWN", "pageDownPassThrough",
 699                      "HOME", "homePassThrough",
 700                       "END", "endPassThrough",
 701                      "DOWN", "selectNext2",
 702                   "KP_DOWN", "selectNext2",
 703                        "UP", "selectPrevious2",
 704                     "KP_UP", "selectPrevious2",
 705                     "ENTER", "enterPressed",
 706                        "F4", "togglePopup",
 707                  "alt DOWN", "togglePopup",
 708               "alt KP_DOWN", "togglePopup",
 709                    "alt UP", "togglePopup",
 710                 "alt KP_UP", "togglePopup"
 711               }),
 712 
 713             // DeskTop.
 714             "Desktop.background", new DesktopProperty(
 715                                                  "win.desktop.backgroundColor",
 716                                                   table.get("desktop")),
 717             "Desktop.ancestorInputMap",
 718                new UIDefaults.LazyInputMap(new Object[] {
 719                    "ctrl F5", "restore",
 720                    "ctrl F4", "close",
 721                    "ctrl F7", "move",
 722                    "ctrl F8", "resize",
 723                    "RIGHT", "right",
 724                    "KP_RIGHT", "right",
 725                    "LEFT", "left",
 726                    "KP_LEFT", "left",
 727                    "UP", "up",
 728                    "KP_UP", "up",
 729                    "DOWN", "down",
 730                    "KP_DOWN", "down",
 731                    "ESCAPE", "escape",
 732                    "ctrl F9", "minimize",
 733                    "ctrl F10", "maximize",
 734                    "ctrl F6", "selectNextFrame",
 735                    "ctrl TAB", "selectNextFrame",
 736                    "ctrl alt F6", "selectNextFrame",
 737                    "shift ctrl alt F6", "selectPreviousFrame",
 738                    "ctrl F12", "navigateNext",
 739                    "shift ctrl F12", "navigatePrevious"
 740                }),
 741 
 742             // DesktopIcon
 743             "DesktopIcon.width", Integer.valueOf(160),
 744 
 745             "EditorPane.font", ControlFont,
 746             "EditorPane.background", WindowBackgroundColor,
 747             "EditorPane.foreground", WindowTextColor,
 748             "EditorPane.selectionBackground", SelectionBackgroundColor,
 749             "EditorPane.selectionForeground", SelectionTextColor,
 750             "EditorPane.caretForeground", WindowTextColor,
 751             "EditorPane.inactiveForeground", InactiveTextColor,
 752             "EditorPane.inactiveBackground", WindowBackgroundColor,
 753             "EditorPane.disabledBackground", DisabledTextBackground,
 754 
 755             "FileChooser.homeFolderIcon",  new LazyWindowsIcon(null,
 756                                                                "icons/HomeFolder.gif"),
 757             "FileChooser.listFont", IconFont,
 758             "FileChooser.listViewBackground", new XPColorValue(Part.LVP_LISTVIEW, null, Prop.FILLCOLOR,
 759                                                                WindowBackgroundColor),
 760             "FileChooser.listViewBorder", new XPBorderValue(Part.LVP_LISTVIEW,
 761                                                   new SwingLazyValue(
 762                                                         "javax.swing.plaf.BorderUIResource",
 763                                                         "getLoweredBevelBorderUIResource")),
 764             "FileChooser.listViewIcon",    new LazyWindowsIcon("fileChooserIcon ListView",
 765                                                                "icons/ListView.gif"),
 766             "FileChooser.listViewWindowsStyle", Boolean.TRUE,
 767             "FileChooser.detailsViewIcon", new LazyWindowsIcon("fileChooserIcon DetailsView",
 768                                                                "icons/DetailsView.gif"),
 769             "FileChooser.viewMenuIcon", new LazyWindowsIcon("fileChooserIcon ViewMenu",
 770                                                             "icons/ListView.gif"),
 771             "FileChooser.upFolderIcon",    new LazyWindowsIcon("fileChooserIcon UpFolder",
 772                                                                "icons/UpFolder.gif"),
 773             "FileChooser.newFolderIcon",   new LazyWindowsIcon("fileChooserIcon NewFolder",
 774                                                                "icons/NewFolder.gif"),
 775             "FileChooser.useSystemExtensionHiding", Boolean.TRUE,
 776 
 777             "FileChooser.usesSingleFilePane", Boolean.TRUE,
 778             "FileChooser.noPlacesBar", new DesktopProperty("win.comdlg.noPlacesBar",
 779                                                            Boolean.FALSE),
 780             "FileChooser.ancestorInputMap",
 781                new UIDefaults.LazyInputMap(new Object[] {
 782                      "ESCAPE", "cancelSelection",
 783                      "F2", "editFileName",
 784                      "F5", "refresh",
 785                      "BACK_SPACE", "Go Up"
 786                  }),
 787 
 788             "FileView.directoryIcon", SwingUtilities2.makeIcon(getClass(),
 789                                                                WindowsLookAndFeel.class,
 790                                                                "icons/Directory.gif"),
 791             "FileView.fileIcon", SwingUtilities2.makeIcon(getClass(),
 792                                                           WindowsLookAndFeel.class,
 793                                                           "icons/File.gif"),
 794             "FileView.computerIcon", SwingUtilities2.makeIcon(getClass(),
 795                                                               WindowsLookAndFeel.class,
 796                                                               "icons/Computer.gif"),
 797             "FileView.hardDriveIcon", SwingUtilities2.makeIcon(getClass(),
 798                                                                WindowsLookAndFeel.class,
 799                                                                "icons/HardDrive.gif"),
 800             "FileView.floppyDriveIcon", SwingUtilities2.makeIcon(getClass(),
 801                                                                  WindowsLookAndFeel.class,
 802                                                                  "icons/FloppyDrive.gif"),
 803 
 804             "FormattedTextField.font", ControlFont,
 805             "InternalFrame.titleFont", WindowFont,
 806             "InternalFrame.titlePaneHeight",   TitlePaneHeight,
 807             "InternalFrame.titleButtonWidth",  TitleButtonWidth,
 808             "InternalFrame.titleButtonHeight", TitleButtonHeight,
 809             "InternalFrame.titleButtonToolTipsOn", hotTrackingOn,
 810             "InternalFrame.borderColor", ControlBackgroundColor,
 811             "InternalFrame.borderShadow", ControlShadowColor,
 812             "InternalFrame.borderDarkShadow", ControlDarkShadowColor,
 813             "InternalFrame.borderHighlight", ControlHighlightColor,
 814             "InternalFrame.borderLight", ControlLightColor,
 815             "InternalFrame.borderWidth", WindowBorderWidth,
 816             "InternalFrame.minimizeIconBackground", ControlBackgroundColor,
 817             "InternalFrame.resizeIconHighlight", ControlLightColor,
 818             "InternalFrame.resizeIconShadow", ControlShadowColor,
 819             "InternalFrame.activeBorderColor", new DesktopProperty(
 820                                                        "win.frame.activeBorderColor",
 821                                                        table.get("windowBorder")),
 822             "InternalFrame.inactiveBorderColor", new DesktopProperty(
 823                                                        "win.frame.inactiveBorderColor",
 824                                                        table.get("windowBorder")),
 825             "InternalFrame.activeTitleBackground", new DesktopProperty(
 826                                                         "win.frame.activeCaptionColor",
 827                                                          table.get("activeCaption")),
 828             "InternalFrame.activeTitleGradient", new DesktopProperty(
 829                                                         "win.frame.activeCaptionGradientColor",
 830                                                          table.get("activeCaption")),
 831             "InternalFrame.activeTitleForeground", new DesktopProperty(
 832                                                         "win.frame.captionTextColor",
 833                                                          table.get("activeCaptionText")),
 834             "InternalFrame.inactiveTitleBackground", new DesktopProperty(
 835                                                         "win.frame.inactiveCaptionColor",
 836                                                          table.get("inactiveCaption")),
 837             "InternalFrame.inactiveTitleGradient", new DesktopProperty(
 838                                                         "win.frame.inactiveCaptionGradientColor",
 839                                                          table.get("inactiveCaption")),
 840             "InternalFrame.inactiveTitleForeground", new DesktopProperty(
 841                                                         "win.frame.inactiveCaptionTextColor",
 842                                                          table.get("inactiveCaptionText")),
 843 
 844             "InternalFrame.maximizeIcon",
 845                 WindowsIconFactory.createFrameMaximizeIcon(),
 846             "InternalFrame.minimizeIcon",
 847                 WindowsIconFactory.createFrameMinimizeIcon(),
 848             "InternalFrame.iconifyIcon",
 849                 WindowsIconFactory.createFrameIconifyIcon(),
 850             "InternalFrame.closeIcon",
 851                 WindowsIconFactory.createFrameCloseIcon(),
 852             "InternalFrame.icon",
 853                 new SwingLazyValue(
 854         "com.sun.java.swing.plaf.windows.WindowsInternalFrameTitlePane$ScalableIconUIResource",
 855                     // The constructor takes one arg: an array of UIDefaults.LazyValue
 856                     // representing the icons
 857                     new Object[][] { {
 858                         SwingUtilities2.makeIcon(getClass(), BasicLookAndFeel.class, "icons/JavaCup16.png"),
 859                         SwingUtilities2.makeIcon(getClass(), WindowsLookAndFeel.class, "icons/JavaCup32.png")
 860                     } }),
 861 
 862             // Internal Frame Auditory Cue Mappings
 863             "InternalFrame.closeSound", "win.sound.close",
 864             "InternalFrame.maximizeSound", "win.sound.maximize",
 865             "InternalFrame.minimizeSound", "win.sound.minimize",
 866             "InternalFrame.restoreDownSound", "win.sound.restoreDown",
 867             "InternalFrame.restoreUpSound", "win.sound.restoreUp",
 868 
 869             "InternalFrame.windowBindings", new Object[] {
 870                 "shift ESCAPE", "showSystemMenu",
 871                   "ctrl SPACE", "showSystemMenu",
 872                       "ESCAPE", "hideSystemMenu"},
 873 
 874             // Label
 875             "Label.font", ControlFont,
 876             "Label.background", ControlBackgroundColor,
 877             "Label.foreground", WindowTextColor,
 878             "Label.disabledForeground", InactiveTextColor,
 879             "Label.disabledShadow", ControlHighlightColor,
 880 
 881             // List.
 882             "List.font", ControlFont,
 883             "List.background", WindowBackgroundColor,
 884             "List.foreground", WindowTextColor,
 885             "List.selectionBackground", SelectionBackgroundColor,
 886             "List.selectionForeground", SelectionTextColor,
 887             "List.lockToPositionOnScroll", Boolean.TRUE,
 888             "List.focusInputMap",
 889                new UIDefaults.LazyInputMap(new Object[] {
 890                            "ctrl C", "copy",
 891                            "ctrl V", "paste",
 892                            "ctrl X", "cut",
 893                              "COPY", "copy",
 894                             "PASTE", "paste",
 895                               "CUT", "cut",
 896                    "control INSERT", "copy",
 897                      "shift INSERT", "paste",
 898                      "shift DELETE", "cut",
 899                                "UP", "selectPreviousRow",
 900                             "KP_UP", "selectPreviousRow",
 901                          "shift UP", "selectPreviousRowExtendSelection",
 902                       "shift KP_UP", "selectPreviousRowExtendSelection",
 903                     "ctrl shift UP", "selectPreviousRowExtendSelection",
 904                  "ctrl shift KP_UP", "selectPreviousRowExtendSelection",
 905                           "ctrl UP", "selectPreviousRowChangeLead",
 906                        "ctrl KP_UP", "selectPreviousRowChangeLead",
 907                              "DOWN", "selectNextRow",
 908                           "KP_DOWN", "selectNextRow",
 909                        "shift DOWN", "selectNextRowExtendSelection",
 910                     "shift KP_DOWN", "selectNextRowExtendSelection",
 911                   "ctrl shift DOWN", "selectNextRowExtendSelection",
 912                "ctrl shift KP_DOWN", "selectNextRowExtendSelection",
 913                         "ctrl DOWN", "selectNextRowChangeLead",
 914                      "ctrl KP_DOWN", "selectNextRowChangeLead",
 915                              "LEFT", "selectPreviousColumn",
 916                           "KP_LEFT", "selectPreviousColumn",
 917                        "shift LEFT", "selectPreviousColumnExtendSelection",
 918                     "shift KP_LEFT", "selectPreviousColumnExtendSelection",
 919                   "ctrl shift LEFT", "selectPreviousColumnExtendSelection",
 920                "ctrl shift KP_LEFT", "selectPreviousColumnExtendSelection",
 921                         "ctrl LEFT", "selectPreviousColumnChangeLead",
 922                      "ctrl KP_LEFT", "selectPreviousColumnChangeLead",
 923                             "RIGHT", "selectNextColumn",
 924                          "KP_RIGHT", "selectNextColumn",
 925                       "shift RIGHT", "selectNextColumnExtendSelection",
 926                    "shift KP_RIGHT", "selectNextColumnExtendSelection",
 927                  "ctrl shift RIGHT", "selectNextColumnExtendSelection",
 928               "ctrl shift KP_RIGHT", "selectNextColumnExtendSelection",
 929                        "ctrl RIGHT", "selectNextColumnChangeLead",
 930                     "ctrl KP_RIGHT", "selectNextColumnChangeLead",
 931                              "HOME", "selectFirstRow",
 932                        "shift HOME", "selectFirstRowExtendSelection",
 933                   "ctrl shift HOME", "selectFirstRowExtendSelection",
 934                         "ctrl HOME", "selectFirstRowChangeLead",
 935                               "END", "selectLastRow",
 936                         "shift END", "selectLastRowExtendSelection",
 937                    "ctrl shift END", "selectLastRowExtendSelection",
 938                          "ctrl END", "selectLastRowChangeLead",
 939                           "PAGE_UP", "scrollUp",
 940                     "shift PAGE_UP", "scrollUpExtendSelection",
 941                "ctrl shift PAGE_UP", "scrollUpExtendSelection",
 942                      "ctrl PAGE_UP", "scrollUpChangeLead",
 943                         "PAGE_DOWN", "scrollDown",
 944                   "shift PAGE_DOWN", "scrollDownExtendSelection",
 945              "ctrl shift PAGE_DOWN", "scrollDownExtendSelection",
 946                    "ctrl PAGE_DOWN", "scrollDownChangeLead",
 947                            "ctrl A", "selectAll",
 948                        "ctrl SLASH", "selectAll",
 949                   "ctrl BACK_SLASH", "clearSelection",
 950                             "SPACE", "addToSelection",
 951                        "ctrl SPACE", "toggleAndAnchor",
 952                       "shift SPACE", "extendTo",
 953                  "ctrl shift SPACE", "moveSelectionTo"
 954                  }),
 955 
 956             // PopupMenu
 957             "PopupMenu.font", MenuFont,
 958             "PopupMenu.background", MenuBackgroundColor,
 959             "PopupMenu.foreground", MenuTextColor,
 960             "PopupMenu.popupSound", "win.sound.menuPopup",
 961             "PopupMenu.consumeEventOnClose", Boolean.TRUE,
 962 
 963             // Menus
 964             "Menu.font", MenuFont,
 965             "Menu.foreground", MenuTextColor,
 966             "Menu.background", MenuBackgroundColor,
 967             "Menu.useMenuBarBackgroundForTopLevel", Boolean.TRUE,
 968             "Menu.selectionForeground", SelectionTextColor,
 969             "Menu.selectionBackground", SelectionBackgroundColor,
 970             "Menu.acceleratorForeground", MenuTextColor,
 971             "Menu.acceleratorSelectionForeground", SelectionTextColor,
 972             "Menu.menuPopupOffsetX", Integer.valueOf(0),
 973             "Menu.menuPopupOffsetY", Integer.valueOf(0),
 974             "Menu.submenuPopupOffsetX", Integer.valueOf(-4),
 975             "Menu.submenuPopupOffsetY", Integer.valueOf(-3),
 976             "Menu.crossMenuMnemonic", Boolean.FALSE,
 977             "Menu.preserveTopLevelSelection", Boolean.TRUE,
 978 
 979             // MenuBar.
 980             "MenuBar.font", MenuFont,
 981             "MenuBar.background", new XPValue(MenuBarBackgroundColor,
 982                                               MenuBackgroundColor),
 983             "MenuBar.foreground", MenuTextColor,
 984             "MenuBar.shadow", ControlShadowColor,
 985             "MenuBar.highlight", ControlHighlightColor,
 986             "MenuBar.height", menuBarHeight,
 987             "MenuBar.rolloverEnabled", hotTrackingOn,
 988             "MenuBar.windowBindings", new Object[] {
 989                 "F10", "takeFocus" },
 990 
 991             "MenuItem.font", MenuFont,
 992             "MenuItem.acceleratorFont", MenuFont,
 993             "MenuItem.foreground", MenuTextColor,
 994             "MenuItem.background", MenuBackgroundColor,
 995             "MenuItem.selectionForeground", SelectionTextColor,
 996             "MenuItem.selectionBackground", SelectionBackgroundColor,
 997             "MenuItem.disabledForeground", InactiveTextColor,
 998             "MenuItem.acceleratorForeground", MenuTextColor,
 999             "MenuItem.acceleratorSelectionForeground", SelectionTextColor,
1000             "MenuItem.acceleratorDelimiter", menuItemAcceleratorDelimiter,
1001                  // Menu Item Auditory Cue Mapping
1002             "MenuItem.commandSound", "win.sound.menuCommand",
1003              // indicates that keyboard navigation won't skip disabled menu items
1004             "MenuItem.disabledAreNavigable", Boolean.TRUE,
1005 
1006             "RadioButton.font", ControlFont,
1007             "RadioButton.interiorBackground", WindowBackgroundColor,
1008             "RadioButton.background", ControlBackgroundColor,
1009             "RadioButton.foreground", WindowTextColor,
1010             "RadioButton.shadow", ControlShadowColor,
1011             "RadioButton.darkShadow", ControlDarkShadowColor,
1012             "RadioButton.light", ControlLightColor,
1013             "RadioButton.highlight", ControlHighlightColor,
1014             "RadioButton.focus", buttonFocusColor,
1015             "RadioButton.focusInputMap",
1016                new UIDefaults.LazyInputMap(new Object[] {
1017                           "SPACE", "pressed",
1018                  "released SPACE", "released"
1019               }),
1020             // margin is 2 all the way around, BasicBorders.RadioButtonBorder
1021             // is 2 all the way around too.
1022             "RadioButton.totalInsets", new Insets(4, 4, 4, 4),
1023 
1024 
1025             "RadioButtonMenuItem.font", MenuFont,
1026             "RadioButtonMenuItem.foreground", MenuTextColor,
1027             "RadioButtonMenuItem.background", MenuBackgroundColor,
1028             "RadioButtonMenuItem.selectionForeground", SelectionTextColor,
1029             "RadioButtonMenuItem.selectionBackground", SelectionBackgroundColor,
1030             "RadioButtonMenuItem.disabledForeground", InactiveTextColor,
1031             "RadioButtonMenuItem.acceleratorForeground", MenuTextColor,
1032             "RadioButtonMenuItem.acceleratorSelectionForeground", SelectionTextColor,
1033             "RadioButtonMenuItem.commandSound", "win.sound.menuCommand",
1034 
1035             // OptionPane.
1036             "OptionPane.font", MessageFont,
1037             "OptionPane.messageFont", MessageFont,
1038             "OptionPane.buttonFont", MessageFont,
1039             "OptionPane.background", ControlBackgroundColor,
1040             "OptionPane.foreground", WindowTextColor,
1041             "OptionPane.buttonMinimumWidth", new XPDLUValue(50, 50, SwingConstants.EAST),
1042             "OptionPane.messageForeground", ControlTextColor,
1043             "OptionPane.errorIcon",       new LazyWindowsIcon("optionPaneIcon Error",
1044                                                               "icons/Error.gif"),
1045             "OptionPane.informationIcon", new LazyWindowsIcon("optionPaneIcon Information",
1046                                                               "icons/Inform.gif"),
1047             "OptionPane.questionIcon",    new LazyWindowsIcon("optionPaneIcon Question",
1048                                                               "icons/Question.gif"),
1049             "OptionPane.warningIcon",     new LazyWindowsIcon("optionPaneIcon Warning",
1050                                                               "icons/Warn.gif"),
1051             "OptionPane.windowBindings", new Object[] {
1052                 "ESCAPE", "close" },
1053                  // Option Pane Auditory Cue Mappings
1054             "OptionPane.errorSound", "win.sound.hand", // Error
1055             "OptionPane.informationSound", "win.sound.asterisk", // Info Plain
1056             "OptionPane.questionSound", "win.sound.question", // Question
1057             "OptionPane.warningSound", "win.sound.exclamation", // Warning
1058 
1059             "FormattedTextField.focusInputMap",
1060               new UIDefaults.LazyInputMap(new Object[] {
1061                            "ctrl C", DefaultEditorKit.copyAction,
1062                            "ctrl V", DefaultEditorKit.pasteAction,
1063                            "ctrl X", DefaultEditorKit.cutAction,
1064                              "COPY", DefaultEditorKit.copyAction,
1065                             "PASTE", DefaultEditorKit.pasteAction,
1066                               "CUT", DefaultEditorKit.cutAction,
1067                    "control INSERT", DefaultEditorKit.copyAction,
1068                      "shift INSERT", DefaultEditorKit.pasteAction,
1069                      "shift DELETE", DefaultEditorKit.cutAction,
1070                        "shift LEFT", DefaultEditorKit.selectionBackwardAction,
1071                     "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction,
1072                       "shift RIGHT", DefaultEditorKit.selectionForwardAction,
1073                    "shift KP_RIGHT", DefaultEditorKit.selectionForwardAction,
1074                         "ctrl LEFT", DefaultEditorKit.previousWordAction,
1075                      "ctrl KP_LEFT", DefaultEditorKit.previousWordAction,
1076                        "ctrl RIGHT", DefaultEditorKit.nextWordAction,
1077                     "ctrl KP_RIGHT", DefaultEditorKit.nextWordAction,
1078                   "ctrl shift LEFT", DefaultEditorKit.selectionPreviousWordAction,
1079                "ctrl shift KP_LEFT", DefaultEditorKit.selectionPreviousWordAction,
1080                  "ctrl shift RIGHT", DefaultEditorKit.selectionNextWordAction,
1081               "ctrl shift KP_RIGHT", DefaultEditorKit.selectionNextWordAction,
1082                            "ctrl A", DefaultEditorKit.selectAllAction,
1083                              "HOME", DefaultEditorKit.beginLineAction,
1084                               "END", DefaultEditorKit.endLineAction,
1085                        "shift HOME", DefaultEditorKit.selectionBeginLineAction,
1086                         "shift END", DefaultEditorKit.selectionEndLineAction,
1087                        "BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
1088                  "shift BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
1089                            "ctrl H", DefaultEditorKit.deletePrevCharAction,
1090                            "DELETE", DefaultEditorKit.deleteNextCharAction,
1091                       "ctrl DELETE", DefaultEditorKit.deleteNextWordAction,
1092                   "ctrl BACK_SPACE", DefaultEditorKit.deletePrevWordAction,
1093                             "RIGHT", DefaultEditorKit.forwardAction,
1094                              "LEFT", DefaultEditorKit.backwardAction,
1095                          "KP_RIGHT", DefaultEditorKit.forwardAction,
1096                           "KP_LEFT", DefaultEditorKit.backwardAction,
1097                             "ENTER", JTextField.notifyAction,
1098                   "ctrl BACK_SLASH", "unselect",
1099                    "control shift O", "toggle-componentOrientation",
1100                            "ESCAPE", "reset-field-edit",
1101                                "UP", "increment",
1102                             "KP_UP", "increment",
1103                              "DOWN", "decrement",
1104                           "KP_DOWN", "decrement",
1105               }),
1106             "FormattedTextField.inactiveBackground", ReadOnlyTextBackground,
1107             "FormattedTextField.disabledBackground", DisabledTextBackground,
1108 
1109             // *** Panel
1110             "Panel.font", ControlFont,
1111             "Panel.background", ControlBackgroundColor,
1112             "Panel.foreground", WindowTextColor,
1113 
1114             // *** PasswordField
1115             "PasswordField.font", ControlFont,
1116             "PasswordField.background", TextBackground,
1117             "PasswordField.foreground", WindowTextColor,
1118             "PasswordField.inactiveForeground", InactiveTextColor,      // for disabled
1119             "PasswordField.inactiveBackground", ReadOnlyTextBackground, // for readonly
1120             "PasswordField.disabledBackground", DisabledTextBackground, // for disabled
1121             "PasswordField.selectionBackground", SelectionBackgroundColor,
1122             "PasswordField.selectionForeground", SelectionTextColor,
1123             "PasswordField.caretForeground",WindowTextColor,
1124             "PasswordField.echoChar", new XPValue(new Character((char)0x25CF),
1125                                                   new Character('*')),
1126 
1127             // *** ProgressBar
1128             "ProgressBar.font", ControlFont,
1129             "ProgressBar.foreground",  SelectionBackgroundColor,
1130             "ProgressBar.background", ControlBackgroundColor,
1131             "ProgressBar.shadow", ControlShadowColor,
1132             "ProgressBar.highlight", ControlHighlightColor,
1133             "ProgressBar.selectionForeground", ControlBackgroundColor,
1134             "ProgressBar.selectionBackground", SelectionBackgroundColor,
1135             "ProgressBar.cellLength", Integer.valueOf(7),
1136             "ProgressBar.cellSpacing", Integer.valueOf(2),
1137             "ProgressBar.indeterminateInsets", new Insets(3, 3, 3, 3),
1138 
1139             // *** RootPane.
1140             // These bindings are only enabled when there is a default
1141             // button set on the rootpane.
1142             "RootPane.defaultButtonWindowKeyBindings", new Object[] {
1143                              "ENTER", "press",
1144                     "released ENTER", "release",
1145                         "ctrl ENTER", "press",
1146                "ctrl released ENTER", "release"
1147               },
1148 
1149             // *** ScrollBar.
1150             "ScrollBar.background", ScrollbarBackgroundColor,
1151             "ScrollBar.foreground", ControlBackgroundColor,
1152             "ScrollBar.track", white,
1153             "ScrollBar.trackForeground", ScrollbarBackgroundColor,
1154             "ScrollBar.trackHighlight", black,
1155             "ScrollBar.trackHighlightForeground", scrollBarTrackHighlight,
1156             "ScrollBar.thumb", ControlBackgroundColor,
1157             "ScrollBar.thumbHighlight", ControlHighlightColor,
1158             "ScrollBar.thumbDarkShadow", ControlDarkShadowColor,
1159             "ScrollBar.thumbShadow", ControlShadowColor,
1160             "ScrollBar.width", scrollBarWidth,
1161             "ScrollBar.ancestorInputMap",
1162                new UIDefaults.LazyInputMap(new Object[] {
1163                        "RIGHT", "positiveUnitIncrement",
1164                     "KP_RIGHT", "positiveUnitIncrement",
1165                         "DOWN", "positiveUnitIncrement",
1166                      "KP_DOWN", "positiveUnitIncrement",
1167                    "PAGE_DOWN", "positiveBlockIncrement",
1168               "ctrl PAGE_DOWN", "positiveBlockIncrement",
1169                         "LEFT", "negativeUnitIncrement",
1170                      "KP_LEFT", "negativeUnitIncrement",
1171                           "UP", "negativeUnitIncrement",
1172                        "KP_UP", "negativeUnitIncrement",
1173                      "PAGE_UP", "negativeBlockIncrement",
1174                 "ctrl PAGE_UP", "negativeBlockIncrement",
1175                         "HOME", "minScroll",
1176                          "END", "maxScroll"
1177                  }),
1178 
1179             // *** ScrollPane.
1180             "ScrollPane.font", ControlFont,
1181             "ScrollPane.background", ControlBackgroundColor,
1182             "ScrollPane.foreground", ControlTextColor,
1183             "ScrollPane.ancestorInputMap",
1184                new UIDefaults.LazyInputMap(new Object[] {
1185                            "RIGHT", "unitScrollRight",
1186                         "KP_RIGHT", "unitScrollRight",
1187                             "DOWN", "unitScrollDown",
1188                          "KP_DOWN", "unitScrollDown",
1189                             "LEFT", "unitScrollLeft",
1190                          "KP_LEFT", "unitScrollLeft",
1191                               "UP", "unitScrollUp",
1192                            "KP_UP", "unitScrollUp",
1193                          "PAGE_UP", "scrollUp",
1194                        "PAGE_DOWN", "scrollDown",
1195                     "ctrl PAGE_UP", "scrollLeft",
1196                   "ctrl PAGE_DOWN", "scrollRight",
1197                        "ctrl HOME", "scrollHome",
1198                         "ctrl END", "scrollEnd"
1199                  }),
1200 
1201             // *** Separator
1202             "Separator.background", ControlHighlightColor,
1203             "Separator.foreground", ControlShadowColor,
1204 
1205             // *** Slider.
1206             "Slider.font", ControlFont,
1207             "Slider.foreground", ControlBackgroundColor,
1208             "Slider.background", ControlBackgroundColor,
1209             "Slider.highlight", ControlHighlightColor,
1210             "Slider.shadow", ControlShadowColor,
1211             "Slider.focus", ControlDarkShadowColor,
1212             "Slider.focusInputMap",
1213                new UIDefaults.LazyInputMap(new Object[] {
1214                        "RIGHT", "positiveUnitIncrement",
1215                     "KP_RIGHT", "positiveUnitIncrement",
1216                         "DOWN", "negativeUnitIncrement",
1217                      "KP_DOWN", "negativeUnitIncrement",
1218                    "PAGE_DOWN", "negativeBlockIncrement",
1219                         "LEFT", "negativeUnitIncrement",
1220                      "KP_LEFT", "negativeUnitIncrement",
1221                           "UP", "positiveUnitIncrement",
1222                        "KP_UP", "positiveUnitIncrement",
1223                      "PAGE_UP", "positiveBlockIncrement",
1224                         "HOME", "minScroll",
1225                          "END", "maxScroll"
1226                  }),
1227 
1228             // Spinner
1229             "Spinner.font", ControlFont,
1230             "Spinner.ancestorInputMap",
1231                new UIDefaults.LazyInputMap(new Object[] {
1232                                "UP", "increment",
1233                             "KP_UP", "increment",
1234                              "DOWN", "decrement",
1235                           "KP_DOWN", "decrement",
1236                }),
1237 
1238             // *** SplitPane
1239             "SplitPane.background", ControlBackgroundColor,
1240             "SplitPane.highlight", ControlHighlightColor,
1241             "SplitPane.shadow", ControlShadowColor,
1242             "SplitPane.darkShadow", ControlDarkShadowColor,
1243             "SplitPane.dividerSize", Integer.valueOf(5),
1244             "SplitPane.ancestorInputMap",
1245                new UIDefaults.LazyInputMap(new Object[] {
1246                         "UP", "negativeIncrement",
1247                       "DOWN", "positiveIncrement",
1248                       "LEFT", "negativeIncrement",
1249                      "RIGHT", "positiveIncrement",
1250                      "KP_UP", "negativeIncrement",
1251                    "KP_DOWN", "positiveIncrement",
1252                    "KP_LEFT", "negativeIncrement",
1253                   "KP_RIGHT", "positiveIncrement",
1254                       "HOME", "selectMin",
1255                        "END", "selectMax",
1256                         "F8", "startResize",
1257                         "F6", "toggleFocus",
1258                   "ctrl TAB", "focusOutForward",
1259             "ctrl shift TAB", "focusOutBackward"
1260                }),
1261 
1262             // *** TabbedPane
1263             "TabbedPane.tabsOverlapBorder", new XPValue(Boolean.TRUE, Boolean.FALSE),
1264             "TabbedPane.tabInsets",         new XPValue(new InsetsUIResource(1, 4, 1, 4),
1265                                                         new InsetsUIResource(0, 4, 1, 4)),
1266             "TabbedPane.tabAreaInsets",     new XPValue(new InsetsUIResource(3, 2, 2, 2),
1267                                                         new InsetsUIResource(3, 2, 0, 2)),
1268             "TabbedPane.font", ControlFont,
1269             "TabbedPane.background", ControlBackgroundColor,
1270             "TabbedPane.foreground", ControlTextColor,
1271             "TabbedPane.highlight", ControlHighlightColor,
1272             "TabbedPane.light", ControlLightColor,
1273             "TabbedPane.shadow", ControlShadowColor,
1274             "TabbedPane.darkShadow", ControlDarkShadowColor,
1275             "TabbedPane.focus", ControlTextColor,
1276             "TabbedPane.focusInputMap",
1277               new UIDefaults.LazyInputMap(new Object[] {
1278                          "RIGHT", "navigateRight",
1279                       "KP_RIGHT", "navigateRight",
1280                           "LEFT", "navigateLeft",
1281                        "KP_LEFT", "navigateLeft",
1282                             "UP", "navigateUp",
1283                          "KP_UP", "navigateUp",
1284                           "DOWN", "navigateDown",
1285                        "KP_DOWN", "navigateDown",
1286                      "ctrl DOWN", "requestFocusForVisibleComponent",
1287                   "ctrl KP_DOWN", "requestFocusForVisibleComponent",
1288                 }),
1289             "TabbedPane.ancestorInputMap",
1290                new UIDefaults.LazyInputMap(new Object[] {
1291                          "ctrl TAB", "navigateNext",
1292                    "ctrl shift TAB", "navigatePrevious",
1293                    "ctrl PAGE_DOWN", "navigatePageDown",
1294                      "ctrl PAGE_UP", "navigatePageUp",
1295                           "ctrl UP", "requestFocus",
1296                        "ctrl KP_UP", "requestFocus",
1297                  }),
1298 
1299             // *** Table
1300             "Table.font", ControlFont,
1301             "Table.foreground", ControlTextColor,  // cell text color
1302             "Table.background", WindowBackgroundColor,  // cell background color
1303             "Table.highlight", ControlHighlightColor,
1304             "Table.light", ControlLightColor,
1305             "Table.shadow", ControlShadowColor,
1306             "Table.darkShadow", ControlDarkShadowColor,
1307             "Table.selectionForeground", SelectionTextColor,
1308             "Table.selectionBackground", SelectionBackgroundColor,
1309             "Table.gridColor", gray,  // grid line color
1310             "Table.focusCellBackground", WindowBackgroundColor,
1311             "Table.focusCellForeground", ControlTextColor,
1312             "Table.ancestorInputMap",
1313                new UIDefaults.LazyInputMap(new Object[] {
1314                                "ctrl C", "copy",
1315                                "ctrl V", "paste",
1316                                "ctrl X", "cut",
1317                                  "COPY", "copy",
1318                                 "PASTE", "paste",
1319                                   "CUT", "cut",
1320                        "control INSERT", "copy",
1321                          "shift INSERT", "paste",
1322                          "shift DELETE", "cut",
1323                                 "RIGHT", "selectNextColumn",
1324                              "KP_RIGHT", "selectNextColumn",
1325                           "shift RIGHT", "selectNextColumnExtendSelection",
1326                        "shift KP_RIGHT", "selectNextColumnExtendSelection",
1327                      "ctrl shift RIGHT", "selectNextColumnExtendSelection",
1328                   "ctrl shift KP_RIGHT", "selectNextColumnExtendSelection",
1329                            "ctrl RIGHT", "selectNextColumnChangeLead",
1330                         "ctrl KP_RIGHT", "selectNextColumnChangeLead",
1331                                  "LEFT", "selectPreviousColumn",
1332                               "KP_LEFT", "selectPreviousColumn",
1333                            "shift LEFT", "selectPreviousColumnExtendSelection",
1334                         "shift KP_LEFT", "selectPreviousColumnExtendSelection",
1335                       "ctrl shift LEFT", "selectPreviousColumnExtendSelection",
1336                    "ctrl shift KP_LEFT", "selectPreviousColumnExtendSelection",
1337                             "ctrl LEFT", "selectPreviousColumnChangeLead",
1338                          "ctrl KP_LEFT", "selectPreviousColumnChangeLead",
1339                                  "DOWN", "selectNextRow",
1340                               "KP_DOWN", "selectNextRow",
1341                            "shift DOWN", "selectNextRowExtendSelection",
1342                         "shift KP_DOWN", "selectNextRowExtendSelection",
1343                       "ctrl shift DOWN", "selectNextRowExtendSelection",
1344                    "ctrl shift KP_DOWN", "selectNextRowExtendSelection",
1345                             "ctrl DOWN", "selectNextRowChangeLead",
1346                          "ctrl KP_DOWN", "selectNextRowChangeLead",
1347                                    "UP", "selectPreviousRow",
1348                                 "KP_UP", "selectPreviousRow",
1349                              "shift UP", "selectPreviousRowExtendSelection",
1350                           "shift KP_UP", "selectPreviousRowExtendSelection",
1351                         "ctrl shift UP", "selectPreviousRowExtendSelection",
1352                      "ctrl shift KP_UP", "selectPreviousRowExtendSelection",
1353                               "ctrl UP", "selectPreviousRowChangeLead",
1354                            "ctrl KP_UP", "selectPreviousRowChangeLead",
1355                                  "HOME", "selectFirstColumn",
1356                            "shift HOME", "selectFirstColumnExtendSelection",
1357                       "ctrl shift HOME", "selectFirstRowExtendSelection",
1358                             "ctrl HOME", "selectFirstRow",
1359                                   "END", "selectLastColumn",
1360                             "shift END", "selectLastColumnExtendSelection",
1361                        "ctrl shift END", "selectLastRowExtendSelection",
1362                              "ctrl END", "selectLastRow",
1363                               "PAGE_UP", "scrollUpChangeSelection",
1364                         "shift PAGE_UP", "scrollUpExtendSelection",
1365                    "ctrl shift PAGE_UP", "scrollLeftExtendSelection",
1366                          "ctrl PAGE_UP", "scrollLeftChangeSelection",
1367                             "PAGE_DOWN", "scrollDownChangeSelection",
1368                       "shift PAGE_DOWN", "scrollDownExtendSelection",
1369                  "ctrl shift PAGE_DOWN", "scrollRightExtendSelection",
1370                        "ctrl PAGE_DOWN", "scrollRightChangeSelection",
1371                                   "TAB", "selectNextColumnCell",
1372                             "shift TAB", "selectPreviousColumnCell",
1373                                 "ENTER", "selectNextRowCell",
1374                           "shift ENTER", "selectPreviousRowCell",
1375                                "ctrl A", "selectAll",
1376                            "ctrl SLASH", "selectAll",
1377                       "ctrl BACK_SLASH", "clearSelection",
1378                                "ESCAPE", "cancel",
1379                                    "F2", "startEditing",
1380                                 "SPACE", "addToSelection",
1381                            "ctrl SPACE", "toggleAndAnchor",
1382                           "shift SPACE", "extendTo",
1383                      "ctrl shift SPACE", "moveSelectionTo",
1384                                    "F8", "focusHeader"
1385                  }),
1386             "Table.sortIconHighlight", ControlShadowColor,
1387             "Table.sortIconLight", white,
1388 
1389             "TableHeader.font", ControlFont,
1390             "TableHeader.foreground", ControlTextColor, // header text color
1391             "TableHeader.background", ControlBackgroundColor, // header background
1392             "TableHeader.focusCellBackground",
1393                 new XPValue(XPValue.NULL_VALUE,     // use default bg from XP styles
1394                             WindowBackgroundColor), // or white bg otherwise
1395 
1396             // *** TextArea
1397             "TextArea.font", FixedControlFont,
1398             "TextArea.background", WindowBackgroundColor,
1399             "TextArea.foreground", WindowTextColor,
1400             "TextArea.inactiveForeground", InactiveTextColor,
1401             "TextArea.inactiveBackground", WindowBackgroundColor,
1402             "TextArea.disabledBackground", DisabledTextBackground,
1403             "TextArea.selectionBackground", SelectionBackgroundColor,
1404             "TextArea.selectionForeground", SelectionTextColor,
1405             "TextArea.caretForeground", WindowTextColor,
1406 
1407             // *** TextField
1408             "TextField.font", ControlFont,
1409             "TextField.background", TextBackground,
1410             "TextField.foreground", WindowTextColor,
1411             "TextField.shadow", ControlShadowColor,
1412             "TextField.darkShadow", ControlDarkShadowColor,
1413             "TextField.light", ControlLightColor,
1414             "TextField.highlight", ControlHighlightColor,
1415             "TextField.inactiveForeground", InactiveTextColor,      // for disabled
1416             "TextField.inactiveBackground", ReadOnlyTextBackground, // for readonly
1417             "TextField.disabledBackground", DisabledTextBackground, // for disabled
1418             "TextField.selectionBackground", SelectionBackgroundColor,
1419             "TextField.selectionForeground", SelectionTextColor,
1420             "TextField.caretForeground", WindowTextColor,
1421 
1422             // *** TextPane
1423             "TextPane.font", ControlFont,
1424             "TextPane.background", WindowBackgroundColor,
1425             "TextPane.foreground", WindowTextColor,
1426             "TextPane.selectionBackground", SelectionBackgroundColor,
1427             "TextPane.selectionForeground", SelectionTextColor,
1428             "TextPane.inactiveBackground", WindowBackgroundColor,
1429             "TextPane.disabledBackground", DisabledTextBackground,
1430             "TextPane.caretForeground", WindowTextColor,
1431 
1432             // *** TitledBorder
1433             "TitledBorder.font", ControlFont,
1434             "TitledBorder.titleColor",
1435                         new XPColorValue(Part.BP_GROUPBOX, null, Prop.TEXTCOLOR,
1436                                          WindowTextColor),
1437 
1438             // *** ToggleButton
1439             "ToggleButton.font", ControlFont,
1440             "ToggleButton.background", ControlBackgroundColor,
1441             "ToggleButton.foreground", ControlTextColor,
1442             "ToggleButton.shadow", ControlShadowColor,
1443             "ToggleButton.darkShadow", ControlDarkShadowColor,
1444             "ToggleButton.light", ControlLightColor,
1445             "ToggleButton.highlight", ControlHighlightColor,
1446             "ToggleButton.focus", ControlTextColor,
1447             "ToggleButton.textShiftOffset", Integer.valueOf(1),
1448             "ToggleButton.focusInputMap",
1449               new UIDefaults.LazyInputMap(new Object[] {
1450                             "SPACE", "pressed",
1451                    "released SPACE", "released"
1452                 }),
1453 
1454             // *** ToolBar
1455             "ToolBar.font", MenuFont,
1456             "ToolBar.background", ControlBackgroundColor,
1457             "ToolBar.foreground", ControlTextColor,
1458             "ToolBar.shadow", ControlShadowColor,
1459             "ToolBar.darkShadow", ControlDarkShadowColor,
1460             "ToolBar.light", ControlLightColor,
1461             "ToolBar.highlight", ControlHighlightColor,
1462             "ToolBar.dockingBackground", ControlBackgroundColor,
1463             "ToolBar.dockingForeground", red,
1464             "ToolBar.floatingBackground", ControlBackgroundColor,
1465             "ToolBar.floatingForeground", darkGray,
1466             "ToolBar.ancestorInputMap",
1467                new UIDefaults.LazyInputMap(new Object[] {
1468                         "UP", "navigateUp",
1469                      "KP_UP", "navigateUp",
1470                       "DOWN", "navigateDown",
1471                    "KP_DOWN", "navigateDown",
1472                       "LEFT", "navigateLeft",
1473                    "KP_LEFT", "navigateLeft",
1474                      "RIGHT", "navigateRight",
1475                   "KP_RIGHT", "navigateRight"
1476                  }),
1477             "ToolBar.separatorSize", null,
1478 
1479             // *** ToolTip
1480             "ToolTip.font", ToolTipFont,
1481             "ToolTip.background", new DesktopProperty("win.tooltip.backgroundColor", table.get("info")),
1482             "ToolTip.foreground", new DesktopProperty("win.tooltip.textColor", table.get("infoText")),
1483 
1484         // *** ToolTipManager
1485             "ToolTipManager.enableToolTipMode", "activeApplication",
1486 
1487         // *** Tree
1488             "Tree.selectionBorderColor", black,
1489             "Tree.drawDashedFocusIndicator", Boolean.TRUE,
1490             "Tree.lineTypeDashed", Boolean.TRUE,
1491             "Tree.font", ControlFont,
1492             "Tree.background", WindowBackgroundColor,
1493             "Tree.foreground", WindowTextColor,
1494             "Tree.hash", gray,
1495             "Tree.leftChildIndent", Integer.valueOf(8),
1496             "Tree.rightChildIndent", Integer.valueOf(11),
1497             "Tree.textForeground", WindowTextColor,
1498             "Tree.textBackground", WindowBackgroundColor,
1499             "Tree.selectionForeground", SelectionTextColor,
1500             "Tree.selectionBackground", SelectionBackgroundColor,
1501             "Tree.expandedIcon", treeExpandedIcon,
1502             "Tree.collapsedIcon", treeCollapsedIcon,
1503             "Tree.openIcon",   new ActiveWindowsIcon("win.icon.shellIconBPP",
1504                                    "shell32Icon 5", "icons/TreeOpen.gif"),
1505             "Tree.closedIcon", new ActiveWindowsIcon("win.icon.shellIconBPP",
1506                                    "shell32Icon 4", "icons/TreeClosed.gif"),
1507             "Tree.focusInputMap",
1508                new UIDefaults.LazyInputMap(new Object[] {
1509                                     "ADD", "expand",
1510                                "SUBTRACT", "collapse",
1511                                  "ctrl C", "copy",
1512                                  "ctrl V", "paste",
1513                                  "ctrl X", "cut",
1514                                    "COPY", "copy",
1515                                   "PASTE", "paste",
1516                                     "CUT", "cut",
1517                          "control INSERT", "copy",
1518                            "shift INSERT", "paste",
1519                            "shift DELETE", "cut",
1520                                      "UP", "selectPrevious",
1521                                   "KP_UP", "selectPrevious",
1522                                "shift UP", "selectPreviousExtendSelection",
1523                             "shift KP_UP", "selectPreviousExtendSelection",
1524                           "ctrl shift UP", "selectPreviousExtendSelection",
1525                        "ctrl shift KP_UP", "selectPreviousExtendSelection",
1526                                 "ctrl UP", "selectPreviousChangeLead",
1527                              "ctrl KP_UP", "selectPreviousChangeLead",
1528                                    "DOWN", "selectNext",
1529                                 "KP_DOWN", "selectNext",
1530                              "shift DOWN", "selectNextExtendSelection",
1531                           "shift KP_DOWN", "selectNextExtendSelection",
1532                         "ctrl shift DOWN", "selectNextExtendSelection",
1533                      "ctrl shift KP_DOWN", "selectNextExtendSelection",
1534                               "ctrl DOWN", "selectNextChangeLead",
1535                            "ctrl KP_DOWN", "selectNextChangeLead",
1536                                   "RIGHT", "selectChild",
1537                                "KP_RIGHT", "selectChild",
1538                                    "LEFT", "selectParent",
1539                                 "KP_LEFT", "selectParent",
1540                                 "PAGE_UP", "scrollUpChangeSelection",
1541                           "shift PAGE_UP", "scrollUpExtendSelection",
1542                      "ctrl shift PAGE_UP", "scrollUpExtendSelection",
1543                            "ctrl PAGE_UP", "scrollUpChangeLead",
1544                               "PAGE_DOWN", "scrollDownChangeSelection",
1545                         "shift PAGE_DOWN", "scrollDownExtendSelection",
1546                    "ctrl shift PAGE_DOWN", "scrollDownExtendSelection",
1547                          "ctrl PAGE_DOWN", "scrollDownChangeLead",
1548                                    "HOME", "selectFirst",
1549                              "shift HOME", "selectFirstExtendSelection",
1550                         "ctrl shift HOME", "selectFirstExtendSelection",
1551                               "ctrl HOME", "selectFirstChangeLead",
1552                                     "END", "selectLast",
1553                               "shift END", "selectLastExtendSelection",
1554                          "ctrl shift END", "selectLastExtendSelection",
1555                                "ctrl END", "selectLastChangeLead",
1556                                      "F2", "startEditing",
1557                                  "ctrl A", "selectAll",
1558                              "ctrl SLASH", "selectAll",
1559                         "ctrl BACK_SLASH", "clearSelection",
1560                               "ctrl LEFT", "scrollLeft",
1561                            "ctrl KP_LEFT", "scrollLeft",
1562                              "ctrl RIGHT", "scrollRight",
1563                           "ctrl KP_RIGHT", "scrollRight",
1564                                   "SPACE", "addToSelection",
1565                              "ctrl SPACE", "toggleAndAnchor",
1566                             "shift SPACE", "extendTo",
1567                        "ctrl shift SPACE", "moveSelectionTo"
1568                  }),
1569             "Tree.ancestorInputMap",
1570                new UIDefaults.LazyInputMap(new Object[] {
1571                      "ESCAPE", "cancel"
1572                  }),
1573 
1574             // *** Viewport
1575             "Viewport.font", ControlFont,
1576             "Viewport.background", ControlBackgroundColor,
1577             "Viewport.foreground", WindowTextColor,
1578 
1579 
1580         };
1581 
1582         table.putDefaults(defaults);
1583         table.putDefaults(getLazyValueDefaults());
1584         initVistaComponentDefaults(table);
1585     }
1586 
1587     static boolean isOnVista() {
1588         return OSInfo.getOSType() == OSInfo.OSType.WINDOWS
1589                 && OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_VISTA) >= 0;
1590     }
1591 
1592     private void initVistaComponentDefaults(UIDefaults table) {
1593         if (! isOnVista()) {
1594             return;
1595         }
1596         /* START handling menus for Vista */
1597         String[] menuClasses = { "MenuItem", "Menu",
1598                 "CheckBoxMenuItem", "RadioButtonMenuItem",
1599         };
1600 
1601         Object menuDefaults[] = new Object[menuClasses.length * 2];
1602 
1603         /* all the menus need to be non opaque. */
1604         for (int i = 0, j = 0; i < menuClasses.length; i++) {
1605             String key = menuClasses[i] + ".opaque";
1606             Object oldValue = table.get(key);
1607             menuDefaults[j++] = key;
1608             menuDefaults[j++] =
1609                 new XPValue(Boolean.FALSE, oldValue);
1610         }
1611         table.putDefaults(menuDefaults);
1612 
1613         /*
1614          * acceleratorSelectionForeground color is the same as
1615          * acceleratorForeground
1616          */
1617         for (int i = 0, j = 0; i < menuClasses.length; i++) {
1618             String key = menuClasses[i] + ".acceleratorSelectionForeground";
1619             Object oldValue = table.get(key);
1620             menuDefaults[j++] = key;
1621             menuDefaults[j++] =
1622                 new XPValue(
1623                     table.getColor(
1624                         menuClasses[i] + ".acceleratorForeground"),
1625                         oldValue);
1626         }
1627         table.putDefaults(menuDefaults);
1628 
1629         /* they have the same MenuItemCheckIconFactory */
1630         VistaMenuItemCheckIconFactory menuItemCheckIconFactory =
1631             WindowsIconFactory.getMenuItemCheckIconFactory();
1632         for (int i = 0, j = 0; i < menuClasses.length; i++) {
1633             String key = menuClasses[i] + ".checkIconFactory";
1634             Object oldValue = table.get(key);
1635             menuDefaults[j++] = key;
1636             menuDefaults[j++] =
1637                 new XPValue(menuItemCheckIconFactory, oldValue);
1638         }
1639         table.putDefaults(menuDefaults);
1640 
1641         for (int i = 0, j = 0; i < menuClasses.length; i++) {
1642             String key = menuClasses[i] + ".checkIcon";
1643             Object oldValue = table.get(key);
1644             menuDefaults[j++] = key;
1645             menuDefaults[j++] =
1646                 new XPValue(menuItemCheckIconFactory.getIcon(menuClasses[i]),
1647                     oldValue);
1648         }
1649         table.putDefaults(menuDefaults);
1650 
1651 
1652         /* height can be even */
1653         for (int i = 0, j = 0; i < menuClasses.length; i++) {
1654             String key = menuClasses[i] + ".evenHeight";
1655             Object oldValue = table.get(key);
1656             menuDefaults[j++] = key;
1657             menuDefaults[j++] = new XPValue(Boolean.TRUE, oldValue);
1658         }
1659         table.putDefaults(menuDefaults);
1660 
1661         /* no margins */
1662         InsetsUIResource insets = new InsetsUIResource(0, 0, 0, 0);
1663         for (int i = 0, j = 0; i < menuClasses.length; i++) {
1664             String key = menuClasses[i] + ".margin";
1665             Object oldValue = table.get(key);
1666             menuDefaults[j++] = key;
1667             menuDefaults[j++] = new XPValue(insets, oldValue);
1668         }
1669         table.putDefaults(menuDefaults);
1670 
1671         /* set checkIcon offset */
1672         Integer checkIconOffsetInteger =
1673             Integer.valueOf(0);
1674         for (int i = 0, j = 0; i < menuClasses.length; i++) {
1675             String key = menuClasses[i] + ".checkIconOffset";
1676             Object oldValue = table.get(key);
1677             menuDefaults[j++] = key;
1678             menuDefaults[j++] =
1679                 new XPValue(checkIconOffsetInteger, oldValue);
1680         }
1681         table.putDefaults(menuDefaults);
1682 
1683         /* set width of the gap after check icon */
1684         Integer afterCheckIconGap = WindowsPopupMenuUI.getSpanBeforeGutter()
1685                 + WindowsPopupMenuUI.getGutterWidth()
1686                 + WindowsPopupMenuUI.getSpanAfterGutter();
1687         for (int i = 0, j = 0; i < menuClasses.length; i++) {
1688             String key = menuClasses[i] + ".afterCheckIconGap";
1689             Object oldValue = table.get(key);
1690             menuDefaults[j++] = key;
1691             menuDefaults[j++] =
1692                 new XPValue(afterCheckIconGap, oldValue);
1693         }
1694         table.putDefaults(menuDefaults);
1695 
1696         /* text is started after this position */
1697         Object minimumTextOffset = new UIDefaults.ActiveValue() {
1698             public Object createValue(UIDefaults table) {
1699                 return VistaMenuItemCheckIconFactory.getIconWidth()
1700                 + WindowsPopupMenuUI.getSpanBeforeGutter()
1701                 + WindowsPopupMenuUI.getGutterWidth()
1702                 + WindowsPopupMenuUI.getSpanAfterGutter();
1703             }
1704         };
1705         for (int i = 0, j = 0; i < menuClasses.length; i++) {
1706             String key = menuClasses[i] + ".minimumTextOffset";
1707             Object oldValue = table.get(key);
1708             menuDefaults[j++] = key;
1709             menuDefaults[j++] = new XPValue(minimumTextOffset, oldValue);
1710         }
1711         table.putDefaults(menuDefaults);
1712 
1713         /*
1714          * JPopupMenu has a bit of free space around menu items
1715          */
1716         String POPUP_MENU_BORDER = "PopupMenu.border";
1717 
1718         Object popupMenuBorder = new XPBorderValue(Part.MENU,
1719                 new SwingLazyValue(
1720                   "javax.swing.plaf.basic.BasicBorders",
1721                   "getInternalFrameBorder"),
1722                   BorderFactory.createEmptyBorder(2, 2, 2, 2));
1723         table.put(POPUP_MENU_BORDER, popupMenuBorder);
1724         /* END handling menus for Vista */
1725 
1726         /* START table handling for Vista */
1727         table.put("Table.ascendingSortIcon", new XPValue(
1728             new SkinIcon(Part.HP_HEADERSORTARROW, State.SORTEDDOWN),
1729             new SwingLazyValue(
1730                 "sun.swing.plaf.windows.ClassicSortArrowIcon",
1731                 null, new Object[] { Boolean.TRUE })));
1732         table.put("Table.descendingSortIcon", new XPValue(
1733             new SkinIcon(Part.HP_HEADERSORTARROW, State.SORTEDUP),
1734             new SwingLazyValue(
1735                 "sun.swing.plaf.windows.ClassicSortArrowIcon",
1736                 null, new Object[] { Boolean.FALSE })));
1737         /* END table handling for Vista */
1738     }
1739 
1740     /**
1741      * If we support loading of fonts from the desktop this will return
1742      * a DesktopProperty representing the font. If the font can't be
1743      * represented in the current encoding this will return null and
1744      * turn off the use of system fonts.
1745      */
1746     private Object getDesktopFontValue(String fontName, Object backup) {
1747         if (useSystemFontSettings) {
1748             return new WindowsFontProperty(fontName, backup);
1749         }
1750         return null;
1751     }
1752 
1753     // When a desktop property change is detected, these classes must be
1754     // reinitialized in the defaults table to ensure the classes reference
1755     // the updated desktop property values (colors mostly)
1756     //
1757     private Object[] getLazyValueDefaults() {
1758 
1759         Object buttonBorder =
1760             new XPBorderValue(Part.BP_PUSHBUTTON,
1761                               new SwingLazyValue(
1762                                "javax.swing.plaf.basic.BasicBorders",
1763                                "getButtonBorder"));
1764 
1765         Object textFieldBorder =
1766             new XPBorderValue(Part.EP_EDIT,
1767                               new SwingLazyValue(
1768                                "javax.swing.plaf.basic.BasicBorders",
1769                                "getTextFieldBorder"));
1770 
1771         Object textFieldMargin =
1772             new XPValue(new InsetsUIResource(2, 2, 2, 2),
1773                         new InsetsUIResource(1, 1, 1, 1));
1774 
1775         Object spinnerBorder =
1776             new XPBorderValue(Part.EP_EDIT, textFieldBorder,
1777                               new EmptyBorder(2, 2, 2, 2));
1778 
1779         Object spinnerArrowInsets =
1780             new XPValue(new InsetsUIResource(1, 1, 1, 1),
1781                         null);
1782 
1783         Object comboBoxBorder = new XPBorderValue(Part.CP_COMBOBOX, textFieldBorder);
1784 
1785         // For focus rectangle for cells and trees.
1786         Object focusCellHighlightBorder = new SwingLazyValue(
1787                           "com.sun.java.swing.plaf.windows.WindowsBorders",
1788                           "getFocusCellHighlightBorder");
1789 
1790         Object etchedBorder = new SwingLazyValue(
1791                           "javax.swing.plaf.BorderUIResource",
1792                           "getEtchedBorderUIResource");
1793 
1794         Object internalFrameBorder = new SwingLazyValue(
1795                 "com.sun.java.swing.plaf.windows.WindowsBorders",
1796                 "getInternalFrameBorder");
1797 
1798         Object loweredBevelBorder = new SwingLazyValue(
1799                           "javax.swing.plaf.BorderUIResource",
1800                           "getLoweredBevelBorderUIResource");
1801 
1802 
1803         Object marginBorder = new SwingLazyValue(
1804                             "javax.swing.plaf.basic.BasicBorders$MarginBorder");
1805 
1806         Object menuBarBorder = new SwingLazyValue(
1807                 "javax.swing.plaf.basic.BasicBorders",
1808                 "getMenuBarBorder");
1809 
1810 
1811         Object popupMenuBorder = new XPBorderValue(Part.MENU,
1812                         new SwingLazyValue(
1813                           "javax.swing.plaf.basic.BasicBorders",
1814                           "getInternalFrameBorder"));
1815 
1816         // *** ProgressBar
1817         Object progressBarBorder = new SwingLazyValue(
1818                               "com.sun.java.swing.plaf.windows.WindowsBorders",
1819                               "getProgressBarBorder");
1820 
1821         Object radioButtonBorder = new SwingLazyValue(
1822                                "javax.swing.plaf.basic.BasicBorders",
1823                                "getRadioButtonBorder");
1824 
1825         Object scrollPaneBorder =
1826             new XPBorderValue(Part.LBP_LISTBOX, textFieldBorder);
1827 
1828         Object tableScrollPaneBorder =
1829             new XPBorderValue(Part.LBP_LISTBOX, loweredBevelBorder);
1830 
1831         Object tableHeaderBorder = new SwingLazyValue(
1832                           "com.sun.java.swing.plaf.windows.WindowsBorders",
1833                           "getTableHeaderBorder");
1834 
1835         // *** ToolBar
1836         Object toolBarBorder = new SwingLazyValue(
1837                               "com.sun.java.swing.plaf.windows.WindowsBorders",
1838                               "getToolBarBorder");
1839 
1840         // *** ToolTips
1841         Object toolTipBorder = new SwingLazyValue(
1842                               "javax.swing.plaf.BorderUIResource",
1843                               "getBlackLineBorderUIResource");
1844 
1845 
1846 
1847         Object checkBoxIcon = new SwingLazyValue(
1848                      "com.sun.java.swing.plaf.windows.WindowsIconFactory",
1849                      "getCheckBoxIcon");
1850 
1851         Object radioButtonIcon = new SwingLazyValue(
1852                      "com.sun.java.swing.plaf.windows.WindowsIconFactory",
1853                      "getRadioButtonIcon");
1854 
1855         Object radioButtonMenuItemIcon = new SwingLazyValue(
1856                      "com.sun.java.swing.plaf.windows.WindowsIconFactory",
1857                      "getRadioButtonMenuItemIcon");
1858 
1859         Object menuItemCheckIcon = new SwingLazyValue(
1860                      "com.sun.java.swing.plaf.windows.WindowsIconFactory",
1861                      "getMenuItemCheckIcon");
1862 
1863         Object menuItemArrowIcon = new SwingLazyValue(
1864                      "com.sun.java.swing.plaf.windows.WindowsIconFactory",
1865                      "getMenuItemArrowIcon");
1866 
1867         Object menuArrowIcon = new SwingLazyValue(
1868                      "com.sun.java.swing.plaf.windows.WindowsIconFactory",
1869                      "getMenuArrowIcon");
1870 
1871 
1872         Object[] lazyDefaults = {
1873             "Button.border", buttonBorder,
1874             "CheckBox.border", radioButtonBorder,
1875             "ComboBox.border", comboBoxBorder,
1876             "DesktopIcon.border", internalFrameBorder,
1877             "FormattedTextField.border", textFieldBorder,
1878             "FormattedTextField.margin", textFieldMargin,
1879             "InternalFrame.border", internalFrameBorder,
1880             "List.focusCellHighlightBorder", focusCellHighlightBorder,
1881             "Table.focusCellHighlightBorder", focusCellHighlightBorder,
1882             "Menu.border", marginBorder,
1883             "MenuBar.border", menuBarBorder,
1884             "MenuItem.border", marginBorder,
1885             "PasswordField.border", textFieldBorder,
1886             "PasswordField.margin", textFieldMargin,
1887             "PopupMenu.border", popupMenuBorder,
1888             "ProgressBar.border", progressBarBorder,
1889             "RadioButton.border", radioButtonBorder,
1890             "ScrollPane.border", scrollPaneBorder,
1891             "Spinner.border", spinnerBorder,
1892             "Spinner.arrowButtonInsets", spinnerArrowInsets,
1893             "Spinner.arrowButtonSize", new Dimension(17, 9),
1894             "Table.scrollPaneBorder", tableScrollPaneBorder,
1895             "TableHeader.cellBorder", tableHeaderBorder,
1896             "TextArea.margin", textFieldMargin,
1897             "TextField.border", textFieldBorder,
1898             "TextField.margin", textFieldMargin,
1899             "TitledBorder.border",
1900                         new XPBorderValue(Part.BP_GROUPBOX, etchedBorder),
1901             "ToggleButton.border", radioButtonBorder,
1902             "ToolBar.border", toolBarBorder,
1903             "ToolTip.border", toolTipBorder,
1904 
1905             "CheckBox.icon", checkBoxIcon,
1906             "Menu.arrowIcon", menuArrowIcon,
1907             "MenuItem.checkIcon", menuItemCheckIcon,
1908             "MenuItem.arrowIcon", menuItemArrowIcon,
1909             "RadioButton.icon", radioButtonIcon,
1910             "RadioButtonMenuItem.checkIcon", radioButtonMenuItemIcon,
1911             "InternalFrame.layoutTitlePaneAtOrigin",
1912                         new XPValue(Boolean.TRUE, Boolean.FALSE),
1913             "Table.ascendingSortIcon", new XPValue(
1914                   new SwingLazyValue(
1915                      "sun.swing.icon.SortArrowIcon",
1916                      null, new Object[] { Boolean.TRUE,
1917                                           "Table.sortIconColor" }),
1918                   new SwingLazyValue(
1919                       "sun.swing.plaf.windows.ClassicSortArrowIcon",
1920                       null, new Object[] { Boolean.TRUE })),
1921             "Table.descendingSortIcon", new XPValue(
1922                   new SwingLazyValue(
1923                      "sun.swing.icon.SortArrowIcon",
1924                      null, new Object[] { Boolean.FALSE,
1925                                           "Table.sortIconColor" }),
1926                   new SwingLazyValue(
1927                      "sun.swing.plaf.windows.ClassicSortArrowIcon",
1928                      null, new Object[] { Boolean.FALSE })),
1929         };
1930 
1931         return lazyDefaults;
1932     }
1933 
1934     public void uninitialize() {
1935         super.uninitialize();
1936 
1937         if (WindowsPopupMenuUI.mnemonicListener != null) {
1938             MenuSelectionManager.defaultManager().
1939                 removeChangeListener(WindowsPopupMenuUI.mnemonicListener);
1940         }
1941         KeyboardFocusManager.getCurrentKeyboardFocusManager().
1942             removeKeyEventPostProcessor(WindowsRootPaneUI.altProcessor);
1943         DesktopProperty.flushUnreferencedProperties();
1944     }
1945 
1946 
1947     // Toggle flag for drawing the mnemonic state
1948     private static boolean isMnemonicHidden = true;
1949 
1950     // Flag which indicates that the Win98/Win2k/WinME features
1951     // should be disabled.
1952     private static boolean isClassicWindows = false;
1953 
1954     /**
1955      * Sets the state of the hide mnemonic flag. This flag is used by the
1956      * component UI delegates to determine if the mnemonic should be rendered.
1957      * This method is a non operation if the underlying operating system
1958      * does not support the mnemonic hiding feature.
1959      *
1960      * @param hide true if mnemonics should be hidden
1961      * @since 1.4
1962      */
1963     public static void setMnemonicHidden(boolean hide) {
1964         if (UIManager.getBoolean("Button.showMnemonics") == true) {
1965             // Do not hide mnemonics if the UI defaults do not support this
1966             isMnemonicHidden = false;
1967         } else {
1968             isMnemonicHidden = hide;
1969         }
1970     }
1971 
1972     /**
1973      * Gets the state of the hide mnemonic flag. This only has meaning
1974      * if this feature is supported by the underlying OS.
1975      *
1976      * @return true if mnemonics are hidden, otherwise, false
1977      * @see #setMnemonicHidden
1978      * @since 1.4
1979      */
1980     public static boolean isMnemonicHidden() {
1981         if (UIManager.getBoolean("Button.showMnemonics") == true) {
1982             // Do not hide mnemonics if the UI defaults do not support this
1983             isMnemonicHidden = false;
1984         }
1985         return isMnemonicHidden;
1986     }
1987 
1988     /**
1989      * Gets the state of the flag which indicates if the old Windows
1990      * look and feel should be rendered. This flag is used by the
1991      * component UI delegates as a hint to determine which style the component
1992      * should be rendered.
1993      *
1994      * @return true if Windows 95 and Windows NT 4 look and feel should
1995      *         be rendered
1996      * @since 1.4
1997      */
1998     public static boolean isClassicWindows() {
1999         return isClassicWindows;
2000     }
2001 
2002     /**
2003      * <p>
2004      * Invoked when the user attempts an invalid operation,
2005      * such as pasting into an uneditable <code>JTextField</code>
2006      * that has focus.
2007      * </p>
2008      * <p>
2009      * If the user has enabled visual error indication on
2010      * the desktop, this method will flash the caption bar
2011      * of the active window. The user can also set the
2012      * property awt.visualbell=true to achieve the same
2013      * results.
2014      * </p>
2015      *
2016      * @param component Component the error occured in, may be
2017      *                  null indicating the error condition is
2018      *                  not directly associated with a
2019      *                  <code>Component</code>.
2020      *
2021      * @see javax.swing.LookAndFeel#provideErrorFeedback
2022      */
2023      public void provideErrorFeedback(Component component) {
2024          super.provideErrorFeedback(component);
2025      }
2026 
2027     /**
2028      * {@inheritDoc}
2029      */
2030     public LayoutStyle getLayoutStyle() {
2031         LayoutStyle style = this.style;
2032         if (style == null) {
2033             style = new WindowsLayoutStyle();
2034             this.style = style;
2035         }
2036         return style;
2037     }
2038 
2039     // ********* Auditory Cue support methods and objects *********
2040 
2041     /**
2042      * Returns an <code>Action</code>.
2043      * <P>
2044      * This Action contains the information and logic to render an
2045      * auditory cue. The <code>Object</code> that is passed to this
2046      * method contains the information needed to render the auditory
2047      * cue. Normally, this <code>Object</code> is a <code>String</code>
2048      * that points to a <code>Toolkit</code> <code>desktopProperty</code>.
2049      * This <code>desktopProperty</code> is resolved by AWT and the
2050      * Windows OS.
2051      * <P>
2052      * This <code>Action</code>'s <code>actionPerformed</code> method
2053      * is fired by the <code>playSound</code> method.
2054      *
2055      * @return      an Action which knows how to render the auditory
2056      *              cue for one particular system or user activity
2057      * @see #playSound(Action)
2058      * @since 1.4
2059      */
2060     protected Action createAudioAction(Object key) {
2061         if (key != null) {
2062             String audioKey = (String)key;
2063             String audioValue = (String)UIManager.get(key);
2064             return new AudioAction(audioKey, audioValue);
2065         } else {
2066             return null;
2067         }
2068     }
2069 
2070     static void repaintRootPane(Component c) {
2071         JRootPane root = null;
2072         for (; c != null; c = c.getParent()) {
2073             if (c instanceof JRootPane) {
2074                 root = (JRootPane)c;
2075             }
2076         }
2077 
2078         if (root != null) {
2079             root.repaint();
2080         } else {
2081             c.repaint();
2082         }
2083     }
2084 
2085     /**
2086      * Pass the name String to the super constructor. This is used
2087      * later to identify the Action and decide whether to play it or
2088      * not. Store the resource String. It is used to get the audio
2089      * resource. In this case, the resource is a <code>Runnable</code>
2090      * supplied by <code>Toolkit</code>. This <code>Runnable</code> is
2091      * effectively a pointer down into the Win32 OS that knows how to
2092      * play the right sound.
2093      *
2094      * @since 1.4
2095      */
2096     private static class AudioAction extends AbstractAction {
2097         private Runnable audioRunnable;
2098         private String audioResource;
2099         /**
2100          * We use the String as the name of the Action and as a pointer to
2101          * the underlying OSes audio resource.
2102          */
2103         public AudioAction(String name, String resource) {
2104             super(name);
2105             audioResource = resource;
2106         }
2107         public void actionPerformed(ActionEvent e) {
2108             if (audioRunnable == null) {
2109                 audioRunnable = (Runnable)Toolkit.getDefaultToolkit().getDesktopProperty(audioResource);
2110             }
2111             if (audioRunnable != null) {
2112                 // Runnable appears to block until completed playing, hence
2113                 // start up another thread to handle playing.
2114                 new Thread(audioRunnable).start();
2115             }
2116         }
2117     }
2118 
2119     /**
2120      * Gets an <code>Icon</code> from the native libraries if available,
2121      * otherwise gets it from an image resource file.
2122      */
2123     private static class LazyWindowsIcon implements UIDefaults.LazyValue {
2124         private String nativeImage;
2125         private String resource;
2126 
2127         LazyWindowsIcon(String nativeImage, String resource) {
2128             this.nativeImage = nativeImage;
2129             this.resource = resource;
2130         }
2131 
2132         public Object createValue(UIDefaults table) {
2133             if (nativeImage != null) {
2134                 Image image = (Image)ShellFolder.get(nativeImage);
2135                 if (image != null) {
2136                     return new ImageIcon(image);
2137                 }
2138             }
2139             return SwingUtilities2.makeIcon(getClass(),
2140                                             WindowsLookAndFeel.class,
2141                                             resource);
2142         }
2143     }
2144 
2145 
2146     /**
2147      * Gets an <code>Icon</code> from the native libraries if available.
2148      * A desktop property is used to trigger reloading the icon when needed.
2149      */
2150     private class ActiveWindowsIcon implements UIDefaults.ActiveValue {
2151         private Icon icon;
2152         private String nativeImageName;
2153         private String fallbackName;
2154         private DesktopProperty desktopProperty;
2155 
2156         ActiveWindowsIcon(String desktopPropertyName,
2157                             String nativeImageName, String fallbackName) {
2158             this.nativeImageName = nativeImageName;
2159             this.fallbackName = fallbackName;
2160 
2161             if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
2162                     OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) < 0) {
2163                 // This desktop property is needed to trigger reloading the icon.
2164                 // It is kept in member variable to avoid GC.
2165                 this.desktopProperty = new TriggerDesktopProperty(desktopPropertyName) {
2166                     @Override protected void updateUI() {
2167                         icon = null;
2168                         super.updateUI();
2169                     }
2170                 };
2171             }
2172         }
2173 
2174         @Override
2175         public Object createValue(UIDefaults table) {
2176             if (icon == null) {
2177                 Image image = (Image)ShellFolder.get(nativeImageName);
2178                 if (image != null) {
2179                     icon = new ImageIconUIResource(image);
2180                 }
2181             }
2182             if (icon == null && fallbackName != null) {
2183                 UIDefaults.LazyValue fallback = (UIDefaults.LazyValue)
2184                         SwingUtilities2.makeIcon(WindowsLookAndFeel.class,
2185                             BasicLookAndFeel.class, fallbackName);
2186                 icon = (Icon) fallback.createValue(table);
2187             }
2188             return icon;
2189         }
2190     }
2191 
2192     /**
2193      * Icon backed-up by XP Skin.
2194      */
2195     private static class SkinIcon implements Icon, UIResource {
2196         private final Part part;
2197         private final State state;
2198         SkinIcon(Part part, State state) {
2199             this.part = part;
2200             this.state = state;
2201         }
2202 
2203         /**
2204          * Draw the icon at the specified location.  Icon implementations
2205          * may use the Component argument to get properties useful for
2206          * painting, e.g. the foreground or background color.
2207          */
2208         public void paintIcon(Component c, Graphics g, int x, int y) {
2209             XPStyle xp = XPStyle.getXP();
2210             assert xp != null;
2211             if (xp != null) {
2212                 Skin skin = xp.getSkin(null, part);
2213                 skin.paintSkin(g, x, y, state);
2214             }
2215         }
2216 
2217         /**
2218          * Returns the icon's width.
2219          *
2220          * @return an int specifying the fixed width of the icon.
2221          */
2222         public int getIconWidth() {
2223             int width = 0;
2224             XPStyle xp = XPStyle.getXP();
2225             assert xp != null;
2226             if (xp != null) {
2227                 Skin skin = xp.getSkin(null, part);
2228                 width = skin.getWidth();
2229             }
2230             return width;
2231         }
2232 
2233         /**
2234          * Returns the icon's height.
2235          *
2236          * @return an int specifying the fixed height of the icon.
2237          */
2238         public int getIconHeight() {
2239             int height = 0;
2240             XPStyle xp = XPStyle.getXP();
2241             if (xp != null) {
2242                 Skin skin = xp.getSkin(null, part);
2243                 height = skin.getHeight();
2244             }
2245             return height;
2246         }
2247 
2248     }
2249 
2250     /**
2251      * DesktopProperty for fonts. If a font with the name 'MS Sans Serif'
2252      * is returned, it is mapped to 'Microsoft Sans Serif'.
2253      */
2254     private static class WindowsFontProperty extends DesktopProperty {
2255         WindowsFontProperty(String key, Object backup) {
2256             super(key, backup);
2257         }
2258 
2259         public void invalidate(LookAndFeel laf) {
2260             if ("win.defaultGUI.font.height".equals(getKey())) {
2261                 ((WindowsLookAndFeel)laf).style = null;
2262             }
2263             super.invalidate(laf);
2264         }
2265 
2266         protected Object configureValue(Object value) {
2267             if (value instanceof Font) {
2268                 Font font = (Font)value;
2269                 if ("MS Sans Serif".equals(font.getName())) {
2270                     int size = font.getSize();
2271                     // 4950968: Workaround to mimic the way Windows maps the default
2272                     // font size of 6 pts to the smallest available bitmap font size.
2273                     // This happens mostly on Win 98/Me & NT.
2274                     int dpi;
2275                     try {
2276                         dpi = Toolkit.getDefaultToolkit().getScreenResolution();
2277                     } catch (HeadlessException ex) {
2278                         dpi = 96;
2279                     }
2280                     if (Math.round(size * 72F / dpi) < 8) {
2281                         size = Math.round(8 * dpi / 72F);
2282                     }
2283                     Font msFont = new FontUIResource("Microsoft Sans Serif",
2284                                           font.getStyle(), size);
2285                     if (msFont.getName() != null &&
2286                         msFont.getName().equals(msFont.getFamily())) {
2287                         font = msFont;
2288                     } else if (size != font.getSize()) {
2289                         font = new FontUIResource("MS Sans Serif",
2290                                                   font.getStyle(), size);
2291                     }
2292                 }
2293 
2294                 if (FontUtilities.fontSupportsDefaultEncoding(font)) {
2295                     if (!(font instanceof UIResource)) {
2296                         font = new FontUIResource(font);
2297                     }
2298                 }
2299                 else {
2300                     font = FontUtilities.getCompositeFontUIResource(font);
2301                 }
2302                 return font;
2303 
2304             }
2305             return super.configureValue(value);
2306         }
2307     }
2308 
2309 
2310     /**
2311      * DesktopProperty for fonts that only gets sizes from the desktop,
2312      * font name and style are passed into the constructor
2313      */
2314     private static class WindowsFontSizeProperty extends DesktopProperty {
2315         private String fontName;
2316         private int fontSize;
2317         private int fontStyle;
2318 
2319         WindowsFontSizeProperty(String key, String fontName,
2320                                 int fontStyle, int fontSize) {
2321             super(key, null);
2322             this.fontName = fontName;
2323             this.fontSize = fontSize;
2324             this.fontStyle = fontStyle;
2325         }
2326 
2327         protected Object configureValue(Object value) {
2328             if (value == null) {
2329                 value = new FontUIResource(fontName, fontStyle, fontSize);
2330             }
2331             else if (value instanceof Integer) {
2332                 value = new FontUIResource(fontName, fontStyle,
2333                                            ((Integer)value).intValue());
2334             }
2335             return value;
2336         }
2337     }
2338 
2339 
2340     /**
2341      * A value wrapper that actively retrieves values from xp or falls back
2342      * to the classic value if not running XP styles.
2343      */
2344     private static class XPValue implements UIDefaults.ActiveValue {
2345         protected Object classicValue, xpValue;
2346 
2347         // A constant that lets you specify null when using XP styles.
2348         private final static Object NULL_VALUE = new Object();
2349 
2350         XPValue(Object xpValue, Object classicValue) {
2351             this.xpValue = xpValue;
2352             this.classicValue = classicValue;
2353         }
2354 
2355         public Object createValue(UIDefaults table) {
2356             Object value = null;
2357             if (XPStyle.getXP() != null) {
2358                 value = getXPValue(table);
2359             }
2360 
2361             if (value == null) {
2362                 value = getClassicValue(table);
2363             } else if (value == NULL_VALUE) {
2364                 value = null;
2365             }
2366 
2367             return value;
2368         }
2369 
2370         protected Object getXPValue(UIDefaults table) {
2371             return recursiveCreateValue(xpValue, table);
2372         }
2373 
2374         protected Object getClassicValue(UIDefaults table) {
2375             return recursiveCreateValue(classicValue, table);
2376         }
2377 
2378         private Object recursiveCreateValue(Object value, UIDefaults table) {
2379             if (value instanceof UIDefaults.LazyValue) {
2380                 value = ((UIDefaults.LazyValue)value).createValue(table);
2381             }
2382             if (value instanceof UIDefaults.ActiveValue) {
2383                 return ((UIDefaults.ActiveValue)value).createValue(table);
2384             } else {
2385                 return value;
2386             }
2387         }
2388     }
2389 
2390     private static class XPBorderValue extends XPValue {
2391         private final Border extraMargin;
2392 
2393         XPBorderValue(Part xpValue, Object classicValue) {
2394             this(xpValue, classicValue, null);
2395         }
2396 
2397         XPBorderValue(Part xpValue, Object classicValue, Border extraMargin) {
2398             super(xpValue, classicValue);
2399             this.extraMargin = extraMargin;
2400         }
2401 
2402         public Object getXPValue(UIDefaults table) {
2403             XPStyle xp = XPStyle.getXP();
2404             Border xpBorder = xp != null ? xp.getBorder(null, (Part)xpValue) : null;
2405             if (xpBorder != null && extraMargin != null) {
2406                 return new BorderUIResource.
2407                         CompoundBorderUIResource(xpBorder, extraMargin);
2408             } else {
2409                 return xpBorder;
2410             }
2411         }
2412     }
2413 
2414     private static class XPColorValue extends XPValue {
2415         XPColorValue(Part part, State state, Prop prop, Object classicValue) {
2416             super(new XPColorValueKey(part, state, prop), classicValue);
2417         }
2418 
2419         public Object getXPValue(UIDefaults table) {
2420             XPColorValueKey key = (XPColorValueKey)xpValue;
2421             XPStyle xp = XPStyle.getXP();
2422             return xp != null ? xp.getColor(key.skin, key.prop, null) : null;
2423         }
2424 
2425         private static class XPColorValueKey {
2426             Skin skin;
2427             Prop prop;
2428 
2429             XPColorValueKey(Part part, State state, Prop prop) {
2430                 this.skin = new Skin(part, state);
2431                 this.prop = prop;
2432             }
2433         }
2434     }
2435 
2436     private class XPDLUValue extends XPValue {
2437         private int direction;
2438 
2439         XPDLUValue(int xpdlu, int classicdlu, int direction) {
2440             super(Integer.valueOf(xpdlu), Integer.valueOf(classicdlu));
2441             this.direction = direction;
2442         }
2443 
2444         public Object getXPValue(UIDefaults table) {
2445             int px = dluToPixels(((Integer)xpValue).intValue(), direction);
2446             return Integer.valueOf(px);
2447         }
2448 
2449         public Object getClassicValue(UIDefaults table) {
2450             int px = dluToPixels(((Integer)classicValue).intValue(), direction);
2451             return Integer.valueOf(px);
2452         }
2453     }
2454 
2455     private class TriggerDesktopProperty extends DesktopProperty {
2456         TriggerDesktopProperty(String key) {
2457             super(key, null);
2458             // This call adds a property change listener for the property,
2459             // which triggers a call to updateUI(). The value returned
2460             // is not interesting here.
2461             getValueFromDesktop();
2462         }
2463 
2464         protected void updateUI() {
2465             super.updateUI();
2466 
2467             // Make sure property change listener is readded each time
2468             getValueFromDesktop();
2469         }
2470     }
2471 
2472     private class FontDesktopProperty extends TriggerDesktopProperty {
2473         FontDesktopProperty(String key) {
2474             super(key);
2475         }
2476 
2477         protected void updateUI() {
2478             Object aaTextInfo = SwingUtilities2.AATextInfo.getAATextInfo(true);
2479             UIDefaults defaults = UIManager.getLookAndFeelDefaults();
2480             defaults.put(SwingUtilities2.AA_TEXT_PROPERTY_KEY, aaTextInfo);
2481             super.updateUI();
2482         }
2483     }
2484 
2485     // Windows LayoutStyle.  From:
2486     // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwue/html/ch14e.asp
2487     private class WindowsLayoutStyle extends DefaultLayoutStyle {
2488         @Override
2489         public int getPreferredGap(JComponent component1,
2490                 JComponent component2, ComponentPlacement type, int position,
2491                 Container parent) {
2492             // Checks args
2493             super.getPreferredGap(component1, component2, type, position,
2494                                   parent);
2495 
2496             switch(type) {
2497             case INDENT:
2498                 // Windows doesn't spec this
2499                 if (position == SwingConstants.EAST ||
2500                         position == SwingConstants.WEST) {
2501                     int indent = getIndent(component1, position);
2502                     if (indent > 0) {
2503                         return indent;
2504                     }
2505                     return 10;
2506                 }
2507                 // Fall through to related.
2508             case RELATED:
2509                 if (isLabelAndNonlabel(component1, component2, position)) {
2510                     // Between text labels and their associated controls (for
2511                     // example, text boxes and list boxes): 3
2512                     // NOTE: We're not honoring:
2513                     // 'Text label beside a button 3 down from the top of
2514                     // the button,' but I suspect that is an attempt to
2515                     // enforce a baseline layout which will be handled
2516                     // separately.  In order to enforce this we would need
2517                     // this API to return a more complicated type (Insets,
2518                     // or something else).
2519                     return getButtonGap(component1, component2, position,
2520                                         dluToPixels(3, position));
2521                 }
2522                 // Between related controls: 4
2523                 return getButtonGap(component1, component2, position,
2524                                     dluToPixels(4, position));
2525             case UNRELATED:
2526                 // Between unrelated controls: 7
2527                 return getButtonGap(component1, component2, position,
2528                                     dluToPixels(7, position));
2529             }
2530             return 0;
2531         }
2532 
2533         @Override
2534         public int getContainerGap(JComponent component, int position,
2535                                    Container parent) {
2536             // Checks args
2537             super.getContainerGap(component, position, parent);
2538             return getButtonGap(component, position, dluToPixels(7, position));
2539         }
2540 
2541     }
2542 
2543     /**
2544      * Converts the dialog unit argument to pixels along the specified
2545      * axis.
2546      */
2547     private int dluToPixels(int dlu, int direction) {
2548         if (baseUnitX == 0) {
2549             calculateBaseUnits();
2550         }
2551         if (direction == SwingConstants.EAST ||
2552             direction == SwingConstants.WEST) {
2553             return dlu * baseUnitX / 4;
2554         }
2555         assert (direction == SwingConstants.NORTH ||
2556                 direction == SwingConstants.SOUTH);
2557         return dlu * baseUnitY / 8;
2558     }
2559 
2560     /**
2561      * Calculates the dialog unit mapping.
2562      */
2563     private void calculateBaseUnits() {
2564         // This calculation comes from:
2565         // http://support.microsoft.com/default.aspx?scid=kb;EN-US;125681
2566         FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics(
2567                 UIManager.getFont("Button.font"));
2568         baseUnitX = metrics.stringWidth(
2569                 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
2570         baseUnitX = (baseUnitX / 26 + 1) / 2;
2571         // The -1 comes from experimentation.
2572         baseUnitY = metrics.getAscent() + metrics.getDescent() - 1;
2573     }
2574 
2575     /**
2576      * {@inheritDoc}
2577      *
2578      * @since 1.6
2579      */
2580     public Icon getDisabledIcon(JComponent component, Icon icon) {
2581         // if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
2582         // client property set to Boolean.TRUE, then use the new
2583         // hi res algorithm for creating the disabled icon (used
2584         // in particular by the WindowsFileChooserUI class)
2585         if (icon != null
2586                 && component != null
2587                 && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
2588                 && icon.getIconWidth() > 0
2589                 && icon.getIconHeight() > 0) {
2590             BufferedImage img = new BufferedImage(icon.getIconWidth(),
2591                     icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
2592             icon.paintIcon(component, img.getGraphics(), 0, 0);
2593             ImageFilter filter = new RGBGrayFilter();
2594             ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
2595             Image resultImage = component.createImage(producer);
2596             return new ImageIconUIResource(resultImage);
2597         }
2598         return super.getDisabledIcon(component, icon);
2599     }
2600 
2601     private static class RGBGrayFilter extends RGBImageFilter {
2602         public RGBGrayFilter() {
2603             canFilterIndexColorModel = true;
2604         }
2605         public int filterRGB(int x, int y, int rgb) {
2606             // find the average of red, green, and blue
2607             float avg = (((rgb >> 16) & 0xff) / 255f +
2608                           ((rgb >>  8) & 0xff) / 255f +
2609                            (rgb        & 0xff) / 255f) / 3;
2610             // pull out the alpha channel
2611             float alpha = (((rgb>>24)&0xff)/255f);
2612             // calc the average
2613             avg = Math.min(1.0f, (1f-avg)/(100.0f/35.0f) + avg);
2614             // turn back into rgb
2615             int rgbval = (int)(alpha * 255f) << 24 |
2616                          (int)(avg   * 255f) << 16 |
2617                          (int)(avg   * 255f) <<  8 |
2618                          (int)(avg   * 255f);
2619             return rgbval;
2620         }
2621     }
2622 
2623     private static class FocusColorProperty extends DesktopProperty {
2624         public FocusColorProperty () {
2625             // Fallback value is never used bacause of the configureValue method doesn't return null
2626             super("win.3d.backgroundColor", Color.BLACK);
2627         }
2628 
2629         @Override
2630         protected Object configureValue(Object value) {
2631             if (! ((Boolean)Toolkit.getDefaultToolkit().getDesktopProperty("win.highContrast.on")).booleanValue()){
2632                 return Color.BLACK;
2633             }
2634             return Color.BLACK.equals(value) ? Color.WHITE : Color.BLACK;
2635         }
2636     }
2637 
2638 }