📄 basiclookandfeel.java
字号:
/* BasicLookAndFeel.java -- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.plaf.basic;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.event.InputEvent;import java.awt.event.KeyEvent;import java.io.Serializable;import java.util.Enumeration;import java.util.ResourceBundle;import javax.swing.BorderFactory;import javax.swing.KeyStroke;import javax.swing.LookAndFeel;import javax.swing.UIDefaults;import javax.swing.border.BevelBorder;import javax.swing.border.Border;import javax.swing.plaf.BorderUIResource;import javax.swing.plaf.ColorUIResource;import javax.swing.plaf.DimensionUIResource;import javax.swing.plaf.FontUIResource;import javax.swing.plaf.IconUIResource;import javax.swing.plaf.InsetsUIResource;import javax.swing.text.JTextComponent;/** * BasicLookAndFeel * @author Andrew Selkirk */public abstract class BasicLookAndFeel extends LookAndFeel implements Serializable{ static final long serialVersionUID = -6096995660290287879L; /** * Creates a new instance of the Basic look and feel. */ public BasicLookAndFeel() { // TODO } /** * Creates and returns a new instance of the default resources for this look * and feel. * * @return The UI defaults. */ public UIDefaults getDefaults() { // Variables UIDefaults def = new UIDefaults(); // Initialize Class Defaults initClassDefaults(def); // Initialize System Colour Defaults initSystemColorDefaults(def); // Initialize Component Defaults initComponentDefaults(def); // Return UI Defaults return def; } /** * Populates the <code>defaults</code> table with mappings between class IDs * and fully qualified class names for the UI delegates. * * @param defaults the defaults table (<code>null</code> not permitted). */ protected void initClassDefaults(UIDefaults defaults) { // Variables Object[] uiDefaults; // Initialize Class Defaults uiDefaults = new Object[] { "ButtonUI", "javax.swing.plaf.basic.BasicButtonUI", "CheckBoxMenuItemUI", "javax.swing.plaf.basic.BasicCheckBoxMenuItemUI", "CheckBoxUI", "javax.swing.plaf.basic.BasicCheckBoxUI", "ColorChooserUI", "javax.swing.plaf.basic.BasicColorChooserUI", "ComboBoxUI", "javax.swing.plaf.basic.BasicComboBoxUI", "DesktopIconUI", "javax.swing.plaf.basic.BasicDesktopIconUI", "DesktopPaneUI", "javax.swing.plaf.basic.BasicDesktopPaneUI", "EditorPaneUI", "javax.swing.plaf.basic.BasicEditorPaneUI", "FileChooserUI", "javax.swing.plaf.basic.BasicFileChooserUI", "FormattedTextFieldUI", "javax.swing.plaf.basic.BasicFormattedTextFieldUI", "InternalFrameUI", "javax.swing.plaf.basic.BasicInternalFrameUI", "LabelUI", "javax.swing.plaf.basic.BasicLabelUI", "ListUI", "javax.swing.plaf.basic.BasicListUI", "MenuBarUI", "javax.swing.plaf.basic.BasicMenuBarUI", "MenuItemUI", "javax.swing.plaf.basic.BasicMenuItemUI", "MenuUI", "javax.swing.plaf.basic.BasicMenuUI", "OptionPaneUI", "javax.swing.plaf.basic.BasicOptionPaneUI", "PanelUI", "javax.swing.plaf.basic.BasicPanelUI", "PasswordFieldUI", "javax.swing.plaf.basic.BasicPasswordFieldUI", "PopupMenuSeparatorUI", "javax.swing.plaf.basic.BasicPopupMenuSeparatorUI", "PopupMenuUI", "javax.swing.plaf.basic.BasicPopupMenuUI", "ProgressBarUI", "javax.swing.plaf.basic.BasicProgressBarUI", "RadioButtonMenuItemUI", "javax.swing.plaf.basic.BasicRadioButtonMenuItemUI", "RadioButtonUI", "javax.swing.plaf.basic.BasicRadioButtonUI", "RootPaneUI", "javax.swing.plaf.basic.BasicRootPaneUI", "ScrollBarUI", "javax.swing.plaf.basic.BasicScrollBarUI", "ScrollPaneUI", "javax.swing.plaf.basic.BasicScrollPaneUI", "SeparatorUI", "javax.swing.plaf.basic.BasicSeparatorUI", "SliderUI", "javax.swing.plaf.basic.BasicSliderUI", "SplitPaneUI", "javax.swing.plaf.basic.BasicSplitPaneUI", "SpinnerUI", "javax.swing.plaf.basic.BasicSpinnerUI", "StandardDialogUI", "javax.swing.plaf.basic.BasicStandardDialogUI", "TabbedPaneUI", "javax.swing.plaf.basic.BasicTabbedPaneUI", "TableHeaderUI", "javax.swing.plaf.basic.BasicTableHeaderUI", "TableUI", "javax.swing.plaf.basic.BasicTableUI", "TextPaneUI", "javax.swing.plaf.basic.BasicTextPaneUI", "TextAreaUI", "javax.swing.plaf.basic.BasicTextAreaUI", "TextFieldUI", "javax.swing.plaf.basic.BasicTextFieldUI", "TextPaneUI", "javax.swing.plaf.basic.BasicTextPaneUI", "ToggleButtonUI", "javax.swing.plaf.basic.BasicToggleButtonUI", "ToolBarSeparatorUI", "javax.swing.plaf.basic.BasicToolBarSeparatorUI", "ToolBarUI", "javax.swing.plaf.basic.BasicToolBarUI", "ToolTipUI", "javax.swing.plaf.basic.BasicToolTipUI", "TreeUI", "javax.swing.plaf.basic.BasicTreeUI", "ViewportUI", "javax.swing.plaf.basic.BasicViewportUI" }; // Add Class Defaults to UI Defaults table defaults.putDefaults(uiDefaults); } /** * Populates the <code>defaults</code> table with system color defaults. * * @param defaults the defaults table (<code>null</code> not permitted). */ protected void initSystemColorDefaults(UIDefaults defaults) { Color highLight = new Color(249, 247, 246); Color light = new Color(239, 235, 231); Color shadow = new Color(139, 136, 134); Color darkShadow = new Color(16, 16, 16); Object[] uiDefaults; uiDefaults = new Object[] { "activeCaption", new ColorUIResource(0, 0, 128), "activeCaptionBorder", new ColorUIResource(Color.lightGray), "activeCaptionText", new ColorUIResource(Color.white), "control", new ColorUIResource(light), "controlDkShadow", new ColorUIResource(shadow), "controlHighlight", new ColorUIResource(highLight), "controlLtHighlight", new ColorUIResource(highLight), "controlShadow", new ColorUIResource(shadow), "controlText", new ColorUIResource(darkShadow), "desktop", new ColorUIResource(0, 92, 92), "inactiveCaption", new ColorUIResource(Color.gray), "inactiveCaptionBorder", new ColorUIResource(Color.lightGray), "inactiveCaptionText", new ColorUIResource(Color.lightGray), "info", new ColorUIResource(light), "infoText", new ColorUIResource(darkShadow), "menu", new ColorUIResource(light), "menuText", new ColorUIResource(darkShadow), "scrollbar", new ColorUIResource(light), "text", new ColorUIResource(Color.white), "textHighlight", new ColorUIResource(Color.black), "textHighlightText", new ColorUIResource(Color.white), "textInactiveText", new ColorUIResource(Color.gray), "textText", new ColorUIResource(Color.black), "window", new ColorUIResource(light), "windowBorder", new ColorUIResource(Color.black), "windowText", new ColorUIResource(darkShadow) }; defaults.putDefaults(uiDefaults); } /** * Loads the system colors. This method is not implemented yet. * * @param defaults the defaults table (<code>null</code> not permitted). * @param systemColors TODO * @param useNative TODO */ protected void loadSystemColors(UIDefaults defaults, String[] systemColors, boolean useNative) { // TODO } /** * loadResourceBundle * @param defaults TODO */ private void loadResourceBundle(UIDefaults defaults) { ResourceBundle bundle; Enumeration e; String key; String value; bundle = ResourceBundle.getBundle("resources/basic"); // Process Resources e = bundle.getKeys(); while (e.hasMoreElements()) { key = (String) e.nextElement(); value = bundle.getString(key); defaults.put(key, value); } } /** * initComponentDefaults * @param defaults the defaults table (<code>null</code> not permitted). */ protected void initComponentDefaults(UIDefaults defaults) { Object[] uiDefaults; Color highLight = new Color(249, 247, 246); Color light = new Color(239, 235, 231); Color shadow = new Color(139, 136, 134); Color darkShadow = new Color(16, 16, 16); uiDefaults = new Object[] { "AbstractUndoableEdit.undoText", "Undo", "AbstractUndoableEdit.redoText", "Redo", "Button.background", new ColorUIResource(Color.LIGHT_GRAY), "Button.border", new UIDefaults.LazyValue() { public Object createValue(UIDefaults table) { return BasicBorders.getButtonBorder(); } }, "Button.darkShadow", new ColorUIResource(Color.BLACK), "Button.focusInputMap", new UIDefaults.LazyInputMap(new Object[] { "SPACE", "pressed", "released SPACE", "released" }), "Button.font", new FontUIResource("Dialog", Font.PLAIN, 12), "Button.foreground", new ColorUIResource(Color.BLACK), "Button.highlight", new ColorUIResource(Color.WHITE), "Button.light", new ColorUIResource(Color.LIGHT_GRAY), "Button.margin", new InsetsUIResource(2, 14, 2, 14), "Button.shadow", new ColorUIResource(Color.GRAY), "Button.textIconGap", new Integer(4), "Button.textShiftOffset", new Integer(0), "CheckBox.background", new ColorUIResource(new Color(204, 204, 204)), "CheckBox.border", new BorderUIResource.CompoundBorderUIResource(null, null), "CheckBox.focusInputMap", new UIDefaults.LazyInputMap(new Object[] { "SPACE", "pressed", "released SPACE", "released" }), "CheckBox.font", new FontUIResource("Dialog", Font.PLAIN, 12), "CheckBox.foreground", new ColorUIResource(darkShadow), "CheckBox.icon", new UIDefaults.LazyValue() { public Object createValue(UIDefaults def) { return BasicIconFactory.getCheckBoxIcon(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -