1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 * Bernd Hufmann - Updated to use RGB for the tick color
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.colors
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
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
;
28 * Class for storing color settings of a TMF filter.
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.
35 * @author Patrick Tasse
37 public class ColorSetting
{
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
;
52 * You must dispose the color setting when it is no longer required.
55 * The foreground color, or null to use the default system color
57 * The background color, or null to use the default system color
59 * The color for the time graph ticks, or null to use the default system color
61 * The filter tree node, or null
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());
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
);
80 * Dispose the color setting resources
82 public void dispose() {
83 if (fForegroundColor
!= null) {
84 fForegroundColor
.dispose();
86 if (fBackgroundColor
!= null) {
87 fBackgroundColor
.dispose();
89 if (fDimmedForegroundColor
!= null) {
90 fDimmedForegroundColor
.dispose();
92 if (fDimmedBackgroundColor
!= null) {
93 fDimmedBackgroundColor
.dispose();
99 * Returns foreground RGB value, or null if the default system color is
102 * @return the foreground RGB, or null
104 public @Nullable RGB
getForegroundRGB() {
105 return fForegroundRGB
;
109 * Sets the foreground RGB value. If the argument is null the default system
110 * color will be used.
113 * the foreground to set, or null
115 public void setForegroundRGB(@Nullable RGB foreground
) {
116 fForegroundRGB
= foreground
;
117 if (fForegroundColor
!= null) {
118 fForegroundColor
.dispose();
120 if (fDimmedForegroundColor
!= null) {
121 fDimmedForegroundColor
.dispose();
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()));
131 * Returns the background RGB value, or null if the default system color is
134 * @return the background RGB, or null
136 public @Nullable RGB
getBackgroundRGB() {
137 return fBackgroundRGB
;
141 * Sets the background RGB value. If the argument is null the default system
142 * color will be used.
145 * the background to set, or null
147 public void setBackgroundRGB(@Nullable RGB background
) {
148 fBackgroundRGB
= background
;
149 if (fBackgroundColor
!= null) {
150 fBackgroundColor
.dispose();
152 if (fDimmedBackgroundColor
!= null) {
153 fDimmedBackgroundColor
.dispose();
155 if (fDimmedForegroundColor
!= null) {
156 fDimmedForegroundColor
.dispose();
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()));
168 * Returns the RGB of the tick color
170 * @return the RGB of the tick color
172 public @NonNull RGB
getTickColorRGB() {
173 return fTickColorRGB
;
177 * Sets the RGB of the tick color
179 * @param tickColorRGB
182 public void setTickColorRGB(@NonNull RGB tickColorRGB
) {
183 fTickColorRGB
= tickColorRGB
;
184 fTickColor
.dispose();
185 Display display
= Display
.getDefault();
186 fTickColor
= new Color(display
, fTickColorRGB
);
190 * Returns the filter implementation.
192 * @return the filter, or null
194 public @Nullable ITmfFilterTreeNode
getFilter() {
199 * Sets the filter implementation.
202 * the filter to set, or null
204 public void setFilter(@Nullable ITmfFilterTreeNode filter
) {
209 * Returns the foreground color, or null if the default system color is
212 * @return the foreground color, or null
214 public @Nullable Color
getForegroundColor() {
215 return fForegroundColor
;
219 * Returns the background color, or null if the default system color is
222 * @return the background color, or null
224 public @Nullable Color
getBackgroundColor() {
225 return fBackgroundColor
;
229 * Returns the dimmed foreground color, or null if the default system color
232 * @return the dimmed foreground color, or null
234 public @Nullable Color
getDimmedForegroundColor() {
235 return fDimmedForegroundColor
;
239 * Returns the dimmed background color, or null if the default system color
242 * @return the dimmed background color, or null
244 public @Nullable Color
getDimmedBackgroundColor() {
245 return fDimmedBackgroundColor
;
249 * Returns the tick color.
251 * @return the tick color
253 public Color
getTickColor() {