1 /*****************************************************************************
2 * Copyright (c) 2007, 2014 Intel Corporation, 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
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 *****************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
;
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
;
26 * Base control abstract class for the time graph widget
29 * @author Alvaro Sanchez-Leon
30 * @author Patrick Tasse
32 public abstract class TimeGraphBaseControl
extends Canvas
implements PaintListener
{
34 /** Default left margin size */
35 public static final int MARGIN
= 4;
37 /** Default expanded size */
38 public static final int EXPAND_SIZE
= 9; // the [+] or [-] control size
40 /** Default size of the right margin */
41 public static final int RIGHT_MARGIN
= 1; // 1 pixels less to make sure end time is visible
43 /** Default size for small icons */
44 public static final int SMALL_ICON_SIZE
= 16;
47 private TimeGraphColorScheme fColorScheme
;
50 private int fFontHeight
= 0;
53 * Basic constructor. Uses a default style value
56 * The parent composite object
58 * The color scheme to use
60 public TimeGraphBaseControl(Composite parent
, TimeGraphColorScheme colors
) {
61 this(parent
, colors
, SWT
.NO_BACKGROUND
| SWT
.NO_FOCUS
);
65 * Standard constructor
68 * The parent composite object
70 * The color scheme to use
72 * The index of the style to use
74 public TimeGraphBaseControl(Composite parent
, TimeGraphColorScheme colorScheme
, int style
) {
76 fColorScheme
= colorScheme
;
77 addPaintListener(this);
81 public void paintControl(PaintEvent e
) {
82 if (e
.widget
!= this) {
86 // we will use advanced graphics, set now for consistent output
87 e
.gc
.setAdvanced(true);
89 fFontHeight
= e
.gc
.getFontMetrics().getHeight();
90 Rectangle bound
= getClientArea();
91 if (!bound
.isEmpty()) {
92 Color colBackup
= e
.gc
.getBackground();
94 e
.gc
.setBackground(colBackup
);
99 * Retrieve the color scheme
101 * @return The color scheme
103 public TimeGraphColorScheme
getColorScheme() {
108 * Retrieve the current font's height
112 public int getFontHeight() {
116 abstract void paint(Rectangle bound
, PaintEvent e
);