Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
9b840a86 | 2 | * Copyright (c) 2010, 2015 Ericsson |
be222f56 PT |
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 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.ui.views.colors; |
be222f56 | 15 | |
9b840a86 PT |
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; | |
be222f56 PT |
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; | |
2bdf0193 | 24 | import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode; |
be222f56 PT |
25 | import org.eclipse.ui.themes.ColorUtil; |
26 | ||
27 | /** | |
28 | * Class for storing color settings of a TMF filter. | |
29 | * | |
9b840a86 PT |
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. | |
be222f56 | 33 | * |
9b840a86 PT |
34 | * @version 1.0 |
35 | * @author Patrick Tasse | |
be222f56 PT |
36 | */ |
37 | public class ColorSetting { | |
38 | ||
9b840a86 PT |
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 | /** | |
be222f56 PT |
50 | * Constructor |
51 | * | |
52 | * You must dispose the color setting when it is no longer required. | |
53 | * | |
54 | * @param foreground | |
9b840a86 | 55 | * The foreground color, or null to use the default system color |
be222f56 | 56 | * @param background |
9b840a86 | 57 | * The background color, or null to use the default system color |
be222f56 | 58 | * @param tickColorRGB |
9b840a86 | 59 | * The color for the time graph ticks, or null to use the default system color |
be222f56 | 60 | * @param filter |
9b840a86 | 61 | * The filter tree node, or null |
be222f56 | 62 | */ |
9b840a86 | 63 | public ColorSetting(@Nullable RGB foreground, @Nullable RGB background, @Nullable RGB tickColorRGB, @Nullable ITmfFilterTreeNode filter) { |
d5efe032 AF |
64 | fForegroundRGB = foreground; |
65 | fBackgroundRGB = background; | |
9b840a86 | 66 | fTickColorRGB = (tickColorRGB != null) ? tickColorRGB : checkNotNull(Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB()); |
d5efe032 AF |
67 | fFilter = filter; |
68 | Display display = Display.getDefault(); | |
9b840a86 PT |
69 | fForegroundColor = (fForegroundRGB != null) ? new Color(display, fForegroundRGB) : null; |
70 | fBackgroundColor = (fBackgroundRGB != null) ? new Color(display, fBackgroundRGB) : null; | |
d5efe032 | 71 | fDimmedForegroundColor = new Color(display, ColorUtil.blend( |
9b840a86 PT |
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( | |
d5efe032 AF |
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() { | |
9b840a86 PT |
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 | } | |
d5efe032 AF |
95 | fTickColor.dispose(); |
96 | } | |
97 | ||
98 | /** | |
9b840a86 PT |
99 | * Returns foreground RGB value, or null if the default system color is |
100 | * used. | |
d5efe032 | 101 | * |
9b840a86 | 102 | * @return the foreground RGB, or null |
d5efe032 | 103 | */ |
9b840a86 | 104 | public @Nullable RGB getForegroundRGB() { |
d5efe032 AF |
105 | return fForegroundRGB; |
106 | } | |
107 | ||
108 | /** | |
9b840a86 PT |
109 | * Sets the foreground RGB value. If the argument is null the default system |
110 | * color will be used. | |
d5efe032 | 111 | * |
9b840a86 PT |
112 | * @param foreground |
113 | * the foreground to set, or null | |
d5efe032 | 114 | */ |
9b840a86 | 115 | public void setForegroundRGB(@Nullable RGB foreground) { |
d5efe032 | 116 | fForegroundRGB = foreground; |
9b840a86 PT |
117 | if (fForegroundColor != null) { |
118 | fForegroundColor.dispose(); | |
119 | } | |
120 | if (fDimmedForegroundColor != null) { | |
121 | fDimmedForegroundColor.dispose(); | |
122 | } | |
d5efe032 | 123 | Display display = Display.getDefault(); |
9b840a86 | 124 | fForegroundColor = (fForegroundRGB != null) ? new Color(display, fForegroundRGB) : null; |
d5efe032 | 125 | fDimmedForegroundColor = new Color(display, ColorUtil.blend( |
9b840a86 PT |
126 | (fForegroundRGB != null) ? fForegroundRGB : display.getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), |
127 | (fBackgroundRGB != null) ? fBackgroundRGB : display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB())); | |
d5efe032 AF |
128 | } |
129 | ||
130 | /** | |
9b840a86 PT |
131 | * Returns the background RGB value, or null if the default system color is |
132 | * used. | |
d5efe032 | 133 | * |
9b840a86 | 134 | * @return the background RGB, or null |
d5efe032 | 135 | */ |
9b840a86 | 136 | public @Nullable RGB getBackgroundRGB() { |
d5efe032 AF |
137 | return fBackgroundRGB; |
138 | } | |
139 | ||
140 | /** | |
9b840a86 PT |
141 | * Sets the background RGB value. If the argument is null the default system |
142 | * color will be used. | |
d5efe032 | 143 | * |
9b840a86 PT |
144 | * @param background |
145 | * the background to set, or null | |
d5efe032 | 146 | */ |
9b840a86 | 147 | public void setBackgroundRGB(@Nullable RGB background) { |
d5efe032 | 148 | fBackgroundRGB = background; |
9b840a86 PT |
149 | if (fBackgroundColor != null) { |
150 | fBackgroundColor.dispose(); | |
151 | } | |
152 | if (fDimmedBackgroundColor != null) { | |
153 | fDimmedBackgroundColor.dispose(); | |
154 | } | |
155 | if (fDimmedForegroundColor != null) { | |
156 | fDimmedForegroundColor.dispose(); | |
157 | } | |
d5efe032 | 158 | Display display = Display.getDefault(); |
9b840a86 PT |
159 | fBackgroundColor = (fBackgroundRGB != null) ? new Color(display, fBackgroundRGB) : null; |
160 | fDimmedBackgroundColor = (fBackgroundRGB == null) ? null : new Color(display, ColorUtil.blend( | |
d5efe032 | 161 | fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB())); |
9b840a86 PT |
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())); | |
d5efe032 AF |
165 | } |
166 | ||
167 | /** | |
168 | * Returns the RGB of the tick color | |
169 | * | |
170 | * @return the RGB of the tick color | |
171 | */ | |
9b840a86 | 172 | public @NonNull RGB getTickColorRGB() { |
d5efe032 AF |
173 | return fTickColorRGB; |
174 | } | |
175 | ||
176 | /** | |
177 | * Sets the RGB of the tick color | |
178 | * | |
9b840a86 PT |
179 | * @param tickColorRGB |
180 | * the tick color TGB | |
d5efe032 | 181 | */ |
9b840a86 PT |
182 | public void setTickColorRGB(@NonNull RGB tickColorRGB) { |
183 | fTickColorRGB = tickColorRGB; | |
184 | fTickColor.dispose(); | |
185 | Display display = Display.getDefault(); | |
186 | fTickColor = new Color(display, fTickColorRGB); | |
d5efe032 AF |
187 | } |
188 | ||
189 | /** | |
190 | * Returns the filter implementation. | |
9b840a86 PT |
191 | * |
192 | * @return the filter, or null | |
d5efe032 | 193 | */ |
9b840a86 | 194 | public @Nullable ITmfFilterTreeNode getFilter() { |
d5efe032 AF |
195 | return fFilter; |
196 | } | |
197 | ||
198 | /** | |
199 | * Sets the filter implementation. | |
200 | * | |
9b840a86 PT |
201 | * @param filter |
202 | * the filter to set, or null | |
d5efe032 | 203 | */ |
9b840a86 | 204 | public void setFilter(@Nullable ITmfFilterTreeNode filter) { |
d5efe032 AF |
205 | fFilter = filter; |
206 | } | |
207 | ||
208 | /** | |
9b840a86 PT |
209 | * Returns the foreground color, or null if the default system color is |
210 | * used. | |
d5efe032 | 211 | * |
9b840a86 | 212 | * @return the foreground color, or null |
d5efe032 | 213 | */ |
9b840a86 | 214 | public @Nullable Color getForegroundColor() { |
d5efe032 AF |
215 | return fForegroundColor; |
216 | } | |
217 | ||
218 | /** | |
9b840a86 PT |
219 | * Returns the background color, or null if the default system color is |
220 | * used. | |
d5efe032 | 221 | * |
9b840a86 | 222 | * @return the background color, or null |
d5efe032 | 223 | */ |
9b840a86 | 224 | public @Nullable Color getBackgroundColor() { |
d5efe032 AF |
225 | return fBackgroundColor; |
226 | } | |
227 | ||
228 | /** | |
9b840a86 PT |
229 | * Returns the dimmed foreground color, or null if the default system color |
230 | * is used. | |
d5efe032 | 231 | * |
9b840a86 | 232 | * @return the dimmed foreground color, or null |
d5efe032 | 233 | */ |
9b840a86 | 234 | public @Nullable Color getDimmedForegroundColor() { |
d5efe032 AF |
235 | return fDimmedForegroundColor; |
236 | } | |
237 | ||
238 | /** | |
9b840a86 PT |
239 | * Returns the dimmed background color, or null if the default system color |
240 | * is used. | |
d5efe032 | 241 | * |
9b840a86 | 242 | * @return the dimmed background color, or null |
d5efe032 | 243 | */ |
9b840a86 | 244 | public @Nullable Color getDimmedBackgroundColor() { |
d5efe032 AF |
245 | return fDimmedBackgroundColor; |
246 | } | |
247 | ||
248 | /** | |
249 | * Returns the tick color. | |
250 | * | |
251 | * @return the tick color | |
252 | */ | |
253 | public Color getTickColor() { | |
be222f56 PT |
254 | return fTickColor; |
255 | } | |
256 | } |