Package syn3d.nodes

Source Code of syn3d.nodes.RootNode

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2004, by :
*     Corporate:
*         EADS Corporate Research Center
*     Individual:
*         Nicolas Brodu
*
* $Id: RootNode.java,v 1.8 2006/06/08 09:50:22 ogor Exp $
*
* Changes
* -------
* 17-Mar-2004 : Creation date (NB);
*
*/
package syn3d.nodes;

import java.io.Serializable;

import simtools.util.ListenerManager;
import syn3d.base.ActiveNode;

/**
* Special active node that can be recognized as the root node by other active nodes.
* Does nothing, really, it's just a type def.
* @author nicolas
*/
public class RootNode extends ActiveNode implements Serializable{

  static final long serialVersionUID = 898675638140874677L;
 
  /** An array of ActiveNodeTreeChangeListener objects */
    protected transient ListenerManager listeners = new ListenerManager();
   
  public RootNode() {
      name = "RootNode"; // Should not be displayed in any case, but...
  }
   
    // Listeners related functions. Take care of duplicates

  public void addListener(ActiveNodeTreeChangeListener dsl) {
    listeners.add(dsl);
  }

  public void removeListener(ActiveNodeTreeChangeListener dsl) {
    listeners.remove(dsl);
  }

  public void notifyListenersForNodeAdded(ActiveNode node) {
      synchronized(listeners) {
        int n = listeners.size(); // only one call outside loop
        for (int i=0; i<n; ++i) {
            ActiveNodeTreeChangeListener ancl = (ActiveNodeTreeChangeListener)listeners.get(i);
            if (ancl!=null) ancl.nodeAdded(node);
        }
      }
  }

  public void notifyListenersForNodeRemoved(ActiveNode node) {
      synchronized(listeners) {
        int n = listeners.size(); // only one call outside loop
        for (int i=0; i<n; ++i) {
            ActiveNodeTreeChangeListener ancl = (ActiveNodeTreeChangeListener)listeners.get(i);
            if (ancl!=null) ancl.nodeRemoved(node);
        }
      }
  }

  public void notifyListenersForNameChange(ActiveNode node) {
      synchronized(listeners) {
        int n = listeners.size(); // only one call outside loop
        for (int i=0; i<n; ++i) {
            ActiveNodeTreeChangeListener ancl = (ActiveNodeTreeChangeListener)listeners.get(i);
            if (ancl!=null) ancl.nameChanged(node);
        }
      }
  }

  public void notifyListenersForStructuralChange(ActiveNode node) {
      synchronized(listeners) {
        int n = listeners.size(); // only one call outside loop
        for (int i=0; i<n; ++i) {
            ActiveNodeTreeChangeListener ancl = (ActiveNodeTreeChangeListener)listeners.get(i);
            if (ancl!=null) ancl.structureChanged(node);
        }
      }
  }

    public void notifyListenersForHighlight(ActiveNode node, boolean on) {
      synchronized(listeners) {
        int n = listeners.size(); // only one call outside loop
        for (int i=0; i<n; ++i) {
            ActiveNodeTreeChangeListener ancl = (ActiveNodeTreeChangeListener)listeners.get(i);
            if (ancl!=null) ancl.highlightChanged(node,on);
        }
      }
    }

    protected void propagateAddChildEvent(ActiveNode child) {
        // Dont call super instance, as there is no parent in RootNode to propagate to
        // Rather, notify our listeners... If it's not the RootNode constructor call!
        if (listeners!=null) notifyListenersForNodeAdded(child);
    }
   
    protected void propagateRemoveChildEvent(ActiveNode child) {
        // Dont call super instance, as there is no parent in RootNode to propagate to
        // Rather, notify our listeners... If it's not the RootNode constructor call! (test for nullity)
    
      if (listeners!=null) notifyListenersForNodeRemoved(child);
    }
   
    protected void propagateChangeNameEvent(ActiveNode node) {
        // see other function for comments
        if (listeners!=null) notifyListenersForNameChange(node);
    }

    protected void propagateHighlightEvent(ActiveNode node, boolean on) {
        // see other function for comments
        if (listeners!=null) notifyListenersForHighlight(node, on);
    }

    protected void propagateStructuralChangeEvent(ActiveNode node) {
        // see other function for comments
        if (listeners!=null) notifyListenersForStructuralChange(node);
    }
          
    private void readObject(java.io.ObjectInputStream in) throws java.lang.ClassNotFoundException, java.io.IOException {
      in.defaultReadObject();
      listeners = new ListenerManager();
    }
 
}
TOP

Related Classes of syn3d.nodes.RootNode

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.