Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / colors / ColorSettingsManager.java
1 /*******************************************************************************
2 * Copyright (c) 2010 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 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.colors;
14
15 import java.util.ArrayList;
16
17 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
18 import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;
19 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TraceColorScheme;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.widgets.Display;
22
23 public class ColorSettingsManager {
24
25 private static final String COLOR_SETTINGS_FILE_NAME = "color_settings.xml"; //$NON-NLS-1$
26 private static final String COLOR_SETTINGS_PATH_NAME =
27 TmfUiPlugin.getDefault().getStateLocation().addTrailingSeparator().append(COLOR_SETTINGS_FILE_NAME).toString();
28 private static final ColorSetting DEFAULT_COLOR_SETTING = new ColorSetting(
29 Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
30 Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(),
31 TraceColorScheme.BLACK_STATE,
32 null);
33 public static final int PRIORITY_NONE = Integer.MAX_VALUE;
34
35 private static ColorSetting[] fColorSettings = ColorSettingsXML.load(COLOR_SETTINGS_PATH_NAME);
36 private static ArrayList<IColorSettingsListener> fListeners = new ArrayList<IColorSettingsListener>();
37
38 public static ColorSetting[] getColorSettings() {
39 return fColorSettings;
40 }
41
42 public static void setColorSettings(ColorSetting[] colorSettings) {
43 fColorSettings = colorSettings;
44 ColorSettingsXML.save(COLOR_SETTINGS_PATH_NAME, fColorSettings);
45 fireColorSettingsChanged();
46 }
47
48 public static ColorSetting getColorSetting(TmfEvent event) {
49 for (int i = 0; i < fColorSettings.length; i++) {
50 ColorSetting colorSetting = fColorSettings[i];
51 if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) {
52 return colorSetting;
53 }
54 }
55 return DEFAULT_COLOR_SETTING;
56 }
57
58 public static int getColorSettingPriority(TmfEvent event) {
59 for (int i = 0; i < fColorSettings.length; i++) {
60 ColorSetting colorSetting = fColorSettings[i];
61 if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) {
62 return i;
63 }
64 }
65 return PRIORITY_NONE;
66 }
67
68 public static ColorSetting getColorSetting(int priority) {
69 if (priority < fColorSettings.length) {
70 return fColorSettings[priority];
71 }
72 return DEFAULT_COLOR_SETTING;
73 }
74
75 public static void addColorSettingsListener(IColorSettingsListener listener) {
76 if (! fListeners.contains(listener)) {
77 fListeners.add(listener);
78 }
79 }
80
81 public static void removeColorSettingsListener(IColorSettingsListener listener) {
82 fListeners.remove(listener);
83 }
84
85 private static void fireColorSettingsChanged() {
86 for (IColorSettingsListener listener : fListeners) {
87 listener.colorSettingsChanged(fColorSettings);
88 }
89 }
90 }
This page took 0.041726 seconds and 5 git commands to generate.