officexpcolormanager.java

来自「JAVA swing 的office xp 和 office2003 风格。」· Java 代码 · 共 435 行 · 第 1/2 页

JAVA
435
字号
			"OfficeXPLnF.PressedHighlightColor",	new ColorUIResource(201,208,184),
			"OfficeXPLnF.CheckBoxHighlightColor",	new ColorUIResource(234,235,223),
			"OfficeXPLnF.ChosenMenuColor",		table.getColor("ToolBar.background"),
			"OfficeLnF.MenuBorderColor",			new ColorUIResource(138,134,122),
			"OfficeXPLnF.MenuItemBackground",		table.getColor("MenuItem.background"),

		};

		return defaults;

	}


	protected Object[] getColorSchemeSilverDefaults(UIDefaults table) {

		// Unlike blue and green color schemes, the silver scheme's standard
		// panel background color is different from Swing's suggested value.
		Object standardBackground = new ColorUIResource(224,223,227); // Panels, menu bar, etc.
		Object menuItemBackgroundColor = new ColorUIResource(251,250,251);
		Object inactiveTextColor = new ColorUIResource(197,194,184);
		Object highlightColor = new ColorUIResource(199,199,202);

		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.

			"MenuBar.background",				standardBackground,

			"Panel.background",					standardBackground,

			"PopupMenu.background",				menuItemBackgroundColor,
			"PopupMenu.disabledForeground",		inactiveTextColor,

			"RadioButtonMenuItem.background",		menuItemBackgroundColor,
			"RadioButtonMenuItem.disabledForeground",inactiveTextColor,

			"Separator.foreground",				inactiveTextColor,
			"Separator.background",				menuItemBackgroundColor,

			"ToolBar.background",				new ColorUIResource(229,228,232),
			"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(210,211,216),
			"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(169,171,181),
			"OfficeLnF.HighlightColor",			highlightColor,
			"OfficeXPLnF.PressedHighlightColor",	new ColorUIResource(210,211,216),
			"OfficeXPLnF.CheckBoxHighlightColor",	new ColorUIResource(233,234,237),
			"OfficeXPLnF.ChosenMenuColor",		table.getColor("ToolBar.background"),
			"OfficeLnF.MenuBorderColor",			new ColorUIResource(126,126,129),
			"OfficeXPLnF.MenuItemBackground",		table.getColor("MenuItem.background"),

		};

		return defaults;

	}


	protected Object[] getColorSchemeWindowsClassicDefaults(UIDefaults table) {

		Object menuItemBackgroundColor = new ColorUIResource(249,248,247);
		Object inactiveTextColor = new ColorUIResource(166,166,166);
		Object highlightColor = new ColorUIResource(182,189,210);

		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(219,216,209),
			"ToolBar.shadow",					new ColorUIResource(166,166,166),

			"OfficeLnF.ComboBox.Arrow.Armed.Gradient1",		highlightColor,
			"OfficeLnF.ComboBox.Arrow.Armed.Gradient2",		null,
			"OfficeLnF.ComboBox.Arrow.Selected.Gradient1",	new ColorUIResource(133,146,181),
			"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(10,36,106),
			"OfficeLnF.HighlightColor",			highlightColor,
			"OfficeXPLnF.PressedHighlightColor",	new ColorUIResource(133,146,181),
			"OfficeXPLnF.CheckBoxHighlightColor",	new ColorUIResource(212,213,216),
			"OfficeXPLnF.ChosenMenuColor",		table.getColor("ToolBar.background"),
			"OfficeLnF.MenuBorderColor",			new ColorUIResource(102,102,102),
			"OfficeXPLnF.MenuItemBackground",		table.getColor("MenuItem.background"),

		};

		return defaults;

	}


	protected String getLookAndFeelClassName() {
		return "org.fife.plaf.OfficeXP.OfficeXPLookAndFeel";
	}


	public void install() {
		toolkit.addPropertyChangeListener(STYLE_DESKTOP_PROPERTY, this);
		toolkit.addPropertyChangeListener(THEMEACTIVE_DESKTOP_PROPERTY, this);
	}


	/**
	 * Listens for desktop property changes that signify the need to
	 * update Look and Feel-specific colors.
	 *
	 * @param e The property change event.
	 */
	public void propertyChange(PropertyChangeEvent e) {

		String name = e.getPropertyName();

		if (STYLE_DESKTOP_PROPERTY.equals(name) ||
				THEMEACTIVE_DESKTOP_PROPERTY.equals(name)) {
			// Unfortunately we must reload the entire look and feel.
			// In the future we should look for a way to simply reload the
			// colors.
			try {
				UIManager.setLookAndFeel(getLookAndFeelClassName());
			} catch (Exception ex) {
				// Never happens.
				ex.printStackTrace();
			}
		}

	}


	/**
	 * Updates the specified UI default values with Look and Feel-specific
	 * colors.
	 *
	 * @param table The UI defaults table.
	 */
	public void updateDefaultColors(UIDefaults table) {

		Object[] defaults = null;

		String theme = System.getProperty(OfficeXPLookAndFeel.THEME_PROPERTY);

		if (OfficeXPLookAndFeel.THEME_BLUE.equals(theme)) {
			defaults = getColorSchemeBlueDefaults(table);
		}
		else if (OfficeXPLookAndFeel.THEME_OLIVE.equals(theme)) {
			defaults = getColorSchemeGreenDefaults(table);
		}
		else if (OfficeXPLookAndFeel.THEME_SILVER.equals(theme)) {
			defaults = getColorSchemeSilverDefaults(table);
		}
		else if (OfficeXPLookAndFeel.THEME_CLASSIC.equals(theme)) {
			defaults = getColorSchemeWindowsClassicDefaults(table);
		}
		else { // No override
			Boolean themeActive = (Boolean)toolkit.getDesktopProperty(
										THEMEACTIVE_DESKTOP_PROPERTY);
			boolean isThemeActive = themeActive!=null ?
								themeActive.booleanValue() : false;
			if (isThemeActive) {
				switch (getColorScheme(table)) {
					case COLOR_SCHEME_BLUE:
						defaults = getColorSchemeBlueDefaults(table);
						break;
					case COLOR_SCHEME_GREEN:
						defaults = getColorSchemeGreenDefaults(table);
						break;
					case COLOR_SCHEME_SILVER:
						defaults = getColorSchemeSilverDefaults(table);
						break;
				}
			}
			else { // "Classic" Windows look.
				defaults = getColorSchemeWindowsClassicDefaults(table);
			}
		}

		table.putDefaults(defaults);

	}


	public void uninstall() {
		toolkit.removePropertyChangeListener(THEMEACTIVE_DESKTOP_PROPERTY,
										this);
		toolkit.removePropertyChangeListener(STYLE_DESKTOP_PROPERTY, this);
	}


}

⌨️ 快捷键说明

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