--- /dev/null
+/*******************************************************************************
+ * 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;
+ }
+
+}