Skip to content

Commit d5c939b

Browse files
committed
ColorPool no longer has getSystemColor because the resource management angle doesn't matter anymore. #8
1 parent 24b47a5 commit d5c939b

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

durian-swt/src/main/java/com/diffplug/common/swt/ColorPool.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,13 @@
2626

2727
/** Caches {@link Color}s, and automatically manages their disposal. */
2828
public class ColorPool {
29-
private final HashMap<RGB, Color> colorTable = Maps.newHashMap();
30-
private final Display display;
29+
private final HashMap<RGB, Color> colorTable = new HashMap<>();
3130

32-
private ColorPool(Widget parent) {
33-
display = parent.getDisplay();
34-
parent.addListener(SWT.Dispose, e -> colorTable.values().forEach(Color::dispose));
35-
}
31+
private ColorPool() {}
3632

3733
/** Returns a Color for the given RGB value. */
3834
public Color getColor(RGB rgb) {
39-
Color color = colorTable.get(rgb);
40-
if (color == null) {
41-
color = new Color(display, rgb);
42-
colorTable.put(rgb, color);
43-
}
44-
return color;
45-
}
46-
47-
/** Returns a Color for the SWT.COLOR_xxx. */
48-
public Color getSystemColor(int systemColor) {
49-
return display.getSystemColor(systemColor);
35+
return colorTable.computeIfAbsent(rgb, raw -> new Color(raw));
5036
}
5137

5238
/** Returns a ColorPool for the given Widget, creating one if necessary. */
@@ -59,5 +45,5 @@ public static ColorPool forWidget(ControlWrapper wrapper) {
5945
return onePerWidget.forWidget(wrapper.getRootControl());
6046
}
6147

62-
private static final OnePerWidget<Widget, ColorPool> onePerWidget = OnePerWidget.from(ColorPool::new);
48+
private static final OnePerWidget<Widget, ColorPool> onePerWidget = OnePerWidget.from(unused -> new ColorPool());
6349
}

0 commit comments

Comments
 (0)