[WIP] CFV Refactor
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / provisional / tmf / ui / views / timegraph2 / swt / SwtColorFactory.java
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/provisional/tmf/ui/views/timegraph2/swt/SwtColorFactory.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/provisional/tmf/ui/views/timegraph2/swt/SwtColorFactory.java
new file mode 100644 (file)
index 0000000..1db44db
--- /dev/null
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.provisional.tmf.ui.views.timegraph2.swt;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.tracecompass.internal.provisional.tmf.core.views.timegraph2.ColorDefinition;
+
+final class SwtColorFactory {
+
+    private SwtColorFactory() {}
+
+    private static final Map<ColorDefinition, Color> COLOR_MAP = new HashMap<>();
+
+    /**
+     * Instantiate a {@link Color} from a {@link ColorDefinition} object.
+     *
+     * Must be called by the UI thread only, so it should not need any special
+     * synchronization.
+     *
+     * @param colorDef
+     *            The ColorDefinition
+     * @return The Color object
+     */
+    public static Color getColorFromDef(ColorDefinition colorDef) {
+        Color color = COLOR_MAP.get(colorDef);
+        if (color == null) {
+            color = new Color(Display.getDefault(), colorDef.fRed, colorDef.fGreen, colorDef.fBlue, colorDef.fAlpha);
+            COLOR_MAP.put(colorDef, color);
+        }
+        return color;
+    }
+
+}
This page took 0.024196 seconds and 5 git commands to generate.