~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartAnalysisProvider.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

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