-/*******************************************************************************\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.modeling.ui.preferences;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\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.modeling.ui.Activator;\r
-import org.simantics.utils.page.PageDesc;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public final class DiagramPreferenceUtil {\r
-\r
- public static final String PLUGIN_ID = Activator.PLUGIN_ID;\r
-\r
- public static DiagramPreferences getDefaultPreferences() {\r
- return getPreferences(DefaultScope.INSTANCE);\r
- }\r
-\r
- /**\r
- * @return\r
- */\r
- public static DiagramPreferences getPreferences() {\r
- return getPreferences(InstanceScope.INSTANCE);\r
- }\r
-\r
- /**\r
- * @return\r
- */\r
- public static DiagramPreferences getPreferences(IScopeContext context) {\r
- IEclipsePreferences node = context.getNode(PLUGIN_ID);\r
- double gridSize = node.getDouble(DiagramPreferences.P_SNAP_GRID_SIZE, DiagramPreferences.DEFAULT_SNAP_GRID_SIZE);\r
- PageDesc pageDesc = getPageDesc(node);\r
- //System.out.println("GET pagedesc: " + pageDesc);\r
- //String pos = node.get(DiagramPreferences.P_DEFAULT_PAGE_ORIENTATION, DiagramPreferences.DEFAULT_PAGE_ORIENTATION.toString());\r
- //PageOrientation po = PageOrientation.valueOf(pos);\r
-\r
-// Margins margins = DiagramPreferences.DEFAULT_PAGE_MARGINS;\r
-// String marginString = node.get(DiagramPreferences.P_DEFAULT_PAGE_MARGINS, null);\r
-// if (marginString != null)\r
-// margins = PageDesc.deserializeMargins(marginString, margins);\r
-// pageDesc = pageDesc.withMargins(margins);\r
-\r
- boolean displayPage = node.getBoolean(DiagramPreferences.P_DISPLAY_PAGE_SIZE, DiagramPreferences.DEFAULT_DISPLAY_PAGE_SIZE);\r
- boolean displayMargins = node.getBoolean(DiagramPreferences.P_DISPLAY_MARGINS, DiagramPreferences.DEFAULT_DISPLAY_MARGINS);\r
- boolean displayGrid = node.getBoolean(DiagramPreferences.P_DISPLAY_MARGINS, DiagramPreferences.DEFAULT_DISPLAY_GRID);\r
- boolean displayRuler = node.getBoolean(DiagramPreferences.P_DISPLAY_MARGINS, DiagramPreferences.DEFAULT_DISPLAY_RULER);\r
-\r
- Map<String, Object> map = new HashMap<String, Object>();\r
- map.put(DiagramPreferences.P_SNAP_GRID_SIZE, gridSize);\r
- map.put(DiagramPreferences.P_DEFAULT_PAGE_SIZE, pageDesc);\r
-// map.put(DiagramPreferences.P_DEFAULT_PAGE_ORIENTATION, po);\r
-// map.put(DiagramPreferences.P_DEFAULT_PAGE_MARGINS, margins);\r
- map.put(DiagramPreferences.P_DISPLAY_PAGE_SIZE, displayPage);\r
- map.put(DiagramPreferences.P_DISPLAY_MARGINS, displayMargins);\r
- map.put(DiagramPreferences.P_DISPLAY_GRID, displayGrid);\r
- map.put(DiagramPreferences.P_DISPLAY_RULER, displayRuler);\r
-\r
- return new DiagramPreferences(node, map);\r
- }\r
-\r
- /**\r
- * @return\r
- * @throws BackingStoreException\r
- */\r
- public static void setPreferences(DiagramPreferences prefs) {\r
- _setPreferences(InstanceScope.INSTANCE, prefs);\r
- }\r
-\r
- /**\r
- * @return\r
- * @throws BackingStoreException\r
- */\r
- public static void flushPreferences(DiagramPreferences prefs) throws BackingStoreException {\r
- Preferences p = _setPreferences(InstanceScope.INSTANCE, prefs);\r
- p.flush();\r
- }\r
-\r
- /**\r
- * @return\r
- * @throws BackingStoreException\r
- */\r
- public static void setPreferences(IScopeContext context, DiagramPreferences prefs) {\r
- _setPreferences(context, prefs);\r
- }\r
-\r
- /**\r
- * @return\r
- * @throws BackingStoreException\r
- */\r
- private static IEclipsePreferences _setPreferences(IScopeContext context, DiagramPreferences prefs) {\r
- IEclipsePreferences node = context.getNode(PLUGIN_ID);\r
- //System.out.println("SET pagedesc: " + prefs.get(DiagramPreferences.P_DEFAULT_PAGE_SIZE));\r
- node.putDouble(DiagramPreferences.P_SNAP_GRID_SIZE, (Double) prefs.get(DiagramPreferences.P_SNAP_GRID_SIZE));\r
- node.put(DiagramPreferences.P_DEFAULT_PAGE_SIZE, PageDesc.serialize((PageDesc) prefs.get(DiagramPreferences.P_DEFAULT_PAGE_SIZE)));\r
-// node.put(DiagramPreferences.P_DEFAULT_PAGE_ORIENTATION, prefs.get(DiagramPreferences.P_DEFAULT_PAGE_ORIENTATION).toString());\r
-// node.put(DiagramPreferences.P_DEFAULT_PAGE_MARGINS, PageDesc.serialize((Margins) prefs.get(DiagramPreferences.P_DEFAULT_PAGE_MARGINS)));\r
- node.putBoolean(DiagramPreferences.P_DISPLAY_PAGE_SIZE, (Boolean) prefs.get(DiagramPreferences.P_DISPLAY_PAGE_SIZE));\r
- node.putBoolean(DiagramPreferences.P_DISPLAY_MARGINS, (Boolean) prefs.get(DiagramPreferences.P_DISPLAY_MARGINS));\r
- node.putBoolean(DiagramPreferences.P_DISPLAY_GRID, (Boolean) prefs.get(DiagramPreferences.P_DISPLAY_GRID));\r
- node.putBoolean(DiagramPreferences.P_DISPLAY_RULER, (Boolean) prefs.get(DiagramPreferences.P_DISPLAY_RULER));\r
- return node;\r
- }\r
-\r
- private static PageDesc getPageDesc(IEclipsePreferences node) {\r
- String desc = node.get(DiagramPreferences.P_DEFAULT_PAGE_SIZE, null);\r
- return PageDesc.deserialize(desc, DiagramPreferences.DEFAULT_PAGE_SIZE);\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.modeling.ui.preferences;
+
+import java.util.HashMap;
+import java.util.Map;
+
+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.modeling.ui.Activator;
+import org.simantics.utils.page.PageDesc;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public final class DiagramPreferenceUtil {
+
+ public static final String PLUGIN_ID = Activator.PLUGIN_ID;
+
+ public static DiagramPreferences getDefaultPreferences() {
+ return getPreferences(DefaultScope.INSTANCE);
+ }
+
+ /**
+ * @return
+ */
+ public static DiagramPreferences getPreferences() {
+ return getPreferences(InstanceScope.INSTANCE);
+ }
+
+ /**
+ * @return
+ */
+ public static DiagramPreferences getPreferences(IScopeContext context) {
+ IEclipsePreferences node = context.getNode(PLUGIN_ID);
+ double gridSize = node.getDouble(DiagramPreferences.P_SNAP_GRID_SIZE, DiagramPreferences.DEFAULT_SNAP_GRID_SIZE);
+ PageDesc pageDesc = getPageDesc(node);
+ //System.out.println("GET pagedesc: " + pageDesc);
+ //String pos = node.get(DiagramPreferences.P_DEFAULT_PAGE_ORIENTATION, DiagramPreferences.DEFAULT_PAGE_ORIENTATION.toString());
+ //PageOrientation po = PageOrientation.valueOf(pos);
+
+// Margins margins = DiagramPreferences.DEFAULT_PAGE_MARGINS;
+// String marginString = node.get(DiagramPreferences.P_DEFAULT_PAGE_MARGINS, null);
+// if (marginString != null)
+// margins = PageDesc.deserializeMargins(marginString, margins);
+// pageDesc = pageDesc.withMargins(margins);
+
+ boolean displayPage = node.getBoolean(DiagramPreferences.P_DISPLAY_PAGE_SIZE, DiagramPreferences.DEFAULT_DISPLAY_PAGE_SIZE);
+ boolean displayMargins = node.getBoolean(DiagramPreferences.P_DISPLAY_MARGINS, DiagramPreferences.DEFAULT_DISPLAY_MARGINS);
+ boolean displayGrid = node.getBoolean(DiagramPreferences.P_DISPLAY_MARGINS, DiagramPreferences.DEFAULT_DISPLAY_GRID);
+ boolean displayRuler = node.getBoolean(DiagramPreferences.P_DISPLAY_MARGINS, DiagramPreferences.DEFAULT_DISPLAY_RULER);
+
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put(DiagramPreferences.P_SNAP_GRID_SIZE, gridSize);
+ map.put(DiagramPreferences.P_DEFAULT_PAGE_SIZE, pageDesc);
+// map.put(DiagramPreferences.P_DEFAULT_PAGE_ORIENTATION, po);
+// map.put(DiagramPreferences.P_DEFAULT_PAGE_MARGINS, margins);
+ map.put(DiagramPreferences.P_DISPLAY_PAGE_SIZE, displayPage);
+ map.put(DiagramPreferences.P_DISPLAY_MARGINS, displayMargins);
+ map.put(DiagramPreferences.P_DISPLAY_GRID, displayGrid);
+ map.put(DiagramPreferences.P_DISPLAY_RULER, displayRuler);
+
+ return new DiagramPreferences(node, map);
+ }
+
+ /**
+ * @return
+ * @throws BackingStoreException
+ */
+ public static void setPreferences(DiagramPreferences prefs) {
+ _setPreferences(InstanceScope.INSTANCE, prefs);
+ }
+
+ /**
+ * @return
+ * @throws BackingStoreException
+ */
+ public static void flushPreferences(DiagramPreferences prefs) throws BackingStoreException {
+ Preferences p = _setPreferences(InstanceScope.INSTANCE, prefs);
+ p.flush();
+ }
+
+ /**
+ * @return
+ * @throws BackingStoreException
+ */
+ public static void setPreferences(IScopeContext context, DiagramPreferences prefs) {
+ _setPreferences(context, prefs);
+ }
+
+ /**
+ * @return
+ * @throws BackingStoreException
+ */
+ private static IEclipsePreferences _setPreferences(IScopeContext context, DiagramPreferences prefs) {
+ IEclipsePreferences node = context.getNode(PLUGIN_ID);
+ //System.out.println("SET pagedesc: " + prefs.get(DiagramPreferences.P_DEFAULT_PAGE_SIZE));
+ node.putDouble(DiagramPreferences.P_SNAP_GRID_SIZE, (Double) prefs.get(DiagramPreferences.P_SNAP_GRID_SIZE));
+ node.put(DiagramPreferences.P_DEFAULT_PAGE_SIZE, PageDesc.serialize((PageDesc) prefs.get(DiagramPreferences.P_DEFAULT_PAGE_SIZE)));
+// node.put(DiagramPreferences.P_DEFAULT_PAGE_ORIENTATION, prefs.get(DiagramPreferences.P_DEFAULT_PAGE_ORIENTATION).toString());
+// node.put(DiagramPreferences.P_DEFAULT_PAGE_MARGINS, PageDesc.serialize((Margins) prefs.get(DiagramPreferences.P_DEFAULT_PAGE_MARGINS)));
+ node.putBoolean(DiagramPreferences.P_DISPLAY_PAGE_SIZE, (Boolean) prefs.get(DiagramPreferences.P_DISPLAY_PAGE_SIZE));
+ node.putBoolean(DiagramPreferences.P_DISPLAY_MARGINS, (Boolean) prefs.get(DiagramPreferences.P_DISPLAY_MARGINS));
+ node.putBoolean(DiagramPreferences.P_DISPLAY_GRID, (Boolean) prefs.get(DiagramPreferences.P_DISPLAY_GRID));
+ node.putBoolean(DiagramPreferences.P_DISPLAY_RULER, (Boolean) prefs.get(DiagramPreferences.P_DISPLAY_RULER));
+ return node;
+ }
+
+ private static PageDesc getPageDesc(IEclipsePreferences node) {
+ String desc = node.get(DiagramPreferences.P_DEFAULT_PAGE_SIZE, null);
+ return PageDesc.deserialize(desc, DiagramPreferences.DEFAULT_PAGE_SIZE);
+ }
+
+}