Debian Codegraph @

src/com/jidesoft/plaf/office2003/BasicOffice2003Theme.java

raw
1 /*
2 * @(#)BasicOffice2003Theme.java 3/17/2006
3 *
4 * Copyright 2002 - 2006 JIDE Software Inc. All rights reserved.
5 */
6
7 package com.jidesoft.plaf.office2003;
8
9 import com.jidesoft.icons.IconsFactory;
10 import com.jidesoft.plaf.LookAndFeelFactory;
11 import com.jidesoft.utils.ColorUtils;
12
13 import javax.swing.*;
14 import javax.swing.plaf.ColorUIResource;
15 import java.awt.*;
16
17 /**
18 * <tt>BasicOffice2003Theme</tt> is a special Office2003 theme that uses a base color to calculate
19 * all other colors used by JIDE components. This is done regardless what current XP theme you are using.
20 */
21 public class BasicOffice2003Theme extends Office2003Theme {
22 private Color _baseColor;
23
24 public BasicOffice2003Theme(String themeName) {
25 super(themeName);
26 }
27
28 /**
29 * Sets the base color. The Office2003 theme will use this color as base color and calculate
30 * all other colors that will be used by JIDE components.
31 *
32 * @param color the base color.
33 * @param derivedSelectionColor if deriving selection colors from the base color. Selection color is used in
34 * places like JideButton's background and DockableFrame's title pane background.
35 * @param prefix the prefix is for the expand/collapse icon on collapsible pane. Available prefixes are
36 * "default", "blue", "homestead", "metallic", and "gray". You can decide which one to use depending
37 * on what base color is. In most cases, "default" works just fine. But if your base color has more blue,
38 * using "blue" will produce a better result. If green, you can use "homestead".
39 */
40 public void setBaseColor(Color color, boolean derivedSelectionColor, String prefix) {
41 _baseColor = color;
42 float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
43 Color selectionColor = Color.getHSBColor(hsb[0], (hsb[1] > 0.01) ? 0.45f : hsb[0], 0.90f);
44
45 Object uiDefaults[] = {
46 "control", ColorUtils.getDerivedColor(color, 0.9f),
47 "controlLt", ColorUtils.getDerivedColor(color, 0.95f),
48 "controlDk", ColorUtils.getDerivedColor(color, 0.8f),
49 "controlShadow", ColorUtils.getDerivedColor(color, 0.4f),
50
51 "TabbedPane.selectDk", ColorUtils.getDerivedColor(selectionColor, 0.40f),
52 "TabbedPane.selectLt", ColorUtils.getDerivedColor(selectionColor, 0.55f),
53
54 "OptionPane.bannerLt", ColorUtils.getDerivedColor(color, 0.5f),
55 "OptionPane.bannerDk", ColorUtils.getDerivedColor(color, 0.3f),
56 "OptionPane.bannerForeground", new ColorUIResource(255, 255, 255),
57
58 "Separator.foreground", ColorUtils.getDerivedColor(color, 0.4f),
59 "Separator.foregroundLt", ColorUtils.getDerivedColor(color, 1.0f),
60
61 "Gripper.foreground", ColorUtils.getDerivedColor(color, 0.6f),
62 "Gripper.foregroundLt", ColorUtils.getDerivedColor(color, 0.92f),
63
64 "Chevron.backgroundLt", ColorUtils.getDerivedColor(color, 0.85f),
65 "Chevron.backgroundDk", ColorUtils.getDerivedColor(color, 0.75f),
66
67 "Divider.backgroundLt", ColorUtils.getDerivedColor(color, 0.9f),
68 "Divider.backgroundDk", ColorUtils.getDerivedColor(color, 0.97f),
69
70 "backgroundLt", ColorUtils.getDerivedColor(color, 0.95f),
71 "backgroundDk", ColorUtils.getDerivedColor(color, 0.9f),
72
73 "CommandBar.titleBarBackground", ColorUtils.getDerivedColor(color, 0.6f),
74 "MenuItem.background", ColorUtils.getDerivedColor(color, 0.95f),
75
76 "DockableFrameTitlePane.backgroundLt", ColorUtils.getDerivedColor(color, 0.92f),
77 "DockableFrameTitlePane.backgroundDk", ColorUtils.getDerivedColor(color, 0.85f),
78 "DockableFrameTitlePane.activeForeground", new ColorUIResource(0, 0, 0),
79 "DockableFrameTitlePane.inactiveForeground", new ColorUIResource(0, 0, 0),
80 "DockableFrame.backgroundLt", ColorUtils.getDerivedColor(color, 0.92f),
81 "DockableFrame.backgroundDk", ColorUtils.getDerivedColor(color, 0.89f),
82
83 "selection.border", ColorUtils.getDerivedColor(color, 0.5f)
84 };
85
86 putDefaults(uiDefaults);
87
88 int products = LookAndFeelFactory.getProductsUsed();
89 if ((products & LookAndFeelFactory.PRODUCT_COMPONENTS) != 0) {
90 final int SIZE = 20;
91 final int MASK_SIZE = 11;
92 ImageIcon collapsiblePaneImage = IconsFactory.getImageIcon(Office2003WindowsUtils.class, "icons/collapsible_pane_" + prefix + ".png"); // 20 x 20
93 ImageIcon collapsiblePaneMask = IconsFactory.getImageIcon(Office2003WindowsUtils.class, "icons/collapsible_pane_mask.png"); // 11 x 11
94 ImageIcon normalIcon = IconsFactory.getIcon(null, collapsiblePaneImage, 0, 0, SIZE, SIZE);
95 ImageIcon emphasizedIcon = IconsFactory.getIcon(null, collapsiblePaneImage, SIZE, 0, SIZE, SIZE);
96 ImageIcon downMark = IconsFactory.getIcon(null, collapsiblePaneMask, 0, 0, MASK_SIZE, MASK_SIZE);
97 ImageIcon upMark = IconsFactory.getIcon(null, collapsiblePaneMask, 0, MASK_SIZE, MASK_SIZE, MASK_SIZE);
98 uiDefaults = new Object[]{
99 "CollapsiblePane.contentBackground", ColorUtils.getDerivedColor(color, 0.98f),
100 "CollapsiblePanes.backgroundLt", ColorUtils.getDerivedColor(color, 0.82f),
101 "CollapsiblePanes.backgroundDk", ColorUtils.getDerivedColor(color, 0.78f),
102 "CollapsiblePaneTitlePane.backgroundLt", ColorUtils.getDerivedColor(color, 0.98f),
103 "CollapsiblePaneTitlePane.backgroundDk", ColorUtils.getDerivedColor(color, 0.93f),
104 "CollapsiblePaneTitlePane.foreground", new ColorUIResource(63, 61, 61),
105 "CollapsiblePaneTitlePane.foreground.focus", new ColorUIResource(126, 124, 124),
106 "CollapsiblePaneTitlePane.backgroundLt.emphasized", ColorUtils.getDerivedColor(color, 0.7f),
107 "CollapsiblePaneTitlePane.backgroundDk.emphasized", ColorUtils.getDerivedColor(color, 0.72f),
108 "CollapsiblePaneTitlePane.foreground.emphasized", new ColorUIResource(255, 255, 255),
109 "CollapsiblePaneTitlePane.foreground.focus.emphasized", new ColorUIResource(230, 230, 230),
110
111 "CollapsiblePane.downIcon", IconsFactory.getOverlayIcon(null, normalIcon, downMark, SwingConstants.CENTER),
112 "CollapsiblePane.upIcon", IconsFactory.getOverlayIcon(null, normalIcon, upMark, SwingConstants.CENTER),
113 "CollapsiblePane.downIcon.emphasized", IconsFactory.getOverlayIcon(null, emphasizedIcon, downMark, SwingConstants.CENTER),
114 "CollapsiblePane.upIcon.emphasized", IconsFactory.getOverlayIcon(null, emphasizedIcon, upMark, SwingConstants.CENTER),
115 "CollapsiblePane.upMask", upMark,
116 "CollapsiblePane.downMask", downMark,
117 "CollapsiblePane.titleButtonBackground", normalIcon,
118 "CollapsiblePane.titleButtonBackground.emphasized", emphasizedIcon,
119 };
120 putDefaults(uiDefaults);
121 }
122
123 if (derivedSelectionColor) {
124 Object[] uiDefaultsSelection = new Object[]{
125 "selection.Rollover", selectionColor,
126 "selection.RolloverLt", ColorUtils.getDerivedColor(selectionColor, 0.55f),
127 "selection.RolloverDk", ColorUtils.getDerivedColor(selectionColor, 0.45f),
128
129 "selection.Selected", ColorUtils.getDerivedColor(selectionColor, 0.45f),
130 "selection.SelectedLt", ColorUtils.getDerivedColor(selectionColor, 0.55f),
131 "selection.SelectedDk", ColorUtils.getDerivedColor(selectionColor, 0.50f),
132
133 "selection.Pressed", ColorUtils.getDerivedColor(selectionColor, 0.4f), // focused and selected;
134 "selection.PressedLt", ColorUtils.getDerivedColor(selectionColor, 0.45f),
135 "selection.PressedDk", ColorUtils.getDerivedColor(selectionColor, 0.35f)
136 };
137 putDefaults(uiDefaultsSelection);
138 }
139
140 }
141
142 /**
143 * Gets the base color for this theme. It is set using
144 * {@link #setBaseColor(java.awt.Color,boolean,String)} method.
145 *
146 * @return the base color.
147 */
148 public Color getBaseColor() {
149 return _baseColor;
150 }
151 }