Bug 378401: Implementation of time graph widget.
[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 java.util.Map;
16
17 import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;
18 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
19 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
20 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
21 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.graphics.Color;
24 import org.eclipse.swt.graphics.GC;
25 import org.eclipse.swt.graphics.RGB;
26 import org.eclipse.swt.graphics.Rectangle;
27 import org.eclipse.swt.widgets.Display;
28 import org.eclipse.ui.themes.ColorUtil;
29
30 public class TimeChartAnalysisProvider extends TimeGraphPresentationProvider {
31
32 private static final Color BOOKMARK_INNER_COLOR = new Color(Display.getDefault(), 115, 165, 224);
33 private static final Color BOOKMARK_OUTER_COLOR = new Color(Display.getDefault(), 2, 70, 140);
34 private static final Color SEARCH_MATCH_COLOR = new Color(Display.getDefault(), 177, 118, 14);
35
36 private int lastX = Integer.MIN_VALUE;
37 private int currX = Integer.MIN_VALUE;
38 private int lastPriority;
39 private int lastBookmarkX = Integer.MIN_VALUE;
40
41 @Override
42 public StateItem[] getStateTable() {
43 return new StateItem[] {
44 new StateItem(new RGB(100, 100, 100)),
45 new StateItem(new RGB(174, 200, 124)),
46 new StateItem(ColorUtil.blend(Display.getDefault().getSystemColor(SWT.COLOR_BLUE).getRGB(), Display.getDefault().getSystemColor(SWT.COLOR_GRAY).getRGB())),
47 new StateItem(new RGB(210, 150, 60)),
48 new StateItem(new RGB(242, 225, 168)),
49 new StateItem(ColorUtil.blend(Display.getDefault().getSystemColor(SWT.COLOR_RED).getRGB(), Display.getDefault().getSystemColor(SWT.COLOR_GRAY).getRGB())),
50 new StateItem(new RGB(200, 200, 200)),
51 new StateItem(new RGB(35, 107, 42)),
52 new StateItem(new RGB(205,205,0)),
53 new StateItem(new RGB(205, 0, 205)),
54 new StateItem(new RGB(171, 130, 255)),
55 new StateItem(new RGB(255, 181, 197)),
56 new StateItem(new RGB(112, 219, 147)),
57 new StateItem(new RGB(198, 226, 255)),
58 new StateItem(new RGB(95, 158, 160)),
59 new StateItem(new RGB(107, 142, 35))
60 };
61 }
62
63 @Override
64 public int getEventTableIndex(ITimeEvent event) {
65 int priority = ((TimeChartEvent) event).getColorSettingPriority();
66 if (currX == lastX) {
67 priority = Math.min(priority, lastPriority);
68 }
69 lastPriority = priority;
70 return ColorSettingsManager.getColorSetting(priority).getTickColorIndex();
71 }
72
73 @Override
74 public String getTraceClassName(ITimeGraphEntry entry) {
75 return null;
76 }
77
78 @Override
79 public String getEventName(ITimeEvent event) {
80 return null;
81 }
82
83 @Override
84 public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {
85 return null;
86 }
87
88 @Override
89 public void postDrawEvent(ITimeEvent event, Rectangle rect, GC gc) {
90 if (! ((TimeChartEvent) event).isVisible()) {
91 return;
92 }
93 lastX = currX;
94 currX = rect.x;
95 if (lastBookmarkX == rect.x || ((TimeChartEvent) event).isBookmarked()) {
96 drawBookmark(rect, gc);
97 lastBookmarkX = rect.x;
98 } else if (lastBookmarkX == rect.x - 1) {
99 Rectangle r = new Rectangle(lastBookmarkX, rect.y, rect.width, rect.height);
100 drawBookmark(r, gc);
101 } else {
102 lastBookmarkX = Integer.MIN_VALUE;
103 }
104 if (((TimeChartEvent) event).isSearchMatch()) {
105 drawSearchMatch(rect, gc);
106 }
107 }
108
109 private void drawBookmark(Rectangle r, GC gc) {
110 gc.setForeground(BOOKMARK_OUTER_COLOR);
111 gc.drawLine(r.x - 1, r.y - 2, r.x - 1, r.y + 2);
112 gc.drawLine(r.x + 1, r.y - 2, r.x + 1, r.y + 2);
113 gc.drawPoint(r.x, r.y - 2);
114 gc.setForeground(BOOKMARK_INNER_COLOR);
115 gc.drawLine(r.x, r.y - 1, r.x, r.y + 1);
116 gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
117 gc.drawPoint(r.x - 1, r.y + 3);
118 gc.drawPoint(r.x, r.y + 2);
119 gc.drawPoint(r.x + 1, r.y + 3);
120 }
121
122 private void drawSearchMatch(Rectangle r, GC gc) {
123 gc.setForeground(SEARCH_MATCH_COLOR);
124 gc.drawPoint(r.x, r.y + r.height);
125 gc.drawLine(r.x - 1, r.y + r.height + 1, r.x + 1, r.y + r.height + 1);
126 gc.drawLine(r.x - 2, r.y + r.height + 2, r.x + 2, r.y + r.height + 2);
127 }
128 }
This page took 0.035522 seconds and 6 git commands to generate.