?? officexpcolormanager.java
字號:
/* ====================================================================
*
* Office Look and Feels License
* http://sourceforge.net/projects/officelnfs
*
* Copyright (c) 2003-2005 Robert Futrell. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The names "Office Look And Feels" and "OfficeLnFs" must not
* be used to endorse or promote products derived from this software
* without prior written permission. For written permission, please
* contact robert_futrell@users.sourceforge.net.
*
* 4. Products derived from this software may not be called "OfficeLnFs"
* nor may "OfficeLnFs" appear in their names without prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
package org.fife.plaf.OfficeXP;
import java.awt.Color;
import java.awt.Toolkit;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
/**
* Installs Windows UxTheme-specific colors.
*
* @author Robert Futrell
* @version 1.0
*/
public class OfficeXPColorManager implements PropertyChangeListener {
protected static final int COLOR_SCHEME_BLUE = 0;
protected static final int COLOR_SCHEME_GREEN = 1;
protected static final int COLOR_SCHEME_SILVER = 2;
protected static final String DLL_DESKTOP_PROPERTY = "win.xpstyle.dllName";
protected static final String STYLE_DESKTOP_PROPERTY = "win.xpstyle.colorName";
protected static final String THEMEACTIVE_DESKTOP_PROPERTY = "win.xpstyle.themeActive";
private static final Toolkit toolkit = Toolkit.getDefaultToolkit();
private static final int DELTA = 2;
/**
* Constructor.
*/
protected OfficeXPColorManager() {
}
/**
* Out of paranoia, we'll check RGB values +/- a delta. This method
* is called when trying to divine the current Windows color scheme
* based on a Swing UIDefaults color. Not being certain whether Sun
* grabs these values from Windows of hard-codes (possibly incorrect!)
* values which may change from one release to the next, we give
* ourselves a fudge factor.
*
* @param value The value to check.
* @param target The target value.
* @return Whether or not the specified value is "close enough" to the
* target.
*/
private static final boolean closeEnough(int value, int target) {
return (value>=(target-DELTA)) && (value<=(target+DELTA));
}
/**
* Returns the color scheme to use.
*
* @param table UI default values gotten from Swing's WindowsLookAndFeel.
* These have not yet been installed. This method examines them
* in an attempt to determine the current UxTheme color scheme
* being used.
* @return An integer representing the color scheme.
*/
protected static final int getColorScheme(final UIDefaults table) {
Color c = table.getColor("Menu.selectionBackground");
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
if (closeEnough(r,49) && closeEnough(g,106) && closeEnough(b,197)) {
return COLOR_SCHEME_BLUE;
}
else if (closeEnough(r,147) && closeEnough(g,160) && closeEnough(b,112)) {
return COLOR_SCHEME_GREEN;
}
else if (closeEnough(r,178) && closeEnough(g,180) && closeEnough(b,191)) {
return COLOR_SCHEME_SILVER;
}
else { // Unknown color scheme!
return COLOR_SCHEME_BLUE; // ???
}
}
protected Object[] getColorSchemeBlueDefaults(UIDefaults table) {
Object menuItemBackgroundColor = new ColorUIResource(252,252,249);
Object inactiveTextColor = new ColorUIResource(197,194,184);
Object highlightColor = new ColorUIResource(193,210,238);
Object[] defaults = {
"Button.disabledForeground", inactiveTextColor, // Actually JMenuItem's disabled text color (but not for accelerator).
"CheckBoxMenuItem.background", menuItemBackgroundColor,
"CheckBoxMenuItem.disabledForeground", inactiveTextColor,
"Menu.background", menuItemBackgroundColor,
"MenuItem.background", menuItemBackgroundColor,
"MenuItem.disabledForeground", inactiveTextColor, // Actually just the accelerator's disabled color.
"PopupMenu.background", menuItemBackgroundColor,
"PopupMenu.disabledForeground", inactiveTextColor,
"RadioButtonMenuItem.background", menuItemBackgroundColor,
"RadioButtonMenuItem.disabledForeground",inactiveTextColor,
"Separator.foreground", inactiveTextColor,
"Separator.background", menuItemBackgroundColor,
"ToolBar.background", new ColorUIResource(239,237,222),
"ToolBar.shadow", new ColorUIResource(191,188,177),
"OfficeLnF.ComboBox.Arrow.Armed.Gradient1", highlightColor,
"OfficeLnF.ComboBox.Arrow.Armed.Gradient2", null,
"OfficeLnF.ComboBox.Arrow.Selected.Gradient1", new ColorUIResource(152,181,226),
"OfficeLnF.ComboBox.Arrow.Selected.Gradient2", null,
"OfficeLnF.ComboBox.Arrow.Normal.Gradient1", table.getColor("Panel.background"),
"OfficeLnF.ComboBox.Arrow.Normal.Gradient2", null,
"OfficeLnF.HighlightBorderColor", new ColorUIResource(49,106,197),
"OfficeLnF.HighlightColor", highlightColor,
"OfficeXPLnF.PressedHighlightColor", new ColorUIResource(152,181,226),
"OfficeXPLnF.CheckBoxHighlightColor", new ColorUIResource(225,230,232),
"OfficeXPLnF.ChosenMenuColor", table.getColor("ToolBar.background"),
"OfficeLnF.MenuBorderColor", new ColorUIResource(138,134,122),
"OfficeXPLnF.MenuItemBackground", table.getColor("MenuItem.background"),
};
return defaults;
}
protected Object[] getColorSchemeGreenDefaults(UIDefaults table) {
Object menuItemBackgroundColor = new ColorUIResource(252,252,249);
Object inactiveTextColor = new ColorUIResource(197,194,184);
Object highlightColor = new ColorUIResource(206,209,195);
Object[] defaults = {
"Button.disabledForeground", inactiveTextColor, // Actually JMenuItem's disabled text color (but not for accelerator).
"CheckBoxMenuItem.background", menuItemBackgroundColor,
"CheckBoxMenuItem.disabledForeground", inactiveTextColor,
"Menu.background", menuItemBackgroundColor,
"MenuItem.background", menuItemBackgroundColor,
"MenuItem.disabledForeground", inactiveTextColor, // Actually just the accelerator's disabled color.
"PopupMenu.background", menuItemBackgroundColor,
"PopupMenu.disabledForeground", inactiveTextColor,
"RadioButtonMenuItem.background", menuItemBackgroundColor,
"RadioButtonMenuItem.disabledForeground",inactiveTextColor,
"Separator.foreground", inactiveTextColor,
"Separator.background", menuItemBackgroundColor,
"ToolBar.background", new ColorUIResource(239,237,222),
"ToolBar.shadow", new ColorUIResource(191,188,177),
"OfficeLnF.ComboBox.Arrow.Armed.Gradient1", highlightColor,
"OfficeLnF.ComboBox.Arrow.Armed.Gradient2", null,
"OfficeLnF.ComboBox.Arrow.Selected.Gradient1", new ColorUIResource(201,208,184),
"OfficeLnF.ComboBox.Arrow.Selected.Gradient2", null,
"OfficeLnF.ComboBox.Arrow.Normal.Gradient1", table.getColor("Panel.background"),
"OfficeLnF.ComboBox.Arrow.Normal.Gradient2", null,
"OfficeLnF.HighlightBorderColor", new ColorUIResource(147,160,112),
"OfficeLnF.HighlightColor", highlightColor,
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -