From 5cd9bf2669ef6907cff73670a393af5355241f56 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Tue, 29 Oct 2019 17:59:50 +0200 Subject: [PATCH] Use ListenerList with G3D nodes gitlab #42 Change-Id: I9ba6f84592c4122467608d72b45be592e259c0b2 --- .../simantics/g3d/scenegraph/base/INode.java | 4 +- .../simantics/g3d/scenegraph/base/Node.java | 199 +++++++++--------- 2 files changed, 102 insertions(+), 101 deletions(-) diff --git a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/INode.java b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/INode.java index 5a0297af..8dfef39d 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/INode.java +++ b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/INode.java @@ -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 getListeners(); + public ListenerList getListeners(); } diff --git a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/Node.java b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/Node.java index f7fe9ede..6d122930 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/Node.java +++ b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/Node.java @@ -1,99 +1,100 @@ -/******************************************************************************* - * 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; - - -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 List listeners = new ArrayList(); - - @Override - public void addListener(NodeListener listener) { - if (!listeners.contains(listener)) - listeners.add(listener); - } - - @Override - public void removeListener(NodeListener listener) { - listeners.remove(listener); - } - - @Override - public List getListeners() { - return listeners; - } - - protected void firePropertyChanged(String id) { - for (NodeListener listener : listeners) { - listener.propertyChanged(this, id); - } - } - -} +/******************************************************************************* + * 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 listeners = new ListenerList(); + + @Override + public void addListener(NodeListener listener) { + listeners.add(listener); + } + + @Override + public void removeListener(NodeListener listener) { + listeners.remove(listener); + } + + @Override + public ListenerList getListeners() { + return listeners; + } + + protected void firePropertyChanged(String id) { + for (NodeListener listener : listeners) { + listener.propertyChanged(this, id); + } + } + +} -- 2.47.1