[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
1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.provisional.tmf.ui.views.timegraph2.swt;
11
12 import java.util.HashMap;
13 import java.util.Map;
14
15 import org.eclipse.swt.graphics.Color;
16 import org.eclipse.swt.widgets.Display;
17 import org.eclipse.tracecompass.internal.provisional.tmf.core.views.timegraph2.ColorDefinition;
18
19 final class SwtColorFactory {
20
21 private SwtColorFactory() {}
22
23 private static final Map<ColorDefinition, Color> COLOR_MAP = new HashMap<>();
24
25 /**
26 * Instantiate a {@link Color} from a {@link ColorDefinition} object.
27 *
28 * Must be called by the UI thread only, so it should not need any special
29 * synchronization.
30 *
31 * @param colorDef
32 * The ColorDefinition
33 * @return The Color object
34 */
35 public static Color getColorFromDef(ColorDefinition colorDef) {
36 Color color = COLOR_MAP.get(colorDef);
37 if (color == null) {
38 color = new Color(Display.getDefault(), colorDef.fRed, colorDef.fGreen, colorDef.fBlue, colorDef.fAlpha);
39 COLOR_MAP.put(colorDef, color);
40 }
41 return color;
42 }
43
44 }
This page took 0.038427 seconds and 5 git commands to generate.