1 /*******************************************************************************
2 * Copyright (c) 2010, 2011, 2012, 2013 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
.ColorSetting
;
16 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.colors
.ColorSettingsManager
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider
;
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
.swt
.SWT
;
22 import org
.eclipse
.swt
.graphics
.Color
;
23 import org
.eclipse
.swt
.graphics
.GC
;
24 import org
.eclipse
.swt
.graphics
.Rectangle
;
25 import org
.eclipse
.swt
.widgets
.Display
;
28 * Provider for a time chart analysis view
31 * @author Patrick Tasse
33 public class TimeChartAnalysisProvider
extends TimeGraphPresentationProvider
{
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);
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
;
45 public StateItem
[] getStateTable() {
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());
56 public int getStateTableIndex(ITimeEvent event
) {
57 if (! ((TimeChartEvent
) event
).isVisible()) {
58 return ITimeGraphPresentationProvider
.INVISIBLE
;
60 int priority
= ((TimeChartEvent
) event
).getColorSettingPriority();
62 priority
= Math
.min(priority
, lastPriority
);
64 lastPriority
= priority
;
69 public void postDrawEvent(ITimeEvent event
, Rectangle rect
, GC gc
) {
70 if (! ((TimeChartEvent
) event
).isVisible()) {
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
);
82 lastBookmarkX
= Integer
.MIN_VALUE
;
84 if (((TimeChartEvent
) event
).isSearchMatch()) {
85 drawSearchMatch(rect
, gc
);
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);
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);