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
CommitLineData
ce62370f
FC
1/*******************************************************************************\r
2 * Copyright (c) 2010 Ericsson\r
3 * \r
4 * All rights reserved. This program and the accompanying materials are\r
5 * made available under the terms of the Eclipse Public License v1.0 which\r
6 * accompanies this distribution, and is available at\r
7 * http://www.eclipse.org/legal/epl-v10.html\r
8 * \r
9 * Contributors:\r
10 * Patrick Tasse - Initial API and implementation\r
11 *******************************************************************************/\r
12\r
13package org.eclipse.linuxtools.tmf.ui.views.timechart;\r
14\r
15import java.util.Map;\r
16\r
ce62370f 17import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;\r
eee04af0
PT
18import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;\r
19import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;\r
2fa130b8 20import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
fb5cad3d 21import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
ce62370f
FC
22import org.eclipse.swt.SWT;\r
23import org.eclipse.swt.graphics.Color;\r
24import org.eclipse.swt.graphics.GC;\r
eee04af0 25import org.eclipse.swt.graphics.RGB;\r
ce62370f
FC
26import org.eclipse.swt.graphics.Rectangle;\r
27import org.eclipse.swt.widgets.Display;\r
eee04af0 28import org.eclipse.ui.themes.ColorUtil;\r
ce62370f 29\r
eee04af0
PT
30public class TimeChartAnalysisProvider extends TimeGraphPresentationProvider {\r
31\r
32 private static final Color BOOKMARK_INNER_COLOR = new Color(Display.getDefault(), 115, 165, 224);\r
33 private static final Color BOOKMARK_OUTER_COLOR = new Color(Display.getDefault(), 2, 70, 140);\r
34 private static final Color SEARCH_MATCH_COLOR = new Color(Display.getDefault(), 177, 118, 14);\r
35\r
36 private int lastX = Integer.MIN_VALUE;\r
37 private int currX = Integer.MIN_VALUE;\r
38 private int lastPriority;\r
39 private int lastBookmarkX = Integer.MIN_VALUE;\r
ce62370f 40\r
ce62370f 41 @Override\r
eee04af0
PT
42 public StateItem[] getStateTable() {\r
43 return new StateItem[] {\r
44 new StateItem(new RGB(100, 100, 100)), \r
45 new StateItem(new RGB(174, 200, 124)),\r
46 new StateItem(ColorUtil.blend(Display.getDefault().getSystemColor(SWT.COLOR_BLUE).getRGB(), Display.getDefault().getSystemColor(SWT.COLOR_GRAY).getRGB())),\r
47 new StateItem(new RGB(210, 150, 60)),\r
48 new StateItem(new RGB(242, 225, 168)),\r
49 new StateItem(ColorUtil.blend(Display.getDefault().getSystemColor(SWT.COLOR_RED).getRGB(), Display.getDefault().getSystemColor(SWT.COLOR_GRAY).getRGB())),\r
50 new StateItem(new RGB(200, 200, 200)),\r
51 new StateItem(new RGB(35, 107, 42)),\r
52 new StateItem(new RGB(205,205,0)),\r
53 new StateItem(new RGB(205, 0, 205)),\r
54 new StateItem(new RGB(171, 130, 255)),\r
55 new StateItem(new RGB(255, 181, 197)),\r
56 new StateItem(new RGB(112, 219, 147)),\r
57 new StateItem(new RGB(198, 226, 255)),\r
58 new StateItem(new RGB(95, 158, 160)),\r
59 new StateItem(new RGB(107, 142, 35))\r
60 };\r
ce62370f
FC
61 }\r
62\r
63 @Override\r
eee04af0
PT
64 public int getEventTableIndex(ITimeEvent event) {\r
65 int priority = ((TimeChartEvent) event).getColorSettingPriority();\r
66 if (currX == lastX) {\r
67 priority = Math.min(priority, lastPriority);\r
68 }\r
69 lastPriority = priority;\r
70 return ColorSettingsManager.getColorSetting(priority).getTickColorIndex();\r
ce62370f
FC
71 }\r
72\r
eee04af0 73 @Override\r
fb5cad3d 74 public String getTraceClassName(ITimeGraphEntry entry) {\r
ce62370f
FC
75 return null;\r
76 }\r
77\r
78 @Override\r
eee04af0 79 public String getEventName(ITimeEvent event) {\r
ce62370f
FC
80 return null;\r
81 }\r
82\r
83 @Override\r
84 public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {\r
85 return null;\r
86 }\r
87\r
88 @Override\r
eee04af0
PT
89 public void postDrawEvent(ITimeEvent event, Rectangle rect, GC gc) {\r
90 if (! ((TimeChartEvent) event).isVisible()) {\r
91 return;\r
92 }\r
93 lastX = currX;\r
94 currX = rect.x;\r
95 if (lastBookmarkX == rect.x || ((TimeChartEvent) event).isBookmarked()) {\r
96 drawBookmark(rect, gc);\r
97 lastBookmarkX = rect.x;\r
98 } else if (lastBookmarkX == rect.x - 1) {\r
99 Rectangle r = new Rectangle(lastBookmarkX, rect.y, rect.width, rect.height);\r
100 drawBookmark(r, gc);\r
101 } else {\r
102 lastBookmarkX = Integer.MIN_VALUE;\r
103 }\r
104 if (((TimeChartEvent) event).isSearchMatch()) {\r
105 drawSearchMatch(rect, gc);\r
106 }\r
ce62370f
FC
107 }\r
108\r
109 private void drawBookmark(Rectangle r, GC gc) {\r
eee04af0
PT
110 gc.setForeground(BOOKMARK_OUTER_COLOR);\r
111 gc.drawLine(r.x - 1, r.y - 2, r.x - 1, r.y + 2);\r
112 gc.drawLine(r.x + 1, r.y - 2, r.x + 1, r.y + 2);\r
113 gc.drawPoint(r.x, r.y - 2);\r
114 gc.setForeground(BOOKMARK_INNER_COLOR);\r
115 gc.drawLine(r.x, r.y - 1, r.x, r.y + 1);\r
116 gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));\r
117 gc.drawPoint(r.x - 1, r.y + 3);\r
118 gc.drawPoint(r.x, r.y + 2);\r
119 gc.drawPoint(r.x + 1, r.y + 3);\r
ce62370f 120 }\r
eee04af0 121\r
ce62370f 122 private void drawSearchMatch(Rectangle r, GC gc) {\r
eee04af0
PT
123 gc.setForeground(SEARCH_MATCH_COLOR);\r
124 gc.drawPoint(r.x, r.y + r.height);\r
125 gc.drawLine(r.x - 1, r.y + r.height + 1, r.x + 1, r.y + r.height + 1);\r
126 gc.drawLine(r.x - 2, r.y + r.height + 2, r.x + 2, r.y + r.height + 2);\r
ce62370f
FC
127 }\r
128}\r
This page took 0.048761 seconds and 5 git commands to generate.