From 303ae1266095df51e5ca9e2056403d151efd1b66 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 20 Oct 2011 13:58:18 +0000 Subject: [PATCH] Playback reload and rounding of time label git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@22897 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/plugin.xml | 37 +++++++++++++++++-- .../PlaybackReloadHandler.java | 24 ++++++++++++ .../ui/menu/PlaybackSliderContribution.java | 19 +++++++--- .../widgets/expressions/StockExpression.java | 3 +- 4 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 0f62b299..06b479bb 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -244,7 +244,8 @@ hoverIcon="platform:/plugin/com.famfamfam.silk/icons/control_eject_blue.png" icon="platform:/plugin/com.famfamfam.silk/icons/control_eject.png" id="org.simantics.sysdyn.ui.dispose.button" - label="Quit Experiment"> + label="Quit Experiment" + tooltip="Quit Experiment"> @@ -284,7 +285,8 @@ icon="platform:/plugin/com.famfamfam.silk/icons/control_start.png" id="org.simantics.sysdyn.ui.playbackReset.button" label="Reset" - style="push"> + style="push" + tooltip="Reset"> @@ -304,7 +306,8 @@ icon="platform:/plugin/com.famfamfam.silk/icons/control_play.png" id="org.simantics.sysdyn.ui.playback.button" label="Start playback" - style="pulldown"> + style="pulldown" + tooltip="Start playback"> @@ -334,12 +337,33 @@ + + + + + + + + + + + label="Quit Experiment" + tooltip="Quit Experiment"> @@ -862,6 +886,11 @@ id="org.simantics.sysdyn.ui.playbackReset" name="Reset Playback"> + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java new file mode 100644 index 00000000..e7d97445 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java @@ -0,0 +1,24 @@ +package org.simantics.sysdyn.ui.handlers.simulationPlayback; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; +import org.simantics.ui.SimanticsUI; + +public class PlaybackReloadHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment)) + return null; + SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment; + spe.simulate(true); + return null; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/menu/PlaybackSliderContribution.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/menu/PlaybackSliderContribution.java index e589c31d..a0c15aab 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/menu/PlaybackSliderContribution.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/menu/PlaybackSliderContribution.java @@ -1,5 +1,8 @@ package org.simantics.sysdyn.ui.menu; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; + import org.eclipse.jface.action.ToolBarContributionItem; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; @@ -72,15 +75,21 @@ public class PlaybackSliderContribution extends ToolBarContributionItem { s.setThumb(1); final Label label = new Label(composite, SWT.NONE); - GridDataFactory.fillDefaults().hint(50, SWT.DEFAULT).applyTo(label); + GridDataFactory.fillDefaults().hint(70, SWT.DEFAULT).applyTo(label); label.setText("0.0"); - ti.setWidth(250); + ti.setWidth(270); ti.setControl(composite); startTime = numbers[0]; endTime = numbers[1]; - + final DecimalFormat format = new DecimalFormat(); + format.setMinimumFractionDigits(0); + format.setMaximumFractionDigits(2); + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + symbols.setDecimalSeparator('.'); + symbols.setGroupingSeparator(' '); + format.setDecimalFormatSymbols(symbols); s.addSelectionListener(new SelectionListener() { @Override @@ -89,7 +98,7 @@ public class PlaybackSliderContribution extends ToolBarContributionItem { Double time = s.getSelection() / 99.0 * (endTime - startTime) + startTime; spe.setTimeAndContinue(time); if(!label.isDisposed()) { - label.setText(time.toString()); + label.setText(format.format(time)); } } @@ -112,7 +121,7 @@ public class PlaybackSliderContribution extends ToolBarContributionItem { public void run() { int value = (int) ((spe.getTime() - startTime) / (endTime - startTime) * 99); s.setSelection(value); - label.setText("" + spe.getTime()); + label.setText(format.format(spe.getTime())); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java index 4f9698b3..96d833dc 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java @@ -96,7 +96,8 @@ public class StockExpression implements IExpression { public String perform(ReadGraph graph) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); if (graph.isInstanceOf(expression, sr.StockExpression)) { - return graph.getRelatedValue(expression, sr.HasInitialEquation); + String initialEquation = graph.getPossibleRelatedValue(expression, sr.HasInitialEquation); + return initialEquation != null ? initialEquation : ""; } else { return ""; } -- 2.47.1