~ubuntu-branches/ubuntu/utopic/eclipse-linuxtools/utopic

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphComposite.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2014-05-12 18:11:40 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140512181140-w237r3vsah1tmybz
Tags: 2.2.1-1
* New upstream release.
* Refreshed d/patches.
* Removed eclipse-cdt-valgrind-remote package, all its functionality
  is now provided by eclipse-cdt-profiling-framework-remote.
* Added remove-license-feature.patch.
* Bump Standards-Version to 3.9.5.
* Enable eclipse-changelog package.
* Enable eclipse-rpm-editor package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2006 IBM 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
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets;
 
13
 
 
14
import java.util.ArrayList;
 
15
 
 
16
import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSet;
 
17
import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.GraphData;
 
18
import org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.AbstractChartBuilder;
 
19
import org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.AbstractChartWithoutAxisBuilder;
 
20
import org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.graph.GraphFactory;
 
21
import org.eclipse.swt.SWT;
 
22
import org.eclipse.swt.events.SelectionAdapter;
 
23
import org.eclipse.swt.events.SelectionEvent;
 
24
import org.eclipse.swt.events.SelectionListener;
 
25
import org.eclipse.swt.graphics.Font;
 
26
import org.eclipse.swt.layout.FormAttachment;
 
27
import org.eclipse.swt.layout.FormData;
 
28
import org.eclipse.swt.layout.FormLayout;
 
29
import org.eclipse.swt.widgets.Button;
 
30
import org.eclipse.swt.widgets.Composite;
 
31
import org.eclipse.swt.widgets.Label;
 
32
import org.eclipse.swt.widgets.Scale;
 
33
 
 
34
/**
 
35
 * A Composite type to contain a Graph object.
 
36
 * @author Henry Hughes
 
37
 * @author Ryan Morse
 
38
 */
 
39
public class GraphComposite extends Composite {
 
40
        /**
 
41
         * The default constructor: creates an internal composite for the Graph to render on, asks GraphFactory
 
42
         * to create the graph from the given GraphData and DataSet, then initializes all buttons and listeners.
 
43
         */
 
44
        public GraphComposite(Composite parent, int style, GraphData gd, IDataSet ds) {
 
45
                super(parent, style);
 
46
                FormLayout layout = new FormLayout();
 
47
                layout.marginWidth = 5;
 
48
                layout.marginHeight = 5;
 
49
                this.setLayout(layout);
 
50
                checkOptions = new ArrayList<Button>();
 
51
 
 
52
                label = new Label(this, SWT.HORIZONTAL | SWT.BORDER | SWT.BOLD | SWT.CENTER);
 
53
                scale = scales[7];
 
54
                label.setText("-"); //$NON-NLS-1$
 
55
                FormData data = new FormData();
 
56
                data.bottom = new FormAttachment(100,-4);
 
57
                data.left = new FormAttachment(0, 2);
 
58
                data.width = 15;
 
59
                label.setLayoutData(data);
 
60
                label.setFont(new Font(parent.getDisplay(), "Arial", 10, SWT.BOLD )); //$NON-NLS-1$
 
61
                zoomScale = new Scale(this,SWT.HORIZONTAL);
 
62
                zoomScale.setMinimum(0);
 
63
                zoomScale.setMaximum(14);
 
64
                zoomScale.setIncrement(1);
 
65
                zoomScale.setPageIncrement(1);
 
66
                zoomScale.setSelection(7);
 
67
                zoomScale.setToolTipText("Increase/Decrease the no of X axis ticks"); //$NON-NLS-1$
 
68
                data = new FormData();
 
69
                data.left = new FormAttachment(label,2);
 
70
                data.bottom = new FormAttachment(100, -4);
 
71
                data.right = new FormAttachment(100, -20);
 
72
                zoomScale.setLayoutData(data);
 
73
 
 
74
                pluslabel = new Label(this, SWT.HORIZONTAL | SWT.BOLD | SWT.BORDER | SWT.CENTER);
 
75
                pluslabel.setText("+"); //$NON-NLS-1$
 
76
                pluslabel.setFont(new Font(parent.getDisplay(), "Arial", 10, SWT.BOLD)); //$NON-NLS-1$
 
77
                data = new FormData();
 
78
                data.left = new FormAttachment(zoomScale,2);
 
79
                data.bottom = new FormAttachment(100,-4);
 
80
                data.width = 15;
 
81
                pluslabel.setLayoutData(data);
 
82
 
 
83
                builder = GraphFactory.createGraph(this, style,gd, ds);
 
84
                data = new FormData();
 
85
                data.top = new FormAttachment(0,0);
 
86
                data.bottom = new FormAttachment(label,-5);
 
87
                data.right = new FormAttachment(100,0);
 
88
                data.left = new FormAttachment(0,0);
 
89
                builder.build();
 
90
 
 
91
 
 
92
 
 
93
                builder.setLayoutData(data);
 
94
 
 
95
                zoomScale.addSelectionListener(scaleListener);
 
96
 
 
97
                //The scale zoom scrool doesn't make sense for charts without axis
 
98
                if (builder instanceof AbstractChartWithoutAxisBuilder) {
 
99
                        this.configure(false);
 
100
                }
 
101
        }
 
102
 
 
103
        /**
 
104
         * Toggles sidebar visible or not visible.
 
105
         * @param withSidebar Enables or disables the sidebar.
 
106
         */
 
107
        public void configure(boolean withSidebar) {
 
108
                sidebarVisible = withSidebar;
 
109
 
 
110
                for(Button b:checkOptions) {
 
111
                        b.setVisible(sidebarVisible);
 
112
                }
 
113
 
 
114
                zoomScale.setVisible(sidebarVisible);
 
115
                label.setVisible(sidebarVisible);
 
116
                pluslabel.setVisible(sidebarVisible);
 
117
 
 
118
                FormData data = new FormData();
 
119
                data.top = new FormAttachment(0,0);
 
120
                data.bottom = (withSidebar ? new FormAttachment(label,-7) : new FormAttachment(100, 0));
 
121
                data.left = new FormAttachment(0,0);
 
122
                data.right = new FormAttachment(100,0);
 
123
                builder.setLayoutData(data);
 
124
 
 
125
                layout(true, true);
 
126
        }
 
127
 
 
128
        public void addCheckOption(String title, SelectionListener listener) {
 
129
                Button b = new Button(this, SWT.CHECK);
 
130
                b.setText(title);
 
131
 
 
132
                Button old = null;
 
133
                if(checkOptions.size() > 0) {
 
134
                        old = checkOptions.get(checkOptions.size()-1);
 
135
                }
 
136
 
 
137
                FormData data = new FormData();
 
138
                data.bottom = (null != old) ? new FormAttachment(old,0) : new FormAttachment(100, 0);
 
139
                data.right = new FormAttachment(100,0);
 
140
                data.width = 85;
 
141
                b.setLayoutData(data);
 
142
                b.addSelectionListener(listener);
 
143
 
 
144
                checkOptions.add(b);
 
145
 
 
146
                if(checkOptions.size() == 1) {
 
147
                        ((FormData)label.getLayoutData()).right = new FormAttachment(b, 0);
 
148
                        ((FormData)zoomScale.getLayoutData()).right = new FormAttachment(b, 0);
 
149
                }
 
150
        }
 
151
 
 
152
        public void removeCheckOption(String title) {
 
153
                for(Button b :checkOptions) {
 
154
                        if(b.getText().equals(title)) {
 
155
                                checkOptions.remove(b);
 
156
 
 
157
                                if(checkOptions.size() == 0) {
 
158
                                        ((FormData)label.getLayoutData()).right = new FormAttachment(100, 0);
 
159
                                }
 
160
 
 
161
                                return;
 
162
                        }
 
163
                }
 
164
        }
 
165
 
 
166
        /**
 
167
         * Returns the graph that is rendering to this composite.
 
168
         */
 
169
        public AbstractChartBuilder getCanvas() {
 
170
                return builder;
 
171
        }
 
172
 
 
173
        /**
 
174
         * Returns the current sidebar visibility state.
 
175
         */
 
176
        public boolean isSidebarVisible() {
 
177
                return sidebarVisible;
 
178
        }
 
179
 
 
180
        /**
 
181
         * Dispose is overriden in order to dispose of the listeners attached to this Composite on disposal.
 
182
         */
 
183
        @Override
 
184
        public void dispose() {
 
185
                scaleListener = null;
 
186
 
 
187
                if(null != zoomScale) {
 
188
                        zoomScale.dispose();
 
189
                }
 
190
                zoomScale = null;
 
191
 
 
192
                if(null != label) {
 
193
                        label.dispose();
 
194
                }
 
195
                label = null;
 
196
                super.dispose();
 
197
        }
 
198
 
 
199
        /**
 
200
         * Listeners are below:
 
201
         *      scaleListener - detects movement in the Scale widget and rescales the graph on change
 
202
         *  titleListener - A SelectionListener for the title button
 
203
         *  legendListener - A SelectionListener for the legend checkbox
 
204
         *  gridListener - A SelectionListener for the Grid checkbox
 
205
         *  normalizeListener - A SelectionListener for the normalization checkbox
 
206
         *  propertyChangeListener - Detects changes in user preferences and applies them
 
207
         */
 
208
        private SelectionListener scaleListener = new SelectionAdapter() {
 
209
                @Override
 
210
                public void widgetSelected(SelectionEvent e) {
 
211
 
 
212
                        Scale scaler = (Scale) e.widget;
 
213
                        int index = scaler.getSelection();
 
214
                        if(scale != scales[index]) {
 
215
                                scale = scales[index];
 
216
                                builder.setScale(scale);
 
217
                        }
 
218
                }
 
219
        };
 
220
 
 
221
        private boolean sidebarVisible = true;
 
222
        private AbstractChartBuilder builder;
 
223
        private Scale zoomScale;
 
224
        public double scale;
 
225
        private static final double[] scales = { .0625, .125, .25, .33 , .5, .66, .8, 1.0, 1.25, 1.5, 2, 3, 4, 8, 16 };
 
226
        private Label label;
 
227
        private Label pluslabel;
 
228
 
 
229
        private ArrayList<Button> checkOptions;
 
230
 
 
231
}