diff options
author | Darin Wright | 2008-02-01 03:26:19 +0000 |
---|---|---|
committer | Darin Wright | 2008-02-01 03:26:19 +0000 |
commit | 134d409a2d2a15ee251ce1c96576028e6c36f736 (patch) | |
tree | f622e314dfa2d8496f0b3cd2d61f7e9a3b9da6d0 | |
parent | 1ff19b0d40844b4970d3d599b43ccfe5616094e2 (diff) | |
download | eclipse.platform.debug-134d409a2d2a15ee251ce1c96576028e6c36f736.tar.gz eclipse.platform.debug-134d409a2d2a15ee251ce1c96576028e6c36f736.tar.xz eclipse.platform.debug-134d409a2d2a15ee251ce1c96576028e6c36f736.zip |
clock slider/control
10 files changed, 318 insertions, 38 deletions
diff --git a/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/ClockControl.java b/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/ClockControl.java new file mode 100644 index 000000000..639f1acf5 --- /dev/null +++ b/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/ClockControl.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.core.midi.launcher; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.examples.core.pda.DebugCorePlugin; + +/** + * Controls the location of the sequencer in microseconds. + * + * @since 1.0 + */ +public class ClockControl extends TimeControl { + + /** + * @param launch + */ + public ClockControl(MidiLaunch launch) { + super("Time" , launch); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.examples.core.midi.launcher.TimeControl#getTimeValue() + */ + protected long getTimeValue() { + return getSequencer().getMicrosecondPosition(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.examples.core.midi.launcher.SequencerControl#isEditable() + */ + public boolean isEditable() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.examples.core.midi.launcher.SequencerControl#setValue(java.lang.String) + */ + public IStatus setValue(String newValue) { + try { + long value = getLong(newValue); + getSequencer().setMicrosecondPosition(value); + fireEvent(new DebugEvent(this, DebugEvent.CHANGE)); + return Status.OK_STATUS; + } catch (CoreException e) { + return e.getStatus(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.examples.core.midi.launcher.SequencerControl#validateValue(java.lang.String) + */ + public IStatus validateValue(String value) { + try { + getLong(value); + return Status.OK_STATUS; + } catch (CoreException e) { + return e.getStatus(); + } + } + + /** + * Returns a float for the string. + * + * @param value string + * @return float + * @throws CoreException if not a valid value + */ + protected long getLong(String value) throws CoreException { + try { + if (value.indexOf(':') == -1) { + long secs = Long.parseLong(value); + return secs * 1000000; + } + } catch (NumberFormatException e) { + throw new CoreException(new Status(IStatus.ERROR, DebugCorePlugin.PLUGIN_ID, "Time must be an integer (seconds) or 00:00 (minutes:seconds) format", e)); + } + return 0L; + } + + +} diff --git a/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/LengthControl.java b/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/LengthControl.java new file mode 100644 index 000000000..3a754c91a --- /dev/null +++ b/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/LengthControl.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.core.midi.launcher; + + +/** + * Describes the length of the sequence in microseconds. + * + * @since 1.0 + */ +public class LengthControl extends TimeControl { + + /** + * @param launch + */ + public LengthControl(MidiLaunch launch) { + super("Duration" , launch); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.examples.core.midi.launcher.TimeControl#getTimeValue() + */ + protected long getTimeValue() { + return getSequencer().getMicrosecondLength(); + } + + +} diff --git a/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/SequencerControl.java b/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/SequencerControl.java index fcc56c97c..3274582cc 100644 --- a/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/SequencerControl.java +++ b/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/SequencerControl.java @@ -114,9 +114,11 @@ public abstract class SequencerControl { * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { - if (obj.getClass().equals(getClass())) { - return ((SequencerControl)obj).getSequencer().equals(getSequencer()); - + if (obj != null) { + if (getClass().equals(obj.getClass())) { + return ((SequencerControl)obj).getSequencer().equals(getSequencer()); + + } } return false; } diff --git a/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/TimeControl.java b/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/TimeControl.java index 19200ba0e..93aa54df4 100644 --- a/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/TimeControl.java +++ b/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/TimeControl.java @@ -10,46 +10,31 @@ *******************************************************************************/ package org.eclipse.debug.examples.core.midi.launcher; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.examples.core.pda.DebugCorePlugin; /** - * Controls the location of the sequencer in microseconds. + * Displays a time value based on underlying microsecond value * * @since 1.0 */ -public class TimeControl extends SequencerControl { +public abstract class TimeControl extends SequencerControl { /** + * Constructs a time control with the given name for the + * given launch. + * * @param name * @param launch */ - public TimeControl(MidiLaunch launch) { - super("Time" , launch); - } - - /** - * Returns a long for the string. - * - * @param value string - * @return long - * @throws CoreException if not a valid value - */ - protected long getLong(String value) throws CoreException { - try { - return Long.parseLong(value); - } catch (NumberFormatException e) { - throw new CoreException(new Status(IStatus.ERROR, DebugCorePlugin.PLUGIN_ID, "Time must be a number", e)); - } + public TimeControl(String name, MidiLaunch launch) { + super(name, launch); } /* (non-Javadoc) * @see org.eclipse.debug.examples.core.midi.launcher.SequencerControl#getValue() */ public String getValue() { - long position = getSequencer().getMicrosecondPosition(); + long position = getTimeValue(); int milli = (int) (position & 0x3F); int sec = (int) (position / 1000000); int min = sec / 60; @@ -71,12 +56,18 @@ public class TimeControl extends SequencerControl { } return clock.toString(); } + + /** + * Provided by subclasses for the control. + * + * @return time in microseconds + */ + protected abstract long getTimeValue(); /* (non-Javadoc) * @see org.eclipse.debug.examples.core.midi.launcher.SequencerControl#isEditable() */ public boolean isEditable() { - // TODO Auto-generated method stub return false; } @@ -84,7 +75,6 @@ public class TimeControl extends SequencerControl { * @see org.eclipse.debug.examples.core.midi.launcher.SequencerControl#setValue(java.lang.String) */ public IStatus setValue(String newValue) { - // TODO Auto-generated method stub return null; } @@ -92,7 +82,6 @@ public class TimeControl extends SequencerControl { * @see org.eclipse.debug.examples.core.midi.launcher.SequencerControl#validateValue(java.lang.String) */ public IStatus validateValue(String value) { - // TODO Auto-generated method stub return null; } diff --git a/org.eclipse.debug.examples.ui/plugin.xml b/org.eclipse.debug.examples.ui/plugin.xml index c84e5956a..a646b37c0 100644 --- a/org.eclipse.debug.examples.ui/plugin.xml +++ b/org.eclipse.debug.examples.ui/plugin.xml @@ -252,9 +252,14 @@ value="1"> </count> <iterate> - <instanceof - value="org.eclipse.debug.examples.core.midi.launcher.TempoControl"> - </instanceof> + <or> + <instanceof + value="org.eclipse.debug.examples.core.midi.launcher.TempoControl"> + </instanceof> + <instanceof + value="org.eclipse.debug.examples.core.midi.launcher.ClockControl"> + </instanceof> + </or> </iterate> </with> </enablement> diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/ControlEventHandler.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/ControlEventHandler.java index 9472914a9..363718233 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/ControlEventHandler.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/ControlEventHandler.java @@ -15,7 +15,7 @@ import java.util.TimerTask; import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.examples.core.midi.launcher.MidiLaunch; -import org.eclipse.debug.examples.core.midi.launcher.TimeControl; +import org.eclipse.debug.examples.core.midi.launcher.ClockControl; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta; import org.eclipse.debug.internal.ui.viewers.update.DebugEventHandler; @@ -45,6 +45,12 @@ public class ControlEventHandler extends DebugEventHandler { super(proxy); fLaunch = proxy.getMidiLaunch(); } + + protected void init() { + if (!fLaunch.isSuspended() && !fLaunch.isTerminated() && !fLaunch.isDisconnected()) { + startTimer(); + } + } /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.update.DebugEventHandler#handlesEvent(org.eclipse.debug.core.DebugEvent) @@ -87,7 +93,7 @@ public class ControlEventHandler extends DebugEventHandler { fTimer.schedule(new TimerTask() { public void run() { ModelDelta delta = new ModelDelta(fLaunch, IModelDelta.NO_CHANGE); - delta = delta.addNode(new TimeControl(fLaunch), IModelDelta.STATE); + delta = delta.addNode(new ClockControl(fLaunch), IModelDelta.STATE); fireDelta(delta); } }, 0, 100); diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/SequencerContentProvider.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/SequencerContentProvider.java index b4c04b6f5..1f57c9b1a 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/SequencerContentProvider.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/SequencerContentProvider.java @@ -14,10 +14,11 @@ import javax.sound.midi.Sequencer; import javax.sound.midi.Track; import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.examples.core.midi.launcher.LengthControl; import org.eclipse.debug.examples.core.midi.launcher.MidiLaunch; import org.eclipse.debug.examples.core.midi.launcher.SequencerControl; import org.eclipse.debug.examples.core.midi.launcher.TempoControl; -import org.eclipse.debug.examples.core.midi.launcher.TimeControl; +import org.eclipse.debug.examples.core.midi.launcher.ClockControl; import org.eclipse.debug.internal.ui.model.elements.ElementContentProvider; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; @@ -37,7 +38,7 @@ public class SequencerContentProvider extends ElementContentProvider { if (IDebugUIConstants.ID_DEBUG_VIEW.equals(context.getId())) { return getTracks((MidiLaunch) element).length; } else if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(context.getId())) { - return 2; + return 3; } return 0; } @@ -63,7 +64,8 @@ public class SequencerContentProvider extends ElementContentProvider { public SequencerControl[] getControls(MidiLaunch launch) { return new SequencerControl[]{ new TempoControl(launch), - new TimeControl(launch) + new ClockControl(launch), + new LengthControl(launch) }; } diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/SequencerControlsModelProxy.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/SequencerControlsModelProxy.java index ac0e0b3a7..e200493fe 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/SequencerControlsModelProxy.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/SequencerControlsModelProxy.java @@ -17,6 +17,7 @@ import org.eclipse.debug.examples.core.midi.launcher.MidiLaunch; import org.eclipse.debug.examples.core.midi.launcher.SequencerControl; import org.eclipse.debug.internal.ui.viewers.update.DebugEventHandler; import org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy; +import org.eclipse.jface.viewers.Viewer; /** * Model proxy for a sequencer in the variables view. Listens @@ -33,6 +34,11 @@ public class SequencerControlsModelProxy extends EventHandlerModelProxy { private MidiLaunch fLaunch; /** + * Event handler + */ + private ControlEventHandler fHandler; + + /** * Constructs a model proxy to update based on changes in controls * for the associated sequencer. * @@ -42,6 +48,14 @@ public class SequencerControlsModelProxy extends EventHandlerModelProxy { fLaunch = launch; } + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy#installed(org.eclipse.jface.viewers.Viewer) + */ + public void installed(Viewer viewer) { + super.installed(viewer); + fHandler.init(); + } + /** * Returns the launch assocaited with this proxy. * @@ -55,7 +69,8 @@ public class SequencerControlsModelProxy extends EventHandlerModelProxy { * @see org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy#createEventHandlers() */ protected DebugEventHandler[] createEventHandlers() { - return new DebugEventHandler[]{new ControlEventHandler(this)}; + fHandler = new ControlEventHandler(this); + return new DebugEventHandler[]{fHandler}; } /* (non-Javadoc) diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/detailpanes/ClockSliderDetailPane.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/detailpanes/ClockSliderDetailPane.java new file mode 100644 index 000000000..234618f4a --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/detailpanes/ClockSliderDetailPane.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * 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; + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDetailPane#createControl(org.eclipse.swt.widgets.Composite) + */ + public Control createControl(Composite parent) { + fSlider = new Slider(parent, SWT.HORIZONTAL); + fSlider.setMinimum(0); + fSlider.setMaximum(1000); + fSlider.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + int selection = fSlider.getSelection(); + if (fControl != null) { + fControl.setValue(Integer.toString(selection)); + } + } + }); + return fSlider; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDetailPane#display(org.eclipse.jface.viewers.IStructuredSelection) + */ + 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); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDetailPane#dispose() + */ + public void dispose() { + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDetailPane#getDescription() + */ + public String getDescription() { + return "Location (seconds)"; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDetailPane#getID() + */ + public String getID() { + return ControlDetailPaneFactory.ID_CLOCK_SLIDER; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDetailPane#getName() + */ + public String getName() { + return "Clock Slider (seconds)"; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDetailPane#init(org.eclipse.ui.IWorkbenchPartSite) + */ + public void init(IWorkbenchPartSite partSite) { + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDetailPane#setFocus() + */ + public boolean setFocus() { + fSlider.setFocus(); + return true; + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/detailpanes/ControlDetailPaneFactory.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/detailpanes/ControlDetailPaneFactory.java index d258abf7d..10353fd57 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/detailpanes/ControlDetailPaneFactory.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/detailpanes/ControlDetailPaneFactory.java @@ -13,6 +13,7 @@ package org.eclipse.debug.examples.ui.midi.detailpanes; import java.util.HashSet; import java.util.Set; +import org.eclipse.debug.examples.core.midi.launcher.ClockControl; import org.eclipse.debug.examples.core.midi.launcher.TempoControl; import org.eclipse.debug.ui.IDetailPane; import org.eclipse.debug.ui.IDetailPaneFactory; @@ -29,6 +30,11 @@ public class ControlDetailPaneFactory implements IDetailPaneFactory { * Identifier for the tempo slider detail pane */ public static final String ID_TEMPO_SLIDER = "TEMPO_SLIDER"; + + /** + * Identifier for the clock slider detail pane + */ + public static final String ID_CLOCK_SLIDER = "CLOCK_SLIDER"; /* (non-Javadoc) * @see org.eclipse.debug.ui.IDetailPaneFactory#createDetailPane(java.lang.String) @@ -37,6 +43,9 @@ public class ControlDetailPaneFactory implements IDetailPaneFactory { if (ID_TEMPO_SLIDER.equals(paneID)) { return new TempoSliderDetailPane(); } + if (ID_CLOCK_SLIDER.equals(paneID)) { + return new ClockSliderDetailPane(); + } return null; } @@ -49,6 +58,9 @@ public class ControlDetailPaneFactory implements IDetailPaneFactory { if (element instanceof TempoControl) { return ID_TEMPO_SLIDER; } + if (element instanceof ClockControl) { + return ID_CLOCK_SLIDER; + } } return null; } @@ -60,6 +72,9 @@ public class ControlDetailPaneFactory implements IDetailPaneFactory { if (ID_TEMPO_SLIDER.equals(paneID)) { return "Tempo Slider"; } + if (ID_CLOCK_SLIDER.equals(paneID)) { + return "Clock Slider"; + } return null; } @@ -70,6 +85,9 @@ public class ControlDetailPaneFactory implements IDetailPaneFactory { if (ID_TEMPO_SLIDER.equals(paneID)) { return "Tempo Slider"; } + if (ID_CLOCK_SLIDER.equals(paneID)) { + return "Clock Slider"; + } return null; } @@ -83,6 +101,9 @@ public class ControlDetailPaneFactory implements IDetailPaneFactory { if (element instanceof TempoControl) { set.add(ID_TEMPO_SLIDER); } + if (element instanceof ClockControl) { + set.add(ID_CLOCK_SLIDER); + } } return set; } |