⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metallookandfeel.java

📁 JAVA的一些源码 JAVA2 STANDARD EDITION DEVELOPMENT KIT 5.0
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * @(#)MetalLookAndFeel.java	1.182 04/04/02 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.metal;import java.awt.*;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.util.*;import java.awt.Font;import java.awt.Color;import java.awt.SystemColor;import java.awt.event.KeyEvent;import java.awt.event.InputEvent;import java.lang.reflect.*;import java.net.URL;import java.io.Serializable;import java.security.AccessController;import java.security.PrivilegedAction;import sun.awt.AppContext;import sun.security.action.GetPropertyAction;import sun.swing.SwingLazyValue;/** * Implements the Java look and feel (codename: Metal). * <p> * By default metal uses bold fonts for many controls.  To make all * controls (with the exception of the internal frame title bars and * client decorated frame title bars) use plain fonts you can do either of * the following: * <ul> * <li>Set the system property <code>swing.boldMetal</code> to *     <code>false</code>.  For example, *     <code>java&nbsp;-Dswing.boldMetal=false&nbsp;MyApp</code>. * <li>Set the defaults property <code>swing.boldMetal</code> to *     <code>Boolean.FALSE</code>.  For example: *     <code>UIManager.put("swing.boldMetal",&nbsp;Boolean.FALSE);</code> * </ul> * The defaults property <code>swing.boldMetal</code>, if set, * takes precendence over the system property of the same name. After * setting this defaults property you need to re-install the * <code>MetalLookAndFeel</code>, as well as update the UI * of any previously created widgets. Otherwise the results are undefined. * These lines of code show you how to accomplish this: * <pre> *   // turn off bold fonts *   UIManager.put("swing.boldMetal", Boolean.FALSE); * *   // re-install the Metal Look and Feel *   UIManager.setLookAndFeel(new MetalLookAndFeel()); * *   // only needed to update existing widgets *   SwingUtilities.updateComponentTreeUI(rootComponent); * </pre> * <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.  As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @version @(#)MetalLookAndFeel.java	1.182 04/04/02 * @author Steve Wilson */public class MetalLookAndFeel extends BasicLookAndFeel{    private static boolean METAL_LOOK_AND_FEEL_INITED = false;    private static MetalTheme currentTheme;    private static boolean isOnlyOneContext = true;    private static AppContext cachedAppContext;    /**     * True if checked for windows yet.     */    private static boolean checkedWindows;    /**     * True if running on Windows.     */    private static boolean isWindows;    /**     * Set to true first time we've checked swing.useSystemFontSettings.     */    private static boolean checkedSystemFontSettings;    /**     * True indicates we should use system fonts, unless the developer has     * specified otherwise with Application.useSystemFontSettings.     */    private static boolean useSystemFonts;    /**     * Returns true if running on Windows.     */    static boolean isWindows() {        if (!checkedWindows) {            String osName = (String)AccessController.doPrivileged(                new GetPropertyAction("os.name"));            if (osName != null && osName.indexOf("Windows") != -1) {                isWindows = true;                String systemFonts = (String)AccessController.doPrivileged(                    new GetPropertyAction("swing.useSystemFontSettings"));                useSystemFonts = (systemFonts != null &&                               (Boolean.valueOf(systemFonts).booleanValue()));            }            checkedWindows = true;        }        return isWindows;    }    /**     * Returns true if system fonts should be used, this is only useful     * for windows.     */    static boolean useSystemFonts() {        if (isWindows() && useSystemFonts) {            if (METAL_LOOK_AND_FEEL_INITED) {                Object value = UIManager.get(                                 "Application.useSystemFontSettings");                return (value == null || Boolean.TRUE.equals(value));            }            // If an instanceof MetalLookAndFeel hasn't been inited yet, we            // don't want to trigger loading of a UI by asking the UIManager            // for a property, assume the user wants system fonts. This will            // be properly adjusted when install is invoked on the            // MetalTheme            return true;        }        return false;    }    /**     * Returns true if the high contrast theme should be used as the default     * theme.     */    private static boolean useHighContrastTheme() {        if (isWindows() && useSystemFonts()) {            Boolean highContrast = (Boolean)Toolkit.getDefaultToolkit().                                  getDesktopProperty("win.highContrast.on");            return (highContrast == null) ? false : highContrast.                                            booleanValue();        }        return false;    }    /**     * Returns true if we're using the Ocean Theme.     */    static boolean usingOcean() {        return (getCurrentTheme() instanceof OceanTheme);    }    public String getName() {        return "Metal";    }    public String getID() {        return "Metal";    }    public String getDescription() {        return "The Java(tm) Look and Feel";    }        public boolean isNativeLookAndFeel() {        return false;    }    public boolean isSupportedLookAndFeel() {        return true;    }        /**     * Returns true if the <code>LookAndFeel</code> returned     * <code>RootPaneUI</code> instances support providing Window decorations     * in a <code>JRootPane</code>.     * <p>     * This implementation returns true, since it does support providing     * these border and window title pane decorations.     *     * @return True if the RootPaneUI instances created support client side     *              decorations     * @see JDialog#setDefaultLookAndFeelDecorated     * @see JFrame#setDefaultLookAndFeelDecorated     * @see JRootPane#setWindowDecorationStyle     * @since 1.4     */    public boolean getSupportsWindowDecorations() {        return true;    }    /**      * Creates the mapping from     * UI class IDs to <code>ComponentUI</code> classes,     * putting the ID-<code>ComponentUI</code> pairs     * in the passed-in defaults table.     * Each <code>JComponent</code> class     * specifies its own UI class ID string.     * For example,      * <code>JButton</code> has the UI class ID "ButtonUI",     * which this method maps to "javax.swing.plaf.metal.MetalButtonUI".     *      * @see BasicLookAndFeel#getDefaults     * @see javax.swing.JComponent#getUIClassID     */    protected void initClassDefaults(UIDefaults table)    {        super.initClassDefaults(table);        final String metalPackageName = "javax.swing.plaf.metal.";        Object[] uiDefaults = {                   "ButtonUI", metalPackageName + "MetalButtonUI",                 "CheckBoxUI", metalPackageName + "MetalCheckBoxUI",                 "ComboBoxUI", metalPackageName + "MetalComboBoxUI",              "DesktopIconUI", metalPackageName + "MetalDesktopIconUI",              "FileChooserUI", metalPackageName + "MetalFileChooserUI",            "InternalFrameUI", metalPackageName + "MetalInternalFrameUI",                    "LabelUI", metalPackageName + "MetalLabelUI",       "PopupMenuSeparatorUI", metalPackageName + "MetalPopupMenuSeparatorUI",              "ProgressBarUI", metalPackageName + "MetalProgressBarUI",              "RadioButtonUI", metalPackageName + "MetalRadioButtonUI",                "ScrollBarUI", metalPackageName + "MetalScrollBarUI",               "ScrollPaneUI", metalPackageName + "MetalScrollPaneUI",                "SeparatorUI", metalPackageName + "MetalSeparatorUI",                   "SliderUI", metalPackageName + "MetalSliderUI",                "SplitPaneUI", metalPackageName + "MetalSplitPaneUI",               "TabbedPaneUI", metalPackageName + "MetalTabbedPaneUI",                "TextFieldUI", metalPackageName + "MetalTextFieldUI",             "ToggleButtonUI", metalPackageName + "MetalToggleButtonUI",                  "ToolBarUI", metalPackageName + "MetalToolBarUI",                  "ToolTipUI", metalPackageName + "MetalToolTipUI",                     "TreeUI", metalPackageName + "MetalTreeUI",                 "RootPaneUI", metalPackageName + "MetalRootPaneUI",        };        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.     */    protected void initSystemColorDefaults(UIDefaults table)    {        MetalTheme theme = getCurrentTheme();        Color control = theme.getControl();        Object[] systemColors = {                "desktop", theme.getDesktopColor(), /* Color of the desktop background */          "activeCaption", theme.getWindowTitleBackground(), /* Color for captions (title bars) when they are active. */      "activeCaptionText", theme.getWindowTitleForeground(), /* Text color for text in captions (title bars). */    "activeCaptionBorder", theme.getPrimaryControlShadow(), /* Border color for caption (title bar) window borders. */        "inactiveCaption", theme.getWindowTitleInactiveBackground(), /* Color for captions (title bars) when not active. */    "inactiveCaptionText", theme.getWindowTitleInactiveForeground(), /* Text color for text in inactive captions (title bars). */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -