1 /* Copyright (C) 2005-2011 Fabio Riccardi */
2 
3 package com.lightcrafts.ui;
4 
5 import org.jvnet.substance.theme.SubstanceTheme;
6 import org.jvnet.substance.theme.SubstanceComplexTheme;
7 import org.jvnet.substance.theme.SubstanceEbonyTheme;
8 import org.jvnet.substance.color.BaseColorScheme;
9 import org.jvnet.substance.color.ColorScheme;
10 import org.jvnet.substance.skin.SubstanceAbstractSkin;
11 import org.jvnet.substance.painter.SimplisticSoftBorderReverseGradientPainter;
12 import org.jvnet.substance.painter.GlassGradientPainter;
13 import org.jvnet.substance.painter.AlphaControlBackgroundComposite;
14 import org.jvnet.substance.button.ClassicButtonShaper;
15 import org.jvnet.substance.watermark.SubstanceNoneWatermark;
16 import org.jvnet.substance.title.ArcHeaderPainter;
17 import org.jvnet.substance.SubstanceLookAndFeel;
18 import org.jvnet.substance.SubstanceToggleButtonUI;
19 import org.jvnet.substance.SubstanceButtonUI;
20 import org.jvnet.substance.SubstanceLabelUI;
21 
22 import javax.swing.border.Border;
23 import javax.swing.border.EtchedBorder;
24 import javax.swing.plaf.FontUIResource;
25 import javax.swing.plaf.ComponentUI;
26 import javax.swing.*;
27 import java.awt.*;
28 import java.awt.color.ColorSpace;
29 
30 import contrib.com.jgoodies.looks.common.FontSet;
31 import contrib.com.jgoodies.looks.common.FontPolicy;
32 import com.lightcrafts.mediax.jai.IHSColorSpace;
33 
34 public class LightZoneSkin extends SubstanceAbstractSkin {
35     public static String NAME = "LightZone";
36 
37     public static class Colors {
38         public final static Color NeutralGray;
39 
40         static {
41             float[] comps = ColorSpace.getInstance(ColorSpace.CS_sRGB).fromCIEXYZ(
42                     ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB).toCIEXYZ(new float[]{0.18f, 0.18f, 0.18f}));
43             NeutralGray = new Color(comps[0], comps[0], comps[0]);
44         }
45 
46         static {
47             Color temp = NeutralGray.darker();
48             BrowserImageTypeLabelBackground = new Color(
49                     temp.getRed(), temp.getGreen(), temp.getBlue(), 128
50             );
51         }
52 
53         public final static Color EditorBackground = NeutralGray.darker();
54 
55         public final static Color FrameBackground = new Color(28, 28, 28);
56 
57         public final static Color ToolPanesBackground = new Color(62, 62, 62);
58 
59         public final static Color LabelForeground = new Color(229, 229, 229);
60 
61         public final static Color ToolsBackground = ToolPanesBackground;
62         public final static Color ToolTitleTextColor = LabelForeground;
63         public final static Color ToolPanesForeground = LabelForeground;
64 
65         public final static Color BrowserBackground = NeutralGray.darker();
66 
67         public final static Color BrowserSelectHighlight = new Color(188, 188, 154);
68         public final static Color BrowserLabelBackground = new Color(38, 38, 38);
69 
70         public final static Color BrowserLabelForeground = LabelForeground;
71 
72         public final static Color BrowserGroupColor = Color.gray;
73         public final static Color BrowserImageTypeLabelBackground;
74 
75         public final static Color LZOrange = new Color(254, 155, 14);
76         public final static Color SelectedToolBorder = relight(LZOrange, 0.7f);
77     }
78 
relight(Color color, float amount)79     static Color relight(Color color, float amount) {
80         IHSColorSpace ihs = IHSColorSpace.getInstance();
81 
82         float components[] = new float[3];
83         components = ihs.fromRGB(color.getColorComponents(components));
84         components[0] *= amount;
85         components = ihs.toRGB(components);
86         return new Color(components[0], components[1], components[2]);
87     }
88 
89     public static class CustomColorScheme extends BaseColorScheme {
90         private final Color mainUltraLightColor;
91         private final Color mainExtraLightColor;
92         private final Color mainLightColor;
93         private final Color mainMidColor;
94         private final Color mainDarkColor;
95         private final Color mainUltraDarkColor;
96         private final Color foregroundColor;
97 
CustomColorScheme(Color baseColor)98         public CustomColorScheme(Color baseColor) {
99             mainUltraLightColor = relight(baseColor, 0.95f);
100             mainExtraLightColor = relight(baseColor, 0.85f);
101             mainLightColor = relight(baseColor, 0.7f);
102             mainMidColor = relight(baseColor, 0.6f);
103             mainDarkColor = relight(baseColor, 0.5f);
104             mainUltraDarkColor = relight(baseColor, 0.4f);
105             foregroundColor = Color.white;
106         }
107 
getForegroundColor()108         public Color getForegroundColor() { return foregroundColor; }
getUltraLightColor()109         public Color getUltraLightColor() { return mainUltraLightColor; }
getExtraLightColor()110         public Color getExtraLightColor() { return mainExtraLightColor; }
getLightColor()111         public Color getLightColor() { return mainLightColor; }
getMidColor()112         public Color getMidColor() { return mainMidColor; }
getDarkColor()113         public Color getDarkColor() { return mainDarkColor; }
getUltraDarkColor()114         public Color getUltraDarkColor() { return mainUltraDarkColor; }
115     }
116 
makeTheme(ColorScheme colorScheme, String name)117     public static SubstanceTheme makeTheme(ColorScheme colorScheme, String name) {
118         SubstanceTheme activeTheme = new SubstanceTheme(colorScheme, name, SubstanceTheme.ThemeKind.DARK);
119 
120         SubstanceTheme basicTheme = new SubstanceEbonyTheme().tint(0.05);
121         SubstanceTheme defaultTheme = basicTheme.shade(0.2);
122         SubstanceTheme disabledTheme = basicTheme.shade(0.3);
123         SubstanceTheme activeTitleTheme = defaultTheme;
124 
125         SubstanceComplexTheme theme = new SubstanceComplexTheme(name + " Theme",
126                                                                 SubstanceTheme.ThemeKind.DARK, activeTheme, defaultTheme, disabledTheme,
127                                                                 activeTitleTheme);
128 
129         theme.setNonActivePainter(new SimplisticSoftBorderReverseGradientPainter());
130         theme.setSelectedTabFadeStart(0.4);
131         theme.setSelectedTabFadeEnd(0.7);
132         theme.setCellRendererBackgroundTheme(new SubstanceEbonyTheme());
133 
134         return theme;
135     }
136 
137     public static final SubstanceTheme orangeTheme = makeTheme(new CustomColorScheme(Colors.LZOrange), "Orange");
138 
LightZoneSkin()139     public LightZoneSkin() {
140         SubstanceTheme activeTheme = new SubstanceEbonyTheme();
141         SubstanceTheme defaultTheme = activeTheme.shade(0.2);
142         SubstanceTheme disabledTheme = activeTheme.shade(0.3);
143         SubstanceTheme activeTitleTheme = defaultTheme;
144 
145         SubstanceComplexTheme theme = new SubstanceComplexTheme(NAME,
146                                                                 SubstanceTheme.ThemeKind.DARK, activeTheme, defaultTheme, disabledTheme,
147                                                                 activeTitleTheme);
148         theme.setNonActivePainter(new SimplisticSoftBorderReverseGradientPainter());
149         theme.setSelectedTabFadeStart(0.3);
150         theme.setSelectedTabFadeEnd(0.6);
151         theme.setCellRendererBackgroundTheme(new SubstanceEbonyTheme());
152 
153         this.theme = theme;
154         this.shaper = new ClassicButtonShaper();
155         this.watermark = new SubstanceNoneWatermark();
156         this.gradientPainter = new GlassGradientPainter();
157         this.titlePainter = new ArcHeaderPainter();
158         this.tabBackgroundComposite = new AlphaControlBackgroundComposite(0.5f);
159     }
160 
getDisplayName()161     public String getDisplayName() {
162         return NAME;
163     }
164 
165     public static class LightZoneFontSet implements FontSet {
166         FontUIResource controlFont;
167         FontUIResource menuFont;
168         FontUIResource titleFont;
169         FontUIResource windowTitleFont;
170         FontUIResource smallFont;
171         FontUIResource messageFont;
172 
173         String fontFamily = Font.SANS_SERIF;
174 
LightZoneFontSet()175         public LightZoneFontSet() {
176             controlFont = new FontUIResource(fontFamily, Font.PLAIN, 13);
177             menuFont = new FontUIResource(fontFamily, Font.PLAIN, 13);
178             titleFont = new FontUIResource(fontFamily, Font.BOLD, 11);
179             windowTitleFont = new FontUIResource(fontFamily, Font.BOLD, 16);
180             smallFont = new FontUIResource(fontFamily, Font.PLAIN, 13);
181             messageFont = new FontUIResource(fontFamily, Font.BOLD, 13);
182         }
183 
getControlFont()184         public FontUIResource getControlFont() {
185             return controlFont;
186         }
187 
getMenuFont()188         public FontUIResource getMenuFont() {
189             return menuFont;
190         }
191 
getTitleFont()192         public FontUIResource getTitleFont() {
193             return titleFont;
194         }
195 
getWindowTitleFont()196         public FontUIResource getWindowTitleFont() {
197             return windowTitleFont;
198         }
199 
getSmallFont()200         public FontUIResource getSmallFont() {
201             return smallFont;
202         }
203 
getMessageFont()204         public FontUIResource getMessageFont() {
205             return messageFont;
206         }
207     }
208 
209     public static final FontSet fontSet = new LightZoneFontSet();
210 
getImageBorder()211     public static Border getImageBorder() {
212         return getPaneBorder(); // new CompoundBorder(getPaneBorder(), new MatteBorder(6, 6, 6, 6, Colors.EditorBackground));
213     }
214 
getPaneBorder()215     public static Border getPaneBorder() {
216         return new EtchedBorder(EtchedBorder.LOWERED, new Color(48, 48, 48), new Color(23, 23, 23));
217     }
218 
219     private static final RenderingHints aliasingRenderHints;
220 
221     static {
222         aliasingRenderHints = new RenderingHints(
223             RenderingHints.KEY_ANTIALIASING,
224             RenderingHints.VALUE_ANTIALIAS_ON
225         );
aliasingRenderHints.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON )226         aliasingRenderHints.put(
227             RenderingHints.KEY_TEXT_ANTIALIASING,
228             RenderingHints.VALUE_TEXT_ANTIALIAS_ON
229         );
aliasingRenderHints.put( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY )230         aliasingRenderHints.put(
231             RenderingHints.KEY_RENDERING,
232             RenderingHints.VALUE_RENDER_QUALITY
233         );
234     }
235 
236     public static class LightZoneButtonUI extends SubstanceButtonUI {
createUI(JComponent b)237         public static ComponentUI createUI(JComponent b) {
238             AbstractButton button = (AbstractButton) b;
239             button.setRolloverEnabled(true);
240             button.setOpaque(false);
241             button.setFocusable(false);
242             button.setFocusPainted(false);
243             return new LightZoneButtonUI();
244         }
245 
246         // On Windows text aliasing is off for some reason...
paint(java.awt.Graphics graphics, javax.swing.JComponent jComponent)247         public void paint(java.awt.Graphics graphics, javax.swing.JComponent jComponent) {
248             Graphics2D g = (Graphics2D) graphics;
249             g.setRenderingHints(aliasingRenderHints);
250             super.paint(graphics, jComponent);
251         }
252 
installDefaults(final AbstractButton b)253         public void installDefaults(final AbstractButton b) {
254             super.installDefaults(b);
255             b.setBorder(BorderFactory.createEmptyBorder(4, 6, 4, 6));
256         }
257     }
258 
259     public static class LightZoneToggleButtonUI extends SubstanceToggleButtonUI {
createUI(JComponent b)260         public static ComponentUI createUI(JComponent b) {
261             AbstractButton button = (AbstractButton) b;
262             button.setRolloverEnabled(true);
263             button.setFocusable(false);
264             button.setFocusPainted(false);
265             return new LightZoneToggleButtonUI();
266         }
267 
268         // On Windows text aliasing is off for some reason...
paint(java.awt.Graphics graphics, javax.swing.JComponent jComponent)269         public void paint(java.awt.Graphics graphics, javax.swing.JComponent jComponent) {
270             Graphics2D g = (Graphics2D) graphics;
271             g.setRenderingHints(aliasingRenderHints);
272             super.paint(graphics, jComponent);
273         }
274 
installDefaults(final AbstractButton b)275         public void installDefaults(final AbstractButton b) {
276             super.installDefaults(b);
277             b.setBorder(BorderFactory.createEmptyBorder(4, 6, 4, 6));
278         }
279     }
280 
281     public static class LightZoneLookAndFeel extends SubstanceLookAndFeel {
initClassDefaults(UIDefaults table)282         protected void initClassDefaults(UIDefaults table) {
283             super.initClassDefaults(table);
284             Object[] uiDefaults = {
285                 "ButtonUI", LightZoneButtonUI.class.getName(),
286                 "ToggleButtonUI", LightZoneToggleButtonUI.class.getName()
287             };
288             table.putDefaults(uiDefaults);
289         }
290     }
291 
getLightZoneLookAndFeel()292     public static LookAndFeel getLightZoneLookAndFeel() {
293         LookAndFeel substance = new LightZoneLookAndFeel();
294 
295         LightZoneLookAndFeel.setSkin(new LightZoneSkin());
296 
297         FontPolicy newFontPolicy = new FontPolicy() {
298             public FontSet getFontSet(String lafName,
299                                       UIDefaults table) {
300                 return new LightZoneSkin.LightZoneFontSet();
301             }
302         };
303 
304         LightZoneLookAndFeel.setFontPolicy(newFontPolicy);
305 
306         UIManager.put(SubstanceLookAndFeel.NO_EXTRA_ELEMENTS, Boolean.TRUE);
307 
308         UIManager.put("ToolTip.backgroundInactive", substance.getDefaults().get("ToolTip.background"));
309         UIManager.put("ToolTip.foregroundInactive", substance.getDefaults().get("ToolTip.foreground"));
310 
311         return substance;
312     }
313 }
314