analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / widgets / timegraph / widgets / TimeGraphBaseControl.java
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
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 package org.eclipse.tracecompass.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 */
35 public static final int MARGIN = 4;
36
37 /** Default expanded size */
38 public static final int EXPAND_SIZE = 9; // the [+] or [-] control size
39
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
42
43 /** Default size for small icons */
44 public static final int SMALL_ICON_SIZE = 16;
45
46 /** Color scheme */
47 private TimeGraphColorScheme fColorScheme;
48
49 /** Font size */
50 private int fFontHeight = 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 colorScheme
70 * The color scheme to use
71 * @param style
72 * The index of the style to use
73 */
74 public TimeGraphBaseControl(Composite parent, TimeGraphColorScheme colorScheme, int style) {
75 super(parent, style);
76 fColorScheme = colorScheme;
77 addPaintListener(this);
78 }
79
80 @Override
81 public void paintControl(PaintEvent e) {
82 if (e.widget != this) {
83 return;
84 }
85 fFontHeight = e.gc.getFontMetrics().getHeight();
86 Rectangle bound = getClientArea();
87 if (!bound.isEmpty()) {
88 Color colBackup = e.gc.getBackground();
89 paint(bound, e);
90 e.gc.setBackground(colBackup);
91 }
92 }
93
94 /**
95 * Retrieve the color scheme
96 *
97 * @return The color scheme
98 */
99 public TimeGraphColorScheme getColorScheme() {
100 return fColorScheme;
101 }
102
103 /**
104 * Retrieve the current font's height
105 *
106 * @return The height
107 */
108 public int getFontHeight() {
109 return fFontHeight;
110 }
111
112 abstract void paint(Rectangle bound, PaintEvent e);
113 }
This page took 0.04008 seconds and 5 git commands to generate.