Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3425aaf5897ee3b5cf15758320c0f57dd7f122a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*******************************************************************************
 * Copyright (c) 2012 Tilera Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     William R. Swanson (Tilera Corporation)
 *******************************************************************************/

package org.eclipse.cdt.visualizer.ui.util;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;

// ---------------------------------------------------------------------------
// Colors
// ---------------------------------------------------------------------------

/**
 * Standard color constants.
 *
 * This is basically a set of cached color resources
 * for commonly-used colors.
 * These are drawn from an associated UIResourceManager.
 * The initialize() method should be called immediately
 * after you create the resource manager.
 */
public class Colors {

	// --- static members ---

	/** UI Resource manager colors are drawn from */
	protected static UIResourceManager s_resources = null;

	// Color objects for all the standard "int" colors in the SWT class:
	public static Color WHITE = null;
	public static Color BLACK = null;
	public static Color RED = null;
	public static Color DARK_RED = null;
	public static Color GREEN = null;
	public static Color DARK_GREEN = null;
	public static Color YELLOW = null;
	public static Color DARK_YELLOW = null;
	public static Color BLUE = null;
	public static Color DARK_BLUE = null;
	public static Color MAGENTA = null;
	public static Color DARK_MAGENTA = null;
	public static Color CYAN = null;
	public static Color DARK_CYAN = null;
	public static Color GRAY = null;
	public static Color DARK_GRAY = null;

	// Other "custom" Color objects:
	public static Color ORANGE = null;
	public static Color MEDIUM_GREEN = null;
	public static Color DARK_ORANGE = null;
	public static Color SEMI_DARK_YELLOW = null;
	public static Color DARK_MUTED_YELLOW = null;
	public static Color DARK_MUTED_GREEN = null;
	public static Color DARKER_RED = null;
	public static Color VERY_DARK_GRAY = null;
	public static Color WIDGET_UNEDITABLE_BACKGROUND = null;
	public static Color WIDGET_NORMAL_BACKGROUND = null;

	public static void initialize(UIResourceManager resources) {

		// set resource manager for future use
		s_resources = resources;

		// Color objects for all the standard "int" colors in the SWT class:
		WHITE = getColor(SWT.COLOR_WHITE);
		BLACK = getColor(SWT.COLOR_BLACK);
		RED = getColor(SWT.COLOR_RED);
		DARK_RED = getColor(SWT.COLOR_DARK_RED);
		GREEN = getColor(SWT.COLOR_GREEN);
		DARK_GREEN = getColor(SWT.COLOR_DARK_GREEN);
		YELLOW = getColor(SWT.COLOR_YELLOW);
		DARK_YELLOW = getColor(SWT.COLOR_DARK_YELLOW);
		BLUE = getColor(SWT.COLOR_BLUE);
		DARK_BLUE = getColor(SWT.COLOR_DARK_BLUE);
		MAGENTA = getColor(SWT.COLOR_MAGENTA);
		DARK_MAGENTA = getColor(SWT.COLOR_DARK_MAGENTA);
		CYAN = getColor(SWT.COLOR_CYAN);
		DARK_CYAN = getColor(SWT.COLOR_DARK_CYAN);
		GRAY = getColor(SWT.COLOR_GRAY);
		DARK_GRAY = getColor(SWT.COLOR_DARK_GRAY);

		// Other "custom" Color objects:
		ORANGE = getColor(255, 150, 90);
		MEDIUM_GREEN = getColor(0, 192, 0);
		DARK_ORANGE = getColor(215, 128, 81);
		SEMI_DARK_YELLOW = getColor(192, 192, 0);
		DARK_MUTED_YELLOW = getColor(90, 90, 50);
		DARK_MUTED_GREEN = getColor(18, 92, 18);
		DARKER_RED = getColor(174, 25, 13);
		VERY_DARK_GRAY = getColor(60, 60, 60);

		WIDGET_NORMAL_BACKGROUND = getColor(SWT.COLOR_WHITE);
		WIDGET_UNEDITABLE_BACKGROUND = getColor(220, 220, 220);
	}

	// --- constructors/destructors ---

	/** Constructor
	 *  Private, since this is basically a bunch of constants.
	 */
	private Colors() {
	}

	/**
	 *  Gets color for a given SWT color constant.
	 */
	// final so this can be inlined where possible
	public static final Color getColor(int colorID) {
		return (s_resources == null) ? null : s_resources.getColor(colorID);
	}

	/**
	 *  Gets color for given RGB values (0-255).
	 */
	// final so this can be inlined where possible
	public static final Color getColor(int red, int green, int blue) {
		return (s_resources == null) ? null : s_resources.getColor(red, green, blue);
	}
}

Back to the top