Debian Codegraph @

src/com/bulenkov/iconloader/util/DoubleColor.java

raw symbols SCIP
1 /*
2 * Copyright 2000-2013 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.bulenkov.iconloader.util;
17
18
19 import java.awt.*;
20 import java.awt.color.ColorSpace;
21 import java.awt.geom.AffineTransform;
22 import java.awt.geom.Rectangle2D;
23 import java.awt.image.ColorModel;
24
25 /**
26 * @author Konstantin Bulenkov
27 */
28 public class DoubleColor extends Color {
29
30 private static volatile boolean DARK = UIUtil.isUnderDarcula();
31
32 private final Color darkColor;
33
34 public DoubleColor(int rgb, int darkRGB) {
35 this(new Color(rgb), new Color(darkRGB));
36 }
37
38 public DoubleColor(Color regular, Color dark) {
39 super(regular.getRGB(), regular.getAlpha() != 255);
40 darkColor = dark;
41 //noinspection AssignmentToStaticFieldFromInstanceMethod
42 DARK = UIUtil.isUnderDarcula(); //Double check. Sometimes DARK != isDarcula() after dialogs appear on splash screen
43 }
44
45 public static void setDark(boolean dark) {
46 DARK = dark;
47 }
48
49 Color getDarkVariant() {
50 return darkColor;
51 }
52
53 @Override
54 public int getRed() {
55 return DARK ? getDarkVariant().getRed() : super.getRed();
56 }
57
58 @Override
59 public int getGreen() {
60 return DARK ? getDarkVariant().getGreen() : super.getGreen();
61 }
62
63 @Override
64 public int getBlue() {
65 return DARK ? getDarkVariant().getBlue() : super.getBlue();
66 }
67
68 @Override
69 public int getAlpha() {
70 return DARK ? getDarkVariant().getAlpha() : super.getAlpha();
71 }
72
73 @Override
74 public int getRGB() {
75 return DARK ? getDarkVariant().getRGB() : super.getRGB();
76 }
77
78 @Override
79 public Color brighter() {
80 return new DoubleColor(super.brighter(), getDarkVariant().brighter());
81 }
82
83 @Override
84 public Color darker() {
85 return new DoubleColor(super.darker(), getDarkVariant().darker());
86 }
87
88 @Override
89 public int hashCode() {
90 return DARK ? getDarkVariant().hashCode() : super.hashCode();
91 }
92
93 @Override
94 public boolean equals(Object obj) {
95 return DARK ? getDarkVariant().equals(obj) : super.equals(obj);
96 }
97
98 @Override
99 public String toString() {
100 return DARK ? getDarkVariant().toString() : super.toString();
101 }
102
103 @Override
104 public float[] getRGBComponents(float[] compArray) {
105 return DARK ? getDarkVariant().getRGBComponents(compArray) : super.getRGBComponents(compArray);
106 }
107
108 @Override
109 public float[] getRGBColorComponents(float[] compArray) {
110 return DARK ? getDarkVariant().getRGBColorComponents(compArray) : super.getRGBComponents(compArray);
111 }
112
113 @Override
114 public float[] getComponents(float[] compArray) {
115 return DARK ? getDarkVariant().getComponents(compArray) : super.getComponents(compArray);
116 }
117
118 @Override
119 public float[] getColorComponents(float[] compArray) {
120 return DARK ? getDarkVariant().getColorComponents(compArray) : super.getColorComponents(compArray);
121 }
122
123 @Override
124 public float[] getComponents(ColorSpace cspace, float[] compArray) {
125 return DARK ? getDarkVariant().getComponents(cspace, compArray) : super.getComponents(cspace, compArray);
126 }
127
128 @Override
129 public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
130 return DARK ? getDarkVariant().getColorComponents(cspace, compArray) : super.getColorComponents(cspace, compArray);
131 }
132
133 @Override
134 public ColorSpace getColorSpace() {
135 return DARK ? getDarkVariant().getColorSpace() : super.getColorSpace();
136 }
137
138 @Override
139 public synchronized PaintContext createContext(ColorModel cm, Rectangle r, Rectangle2D r2d, AffineTransform xform, RenderingHints hints) {
140 return DARK ? getDarkVariant().createContext(cm, r, r2d, xform, hints) : super.createContext(cm, r, r2d, xform, hints);
141 }
142
143 @Override
144 public int getTransparency() {
145 return DARK ? getDarkVariant().getTransparency() : super.getTransparency();
146 }
147
148 public static final DoubleColor red = new DoubleColor(Color.red, new Color(255, 100, 100));
149 public static final DoubleColor RED = red;
150
151 public static final DoubleColor blue = new DoubleColor(Color.blue, new Color(0x589df6));
152 public static final DoubleColor BLUE = blue;
153
154 public static final DoubleColor white = new DoubleColor(Color.white, UIUtil.getListBackground()) {
155 @Override
156 Color getDarkVariant() {
157 return UIUtil.getListBackground();
158 }
159 };
160 public static final DoubleColor WHITE = white;
161
162 public static final DoubleColor black = new DoubleColor(Color.black, UIUtil.getListForeground()) {
163 @Override
164 Color getDarkVariant() {
165 return UIUtil.getListForeground();
166 }
167 };
168 public static final DoubleColor BLACK = black;
169
170 public static final DoubleColor gray = new DoubleColor(Gray._128, Gray._128);
171 public static final DoubleColor GRAY = gray;
172
173 public static final DoubleColor lightGray = new DoubleColor(Gray._192, Gray._64);
174 public static final DoubleColor LIGHT_GRAY = lightGray;
175
176 public static final DoubleColor darkGray = new DoubleColor(Gray._64, Gray._192);
177 public static final DoubleColor DARK_GRAY = darkGray;
178
179 public static final DoubleColor pink = new DoubleColor(Color.pink, Color.pink);
180 public static final DoubleColor PINK = pink;
181
182 public static final DoubleColor orange = new DoubleColor(Color.orange, new Color(159, 107, 0));
183 public static final DoubleColor ORANGE = orange;
184
185 public static final DoubleColor yellow = new DoubleColor(Color.yellow, new Color(138, 138, 0));
186 public static final DoubleColor YELLOW = yellow;
187
188 public static final DoubleColor green = new DoubleColor(Color.green, new Color(98, 150, 85));
189 public static final DoubleColor GREEN = green;
190
191 public static final Color magenta = new DoubleColor(Color.magenta, new Color(151, 118, 169));
192 public static final Color MAGENTA = magenta;
193
194 public static final Color cyan = new DoubleColor(Color.cyan, new Color(0, 137, 137));
195 public static final Color CYAN = cyan;
196
197 public static Color foreground() {
198 return UIUtil.getLabelForeground();
199 }
200
201 public static Color background() {
202 return UIUtil.getListBackground();
203 }
204 }