tmf: Replace Color resource with RGBA descriptor in marker events
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / widgets / timegraph / widgets / TimeGraphColorScheme.java
index 2c44c26157f5074c30309dea05ce44aecf5db0de..f4e0ec7f5ebd397bef4c674be0ae1950c2643cf4 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (c) 2008, 2014 Intel Corporation, Ericsson
+ * Copyright (c) 2008, 2016 Intel Corporation, Ericsson
  * 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
 
 package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGBA;
+import org.eclipse.swt.widgets.Display;
 
 /**
  * Color theme used by the timegraph view
@@ -300,13 +305,17 @@ public class TimeGraphColorScheme {
         new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_WIDGET_BACKGROUND), 1, 6), // BACKGROUND_NAME_SEL_NOFOCUS
     };
 
+    /** Fixed scheme colors */
     private final Color fColors[];
+    /** Dynamic RGBA to Color map */
+    private final Map<RGBA, Color> fColorMap;
 
     /**
      * Default constructor
      */
     public TimeGraphColorScheme() {
         fColors = new Color[PROVIDERS_MAP.length];
+        fColorMap = new HashMap<>();
     }
 
     /**
@@ -317,6 +326,9 @@ public class TimeGraphColorScheme {
             Utils.dispose(fColors[i]);
             fColors[i] = null;
         }
+        for (Color color : fColorMap.values()) {
+            color.dispose();
+        }
     }
 
     /**
@@ -425,4 +437,22 @@ public class TimeGraphColorScheme {
         }
         return getColor(GR_FOREGROUND);
     }
+
+    /**
+     * Get a color resource for the specified RGBA color descriptor
+     *
+     * @param rgba
+     *            the color descriptor
+     * @return a color resource
+     * @since 2.0
+     */
+    public Color getColor(RGBA rgba) {
+        Color color = fColorMap.get(rgba);
+        if (color == null) {
+            color = new Color(Display.getDefault(), rgba);
+            fColorMap.put(rgba, color);
+        }
+        return color;
+    }
+
 }
This page took 0.029494 seconds and 5 git commands to generate.