metallookandfeel.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,404 行 · 第 1/5 页
JAVA
1,404 行
/* * @(#)MetalLookAndFeel.java 1.161 03/01/23 * * Copyright 2003 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.net.URL;import java.io.Serializable;import java.security.AccessController;import sun.awt.AppContext;import sun.security.action.GetPropertyAction;/** * Implements the Java look and feel (codename: Metal). * <p> * For the keyboard keys defined for each component in this look and * feel, see * <a href="../../doc-files/Key-Metal.html">Component Keystroke Actions for the Java Look and Feel.</a> * <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.161 03/01/23 * @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; } 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); 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) { Object[] systemColors = { "desktop", getDesktopColor(), /* Color of the desktop background */ "activeCaption", getWindowTitleBackground(), /* Color for captions (title bars) when they are active. */ "activeCaptionText", getWindowTitleForeground(), /* Text color for text in captions (title bars). */ "activeCaptionBorder", getPrimaryControlShadow(), /* Border color for caption (title bar) window borders. */ "inactiveCaption", getWindowTitleInactiveBackground(), /* Color for captions (title bars) when not active. */ "inactiveCaptionText", getWindowTitleInactiveForeground(), /* Text color for text in inactive captions (title bars). */ "inactiveCaptionBorder", getControlShadow(), /* Border color for inactive caption (title bar) window borders. */ "window", getWindowBackground(), /* Default color for the interior of windows */ "windowBorder", getControl(), /* ??? */ "windowText", getUserTextColor(), /* ??? */ "menu", getMenuBackground(), /* Background color for menus */ "menuText", getMenuForeground(), /* Text color for menus */ "text", getWindowBackground(), /* Text background color */ "textText", getUserTextColor(), /* Text foreground color */ "textHighlight", getTextHighlightColor(), /* Text background color when selected */ "textHighlightText", getHighlightedTextColor(), /* Text color when selected */ "textInactiveText", getInactiveSystemTextColor(), /* Text color when disabled */ "control", getControl(), /* Default color for controls (buttons, sliders, etc) */ "controlText", getControlTextColor(), /* Default color for text in controls */ "controlHighlight", getControlHighlight(), /* Specular highlight (opposite of the shadow) */ "controlLtHighlight", getControlHighlight(), /* Highlight color for controls */ "controlShadow", getControlShadow(), /* Shadow color for controls */ "controlDkShadow", getControlDarkShadow(), /* Dark shadow color for controls */ "scrollbar", getControl(), /* Scrollbar background (usually the "track") */ "info", getPrimaryControl(), /* ToolTip Background */ "infoText", getPrimaryControlInfo() /* ToolTip Text */ }; for(int i = 0; i < systemColors.length; i += 2) { table.put((String)systemColors[i], systemColors[i + 1]); } } /** * Initialize the defaults table with the name of the ResourceBundle * used for getting localized defaults. */ private void initResourceBundle(UIDefaults table) { table.addResourceBundle( "com.sun.swing.internal.plaf.metal.resources.metal" ); } protected void initComponentDefaults(UIDefaults table) { super.initComponentDefaults( table ); initResourceBundle(table);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?