Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / widgets / TimeGraphBaseControl.java
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 */
36 static public final int MARGIN = 4;
37
38 /** Default expanded size */
39 static public final int EXPAND_SIZE = 9; // the [+] or [-] control size
40
41 /** Default size of the right margin */
42 static public final int RIGHT_MARGIN = 1; // 1 pixels less to make sure end time is visible
43
44 /** Default size for small icons */
45 static public final int SMALL_ICON_SIZE = 16;
46
47 protected TimeGraphColorScheme _colors;
48 protected int _fontHeight = 0;
49
50 /**
51 * Basic constructor. Uses a default style value
52 *
53 * @param parent
54 * The parent composite object
55 * @param colors
56 * The color scheme to use
57 */
58 public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors) {
59 this(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS);
60 }
61
62 /**
63 * Standard constructor
64 *
65 * @param parent
66 * The parent composite object
67 * @param colors
68 * The color scheme to use
69 * @param style
70 * The index of the style to use
71 */
72 public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colors, int style) {
73 super(parent, style);
74 _colors = colors;
75 addPaintListener(this);
76 }
77
78 @Override
79 public void dispose() {
80 super.dispose();
81 }
82
83 @Override
84 public void paintControl(PaintEvent e) {
85 if (e.widget != this) {
86 return;
87 }
88 _fontHeight = e.gc.getFontMetrics().getHeight();
89 Rectangle bound = getClientArea();
90 if (!bound.isEmpty()) {
91 Color colBackup = e.gc.getBackground();
92 paint(bound, e);
93 e.gc.setBackground(colBackup);
94 }
95 }
96
97 /**
98 * Retrieve the current font's height
99 *
100 * @return The height
101 */
102 public int getFontHeight() {
103 return _fontHeight;
104 }
105
106 abstract void paint(Rectangle bound, PaintEvent e);
107 }
This page took 0.046627 seconds and 5 git commands to generate.