]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Use ListenerList with G3D nodes 22/3422/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 29 Oct 2019 15:59:50 +0000 (17:59 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 29 Oct 2019 15:59:50 +0000 (17:59 +0200)
gitlab #42

Change-Id: I9ba6f84592c4122467608d72b45be592e259c0b2

org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/INode.java
org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/Node.java

index 5a0297af7ca290f4bf398ae695a9112055526850..8dfef39d84c3079b217b82478328af7b08f961ef 100644 (file)
@@ -11,7 +11,7 @@
  *******************************************************************************/
 package org.simantics.g3d.scenegraph.base;
 
-import java.util.List;
+import org.eclipse.core.runtime.ListenerList;
 
 
 
@@ -63,6 +63,6 @@ public interface INode {
        public void addListener(NodeListener listener);
        public void removeListener(NodeListener listener);
        
-       public List<NodeListener> getListeners();
+       public ListenerList<NodeListener> getListeners();
 
 }
index f7fe9eded0e0d1e606814e5b6556af2da85b5096..6d122930a3e2be155771d4b99d0e313cbf39d7c9 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * 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.g3d.scenegraph.base;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-\r
-public abstract class Node implements INode {\r
-       public transient static long               IDCOUNTER              = 1;\r
-       protected transient ParentNode<?>          parent                 = null;\r
-       protected transient String                                 parentName                     = null; \r
-       protected Long                             id                     = IDCOUNTER++;\r
-       \r
-\r
-       public Long getId() {\r
-               return id;\r
-       }\r
-\r
-\r
-       public ParentNode<?> getParent() {\r
-               return parent;\r
-       }\r
-\r
-       \r
-       @Override\r
-       public String getParentRel() {\r
-               return parentName;\r
-       }\r
-       \r
-       public void setParent(ParentNode<?> parent, String name) {\r
-               this.parent = parent;\r
-               this.parentName = name;\r
-       }\r
-       \r
-       public ParentNode<?> getRootNode() {\r
-               return parent != null ? parent.getRootNode() : null;\r
-       }\r
-       \r
-       public void remove() {\r
-               if (parent != null) {\r
-                       parent.removeNode(parentName, this);\r
-               }\r
-       }\r
-       \r
-       public void deattach() {\r
-               if (parent != null) {\r
-                       parent.deattachNode(parentName, this);\r
-               }\r
-       }\r
-       \r
-       public void init() {\r
-       }\r
-       \r
-       public void cleanup() {\r
-               if (parent != null) {\r
-                       parent.removeNode(parentName, this);\r
-               }\r
-       }\r
-       \r
-       @Override\r
-       public String toString() {\r
-               return getClass().getSimpleName();\r
-       }\r
-       \r
-       protected List<NodeListener> listeners = new ArrayList<NodeListener>();\r
-       \r
-       @Override\r
-       public void addListener(NodeListener listener) {\r
-               if (!listeners.contains(listener))\r
-                       listeners.add(listener);\r
-       }\r
-       \r
-       @Override\r
-       public void removeListener(NodeListener listener) {\r
-               listeners.remove(listener);\r
-       }\r
-       \r
-       @Override\r
-       public List<NodeListener> getListeners() {\r
-               return listeners;\r
-       }\r
-       \r
-       protected void firePropertyChanged(String id) {\r
-               for (NodeListener listener : listeners) {\r
-                       listener.propertyChanged(this, id);\r
-               }\r
-       }\r
-       \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 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.g3d.scenegraph.base;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.ListenerList;
+
+
+public abstract class Node implements INode {
+       public transient static long               IDCOUNTER              = 1;
+       protected transient ParentNode<?>          parent                 = null;
+       protected transient String                                 parentName                     = null; 
+       protected Long                             id                     = IDCOUNTER++;
+       
+
+       public Long getId() {
+               return id;
+       }
+
+
+       public ParentNode<?> getParent() {
+               return parent;
+       }
+
+       
+       @Override
+       public String getParentRel() {
+               return parentName;
+       }
+       
+       public void setParent(ParentNode<?> parent, String name) {
+               this.parent = parent;
+               this.parentName = name;
+       }
+       
+       public ParentNode<?> getRootNode() {
+               return parent != null ? parent.getRootNode() : null;
+       }
+       
+       public void remove() {
+               if (parent != null) {
+                       parent.removeNode(parentName, this);
+               }
+       }
+       
+       public void deattach() {
+               if (parent != null) {
+                       parent.deattachNode(parentName, this);
+               }
+       }
+       
+       public void init() {
+       }
+       
+       public void cleanup() {
+               if (parent != null) {
+                       parent.removeNode(parentName, this);
+               }
+       }
+       
+       @Override
+       public String toString() {
+               return getClass().getSimpleName();
+       }
+       
+       protected ListenerList<NodeListener> listeners = new ListenerList<NodeListener>();
+       
+       @Override
+       public void addListener(NodeListener listener) {
+               listeners.add(listener);
+       }
+       
+       @Override
+       public void removeListener(NodeListener listener) {
+               listeners.remove(listener);
+       }
+       
+       @Override
+       public ListenerList<NodeListener> getListeners() {
+               return listeners;
+       }
+       
+       protected void firePropertyChanged(String id) {
+               for (NodeListener listener : listeners) {
+                       listener.propertyChanged(this, id);
+               }
+       }
+       
+}