Mercurial > projects > dwt-addons
comparison dwtx/jface/fieldassist/FieldAssistColors.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | f12d40e7da8f |
children |
comparison
equal
deleted
inserted
replaced
103:2d6540440fe6 | 104:04b47443bb01 |
---|---|
10 * Port to the D programming language: | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | 11 * Frank Benoit <benoit@tionex.de> |
12 *******************************************************************************/ | 12 *******************************************************************************/ |
13 module dwtx.jface.fieldassist.FieldAssistColors; | 13 module dwtx.jface.fieldassist.FieldAssistColors; |
14 | 14 |
15 import tango.util.collection.ArraySeq; | |
16 import tango.util.collection.HashMap; | |
17 import tango.util.collection.model.Map; | |
18 import tango.util.collection.model.Seq; | |
19 | 15 |
20 import dwt.DWT; | 16 import dwt.DWT; |
21 import dwt.graphics.Color; | 17 import dwt.graphics.Color; |
22 import dwt.graphics.RGB; | 18 import dwt.graphics.RGB; |
23 import dwt.widgets.Control; | 19 import dwt.widgets.Control; |
24 import dwt.widgets.Display; | 20 import dwt.widgets.Display; |
25 import dwtx.jface.resource.JFaceColors; | 21 import dwtx.jface.resource.JFaceColors; |
26 | 22 |
27 import dwt.dwthelper.utils; | 23 import dwt.dwthelper.utils; |
24 import dwtx.dwtxhelper.Collection; | |
28 import dwt.dwthelper.Runnable; | 25 import dwt.dwthelper.Runnable; |
29 import tango.io.Stdout; | 26 import tango.io.Stdout; |
30 | 27 |
31 /** | 28 /** |
32 * FieldAssistColors defines protocol for retrieving colors that can be used to | 29 * FieldAssistColors defines protocol for retrieving colors that can be used to |
51 | 48 |
52 /* | 49 /* |
53 * Keys are background colors, values are the color with the alpha value | 50 * Keys are background colors, values are the color with the alpha value |
54 * applied | 51 * applied |
55 */ | 52 */ |
56 private static Map!(Object,Object) requiredFieldColorMap; | 53 private static Map requiredFieldColorMap; |
57 | 54 |
58 /* | 55 /* |
59 * Keys are colors we have created, values are the displays on which they | 56 * Keys are colors we have created, values are the displays on which they |
60 * were created. | 57 * were created. |
61 */ | 58 */ |
62 private static Map!(Object,Object) displays; | 59 private static Map displays; |
63 | 60 |
64 static this(){ | 61 static this(){ |
65 requiredFieldColorMap = new HashMap!(Object,Object); | 62 requiredFieldColorMap = new HashMap(); |
66 displays = new HashMap!(Object,Object); | 63 displays = new HashMap(); |
67 } | 64 } |
68 | 65 |
69 /** | 66 /** |
70 * Compute the RGB of the color that should be used for the background of a | 67 * Compute the RGB of the color that should be used for the background of a |
71 * control to indicate that the control has an error. Because the color | 68 * control to indicate that the control has an error. Because the color |
145 destBlue += (src.getBlue() - destBlue) * alpha / 0xFF; | 142 destBlue += (src.getBlue() - destBlue) * alpha / 0xFF; |
146 | 143 |
147 // create the color | 144 // create the color |
148 Color color = new Color(display, destRed, destGreen, destBlue); | 145 Color color = new Color(display, destRed, destGreen, destBlue); |
149 // record the color in a map using the original color as the key | 146 // record the color in a map using the original color as the key |
150 requiredFieldColorMap.add(dest, color); | 147 requiredFieldColorMap.put(dest, color); |
151 // If we have never created a color on this display before, install | 148 // If we have never created a color on this display before, install |
152 // a dispose exec on the display. | 149 // a dispose exec on the display. |
153 if (!displays.contains(display)) { | 150 if (!displays.containsKey(display)) { |
154 display.disposeExec(new class Runnable { | 151 display.disposeExec(new class Runnable { |
155 public void run() { | 152 public void run() { |
156 disposeColors(display); | 153 disposeColors(display); |
157 } | 154 } |
158 }); | 155 }); |
159 } | 156 } |
160 // Record the color and its display in a map for later disposal. | 157 // Record the color and its display in a map for later disposal. |
161 displays.add(color, display); | 158 displays.put(color, display); |
162 return color; | 159 return color; |
163 } | 160 } |
164 | 161 |
165 /* | 162 /* |
166 * Dispose any colors that were allocated for the given display. | 163 * Dispose any colors that were allocated for the given display. |
167 */ | 164 */ |
168 private static void disposeColors(Display display) { | 165 private static void disposeColors(Display display) { |
169 auto toBeRemoved = new ArraySeq!(Object); | 166 List toBeRemoved = new ArrayList(1); |
170 | 167 |
171 if (DEBUG) { | 168 if (DEBUG) { |
172 Stdout.formatln("Display map is {}", (cast(Object)displays).toString()); //$NON-NLS-1$ | 169 Stdout.formatln("Display map is {}", (cast(Object)displays).toString()); //$NON-NLS-1$ |
173 Stdout.formatln("Color map is {}", (cast(Object)requiredFieldColorMap).toString()); //$NON-NLS-1$ | 170 Stdout.formatln("Color map is {}", (cast(Object)requiredFieldColorMap).toString()); //$NON-NLS-1$ |
174 } | 171 } |
175 | 172 |
176 // Look for any stored colors that were created on this display | 173 // Look for any stored colors that were created on this display |
177 foreach( k, v; displays ){ | 174 for (Iterator i = displays.keySet().iterator(); i.hasNext();) { |
178 Color color = cast(Color) k; | 175 Color color = cast(Color) i.next(); |
179 if ((cast(Display) displays.get(color)).opEquals(display)) { | 176 if ((cast(Display) displays.get(color)).opEquals(display)) { |
180 // The color is on this display. Mark it for removal. | 177 // The color is on this display. Mark it for removal. |
181 toBeRemoved.append(color); | 178 toBeRemoved.add(color); |
182 | 179 |
183 // Now look for any references to it in the required field color | 180 // Now look for any references to it in the required field color |
184 // map | 181 // map |
185 auto toBeRemovedFromRequiredMap = new ArraySeq!(Object); | 182 List toBeRemovedFromRequiredMap = new ArrayList(1); |
186 foreach( k, v; requiredFieldColorMap ){ | 183 for (Iterator iter = requiredFieldColorMap.keySet().iterator(); iter |
187 Color bgColor = cast(Color) k; | 184 .hasNext();) { |
185 Color bgColor = cast(Color) iter.next(); | |
188 if ((cast(Color) requiredFieldColorMap.get(bgColor)) | 186 if ((cast(Color) requiredFieldColorMap.get(bgColor)) |
189 .opEquals(color)) { | 187 .opEquals(color)) { |
190 // mark it for removal from the required field color map | 188 // mark it for removal from the required field color map |
191 toBeRemovedFromRequiredMap.append(bgColor); | 189 toBeRemovedFromRequiredMap.add(bgColor); |
192 } | 190 } |
193 } | 191 } |
194 // Remove references in the required field map now that | 192 // Remove references in the required field map now that |
195 // we are done iterating. | 193 // we are done iterating. |
196 for (int j = 0; j < toBeRemovedFromRequiredMap.size(); j++) { | 194 for (int j = 0; j < toBeRemovedFromRequiredMap.size(); j++) { |