003e5e593d31d9b3c9e49a16817d4b3b3923ab27
[deliverable/tracecompass.git] / tmf / 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
86 // we will use advanced graphics, set now for consistent output
87 e.gc.setAdvanced(true);
88
89 fFontHeight = e.gc.getFontMetrics().getHeight();
90 Rectangle bound = getClientArea();
91 if (!bound.isEmpty()) {
92 Color colBackup = e.gc.getBackground();
93 paint(bound, e);
94 e.gc.setBackground(colBackup);
95 }
96 }
97
98 /**
99 * Retrieve the color scheme
100 *
101 * @return The color scheme
102 */
103 public TimeGraphColorScheme getColorScheme() {
104 return fColorScheme;
105 }
106
107 /**
108 * Retrieve the current font's height
109 *
110 * @return The height
111 */
112 public int getFontHeight() {
113 return fFontHeight;
114 }
115
116 abstract void paint(Rectangle bound, PaintEvent e);
117 }
This page took 0.032093 seconds and 4 git commands to generate.