nimbuslookandfeel.java
来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 503 行 · 第 1/2 页
JAVA
503 行
/* * @(#)NimbusLookAndFeel.java 1.17 08/06/27 * * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.nimbus;import java.awt.BorderLayout;import static java.awt.BorderLayout.*;import javax.swing.JComponent;import javax.swing.UIDefaults;import javax.swing.UIManager;import javax.swing.plaf.synth.Region;import javax.swing.plaf.synth.SynthLookAndFeel;import javax.swing.plaf.synth.SynthStyle;import javax.swing.plaf.synth.SynthStyleFactory;import javax.swing.plaf.UIResource;import java.security.AccessController;import java.awt.Color;import java.awt.Container;import java.awt.Graphics2D;import java.awt.LayoutManager;import java.awt.image.BufferedImage;import javax.swing.GrayFilter;import javax.swing.Icon;import javax.swing.JToolBar;import javax.swing.border.TitledBorder;import javax.swing.plaf.BorderUIResource;import javax.swing.plaf.ColorUIResource;import sun.swing.ImageIconUIResource;import sun.swing.plaf.synth.SynthIcon;import sun.swing.plaf.GTKKeybindings;import sun.swing.plaf.WindowsKeybindings;import sun.security.action.GetPropertyAction;/** * <p>The NimbusLookAndFeel class.</p> * * @author Jasper Potts * @author Richard Bair */public class NimbusLookAndFeel extends SynthLookAndFeel { /** Set of standard region names for UIDefaults Keys */ private static final String[] COMPONENT_KEYS = new String[]{"ArrowButton", "Button", "CheckBox", "CheckBoxMenuItem", "ColorChooser", "ComboBox", "DesktopPane", "DesktopIcon", "EditorPane", "FileChooser", "FormattedTextField", "InternalFrame", "InternalFrameTitlePane", "Label", "List", "Menu", "MenuBar", "MenuItem", "OptionPane", "Panel", "PasswordField", "PopupMenu", "PopupMenuSeparator", "ProgressBar", "RadioButton", "RadioButtonMenuItem", "RootPane", "ScrollBar", "ScrollBarTrack", "ScrollBarThumb", "ScrollPane", "Separator", "Slider", "SliderTrack", "SliderThumb", "Spinner", "SplitPane", "TabbedPane", "Table", "TableHeader", "TextArea", "TextField", "TextPane", "ToggleButton", "ToolBar", "ToolTip", "Tree", "Viewport"}; /** * A reference to the auto-generated file NimbusDefaults. This file contains * the default mappings and values for the look and feel as specified in the * visual designer. */ private NimbusDefaults defaults; /** * Reference to populated LAD uidefaults */ private UIDefaults uiDefaults; /** * Create a new NimbusLookAndFeel. */ public NimbusLookAndFeel() { super(); defaults = new NimbusDefaults(); } /** Called by UIManager when this look and feel is installed. */ @Override public void initialize() { super.initialize(); defaults.initialize(); // create synth style factory setStyleFactory(new SynthStyleFactory() { @Override public SynthStyle getStyle(JComponent c, Region r) { return defaults.getStyle(c, r); } }); } /** Called by UIManager when this look and feel is uninstalled. */ @Override public void uninitialize() { super.uninitialize(); defaults.uninitialize(); // clear all cached images to free memory ImageCache.getInstance().flush(); // remove the listeners and things installed by NimbusStyle NimbusStyle.uninitialize(); } /** * @inheritDoc */ @Override public UIDefaults getDefaults() { if (uiDefaults == null){ // Detect platform String osName = getSystemProperty("os.name"); boolean isWindows = osName != null && osName.contains("Windows"); // We need to call super for basic's properties file. uiDefaults = super.getDefaults(); defaults.initializeDefaults(uiDefaults); // Install Keybindings if (isWindows) { WindowsKeybindings.installKeybindings(uiDefaults); } else { GTKKeybindings.installKeybindings(uiDefaults); } // Add Titled Border uiDefaults.put("TitledBorder.titlePosition", TitledBorder.ABOVE_TOP); uiDefaults.put("TitledBorder.border", new BorderUIResource( new LoweredBorder())); uiDefaults.put("TitledBorder.titleColor", getDerivedColor("text",0.0f,0.0f,0.23f,0,true)); uiDefaults.put("TitledBorder.font", new NimbusDefaults.DerivedFont("defaultFont", 1f, true, null)); // Choose Dialog button positions uiDefaults.put("OptionPane.isYesLast", !isWindows); // Store Table ScrollPane Corner Component uiDefaults.put("Table.scrollPaneCornerComponent", TableScrollPaneCorner.class); // Setup the settings for ToolBarSeparator which is custom // installed for Nimbus uiDefaults.put("ToolBarSeparator[Enabled].backgroundPainter", new ToolBarSeparatorPainter()); // Populate UIDefaults with a standard set of properties for (String componentKey : COMPONENT_KEYS) { String key = componentKey+".foreground"; if (!uiDefaults.containsKey(key)){ uiDefaults.put(key, new NimbusProperty(componentKey,"textForeground")); } key = componentKey+".background"; if (!uiDefaults.containsKey(key)){ uiDefaults.put(key, new NimbusProperty(componentKey,"background")); } key = componentKey+".font"; if (!uiDefaults.containsKey(key)){ uiDefaults.put(key, new NimbusProperty(componentKey,"font")); } key = componentKey+".disabledText"; if (!uiDefaults.containsKey(key)){ uiDefaults.put(key, new NimbusProperty(componentKey,"Disabled", "textForeground")); } key = componentKey+".disabled"; if (!uiDefaults.containsKey(key)){ uiDefaults.put(key, new NimbusProperty(componentKey,"Disabled", "background")); } } // FileView icon keys are used by some applications, we don't have // a computer icon at the moment so using home icon for now uiDefaults.put("FileView.computerIcon", new LinkProperty("FileChooser.homeFolderIcon")); uiDefaults.put("FileView.directoryIcon", new LinkProperty("FileChooser.directoryIcon")); uiDefaults.put("FileView.fileIcon", new LinkProperty("FileChooser.fileIcon")); uiDefaults.put("FileView.floppyDriveIcon", new LinkProperty("FileChooser.floppyDriveIcon")); uiDefaults.put("FileView.hardDriveIcon", new LinkProperty("FileChooser.hardDriveIcon")); } return uiDefaults; } /** * Gets the style associated with the given component and region. This * will never return null. If an appropriate component and region cannot * be determined, then a default style is returned. * * @param c a non-null reference to a JComponent * @param r a non-null reference to the region of the component c * @return a non-null reference to a NimbusStyle. */ public static NimbusStyle getStyle(JComponent c, Region r) { return (NimbusStyle)SynthLookAndFeel.getStyle(c, r); } /** * Return a short string that identifies this look and feel. This * String will be the unquoted String "Nimbus". * * @return a short string identifying this look and feel. */ @Override public String getName() { return "Nimbus"; } /** * Return a string that identifies this look and feel. This String will * be the unquoted String "Nimbus". * * @return a short string identifying this look and feel. */ @Override public String getID() { return "Nimbus"; } /** * Returns a textual description of this look and feel. * * @return textual description of this look and feel. */ @Override public String getDescription() { return "Nimbus Look and Feel"; } /** * @inheritDoc * @return true */ @Override public boolean shouldUpdateStyleOnAncestorChanged() { return true; } /** * <p>Registers a third party component with the NimbusLookAndFeel.</p> * * <p>Regions represent Components and areas within Components that act as * independent painting areas. Once registered with the NimbusLookAndFeel, * NimbusStyles for these Regions can be retrieved via the * <code>getStyle</code> method.</p> * * <p>The NimbusLookAndFeel uses a standard naming scheme for entries in the
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?