?? basiclookandfeel.java
字號:
/* * @(#)BasicLookAndFeel.java 1.242 06/08/16 * * Copyright 2005 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 com.sun.java.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 java.beans.PropertyChangeListener;import java.beans.PropertyChangeEvent;/** * Implements the a standard base LookAndFeel class from which * standard desktop LookAndFeel classes (JLF, Mac, Windows, etc.) * can be derived. This class cannot be instantiated directly, * however the UI classes "Basic" defines can be. * <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.242 08/16/06 * @author unattributed */public abstract class BasicLookAndFeel extends LookAndFeel implements Serializable{ /** * Whether or not the developer has created a JPopupMenu. */ static boolean hasPopups; /** * Lock used when manipulating clipPlaying. */ private Object audioLock = new Object(); /** * The Clip that is currently playing (set in AudioAction). */ private Clip clipPlaying; PopupInvocationHelper invocator = null; /* * Listen for our AppContext being disposed */ private PropertyChangeListener disposer = null; public UIDefaults getDefaults() { UIDefaults table = new UIDefaults(); initClassDefaults(table); initSystemColorDefaults(table); initComponentDefaults(table); return table; } /** * UIManager.setLookAndFeel calls this method before the first call * (and typically the only call) to getDefaults(). */ public void initialize() { if (hasPopups) { createdPopup(); } } /** * UIManager.setLookAndFeel calls this method just * before we're replaced by a new default look and feel. */ public void uninitialize() { Toolkit tk = Toolkit.getDefaultToolkit(); 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. AppContext.getAppContext().removePropertyChangeListener( AppContext.GUI_DISPOSED, disposer); disposer = null; } } /** * 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 #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); } /** * 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 */ "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", /* 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 */ "scrollbar", "#E0E0E0", /* Scrollbar background (usually the "track") */ "info", "#FFFFE1", /* ??? */ "infoText", "#000000" /* ??? */ }; loadSystemColors(table, defaultSystemColors, isNativeLookAndFeel()); } /** * If this is the native look and feel the initial values for the * system color properties are the same as the SystemColor constants. * If not we use the integer color values in the <code>systemColors</code> * argument. */ protected void loadSystemColors(UIDefaults table, String[] systemColors, boolean useNative) { /* PENDING(hmuller) We don't load the system colors below because * they're not reliable. Hopefully we'll be able to do better in * a future version of AWT. */ if (useNative) { for(int i = 0; i < systemColors.length; i += 2) { Color color = Color.black; try { String name = systemColors[i]; color = (Color)(SystemColor.class.getField(name).get(null)); } catch (Exception e) { } table.put(systemColors[i], new ColorUIResource(color)); } } else { for(int i = 0; i < systemColors.length; i += 2) { Color color = Color.black; try { color = Color.decode(systemColors[i + 1]); } catch(NumberFormatException e) { e.printStackTrace(); } table.put(systemColors[i], new ColorUIResource(color)); } } } /** * Initialize the defaults table with the name of the ResourceBundle * used for getting localized defaults. Also initialize the default * locale used when no locale is passed into UIDefaults.get(). The * default locale should generally not be relied upon. It is here for * compatability with releases prior to 1.4. */ private void initResourceBundle(UIDefaults table) { table.setDefaultLocale( Locale.getDefault() ); table.addResourceBundle( "com.sun.swing.internal.plaf.basic.resources.basic" ); } protected void initComponentDefaults(UIDefaults table) { initResourceBundle(table); // *** Shared Integers Integer fiveHundred = new Integer(500); // *** Shared Longs Long oneThousand = new Long(1000); // *** Shared Fonts Integer twelve = new Integer(12); Integer fontPlain = new Integer(Font.PLAIN); Integer fontBold = new Integer(Font.BOLD);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -