lttng: Help stabilize some TimeGraphs tests
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / colors / ColorSetting.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 Ericsson
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 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 * Bernd Hufmann - Updated to use RGB for the tick color
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.ui.views.colors;
15
16 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.graphics.Color;
22 import org.eclipse.swt.graphics.RGB;
23 import org.eclipse.swt.widgets.Display;
24 import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode;
25 import org.eclipse.ui.themes.ColorUtil;
26
27 /**
28 * Class for storing color settings of a TMF filter.
29 *
30 * Application code must explicitly invoke the ColorSetting.dispose() method to
31 * release the operating system resources managed by each instance when those
32 * instances are no longer required.
33 *
34 * @version 1.0
35 * @author Patrick Tasse
36 */
37 public class ColorSetting {
38
39 private @Nullable RGB fForegroundRGB;
40 private @Nullable RGB fBackgroundRGB;
41 private @NonNull RGB fTickColorRGB;
42 private @Nullable Color fForegroundColor;
43 private @Nullable Color fBackgroundColor;
44 private @Nullable Color fDimmedForegroundColor;
45 private @Nullable Color fDimmedBackgroundColor;
46 private @NonNull Color fTickColor;
47 private @Nullable ITmfFilterTreeNode fFilter;
48
49 /**
50 * Constructor
51 *
52 * You must dispose the color setting when it is no longer required.
53 *
54 * @param foreground
55 * The foreground color, or null to use the default system color
56 * @param background
57 * The background color, or null to use the default system color
58 * @param tickColorRGB
59 * The color for the time graph ticks, or null to use the default system color
60 * @param filter
61 * The filter tree node, or null
62 */
63 public ColorSetting(@Nullable RGB foreground, @Nullable RGB background, @Nullable RGB tickColorRGB, @Nullable ITmfFilterTreeNode filter) {
64 fForegroundRGB = foreground;
65 fBackgroundRGB = background;
66 fTickColorRGB = (tickColorRGB != null) ? tickColorRGB : checkNotNull(Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB());
67 fFilter = filter;
68 Display display = Display.getDefault();
69 fForegroundColor = (fForegroundRGB != null) ? new Color(display, fForegroundRGB) : null;
70 fBackgroundColor = (fBackgroundRGB != null) ? new Color(display, fBackgroundRGB) : null;
71 fDimmedForegroundColor = new Color(display, ColorUtil.blend(
72 (fForegroundRGB != null) ? fForegroundRGB : display.getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
73 (fBackgroundRGB != null) ? fBackgroundRGB : display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()));
74 fDimmedBackgroundColor = (fBackgroundRGB == null) ? null : new Color(display, ColorUtil.blend(
75 fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()));
76 fTickColor = new Color(display, fTickColorRGB);
77 }
78
79 /**
80 * Dispose the color setting resources
81 */
82 public void dispose() {
83 if (fForegroundColor != null) {
84 fForegroundColor.dispose();
85 }
86 if (fBackgroundColor != null) {
87 fBackgroundColor.dispose();
88 }
89 if (fDimmedForegroundColor != null) {
90 fDimmedForegroundColor.dispose();
91 }
92 if (fDimmedBackgroundColor != null) {
93 fDimmedBackgroundColor.dispose();
94 }
95 fTickColor.dispose();
96 }
97
98 /**
99 * Returns foreground RGB value, or null if the default system color is
100 * used.
101 *
102 * @return the foreground RGB, or null
103 */
104 public @Nullable RGB getForegroundRGB() {
105 return fForegroundRGB;
106 }
107
108 /**
109 * Sets the foreground RGB value. If the argument is null the default system
110 * color will be used.
111 *
112 * @param foreground
113 * the foreground to set, or null
114 */
115 public void setForegroundRGB(@Nullable RGB foreground) {
116 fForegroundRGB = foreground;
117 if (fForegroundColor != null) {
118 fForegroundColor.dispose();
119 }
120 if (fDimmedForegroundColor != null) {
121 fDimmedForegroundColor.dispose();
122 }
123 Display display = Display.getDefault();
124 fForegroundColor = (fForegroundRGB != null) ? new Color(display, fForegroundRGB) : null;
125 fDimmedForegroundColor = new Color(display, ColorUtil.blend(
126 (fForegroundRGB != null) ? fForegroundRGB : display.getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
127 (fBackgroundRGB != null) ? fBackgroundRGB : display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()));
128 }
129
130 /**
131 * Returns the background RGB value, or null if the default system color is
132 * used.
133 *
134 * @return the background RGB, or null
135 */
136 public @Nullable RGB getBackgroundRGB() {
137 return fBackgroundRGB;
138 }
139
140 /**
141 * Sets the background RGB value. If the argument is null the default system
142 * color will be used.
143 *
144 * @param background
145 * the background to set, or null
146 */
147 public void setBackgroundRGB(@Nullable RGB background) {
148 fBackgroundRGB = background;
149 if (fBackgroundColor != null) {
150 fBackgroundColor.dispose();
151 }
152 if (fDimmedBackgroundColor != null) {
153 fDimmedBackgroundColor.dispose();
154 }
155 if (fDimmedForegroundColor != null) {
156 fDimmedForegroundColor.dispose();
157 }
158 Display display = Display.getDefault();
159 fBackgroundColor = (fBackgroundRGB != null) ? new Color(display, fBackgroundRGB) : null;
160 fDimmedBackgroundColor = (fBackgroundRGB == null) ? null : new Color(display, ColorUtil.blend(
161 fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()));
162 fDimmedForegroundColor = new Color(display, ColorUtil.blend(
163 (fForegroundRGB != null) ? fForegroundRGB : display.getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
164 (fBackgroundRGB != null) ? fBackgroundRGB : display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()));
165 }
166
167 /**
168 * Returns the RGB of the tick color
169 *
170 * @return the RGB of the tick color
171 */
172 public @NonNull RGB getTickColorRGB() {
173 return fTickColorRGB;
174 }
175
176 /**
177 * Sets the RGB of the tick color
178 *
179 * @param tickColorRGB
180 * the tick color TGB
181 */
182 public void setTickColorRGB(@NonNull RGB tickColorRGB) {
183 fTickColorRGB = tickColorRGB;
184 fTickColor.dispose();
185 Display display = Display.getDefault();
186 fTickColor = new Color(display, fTickColorRGB);
187 }
188
189 /**
190 * Returns the filter implementation.
191 *
192 * @return the filter, or null
193 */
194 public @Nullable ITmfFilterTreeNode getFilter() {
195 return fFilter;
196 }
197
198 /**
199 * Sets the filter implementation.
200 *
201 * @param filter
202 * the filter to set, or null
203 */
204 public void setFilter(@Nullable ITmfFilterTreeNode filter) {
205 fFilter = filter;
206 }
207
208 /**
209 * Returns the foreground color, or null if the default system color is
210 * used.
211 *
212 * @return the foreground color, or null
213 */
214 public @Nullable Color getForegroundColor() {
215 return fForegroundColor;
216 }
217
218 /**
219 * Returns the background color, or null if the default system color is
220 * used.
221 *
222 * @return the background color, or null
223 */
224 public @Nullable Color getBackgroundColor() {
225 return fBackgroundColor;
226 }
227
228 /**
229 * Returns the dimmed foreground color, or null if the default system color
230 * is used.
231 *
232 * @return the dimmed foreground color, or null
233 */
234 public @Nullable Color getDimmedForegroundColor() {
235 return fDimmedForegroundColor;
236 }
237
238 /**
239 * Returns the dimmed background color, or null if the default system color
240 * is used.
241 *
242 * @return the dimmed background color, or null
243 */
244 public @Nullable Color getDimmedBackgroundColor() {
245 return fDimmedBackgroundColor;
246 }
247
248 /**
249 * Returns the tick color.
250 *
251 * @return the tick color
252 */
253 public Color getTickColor() {
254 return fTickColor;
255 }
256 }
This page took 0.038765 seconds and 5 git commands to generate.