]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/PlainElementPropertySetter.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / elementclass / PlainElementPropertySetter.java
index 12bf6bc04754259a4db6e3ff86c6287005e4f8fd..2500787369959c9a0a99ca3143ed90e08a425b07 100644 (file)
-/*******************************************************************************\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.g2d.elementclass;\r
-\r
-import org.simantics.g2d.element.ElementHints;\r
-import org.simantics.g2d.element.ElementHints.Properties;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.handler.PropertySetter;\r
-import org.simantics.scenegraph.INode;\r
-import org.simantics.scenegraph.Node;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.scenegraph.g2d.IG2DNode;\r
-import org.simantics.scenegraph.g2d.nodes.AnimatedSVGNode;\r
-import org.simantics.scenegraph.utils.NodeUtil;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
-import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
-\r
-public class PlainElementPropertySetter implements PropertySetter {\r
-\r
-    private static final long serialVersionUID = -3165827599737160621L;\r
-\r
-    public static final PlainElementPropertySetter INSTANCE = new PlainElementPropertySetter(ElementHints.KEY_SG_NODE);\r
-    public static final Key KEY_PROFILE_PROPERTIES = new KeyOf(Properties.class, "ELEMENT_PROFILE_PROPERTIES");\r
-    private final Key key;\r
-\r
-    public PlainElementPropertySetter(Key key) {\r
-        this.key = key;\r
-    }\r
-\r
-    @Override\r
-    public void overrideProperties(IElement e, Properties properties) {\r
-        Properties profile = e.getHint(KEY_PROFILE_PROPERTIES);\r
-        if(profile == null) {\r
-            profile = new Properties();\r
-            e.setHint(KEY_PROFILE_PROPERTIES, profile);\r
-        }\r
-        profile.clear();\r
-        profile.putAll(properties);\r
-    }\r
-\r
-    @Override\r
-    public void overrideProperty(IElement e, String name, Object value) {\r
-        //System.out.println(name+"="+value);\r
-        Properties profile = e.getHint(KEY_PROFILE_PROPERTIES);\r
-        if(profile == null) {\r
-            profile = new Properties();\r
-            e.setHint(KEY_PROFILE_PROPERTIES, profile);\r
-        }\r
-        profile.put(name, value);\r
-    }\r
-\r
-    private Node findSingle(Node node, Class<?> clazz) {\r
-\r
-//             System.err.println("findSingle " + node);\r
-\r
-        if(clazz.isInstance(node)) return node;\r
-\r
-        if(node instanceof G2DParentNode) {\r
-            G2DParentNode parent = (G2DParentNode)node;\r
-            Node found = null;\r
-            for(IG2DNode child : parent.getNodes()) {\r
-                if(child instanceof Node) {\r
-                    Node test = findSingle((Node)child, clazz);\r
-                    if(test != null) {\r
-                        if(found == null) found = test;\r
-                        else return null;\r
-                    }\r
-                }\r
-            }\r
-            return found;\r
-        } else {\r
-            return null;\r
-        }\r
-\r
-    }\r
-\r
-    private Node findAnimatedNode(Node node) {\r
-        Node animated = findSingle(node, AnimatedSVGNode.class);\r
-        if(animated != null) return animated;\r
-        else return node;\r
-    }\r
-\r
-    @Override\r
-    public void syncPropertiesToNode(IElement e) {\r
-        Properties profile = e.getHint(KEY_PROFILE_PROPERTIES);\r
-        Properties element = e.getHint(ElementHints.KEY_ELEMENT_PROPERTIES);\r
-\r
-        Node node = e.getHint(this.key);\r
-        if(node == null) return; // FIXME\r
-\r
-        node = findAnimatedNode(node);\r
-\r
-        Properties concat = new Properties();\r
-        if(element != null) {\r
-            for(String key : element.keySet()) {\r
-                concat.put(key, element.get(key));\r
-            }\r
-        }\r
-\r
-        if(profile != null) {\r
-            for(String key : profile.keySet()) {\r
-                concat.put(key, profile.get(key));\r
-            }\r
-        }\r
-\r
-        for(String property : concat.keySet()) {\r
-            //System.out.println("sync: "+property+" | "+concat.get(property));\r
-            // TODO: property names containing dots "." should be splitted and treated as hierarchical properties \r
-            if(property.contains(".")) {\r
-                String t[] = property.split("\\.");\r
-                if(t.length == 2) { // FIXME: add support for deeper hierarchy\r
-                    String child_name = t[0];\r
-                    String property_name = t[1];\r
-                    if(node instanceof G2DParentNode) {\r
-                        INode child = NodeUtil.findChildById((G2DParentNode)node, child_name);\r
-                        if(child != null)\r
-                            NodeUtil.setPropertyIfSupported(property_name, concat.get(property), child);\r
-                    }\r
-                }\r
-            } else {\r
-                NodeUtil.setPropertyIfSupported(property, concat.get(property), node);\r
-            }\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.g2d.elementclass;
+
+import org.simantics.g2d.element.ElementHints;
+import org.simantics.g2d.element.ElementHints.Properties;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.PropertySetter;
+import org.simantics.scenegraph.INode;
+import org.simantics.scenegraph.Node;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.IG2DNode;
+import org.simantics.scenegraph.g2d.nodes.AnimatedSVGNode;
+import org.simantics.scenegraph.utils.NodeUtil;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
+
+public class PlainElementPropertySetter implements PropertySetter {
+
+    private static final long serialVersionUID = -3165827599737160621L;
+
+    public static final PlainElementPropertySetter INSTANCE = new PlainElementPropertySetter(ElementHints.KEY_SG_NODE);
+    public static final Key KEY_PROFILE_PROPERTIES = new KeyOf(Properties.class, "ELEMENT_PROFILE_PROPERTIES");
+    private final Key key;
+
+    public PlainElementPropertySetter(Key key) {
+        this.key = key;
+    }
+
+    @Override
+    public void overrideProperties(IElement e, Properties properties) {
+        Properties profile = e.getHint(KEY_PROFILE_PROPERTIES);
+        if(profile == null) {
+            profile = new Properties();
+            e.setHint(KEY_PROFILE_PROPERTIES, profile);
+        }
+        profile.clear();
+        profile.putAll(properties);
+    }
+
+    @Override
+    public void overrideProperty(IElement e, String name, Object value) {
+        //System.out.println(name+"="+value);
+        Properties profile = e.getHint(KEY_PROFILE_PROPERTIES);
+        if(profile == null) {
+            profile = new Properties();
+            e.setHint(KEY_PROFILE_PROPERTIES, profile);
+        }
+        profile.put(name, value);
+    }
+
+    private Node findSingle(Node node, Class<?> clazz) {
+
+//             System.err.println("findSingle " + node);
+
+        if(clazz.isInstance(node)) return node;
+
+        if(node instanceof G2DParentNode) {
+            G2DParentNode parent = (G2DParentNode)node;
+            Node found = null;
+            for(IG2DNode child : parent.getNodes()) {
+                if(child instanceof Node) {
+                    Node test = findSingle((Node)child, clazz);
+                    if(test != null) {
+                        if(found == null) found = test;
+                        else return null;
+                    }
+                }
+            }
+            return found;
+        } else {
+            return null;
+        }
+
+    }
+
+    private Node findAnimatedNode(Node node) {
+        Node animated = findSingle(node, AnimatedSVGNode.class);
+        if(animated != null) return animated;
+        else return node;
+    }
+
+    @Override
+    public void syncPropertiesToNode(IElement e) {
+        Properties profile = e.getHint(KEY_PROFILE_PROPERTIES);
+        Properties element = e.getHint(ElementHints.KEY_ELEMENT_PROPERTIES);
+
+        Node node = e.getHint(this.key);
+        if(node == null) return; // FIXME
+
+        node = findAnimatedNode(node);
+
+        Properties concat = new Properties();
+        if(element != null) {
+            for(String key : element.keySet()) {
+                concat.put(key, element.get(key));
+            }
+        }
+
+        if(profile != null) {
+            for(String key : profile.keySet()) {
+                concat.put(key, profile.get(key));
+            }
+        }
+
+        for(String property : concat.keySet()) {
+            //System.out.println("sync: "+property+" | "+concat.get(property));
+            // TODO: property names containing dots "." should be splitted and treated as hierarchical properties 
+            if(property.contains(".")) {
+                String t[] = property.split("\\.");
+                if(t.length == 2) { // FIXME: add support for deeper hierarchy
+                    String child_name = t[0];
+                    String property_name = t[1];
+                    if(node instanceof G2DParentNode) {
+                        INode child = NodeUtil.findChildById((G2DParentNode)node, child_name);
+                        if(child != null)
+                            NodeUtil.setPropertyIfSupported(property_name, concat.get(property), child);
+                    }
+                }
+            } else {
+                NodeUtil.setPropertyIfSupported(property, concat.get(property), node);
+            }
+        }
+    }
+}