Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 83cc91251030e717d792fe610089ca67a067dd66 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*******************************************************************************
 * Copyright (c) 2008, 2013 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.examples.ui.midi.detailpanes;

import org.eclipse.debug.examples.core.midi.launcher.ClockControl;
import org.eclipse.debug.ui.IDetailPane;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Slider;
import org.eclipse.ui.IWorkbenchPartSite;

/**
 * A slider to control the clock position.
 *
 * @since 1.0
 */
public class ClockSliderDetailPane implements IDetailPane {

	private Slider fSlider;
	private ClockControl fControl;

	@Override
	public Control createControl(Composite parent) {
		fSlider = new Slider(parent, SWT.HORIZONTAL);
		fSlider.setMinimum(0);
		fSlider.setMaximum(1000);
		fSlider.addSelectionListener(new SelectionAdapter(){
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selection = fSlider.getSelection();
				if (fControl != null) {
					fControl.setValue(Integer.toString(selection));
				}
			}
		});
		return fSlider;
	}

	@Override
	public void display(IStructuredSelection selection) {
		fControl = null;
		if (selection == null || selection.isEmpty()) {
			fSlider.setEnabled(false);
		} else {
			fSlider.setEnabled(true);
			fControl = (ClockControl) selection.getFirstElement();
			int max = (int)fControl.getSequencer().getMicrosecondLength() / 1000000;
			long micro = fControl.getSequencer().getMicrosecondPosition();
			int seconds = (int) micro / 1000000;
			fSlider.setMaximum(max);
			fSlider.setSelection(seconds);
		}
	}

	@Override
	public void dispose() {
	}

	@Override
	public String getDescription() {
		return "Location (seconds)"; //$NON-NLS-1$
	}

	@Override
	public String getID() {
		return ControlDetailPaneFactory.ID_CLOCK_SLIDER;
	}

	@Override
	public String getName() {
		return "Clock Slider (seconds)"; //$NON-NLS-1$
	}

	@Override
	public void init(IWorkbenchPartSite partSite) {
	}

	@Override
	public boolean setFocus() {
		fSlider.setFocus();
		return true;
	}

}

Back to the top