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.watermark;
33
import java.awt.image.BufferedImage;
35
import org.pushingpixels.substance.api.SubstanceColorScheme;
36
import org.pushingpixels.substance.api.SubstanceSkin;
37
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
40
* Simple implementation of {@link SubstanceWatermark}, drawing cross hatches as
41
* watermark. This implementation is inspired by Office 12 background. This
42
* class is part of officially supported API.
44
* @author Kirill Grouchnikov
47
public class SubstanceCrosshatchWatermark implements SubstanceWatermark {
49
* Watermark image (screen-sized).
51
private static Image watermarkImage = null;
57
* org.pushingpixels.substance.watermark.SubstanceWatermark#drawWatermarkImage(java
58
* .awt.Graphics, int, int, int, int)
61
public void drawWatermarkImage(Graphics graphics, Component c, int x,
62
int y, int width, int height) {
65
int dx = c.getLocationOnScreen().x;
66
int dy = c.getLocationOnScreen().y;
67
graphics.drawImage(SubstanceCrosshatchWatermark.watermarkImage, x, y, x
68
+ width, y + height, x + dx, y + dy, x + dx + width, y + dy
76
* org.pushingpixels.substance.watermark.SubstanceWatermark#updateWatermarkImage
77
* (org.pushingpixels.substance.skin.SubstanceSkin)
80
public boolean updateWatermarkImage(SubstanceSkin skin) {
81
// fix by Chris for bug 67 - support for multiple screens
82
Rectangle virtualBounds = new Rectangle();
83
GraphicsEnvironment ge = GraphicsEnvironment
84
.getLocalGraphicsEnvironment();
85
GraphicsDevice[] gds = ge.getScreenDevices();
86
for (GraphicsDevice gd : gds) {
87
GraphicsConfiguration gc = gd.getDefaultConfiguration();
88
virtualBounds = virtualBounds.union(gc.getBounds());
91
int screenWidth = virtualBounds.width;
92
int screenHeight = virtualBounds.height;
93
SubstanceCrosshatchWatermark.watermarkImage = SubstanceCoreUtilities
94
.getBlankImage(screenWidth, screenHeight);
96
Graphics2D graphics = (Graphics2D) SubstanceCrosshatchWatermark.watermarkImage
97
.getGraphics().create();
98
boolean status = this.drawWatermarkImage(skin, graphics, 0, 0,
99
screenWidth, screenHeight, false);
108
* org.pushingpixels.substance.api.watermark.SubstanceWatermark#previewWatermark
109
* (java.awt.Graphics, org.pushingpixels.substance.api.SubstanceSkin, int, int, int,
113
public void previewWatermark(Graphics g, SubstanceSkin skin, int x, int y,
114
int width, int height) {
116
.drawWatermarkImage(skin, (Graphics2D) g, x, y, width, height,
121
* Draws the specified portion of the watermark image.
124
* Skin to use for painting the watermark.
128
* the <i>x</i> coordinate of the watermark to be drawn.
130
* The <i>y</i> coordinate of the watermark to be drawn.
132
* The width of the watermark to be drawn.
134
* The height of the watermark to be drawn.
136
* Indication whether the result is a preview image.
137
* @return Indication whether the draw succeeded.
139
private boolean drawWatermarkImage(SubstanceSkin skin, Graphics2D graphics,
140
int x, int y, int width, int height, boolean isPreview) {
141
Color stampColorDark = null;
142
Color stampColorAll = null;
143
Color stampColorLight = null;
144
SubstanceColorScheme scheme = skin.getWatermarkColorScheme();
146
stampColorDark = scheme.isDark() ? Color.white : Color.black;
147
stampColorAll = Color.lightGray;
148
stampColorLight = scheme.isDark() ? Color.black : Color.white;
150
stampColorDark = scheme.getWatermarkDarkColor();
151
stampColorAll = scheme.getWatermarkStampColor();
152
stampColorLight = scheme.getWatermarkLightColor();
155
graphics.setColor(stampColorAll);
156
graphics.fillRect(0, 0, width, height);
158
BufferedImage tile = SubstanceCoreUtilities.getBlankImage(4, 4);
159
tile.setRGB(0, 0, stampColorDark.getRGB());
160
tile.setRGB(2, 2, stampColorDark.getRGB());
161
tile.setRGB(0, 1, stampColorLight.getRGB());
162
tile.setRGB(2, 3, stampColorLight.getRGB());
164
Graphics2D g2d = (Graphics2D) graphics.create();
165
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
167
for (int row = y; row < (y + height); row += 4) {
168
for (int col = x; col < (x + width); col += 4) {
169
g2d.drawImage(tile, col, row, null);
179
* @see org.pushingpixels.substance.api.trait.SubstanceTrait#getDisplayName()
182
public String getDisplayName() {
183
return SubstanceCrosshatchWatermark.getName();
187
* Returns the name of all watermarks of <code>this</code> class.
189
* @return The name of all watermarks of <code>this</code> class.
191
public static String getName() {
198
* @see org.pushingpixels.substance.watermark.SubstanceWatermark#dispose()
201
public void dispose() {
202
watermarkImage = null;