metallookandfeel.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,404 行 · 第 1/5 页

JAVA
1,404
字号
		             "shift DOWN", "selectNextExtendSelection",		          "shift KP_DOWN", "selectNextExtendSelection",		                  "RIGHT", "selectChild",		               "KP_RIGHT", "selectChild",		                   "LEFT", "selectParent",		                "KP_LEFT", "selectParent",		                "PAGE_UP", "scrollUpChangeSelection",		          "shift PAGE_UP", "scrollUpExtendSelection",		              "PAGE_DOWN", "scrollDownChangeSelection",		        "shift PAGE_DOWN", "scrollDownExtendSelection",		                   "HOME", "selectFirst",		             "shift HOME", "selectFirstExtendSelection",		                    "END", "selectLast",		              "shift END", "selectLastExtendSelection",		                     "F2", "startEditing",		                 "ctrl A", "selectAll",		             "ctrl SLASH", "selectAll",		        "ctrl BACK_SLASH", "clearSelection",		             "ctrl SPACE", "toggleSelectionPreserveAnchor",		            "shift SPACE", "extendSelection",		              "ctrl HOME", "selectFirstChangeLead",		               "ctrl END", "selectLastChangeLead",		                "ctrl UP", "selectPreviousChangeLead",		             "ctrl KP_UP", "selectPreviousChangeLead",		              "ctrl DOWN", "selectNextChangeLead",		           "ctrl KP_DOWN", "selectNextChangeLead",		         "ctrl PAGE_DOWN", "scrollDownChangeLead",		   "ctrl shift PAGE_DOWN", "scrollDownExtendSelection",		           "ctrl PAGE_UP", "scrollUpChangeLead",		     "ctrl shift PAGE_UP", "scrollUpExtendSelection",		              "ctrl LEFT", "scrollLeft",		           "ctrl KP_LEFT", "scrollLeft",		             "ctrl RIGHT", "scrollRight",		          "ctrl KP_RIGHT", "scrollRight",		                  "SPACE", "toggleSelectionPreserveAnchor",		 }),	    "Tree.ancestorInputMap",	       new UIDefaults.LazyInputMap(new Object[] {		     "ESCAPE", "cancel"		 }),            // ToolBar            "ToolBar.border", toolBarBorder,            "ToolBar.background", getMenuBackground(),            "ToolBar.foreground", getMenuForeground(),            "ToolBar.font", menuTextValue,            "ToolBar.dockingBackground", getMenuBackground(),            "ToolBar.floatingBackground", getMenuBackground(),            "ToolBar.dockingForeground", getPrimaryControlDarkShadow(),             "ToolBar.floatingForeground", getPrimaryControl(),	    "ToolBar.ancestorInputMap",	       new UIDefaults.LazyInputMap(new Object[] {		        "UP", "navigateUp",		     "KP_UP", "navigateUp",		      "DOWN", "navigateDown",		   "KP_DOWN", "navigateDown",		      "LEFT", "navigateLeft",		   "KP_LEFT", "navigateLeft",		     "RIGHT", "navigateRight",		  "KP_RIGHT", "navigateRight"		 }),            // RootPane            "RootPane.frameBorder", new MetalLazyValue(                      "javax.swing.plaf.metal.MetalBorders$FrameBorder"),            "RootPane.plainDialogBorder", dialogBorder,            "RootPane.informationDialogBorder", dialogBorder,            "RootPane.errorDialogBorder", new MetalLazyValue(                      "javax.swing.plaf.metal.MetalBorders$ErrorDialogBorder"),            "RootPane.colorChooserDialogBorder", questionDialogBorder,            "RootPane.fileChooserDialogBorder", questionDialogBorder,            "RootPane.questionDialogBorder", questionDialogBorder,            "RootPane.warningDialogBorder", new MetalLazyValue(                    "javax.swing.plaf.metal.MetalBorders$WarningDialogBorder"),	    // These bindings are only enabled when there is a default	    // button set on the rootpane.	    "RootPane.defaultButtonWindowKeyBindings", new Object[] {		             "ENTER", "press",		    "released ENTER", "release",		        "ctrl ENTER", "press",	       "ctrl released ENTER", "release"	      },        };        table.putDefaults(defaults);        if (isWindows() && useSystemFonts() && theme.isSystemTheme()) {            Toolkit kit = Toolkit.getDefaultToolkit();            Object messageFont = new MetalFontDesktopProperty(                              "win.messagebox.font.height", kit, MetalTheme.                              CONTROL_TEXT_FONT);            defaults = new Object[] {                "OptionPane.messageFont", messageFont,                "OptionPane.buttonFont", messageFont,            };            table.putDefaults(defaults);        }    }    protected void createDefaultTheme() {        getCurrentTheme();    }    public UIDefaults getDefaults() {        // PENDING: move this to initialize when API changes are allowed        METAL_LOOK_AND_FEEL_INITED = true;        createDefaultTheme();        UIDefaults table = super.getDefaults();        currentTheme.addCustomEntriesToTable(table);        currentTheme.install();        return table;    }    /**     * <p>     * Invoked when the user attempts an invalid operation,      * such as pasting into an uneditable <code>JTextField</code>      * that has focus.     * </p>     * <p>     * If the user has enabled visual error indication on     * the desktop, this method will flash the caption bar     * of the active window. The user can also set the     * property awt.visualbell=true to achieve the same     * results.     * </p>     *     * @param component Component the error occured in, may be      *			null indicating the error condition is      *			not directly associated with a      *			<code>Component</code>.     *      * @see javax.swing.LookAndFeel#provideErrorFeedback     */    public void provideErrorFeedback(Component component) {	super.provideErrorFeedback(component);    }    public static void setCurrentTheme(MetalTheme theme) {        // NOTE: because you need to recreate the look and feel after        // this step, we don't bother blowing away any potential windows        // values.        if (theme == null) {            throw new NullPointerException("Can't have null theme");        }        currentTheme = theme;	cachedAppContext = AppContext.getAppContext();	cachedAppContext.put( "currentMetalTheme", theme );    }    private static MetalTheme getCurrentTheme() {        AppContext context = AppContext.getAppContext();	if ( cachedAppContext != context ) {	    currentTheme = (MetalTheme)context.get( "currentMetalTheme" );            if (currentTheme == null) {                // This will happen in two cases:                // . When MetalLookAndFeel is first being initialized.                // . When a new AppContext has been created that hasn't                //   triggered UIManager to load a LAF. Rather than invoke                //   a method on the UIManager, which would trigger the loading                //   of a potentially different LAF, we directly set the                //   Theme here.                if (useHighContrastTheme()) {                    currentTheme = new MetalHighContrastTheme();                }                else {                    currentTheme = new DefaultMetalTheme();                }                setCurrentTheme(currentTheme);            }	    cachedAppContext = context;	}	return currentTheme;    }    public static FontUIResource getControlTextFont() { return getCurrentTheme().getControlTextFont();}    public static FontUIResource getSystemTextFont() { return getCurrentTheme().getSystemTextFont();}    public static FontUIResource getUserTextFont() { return getCurrentTheme().getUserTextFont();}    public static FontUIResource getMenuTextFont() { return getCurrentTheme().getMenuTextFont();}    public static FontUIResource getWindowTitleFont() { return getCurrentTheme().getWindowTitleFont();}    public static FontUIResource getSubTextFont() { return getCurrentTheme().getSubTextFont();}    public static ColorUIResource getDesktopColor() { return getCurrentTheme().getDesktopColor(); }    public static ColorUIResource getFocusColor() { return getCurrentTheme().getFocusColor(); }    public static ColorUIResource getWhite() { return getCurrentTheme().getWhite(); }    public static ColorUIResource getBlack() { return getCurrentTheme().getBlack(); }    public static ColorUIResource getControl() { return getCurrentTheme().getControl(); }    public static ColorUIResource getControlShadow() { return getCurrentTheme().getControlShadow(); }    public static ColorUIResource getControlDarkShadow() { return getCurrentTheme().getControlDarkShadow(); }    public static ColorUIResource getControlInfo() { return getCurrentTheme().getControlInfo(); }     public static ColorUIResource getControlHighlight() { return getCurrentTheme().getControlHighlight(); }    public static ColorUIResource getControlDisabled() { return getCurrentTheme().getControlDisabled(); }    public static ColorUIResource getPrimaryControl() { return getCurrentTheme().getPrimaryControl(); }      public static ColorUIResource getPrimaryControlShadow() { return getCurrentTheme().getPrimaryControlShadow(); }      public static ColorUIResource getPrimaryControlDarkShadow() { return getCurrentTheme().getPrimaryControlDarkShadow(); }      public static ColorUIResource getPrimaryControlInfo() { return getCurrentTheme().getPrimaryControlInfo(); }     public static ColorUIResource getPrimaryControlHighlight() { return getCurrentTheme().getPrimaryControlHighlight(); }      public static ColorUIResource getSystemTextColor() { return getCurrentTheme().getSystemTextColor(); }    public static ColorUIResource getControlTextColor() { return getCurrentTheme().getControlTextColor(); }      public static ColorUIResource getInactiveControlTextColor() { return getCurrentTheme().getInactiveControlTextColor(); }      public static ColorUIResource getInactiveSystemTextColor() { return getCurrentTheme().getInactiveSystemTextColor(); }    public static ColorUIResource getUserTextColor() { return getCurrentTheme().getUserTextColor(); }    public static ColorUIResource getTextHighlightColor() { return getCurrentTheme().getTextHighlightColor(); }    public static ColorUIResource getHighlightedTextColor() { return getCurrentTheme().getHighlightedTextColor(); }    public static ColorUIResource getWindowBackground() { return getCurrentTheme().getWindowBackground(); }    public static ColorUIResource getWindowTitleBackground() { return getCurrentTheme().getWindowTitleBackground(); }    public static ColorUIResource getWindowTitleForeground() { return getCurrentTheme().getWindowTitleForeground(); }    public static ColorUIResource getWindowTitleInactiveBackground() { return getCurrentTheme().getWindowTitleInactiveBackground(); }    public static ColorUIResource getWindowTitleInactiveForeground() { return getCurrentTheme().getWindowTitleInactiveForeground(); }    public static ColorUIResource getMenuBackground() { return getCurrentTheme().getMenuBackground(); }    public static ColorUIResource getMenuForeground() { return getCurrentTheme().getMenuForeground(); }    public static ColorUIResource getMenuSelectedBackground() { return getCurrentTheme().getMenuSelectedBackground(); }    public static ColorUIResource getMenuSelectedForeground() { return getCurrentTheme().getMenuSelectedForeground(); }    public static ColorUIResource getMenuDisabledForeground() { return getCurrentTheme().getMenuDisabledForeground(); }    public static ColorUIResource getSeparatorBackground() { return getCurrentTheme().getSeparatorBackground(); }    public static ColorUIResource getSeparatorForeground() { return getCurrentTheme().getSeparatorForeground(); }    public static ColorUIResource getAcceleratorForeground() { return getCurrentTheme().getAcceleratorForeground(); }    public static ColorUIResource getAcceleratorSelectedForeground() { return getCurrentTheme().getAcceleratorSelectedForeground(); }    /**     * MetalLazyValue is a slimmed down version of <code>ProxyLaxyValue</code>.     * The code is duplicate so that it can get at the package private     * classes in metal.     */    private static class MetalLazyValue implements UIDefaults.LazyValue {        /**         * Name of the class to create.         */        private String className;        MetalLazyValue(String name) {            this.className = name;        }        public Object createValue(UIDefaults table) {            try {                Class c = Class.forName(className);                return c.newInstance();            } catch (ClassNotFoundException cnfe) {            } catch (InstantiationException ie) {            } catch (IllegalAccessException iae) {            }            return null;        }    }    /**     * FontActiveValue redirects to the appropriate metal theme method.     */    private static class FontActiveValue implements UIDefaults.ActiveValue {        private int type;        private MetalTheme theme;        FontActiveValue(MetalTheme theme, int type) {            this.theme = theme;            this.type = type;        }        public Object createValue(UIDefaults table) {            Object value = null;            switch (type) {            case MetalTheme.CONTROL_TEXT_FONT:                value = theme.getControlTextFont();                break;            case MetalTheme.SYSTEM_TEXT_FONT:                value = theme.getSystemTextFont();                break;            case M

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?