]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/Node.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / Node.java
index fe66f2b79650c67f027db25f7850a3b037195664..7ce4611a38e0afd2a807e4d409ba324df6e34285 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
+/*******************************************************************************
+ * 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.scenegraph;
 
-import java.beans.PropertyChangeListener;\r
-\r
-import org.simantics.scenegraph.utils.NodeUtil;\r
-\r
+import java.beans.PropertyChangeListener;
+
+import org.simantics.scenegraph.utils.NodeUtil;
+
 /**
  * @author J-P
  */
 public abstract class Node implements INode {
-\r
-    private static final long                  serialVersionUID       = -5540999051056414851L;\r
-\r
-    public transient static long               IDCOUNTER              = 1;\r
-
-    protected transient ParentNode<?>          parent                 = null;\r
-    protected transient Location               location               = Location.LOCAL;\r
-\r
+
+    private static final long                  serialVersionUID       = -5540999051056414851L;
+
+    public transient static long               IDCOUNTER              = 1;
+
+    protected transient ParentNode<?>          parent                 = null;
+    protected transient Location               location               = Location.LOCAL;
+
     // This is for internal server communications. Do not touch.
-    // Support for only one listener should be enough, thus we don't need PropertyChangeSupport\r
+    // Support for only one listener should be enough, thus we don't need PropertyChangeSupport
     protected transient PropertyChangeListener propertyChangeListener = null;
 
-    protected Long                             id                     = IDCOUNTER++;\r
-\r
-    /**\r
-     * @see org.simantics.scenegraph.INode#getId()\r
-     */\r
+    protected Long                             id                     = IDCOUNTER++;
+
+    /**
+     * @see org.simantics.scenegraph.INode#getId()
+     */
     public Long getId() {
         return id;
     }
 
-    /**\r
-     * @see org.simantics.scenegraph.INode#getParent()\r
-     */\r
+    /**
+     * @see org.simantics.scenegraph.INode#getParent()
+     */
     public ParentNode<?> getParent() {
         return parent;
     }
 
-    /**\r
-     * @see org.simantics.scenegraph.INode#setParent(org.simantics.scenegraph.ParentNode)\r
-     */\r
+    /**
+     * @see org.simantics.scenegraph.INode#setParent(org.simantics.scenegraph.ParentNode)
+     */
     public void setParent(ParentNode<?> parent) {
         this.parent = parent;
     }
 
-    /**\r
-     * The default implementation of {@link #getRootNode()} always asks for the\r
-     * root node from the parent. Scene graph leaf nodes are never considered to\r
-     * be real scene graph root nodes, although they are can be thought of as\r
-     * such when they are not attached to any scene graph. This implementation\r
-     * prevents the need to have a separate rootNodeCache field in all nodes.\r
-     * \r
-     * @see org.simantics.scenegraph.INode#getRootNode()\r
-     */\r
-    public ParentNode<?> getRootNode() {\r
-        return parent != null ? parent.getRootNode() : null;\r
-    }\r
-\r
+    /**
+     * The default implementation of {@link #getRootNode()} always asks for the
+     * root node from the parent. Scene graph leaf nodes are never considered to
+     * be real scene graph root nodes, although they are can be thought of as
+     * such when they are not attached to any scene graph. This implementation
+     * prevents the need to have a separate rootNodeCache field in all nodes.
+     * 
+     * @see org.simantics.scenegraph.INode#getRootNode()
+     */
+    public ParentNode<?> getRootNode() {
+        return parent != null ? parent.getRootNode() : null;
+    }
+
     public void remove() {
-        if (parent != null) {\r
+        if (parent != null) {
             parent.asyncRemoveNode(this);
         }
     }
 
-    /**\r
-     * @see org.simantics.scenegraph.INode#init()\r
-     */\r
+    /**
+     * @see org.simantics.scenegraph.INode#init()
+     */
     public void init() {
-    }\r
-    \r
-    public void attach() {\r
-    }\r
+    }
+    
+    public void attach() {
+    }
     
 
-    /**\r
-     * @see org.simantics.scenegraph.INode#cleanup()\r
-     */\r
+    /**
+     * @see org.simantics.scenegraph.INode#cleanup()
+     */
     public void cleanup() {
-        retractMapping();\r
-    }\r
-\r
-    /**\r
-     * @see org.simantics.scenegraph.INode#delete()\r
-     */\r
-    public void delete() {\r
-        // 1. Remove this node from parent\r
-        parent.asyncRemoveNode(this);\r
-    }\r
-\r
-    /**\r
-     * Remove any ID<->Node mapping this node might have in the scene graph's\r
-     * {@link LookupService}.\r
-     */\r
-    protected void retractMapping() {\r
-        NodeUtil.tryUnmap(this);\r
-    }\r
-\r
-    public <TC> TC appendParent(String id, Class<TC> nc) {\r
-        assert(parent != null);\r
-\r
-        // 0. Find identifier from parent\r
-        String identifier = null;\r
-        for(String s : parent.children.keySet()) { // FIXME: should not be this complicated\r
-            if(parent.children.get(s) == this) { // Find this from parent child list\r
-                identifier = s;\r
-                break;\r
-            }\r
-        }\r
-        if (identifier == null)\r
-            identifier = "" + this.id;\r
-\r
-        // 1. Remove this node from original parent\r
-        parent.unlinkChild(this);\r
-\r
-        // 2. Add new node under parent\r
-        TC instance = parent.addNode(id, nc);\r
-\r
-        // 3. Add this node under new parent\r
-        ((ParentNode<?>)instance).appendChild(identifier, this);\r
-\r
-        return instance;\r
-    }\r
+        retractMapping();
+    }
+
+    /**
+     * @see org.simantics.scenegraph.INode#delete()
+     */
+    public void delete() {
+        // 1. Remove this node from parent
+        parent.asyncRemoveNode(this);
+    }
+
+    /**
+     * Remove any ID<->Node mapping this node might have in the scene graph's
+     * {@link LookupService}.
+     */
+    protected void retractMapping() {
+        NodeUtil.tryUnmap(this);
+    }
+
+    public <TC> TC appendParent(String id, Class<TC> nc) {
+        assert(parent != null);
+
+        // 0. Find identifier from parent
+        String identifier = null;
+        for(String s : parent.children.keySet()) { // FIXME: should not be this complicated
+            if(parent.children.get(s) == this) { // Find this from parent child list
+                identifier = s;
+                break;
+            }
+        }
+        if (identifier == null)
+            identifier = "" + this.id;
+
+        // 1. Remove this node from original parent
+        parent.unlinkChild(this);
+
+        // 2. Add new node under parent
+        TC instance = parent.addNode(id, nc);
+
+        // 3. Add this node under new parent
+        ((ParentNode<?>)instance).appendChild(identifier, this);
+
+        return instance;
+    }
 
     @Override
     public String toString() {
@@ -147,42 +147,42 @@ public abstract class Node implements INode {
         if (pos >= 0)
             name = name.substring(0, pos);
         return name;
-    }\r
-\r
-    /**\r
-     * Associates this node with the specified ID in the {@link ILookupService}\r
-     * that must be offered by the scene graph root node. After this\r
-     * association, one can use {@link NodeUtil#lookup(INode, String)} to lookup\r
-     * this node from the scene graph by its ID.\r
-     * \r
-     * @param id\r
-     * @throws UnsupportedOperationException if no ILookupService is available\r
-     *         for this node\r
-     */\r
-    @ClientSide\r
-    public void setLookupId(String id) {\r
-        NodeUtil.getLookupService(this).map(id, this);\r
-    }\r
-\r
-    /**\r
-     * A shorthand utility for {@link NodeUtil#lookup(INode, String, Class)}.\r
-     * \r
-     * @param id\r
-     * @param clazz\r
-     * @return\r
-     */\r
-    protected <T extends INode> T lookupNode(String id, Class<T> clazz) {\r
-        return NodeUtil.lookup(this, id, clazz);\r
-    }\r
-\r
-    /**\r
-     * A shorthand utility for {@link NodeUtil#lookupId(INode)}).\r
-     * \r
-     * @param node\r
-     * @return\r
-     */\r
-    protected String lookupId(INode node) {\r
-        return NodeUtil.lookupId(node);\r
-    }\r
-\r
+    }
+
+    /**
+     * Associates this node with the specified ID in the {@link ILookupService}
+     * that must be offered by the scene graph root node. After this
+     * association, one can use {@link NodeUtil#lookup(INode, String)} to lookup
+     * this node from the scene graph by its ID.
+     * 
+     * @param id
+     * @throws UnsupportedOperationException if no ILookupService is available
+     *         for this node
+     */
+    @ClientSide
+    public void setLookupId(String id) {
+        NodeUtil.getLookupService(this).map(id, this);
+    }
+
+    /**
+     * A shorthand utility for {@link NodeUtil#lookup(INode, String, Class)}.
+     * 
+     * @param id
+     * @param clazz
+     * @return
+     */
+    protected <T extends INode> T lookupNode(String id, Class<T> clazz) {
+        return NodeUtil.lookup(this, id, clazz);
+    }
+
+    /**
+     * A shorthand utility for {@link NodeUtil#lookupId(INode)}).
+     * 
+     * @param node
+     * @return
+     */
+    protected String lookupId(INode node) {
+        return NodeUtil.lookupId(node);
+    }
+
 }