Fix for bug 380944 (color mapping in ColorView/TimeChartView)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / timechart / TimeChartAnalysisProvider.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.timechart;
14
15 import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting;
16 import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;
17 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
18 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
19 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.graphics.Color;
22 import org.eclipse.swt.graphics.GC;
23 import org.eclipse.swt.graphics.RGB;
24 import org.eclipse.swt.graphics.Rectangle;
25 import org.eclipse.swt.widgets.Display;
26 import org.eclipse.ui.themes.ColorUtil;
27
28 public class TimeChartAnalysisProvider extends TimeGraphPresentationProvider {
29
30 private static final Color BOOKMARK_INNER_COLOR = new Color(Display.getDefault(), 115, 165, 224);
31 private static final Color BOOKMARK_OUTER_COLOR = new Color(Display.getDefault(), 2, 70, 140);
32 private static final Color SEARCH_MATCH_COLOR = new Color(Display.getDefault(), 177, 118, 14);
33
34 private int lastX = Integer.MIN_VALUE;
35 private int currX = Integer.MIN_VALUE;
36 private int lastPriority;
37 private int lastBookmarkX = Integer.MIN_VALUE;
38
39 @Override
40 public StateItem[] getStateTable() {
41
42 ColorSetting[] settings = ColorSettingsManager.getColorSettings();
43 StateItem[] stateItems = new StateItem[settings.length];
44 for (int i = 0; i < settings.length; i++) {
45 stateItems[i] = new StateItem(settings[i].getTickColorRGB());
46 }
47 return stateItems;
48 }
49
50 @Override
51 public int getStateTableIndex(ITimeEvent event) {
52 int priority = ((TimeChartEvent) event).getColorSettingPriority();
53 if (currX == lastX) {
54 priority = Math.min(priority, lastPriority);
55 }
56 lastPriority = priority;
57 return priority;
58 }
59
60 @Override
61 public void postDrawEvent(ITimeEvent event, Rectangle rect, GC gc) {
62 if (! ((TimeChartEvent) event).isVisible()) {
63 return;
64 }
65 lastX = currX;
66 currX = rect.x;
67 if (lastBookmarkX == rect.x || ((TimeChartEvent) event).isBookmarked()) {
68 drawBookmark(rect, gc);
69 lastBookmarkX = rect.x;
70 } else if (lastBookmarkX == rect.x - 1) {
71 Rectangle r = new Rectangle(lastBookmarkX, rect.y, rect.width, rect.height);
72 drawBookmark(r, gc);
73 } else {
74 lastBookmarkX = Integer.MIN_VALUE;
75 }
76 if (((TimeChartEvent) event).isSearchMatch()) {
77 drawSearchMatch(rect, gc);
78 }
79 }
80
81 private void drawBookmark(Rectangle r, GC gc) {
82 gc.setForeground(BOOKMARK_OUTER_COLOR);
83 gc.drawLine(r.x - 1, r.y - 2, r.x - 1, r.y + 2);
84 gc.drawLine(r.x + 1, r.y - 2, r.x + 1, r.y + 2);
85 gc.drawPoint(r.x, r.y - 2);
86 gc.setForeground(BOOKMARK_INNER_COLOR);
87 gc.drawLine(r.x, r.y - 1, r.x, r.y + 1);
88 gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
89 gc.drawPoint(r.x - 1, r.y + 3);
90 gc.drawPoint(r.x, r.y + 2);
91 gc.drawPoint(r.x + 1, r.y + 3);
92 }
93
94 private void drawSearchMatch(Rectangle r, GC gc) {
95 gc.setForeground(SEARCH_MATCH_COLOR);
96 gc.drawPoint(r.x, r.y + r.height);
97 gc.drawLine(r.x - 1, r.y + r.height + 1, r.x + 1, r.y + r.height + 1);
98 gc.drawLine(r.x - 2, r.y + r.height + 2, r.x + 2, r.y + r.height + 2);
99 }
100 }
This page took 0.032559 seconds and 6 git commands to generate.