~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to substance-flamingo/src/main/java/org/pushingpixels/substance/flamingo/ribbon/gallery/oob/ColorSchemeResizableIcon.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2005-2010 Flamingo / Substance Kirill Grouchnikov. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without 
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 * 
 
7
 *  o Redistributions of source code must retain the above copyright notice, 
 
8
 *    this list of conditions and the following disclaimer. 
 
9
 *     
 
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. 
 
13
 *     
 
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. 
 
17
 *     
 
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. 
 
29
 */
 
30
package org.pushingpixels.substance.flamingo.ribbon.gallery.oob;
 
31
 
 
32
import java.awt.*;
 
33
import java.awt.geom.Ellipse2D;
 
34
 
 
35
import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
 
36
import org.pushingpixels.substance.api.SubstanceColorScheme;
 
37
 
 
38
/**
 
39
 * Resizable icon for <b>Substance</b> themes.
 
40
 * 
 
41
 * @author Kirill Grouchnikov
 
42
 */
 
43
public class ColorSchemeResizableIcon implements ResizableIcon {
 
44
        /**
 
45
         * Current width in pixels.
 
46
         */
 
47
        private int currWidth;
 
48
 
 
49
        /**
 
50
         * Current height in pixels.
 
51
         */
 
52
        private int currHeight;
 
53
 
 
54
        /**
 
55
         * Associated color scheme. Can be <code>null</code>.
 
56
         */
 
57
        private SubstanceColorScheme scheme;
 
58
 
 
59
        /**
 
60
         * Creates a new icon.
 
61
         * 
 
62
         * @param scheme
 
63
         *            Associated color scheme (can be <code>null</code>).
 
64
         * @param startWidth
 
65
         *            Original width in pixels.
 
66
         * @param startHeight
 
67
         *            Original heigth in pixels.
 
68
         */
 
69
        public ColorSchemeResizableIcon(SubstanceColorScheme scheme,
 
70
                        int startWidth, int startHeight) {
 
71
                this.scheme = scheme;
 
72
                this.currWidth = startWidth;
 
73
                this.currHeight = startHeight;
 
74
        }
 
75
 
 
76
        /*
 
77
         * (non-Javadoc)
 
78
         * 
 
79
         * @see
 
80
         * org.jvnet.flamingo.common.ResizableIcon#setDimension(java.awt.Dimension)
 
81
         */
 
82
        @Override
 
83
        public void setDimension(Dimension newDimension) {
 
84
                this.currWidth = newDimension.width;
 
85
                this.currHeight = newDimension.height;
 
86
        }
 
87
 
 
88
        /*
 
89
         * (non-Javadoc)
 
90
         * 
 
91
         * @see javax.swing.Icon#getIconHeight()
 
92
         */
 
93
        @Override
 
94
        public int getIconHeight() {
 
95
                return this.currHeight;
 
96
        }
 
97
 
 
98
        /*
 
99
         * (non-Javadoc)
 
100
         * 
 
101
         * @see javax.swing.Icon#getIconWidth()
 
102
         */
 
103
        @Override
 
104
        public int getIconWidth() {
 
105
                return this.currWidth;
 
106
        }
 
107
 
 
108
        /*
 
109
         * (non-Javadoc)
 
110
         * 
 
111
         * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics,
 
112
         * int, int)
 
113
         */
 
114
        @Override
 
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);
 
119
 
 
120
                graphics.translate(x, y);
 
121
 
 
122
                double R = Math.max(3.0, this.currHeight / 10.0);
 
123
                double r = R / 2.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;
 
130
 
 
131
                R = Math.floor(R);
 
132
 
 
133
                Color color1 = (this.scheme == null) ? Color.red : this.scheme
 
134
                                .getUltraDarkColor();
 
135
                Color color2 = (this.scheme == null) ? Color.yellow : this.scheme
 
136
                                .getDarkColor();
 
137
                Color color3 = (this.scheme == null) ? Color.green : this.scheme
 
138
                                .getMidColor();
 
139
                Color color4 = (this.scheme == null) ? Color.cyan : this.scheme
 
140
                                .getLightColor();
 
141
                Color color5 = (this.scheme == null) ? Color.blue : this.scheme
 
142
                                .getExtraLightColor();
 
143
                Color color6 = (this.scheme == null) ? Color.magenta : this.scheme
 
144
                                .getUltraLightColor();
 
145
 
 
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,
 
152
                                        true);
 
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,
 
156
                                        true);
 
157
 
 
158
                if (r >= 2.0) {
 
159
                        this.paintCircle(graphics, cx + 0.5 + dx / 2.0, R + 0.25 * s, r,
 
160
                                        color1, false);
 
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,
 
168
                                        color6, false);
 
169
                }
 
170
 
 
171
                graphics.dispose();
 
172
        }
 
173
 
 
174
        /**
 
175
         * Paints a single circle.
 
176
         * 
 
177
         * @param graphics
 
178
         *            Graphics context.
 
179
         * @param xc
 
180
         *            X coordinate of the circle center.
 
181
         * @param yc
 
182
         *            Y coordinate of the circle center.
 
183
         * @param r
 
184
         *            Circle radius.
 
185
         * @param color
 
186
         *            Circle color.
 
187
         * @param toDrawOutline
 
188
         *            Indication whether the circle outline should be drawn.
 
189
         */
 
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);
 
194
        }
 
195
 
 
196
        /**
 
197
         * Paints shape.
 
198
         * 
 
199
         * @param graphics
 
200
         *            Graphics context.
 
201
         * @param shape
 
202
         *            Shape to draw.
 
203
         * @param color
 
204
         *            Circle color.
 
205
         * @param toDrawOutline
 
206
         *            Indication whether the shape outline should be drawn.
 
207
         */
 
208
        private void paintShape(Graphics2D graphics, Shape shape, Color color,
 
209
                        boolean toDrawOutline) {
 
210
                graphics.setColor(color);
 
211
                graphics.fill(shape);
 
212
                if (toDrawOutline) {
 
213
                        graphics.setColor(color.darker());
 
214
                        graphics.draw(shape);
 
215
                }
 
216
        }
 
217
}