1 /*******************************************************************************
2 * Copyright (c) 2010 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Arrays
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.widgets
.TraceColorScheme
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.widgets
.Display
;
24 public class ColorSettingsManager
{
26 private static final String COLOR_SETTINGS_FILE_NAME
= "color_settings.xml"; //$NON-NLS-1$
27 private static final String COLOR_SETTINGS_PATH_NAME
=
28 TmfUiPlugin
.getDefault().getStateLocation().addTrailingSeparator().append(COLOR_SETTINGS_FILE_NAME
).toString();
29 private static final ColorSetting DEFAULT_COLOR_SETTING
= new ColorSetting(
30 Display
.getDefault().getSystemColor(SWT
.COLOR_LIST_FOREGROUND
).getRGB(),
31 Display
.getDefault().getSystemColor(SWT
.COLOR_LIST_BACKGROUND
).getRGB(),
32 TraceColorScheme
.BLACK_STATE
,
34 public static final int PRIORITY_NONE
= Integer
.MAX_VALUE
;
36 private static ColorSetting
[] fColorSettings
= ColorSettingsXML
.load(COLOR_SETTINGS_PATH_NAME
);
37 private static ArrayList
<IColorSettingsListener
> fListeners
= new ArrayList
<IColorSettingsListener
>();
39 public static ColorSetting
[] getColorSettings() {
40 return (fColorSettings
!= null) ? Arrays
.copyOf(fColorSettings
, fColorSettings
.length
) : null;
43 public static void setColorSettings(ColorSetting
[] colorSettings
) {
44 fColorSettings
= (colorSettings
!= null) ? Arrays
.copyOf(colorSettings
, colorSettings
.length
) : null;
45 ColorSettingsXML
.save(COLOR_SETTINGS_PATH_NAME
, fColorSettings
);
46 fireColorSettingsChanged();
49 public static ColorSetting
getColorSetting(ITmfEvent event
) {
50 for (int i
= 0; i
< fColorSettings
.length
; i
++) {
51 ColorSetting colorSetting
= fColorSettings
[i
];
52 if (colorSetting
.getFilter() != null && colorSetting
.getFilter().matches(event
)) {
56 return DEFAULT_COLOR_SETTING
;
59 public static int getColorSettingPriority(ITmfEvent event
) {
60 for (int i
= 0; i
< fColorSettings
.length
; i
++) {
61 ColorSetting colorSetting
= fColorSettings
[i
];
62 if (colorSetting
.getFilter() != null && colorSetting
.getFilter().matches(event
)) {
69 public static ColorSetting
getColorSetting(int priority
) {
70 if (priority
< fColorSettings
.length
) {
71 return fColorSettings
[priority
];
73 return DEFAULT_COLOR_SETTING
;
76 public static void addColorSettingsListener(IColorSettingsListener listener
) {
77 if (! fListeners
.contains(listener
)) {
78 fListeners
.add(listener
);
82 public static void removeColorSettingsListener(IColorSettingsListener listener
) {
83 fListeners
.remove(listener
);
86 private static void fireColorSettingsChanged() {
87 for (IColorSettingsListener listener
: fListeners
) {
88 listener
.colorSettingsChanged(fColorSettings
);