2
* Copyright (c) 2005-2010 Flamingo / 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 Flamingo 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.flamingo.ribbon.gallery.oob;
33
import java.awt.geom.Ellipse2D;
35
import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
36
import org.pushingpixels.substance.api.SubstanceColorScheme;
39
* Resizable icon for <b>Substance</b> themes.
41
* @author Kirill Grouchnikov
43
public class ColorSchemeResizableIcon implements ResizableIcon {
45
* Current width in pixels.
47
private int currWidth;
50
* Current height in pixels.
52
private int currHeight;
55
* Associated color scheme. Can be <code>null</code>.
57
private SubstanceColorScheme scheme;
63
* Associated color scheme (can be <code>null</code>).
65
* Original width in pixels.
67
* Original heigth in pixels.
69
public ColorSchemeResizableIcon(SubstanceColorScheme scheme,
70
int startWidth, int startHeight) {
72
this.currWidth = startWidth;
73
this.currHeight = startHeight;
80
* org.jvnet.flamingo.common.ResizableIcon#setDimension(java.awt.Dimension)
83
public void setDimension(Dimension newDimension) {
84
this.currWidth = newDimension.width;
85
this.currHeight = newDimension.height;
91
* @see javax.swing.Icon#getIconHeight()
94
public int getIconHeight() {
95
return this.currHeight;
101
* @see javax.swing.Icon#getIconWidth()
104
public int getIconWidth() {
105
return this.currWidth;
111
* @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics,
115
public void paintIcon(Component c, Graphics g, int x, int y) {
116
Graphics2D graphics = (Graphics2D) g.create();
117
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
118
RenderingHints.VALUE_ANTIALIAS_ON);
120
graphics.translate(x, y);
122
double R = Math.max(3.0, this.currHeight / 10.0);
124
double s = (this.currHeight - 2 * R) / 2.0;
125
double cx = this.currWidth / 2.0;
126
// double cy = this.currHeight / 2.0;
127
double dx = s * Math.sqrt(3.0) / 2.0;
128
// double ss = (this.currHeight - 2 * r) / 2.0;
129
// double dxs = ss * Math.sqrt(3.0) / 2.0;
133
Color color1 = (this.scheme == null) ? Color.red : this.scheme
134
.getUltraDarkColor();
135
Color color2 = (this.scheme == null) ? Color.yellow : this.scheme
137
Color color3 = (this.scheme == null) ? Color.green : this.scheme
139
Color color4 = (this.scheme == null) ? Color.cyan : this.scheme
141
Color color5 = (this.scheme == null) ? Color.blue : this.scheme
142
.getExtraLightColor();
143
Color color6 = (this.scheme == null) ? Color.magenta : this.scheme
144
.getUltraLightColor();
146
this.paintCircle(graphics, cx, R, R, color1, true);
147
if (this.currHeight > 16)
148
this.paintCircle(graphics, cx + dx, R + 0.5 * s, R, color2, true);
149
this.paintCircle(graphics, cx + dx, R + 1.5 * s, R, color3, true);
150
if (this.currHeight > 16)
151
this.paintCircle(graphics, cx, this.currHeight - 1 - R, R, color4,
153
this.paintCircle(graphics, cx + 1 - dx, R + 1.5 * s, R, color5, true);
154
if (this.currHeight > 16)
155
this.paintCircle(graphics, cx + 1 - dx, R + 0.5 * s, R, color6,
159
this.paintCircle(graphics, cx + 0.5 + dx / 2.0, R + 0.25 * s, r,
161
this.paintCircle(graphics, cx + dx, R + s, r, color2, false);
162
this.paintCircle(graphics, cx + 0.5 + dx / 2.0, R
163
+ (this.currHeight - 1 + 1.5 * s) / 2.0, r, color3, false);
164
this.paintCircle(graphics, cx - 0.5 - dx / 2.0, R
165
+ (this.currHeight - 1 + 1.5 * s) / 2.0, r, color4, false);
166
this.paintCircle(graphics, cx - dx, R + s, r, color5, false);
167
this.paintCircle(graphics, cx - 0.5 - dx / 2.0, R + 0.25 * s, r,
175
* Paints a single circle.
180
* X coordinate of the circle center.
182
* Y coordinate of the circle center.
187
* @param toDrawOutline
188
* Indication whether the circle outline should be drawn.
190
private void paintCircle(Graphics2D graphics, double xc, double yc,
191
double r, Color color, boolean toDrawOutline) {
192
Shape shape = new Ellipse2D.Double(xc - r, yc - r, 2 * r, 2 * r);
193
this.paintShape(graphics, shape, color, toDrawOutline);
205
* @param toDrawOutline
206
* Indication whether the shape outline should be drawn.
208
private void paintShape(Graphics2D graphics, Shape shape, Color color,
209
boolean toDrawOutline) {
210
graphics.setColor(color);
211
graphics.fill(shape);
213
graphics.setColor(color.darker());
214
graphics.draw(shape);