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