Commit | Line | Data |
---|---|---|
be222f56 | 1 | /***************************************************************************** |
c8422608 | 2 | * Copyright (c) 2007, 2013 Intel Corporation, Ericsson |
be222f56 PT |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Intel Corporation - Initial API and implementation | |
10 | * Ruslan A. Scherbakov, Intel - Initial API and implementation | |
11 | * Alvaro Sanchez-Leon - Updated for TMF | |
12 | * Patrick Tasse - Refactoring | |
be222f56 PT |
13 | *****************************************************************************/ |
14 | ||
15 | package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; | |
16 | ||
17 | import org.eclipse.swt.SWT; | |
18 | import org.eclipse.swt.events.PaintEvent; | |
19 | import org.eclipse.swt.events.PaintListener; | |
20 | import org.eclipse.swt.graphics.Color; | |
21 | import org.eclipse.swt.graphics.Rectangle; | |
22 | import org.eclipse.swt.widgets.Canvas; | |
23 | import org.eclipse.swt.widgets.Composite; | |
24 | ||
25 | /** | |
26 | * Base control abstract class for the time graph widget | |
27 | * | |
28 | * @version 1.0 | |
29 | * @author Alvaro Sanchez-Leon | |
30 | * @author Patrick Tasse | |
31 | */ | |
32 | public abstract class TimeGraphBaseControl extends Canvas implements PaintListener { | |
33 | ||
34 | /** Default left margin size */ | |
a0a88f65 | 35 | public static final int MARGIN = 4; |
be222f56 PT |
36 | |
37 | /** Default expanded size */ | |
a0a88f65 | 38 | public static final int EXPAND_SIZE = 9; // the [+] or [-] control size |
be222f56 PT |
39 | |
40 | /** Default size of the right margin */ | |
a0a88f65 | 41 | public static final int RIGHT_MARGIN = 1; // 1 pixels less to make sure end time is visible |
be222f56 PT |
42 | |
43 | /** Default size for small icons */ | |
a0a88f65 | 44 | public static final int SMALL_ICON_SIZE = 16; |
be222f56 | 45 | |
a0a88f65 | 46 | /** Color scheme */ |
f1fae91f | 47 | private TimeGraphColorScheme fColorScheme; |
a0a88f65 AM |
48 | |
49 | /** Font size */ | |
f1fae91f | 50 | private int fFontHeight = 0; |
be222f56 PT |
51 | |
52 | /** | |
53 | * Basic constructor. Uses a default style value | |
54 | * | |
55 | * @param parent | |
56 | * The parent composite object | |
57 | * @param colors | |
58 | * The color scheme to use | |
59 | */ | |
60 | public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors) { | |
61 | this(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS); | |
62 | } | |
63 | ||
64 | /** | |
65 | * Standard constructor | |
66 | * | |
67 | * @param parent | |
68 | * The parent composite object | |
f1fae91f | 69 | * @param colorScheme |
be222f56 PT |
70 | * The color scheme to use |
71 | * @param style | |
72 | * The index of the style to use | |
73 | */ | |
f1fae91f | 74 | public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colorScheme, int style) { |
be222f56 | 75 | super(parent, style); |
f1fae91f | 76 | fColorScheme = colorScheme; |
be222f56 PT |
77 | addPaintListener(this); |
78 | } | |
79 | ||
be222f56 PT |
80 | @Override |
81 | public void paintControl(PaintEvent e) { | |
82 | if (e.widget != this) { | |
83 | return; | |
84 | } | |
f1fae91f | 85 | fFontHeight = e.gc.getFontMetrics().getHeight(); |
be222f56 PT |
86 | Rectangle bound = getClientArea(); |
87 | if (!bound.isEmpty()) { | |
88 | Color colBackup = e.gc.getBackground(); | |
89 | paint(bound, e); | |
90 | e.gc.setBackground(colBackup); | |
91 | } | |
92 | } | |
93 | ||
f1fae91f PT |
94 | /** |
95 | * Retrieve the color scheme | |
96 | * | |
97 | * @return The color scheme | |
98 | * | |
99 | * @since 2.0 | |
100 | */ | |
101 | public TimeGraphColorScheme getColorScheme() { | |
102 | return fColorScheme; | |
103 | } | |
104 | ||
be222f56 PT |
105 | /** |
106 | * Retrieve the current font's height | |
107 | * | |
108 | * @return The height | |
109 | */ | |
110 | public int getFontHeight() { | |
f1fae91f | 111 | return fFontHeight; |
be222f56 PT |
112 | } |
113 | ||
114 | abstract void paint(Rectangle bound, PaintEvent e); | |
115 | } |