📄 basiclookandfeel.java
字号:
/* * @(#)BasicLookAndFeel.java 1.277 07/06/01 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.basic;import java.awt.Font;import java.awt.Color;import java.awt.SystemColor;import java.awt.event.*;import java.awt.Insets;import java.awt.Component;import java.awt.Container;import java.awt.FocusTraversalPolicy;import java.awt.AWTEvent;import java.awt.Toolkit;import java.awt.Point;import java.net.URL;import java.io.*;import java.awt.Dimension;import java.awt.KeyboardFocusManager;import java.security.AccessController;import java.security.PrivilegedAction;import java.util.*;import java.lang.reflect.*;import javax.sound.sampled.*;import sun.awt.AppContext;import sun.swing.SwingLazyValue;import sun.swing.SwingUtilities2;import javax.swing.LookAndFeel;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.ActionMap;import javax.swing.BorderFactory;import javax.swing.JComponent;import javax.swing.ImageIcon;import javax.swing.UIDefaults;import javax.swing.UIManager;import javax.swing.KeyStroke;import javax.swing.JTextField;import javax.swing.DefaultListCellRenderer;import javax.swing.FocusManager;import javax.swing.LayoutFocusTraversalPolicy;import javax.swing.SwingUtilities;import javax.swing.MenuSelectionManager;import javax.swing.MenuElement;import javax.swing.border.*;import javax.swing.plaf.*;import javax.swing.text.JTextComponent;import javax.swing.text.DefaultEditorKit;import javax.swing.JInternalFrame;import java.beans.PropertyVetoException;import java.awt.Window;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeEvent;/** * A base class to use in creating a look and feel for Swing. * <p> * Each of the {@code ComponentUI}s provided by {@code * BasicLookAndFeel} derives its behavior from the defaults * table. Unless otherwise noted each of the {@code ComponentUI} * implementations in this package document the set of defaults they * use. Unless otherwise noted the defaults are installed at the time * {@code installUI} is invoked, and follow the recommendations * outlined in {@code LookAndFeel} for installing defaults. * <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 1.277 06/01/07 * @author unattributed */public abstract class BasicLookAndFeel extends LookAndFeel implements Serializable{ /** * Whether or not the developer has created a JPopupMenu. */ static boolean needsEventHelper; /** * Lock used when manipulating clipPlaying. */ private Object audioLock = new Object(); /** * The Clip that is currently playing (set in AudioAction). */ private Clip clipPlaying; AWTEventHelper invocator = null; /* * Listen for our AppContext being disposed */ private PropertyChangeListener disposer = null; /** * Returns the look and feel defaults. The returned {@code UIDefaults} * is populated by invoking, in order, {@code initClassDefaults}, * {@code initSystemColorDefaults} and {@code initComponentDefaults}. * <p> * While this method is public, it should only be invoked by the * {@code UIManager} when the look and feel is set as the current * look and feel and after {@code initialize} has been invoked. * * @return the look and feel defaults * * @see #initClassDefaults * @see #initSystemColorDefaults * @see #initComponentDefaults */ public UIDefaults getDefaults() { UIDefaults table = new UIDefaults(610, 0.75f); initClassDefaults(table); initSystemColorDefaults(table); initComponentDefaults(table); return table; } /** * {@inheritDoc} */ public void initialize() { if (needsEventHelper) { installAWTEventListener(); } } void installAWTEventListener() { if (invocator == null) { invocator = new AWTEventHelper(); needsEventHelper = true; // Add a PropertyChangeListener to our AppContext so we're alerted // when the AppContext is disposed(), at which time this laf should // be uninitialize()d. disposer = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent prpChg) { uninitialize(); } }; AppContext.getAppContext().addPropertyChangeListener( AppContext.GUI_DISPOSED, disposer); } } /** * {@inheritDoc} */ public void uninitialize() { AppContext context = AppContext.getAppContext(); synchronized (BasicPopupMenuUI.MOUSE_GRABBER_KEY) { Object grabber = context.get(BasicPopupMenuUI.MOUSE_GRABBER_KEY); if (grabber != null) { ((BasicPopupMenuUI.MouseGrabber)grabber).uninstall(); } } synchronized (BasicPopupMenuUI.MENU_KEYBOARD_HELPER_KEY) { Object helper = context.get(BasicPopupMenuUI.MENU_KEYBOARD_HELPER_KEY); if (helper != null) { ((BasicPopupMenuUI.MenuKeyboardHelper) helper).uninstall(); } } if(invocator != null) { AccessController.doPrivileged(invocator); invocator = null; } if (disposer != null) { // Note that we're likely calling removePropertyChangeListener() // during the course of AppContext.firePropertyChange(). // However, EventListenerAggreggate has code to safely modify // the list under such circumstances. context.removePropertyChangeListener(AppContext.GUI_DISPOSED, disposer); disposer = null; } } /** * Populates {@code table} with mappings from {@code uiClassID} to the * fully qualified name of the ui class. The value for a * particular {@code uiClassID} is {@code * "javax.swing.plaf.basic.Basic + uiClassID"}. For example, the * value for the {@code uiClassID} {@code TreeUI} is {@code * "javax.swing.plaf.basic.BasicTreeUI"}. * * @param table the {@code UIDefaults} instance the entries are * added to * @throws NullPointerException if {@code table} is {@code null} * * @see javax.swing.LookAndFeel * @see #getDefaults */ protected void initClassDefaults(UIDefaults table) { final String basicPackageName = "javax.swing.plaf.basic."; Object[] uiDefaults = { "ButtonUI", basicPackageName + "BasicButtonUI", "CheckBoxUI", basicPackageName + "BasicCheckBoxUI", "ColorChooserUI", basicPackageName + "BasicColorChooserUI", "FormattedTextFieldUI", basicPackageName + "BasicFormattedTextFieldUI", "MenuBarUI", basicPackageName + "BasicMenuBarUI", "MenuUI", basicPackageName + "BasicMenuUI", "MenuItemUI", basicPackageName + "BasicMenuItemUI", "CheckBoxMenuItemUI", basicPackageName + "BasicCheckBoxMenuItemUI", "RadioButtonMenuItemUI", basicPackageName + "BasicRadioButtonMenuItemUI", "RadioButtonUI", basicPackageName + "BasicRadioButtonUI", "ToggleButtonUI", basicPackageName + "BasicToggleButtonUI", "PopupMenuUI", basicPackageName + "BasicPopupMenuUI", "ProgressBarUI", basicPackageName + "BasicProgressBarUI", "ScrollBarUI", basicPackageName + "BasicScrollBarUI", "ScrollPaneUI", basicPackageName + "BasicScrollPaneUI", "SplitPaneUI", basicPackageName + "BasicSplitPaneUI", "SliderUI", basicPackageName + "BasicSliderUI", "SeparatorUI", basicPackageName + "BasicSeparatorUI", "SpinnerUI", basicPackageName + "BasicSpinnerUI", "ToolBarSeparatorUI", basicPackageName + "BasicToolBarSeparatorUI", "PopupMenuSeparatorUI", basicPackageName + "BasicPopupMenuSeparatorUI", "TabbedPaneUI", basicPackageName + "BasicTabbedPaneUI", "TextAreaUI", basicPackageName + "BasicTextAreaUI", "TextFieldUI", basicPackageName + "BasicTextFieldUI", "PasswordFieldUI", basicPackageName + "BasicPasswordFieldUI", "TextPaneUI", basicPackageName + "BasicTextPaneUI", "EditorPaneUI", basicPackageName + "BasicEditorPaneUI", "TreeUI", basicPackageName + "BasicTreeUI", "LabelUI", basicPackageName + "BasicLabelUI", "ListUI", basicPackageName + "BasicListUI", "ToolBarUI", basicPackageName + "BasicToolBarUI", "ToolTipUI", basicPackageName + "BasicToolTipUI", "ComboBoxUI", basicPackageName + "BasicComboBoxUI", "TableUI", basicPackageName + "BasicTableUI", "TableHeaderUI", basicPackageName + "BasicTableHeaderUI", "InternalFrameUI", basicPackageName + "BasicInternalFrameUI", "DesktopPaneUI", basicPackageName + "BasicDesktopPaneUI", "DesktopIconUI", basicPackageName + "BasicDesktopIconUI", "OptionPaneUI", basicPackageName + "BasicOptionPaneUI", "PanelUI", basicPackageName + "BasicPanelUI", "ViewportUI", basicPackageName + "BasicViewportUI", "RootPaneUI", basicPackageName + "BasicRootPaneUI", }; table.putDefaults(uiDefaults); } /** * Populates {@code table} with system colors. This creates an * array of {@code name-color} pairs and invokes {@code * loadSystemColors}. * <p> * The name is a {@code String} that corresponds to the name of * one of the static {@code SystemColor} fields in the {@code * SystemColor} class. A name-color pair is created for every * such {@code SystemColor} field. * <p> * The {@code color} corresponds to a hex {@code String} as * understood by {@code Color.decode}. For example, one of the * {@code name-color} pairs is {@code * "desktop"-"#005C5C"}. This corresponds to the {@code * SystemColor} field {@code desktop}, with a color value of * {@code new Color(0x005C5C)}. * <p> * The following shows two of the {@code name-color} pairs: * <pre> * String[] nameColorPairs = new String[] { * "desktop", "#005C5C", * "activeCaption", "#000080" }; * loadSystemColors(table, nameColorPairs, isNativeLookAndFeel()); * </pre> * * As previously stated, this invokes {@code loadSystemColors} * with the supplied {@code table} and {@code name-color} pair * array. The last argument to {@code loadSystemColors} indicates * whether the value of the field in {@code SystemColor} should be * used. This method passes the value of {@code * isNativeLookAndFeel()} as the last argument to {@code loadSystemColors}. * * @param table the {@code UIDefaults} object the values are added to * @throws NullPointerException if {@code table} is {@code null} * * @see java.awt.SystemColor * @see #getDefaults * @see #loadSystemColors */ 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). */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -