(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / timeAnalysis / widgets / TraceCtrl.java
1 /*****************************************************************************
2 * Copyright (c) 2007, Intel Corporation.
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 Sanchex-Leon - Udpated for TMF
12 *
13 * $Id: TraceCtrl.java,v 1.2 2007/02/27 18:37:36 ewchan Exp $
14 *****************************************************************************/
15
16 package org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.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 public abstract class TraceCtrl extends Canvas implements PaintListener {
27
28 static public final int MARGIN = 4;
29 static public final int RIGHT_MARGIN = 2; // 2 pixels less to make sure end time is visible
30 static public final int SMALL_ICON_SIZE = 16;
31
32 protected TraceColorScheme _colors;
33 protected int _fontHeight = 0;
34
35 public TraceCtrl(Composite parent, TraceColorScheme colors) {
36 this(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS);
37 }
38
39 public TraceCtrl(Composite parent, TraceColorScheme colors, int style) {
40 super(parent, style);
41 _colors = colors;
42 addPaintListener(this);
43 }
44
45 @Override
46 public void dispose() {
47 super.dispose();
48 }
49
50 public void paintControl(PaintEvent e) {
51 if (e.widget != this)
52 return;
53 _fontHeight = e.gc.getFontMetrics().getHeight();
54 Rectangle bound = getClientArea();
55 if (!bound.isEmpty()) {
56 Color colBackup = e.gc.getBackground();
57 paint(bound, e);
58 e.gc.setBackground(colBackup);
59 }
60 }
61
62 public int getFontHeight() {
63 return _fontHeight;
64 }
65
66 abstract void paint(Rectangle bound, PaintEvent e);
67 }
This page took 0.038842 seconds and 5 git commands to generate.