| 1 |
/* |
| 2 |
* @(#)${NAME} |
| 3 |
* |
| 4 |
* Copyright 2002 - 2004 JIDE Software Inc. All rights reserved. |
| 5 |
*/ |
| 6 |
package com.jidesoft.plaf.office2003; |
| 7 |
|
| 8 |
import com.jidesoft.icons.IconsFactory; |
| 9 |
import com.jidesoft.plaf.*; |
| 10 |
import com.jidesoft.plaf.vsnet.ConvertListener; |
| 11 |
import com.jidesoft.utils.ColorUtils; |
| 12 |
|
| 13 |
import javax.swing.*; |
| 14 |
import javax.swing.plaf.ColorUIResource; |
| 15 |
import java.awt.*; |
| 16 |
|
| 17 |
/** |
| 18 |
* The default 2003 theme. This theme doesn't define any color of its own but derive all colors from |
| 19 |
* the underlying L&F. If your application used a customized L&F other than Windows L&F, this is |
| 20 |
* the preferred theme as it will consider the colors defined underlying L&F to make it looks consistent |
| 21 |
* than hard-coded themes such as BLUE, HOMESTEAD of METALLIC. |
| 22 |
*/ |
| 23 |
public class DefaultOffice2003Theme extends Office2003Theme { |
| 24 |
private static final double DAKRER_FACTOR = 0.76; |
| 25 |
private static final double FACTOR = 0.85; |
| 26 |
private static final double LIGHTER_FACTOR = 0.95; |
| 27 |
private static final double EVEN_LIGHTER_FACTOR = 0.97; |
| 28 |
|
| 29 |
private static boolean _useStandardSelectionColor; |
| 30 |
|
| 31 |
static { |
| 32 |
try { |
| 33 |
_useStandardSelectionColor = XPUtils.isXPStyleOn(); |
| 34 |
} |
| 35 |
catch (UnsupportedOperationException e) { |
| 36 |
_useStandardSelectionColor = false; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
static Color getLighterColor(Color color) { |
| 41 |
if (Color.BLACK.equals(color)) { |
| 42 |
return color; |
| 43 |
} |
| 44 |
else if (Color.WHITE.equals(color)) { |
| 45 |
return color; |
| 46 |
} |
| 47 |
return ColorUtils.getDerivedColor(color, 0.93f); |
| 48 |
} |
| 49 |
|
| 50 |
public DefaultOffice2003Theme() { |
| 51 |
super(XPUtils.DEFAULT); |
| 52 |
|
| 53 |
if (!isUseStandardSelectionColor()) { |
| 54 |
putDerivedSelectionColor(); |
| 55 |
} |
| 56 |
|
| 57 |
Toolkit toolkit = Toolkit.getDefaultToolkit(); |
| 58 |
WindowsDesktopProperty control = new WindowsDesktopProperty("win.3d.backgroundColor", UIDefaultsLookup.get("control"), toolkit); |
| 59 |
Object controlDk2 = new ExtWindowsDesktopProperty(new String[]{"win.3d.backgroundColor"}, |
| 60 |
new Object[]{UIDefaultsLookup.get("control")}, toolkit, new ConvertListener() { |
| 61 |
public Object convert(Object[] obj) { |
| 62 |
return darker((Color) obj[0], LIGHTER_FACTOR); |
| 63 |
} |
| 64 |
}); |
| 65 |
Object controlDk = new ExtWindowsDesktopProperty(new String[]{"win.3d.backgroundColor"}, |
| 66 |
new Object[]{UIDefaultsLookup.get("control")}, toolkit, new ConvertListener() { |
| 67 |
public Object convert(Object[] obj) { |
| 68 |
return darker((Color) obj[0], DAKRER_FACTOR); |
| 69 |
} |
| 70 |
}); |
| 71 |
Object controlLt = new ExtWindowsDesktopProperty(new String[]{"win.3d.highlightColor"}, |
| 72 |
new Object[]{UIDefaultsLookup.get("controlLtHighlight")}, toolkit, new ConvertListener() { |
| 73 |
public Object convert(Object[] obj) { |
| 74 |
return brighter((Color) obj[0], FACTOR); |
| 75 |
} |
| 76 |
}); |
| 77 |
WindowsDesktopProperty controlShadow = new WindowsDesktopProperty("win.3d.shadowColor", UIDefaultsLookup.get("controlShadow"), toolkit); |
| 78 |
Object controlDkShadow = new ExtWindowsDesktopProperty(new String[]{"win.3d.shadowColor"}, |
| 79 |
new Object[]{UIDefaultsLookup.get("controlShadow")}, toolkit, new ConvertListener() { |
| 80 |
public Object convert(Object[] obj) { |
| 81 |
return darker((Color) obj[0], FACTOR); |
| 82 |
} |
| 83 |
}); |
| 84 |
WindowsDesktopProperty controlText = new WindowsDesktopProperty("win.button.textColor", UIDefaultsLookup.get("controlText"), toolkit); |
| 85 |
WindowsDesktopProperty controlLtHighlight = new WindowsDesktopProperty("win.3d.highlightColor", UIDefaultsLookup.get("controlLtHighlight"), toolkit); |
| 86 |
WindowsDesktopProperty commandBarCaption = new WindowsDesktopProperty("", UIDefaultsLookup.get("inactiveCaption"), toolkit); |
| 87 |
Object menuItemBackground = new ExtWindowsDesktopProperty(//Actual color 249, 248, 247 |
| 88 |
new String[]{"win.3d.backgroundColor"}, new Object[]{UIDefaultsLookup.get("control")}, toolkit, new ConvertListener() { |
| 89 |
public Object convert(Object[] obj) { |
| 90 |
return new ColorUIResource(getLighterColor((Color) obj[0])); |
| 91 |
} |
| 92 |
}); |
| 93 |
|
| 94 |
Object uiDefaults[] = { |
| 95 |
"control", control, |
| 96 |
"controlLt", controlLt, |
| 97 |
"controlDk", control, |
| 98 |
"controlShadow", controlShadow, |
| 99 |
|
| 100 |
"OptionPane.bannerLt", new ColorUIResource(0, 52, 206), |
| 101 |
"OptionPane.bannerDk", new ColorUIResource(45, 96, 249), |
| 102 |
"OptionPane.bannerForeground", new ColorUIResource(255, 255, 255), |
| 103 |
|
| 104 |
"Separator.foreground", controlShadow, |
| 105 |
"Separator.foregroundLt", controlLt, |
| 106 |
|
| 107 |
"Gripper.foreground", controlShadow, |
| 108 |
"Gripper.foregroundLt", controlLt, |
| 109 |
|
| 110 |
"Chevron.backgroundLt", controlDk, |
| 111 |
"Chevron.backgroundDk", controlShadow, |
| 112 |
|
| 113 |
"Divider.backgroundLt", controlShadow, |
| 114 |
"Divider.backgroundDk", controlDkShadow, |
| 115 |
|
| 116 |
"backgroundLt", controlLt, |
| 117 |
"backgroundDk", control, |
| 118 |
|
| 119 |
"selection.border", controlShadow, |
| 120 |
|
| 121 |
"MenuItem.background", menuItemBackground, |
| 122 |
|
| 123 |
"DockableFrameTitlePane.backgroundLt", controlLt, |
| 124 |
"DockableFrameTitlePane.backgroundDk", controlDk2, |
| 125 |
"DockableFrameTitlePane.activeForeground", controlText, |
| 126 |
"DockableFrameTitlePane.inactiveForeground", controlText, |
| 127 |
"DockableFrame.backgroundLt", controlLt, |
| 128 |
"DockableFrame.backgroundDk", controlLt, |
| 129 |
|
| 130 |
"CommandBar.titleBarBackground", commandBarCaption, |
| 131 |
}; |
| 132 |
putDefaults(uiDefaults); |
| 133 |
|
| 134 |
int products = LookAndFeelFactory.getProductsUsed(); |
| 135 |
|
| 136 |
if ((products & LookAndFeelFactory.PRODUCT_COMPONENTS) != 0) { |
| 137 |
final int SIZE = 20; |
| 138 |
final int MASK_SIZE = 11; |
| 139 |
ImageIcon collapsiblePaneImage = IconsFactory.getImageIcon(Office2003WindowsUtils.class, "icons/collapsible_pane_default.png"); // 20 x 20 |
| 140 |
ImageIcon collapsiblePaneMask = IconsFactory.getImageIcon(Office2003WindowsUtils.class, "icons/collapsible_pane_mask.png"); // 11 x 11 |
| 141 |
ImageIcon normalIcon = IconsFactory.getIcon(null, collapsiblePaneImage, 0, 0, SIZE, SIZE); |
| 142 |
ImageIcon emphasizedIcon = IconsFactory.getIcon(null, collapsiblePaneImage, SIZE, 0, SIZE, SIZE); |
| 143 |
ImageIcon downMark = IconsFactory.getIcon(null, collapsiblePaneMask, 0, 0, MASK_SIZE, MASK_SIZE); |
| 144 |
ImageIcon upMark = IconsFactory.getIcon(null, collapsiblePaneMask, 0, MASK_SIZE, MASK_SIZE, MASK_SIZE); |
| 145 |
uiDefaults = new Object[]{ |
| 146 |
"CollapsiblePane.contentBackground", controlLtHighlight, |
| 147 |
"CollapsiblePanes.backgroundLt", control, |
| 148 |
"CollapsiblePanes.backgroundDk", controlShadow, |
| 149 |
"CollapsiblePaneTitlePane.backgroundLt", controlLt, |
| 150 |
"CollapsiblePaneTitlePane.backgroundDk", control, |
| 151 |
"CollapsiblePaneTitlePane.foreground", controlText, |
| 152 |
"CollapsiblePaneTitlePane.foreground.focus", controlText, |
| 153 |
"CollapsiblePaneTitlePane.backgroundLt.emphasized", controlShadow, |
| 154 |
"CollapsiblePaneTitlePane.backgroundDk.emphasized", controlDkShadow, |
| 155 |
"CollapsiblePaneTitlePane.foreground.emphasized", controlLtHighlight, |
| 156 |
"CollapsiblePaneTitlePane.foreground.focus.emphasized", controlLtHighlight, |
| 157 |
"CollapsiblePane.downIcon", IconsFactory.getOverlayIcon(null, normalIcon, downMark, SwingConstants.CENTER), |
| 158 |
"CollapsiblePane.upIcon", IconsFactory.getOverlayIcon(null, normalIcon, upMark, SwingConstants.CENTER), |
| 159 |
"CollapsiblePane.downIcon.emphasized", IconsFactory.getOverlayIcon(null, emphasizedIcon, downMark, SwingConstants.CENTER), |
| 160 |
"CollapsiblePane.upIcon.emphasized", IconsFactory.getOverlayIcon(null, emphasizedIcon, upMark, SwingConstants.CENTER), |
| 161 |
"CollapsiblePane.upMask", upMark, |
| 162 |
"CollapsiblePane.downMask", downMark, |
| 163 |
"CollapsiblePane.titleButtonBackground", normalIcon, |
| 164 |
"CollapsiblePane.titleButtonBackground.emphasized", emphasizedIcon, |
| 165 |
}; |
| 166 |
putDefaults(uiDefaults); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
private void putDerivedSelectionColor() { |
| 171 |
Object selectionRollover = new ActiveValue() { |
| 172 |
public Object createValue(UIDefaults table) { |
| 173 |
return UIDefaultsLookup.getColor("JideButton.focusedBackground"); |
| 174 |
} |
| 175 |
}; |
| 176 |
Object selectionRolloverLt = new ActiveValue() { |
| 177 |
public Object createValue(UIDefaults table) { |
| 178 |
return brighter(UIDefaultsLookup.getColor("JideButton.focusedBackground"), LIGHTER_FACTOR); |
| 179 |
} |
| 180 |
}; |
| 181 |
Object selectionRolloverDk = new ActiveValue() { |
| 182 |
public Object createValue(UIDefaults table) { |
| 183 |
return darker(UIDefaultsLookup.getColor("JideButton.focusedBackground"), LIGHTER_FACTOR); |
| 184 |
} |
| 185 |
}; |
| 186 |
|
| 187 |
Object selectionSelected = new ActiveValue() { |
| 188 |
public Object createValue(UIDefaults table) { |
| 189 |
return UIDefaultsLookup.getColor("JideButton.selectedBackground"); |
| 190 |
} |
| 191 |
}; |
| 192 |
Object selectionSelectedLt = new ActiveValue() { |
| 193 |
public Object createValue(UIDefaults table) { |
| 194 |
return brighter(UIDefaultsLookup.getColor("JideButton.selectedBackground"), LIGHTER_FACTOR); |
| 195 |
} |
| 196 |
}; |
| 197 |
Object selectionSelectedDk = new ActiveValue() { |
| 198 |
public Object createValue(UIDefaults table) { |
| 199 |
return darker(UIDefaultsLookup.getColor("JideButton.selectedBackground"), LIGHTER_FACTOR); |
| 200 |
} |
| 201 |
}; |
| 202 |
Object selectionSelectedAndFocused = new ActiveValue() { |
| 203 |
public Object createValue(UIDefaults table) { |
| 204 |
return UIDefaultsLookup.getColor("JideButton.selectedAndFocusedBackground"); |
| 205 |
} |
| 206 |
}; |
| 207 |
Object selectionSelectedAndFocusedLt = new ActiveValue() { |
| 208 |
public Object createValue(UIDefaults table) { |
| 209 |
return brighter(UIDefaultsLookup.getColor("JideButton.selectedAndFocusedBackground"), LIGHTER_FACTOR); |
| 210 |
} |
| 211 |
}; |
| 212 |
Object selectionSelectedAndFocusedDk = new ActiveValue() { |
| 213 |
public Object createValue(UIDefaults table) { |
| 214 |
return darker(UIDefaultsLookup.getColor("JideButton.selectedAndFocusedBackground"), LIGHTER_FACTOR); |
| 215 |
} |
| 216 |
}; |
| 217 |
|
| 218 |
Object[] uiDefaultsSelection = new Object[]{ |
| 219 |
"selection.Rollover", selectionRollover, |
| 220 |
"selection.RolloverLt", selectionRolloverLt, |
| 221 |
"selection.RolloverDk", selectionRolloverDk, |
| 222 |
|
| 223 |
"selection.Selected", selectionSelected, |
| 224 |
"selection.SelectedLt", selectionSelectedLt, |
| 225 |
"selection.SelectedDk", selectionSelectedDk, |
| 226 |
|
| 227 |
"selection.Pressed", selectionSelectedAndFocused, // focused and selected; |
| 228 |
"selection.PressedLt", selectionSelectedAndFocusedLt, |
| 229 |
"selection.PressedDk", selectionSelectedAndFocusedDk |
| 230 |
}; |
| 231 |
putDefaults(uiDefaultsSelection); |
| 232 |
} |
| 233 |
|
| 234 |
private void removeDerivedSelectionColor() { |
| 235 |
Object[] uiDefaultsSelection = new Object[]{ |
| 236 |
"selection.Rollover", |
| 237 |
"selection.RolloverLt", |
| 238 |
"selection.RolloverDk", |
| 239 |
|
| 240 |
"selection.Selected", |
| 241 |
"selection.SelectedLt", |
| 242 |
"selection.SelectedDk", |
| 243 |
|
| 244 |
"selection.Pressed", |
| 245 |
"selection.PressedLt", |
| 246 |
"selection.PressedDk" |
| 247 |
}; |
| 248 |
for (Object o : uiDefaultsSelection) { |
| 249 |
remove(o); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* Creates a new <code>Color</code> that is a brighter version of this |
| 255 |
* <code>Color</code>. |
| 256 |
* <p/> |
| 257 |
* This method applies an arbitrary scale factor to each of the three RGB |
| 258 |
* components of this <code>Color</code> to create a brighter version |
| 259 |
* of this <code>Color</code>. Although <code>brighter</code> and |
| 260 |
* <code>darker</code> are inverse operations, the results of a |
| 261 |
* series of invocations of these two methods might be inconsistent |
| 262 |
* because of rounding errors. |
| 263 |
* |
| 264 |
* @return a new <code>Color</code> object that is |
| 265 |
* a brighter version of this <code>Color</code>. |
| 266 |
* @see java.awt.Color#darker |
| 267 |
* @since JDK1.0 |
| 268 |
*/ |
| 269 |
private Color brighter(Color c, double factor) { |
| 270 |
int r = c.getRed(); |
| 271 |
int g = c.getGreen(); |
| 272 |
int b = c.getBlue(); |
| 273 |
|
| 274 |
/* From 2D group: |
| 275 |
* 1. black.brighter() should return grey |
| 276 |
* 2. applying brighter to blue will always return blue, brighter |
| 277 |
* 3. non pure color (non zero rgb) will eventually return white |
| 278 |
*/ |
| 279 |
int i = (int) (1.0 / (1.0 - factor)); |
| 280 |
if (r == 0 && g == 0 && b == 0) { |
| 281 |
return new Color(i, i, i); |
| 282 |
} |
| 283 |
if (r > 0 && r < i) r = i; |
| 284 |
if (g > 0 && g < i) g = i; |
| 285 |
if (b > 0 && b < i) b = i; |
| 286 |
|
| 287 |
return new Color(Math.min((int) (r / factor), 255), |
| 288 |
Math.min((int) (g / factor), 255), |
| 289 |
Math.min((int) (b / factor), 255)); |
| 290 |
} |
| 291 |
|
| 292 |
/** |
| 293 |
* Creates a new <code>Color</code> that is a darker version of this |
| 294 |
* <code>Color</code>. |
| 295 |
* <p/> |
| 296 |
* This method applies an arbitrary scale factor to each of the three RGB |
| 297 |
* components of this <code>Color</code> to create a darker version of |
| 298 |
* this <code>Color</code>. Although <code>brighter</code> and |
| 299 |
* <code>darker</code> are inverse operations, the results of a series |
| 300 |
* of invocations of these two methods might be inconsistent because |
| 301 |
* of rounding errors. |
| 302 |
* |
| 303 |
* @return a new <code>Color</code> object that is |
| 304 |
* a darker version of this <code>Color</code>. |
| 305 |
* @see java.awt.Color#brighter |
| 306 |
* @since JDK1.0 |
| 307 |
*/ |
| 308 |
private Color darker(Color c, double factor) { |
| 309 |
return new Color(Math.max((int) (c.getRed() * factor), 0), |
| 310 |
Math.max((int) (c.getGreen() * factor), 0), |
| 311 |
Math.max((int) (c.getBlue() * factor), 0)); |
| 312 |
} |
| 313 |
|
| 314 |
/** |
| 315 |
* Checks if the standard selection color will be used. |
| 316 |
* |
| 317 |
* @return true if the standard selection color will be used. |
| 318 |
*/ |
| 319 |
public static boolean isUseStandardSelectionColor() { |
| 320 |
return _useStandardSelectionColor; |
| 321 |
} |
| 322 |
|
| 323 |
/** |
| 324 |
* Sets if the standard selection color will be used. The standard selection color (orange) is the color that used in Office 2003 |
| 325 |
* to indicate a button is selected or focused. By default it will be used for all Office 2003 theme including DefayltOffice2003Theme. |
| 326 |
* If user chooses not to use it, the theme will derive the color from the default selection color of the LookAndFeel. |
| 327 |
* <p/> |
| 328 |
* If you want to call this method, make sure you call it before LookAndFeelFactory.installJideExtension(...) is called. |
| 329 |
* |
| 330 |
* @param useStandardSelectionColor |
| 331 |
*/ |
| 332 |
public static void setUseStandardSelectionColor(boolean useStandardSelectionColor) { |
| 333 |
_useStandardSelectionColor = useStandardSelectionColor; |
| 334 |
} |
| 335 |
} |