1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 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
.linuxtools
.tmf
.ui
.views
.colors
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.graphics
.Color
;
19 import org
.eclipse
.swt
.graphics
.RGB
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.ui
.themes
.ColorUtil
;
24 * Class for storing color settings of a TMF filter.
26 * Application code must explicitly invoke the ColorSetting.dispose() method to release the operating system
27 * resources managed by each instance when those instances are no longer required.
30 * @author Patrick Tasse
32 public class ColorSetting
{
34 private RGB fForegroundRGB
;
35 private RGB fBackgroundRGB
;
36 private RGB fTickColorRGB
;
37 private Color fForegroundColor
;
38 private Color fBackgroundColor
;
39 private Color fDimmedForegroundColor
;
40 private Color fDimmedBackgroundColor
;
41 private Color fTickColor
;
42 private ITmfFilterTreeNode fFilter
;
47 * You must dispose the color setting when it is no longer required.
50 * The foreground color
52 * The background color
54 * The color for the checkbox ticks
56 * The filter tree node
58 public ColorSetting(RGB foreground
, RGB background
, RGB tickColorRGB
, ITmfFilterTreeNode filter
) {
59 fForegroundRGB
= foreground
;
60 fBackgroundRGB
= background
;
61 fTickColorRGB
= tickColorRGB
;
63 Display display
= Display
.getDefault();
64 fForegroundColor
= new Color(display
, fForegroundRGB
);
65 fBackgroundColor
= new Color(display
, fBackgroundRGB
);
66 fDimmedForegroundColor
= new Color(display
, ColorUtil
.blend(
67 fForegroundRGB
, fBackgroundRGB
));
68 fDimmedBackgroundColor
= new Color(display
, ColorUtil
.blend(
69 fBackgroundRGB
, display
.getSystemColor(SWT
.COLOR_LIST_BACKGROUND
).getRGB()));
70 fTickColor
= new Color(display
, fTickColorRGB
);
74 * Dispose the color setting resources
76 public void dispose() {
77 fForegroundColor
.dispose();
78 fBackgroundColor
.dispose();
79 fDimmedForegroundColor
.dispose();
80 fDimmedBackgroundColor
.dispose();
85 * Returns foreground RGB value.
87 * @return the foreground RGB
89 public RGB
getForegroundRGB() {
90 return fForegroundRGB
;
94 * Sets the foreground RGB value
96 * @param foreground the foreground to set
98 public void setForegroundRGB(RGB foreground
) {
99 fForegroundRGB
= foreground
;
100 fForegroundColor
.dispose();
101 fDimmedForegroundColor
.dispose();
102 Display display
= Display
.getDefault();
103 fForegroundColor
= new Color(display
, fForegroundRGB
);
104 fDimmedForegroundColor
= new Color(display
, ColorUtil
.blend(
105 fForegroundRGB
, fBackgroundRGB
));
109 * Returns the background RGB value.
111 * @return the background RGB
113 public RGB
getBackgroundRGB() {
114 return fBackgroundRGB
;
118 * Sets the background RGB value.
120 * @param background the background to set
122 public void setBackgroundRGB(RGB background
) {
123 fBackgroundRGB
= background
;
124 fBackgroundColor
.dispose();
125 fDimmedBackgroundColor
.dispose();
126 Display display
= Display
.getDefault();
127 fBackgroundColor
= new Color(display
, fBackgroundRGB
);
128 fDimmedBackgroundColor
= new Color(display
, ColorUtil
.blend(
129 fBackgroundRGB
, display
.getSystemColor(SWT
.COLOR_LIST_BACKGROUND
).getRGB()));
133 * Returns the RGB of the tick color
135 * @return the RGB of the tick color
137 public RGB
getTickColorRGB() {
138 return fTickColorRGB
;
142 * Sets the RGB of the tick color
144 * @param tickColorRGB the tick color TGB
146 public void setTickColorRGB(RGB tickColorRGB
) {
147 fTickColorRGB
= tickColorRGB
;
148 fTickColor
.dispose();
149 Display display
= Display
.getDefault();
150 fTickColor
= new Color(display
, fTickColorRGB
);
154 * Returns the filter implementation.
157 public ITmfFilterTreeNode
getFilter() {
162 * Sets the filter implementation.
164 * @param filter the filter to set
166 public void setFilter(ITmfFilterTreeNode filter
) {
171 * Returns the foreground color.
173 * @return the foreground color
175 public Color
getForegroundColor() {
176 return fForegroundColor
;
180 * Returns the background color.
182 * @return the background color
184 public Color
getBackgroundColor() {
185 return fBackgroundColor
;
189 * Returns the dimmed foreground color.
191 * @return the dimmed foreground color
193 public Color
getDimmedForegroundColor() {
194 return fDimmedForegroundColor
;
198 * Returns the dimmed background color.
200 * @return the dimmed background color
202 public Color
getDimmedBackgroundColor() {
203 return fDimmedBackgroundColor
;
207 * Returns the tick color.
209 * @return the tick color
211 public Color
getTickColor() {