windowslookandfeel.java
来自「JAVA 所有包」· Java 代码 · 共 1,352 行 · 第 1/5 页
JAVA
1,352 行
/* * @(#)WindowsLookAndFeel.java 1.231 06/12/15 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * <p>These classes are designed to be used while the * corresponding <code>LookAndFeel</code> class has been installed * (<code>UIManager.setLookAndFeel(new <i>XXX</i>LookAndFeel())</code>). * Using them while a different <code>LookAndFeel</code> is installed * may produce unexpected results, including exceptions. * Additionally, changing the <code>LookAndFeel</code> * maintained by the <code>UIManager</code> without updating the * corresponding <code>ComponentUI</code> of any * <code>JComponent</code>s may also produce unexpected results, * such as the wrong colors showing up, and is generally not * encouraged. * */package com.sun.java.swing.plaf.windows;import java.awt.*;import java.awt.image.BufferedImage;import java.awt.image.ImageFilter;import java.awt.image.ImageProducer;import java.awt.image.FilteredImageSource;import java.awt.image.RGBImageFilter;import javax.swing.plaf.*;import javax.swing.*;import javax.swing.plaf.basic.*;import javax.swing.border.*;import javax.swing.text.JTextComponent;import javax.swing.text.DefaultEditorKit;import java.awt.Font;import java.awt.Color;import java.awt.SystemColor;import java.awt.event.KeyEvent;import java.awt.event.InputEvent;import java.awt.event.ActionEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeEvent;import java.net.URL;import java.io.Serializable;import java.security.AccessController;import java.util.*;import sun.awt.SunToolkit;import sun.awt.shell.ShellFolder;import sun.font.FontManager;import sun.security.action.GetPropertyAction;import sun.swing.DefaultLayoutStyle;import sun.swing.ImageIconUIResource;import sun.swing.SwingLazyValue;import sun.swing.SwingUtilities2;import static com.sun.java.swing.plaf.windows.TMSchema.*;import static com.sun.java.swing.plaf.windows.XPStyle.Skin;import com.sun.java.swing.plaf.windows.WindowsIconFactory .VistaMenuItemCheckIconFactory;/** * Implements the Windows95/98/NT/2000 Look and Feel. * UI classes not implemented specifically for Windows will * default to those implemented in Basic. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is appropriate * for short term storage or RMI between applications running the same * version of Swing. A future release of Swing will provide support for * long term persistence. * * @version 1.231 12/15/06 * @author unattributed */public class WindowsLookAndFeel extends BasicLookAndFeel{ /** * A client property that can be used with any JComponent that will end up * calling the LookAndFeel.getDisabledIcon method. This client property, * when set to Boolean.TRUE, will cause getDisabledIcon to use an * alternate algorithm for creating disabled icons to produce icons * that appear similar to the native Windows file chooser */ static final String HI_RES_DISABLED_ICON_CLIENT_KEY = new StringBuilder("WindowsLookAndFeel.generateHiResDisabledIcon").toString(); private Toolkit toolkit; private boolean updatePending = false; private boolean useSystemFontSettings = true; private boolean useSystemFontSizeSettings; // These properties are not used directly, but are kept as // private members to avoid being GC'd. private DesktopProperty themeActive, dllName, colorName, sizeName; private DesktopProperty aaSettings; private transient LayoutStyle style; /** * Base dialog units along the horizontal axis. */ private int baseUnitX; /** * Base dialog units along the vertical axis. */ private int baseUnitY; public String getName() { return "Windows"; } public String getDescription() { return "The Microsoft Windows Look and Feel"; } public String getID() { return "Windows"; } public boolean isNativeLookAndFeel() { String osName = System.getProperty("os.name"); return (osName != null) && (osName.indexOf("Windows") != -1); } public boolean isSupportedLookAndFeel() { return isNativeLookAndFeel(); } public void initialize() { super.initialize(); toolkit = Toolkit.getDefaultToolkit(); // Set the flag which determines which version of Windows should // be rendered. This flag only need to be set once. // if version <= 4.0 then the classic LAF should be loaded. String osVersion = System.getProperty("os.version"); if (osVersion != null) { Float version = Float.valueOf(osVersion); if (version.floatValue() <= 4.0) { isClassicWindows = true; } else { isClassicWindows = false; XPStyle.invalidateStyle(); } } // Using the fonts set by the user can potentially cause // performance and compatibility issues, so allow this feature // to be switched off either at runtime or programmatically // String systemFonts = (String) java.security.AccessController.doPrivileged( new GetPropertyAction("swing.useSystemFontSettings")); useSystemFontSettings = (systemFonts == null || Boolean.valueOf(systemFonts).booleanValue()); if (useSystemFontSettings) { Object value = UIManager.get("Application.useSystemFontSettings"); useSystemFontSettings = (value == null || Boolean.TRUE.equals(value)); } KeyboardFocusManager.getCurrentKeyboardFocusManager(). addKeyEventPostProcessor(WindowsRootPaneUI.altProcessor); } /** * Initialize the uiClassID to BasicComponentUI mapping. * The JComponent classes define their own uiClassID constants * (see AbstractComponent.getUIClassID). This table must * map those constants to a BasicComponentUI class of the * appropriate type. * * @see BasicLookAndFeel#getDefaults */ protected void initClassDefaults(UIDefaults table) { super.initClassDefaults(table); final String windowsPackageName = "com.sun.java.swing.plaf.windows."; Object[] uiDefaults = { "ButtonUI", windowsPackageName + "WindowsButtonUI", "CheckBoxUI", windowsPackageName + "WindowsCheckBoxUI", "CheckBoxMenuItemUI", windowsPackageName + "WindowsCheckBoxMenuItemUI", "LabelUI", windowsPackageName + "WindowsLabelUI", "RadioButtonUI", windowsPackageName + "WindowsRadioButtonUI", "RadioButtonMenuItemUI", windowsPackageName + "WindowsRadioButtonMenuItemUI", "ToggleButtonUI", windowsPackageName + "WindowsToggleButtonUI", "ProgressBarUI", windowsPackageName + "WindowsProgressBarUI", "SliderUI", windowsPackageName + "WindowsSliderUI", "SeparatorUI", windowsPackageName + "WindowsSeparatorUI", "SplitPaneUI", windowsPackageName + "WindowsSplitPaneUI", "SpinnerUI", windowsPackageName + "WindowsSpinnerUI", "TabbedPaneUI", windowsPackageName + "WindowsTabbedPaneUI", "TextAreaUI", windowsPackageName + "WindowsTextAreaUI", "TextFieldUI", windowsPackageName + "WindowsTextFieldUI", "PasswordFieldUI", windowsPackageName + "WindowsPasswordFieldUI", "TextPaneUI", windowsPackageName + "WindowsTextPaneUI", "EditorPaneUI", windowsPackageName + "WindowsEditorPaneUI", "TreeUI", windowsPackageName + "WindowsTreeUI", "ToolBarUI", windowsPackageName + "WindowsToolBarUI", "ToolBarSeparatorUI", windowsPackageName + "WindowsToolBarSeparatorUI", "ComboBoxUI", windowsPackageName + "WindowsComboBoxUI", "TableHeaderUI", windowsPackageName + "WindowsTableHeaderUI", "InternalFrameUI", windowsPackageName + "WindowsInternalFrameUI", "DesktopPaneUI", windowsPackageName + "WindowsDesktopPaneUI", "DesktopIconUI", windowsPackageName + "WindowsDesktopIconUI", "FileChooserUI", windowsPackageName + "WindowsFileChooserUI", "MenuUI", windowsPackageName + "WindowsMenuUI", "MenuItemUI", windowsPackageName + "WindowsMenuItemUI", "MenuBarUI", windowsPackageName + "WindowsMenuBarUI", "PopupMenuUI", windowsPackageName + "WindowsPopupMenuUI", "PopupMenuSeparatorUI", windowsPackageName + "WindowsPopupMenuSeparatorUI", "ScrollBarUI", windowsPackageName + "WindowsScrollBarUI", "RootPaneUI", windowsPackageName + "WindowsRootPaneUI" }; table.putDefaults(uiDefaults); } /** * Load the SystemColors into the defaults table. The keys * for SystemColor defaults are the same as the names of * the public fields in SystemColor. If the table is being * created on a native Windows platform we use the SystemColor * values, otherwise we create color objects whose values match * the defaults Windows95 colors. */ protected void initSystemColorDefaults(UIDefaults table) { String[] defaultSystemColors = { "desktop", "#005C5C", /* Color of the desktop background */ "activeCaption", "#000080", /* Color for captions (title bars) when they are active. */ "activeCaptionText", "#FFFFFF", /* Text color for text in captions (title bars). */ "activeCaptionBorder", "#C0C0C0", /* Border color for caption (title bar) window borders. */ "inactiveCaption", "#808080", /* Color for captions (title bars) when not active. */ "inactiveCaptionText", "#C0C0C0", /* Text color for text in inactive captions (title bars). */ "inactiveCaptionBorder", "#C0C0C0", /* Border color for inactive caption (title bar) window borders. */ "window", "#FFFFFF", /* Default color for the interior of windows */ "windowBorder", "#000000", /* ??? */ "windowText", "#000000", /* ??? */ "menu", "#C0C0C0", /* Background color for menus */ "menuPressedItemB", "#000080", /* LightShadow of menubutton highlight */ "menuPressedItemF", "#FFFFFF", /* Default color for foreground "text" in menu item */ "menuText", "#000000", /* Text color for menus */ "text", "#C0C0C0", /* Text background color */ "textText", "#000000", /* Text foreground color */ "textHighlight", "#000080", /* Text background color when selected */ "textHighlightText", "#FFFFFF", /* Text color when selected */ "textInactiveText", "#808080", /* Text color when disabled */ "control", "#C0C0C0", /* Default color for controls (buttons, sliders, etc) */ "controlText", "#000000", /* Default color for text in controls */ "controlHighlight", "#C0C0C0", /*"controlHighlight", "#E0E0E0",*/ /* Specular highlight (opposite of the shadow) */ "controlLtHighlight", "#FFFFFF", /* Highlight color for controls */ "controlShadow", "#808080", /* Shadow color for controls */ "controlDkShadow", "#000000", /* Dark shadow color for controls */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?