1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.timechart
;
15 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
16 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.graphics
.Color
;
21 import org
.eclipse
.swt
.graphics
.GC
;
22 import org
.eclipse
.swt
.graphics
.RGB
;
23 import org
.eclipse
.swt
.graphics
.Rectangle
;
24 import org
.eclipse
.swt
.widgets
.Display
;
25 import org
.eclipse
.ui
.themes
.ColorUtil
;
27 public class TimeChartAnalysisProvider
extends TimeGraphPresentationProvider
{
29 private static final Color BOOKMARK_INNER_COLOR
= new Color(Display
.getDefault(), 115, 165, 224);
30 private static final Color BOOKMARK_OUTER_COLOR
= new Color(Display
.getDefault(), 2, 70, 140);
31 private static final Color SEARCH_MATCH_COLOR
= new Color(Display
.getDefault(), 177, 118, 14);
33 private int lastX
= Integer
.MIN_VALUE
;
34 private int currX
= Integer
.MIN_VALUE
;
35 private int lastPriority
;
36 private int lastBookmarkX
= Integer
.MIN_VALUE
;
39 public StateItem
[] getStateTable() {
40 return new StateItem
[] {
41 new StateItem(new RGB(100, 100, 100)),
42 new StateItem(new RGB(174, 200, 124)),
43 new StateItem(ColorUtil
.blend(Display
.getDefault().getSystemColor(SWT
.COLOR_BLUE
).getRGB(), Display
.getDefault().getSystemColor(SWT
.COLOR_GRAY
).getRGB())),
44 new StateItem(new RGB(210, 150, 60)),
45 new StateItem(new RGB(242, 225, 168)),
46 new StateItem(ColorUtil
.blend(Display
.getDefault().getSystemColor(SWT
.COLOR_RED
).getRGB(), Display
.getDefault().getSystemColor(SWT
.COLOR_GRAY
).getRGB())),
47 new StateItem(new RGB(200, 200, 200)),
48 new StateItem(new RGB(35, 107, 42)),
49 new StateItem(new RGB(205,205,0)),
50 new StateItem(new RGB(205, 0, 205)),
51 new StateItem(new RGB(171, 130, 255)),
52 new StateItem(new RGB(255, 181, 197)),
53 new StateItem(new RGB(112, 219, 147)),
54 new StateItem(new RGB(198, 226, 255)),
55 new StateItem(new RGB(95, 158, 160)),
56 new StateItem(new RGB(107, 142, 35))
61 public int getStateTableIndex(ITimeEvent event
) {
62 int priority
= ((TimeChartEvent
) event
).getColorSettingPriority();
64 priority
= Math
.min(priority
, lastPriority
);
66 lastPriority
= priority
;
67 return ColorSettingsManager
.getColorSetting(priority
).getTickColorIndex();
71 public void postDrawEvent(ITimeEvent event
, Rectangle rect
, GC gc
) {
72 if (! ((TimeChartEvent
) event
).isVisible()) {
77 if (lastBookmarkX
== rect
.x
|| ((TimeChartEvent
) event
).isBookmarked()) {
78 drawBookmark(rect
, gc
);
79 lastBookmarkX
= rect
.x
;
80 } else if (lastBookmarkX
== rect
.x
- 1) {
81 Rectangle r
= new Rectangle(lastBookmarkX
, rect
.y
, rect
.width
, rect
.height
);
84 lastBookmarkX
= Integer
.MIN_VALUE
;
86 if (((TimeChartEvent
) event
).isSearchMatch()) {
87 drawSearchMatch(rect
, gc
);
91 private void drawBookmark(Rectangle r
, GC gc
) {
92 gc
.setForeground(BOOKMARK_OUTER_COLOR
);
93 gc
.drawLine(r
.x
- 1, r
.y
- 2, r
.x
- 1, r
.y
+ 2);
94 gc
.drawLine(r
.x
+ 1, r
.y
- 2, r
.x
+ 1, r
.y
+ 2);
95 gc
.drawPoint(r
.x
, r
.y
- 2);
96 gc
.setForeground(BOOKMARK_INNER_COLOR
);
97 gc
.drawLine(r
.x
, r
.y
- 1, r
.x
, r
.y
+ 1);
98 gc
.setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_WHITE
));
99 gc
.drawPoint(r
.x
- 1, r
.y
+ 3);
100 gc
.drawPoint(r
.x
, r
.y
+ 2);
101 gc
.drawPoint(r
.x
+ 1, r
.y
+ 3);
104 private void drawSearchMatch(Rectangle r
, GC gc
) {
105 gc
.setForeground(SEARCH_MATCH_COLOR
);
106 gc
.drawPoint(r
.x
, r
.y
+ r
.height
);
107 gc
.drawLine(r
.x
- 1, r
.y
+ r
.height
+ 1, r
.x
+ 1, r
.y
+ r
.height
+ 1);
108 gc
.drawLine(r
.x
- 2, r
.y
+ r
.height
+ 2, r
.x
+ 2, r
.y
+ r
.height
+ 2);