equal
deleted
inserted
replaced
|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.debug.ui.editors; |
|
6 |
|
7 import java.util.HashMap; |
|
8 import java.util.Map; |
|
9 |
|
10 import org.eclipse.swt.graphics.Color; |
|
11 import org.eclipse.swt.graphics.RGB; |
|
12 import org.eclipse.swt.widgets.Display; |
|
13 |
|
14 /** |
|
15 * Converts RGB to Color, reuses the existing Color instances. |
|
16 * A singleton. |
|
17 */ |
|
18 public class EditorColors { |
|
19 |
|
20 private static final Map<Integer, Color> intToColor = new HashMap<Integer, Color>(); |
|
21 |
|
22 public static Color getColor(RGB rgb) { |
|
23 Integer colorInt = rgbToInteger(rgb); |
|
24 Color color = intToColor.get(colorInt); |
|
25 if (color == null) { |
|
26 color = new Color(Display.getDefault(), rgb); |
|
27 intToColor.put(colorInt, color); |
|
28 } |
|
29 return color; |
|
30 } |
|
31 |
|
32 private static Integer rgbToInteger(RGB rgb) { |
|
33 return |
|
34 ((rgb.red & 0xFF) << 16) + |
|
35 ((rgb.green & 0xFF) << 8) + |
|
36 (rgb.blue & 0xFF); |
|
37 } |
|
38 } |