-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.simulation.ui.preferences;\r
-\r
-import org.eclipse.core.runtime.preferences.DefaultScope;\r
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;\r
-import org.eclipse.core.runtime.preferences.IScopeContext;\r
-import org.eclipse.core.runtime.preferences.InstanceScope;\r
-import org.osgi.service.prefs.BackingStoreException;\r
-import org.osgi.service.prefs.Preferences;\r
-import org.simantics.simulation.ui.Activator;\r
-\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public final class SimulationPreferenceUtil {\r
-\r
- public static SimulationPreferences getDefaultPrefs() {\r
- return getPrefs(DefaultScope.INSTANCE);\r
- }\r
-\r
- /**\r
- * @return\r
- */\r
- public static SimulationPreferences getPrefs() {\r
- return getPrefs(InstanceScope.INSTANCE);\r
- }\r
-\r
- /**\r
- * @return\r
- */\r
- public static SimulationPreferences getPrefs(IScopeContext context) {\r
- IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);\r
- double stepDuration = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, SimulationPreferences.DEFAULT_SIMULATION_STEP_DURATION);\r
-\r
- return new SimulationPreferences(node, stepDuration);\r
- }\r
-\r
- /**\r
- * @return\r
- * @throws BackingStoreException \r
- */\r
- public static void setPrefs(SimulationPreferences prefs) {\r
- setPrefs(InstanceScope.INSTANCE, prefs);\r
- }\r
-\r
- /**\r
- * @return\r
- * @throws BackingStoreException \r
- */\r
- public static void flushPrefs(SimulationPreferences prefs) throws BackingStoreException {\r
- Preferences p = _setPrefs(InstanceScope.INSTANCE, prefs);\r
- p.flush();\r
- }\r
-\r
- /**\r
- * @return\r
- * @throws BackingStoreException \r
- */\r
- public static void setPrefs(IScopeContext context, SimulationPreferences prefs) {\r
- _setPrefs(context, prefs);\r
- }\r
-\r
- /**\r
- * @return\r
- * @throws BackingStoreException \r
- */\r
- private static IEclipsePreferences _setPrefs(IScopeContext context, SimulationPreferences prefs) {\r
- IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);\r
- node.putDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, prefs.stepDuration);\r
- return node;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.simulation.ui.preferences;
+
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+import org.simantics.simulation.ui.Activator;
+import org.simantics.simulation.ui.preferences.SimulationPreferences.StepMode;
+
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public final class SimulationPreferenceUtil {
+
+ public static SimulationPreferences getDefaultPrefs() {
+ return getPrefs(DefaultScope.INSTANCE);
+ }
+
+ /**
+ * @return
+ */
+ public static SimulationPreferences getPrefs() {
+ return getPrefs(InstanceScope.INSTANCE);
+ }
+
+ /**
+ * @return
+ */
+ public static SimulationPreferences getPrefs(IScopeContext context) {
+ IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);
+ double stepDuration = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, SimulationPreferences.DEFAULT_SIMULATION_STEP_DURATION);
+ double stepEndTime = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_END_TIME, SimulationPreferences.DEFAULT_SIMULATION_STEP_END_TIME);
+ int stepMode = node.getInt(SimulationPreferences.P_SIMULATION_STEP_MODE, SimulationPreferences.DEFAULT_SIMULATION_STEP_MODE.ordinal());
+
+ return new SimulationPreferences(node, stepDuration, stepEndTime, StepMode.fromInt(stepMode));
+ }
+
+ /**
+ * @return
+ * @throws BackingStoreException
+ */
+ public static void setPrefs(SimulationPreferences prefs) {
+ setPrefs(InstanceScope.INSTANCE, prefs);
+ }
+
+ /**
+ * @return
+ * @throws BackingStoreException
+ */
+ public static void flushPrefs(SimulationPreferences prefs) throws BackingStoreException {
+ Preferences p = _setPrefs(InstanceScope.INSTANCE, prefs);
+ p.flush();
+ }
+
+ /**
+ * @return
+ * @throws BackingStoreException
+ */
+ public static void setPrefs(IScopeContext context, SimulationPreferences prefs) {
+ _setPrefs(context, prefs);
+ }
+
+ /**
+ * @return
+ * @throws BackingStoreException
+ */
+ private static IEclipsePreferences _setPrefs(IScopeContext context, SimulationPreferences prefs) {
+ IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);
+ node.putDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, prefs.stepDuration);
+ node.putDouble(SimulationPreferences.P_SIMULATION_STEP_END_TIME, prefs.stepEndTime);
+ node.putInt(SimulationPreferences.P_SIMULATION_STEP_MODE, prefs.stepMode.ordinal());
+ return node;
+ }
+
+}