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 */ |
be222f56 | 47 | protected TimeGraphColorScheme _colors; |
a0a88f65 AM |
48 | |
49 | /** Font size */ | |
be222f56 PT |
50 | protected int _fontHeight = 0; |
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 | |
69 | * @param colors | |
70 | * The color scheme to use | |
71 | * @param style | |
72 | * The index of the style to use | |
73 | */ | |
74 | public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors, int style) { | |
75 | super(parent, style); | |
76 | _colors = colors; | |
77 | addPaintListener(this); | |
78 | } | |
79 | ||
80 | @Override | |
81 | public void dispose() { | |
82 | super.dispose(); | |
83 | } | |
84 | ||
85 | @Override | |
86 | public void paintControl(PaintEvent e) { | |
87 | if (e.widget != this) { | |
88 | return; | |
89 | } | |
90 | _fontHeight = e.gc.getFontMetrics().getHeight(); | |
91 | Rectangle bound = getClientArea(); | |
92 | if (!bound.isEmpty()) { | |
93 | Color colBackup = e.gc.getBackground(); | |
94 | paint(bound, e); | |
95 | e.gc.setBackground(colBackup); | |
96 | } | |
97 | } | |
98 | ||
99 | /** | |
100 | * Retrieve the current font's height | |
101 | * | |
102 | * @return The height | |
103 | */ | |
104 | public int getFontHeight() { | |
105 | return _fontHeight; | |
106 | } | |
107 | ||
108 | abstract void paint(Rectangle bound, PaintEvent e); | |
109 | } |