2
* Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of Substance Kirill Grouchnikov nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
package org.pushingpixels.substance.api.skin;
33
import java.awt.image.BufferedImage;
35
import org.pushingpixels.substance.api.*;
36
import org.pushingpixels.substance.api.painter.border.ClassicBorderPainter;
37
import org.pushingpixels.substance.api.painter.border.FractionBasedBorderPainter;
38
import org.pushingpixels.substance.api.painter.decoration.MatteDecorationPainter;
39
import org.pushingpixels.substance.api.painter.fill.FractionBasedFillPainter;
40
import org.pushingpixels.substance.api.painter.highlight.ClassicHighlightPainter;
41
import org.pushingpixels.substance.api.painter.overlay.*;
42
import org.pushingpixels.substance.api.shaper.ClassicButtonShaper;
43
import org.pushingpixels.substance.api.watermark.SubstanceCrosshatchWatermark;
44
import org.pushingpixels.substance.api.watermark.SubstanceWatermark;
45
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
48
* <code>Mariner</code> skin. This class is part of officially supported API.
50
* @author Kirill Grouchnikov
53
public class MarinerSkin extends SubstanceSkin {
55
* Display name for <code>this</code> skin.
57
public static final String NAME = "Mariner";
60
* Overlay painter to paint a dark line along the bottom edge of the
63
private BottomLineOverlayPainter menuOverlayPainter;
66
* Overlay painter to paint a light line along the top edge of the toolbars.
68
private TopLineOverlayPainter toolbarOverlayPainter;
71
* Overlay painter to paint a dark line along the bottom edge of the
74
private BottomLineOverlayPainter toolbarBottomLineOverlayPainter;
77
* Overlay painter to paint a bezel line along the top edge of the footer.
79
private TopBezelOverlayPainter footerTopBezelOverlayPainter;
82
* Creates a new <code>Mariner</code> skin.
84
public MarinerSkin() {
85
SubstanceSkin.ColorSchemes schemes = SubstanceSkin
86
.getColorSchemes("org/pushingpixels/substance/api/skin/mariner.colorschemes");
88
SubstanceColorScheme activeScheme = schemes.get("Mariner Active");
89
SubstanceColorScheme enabledScheme = schemes.get("Mariner Enabled");
90
SubstanceColorScheme disabledScheme = schemes.get("Mariner Disabled");
92
SubstanceColorSchemeBundle defaultSchemeBundle = new SubstanceColorSchemeBundle(
93
activeScheme, enabledScheme, disabledScheme);
95
defaultSchemeBundle.registerColorScheme(activeScheme, 0.5f,
96
ComponentState.DISABLED_SELECTED);
97
defaultSchemeBundle.registerColorScheme(disabledScheme, 0.8f,
98
ComponentState.DISABLED_UNSELECTED);
101
SubstanceColorScheme activeBorderScheme = schemes
102
.get("Mariner Active Border");
103
SubstanceColorScheme enabledBorderScheme = schemes
104
.get("Mariner Enabled Border");
105
defaultSchemeBundle.registerColorScheme(activeBorderScheme,
106
ColorSchemeAssociationKind.BORDER, ComponentState
108
defaultSchemeBundle.registerColorScheme(activeBorderScheme,
109
ColorSchemeAssociationKind.BORDER,
110
ComponentState.DISABLED_SELECTED);
111
defaultSchemeBundle.registerColorScheme(enabledBorderScheme,
112
ColorSchemeAssociationKind.BORDER, ComponentState.ENABLED);
115
SubstanceColorScheme activeMarkScheme = schemes
116
.get("Mariner Active Mark");
117
SubstanceColorScheme enabledMarkScheme = schemes
118
.get("Mariner Enabled Mark");
119
defaultSchemeBundle.registerColorScheme(activeMarkScheme,
120
ColorSchemeAssociationKind.MARK, ComponentState
122
defaultSchemeBundle.registerColorScheme(enabledMarkScheme,
123
ColorSchemeAssociationKind.MARK, ComponentState.ENABLED);
125
ComponentState uneditable = new ComponentState("uneditable",
126
new ComponentStateFacet[] { ComponentStateFacet.ENABLE },
127
new ComponentStateFacet[] { ComponentStateFacet.EDITABLE });
128
SubstanceColorScheme uneditableControls = schemes
129
.get("Mariner Uneditable");
130
defaultSchemeBundle.registerColorScheme(uneditableControls,
131
ColorSchemeAssociationKind.FILL, uneditable);
133
this.registerDecorationAreaSchemeBundle(defaultSchemeBundle,
134
DecorationAreaType.NONE);
136
// header color scheme bundle
137
SubstanceColorScheme headerColorScheme = schemes.get("Mariner Header");
138
SubstanceColorScheme headerBorderColorScheme = schemes
139
.get("Mariner Header Border");
140
SubstanceColorSchemeBundle headerSchemeBundle = new SubstanceColorSchemeBundle(
141
headerColorScheme, headerColorScheme, headerColorScheme);
142
headerSchemeBundle.registerColorScheme(headerColorScheme, 0.5f,
143
ComponentState.DISABLED_SELECTED,
144
ComponentState.DISABLED_UNSELECTED);
145
headerSchemeBundle.registerColorScheme(headerColorScheme,
146
ComponentState.ROLLOVER_UNSELECTED);
147
headerSchemeBundle.registerColorScheme(headerColorScheme,
148
ColorSchemeAssociationKind.MARK);
149
headerSchemeBundle.registerColorScheme(headerBorderColorScheme,
150
ColorSchemeAssociationKind.BORDER);
151
this.registerDecorationAreaSchemeBundle(headerSchemeBundle,
152
headerColorScheme, DecorationAreaType.PRIMARY_TITLE_PANE,
153
DecorationAreaType.SECONDARY_TITLE_PANE,
154
DecorationAreaType.HEADER);
156
// footer color scheme bundle
157
SubstanceColorScheme enabledFooterScheme = schemes
158
.get("Mariner Footer Enabled");
159
SubstanceColorScheme disabledFooterScheme = schemes
160
.get("Mariner Footer Disabled");
162
SubstanceColorSchemeBundle footerSchemeBundle = new SubstanceColorSchemeBundle(
163
activeScheme, enabledFooterScheme, disabledFooterScheme);
165
footerSchemeBundle.registerColorScheme(activeScheme, 0.5f,
166
ComponentState.DISABLED_SELECTED);
167
footerSchemeBundle.registerColorScheme(disabledFooterScheme, 0.8f,
168
ComponentState.DISABLED_UNSELECTED);
171
SubstanceColorScheme footerEnabledBorderScheme = schemes
172
.get("Mariner Footer Enabled Border");
173
footerSchemeBundle.registerColorScheme(activeBorderScheme,
174
ColorSchemeAssociationKind.BORDER, ComponentState
176
footerSchemeBundle.registerColorScheme(activeBorderScheme,
177
ColorSchemeAssociationKind.BORDER,
178
ComponentState.DISABLED_SELECTED);
179
footerSchemeBundle.registerColorScheme(footerEnabledBorderScheme,
180
ColorSchemeAssociationKind.BORDER, ComponentState.ENABLED);
183
SubstanceColorScheme footerEnabledMarkScheme = schemes
184
.get("Mariner Footer Enabled Mark");
185
footerSchemeBundle.registerColorScheme(activeMarkScheme,
186
ColorSchemeAssociationKind.MARK, ComponentState
188
footerSchemeBundle.registerColorScheme(footerEnabledMarkScheme,
189
ColorSchemeAssociationKind.MARK, ComponentState.ENABLED);
192
SubstanceColorScheme footerSeparatorScheme = schemes
193
.get("Mariner Footer Separator");
194
footerSchemeBundle.registerColorScheme(footerSeparatorScheme,
195
ColorSchemeAssociationKind.SEPARATOR);
197
SubstanceColorScheme footerWatermarkColorScheme = schemes
198
.get("Mariner Footer Watermark");
199
this.registerDecorationAreaSchemeBundle(footerSchemeBundle,
200
footerWatermarkColorScheme, DecorationAreaType.FOOTER,
201
DecorationAreaType.TOOLBAR, DecorationAreaType.GENERAL);
203
this.setSelectedTabFadeStart(0.15);
204
this.setSelectedTabFadeEnd(0.25);
206
// add an overlay painter to paint a bezel line along the top
208
this.footerTopBezelOverlayPainter = new TopBezelOverlayPainter(
209
ColorSchemeSingleColorQuery.ULTRADARK,
210
ColorSchemeSingleColorQuery.LIGHT);
211
this.addOverlayPainter(this.footerTopBezelOverlayPainter,
212
DecorationAreaType.FOOTER);
214
// add two overlay painters to create a bezel line between
215
// menu bar and toolbars
216
this.menuOverlayPainter = new BottomLineOverlayPainter(
217
new ColorSchemeSingleColorQuery() {
219
public Color query(SubstanceColorScheme scheme) {
220
return scheme.getUltraDarkColor().darker();
223
this.toolbarOverlayPainter = new TopLineOverlayPainter(
224
new ColorSchemeSingleColorQuery() {
226
public Color query(SubstanceColorScheme scheme) {
227
Color fg = scheme.getForegroundColor();
228
return new Color(fg.getRed(), fg.getGreen(), fg
232
this.addOverlayPainter(this.menuOverlayPainter,
233
DecorationAreaType.HEADER);
234
this.addOverlayPainter(this.toolbarOverlayPainter,
235
DecorationAreaType.TOOLBAR);
237
// add overlay painter to paint drop shadows along the bottom
239
this.addOverlayPainter(BottomShadowOverlayPainter.getInstance(),
240
DecorationAreaType.TOOLBAR);
242
// add overlay painter to paint a dark line along the bottom
244
this.toolbarBottomLineOverlayPainter = new BottomLineOverlayPainter(
245
ColorSchemeSingleColorQuery.ULTRADARK);
246
this.addOverlayPainter(this.toolbarBottomLineOverlayPainter,
247
DecorationAreaType.TOOLBAR);
249
this.buttonShaper = new ClassicButtonShaper();
250
this.watermark = new TextureWatermark();
251
this.fillPainter = new FractionBasedFillPainter("Mariner", new float[] {
252
0.0f, 0.5f, 1.0f }, new ColorSchemeSingleColorQuery[] {
253
ColorSchemeSingleColorQuery.EXTRALIGHT,
254
ColorSchemeSingleColorQuery.LIGHT,
255
ColorSchemeSingleColorQuery.MID });
257
this.decorationPainter = new MatteDecorationPainter();
258
this.highlightPainter = new ClassicHighlightPainter();
260
this.borderPainter = new FractionBasedBorderPainter("Mariner",
261
new float[] { 0.0f, 0.5f, 1.0f },
262
new ColorSchemeSingleColorQuery[] {
263
ColorSchemeSingleColorQuery.ULTRADARK,
264
ColorSchemeSingleColorQuery.DARK,
265
ColorSchemeSingleColorQuery.MID });
266
this.highlightBorderPainter = new ClassicBorderPainter();
268
this.watermarkScheme = schemes.get("Mariner Watermark");
274
* @see org.pushingpixels.substance.skin.SubstanceSkin#getDisplayName()
277
public String getDisplayName() {
281
private static class TextureWatermark implements SubstanceWatermark {
283
* Watermark image (screen-sized).
285
private static Image watermarkImage = null;
290
* @seeorg.pushingpixels.substance.watermark.SubstanceWatermark#
291
* drawWatermarkImage(java .awt.Graphics, int, int, int, int)
294
public void drawWatermarkImage(Graphics graphics, Component c, int x,
295
int y, int width, int height) {
298
int dx = c.getLocationOnScreen().x;
299
int dy = c.getLocationOnScreen().y;
300
graphics.drawImage(TextureWatermark.watermarkImage, x, y,
301
x + width, y + height, x + dx, y + dy, x + dx + width, y
302
+ dy + height, null);
308
* @seeorg.pushingpixels.substance.watermark.SubstanceWatermark#
309
* updateWatermarkImage (org.pushingpixels.substance.skin.SubstanceSkin)
312
public boolean updateWatermarkImage(SubstanceSkin skin) {
313
// fix by Chris for bug 67 - support for multiple screens
314
Rectangle virtualBounds = new Rectangle();
315
GraphicsEnvironment ge = GraphicsEnvironment
316
.getLocalGraphicsEnvironment();
317
GraphicsDevice[] gds = ge.getScreenDevices();
318
for (GraphicsDevice gd : gds) {
319
GraphicsConfiguration gc = gd.getDefaultConfiguration();
320
virtualBounds = virtualBounds.union(gc.getBounds());
323
int screenWidth = virtualBounds.width;
324
int screenHeight = virtualBounds.height;
325
TextureWatermark.watermarkImage = SubstanceCoreUtilities
326
.getBlankImage(screenWidth, screenHeight);
328
Graphics2D graphics = (Graphics2D) TextureWatermark.watermarkImage
329
.getGraphics().create();
330
boolean status = this.drawWatermarkImage(skin, graphics, 0, 0,
331
screenWidth, screenHeight, false);
339
* @seeorg.pushingpixels.substance.api.watermark.SubstanceWatermark#
340
* previewWatermark (java.awt.Graphics,
341
* org.pushingpixels.substance.api.SubstanceSkin, int, int, int, int)
344
public void previewWatermark(Graphics g, SubstanceSkin skin, int x,
345
int y, int width, int height) {
346
this.drawWatermarkImage(skin, (Graphics2D) g, x, y, width, height,
351
* Draws the specified portion of the watermark image.
354
* Skin to use for painting the watermark.
358
* the <i>x</i> coordinate of the watermark to be drawn.
360
* The <i>y</i> coordinate of the watermark to be drawn.
362
* The width of the watermark to be drawn.
364
* The height of the watermark to be drawn.
366
* Indication whether the result is a preview image.
367
* @return Indication whether the draw succeeded.
369
private boolean drawWatermarkImage(SubstanceSkin skin,
370
Graphics2D graphics, int x, int y, int width, int height,
372
Color stampColorDark;
374
//Color stampColorLight = null;
375
SubstanceColorScheme scheme = skin.getWatermarkColorScheme();
377
stampColorDark = scheme.isDark() ? Color.white : Color.black;
378
stampColorAll = Color.lightGray;
379
//stampColorLight = scheme.isDark() ? Color.black : Color.white;
381
stampColorDark = scheme.getWatermarkDarkColor();
382
stampColorAll = scheme.getWatermarkStampColor();
383
//stampColorLight = scheme.getWatermarkLightColor();
386
graphics.setColor(stampColorAll);
387
graphics.fillRect(0, 0, width, height);
389
BufferedImage tile = SubstanceCoreUtilities.getBlankImage(8, 4);
390
int rgbDark = stampColorDark.getRGB();
391
tile.setRGB(0, 0, rgbDark);
392
tile.setRGB(0, 1, rgbDark);
393
tile.setRGB(0, 2, rgbDark);
394
tile.setRGB(0, 3, rgbDark);
395
tile.setRGB(1, 2, rgbDark);
396
tile.setRGB(2, 1, rgbDark);
397
tile.setRGB(3, 0, rgbDark);
398
tile.setRGB(4, 0, rgbDark);
399
tile.setRGB(4, 1, rgbDark);
400
tile.setRGB(4, 2, rgbDark);
401
tile.setRGB(4, 3, rgbDark);
402
tile.setRGB(5, 0, rgbDark);
403
tile.setRGB(6, 1, rgbDark);
404
tile.setRGB(7, 2, rgbDark);
406
Graphics2D g2d = (Graphics2D) graphics.create();
407
g2d.setComposite(AlphaComposite.getInstance(
408
AlphaComposite.SRC_OVER, 0.05f));
409
for (int row = y; row < (y + height); row += 4) {
410
for (int col = x; col < (x + width); col += 8) {
411
g2d.drawImage(tile, col, row, null);
422
* org.pushingpixels.substance.api.trait.SubstanceTrait#getDisplayName()
425
public String getDisplayName() {
426
return SubstanceCrosshatchWatermark.getName();
430
* Returns the name of all watermarks of <code>this</code> class.
432
* @return The name of all watermarks of <code>this</code> class.
434
public static String getName() {
442
* org.pushingpixels.substance.watermark.SubstanceWatermark#dispose()
445
public void dispose() {
446
watermarkImage = null;