1
/****************************************************************
2
* Licensed Material - Property of IBM
6
* (c) Copyright IBM Corp. 2006. All rights reserved.
8
* US Government Users Restricted Rights - Use, duplication or
9
* disclosure restricted by GSA ADP Schedule Contract with
12
****************************************************************
14
package org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.charts;
16
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.linuxtools.internal.systemtap.ui.graphingapi.ui.GraphingAPIUIPlugin;
19
import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.preferences.GraphingAPIPreferenceConstants;
21
import org.eclipse.swt.graphics.Color;
22
import org.eclipse.swt.layout.FillLayout;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters.IAdapter;
26
import org.eclipse.linuxtools.systemtap.ui.structures.listeners.IUpdateListener;
27
import org.eclipse.swt.widgets.Display;
29
import org.swtchart.Chart;
30
import org.swtchart.ITitle;
33
* Provides the common members and the framework to build one chart.
37
public abstract class AbstractChartBuilder extends Composite implements IUpdateListener{
40
* Font name for all titles, labels, and values.
42
protected final static String FONT_NAME = "MS Sans Serif";
43
protected int maxItems;
44
protected double scale = 1.0;
47
* Provides data for chart.
49
protected IAdapter adapter = null;
50
protected int xseries;
51
protected int[] yseries;
53
protected static final Color WHITE = new Color(Display.getDefault(), 255, 255, 255);
54
protected static final Color BLACK = new Color(Display.getDefault(), 0, 0, 0);
55
protected static final Color RED = new Color(Display.getDefault(), 255, 0, 0);
57
protected static final Color[] COLORS = {
58
new Color(Display.getDefault(), 255, 0, 0),
59
new Color(Display.getDefault(), 0, 255, 0),
60
new Color(Display.getDefault(), 0, 0, 255),
61
new Color(Display.getDefault(), 255, 255, 0),
62
new Color(Display.getDefault(), 255, 0, 255),
63
new Color(Display.getDefault(), 0, 255, 255),
64
new Color(Display.getDefault(), 0, 0, 0),
65
new Color(Display.getDefault(), 64, 128, 128),
66
new Color(Display.getDefault(), 255, 165, 0),
67
new Color(Display.getDefault(), 128, 128, 128),
72
protected Chart chart = null;
77
protected String title = null;
80
* Constructs one chart builder and associate it to one data set.
86
public AbstractChartBuilder(IAdapter adapter, Composite parent, int style, String title) {
88
this.adapter = adapter;
90
this.setLayout(new FillLayout());
91
IPreferenceStore store = GraphingAPIUIPlugin.getDefault().getPreferenceStore();
92
maxItems = Math.min(store.getInt(GraphingAPIPreferenceConstants.P_VIEWABLE_DATA_ITEMS),
93
store.getInt(GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS));
112
* Creates chart instance.
114
protected void createChart() {
115
this.chart = new Chart(this, getStyle());
121
protected void buildPlot() {
122
this.chart.setBackground(WHITE);
123
this.chart.setBackgroundInPlotArea(WHITE);
129
protected void buildXAxis() {
136
protected void buildYAxis() {
143
protected void buildXSeries() {
150
protected void buildYSeries() {
158
protected void buildLegend() {
159
chart.getLegend().setPosition(SWT.RIGHT);
163
* Builds the chart title.
165
protected void buildTitle() {
166
ITitle ctitle = chart.getTitle();
167
ctitle.setForeground(BLACK);
168
ctitle.setText(this.title);
172
* Returns the chart instance.
174
* @return the chart instance
176
public Chart getChart() {
180
public void updateDataSet() {
184
public void setScale(double scale) {
189
protected double getDoubleValue(Object o) {
190
if (o instanceof Integer)
191
return ((Integer)o).intValue();
192
if (o instanceof Double)
193
return ((Double)o).doubleValue();
194
return new Double(o.toString()).doubleValue();
197
public void handleUpdateEvent() {
202
//e.printStackTrace();
206
protected void repaint() {
207
getDisplay().syncExec(new Runnable() {
208
boolean stop = false;
214
} catch (Exception e) {