1 /******************************************************************************* 2 * Copyright (c) 2008, 2013 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.debug.examples.ui.midi.detailpanes; 15 16 import org.eclipse.debug.examples.core.midi.launcher.ClockControl; 17 import org.eclipse.debug.ui.IDetailPane; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.events.SelectionAdapter; 21 import org.eclipse.swt.events.SelectionEvent; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.swt.widgets.Control; 24 import org.eclipse.swt.widgets.Slider; 25 import org.eclipse.ui.IWorkbenchPartSite; 26 27 /** 28 * A slider to control the clock position. 29 * 30 * @since 1.0 31 */ 32 public class ClockSliderDetailPane implements IDetailPane { 33 34 private Slider fSlider; 35 private ClockControl fControl; 36 37 @Override createControl(Composite parent)38 public Control createControl(Composite parent) { 39 fSlider = new Slider(parent, SWT.HORIZONTAL); 40 fSlider.setMinimum(0); 41 fSlider.setMaximum(1000); 42 fSlider.addSelectionListener(new SelectionAdapter(){ 43 @Override 44 public void widgetSelected(SelectionEvent e) { 45 int selection = fSlider.getSelection(); 46 if (fControl != null) { 47 fControl.setValue(Integer.toString(selection)); 48 } 49 } 50 }); 51 return fSlider; 52 } 53 54 @Override display(IStructuredSelection selection)55 public void display(IStructuredSelection selection) { 56 fControl = null; 57 if (selection == null || selection.isEmpty()) { 58 fSlider.setEnabled(false); 59 } else { 60 fSlider.setEnabled(true); 61 fControl = (ClockControl) selection.getFirstElement(); 62 int max = (int)fControl.getSequencer().getMicrosecondLength() / 1000000; 63 long micro = fControl.getSequencer().getMicrosecondPosition(); 64 int seconds = (int) micro / 1000000; 65 fSlider.setMaximum(max); 66 fSlider.setSelection(seconds); 67 } 68 } 69 70 @Override dispose()71 public void dispose() { 72 } 73 74 @Override getDescription()75 public String getDescription() { 76 return "Location (seconds)"; //$NON-NLS-1$ 77 } 78 79 @Override getID()80 public String getID() { 81 return ControlDetailPaneFactory.ID_CLOCK_SLIDER; 82 } 83 84 @Override getName()85 public String getName() { 86 return "Clock Slider (seconds)"; //$NON-NLS-1$ 87 } 88 89 @Override init(IWorkbenchPartSite partSite)90 public void init(IWorkbenchPartSite partSite) { 91 } 92 93 @Override setFocus()94 public boolean setFocus() { 95 fSlider.setFocus(); 96 return true; 97 } 98 99 } 100