Commit | Line | Data |
---|---|---|
ce62370f FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
013a5f1c | 3 | *\r |
ce62370f FC |
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 | |
013a5f1c | 8 | *\r |
ce62370f FC |
9 | * Contributors:\r |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
13 | package org.eclipse.linuxtools.tmf.ui.views.timechart;\r | |
14 | \r | |
0edc9535 | 15 | import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting;\r |
ce62370f | 16 | import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;\r |
b83af2c3 PT |
17 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;\r |
18 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;\r | |
2fa130b8 | 19 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r |
ce62370f FC |
20 | import org.eclipse.swt.SWT;\r |
21 | import org.eclipse.swt.graphics.Color;\r | |
22 | import org.eclipse.swt.graphics.GC;\r | |
23 | import org.eclipse.swt.graphics.Rectangle;\r | |
24 | import org.eclipse.swt.widgets.Display;\r | |
25 | \r | |
013a5f1c AM |
26 | /**\r |
27 | * Provider for a time chart analysis view\r | |
28 | *\r | |
29 | * @version 1.0\r | |
30 | * @author Patrick Tasse\r | |
31 | */\r | |
b83af2c3 PT |
32 | public class TimeChartAnalysisProvider extends TimeGraphPresentationProvider {\r |
33 | \r | |
34 | private static final Color BOOKMARK_INNER_COLOR = new Color(Display.getDefault(), 115, 165, 224);\r | |
35 | private static final Color BOOKMARK_OUTER_COLOR = new Color(Display.getDefault(), 2, 70, 140);\r | |
36 | private static final Color SEARCH_MATCH_COLOR = new Color(Display.getDefault(), 177, 118, 14);\r | |
37 | \r | |
38 | private int lastX = Integer.MIN_VALUE;\r | |
39 | private int currX = Integer.MIN_VALUE;\r | |
40 | private int lastPriority;\r | |
41 | private int lastBookmarkX = Integer.MIN_VALUE;\r | |
ce62370f | 42 | \r |
ce62370f | 43 | @Override\r |
b83af2c3 | 44 | public StateItem[] getStateTable() {\r |
013a5f1c | 45 | \r |
0edc9535 BH |
46 | ColorSetting[] settings = ColorSettingsManager.getColorSettings();\r |
47 | StateItem[] stateItems = new StateItem[settings.length];\r | |
48 | for (int i = 0; i < settings.length; i++) {\r | |
49 | stateItems[i] = new StateItem(settings[i].getTickColorRGB());\r | |
50 | }\r | |
51 | return stateItems;\r | |
ce62370f FC |
52 | }\r |
53 | \r | |
54 | @Override\r | |
549f3c43 | 55 | public int getStateTableIndex(ITimeEvent event) {\r |
b83af2c3 PT |
56 | int priority = ((TimeChartEvent) event).getColorSettingPriority();\r |
57 | if (currX == lastX) {\r | |
58 | priority = Math.min(priority, lastPriority);\r | |
59 | }\r | |
60 | lastPriority = priority;\r | |
0edc9535 | 61 | return priority;\r |
ce62370f FC |
62 | }\r |
63 | \r | |
ce62370f | 64 | @Override\r |
b83af2c3 PT |
65 | public void postDrawEvent(ITimeEvent event, Rectangle rect, GC gc) {\r |
66 | if (! ((TimeChartEvent) event).isVisible()) {\r | |
67 | return;\r | |
68 | }\r | |
69 | lastX = currX;\r | |
70 | currX = rect.x;\r | |
71 | if (lastBookmarkX == rect.x || ((TimeChartEvent) event).isBookmarked()) {\r | |
72 | drawBookmark(rect, gc);\r | |
73 | lastBookmarkX = rect.x;\r | |
74 | } else if (lastBookmarkX == rect.x - 1) {\r | |
75 | Rectangle r = new Rectangle(lastBookmarkX, rect.y, rect.width, rect.height);\r | |
76 | drawBookmark(r, gc);\r | |
77 | } else {\r | |
78 | lastBookmarkX = Integer.MIN_VALUE;\r | |
79 | }\r | |
80 | if (((TimeChartEvent) event).isSearchMatch()) {\r | |
81 | drawSearchMatch(rect, gc);\r | |
82 | }\r | |
ce62370f FC |
83 | }\r |
84 | \r | |
abbdd66a | 85 | private static void drawBookmark(Rectangle r, GC gc) {\r |
b83af2c3 PT |
86 | gc.setForeground(BOOKMARK_OUTER_COLOR);\r |
87 | gc.drawLine(r.x - 1, r.y - 2, r.x - 1, r.y + 2);\r | |
88 | gc.drawLine(r.x + 1, r.y - 2, r.x + 1, r.y + 2);\r | |
89 | gc.drawPoint(r.x, r.y - 2);\r | |
90 | gc.setForeground(BOOKMARK_INNER_COLOR);\r | |
91 | gc.drawLine(r.x, r.y - 1, r.x, r.y + 1);\r | |
92 | gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));\r | |
93 | gc.drawPoint(r.x - 1, r.y + 3);\r | |
94 | gc.drawPoint(r.x, r.y + 2);\r | |
95 | gc.drawPoint(r.x + 1, r.y + 3);\r | |
ce62370f | 96 | }\r |
b83af2c3 | 97 | \r |
abbdd66a | 98 | private static void drawSearchMatch(Rectangle r, GC gc) {\r |
b83af2c3 PT |
99 | gc.setForeground(SEARCH_MATCH_COLOR);\r |
100 | gc.drawPoint(r.x, r.y + r.height);\r | |
101 | gc.drawLine(r.x - 1, r.y + r.height + 1, r.x + 1, r.y + r.height + 1);\r | |
102 | gc.drawLine(r.x - 2, r.y + r.height + 2, r.x + 2, r.y + r.height + 2);\r | |
ce62370f FC |
103 | }\r |
104 | }\r |