]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/impl/Element.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / impl / Element.java
index e1b54d84e12d3f8e7a532a23a248413ce859ebcb..d8d31ec6d89f7bd225dfa3eec8b79576dd98a691 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.element.impl;\r
-\r
-import java.util.Map;\r
-\r
-import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.ElementHints;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.handler.ElementAdapter;\r
-import org.simantics.g2d.element.handler.LifeCycle;\r
-import org.simantics.utils.datastructures.hints.HintContext;\r
-\r
-/**\r
- * @author Toni Kalajainen\r
- */\r
-public class Element extends HintContext implements IElement {\r
-\r
-    /**\r
-     * Spawn brand new element to the world.\r
-     * The element is initialized.\r
-     * \r
-     * @param clazz\r
-     * @return\r
-     */\r
-    public static IElement clone(IElement cloneFrom)\r
-    {\r
-        IElement e = new Element(cloneFrom.getElementClass());\r
-        e.setHints(cloneFrom.getHints());\r
-        return e;\r
-    }\r
-\r
-    /**\r
-     * Spawn brand new element to the world.\r
-     * The element is initialized.\r
-     * \r
-     * @param clazz\r
-     * @return\r
-     */\r
-    public static IElement spawnNew(ElementClass clazz)\r
-    {\r
-        assert(clazz!=null);\r
-        IElement e = new Element(clazz);\r
-        Element.fireCreated(e);\r
-        return e;\r
-    }\r
-\r
-    /**\r
-     * Instantiate old element back into the world. Initialization is\r
-     * bypassed.\r
-     * \r
-     * @param clazz\r
-     * @param oldValues old values of the element (or null)\r
-     * @return\r
-     */\r
-    public static IElement instantiate(ElementClass clazz, Map<Key, Object> oldValues)\r
-    {\r
-        IElement e = new Element(clazz);\r
-        if (oldValues!=null)\r
-            e.setHints(oldValues);\r
-        return e;\r
-    }\r
-\r
-    private ElementClass clazz;\r
-    private IDiagram diagram;\r
-\r
-    public Element(ElementClass clazz)\r
-    {\r
-        assert(clazz!=null);\r
-        this.clazz = clazz;\r
-    }\r
-\r
-    @Override\r
-    public IDiagram getDiagram() {\r
-        assert(diagram!=null);\r
-        return diagram;\r
-    }\r
-\r
-    @Override\r
-    public IDiagram peekDiagram() {\r
-        return diagram;\r
-    }\r
-\r
-    @Override\r
-    public ElementClass getElementClass() {\r
-        return clazz;\r
-    }\r
-\r
-    /**\r
-     * This is an internal mechanism to be used only when in complete\r
-     * comprehension of the effects. Care must be taken to install the right\r
-     * hints when setting a new element class.\r
-     * \r
-     * @param newClass\r
-     * @param newHints\r
-     */\r
-    public void setElementClass(ElementClass newClass) {\r
-        if (newClass == null)\r
-            throw new IllegalArgumentException("null element class");\r
-        clazz = newClass;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        String text = getHint(ElementHints.KEY_TEXT);\r
-        if (text==null) text = "";\r
-        Object dada = getHint(ElementHints.KEY_OBJECT);\r
-        if (dada==null) dada = "";\r
-        String clazzId = clazz.getId();\r
-        String clazzStr = clazzId != null && !clazzId.isEmpty() ? clazzId\r
-                : (clazz.getClass().getSimpleName() + "@" + clazz.hashCode());\r
-        return clazzStr + "[" + super.toString() + " " + text + " " + dada + "]";\r
-    }\r
-\r
-    @Override\r
-    public void addedToDiagram(IDiagram diagram) {\r
-        this.diagram = diagram;\r
-    }\r
-\r
-    @Override\r
-    public void destroy() {\r
-        Element.fireDestroyed(this);\r
-    }\r
-\r
-    public static void fireDestroyed(IElement e)\r
-    {\r
-        for (LifeCycle lc : e.getElementClass().getItemsByClass(LifeCycle.class))\r
-            lc.onElementDestroyed(e);\r
-    }\r
-\r
-    public static void fireCreated(IElement e)\r
-    {\r
-        for (LifeCycle lc : e.getElementClass().getItemsByClass(LifeCycle.class))\r
-            lc.onElementCreated(e);\r
-    }\r
-\r
-    @Override\r
-    public void dispose() {\r
-        clearWithoutNotification();\r
-    }\r
-\r
-    public <T> T adapt(Class<T> adapter) {\r
-        for (ElementAdapter ea : clazz.getItemsByClass(ElementAdapter.class))\r
-        {\r
-            T result = ea.adapt(this, adapter);\r
-            if (result!=null) return result;\r
-        }\r
-        return null;\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.element.impl;
+
+import java.util.Map;
+
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.ElementHints;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.ElementAdapter;
+import org.simantics.g2d.element.handler.LifeCycle;
+import org.simantics.utils.datastructures.hints.HintContext;
+
+/**
+ * @author Toni Kalajainen
+ */
+public class Element extends HintContext implements IElement {
+
+    /**
+     * Spawn brand new element to the world.
+     * The element is initialized.
+     * 
+     * @param clazz
+     * @return
+     */
+    public static IElement clone(IElement cloneFrom)
+    {
+        IElement e = new Element(cloneFrom.getElementClass());
+        e.setHints(cloneFrom.getHints());
+        return e;
+    }
+
+    /**
+     * Spawn brand new element to the world.
+     * The element is initialized.
+     * 
+     * @param clazz
+     * @return
+     */
+    public static IElement spawnNew(ElementClass clazz)
+    {
+        assert(clazz!=null);
+        IElement e = new Element(clazz);
+        Element.fireCreated(e);
+        return e;
+    }
+
+    /**
+     * Instantiate old element back into the world. Initialization is
+     * bypassed.
+     * 
+     * @param clazz
+     * @param oldValues old values of the element (or null)
+     * @return
+     */
+    public static IElement instantiate(ElementClass clazz, Map<Key, Object> oldValues)
+    {
+        IElement e = new Element(clazz);
+        if (oldValues!=null)
+            e.setHints(oldValues);
+        return e;
+    }
+
+    private ElementClass clazz;
+    private IDiagram diagram;
+
+    public Element(ElementClass clazz)
+    {
+        assert(clazz!=null);
+        this.clazz = clazz;
+    }
+
+    @Override
+    public IDiagram getDiagram() {
+        assert(diagram!=null);
+        return diagram;
+    }
+
+    @Override
+    public IDiagram peekDiagram() {
+        return diagram;
+    }
+
+    @Override
+    public ElementClass getElementClass() {
+        return clazz;
+    }
+
+    /**
+     * This is an internal mechanism to be used only when in complete
+     * comprehension of the effects. Care must be taken to install the right
+     * hints when setting a new element class.
+     * 
+     * @param newClass
+     * @param newHints
+     */
+    public void setElementClass(ElementClass newClass) {
+        if (newClass == null)
+            throw new IllegalArgumentException("null element class");
+        clazz = newClass;
+    }
+
+    @Override
+    public String toString() {
+        String text = getHint(ElementHints.KEY_TEXT);
+        if (text==null) text = "";
+        Object dada = getHint(ElementHints.KEY_OBJECT);
+        if (dada==null) dada = "";
+        String clazzId = clazz.getId();
+        String clazzStr = clazzId != null && !clazzId.isEmpty() ? clazzId
+                : (clazz.getClass().getSimpleName() + "@" + clazz.hashCode());
+        return clazzStr + "[" + super.toString() + " " + text + " " + dada + "]";
+    }
+
+    @Override
+    public void addedToDiagram(IDiagram diagram) {
+        this.diagram = diagram;
+    }
+
+    @Override
+    public void destroy() {
+        Element.fireDestroyed(this);
+    }
+
+    public static void fireDestroyed(IElement e)
+    {
+        for (LifeCycle lc : e.getElementClass().getItemsByClass(LifeCycle.class))
+            lc.onElementDestroyed(e);
+    }
+
+    public static void fireCreated(IElement e)
+    {
+        for (LifeCycle lc : e.getElementClass().getItemsByClass(LifeCycle.class))
+            lc.onElementCreated(e);
+    }
+
+    @Override
+    public void dispose() {
+        clearWithoutNotification();
+    }
+
+    public <T> T adapt(Class<T> adapter) {
+        for (ElementAdapter ea : clazz.getItemsByClass(ElementAdapter.class))
+        {
+            T result = ea.adapt(this, adapter);
+            if (result!=null) return result;
+        }
+        return null;
+    }
+
+}