Commit | Line | Data |
---|---|---|
be222f56 PT |
1 | /***************************************************************************** |
2 | * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson. | |
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 | |
13 | * | |
14 | *****************************************************************************/ | |
15 | ||
16 | package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; | |
17 | ||
18 | import org.eclipse.swt.SWT; | |
19 | import org.eclipse.swt.events.PaintEvent; | |
20 | import org.eclipse.swt.events.PaintListener; | |
21 | import org.eclipse.swt.graphics.Color; | |
22 | import org.eclipse.swt.graphics.Rectangle; | |
23 | import org.eclipse.swt.widgets.Canvas; | |
24 | import org.eclipse.swt.widgets.Composite; | |
25 | ||
26 | /** | |
27 | * Base control abstract class for the time graph widget | |
28 | * | |
29 | * @version 1.0 | |
30 | * @author Alvaro Sanchez-Leon | |
31 | * @author Patrick Tasse | |
32 | */ | |
33 | public abstract class TimeGraphBaseControl extends Canvas implements PaintListener { | |
34 | ||
35 | /** Default left margin size */ | |
a0a88f65 | 36 | public static final int MARGIN = 4; |
be222f56 PT |
37 | |
38 | /** Default expanded size */ | |
a0a88f65 | 39 | public static final int EXPAND_SIZE = 9; // the [+] or [-] control size |
be222f56 PT |
40 | |
41 | /** Default size of the right margin */ | |
a0a88f65 | 42 | public static final int RIGHT_MARGIN = 1; // 1 pixels less to make sure end time is visible |
be222f56 PT |
43 | |
44 | /** Default size for small icons */ | |
a0a88f65 | 45 | public static final int SMALL_ICON_SIZE = 16; |
be222f56 | 46 | |
a0a88f65 | 47 | /** Color scheme */ |
be222f56 | 48 | protected TimeGraphColorScheme _colors; |
a0a88f65 AM |
49 | |
50 | /** Font size */ | |
be222f56 PT |
51 | protected int _fontHeight = 0; |
52 | ||
53 | /** | |
54 | * Basic constructor. Uses a default style value | |
55 | * | |
56 | * @param parent | |
57 | * The parent composite object | |
58 | * @param colors | |
59 | * The color scheme to use | |
60 | */ | |
61 | public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors) { | |
62 | this(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS); | |
63 | } | |
64 | ||
65 | /** | |
66 | * Standard constructor | |
67 | * | |
68 | * @param parent | |
69 | * The parent composite object | |
70 | * @param colors | |
71 | * The color scheme to use | |
72 | * @param style | |
73 | * The index of the style to use | |
74 | */ | |
75 | public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors, int style) { | |
76 | super(parent, style); | |
77 | _colors = colors; | |
78 | addPaintListener(this); | |
79 | } | |
80 | ||
81 | @Override | |
82 | public void dispose() { | |
83 | super.dispose(); | |
84 | } | |
85 | ||
86 | @Override | |
87 | public void paintControl(PaintEvent e) { | |
88 | if (e.widget != this) { | |
89 | return; | |
90 | } | |
91 | _fontHeight = e.gc.getFontMetrics().getHeight(); | |
92 | Rectangle bound = getClientArea(); | |
93 | if (!bound.isEmpty()) { | |
94 | Color colBackup = e.gc.getBackground(); | |
95 | paint(bound, e); | |
96 | e.gc.setBackground(colBackup); | |
97 | } | |
98 | } | |
99 | ||
100 | /** | |
101 | * Retrieve the current font's height | |
102 | * | |
103 | * @return The height | |
104 | */ | |
105 | public int getFontHeight() { | |
106 | return _fontHeight; | |
107 | } | |
108 | ||
109 | abstract void paint(Rectangle bound, PaintEvent e); | |
110 | } |