📄 infonodelookandfeeltheme.java
字号:
/*
* Copyright (C) 2004 NNL Technology AB
* Visit www.infonode.net for information about InfoNode(R)
* products and how to contact NNL Technology AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
// $Id: InfoNodeLookAndFeelTheme.java,v 1.16 2005/12/04 13:46:03 jesper Exp $
package net.infonode.gui.laf;
import net.infonode.gui.Colors;
import net.infonode.gui.border.EdgeBorder;
import net.infonode.gui.border.EtchedLineBorder;
import net.infonode.gui.border.HighlightBorder;
import net.infonode.gui.border.PopupMenuBorder;
import net.infonode.gui.icon.EmptyIcon;
import net.infonode.gui.icon.button.*;
import net.infonode.gui.laf.value.BorderValue;
import net.infonode.gui.laf.value.ColorValue;
import net.infonode.gui.laf.value.FontValue;
import net.infonode.util.ArrayUtil;
import net.infonode.util.ColorUtil;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.plaf.*;
import java.awt.*;
/**
* A theme for InfoNode look and feel. The theme infers some default colors from others, so modifying a color might
* affect other, unmodified colors.
*
* @author $Author: jesper $
* @version $Revision: 1.16 $
*/
public class InfoNodeLookAndFeelTheme {
private static final float PRIMARY_HUE = Colors.ROYAL_BLUE_HUE;
private static final float PRIMARY_SATURATION = 0.6f;
private static final float PRIMARY_BRIGHTNESS = 0.67f;
public static final Color DEFAULT_CONTROL_COLOR = Color.getHSBColor(Colors.SAND_HUE, 0.058f, 0.89f);
public static final Color DEFAULT_PRIMARY_CONTROL_COLOR = Color.getHSBColor(PRIMARY_HUE, PRIMARY_SATURATION, 1f);
public static final Color DEFAULT_BACKGROUND_COLOR = new Color(250, 250, 247);
public static final Color DEFAULT_TEXT_COLOR = Color.BLACK;
public static final Color DEFAULT_SELECTED_BACKGROUND_COLOR = Color.getHSBColor(PRIMARY_HUE,
PRIMARY_SATURATION + 0.1f,
PRIMARY_BRIGHTNESS);
public static final Color DEFAULT_SELECTED_TEXT_COLOR = Color.WHITE;
public static final Color DEFAULT_TOOLTIP_BACKGROUND_COLOR = new Color(255, 255, 180);
public static final Color DEFAULT_TOOLTIP_FOREGROUND_COLOR = Color.BLACK;
public static final Color DEFAULT_DESKTOP_COLOR = Color.getHSBColor(PRIMARY_HUE - 0.02f,
PRIMARY_SATURATION,
PRIMARY_BRIGHTNESS);
public static final int DEFAULT_FONT_SIZE = 11;
private static final String[] FONT_NAMES = {/*"Tahoma", */"Dialog"};
private FontUIResource font = new FontUIResource("Dialog", 0, 11);
private FontUIResource boldFont;
private ColorValue controlColor = new ColorValue();
private ColorValue primaryControlColor = new ColorValue();
private ColorValue backgroundColor = new ColorValue();
private ColorValue textColor = new ColorValue();
private ColorValue selectedTextBackgroundColor = new ColorValue();
private ColorValue focusColor = new ColorValue();
private ColorValue selectedTextColor = new ColorValue();
private ColorValue tooltipBackgroundColor = new ColorValue(DEFAULT_TOOLTIP_BACKGROUND_COLOR);
private ColorValue tooltipForegroundColor = new ColorValue(DEFAULT_TOOLTIP_FOREGROUND_COLOR);
private ColorValue desktopColor = new ColorValue(DEFAULT_DESKTOP_COLOR);
private ColorValue treeIconBackgroundColor = new ColorValue();
private ColorValue selectedMenuBackgroundColor = new ColorValue();
private ColorValue selectedMenuForegroundColor = new ColorValue();
private ColorValue inactiveTextColor = new ColorValue();
private ColorUIResource controlHighlightColor;
private ColorUIResource controlLightShadowColor;
private ColorUIResource controlShadowColor;
private ColorUIResource controlDarkShadowColor;
private ColorUIResource primaryControlHighlightColor;
private ColorUIResource primaryControlShadowColor;
private ColorUIResource primaryControlDarkShadowColor;
private ColorValue scrollBarBackgroundColor = new ColorValue();
private ColorUIResource scrollBarBackgroundShadowColor;
private ColorValue activeInternalFrameTitleBackgroundColor = new ColorValue();
private ColorValue activeInternalFrameTitleGradientColor = new ColorValue();
private ColorValue activeInternalFrameTitleForegroundColor = new ColorValue();
private ColorValue inactiveInternalFrameTitleBackgroundColor = new ColorValue();
private ColorValue inactiveInternalFrameTitleGradientColor = new ColorValue();
private ColorValue inactiveInternalFrameTitleForegroundColor = new ColorValue();
private IconUIResource internalFrameIcon = new IconUIResource(new BorderIcon(new WindowIcon(Color.BLACK, 12), 2));
private IconUIResource internalFrameIconifyIcon = new IconUIResource(new MinimizeIcon());
private IconUIResource internalFrameMinimizeIcon = new IconUIResource(new RestoreIcon());
private IconUIResource internalFrameMaximizeIcon = new IconUIResource(new MaximizeIcon());
private IconUIResource internalFrameCloseIcon = new IconUIResource(new CloseIcon());
private BorderUIResource internalFrameBorder = new BorderUIResource(new LineBorder(Color.BLACK, 2));
private FontValue internalFrameTitleFont = new FontValue();
private FontValue optionPaneButtonFont = new FontValue();
private IconUIResource treeOpenIcon = new IconUIResource(EmptyIcon.INSTANCE);
private IconUIResource treeClosedIcon = new IconUIResource(EmptyIcon.INSTANCE);
private IconUIResource treeLeafIcon = new IconUIResource(EmptyIcon.INSTANCE);
private BorderValue menuBarBorder = new BorderValue();
private BorderValue popupMenuBorder = new BorderValue();
private BorderValue tableHeaderCellBorder = new BorderValue();
private BorderValue textFieldBorder = new BorderValue();
private BorderValue listItemBorder = new BorderValue(new EmptyBorder(1, 4, 1, 4));
private BorderValue listFocusedItemBorder = new BorderValue();
private int splitPaneDividerSize = 7;
private int scrollBarWidth = 17;
private InsetsUIResource buttonMargin = new InsetsUIResource(1, 6, 1, 6);
private double shadingFactor = 1.6;
private String name;
/**
* Creates a default InfoNode look and feel theme.
*/
public InfoNodeLookAndFeelTheme() {
this("Default Theme",
DEFAULT_CONTROL_COLOR,
DEFAULT_PRIMARY_CONTROL_COLOR,
DEFAULT_BACKGROUND_COLOR,
DEFAULT_TEXT_COLOR,
DEFAULT_SELECTED_BACKGROUND_COLOR,
DEFAULT_SELECTED_TEXT_COLOR);
}
/**
* Creates a theme with custom colors.
*
* @param name the name of this theme
* @param controlColor the background color for buttons, labels etc.
* @param primaryControlColor the color of scrollbar "knobs", text and menu selection background
* @param backgroundColor the background color for viewports, tree's, tables etc.
* @param textColor the text color
*/
public InfoNodeLookAndFeelTheme(String name,
Color controlColor,
Color primaryControlColor,
Color backgroundColor,
Color textColor) {
this(name,
controlColor,
primaryControlColor,
backgroundColor,
textColor,
primaryControlColor,
ColorUtil.getOpposite(primaryControlColor));
}
/**
* Creates a theme with custom colors.
*
* @param name the name of this theme
* @param controlColor the background color for buttons, labels etc.
* @param primaryControlColor the color of scrollbar "knobs"
* @param backgroundColor the background color for viewports, tree's, tables etc.
* @param textColor the text color
* @param selectedBackgroundColor the background color for selected text, selected menu items
* @param selectedTextColor the text color for selected text, selected menu items
*/
public InfoNodeLookAndFeelTheme(String name,
Color controlColor,
Color primaryControlColor,
Color backgroundColor,
Color textColor,
Color selectedBackgroundColor,
Color selectedTextColor) {
this(name,
controlColor,
primaryControlColor,
backgroundColor,
textColor,
selectedBackgroundColor,
selectedTextColor,
1.3);
}
/**
* Creates a theme with custom colors.
*
* @param name the name of this theme
* @param controlColor the background color for buttons, labels etc.
* @param primaryControlColor the color of scrollbar "knobs"
* @param backgroundColor the background color for viewports, tree's, tables etc.
* @param textColor the text color
* @param selectedBackgroundColor the background color for selected text, selected menu items
* @param selectedTextColor the text color for selected text, selected menu items
* @param shadingFactor the shading factor is used when calculating brighter and darker control colors. A
* higher factor gives brighter and darker colors.
*/
public InfoNodeLookAndFeelTheme(String name,
Color controlColor,
Color primaryControlColor,
Color backgroundColor,
Color textColor,
Color selectedBackgroundColor,
Color selectedTextColor,
double shadingFactor) {
this.name = name;
String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
for (int i = 0; i < FONT_NAMES.length; i++) {
if (ArrayUtil.containsEqual(fontNames, FONT_NAMES[i])) {
font = new FontUIResource(new Font(FONT_NAMES[i], Font.PLAIN, DEFAULT_FONT_SIZE));
break;
}
}
updateFonts();
this.controlColor.setColor(controlColor);
this.primaryControlColor.setColor(primaryControlColor);
this.backgroundColor.setColor(backgroundColor);
this.selectedTextBackgroundColor.setColor(selectedBackgroundColor);
this.selectedTextColor.setColor(selectedTextColor);
this.textColor.setColor(textColor);
this.shadingFactor = shadingFactor;
updateColors();
}
private void updateFonts() {
boldFont = new FontUIResource(font.deriveFont(Font.BOLD));
internalFrameTitleFont.setDefaultFont(boldFont);
optionPaneButtonFont.setDefaultFont(boldFont);
}
private void updateColors() {
focusColor.setDefaultColor(ColorUtil.blend(controlColor.getColor(), textColor.getColor(), 0.5f));
inactiveTextColor.setDefaultColor(focusColor);
double invShadeAmount = 1.0 / (1 + shadingFactor * 1.2);
double invShadeAmount2 = 1.0 / (1 + shadingFactor / 2);
double invShadeAmount3 = 1.0 / (1 + shadingFactor / 7);
controlHighlightColor = new ColorUIResource(ColorUtil.mult(controlColor.getColor(), 1 + shadingFactor));
controlLightShadowColor = new ColorUIResource(ColorUtil.mult(controlColor.getColor(), invShadeAmount3));
controlShadowColor = new ColorUIResource(ColorUtil.mult(controlColor.getColor(), invShadeAmount2));
controlDarkShadowColor = new ColorUIResource(ColorUtil.mult(controlColor.getColor(), invShadeAmount));
primaryControlHighlightColor = controlHighlightColor;
primaryControlShadowColor = new ColorUIResource(ColorUtil.mult(primaryControlColor.getColor(), invShadeAmount2));
primaryControlDarkShadowColor =
new ColorUIResource(ColorUtil.mult(primaryControlColor.getColor(), invShadeAmount));
scrollBarBackgroundColor.setDefaultColor(controlLightShadowColor);
scrollBarBackgroundShadowColor = new ColorUIResource(ColorUtil.mult(scrollBarBackgroundColor.getColor(),
invShadeAmount));
selectedMenuBackgroundColor.setDefaultColor(selectedTextBackgroundColor);
selectedMenuForegroundColor.setDefaultColor(selectedTextColor);
treeIconBackgroundColor.setDefaultColor(
ColorUtil.blend(backgroundColor.getColor(), primaryControlColor.getColor(), 0.15f));
activeInternalFrameTitleBackgroundColor.setDefaultColor(ColorUtil.blend(primaryControlColor.getColor(),
ColorUtil.getOpposite(getTextColor()),
0.5f));
activeInternalFrameTitleForegroundColor.setDefaultColor(getTextColor());
activeInternalFrameTitleGradientColor.setDefaultColor(
ColorUtil.mult(activeInternalFrameTitleBackgroundColor.getColor(), 1.2));
inactiveInternalFrameTitleBackgroundColor.setDefaultColor(controlLightShadowColor);
inactiveInternalFrameTitleForegroundColor.setDefaultColor(getTextColor());
inactiveInternalFrameTitleGradientColor.setDefaultColor(
ColorUtil.mult(inactiveInternalFrameTitleBackgroundColor.getColor(), 1.2));
menuBarBorder.setDefaultBorder(new BorderUIResource(
new EtchedLineBorder(false, false, true, false, controlHighlightColor, controlDarkShadowColor)));
popupMenuBorder.setDefaultBorder(
new BorderUIResource(new PopupMenuBorder(controlHighlightColor, controlDarkShadowColor)));
textFieldBorder.setDefaultBorder(
new BorderUIResource(new CompoundBorder(new LineBorder(controlDarkShadowColor), new EmptyBorder(1, 2, 1, 2))));
tableHeaderCellBorder.setDefaultBorder(new BorderUIResource(new CompoundBorder(new CompoundBorder(
new EdgeBorder(controlDarkShadowColor, false, true, false, true),
new HighlightBorder(false, controlHighlightColor)),
new EmptyBorder(1, 4, 1, 4))));
listFocusedItemBorder.setDefaultBorder(new CompoundBorder(new LineBorder(focusColor.getColor()),
new EmptyBorder(0, 3, 0, 3)));
}
/**
* Returns the theme name.
*
* @return the theme name
*/
public String getName() {
return name;
}
/**
* Returns the shading factor. The shading factor is used when calculating brighter and darker control colors. A
* higher factor gives brighter and darker colors.
*
* @return the shading factor
*/
public double getShadingFactor() {
return shadingFactor;
}
/**
* Sets the shading factor. The shading factor is used when calculating brighter and darker control colors. A higher
* factor gives brighter and darker colors.
*
* @param shadingFactor the shading factor
*/
public void setShadingFactor(double shadingFactor) {
this.shadingFactor = shadingFactor;
updateColors();
}
/**
* Returns the base font. This font is used as default font for all text.
*
* @return returns the base font
*/
public FontUIResource getFont() {
return font;
}
/**
* Sets the base font. This font is used as default font for all text.
*
* @param font the base font
*/
public void setFont(FontUIResource font) {
this.font = font;
updateFonts();
}
/**
* Gets the background color used for {@link javax.swing.JComponent}.
*
* @return the background color used for {@link javax.swing.JComponent}
*/
public ColorUIResource getControlColor() {
return controlColor.getColor();
}
/**
* Gets the color of scrollbar "knobs" etc.
*
* @return the color of scrollbar "knobs" etc,
*/
public ColorUIResource getPrimaryControlColor() {
return primaryControlColor.getColor();
}
/**
* Gets the background color for {@link javax.swing.JViewport}, {@link javax.swing.JTree}, {@link javax.swing.JTable}
* etc.
*
* @return the background color for {@link javax.swing.JViewport}, {@link javax.swing.JTree}, {@link
* javax.swing.JTable} etc.
*/
public ColorUIResource getBackgroundColor() {
return backgroundColor.getColor();
}
/**
* Gets the text color.
*
* @return the text color
*/
public ColorUIResource getTextColor() {
return textColor.getColor();
}
/**
* Gets the selected text background color.
*
* @return the selected text background color
*/
public ColorUIResource getSelectedTextBackgroundColor() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -