comparison dwtx/draw2d/ColorConstants.d @ 102:0de61c6f08ca

Reduce static ctors
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 03:07:30 +0200
parents 95307ad235d9
children 2d6540440fe6
comparison
equal deleted inserted replaced
101:1082a0fc2bb8 102:0de61c6f08ca
23 /** 23 /**
24 * A collection of color-related constants. 24 * A collection of color-related constants.
25 */ 25 */
26 public struct ColorConstants { 26 public struct ColorConstants {
27 27
28 class SystemColorFactory {
29 private static Color getColor(int which) { 28 private static Color getColor(int which) {
30 Display display = Display.getCurrent(); 29 Display display = Display.getCurrent();
31 if (display !is null) 30 if (display !is null)
32 return display.getSystemColor(which); 31 return display.getSystemColor(which);
33 display = Display.getDefault(); 32 display = Display.getDefault();
40 } )); 39 } ));
41 synchronized (mutex) { 40 synchronized (mutex) {
42 return result; 41 return result;
43 } 42 }
44 } 43 }
45 }
46 44
47 /** 45 /**
48 * @see DWT#COLOR_WIDGET_HIGHLIGHT_SHADOW 46 * @see DWT#COLOR_WIDGET_HIGHLIGHT_SHADOW
49 */ 47 */
50 static const Color buttonLightest; 48 private static Color buttonLightest_;
49 public static Color buttonLightest(){
50 if( buttonLightest_ is null ){
51 buttonLightest_ = getColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
52 }
53 return buttonLightest_;
54 }
51 /** 55 /**
52 * @see DWT#COLOR_WIDGET_BACKGROUND 56 * @see DWT#COLOR_WIDGET_BACKGROUND
53 */ 57 */
54 static const Color button; 58 private static Color button_;
59 public static Color button(){
60 if( button_ is null ){
61 button_ = getColor(DWT.COLOR_WIDGET_BACKGROUND);
62 }
63 return button_;
64 }
55 /** 65 /**
56 * @see DWT#COLOR_WIDGET_NORMAL_SHADOW 66 * @see DWT#COLOR_WIDGET_NORMAL_SHADOW
57 */ 67 */
58 static const Color buttonDarker; 68 private static Color buttonDarker_;
69 public static Color buttonDarker(){
70 if( buttonDarker_ is null ){
71 buttonDarker_ = getColor(DWT.COLOR_WIDGET_NORMAL_SHADOW);
72 }
73 return buttonDarker_;
74 }
59 /** 75 /**
60 * @see DWT#COLOR_WIDGET_DARK_SHADOW 76 * @see DWT#COLOR_WIDGET_DARK_SHADOW
61 */ 77 */
62 static const Color buttonDarkest; 78 private static Color buttonDarkest_;
79 public static Color buttonDarkest(){
80 if( buttonDarkest_ is null ){
81 buttonDarkest_ = getColor(DWT.COLOR_WIDGET_DARK_SHADOW);
82 }
83 return buttonDarkest_;
84 }
63 85
64 /** 86 /**
65 * @see DWT#COLOR_LIST_BACKGROUND 87 * @see DWT#COLOR_LIST_BACKGROUND
66 */ 88 */
67 static const Color listBackground; 89 private static Color listBackground_;
90 public static Color listBackground(){
91 if( listBackground_ is null ){
92 listBackground_ = getColor(DWT.COLOR_LIST_BACKGROUND);
93 }
94 return listBackground_;
95 }
68 /** 96 /**
69 * @see DWT#COLOR_LIST_FOREGROUND 97 * @see DWT#COLOR_LIST_FOREGROUND
70 */ 98 */
71 static const Color listForeground; 99 private static Color listForeground_;
100 public static Color listForeground(){
101 if( listForeground_ is null ){
102 listForeground_ = getColor(DWT.COLOR_LIST_FOREGROUND);
103 }
104 return listForeground_;
105 }
72 106
73 /** 107 /**
74 * @see DWT#COLOR_WIDGET_BACKGROUND 108 * @see DWT#COLOR_WIDGET_BACKGROUND
75 */ 109 */
76 static const Color menuBackground; 110 private static Color menuBackground_;
111 public static Color menuBackground(){
112 if( menuBackground_ is null ){
113 menuBackground_ = getColor(DWT.COLOR_WIDGET_BACKGROUND);
114 }
115 return menuBackground_;
116 }
77 /** 117 /**
78 * @see DWT#COLOR_WIDGET_FOREGROUND 118 * @see DWT#COLOR_WIDGET_FOREGROUND
79 */ 119 */
80 static const Color menuForeground; 120 private static Color menuForeground_;
121 public static Color menuForeground(){
122 if( menuForeground_ is null ){
123 menuForeground_ = getColor(DWT.COLOR_WIDGET_FOREGROUND);
124 }
125 return menuForeground_;
126 }
81 /** 127 /**
82 * @see DWT#COLOR_LIST_SELECTION 128 * @see DWT#COLOR_LIST_SELECTION
83 */ 129 */
84 static const Color menuBackgroundSelected; 130 private static Color menuBackgroundSelected_;
131 public static Color menuBackgroundSelected(){
132 if( menuBackgroundSelected_ is null ){
133 menuBackgroundSelected_ = getColor(DWT.COLOR_LIST_SELECTION);
134 }
135 return menuBackgroundSelected_;
136 }
85 /** 137 /**
86 * @see DWT#COLOR_LIST_SELECTION_TEXT 138 * @see DWT#COLOR_LIST_SELECTION_TEXT
87 */ 139 */
88 static const Color menuForegroundSelected; 140 private static Color menuForegroundSelected_;
141 public static Color menuForegroundSelected(){
142 if( menuForegroundSelected_ is null ){
143 menuForegroundSelected_ = getColor(DWT.COLOR_LIST_SELECTION_TEXT);
144 }
145 return menuForegroundSelected_;
146 }
89 147
90 /** 148 /**
91 * @see DWT#COLOR_TITLE_BACKGROUND 149 * @see DWT#COLOR_TITLE_BACKGROUND
92 */ 150 */
93 static const Color titleBackground; 151 private static Color titleBackground_;
152 public static Color titleBackground(){
153 if( titleBackground_ is null ){
154 titleBackground_ = getColor(DWT.COLOR_TITLE_BACKGROUND);
155 }
156 return titleBackground_;
157 }
94 /** 158 /**
95 * @see DWT#COLOR_TITLE_BACKGROUND_GRADIENT 159 * @see DWT#COLOR_TITLE_BACKGROUND_GRADIENT
96 */ 160 */
97 static const Color titleGradient; 161 private static Color titleGradient_;
162 public static Color titleGradient(){
163 if( titleGradient_ is null ){
164 titleGradient_ = getColor(DWT.COLOR_TITLE_BACKGROUND_GRADIENT);
165 }
166 return titleGradient_;
167 }
98 /** 168 /**
99 * @see DWT#COLOR_TITLE_FOREGROUND 169 * @see DWT#COLOR_TITLE_FOREGROUND
100 */ 170 */
101 static const Color titleForeground; 171 private static Color titleForeground_;
172 public static Color titleForeground(){
173 if( titleForeground_ is null ){
174 titleForeground_ = getColor(DWT.COLOR_TITLE_FOREGROUND);
175 }
176 return titleForeground_;
177 }
102 /** 178 /**
103 * @see DWT#COLOR_TITLE_INACTIVE_FOREGROUND 179 * @see DWT#COLOR_TITLE_INACTIVE_FOREGROUND
104 */ 180 */
105 static const Color titleInactiveForeground; 181 private static Color titleInactiveForeground_;
182 public static Color titleInactiveForeground(){
183 if( titleInactiveForeground_ is null ){
184 titleInactiveForeground_ = getColor(DWT.COLOR_TITLE_INACTIVE_FOREGROUND);
185 }
186 return titleInactiveForeground_;
187 }
106 /** 188 /**
107 * @see DWT#COLOR_TITLE_INACTIVE_BACKGROUND 189 * @see DWT#COLOR_TITLE_INACTIVE_BACKGROUND
108 */ 190 */
109 static const Color titleInactiveBackground; 191 private static Color titleInactiveBackground_;
192 public static Color titleInactiveBackground(){
193 if( titleInactiveBackground_ is null ){
194 titleInactiveBackground_ = getColor(DWT.COLOR_TITLE_INACTIVE_BACKGROUND);
195 }
196 return titleInactiveBackground_;
197 }
110 /** 198 /**
111 * @see DWT#COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT 199 * @see DWT#COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT
112 */ 200 */
113 static const Color titleInactiveGradient; 201 private static Color titleInactiveGradient_;
202 public static Color titleInactiveGradient(){
203 if( titleInactiveGradient_ is null ){
204 titleInactiveGradient_ = getColor(DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT);
205 }
206 return titleInactiveGradient_;
207 }
114 208
115 /** 209 /**
116 * @see DWT#COLOR_INFO_FOREGROUND 210 * @see DWT#COLOR_INFO_FOREGROUND
117 */ 211 */
118 static const Color tooltipForeground; 212 private static Color tooltipForeground_;
213 public static Color tooltipForeground(){
214 if( tooltipForeground_ is null ){
215 tooltipForeground_ = getColor(DWT.COLOR_INFO_FOREGROUND);
216 }
217 return tooltipForeground_;
218 }
119 /** 219 /**
120 * @see DWT#COLOR_INFO_BACKGROUND 220 * @see DWT#COLOR_INFO_BACKGROUND
121 */ 221 */
122 static const Color tooltipBackground; 222 private static Color tooltipBackground_;
223 public static Color tooltipBackground(){
224 if( tooltipBackground_ is null ){
225 tooltipBackground_ = getColor(DWT.COLOR_INFO_BACKGROUND);
226 }
227 return tooltipBackground_;
228 }
123 229
124 /* 230 /*
125 * Misc. colors 231 * Misc. colors
126 */ 232 */
127 /** One of the pre-defined colors */ 233 /** One of the pre-defined colors */
128 static const Color white; 234 private static Color white_;
129 /** One of the pre-defined colors */ 235 public static Color white(){
130 static const Color lightGray; 236 if( white_ is null ){
131 /** One of the pre-defined colors */ 237 white_ = new Color(null, 255, 255, 255);
132 static const Color gray; 238 }
133 /** One of the pre-defined colors */ 239 return white_;
134 static const Color darkGray; 240 }
135 /** One of the pre-defined colors */ 241 /** One of the pre-defined colors */
136 static const Color black; 242 private static Color lightGray_;
137 /** One of the pre-defined colors */ 243 public static Color lightGray(){
138 static const Color red; 244 if( lightGray_ is null ){
139 /** One of the pre-defined colors */ 245 lightGray_ = new Color(null, 192, 192, 192);
140 static const Color orange; 246 }
141 /** One of the pre-defined colors */ 247 return lightGray_;
142 static const Color yellow; 248 }
143 /** One of the pre-defined colors */ 249 /** One of the pre-defined colors */
144 static const Color green; 250 private static Color gray_;
145 /** One of the pre-defined colors */ 251 public static Color gray(){
146 static const Color lightGreen; 252 if( gray_ is null ){
147 /** One of the pre-defined colors */ 253 gray_ = new Color(null, 128, 128, 128);
148 static const Color darkGreen; 254 }
149 /** One of the pre-defined colors */ 255 return gray_;
150 static const Color cyan; 256 }
151 /** One of the pre-defined colors */ 257 /** One of the pre-defined colors */
152 static const Color lightBlue; 258 private static Color darkGray_;
153 /** One of the pre-defined colors */ 259 public static Color darkGray(){
154 static const Color blue; 260 if( darkGray_ is null ){
155 /** One of the pre-defined colors */ 261 darkGray_ = new Color(null, 64, 64, 64);
156 static const Color darkBlue; 262 }
157 263 return darkGray_;
158 264 }
159 static this(){ 265 /** One of the pre-defined colors */
160 buttonLightest = SystemColorFactory.getColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); 266 private static Color black_;
161 button = SystemColorFactory.getColor(DWT.COLOR_WIDGET_BACKGROUND); 267 public static Color black(){
162 buttonDarker = SystemColorFactory.getColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); 268 if( black_ is null ){
163 buttonDarkest = SystemColorFactory.getColor(DWT.COLOR_WIDGET_DARK_SHADOW); 269 black_ = new Color(null, 0, 0, 0);
164 listBackground = SystemColorFactory.getColor(DWT.COLOR_LIST_BACKGROUND); 270 }
165 listForeground = SystemColorFactory.getColor(DWT.COLOR_LIST_FOREGROUND); 271 return black_;
166 menuBackground = SystemColorFactory.getColor(DWT.COLOR_WIDGET_BACKGROUND); 272 }
167 menuForeground = SystemColorFactory.getColor(DWT.COLOR_WIDGET_FOREGROUND); 273 /** One of the pre-defined colors */
168 menuBackgroundSelected = SystemColorFactory.getColor(DWT.COLOR_LIST_SELECTION); 274 private static Color red_;
169 menuForegroundSelected = SystemColorFactory.getColor(DWT.COLOR_LIST_SELECTION_TEXT); 275 public static Color red(){
170 titleBackground = SystemColorFactory.getColor(DWT.COLOR_TITLE_BACKGROUND); 276 if( red_ is null ){
171 titleGradient = SystemColorFactory.getColor(DWT.COLOR_TITLE_BACKGROUND_GRADIENT); 277 red_ = new Color(null, 255, 0, 0);
172 titleForeground = SystemColorFactory.getColor(DWT.COLOR_TITLE_FOREGROUND); 278 }
173 titleInactiveForeground = SystemColorFactory.getColor(DWT.COLOR_TITLE_INACTIVE_FOREGROUND); 279 return red_;
174 titleInactiveBackground = SystemColorFactory.getColor(DWT.COLOR_TITLE_INACTIVE_BACKGROUND); 280 }
175 titleInactiveGradient = SystemColorFactory.getColor(DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT); 281 /** One of the pre-defined colors */
176 tooltipForeground = SystemColorFactory.getColor(DWT.COLOR_INFO_FOREGROUND); 282 private static Color orange_;
177 tooltipBackground = SystemColorFactory.getColor(DWT.COLOR_INFO_BACKGROUND); 283 public static Color orange(){
178 white = new Color(null, 255, 255, 255); 284 if( orange_ is null ){
179 lightGray = new Color(null, 192, 192, 192); 285 orange_ = new Color(null, 255, 196, 0);
180 gray = new Color(null, 128, 128, 128); 286 }
181 darkGray = new Color(null, 64, 64, 64); 287 return orange_;
182 black = new Color(null, 0, 0, 0); 288 }
183 red = new Color(null, 255, 0, 0); 289 /** One of the pre-defined colors */
184 orange = new Color(null, 255, 196, 0); 290 private static Color yellow_;
185 yellow = new Color(null, 255, 255, 0); 291 public static Color yellow(){
186 green = new Color(null, 0, 255, 0); 292 if( yellow_ is null ){
187 lightGreen = new Color(null, 96, 255, 96); 293 yellow_ = new Color(null, 255, 255, 0);
188 darkGreen = new Color(null, 0, 127, 0); 294 }
189 cyan = new Color(null, 0, 255, 255); 295 return yellow_;
190 lightBlue = new Color(null, 127, 127, 255); 296 }
191 blue = new Color(null, 0, 0, 255); 297 /** One of the pre-defined colors */
192 darkBlue = new Color(null, 0, 0, 127); 298 private static Color green_;
193 } 299 public static Color green(){
194 } 300 if( green_ is null ){
195 301 green_ = new Color(null, 0, 255, 0);
196 302 }
303 return green_;
304 }
305 /** One of the pre-defined colors */
306 private static Color lightGreen_;
307 public static Color lightGreen(){
308 if( lightGreen_ is null ){
309 lightGreen_ = new Color(null, 96, 255, 96);
310 }
311 return lightGreen_;
312 }
313 /** One of the pre-defined colors */
314 private static Color darkGreen_;
315 public static Color darkGreen(){
316 if( darkGreen_ is null ){
317 darkGreen_ = new Color(null, 0, 127, 0);
318 }
319 return darkGreen_;
320 }
321 /** One of the pre-defined colors */
322 private static Color cyan_;
323 public static Color cyan(){
324 if( cyan_ is null ){
325 cyan_ = new Color(null, 0, 255, 255);
326 }
327 return cyan_;
328 }
329 /** One of the pre-defined colors */
330 private static Color lightBlue_;
331 public static Color lightBlue(){
332 if( lightBlue_ is null ){
333 lightBlue_ = new Color(null, 127, 127, 255);
334 }
335 return lightBlue_;
336 }
337 /** One of the pre-defined colors */
338 private static Color blue_;
339 public static Color blue(){
340 if( blue_ is null ){
341 blue_ = new Color(null, 0, 0, 255);
342 }
343 return blue_;
344 }
345 /** One of the pre-defined colors */
346 private static Color darkBlue_;
347 public static Color darkBlue(){
348 if( darkBlue_ is null ){
349 darkBlue_ = new Color(null, 0, 0, 127);
350 }
351 return darkBlue_;
352 }
353
354 }
355
356